From 24a375a8f086add50ce1f8a1dcf3562900c9b17f Mon Sep 17 00:00:00 2001 From: jrizzoli Date: Sun, 13 Mar 2016 00:00:21 +0100 Subject: Gello: auto-restart on power mode change Change-Id: I80ed368b4ab274ed87ef181c191abdd1d11b6130 Signed-off-by: jrizzoli --- .../preferences/GeneralPreferencesFragment.java | 36 +++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src') 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); } /* -- cgit v1.2.3