diff options
author | Altaf-Mahdi <altaf.mahdi@gmail.com> | 2015-04-15 19:03:00 +0100 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-26 16:12:35 -0700 |
commit | 8faf268f3404cb7f2a99fb952fcdc49dfbdd352a (patch) | |
tree | 6bd6bd2fae2efde825de4ebadb08e875c5cc1f4c /src | |
parent | f10a82bfca8032a3e4c4c4057aa873dddf6e4c7b (diff) | |
download | packages_apps_Settings-8faf268f3404cb7f2a99fb952fcdc49dfbdd352a.zip packages_apps_Settings-8faf268f3404cb7f2a99fb952fcdc49dfbdd352a.tar.gz packages_apps_Settings-8faf268f3404cb7f2a99fb952fcdc49dfbdd352a.tar.bz2 |
Settings: enable/disable doze through Profiles (2/2)
* moved isDozeAvailable boolean to Utils so we can check for it in profiles
Change-Id: I5a768098b4ed00b28931bee58a58efa8280262a1
Diffstat (limited to 'src')
5 files changed, 139 insertions, 13 deletions
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index eef3c6b..14e4b9c 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -58,6 +58,8 @@ import android.util.Log; import java.util.ArrayList; import java.util.List; +import com.android.settings.Utils; + public class DisplaySettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener, OnPreferenceClickListener, Indexable { private static final String TAG = "DisplaySettings"; @@ -135,8 +137,8 @@ public class DisplaySettings extends SettingsPreferenceFragment implements removePreference(KEY_LIFT_TO_WAKE); } - if (isDozeAvailable(activity)) { - mDozePreference = (SwitchPreference) findPreference(KEY_DOZE); + mDozePreference = (SwitchPreference) findPreference(KEY_DOZE); + if (mDozePreference != null && Utils.isDozeAvailable(activity)) { mDozePreference.setOnPreferenceChangeListener(this); } else { removePreference(KEY_DOZE); @@ -207,15 +209,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements return sensors != null && sensors.getDefaultSensor(Sensor.TYPE_WAKE_GESTURE) != null; } - private static boolean isDozeAvailable(Context context) { - String name = Build.IS_DEBUGGABLE ? SystemProperties.get("debug.doze.component") : null; - if (TextUtils.isEmpty(name)) { - name = context.getResources().getString( - com.android.internal.R.string.config_dozeComponent); - } - return !TextUtils.isEmpty(name); - } - private static boolean isTapToWakeAvailable(Resources res) { return res.getBoolean(com.android.internal.R.bool.config_supportDoubleTapWake); } @@ -224,6 +217,10 @@ public class DisplaySettings extends SettingsPreferenceFragment implements return res.getBoolean(com.android.internal.R.bool.config_automatic_brightness_available); } + private static boolean isAutomaticBrightnessAvailable(Resources res) { + return res.getBoolean(com.android.internal.R.bool.config_automatic_brightness_available); + } + private void updateTimeoutPreferenceDescription(long currentTimeout) { ListPreference preference = mScreenTimeoutPreference; String summary; @@ -484,7 +481,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements if (!isLiftToWakeAvailable(context)) { result.add(KEY_LIFT_TO_WAKE); } - if (!isDozeAvailable(context)) { + if (!Utils.isDozeAvailable(context)) { result.add(KEY_DOZE); } if (!RotationPolicy.isRotationLockToggleVisible(context)) { diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 0a09b15..9c10272 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -52,11 +52,13 @@ import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.Uri; import android.os.BatteryManager; +import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.os.INetworkManagementService; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.os.storage.StorageManager; @@ -1298,6 +1300,15 @@ public final class Utils { } } + public static boolean isDozeAvailable(Context context) { + String name = Build.IS_DEBUGGABLE ? SystemProperties.get("debug.doze.component") : null; + if (TextUtils.isEmpty(name)) { + name = context.getResources().getString( + com.android.internal.R.string.config_dozeComponent); + } + return !TextUtils.isEmpty(name); + } + public static String getServiceStateString(int state, Resources res) { switch (state) { case ServiceState.STATE_IN_SERVICE: diff --git a/src/com/android/settings/profiles/SetupActionsFragment.java b/src/com/android/settings/profiles/SetupActionsFragment.java index c7fe6c2..c7c9680 100644 --- a/src/com/android/settings/profiles/SetupActionsFragment.java +++ b/src/com/android/settings/profiles/SetupActionsFragment.java @@ -75,6 +75,7 @@ import com.android.settings.profiles.actions.item.AirplaneModeItem; import com.android.settings.profiles.actions.item.BrightnessItem; import com.android.settings.profiles.actions.item.AppGroupItem; import com.android.settings.profiles.actions.item.ConnectionOverrideItem; +import com.android.settings.profiles.actions.item.DozeModeItem; import com.android.settings.profiles.actions.item.Header; import com.android.settings.profiles.actions.item.Item; import com.android.settings.profiles.actions.item.LockModeItem; @@ -82,6 +83,7 @@ import com.android.settings.profiles.actions.item.ProfileNameItem; import com.android.settings.profiles.actions.item.RingModeItem; import com.android.settings.profiles.actions.item.TriggerItem; import com.android.settings.profiles.actions.item.VolumeStreamItem; +import com.android.settings.Utils; import java.util.ArrayList; import java.util.List; @@ -120,6 +122,11 @@ public class SetupActionsFragment extends SettingsPreferenceFragment Profile.ExpandedDesktopMode.ENABLE, Profile.ExpandedDesktopMode.DISABLE }; + private static final int[] DOZE_MAPPING = new int[] { + Profile.DozeMode.DEFAULT, + Profile.DozeMode.ENABLE, + Profile.DozeMode.DISABLE + }; private List<Item> mItems = new ArrayList<Item>(); public static SetupActionsFragment newInstance(Profile profile, boolean newProfile) { @@ -213,6 +220,11 @@ public class SetupActionsFragment extends SettingsPreferenceFragment mItems.add(new LockModeItem(mProfile)); mItems.add(new BrightnessItem(mProfile.getBrightness())); + final Activity activity = getActivity(); + if (Utils.isDozeAvailable(activity)) { + mItems.add(new DozeModeItem(mProfile)); + } + // app groups if (SettingsActivity.showAdvancedPreferences(getActivity())) { mItems.add(new Header(getString(R.string.profile_app_group_category_title))); @@ -521,6 +533,35 @@ public class SetupActionsFragment extends SettingsPreferenceFragment builder.show(); } + private void requestDozeModeDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + final String[] dozeEntries = + getResources().getStringArray(R.array.profile_doze_entries); + + int defaultIndex = 0; // no action + for (int i = 0; i < DOZE_MAPPING.length; i++) { + if (DOZE_MAPPING[i] == mProfile.getDozeMode()) { + defaultIndex = i; + break; + } + } + + builder.setTitle(R.string.doze_title); + builder.setSingleChoiceItems(dozeEntries, defaultIndex, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int item) { + mProfile.setDozeMode(DOZE_MAPPING[item]); + updateProfile(); + mAdapter.notifyDataSetChanged(); + dialog.dismiss(); + } + }); + + builder.setNegativeButton(android.R.string.cancel, null); + builder.show(); + } + private void requestAirplaneModeDialog(final AirplaneModeSettings setting) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final String[] connectionNames = @@ -932,6 +973,8 @@ public class SetupActionsFragment extends SettingsPreferenceFragment requestBrightnessDialog(item.getSettings()); } else if (itemAtPosition instanceof LockModeItem) { requestLockscreenModeDialog(); + } else if (itemAtPosition instanceof DozeModeItem) { + requestDozeModeDialog(); } else if (itemAtPosition instanceof RingModeItem) { RingModeItem item = (RingModeItem) itemAtPosition; requestRingModeDialog(item.getSettings()); diff --git a/src/com/android/settings/profiles/actions/ItemListAdapter.java b/src/com/android/settings/profiles/actions/ItemListAdapter.java index e23387d..61bbd0d 100644 --- a/src/com/android/settings/profiles/actions/ItemListAdapter.java +++ b/src/com/android/settings/profiles/actions/ItemListAdapter.java @@ -37,7 +37,8 @@ public class ItemListAdapter extends ArrayAdapter<Item> { LOCKSCREENMODE_ITEM, TRIGGER_ITEM, APP_GROUP_ITEM, - BRIGHTNESS_ITEM + BRIGHTNESS_ITEM, + DOZEMODE_ITEM } public ItemListAdapter(Context context, List<Item> items) { diff --git a/src/com/android/settings/profiles/actions/item/DozeModeItem.java b/src/com/android/settings/profiles/actions/item/DozeModeItem.java new file mode 100644 index 0000000..6e2df52 --- /dev/null +++ b/src/com/android/settings/profiles/actions/item/DozeModeItem.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2014 The CyanogenMod Project + * + * 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.android.settings.profiles.actions.item; + +import android.app.Profile; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.android.settings.R; +import com.android.settings.profiles.actions.ItemListAdapter; + +public class DozeModeItem implements Item { + Profile mProfile; + + public DozeModeItem(Profile profile) { + mProfile = profile; + } + + @Override + public ItemListAdapter.RowType getRowType() { + return ItemListAdapter.RowType.DOZEMODE_ITEM; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) { + View view; + if (convertView == null) { + view = inflater.inflate(R.layout.list_two_line_item, parent, false); + // Do some initialization + } else { + view = convertView; + } + + TextView text = (TextView) view.findViewById(R.id.title); + text.setText(R.string.doze_title); + + TextView desc = (TextView) view.findViewById(R.id.summary); + desc.setText(getSummaryString(mProfile)); + + return view; + } + + public static int getSummaryString(Profile profile) { + switch (profile.getDozeMode()) { + case Profile.DozeMode.DEFAULT: + return R.string.profile_action_none; //"leave unchanged" + case Profile.DozeMode.ENABLE: + return R.string.profile_action_enable; + case Profile.DozeMode.DISABLE: + return R.string.profile_action_disable; + default: return 0; + } + } +} |