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

Commit 7310642c authored by DvTonder's avatar DvTonder Committed by Ricardo Cerqueira
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)

Change-Id: I17669420d9db9a347af182fc398c6426e18534f4

PowerWidget: Make widgets stationary like everything else in the tray

Before patch: widgets move up with the grab bar (and get smashed a bit)
https://dl.dropbox.com/u/1077120/Android/Screenshot_2012-09-13-18-19-39.png

After patch: widgets disappear behind the grab bar, like everything else
https://dl.dropbox.com/u/1077120/Android/Screenshot_2012-09-13-18-23-52.png

Change-Id: Iedded9c4ba89bb5284a8b8cd0e48be8e0cafa01d
parent 3849b2b3
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
@@ -2591,13 +2591,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
         *
@@ -2605,13 +2598,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
@@ -2069,4 +2069,12 @@
  <java-symbol type="string" name="wildcardProfile" />
  <java-symbol type="xml" name="profile_default" />

  <!-- 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
@@ -31,6 +31,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" />
@@ -62,6 +63,11 @@
    <uses-permission android:name="android.permission.READ_DREAM_STATE" />
    <uses-permission android:name="android.permission.WRITE_DREAM_STATE" />

    <!-- 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