From: Braden Farmer Date: Thu, 29 Sep 2016 18:02:43 +0000 (-0600) Subject: Add activity for external applications to apply icon packs X-Git-Tag: android-x86-7.1-r1~489 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0eba8ee6e031e32fc5355299c55101504bda8e86;p=android-x86%2Fpackages-apps-Taskbar.git Add activity for external applications to apply icon packs --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a16c421f..9e7d0e07 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -130,6 +130,17 @@ + + + + + + + + diff --git a/app/src/main/java/com/farmerbb/taskbar/activity/IconPackApplyActivity.java b/app/src/main/java/com/farmerbb/taskbar/activity/IconPackApplyActivity.java new file mode 100644 index 00000000..97ae3525 --- /dev/null +++ b/app/src/main/java/com/farmerbb/taskbar/activity/IconPackApplyActivity.java @@ -0,0 +1,112 @@ +/* Copyright 2016 Braden Farmer + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.farmerbb.taskbar.activity; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.ActivityManager; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.os.Bundle; + +import com.farmerbb.taskbar.R; +import com.farmerbb.taskbar.service.NotificationService; +import com.farmerbb.taskbar.service.StartMenuService; +import com.farmerbb.taskbar.service.TaskbarService; +import com.farmerbb.taskbar.util.U; + +public class IconPackApplyActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if(getIntent().hasExtra(Intent.EXTRA_PACKAGE_NAME)) { + @SuppressLint("InlinedApi") + final String iconPackPackage = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME); + PackageManager pm = getPackageManager(); + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.apply_icon_pack) + .setMessage(getString(R.string.apply_icon_pack_description, + pm.getLaunchIntentForPackage(iconPackPackage).resolveActivityInfo(pm, 0).loadLabel(pm))) + .setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } + }) + .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + SharedPreferences pref = U.getSharedPreferences(IconPackApplyActivity.this); + pref.edit().putString("icon_pack", iconPackPackage).apply(); + + U.refreshPinnedIcons(IconPackApplyActivity.this); + restartTaskbar(); + + finish(); + } + }); + + AlertDialog dialog = builder.create(); + dialog.show(); + dialog.setCancelable(false); + } else { + U.showToast(this, R.string.must_specify_extra); + finish(); + } + } + + private void startTaskbarService(boolean fullRestart) { + startService(new Intent(this, TaskbarService.class)); + startService(new Intent(this, StartMenuService.class)); + if(fullRestart) startService(new Intent(this, NotificationService.class)); + } + + private void stopTaskbarService(boolean fullRestart) { + stopService(new Intent(this, TaskbarService.class)); + stopService(new Intent(this, StartMenuService.class)); + if(fullRestart) stopService(new Intent(this, NotificationService.class)); + } + + private void restartTaskbar() { + SharedPreferences pref = U.getSharedPreferences(this); + if(pref.getBoolean("taskbar_active", false) && !pref.getBoolean("is_hidden", false)) { + pref.edit().putBoolean("is_restarting", true).apply(); + + stopTaskbarService(true); + startTaskbarService(true); + } else if(isServiceRunning()) { + stopTaskbarService(false); + startTaskbarService(false); + } + } + + private boolean isServiceRunning() { + ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + for(ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if(StartMenuService.class.getName().equals(service.service.getClassName())) + return true; + } + + return false; + } +} diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4547fe2c..a0b4bdd7 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -190,4 +190,8 @@ None No icon packs installed + Apply icon pack + Apply \'\'%1$s\'\' to Taskbar? + Must specify Intent.EXTRA_PACKAGE_NAME + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 764ed03c..35a40e7a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,4 +190,8 @@ None No icon packs installed + Apply icon pack + Apply \'\'%1$s\'\' to Taskbar? + Must specify Intent.EXTRA_PACKAGE_NAME +