diff options
author | jrizzoli <joey@cyanogenmoditalia.it> | 2016-03-13 00:00:21 +0100 |
---|---|---|
committer | jrizzoli <joey@cyanogenmoditalia.it> | 2016-03-13 14:02:57 +0100 |
commit | 24a375a8f086add50ce1f8a1dcf3562900c9b17f (patch) | |
tree | 95aff35a9d1ad3c85df45c575400112656203b60 | |
parent | 9013f0f4d08fa1a29c5d75f41e743a9c85703f7d (diff) | |
download | android_packages_apps_Gello-24a375a8f086add50ce1f8a1dcf3562900c9b17f.tar.gz android_packages_apps_Gello-24a375a8f086add50ce1f8a1dcf3562900c9b17f.tar.bz2 android_packages_apps_Gello-24a375a8f086add50ce1f8a1dcf3562900c9b17f.zip |
Gello: auto-restart on power mode change
Change-Id: I80ed368b4ab274ed87ef181c191abdd1d11b6130
Signed-off-by: jrizzoli <joey@cyanogenmoditalia.it>
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/com/android/browser/preferences/GeneralPreferencesFragment.java | 36 |
2 files changed, 27 insertions, 13 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 1dc2c087..228c5b2e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -371,8 +371,8 @@ <string name="autofill_profile_editor_delete_profile">Delete</string> <!-- Text on toast shown to the user when power save mode is enabled or disabled --> - <string name="powersave_dialog_on">Power save mode enabled.\nPlease restart browser.</string> - <string name="powersave_dialog_off">Power save mode disabled.\nPlease restart browser.</string> + <string name="powersave_dialog_on">Power save mode enabled. Browser will be restarted.</string> + <string name="powersave_dialog_off">Power save mode disabled. Browser will be restarted.</string> <!-- Text on a dialog shown to the user when they are prompted to set up the autofill feature [CHAR-LIMIT=NONE] --> <string name="autofill_setup_dialog_message">The browser can automatically complete web forms like this one. Do you want to set up your auto-fill text?</string> diff --git a/src/com/android/browser/preferences/GeneralPreferencesFragment.java b/src/com/android/browser/preferences/GeneralPreferencesFragment.java index df4cf19f..e9d96112 100644 --- a/src/com/android/browser/preferences/GeneralPreferencesFragment.java +++ b/src/com/android/browser/preferences/GeneralPreferencesFragment.java @@ -17,17 +17,21 @@ package com.android.browser.preferences; import android.app.ActionBar; +import android.app.AlarmManager; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; +import android.app.PendingIntent; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; +import android.os.Handler; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceScreen; @@ -177,8 +181,8 @@ public class GeneralPreferencesFragment extends SWEPreferenceFragment settings.setPowerSaveModeEnabled((Boolean)objValue); PermissionsServiceFactory.setDefaultPermissions( PermissionsServiceFactory.PermissionType.WEBREFINER, !(Boolean) objValue); - showPowerSaveInfo((Boolean) objValue); BrowserPreferencesPage.sResultExtra = PreferenceKeys.ACTION_RELOAD_PAGE; + restartGello(getActivity(), (Boolean) objValue); } if (pref.getKey().equals(PreferenceKeys.PREF_NIGHTMODE_ENABLED)) { @@ -269,16 +273,26 @@ public class GeneralPreferencesFragment extends SWEPreferenceFragment return false; } - void showPowerSaveInfo(boolean toggle) { - String toastInfo; - if (toggle) - toastInfo = getActivity().getResources().getString(R.string.powersave_dialog_on); - else - toastInfo = getActivity().getResources().getString(R.string.powersave_dialog_off); - - Toast toast = Toast.makeText(getActivity(), toastInfo, Toast.LENGTH_SHORT); - toast.setGravity(Gravity.CENTER, 0, 0); - toast.show(); + private void restartGello(final Context context, boolean toggle) { + String toastInfo; + toastInfo = toggle ? + context.getResources().getString(R.string.powersave_dialog_on) : + context.getResources().getString(R.string.powersave_dialog_off); + Toast.makeText(context, toastInfo, Toast.LENGTH_SHORT).show(); + + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + Log.d("Gello", "Power save mode changed, restarting..."); + Intent restartIntent = context.getPackageManager() + .getLaunchIntentForPackage(context.getPackageName()); + PendingIntent intent = PendingIntent.getActivity( + context, 0, restartIntent, PendingIntent.FLAG_CANCEL_CURRENT); + AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + manager.set(AlarmManager.RTC, System.currentTimeMillis() + 1, intent); + System.exit(2); + } + }, 1500); } /* |