diff options
author | Petr Sedlacek <petr@sedlacek.biz> | 2016-02-08 22:26:50 +0100 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2016-02-10 14:54:49 -0800 |
commit | 724fd2f5169d4462b29def9d44a24020156cf87a (patch) | |
tree | 59744290e66faf5e3547599f8fb371d29c565ded /src/com/android/settings/profiles | |
parent | d436b02a4b8748c75ce69bb2737868e0d582bb78 (diff) | |
download | packages_apps_Settings-724fd2f5169d4462b29def9d44a24020156cf87a.zip packages_apps_Settings-724fd2f5169d4462b29def9d44a24020156cf87a.tar.gz packages_apps_Settings-724fd2f5169d4462b29def9d44a24020156cf87a.tar.bz2 |
Settings: Add notification light setting to system profiles (2/2)
Change-Id: I6e0f844362ad5a479b40da08bce8a66be10503ec
Diffstat (limited to 'src/com/android/settings/profiles')
3 files changed, 124 insertions, 1 deletions
diff --git a/src/com/android/settings/profiles/SetupActionsFragment.java b/src/com/android/settings/profiles/SetupActionsFragment.java index 7764073..14404bd 100644 --- a/src/com/android/settings/profiles/SetupActionsFragment.java +++ b/src/com/android/settings/profiles/SetupActionsFragment.java @@ -81,6 +81,7 @@ 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; +import com.android.settings.profiles.actions.item.NotificationLightModeItem; import com.android.settings.profiles.actions.item.ProfileNameItem; import com.android.settings.profiles.actions.item.RingModeItem; import com.android.settings.profiles.actions.item.TriggerItem; @@ -123,6 +124,8 @@ public class SetupActionsFragment extends SettingsPreferenceFragment private static final String LAST_SELECTED_POSITION = "last_selected_position"; private static final int DIALOG_REMOVE_PROFILE = 10; + private static final int DIALOG_NOTIFICATION_LIGHT_MODE = 11; + private int mLastSelectedPosition = -1; private Item mSelectedItem; @@ -146,6 +149,11 @@ public class SetupActionsFragment extends SettingsPreferenceFragment Profile.DozeMode.ENABLE, Profile.DozeMode.DISABLE }; + private static final int[] NOTIFICATION_LIGHT_MAPPING = new int[] { + Profile.NotificationLightMode.DEFAULT, + Profile.NotificationLightMode.ENABLE, + Profile.NotificationLightMode.DISABLE + }; private List<Item> mItems = new ArrayList<Item>(); public static SetupActionsFragment newInstance(Profile profile, boolean newProfile) { @@ -256,6 +264,11 @@ public class SetupActionsFragment extends SettingsPreferenceFragment mItems.add(new DozeModeItem(mProfile)); } + if (getResources().getBoolean( + com.android.internal.R.bool.config_intrusiveNotificationLed)) { + mItems.add(new NotificationLightModeItem(mProfile)); + } + // app groups mItems.add(new Header(getString(R.string.profile_app_group_category_title))); @@ -522,6 +535,9 @@ public class SetupActionsFragment extends SettingsPreferenceFragment case DIALOG_DOZE_MODE: return requestDozeModeDialog(); + case DIALOG_NOTIFICATION_LIGHT_MODE: + return requestNotificationLightModeDialog(); + case DIALOG_RING_MODE: return requestRingModeDialog(((RingModeItem) mSelectedItem).getSettings()); @@ -641,6 +657,35 @@ public class SetupActionsFragment extends SettingsPreferenceFragment return builder.create(); } + private AlertDialog requestNotificationLightModeDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + final String[] notificationLightEntries = + getResources().getStringArray(R.array.profile_notification_light_entries); + + int defaultIndex = 0; // no action + for (int i = 0; i < NOTIFICATION_LIGHT_MAPPING.length; i++) { + if (NOTIFICATION_LIGHT_MAPPING[i] == mProfile.getNotificationLightMode()) { + defaultIndex = i; + break; + } + } + + builder.setTitle(R.string.notification_light_title); + builder.setSingleChoiceItems(notificationLightEntries, defaultIndex, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int item) { + mProfile.setNotificationLightMode(NOTIFICATION_LIGHT_MAPPING[item]); + updateProfile(); + mAdapter.notifyDataSetChanged(); + dialog.dismiss(); + } + }); + + builder.setNegativeButton(android.R.string.cancel, null); + return builder.create(); + } + private AlertDialog requestAirplaneModeDialog(final AirplaneModeSettings setting) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final String[] connectionNames = @@ -1083,6 +1128,8 @@ public class SetupActionsFragment extends SettingsPreferenceFragment showDialog(DIALOG_LOCK_MODE); } else if (itemAtPosition instanceof DozeModeItem) { showDialog(DIALOG_DOZE_MODE); + } else if (itemAtPosition instanceof NotificationLightModeItem) { + showDialog(DIALOG_NOTIFICATION_LIGHT_MODE); } else if (itemAtPosition instanceof RingModeItem) { showDialog(DIALOG_RING_MODE); } else if (itemAtPosition instanceof ConnectionOverrideItem) { diff --git a/src/com/android/settings/profiles/actions/ItemListAdapter.java b/src/com/android/settings/profiles/actions/ItemListAdapter.java index 38a58a4..79cf22c 100644 --- a/src/com/android/settings/profiles/actions/ItemListAdapter.java +++ b/src/com/android/settings/profiles/actions/ItemListAdapter.java @@ -40,7 +40,8 @@ public class ItemListAdapter extends ArrayAdapter<Item> { TRIGGER_ITEM, APP_GROUP_ITEM, BRIGHTNESS_ITEM, - DOZEMODE_ITEM + DOZEMODE_ITEM, + NOTIFICATIONLIGHTMODE_ITEM } public ItemListAdapter(Context context, List<Item> items) { diff --git a/src/com/android/settings/profiles/actions/item/NotificationLightModeItem.java b/src/com/android/settings/profiles/actions/item/NotificationLightModeItem.java new file mode 100644 index 0000000..b2c9132 --- /dev/null +++ b/src/com/android/settings/profiles/actions/item/NotificationLightModeItem.java @@ -0,0 +1,75 @@ +/* + * 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.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import cyanogenmod.app.Profile; + +import com.android.settings.R; +import com.android.settings.profiles.actions.ItemListAdapter; + +public class NotificationLightModeItem implements Item { + Profile mProfile; + + public NotificationLightModeItem(Profile profile) { + mProfile = profile; + } + + @Override + public ItemListAdapter.RowType getRowType() { + return ItemListAdapter.RowType.NOTIFICATIONLIGHTMODE_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.notification_light_title); + + TextView desc = (TextView) view.findViewById(R.id.summary); + desc.setText(getSummaryString(mProfile)); + + return view; + } + + public static int getSummaryString(Profile profile) { + switch (profile.getNotificationLightMode()) { + case Profile.NotificationLightMode.DEFAULT: + return R.string.profile_action_none; //"leave unchanged" + case Profile.NotificationLightMode.ENABLE: + return R.string.profile_action_enable; + case Profile.NotificationLightMode.DISABLE: + return R.string.profile_action_disable; + default: return 0; + } + } +} |