OSDN Git Service

Settings: Add notification light setting to system profiles (2/2)
authorPetr Sedlacek <petr@sedlacek.biz>
Mon, 8 Feb 2016 21:26:50 +0000 (22:26 +0100)
committerAdnan Begovic <adnan@cyngn.com>
Wed, 10 Feb 2016 22:54:49 +0000 (14:54 -0800)
Change-Id: I6e0f844362ad5a479b40da08bce8a66be10503ec

res/values/cm_arrays.xml
src/com/android/settings/profiles/SetupActionsFragment.java
src/com/android/settings/profiles/actions/ItemListAdapter.java
src/com/android/settings/profiles/actions/item/NotificationLightModeItem.java [new file with mode: 0644]

index d5435d9..44e7b9a 100644 (file)
         <item>@string/profile_action_disable</item>
     </string-array>
 
+    <string-array name="profile_notification_light_entries" translatable="false">
+        <item>@string/profile_action_none</item>
+        <item>@string/profile_action_enable</item>
+        <item>@string/profile_action_disable</item>
+    </string-array>
+
     <!-- Profile mode options. -->
      <string-array name="profile_entries" translatable="false">
          <item>@string/profile_entries_on</item>
index 7764073..14404bd 100644 (file)
@@ -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) {
index 38a58a4..79cf22c 100644 (file)
@@ -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 (file)
index 0000000..b2c9132
--- /dev/null
@@ -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;
+        }
+    }
+}