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

Commit be4ad242 authored by Jesus David's avatar Jesus David Committed by Steve Kondik
Browse files

Frameworks: tablet powerwidget management (1/2)

Settings: http://review.cyanogenmod.com/#/c/16842/

Adds basic powerwidget management for tablet devices
Allows to setup up to 6 different toggles, or remove all of them

patchset 2: remove whitespaces and tabs
patchset 3: remove some other tabs left
patchset 4: some other tabs were hidden
patchset 5: *changed strings for consistency with phone powerwidget
            *added license header on some files
patchset 6: remove WIP tag

Change-Id: I2e643401aaac0146857abe8c2d2dbc652d28e666
parent e4f08266
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2222,6 +2222,13 @@ public final class Settings {
         */
        public static final String WIDGET_BUTTONS = "expanded_widget_buttons";

        /**
         * Widget Buttons to Use - Tablet
         *
         * @hide
         */
        public static final String WIDGET_BUTTONS_TABLET = "expanded_widget_buttons_tablet";

        /**
         * Navigation controls to Use
         *
+71 −20
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
 * Copyright (C) 2010 The Android Open Source Project
 * This code has been modified. Portions copyright (C) 2012 ParanoidAndroid Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -28,23 +29,23 @@
        android:orientation="vertical"
        >

    <!-- Airplane mode -->
    <!-- Toggle 1 -->
    <LinearLayout
            android:id="@+id/airplane"
            android:id="@+id/toggle_1"
            style="@style/StatusBarPanelSettingsRow"
            >
        <ImageView
                android:id="@+id/airplane_icon"
                android:id="@+id/toggle_1_icon"
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/ic_sysbar_airplane_on"
                />
        <TextView
                android:id="@+id/airplane_label"
                android:id="@+id/toggle_1_label"
                style="@style/StatusBarPanelSettingsContents"
                android:text="@string/status_bar_settings_airplane"
                />
        <Switch
                android:id="@+id/airplane_checkbox"
                android:id="@+id/toggle_1_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
@@ -53,23 +54,23 @@
    </LinearLayout>
    <View style="@style/StatusBarPanelSettingsPanelSeparator" />

    <!-- Network -->
    <!-- Toggle 2 -->
    <LinearLayout
            android:id="@+id/network"
            android:id="@+id/toggle_2"
            style="@style/StatusBarPanelSettingsRow"
            >
        <ImageView
                android:id="@+id/network_icon"
                android:id="@+id/toggle_2_icon"
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/ic_sysbar_wifi_on"
                />
        <TextView
                android:id="@+id/network_label"
                android:id="@+id/toggle_2_label"
                style="@style/StatusBarPanelSettingsContents"
                android:text="@string/status_bar_settings_wifi_button"
                />
        <Switch
                android:id="@+id/wifi_checkbox"
                android:id="@+id/toggle_2_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
@@ -78,23 +79,23 @@
    </LinearLayout>
    <View style="@style/StatusBarPanelSettingsPanelSeparator" />

    <!-- Bluetooth -->
    <!-- Toggle 3 -->
    <LinearLayout
            android:id="@+id/bluetooth"
            android:id="@+id/toggle_3"
            style="@style/StatusBarPanelSettingsRow"
            >
        <ImageView
                android:id="@+id/bluetooth_icon"
                android:id="@+id/toggle_3_icon"
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/stat_sys_data_bluetooth"
                />
        <TextView
                android:id="@+id/bluetooth_label"
                android:id="@+id/toggle_3_label"
                style="@style/StatusBarPanelSettingsContents"
                android:text="@string/status_bar_settings_bluetooth_button"
                />
        <Switch
                android:id="@+id/bluetooth_checkbox"
                android:id="@+id/toggle_3_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
@@ -103,23 +104,73 @@
    </LinearLayout>
    <View style="@style/StatusBarPanelSettingsPanelSeparator" />

    <!-- Rotation lock -->
    <!-- Toggle 4 -->
    <LinearLayout
            android:id="@+id/rotate"
            android:id="@+id/toggle_4"
            style="@style/StatusBarPanelSettingsRow"
            >
        <ImageView
                android:id="@+id/rotate_icon"
                android:id="@+id/toggle_4_icon"
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/ic_sysbar_rotate_on"
                />
        <TextView
                android:id="@+id/rotate_label"
                android:id="@+id/toggle_4_label"
                style="@style/StatusBarPanelSettingsContents"
                android:text="@string/status_bar_settings_auto_rotation"
                />
        <Switch
                android:id="@+id/rotate_checkbox"
                android:id="@+id/toggle_4_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="5dp"
                />
    </LinearLayout>
    <View style="@style/StatusBarPanelSettingsPanelSeparator" />

    <!-- Toggle 5 -->
    <LinearLayout
            android:id="@+id/toggle_5"
            style="@style/StatusBarPanelSettingsRow"
            >
        <ImageView
                android:id="@+id/toggle_5_icon"
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/stat_gps_on"
                />
        <TextView
                android:id="@+id/toggle_5_label"
                style="@style/StatusBarPanelSettingsContents"
                android:text="@string/status_bar_settings_location"
                />
        <Switch
                android:id="@+id/toggle_5_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="5dp"
                />
    </LinearLayout>
    <View style="@style/StatusBarPanelSettingsPanelSeparator" />

    <!-- Toggle 6 -->
    <LinearLayout
            android:id="@+id/toggle_6"
            style="@style/StatusBarPanelSettingsRow"
            >
        <ImageView
                android:id="@+id/toggle_6_icon"
                style="@style/StatusBarPanelSettingsIcon"
                android:src="@drawable/stat_flashlight_on"
                />
        <TextView
                android:id="@+id/toggle_6_label"
                style="@style/StatusBarPanelSettingsContents"
                android:text="@string/status_bar_settings_flashlight"
                />
        <Switch
                android:id="@+id/toggle_6_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
+15 −0
Original line number Diff line number Diff line
@@ -109,6 +109,21 @@
    <!-- Label in the system panel for airplane mode (all radios are turned off)[CHAR LIMIT=30] -->
    <string name="status_bar_settings_airplane">Airplane mode</string>

    <!-- Label in the system panel for gps state [CHAR LIMIT=30] -->
    <string name="status_bar_settings_location">GPS</string>

    <!-- Label in the system panel for flashlight state [CHAR LIMIT=30] -->
    <string name="status_bar_settings_flashlight">LED flashlight</string>

    <!-- Label in the system panel for mobile data state [CHAR LIMIT=30] -->
    <string name="status_bar_settings_mobile_data">Mobile data</string>

    <!-- Label in the system panel for network mode [CHAR LIMIT=30] -->
    <string name="status_bar_settings_network_mode">2G/3G</string>

    <!-- Label in the system panel for sound [CHAR LIMIT=30] -->
    <string name="status_bar_settings_sound_mode">Sound</string>

    <!-- Label in system panel saying the device will use the orientation sensor to rotate [CHAR LIMIT=30] -->
    <string name="status_bar_settings_auto_rotation">Auto-rotate screen</string>

+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The CyanogenMod Project
 * This code has been modified. Portions copyright (C) 2012 ParanoidAndroid 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.systemui.statusbar.policy;

import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.widget.CompoundButton;

import com.android.systemui.R;

public class FlashlightController implements CompoundButton.OnCheckedChangeListener {
    private static final String TAG = "StatusBar.FlashlightController";

    private Context mContext;
    private CompoundButton mCheckBox;

    private boolean mFlashLight;

    public FlashlightController(Context context, CompoundButton checkbox) {
        mContext = context;
        mFlashLight = getFlashLight();
        mCheckBox = checkbox;
        checkbox.setChecked(mFlashLight);
        checkbox.setOnCheckedChangeListener(this);
    }

    public void onCheckedChanged(CompoundButton view, boolean checked) {
        Intent i = new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT");
        i.putExtra("bright", !checked);
        mContext.sendBroadcast(i);
    }

    private boolean getFlashLight() {
        ContentResolver cr = mContext.getContentResolver();
        return Settings.System.getInt(cr, Settings.System.TORCH_STATE, 0) == 1;
    }
}
+28 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -29,6 +30,7 @@ import android.location.LocationManager;
import android.provider.Settings;
import android.util.Slog;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;

// private NM API
@@ -37,15 +39,31 @@ import com.android.internal.statusbar.StatusBarNotification;

import com.android.systemui.R;

public class LocationController extends BroadcastReceiver {
public class LocationController extends BroadcastReceiver implements CompoundButton.OnCheckedChangeListener {
    private static final String TAG = "StatusBar.LocationController";

    private static final int GPS_NOTIFICATION_ID = 374203-122084;

    private Context mContext;
    private CompoundButton mCheckBox;

    private INotificationManager mNotificationService;

    private boolean mGps;

    public LocationController(Context context, CompoundButton checkbox) {
        this(context);
        mContext = context;
        mGps = getGps();
        mCheckBox = checkbox;
        checkbox.setChecked(mGps);
        checkbox.setOnCheckedChangeListener(this);
    }

    public void onCheckedChanged(CompoundButton view, boolean checked) {
        Settings.Secure.setLocationProviderEnabled(mContext.getContentResolver(), LocationManager.GPS_PROVIDER, checked);
    }

    public LocationController(Context context) {
        mContext = context;

@@ -59,6 +77,15 @@ public class LocationController extends BroadcastReceiver {
        mNotificationService = nm.getService();
    }

    private boolean getGps() {
        ContentResolver cr = mContext.getContentResolver();
        return Settings.Secure.isLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER);
    }

    public void release() {
        mContext.unregisterReceiver(this);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
Loading