summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/profiles
diff options
context:
space:
mode:
authorAltaf-Mahdi <altaf.mahdi@gmail.com>2015-04-15 19:03:00 +0100
committerAdnan Begovic <adnan@cyngn.com>2015-10-26 16:12:35 -0700
commit8faf268f3404cb7f2a99fb952fcdc49dfbdd352a (patch)
tree6bd6bd2fae2efde825de4ebadb08e875c5cc1f4c /src/com/android/settings/profiles
parentf10a82bfca8032a3e4c4c4057aa873dddf6e4c7b (diff)
downloadpackages_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/com/android/settings/profiles')
-rw-r--r--src/com/android/settings/profiles/SetupActionsFragment.java43
-rw-r--r--src/com/android/settings/profiles/actions/ItemListAdapter.java3
-rw-r--r--src/com/android/settings/profiles/actions/item/DozeModeItem.java74
3 files changed, 119 insertions, 1 deletions
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;
+ }
+ }
+}