Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 724fd2f5 authored by Petr Sedlacek's avatar Petr Sedlacek Committed by Adnan Begovic
Browse files

Settings: Add notification light setting to system profiles (2/2)

Change-Id: I6e0f844362ad5a479b40da08bce8a66be10503ec
parent d436b02a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -154,6 +154,12 @@
        <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>
+47 −0
Original line number Diff line number Diff line
@@ -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) {
+2 −1
Original line number Diff line number Diff line
@@ -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) {
+75 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}