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

Commit 74f773e8 authored by DvTonder's avatar DvTonder Committed by Danesh M
Browse files

Framework: Add Power Widget (Phone)

This commit adds the Power widget for phones.  All toggles should work
except for LTE (disabled for now)

Patch set 2  - Fixes Sync toggle
Patch set 3  - Removes WIP
Patch set 4  - Rebase
               Switch to MultiSelectListPreference

Change-Id: I17669420d9db9a347af182fc398c6426e18534f4
parent 688e93c2
Loading
Loading
Loading
Loading
+0 −112
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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 android.preference;

import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.AttributeSet;

/**
 * This Preference type is required for the Power Widget functionality.  It should
 * not be used for any other multi select lists, use the Android MultiselectListPreference
 * instead
 * @hide
 */
public class ListPreferenceMultiSelect extends ListPreference {

    private static final String SEPARATOR = "OV=I=XseparatorX=I=VO";

    private boolean[] mClickedDialogEntryIndices;

    public ListPreferenceMultiSelect(Context context) {
        super(context);
    }

    public ListPreferenceMultiSelect(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onPrepareDialogBuilder(Builder builder) {
        CharSequence[] entries = getEntries();
        CharSequence[] entryValues = getEntryValues();

        if (entries == null || entryValues == null || entries.length != entryValues.length) {
            throw new IllegalStateException(
                    this.getClass().getSimpleName()
                            + " requires an entries array and an entryValues array which are both the same length");
        }

        mClickedDialogEntryIndices = new boolean[entryValues.length];
        restoreCheckedEntries();
        builder.setMultiChoiceItems(entries, mClickedDialogEntryIndices, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                mClickedDialogEntryIndices[which] = isChecked;
            }
        });
    }

    public static String[] parseStoredValue(CharSequence val) {
        if (TextUtils.isEmpty(val)) {
            return null;
        } else {
            return val.toString().split(SEPARATOR);
        }
    }

    private void restoreCheckedEntries() {
        CharSequence[] entryValues = getEntryValues();

        String[] vals = parseStoredValue(getValue());
        if (vals != null) {
            for (String val : vals) {
                for (int i = 0; i < entryValues.length; i++) {
                    CharSequence entry = entryValues[i];
                    if (entry.equals(val)) {
                        mClickedDialogEntryIndices[i] = true;
                        break;
                    }
                }
            }
        }
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        CharSequence[] entryValues = getEntryValues();

        if (positiveResult && entryValues != null) {
            StringBuilder value = new StringBuilder();
            for (int i = 0; i < entryValues.length; i++) {
                if (mClickedDialogEntryIndices[i]) {
                    if (value.length() > 0) {
                        value.append(SEPARATOR);
                    }
                    value.append(entryValues[i]);
                }
            }

            String val = value.toString();
            if (callChangeListener(val)) {
                setValue(val);
            }
        }
    }
}
+0 −14
Original line number Diff line number Diff line
@@ -2322,13 +2322,6 @@ public final class Settings {
         */
        public static final String EXPANDED_HIDE_SCROLLBAR = "expanded_hide_scrollbar";

        /**
         * Hide indicator in status bar widget
         *
         * @hide
         */
        public static final String EXPANDED_HIDE_INDICATOR = "expanded_hide_indicator";

        /**
         * Haptic feedback in power widget
         *
@@ -2336,13 +2329,6 @@ public final class Settings {
         */
        public static final String EXPANDED_HAPTIC_FEEDBACK = "expanded_haptic_feedback";

        /**
         * Notification Indicator Color
         *
         * @hide
         */
        public static final String EXPANDED_VIEW_WIDGET_COLOR = "expanded_widget_color";

        /**
         * Widget Buttons to Use
         *
+8 −0
Original line number Diff line number Diff line
@@ -3817,4 +3817,12 @@
  <java-symbol type="id" name="calendar_event_title" />
  <java-symbol type="id" name="calendar_event_details" />

  <!-- Power widget -->
  <java-symbol type="string" name="hour" />
  <java-symbol type="string" name="hours" />
  <java-symbol type="string" name="minute" />
  <java-symbol type="string" name="minutes" />
  <java-symbol type="string" name="second" />
  <java-symbol type="string" name="seconds" />

</resources>
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.MANAGE_NETWORK_POLICY" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

    <!-- Physical hardware -->
    <uses-permission android:name="android.permission.MANAGE_USB" />
@@ -49,6 +50,11 @@
    <uses-permission android:name="android.permission.SET_ORIENTATION" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

    <!-- Power widget -->
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

    <application
        android:persistent="true"
        android:allowClearUserData="false"
+3.12 KiB
Loading image diff...
Loading