OSDN Git Service

Add power off button to quick settings dropdown box
authorDaniel Leung <daniel.leung@intel.com>
Thu, 13 Dec 2012 21:28:11 +0000 (13:28 -0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 25 Sep 2013 02:48:25 +0000 (10:48 +0800)
Add an option to power off the device in the quick settings
drop-down dialog. It is necessary for devices which the power
button does not function as Android expected. For example,
the hardware only sends button down event but no button up
event, or there is not long press event emitted what-so-ever.
Clicking on this button asks user for confirmation, and fires
the shutdown intent.

Issue: AXIA-1271
Change-Id: I12c3af70d39d45a2974f8fca03eb332e68017e15
Original-Change-Id: Iba14b10d12e788f9df6038e20aa98384838531e0
Original-Change-Id: Ic973ebf43b79b436a9e872613b8572a7c77ce0c3
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Signed-off-by: Anton Cherkashyn <antonx.t.cherkashyn@intel.com>
packages/SystemUI/AndroidManifest.xml
packages/SystemUI/res/layout/quick_settings_tile_poweroff.xml [new file with mode: 0644]
packages/SystemUI/res/values/strings.xml
packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java

index 66080f3..ecdbbe6 100644 (file)
@@ -40,6 +40,7 @@
     <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
     <uses-permission android:name="android.permission.MASTER_CLEAR" />
     <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.SHUTDOWN" />
 
     <!-- ActivityManager -->
     <uses-permission android:name="android.permission.GET_TASKS" />
diff --git a/packages/SystemUI/res/layout/quick_settings_tile_poweroff.xml b/packages/SystemUI/res/layout/quick_settings_tile_poweroff.xml
new file mode 100644 (file)
index 0000000..2821f46
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source 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.
+-->
+<TextView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/TextAppearance.QuickSettings.TileView"
+    android:id="@+id/poweroff_tileview"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:layout_gravity="center"
+    android:gravity="center"
+    android:drawableTop="@android:drawable/ic_lock_power_off"
+    />
\ No newline at end of file
index 5767e63..582ea9b 100644 (file)
     <string name="quick_settings_brightness_dialog_title">Brightness</string>
     <!-- QuickSettings: Brightness dialog auto brightness button [CHAR LIMIT=NONE] -->
     <string name="quick_settings_brightness_dialog_auto_brightness_label">AUTO</string>
+    <!-- QuickSettings: Power Off [CHAR LIMIT=NONE] -->
+    <string name="quick_settings_poweroff_label">Power Off</string>
 
     <!-- Title of help text shown when the notification panel is pulled down for the very first time. [CHAR LIMIT=NONE] -->
     <string name="status_bar_help_title">Notifications appear here</string>
index 85bcd8b..dbecea9 100644 (file)
@@ -587,6 +587,24 @@ class QuickSettings {
             parent.addView(bluetoothTile);
         }
 
+        // Power off
+        QuickSettingsTileView powerOffTile = (QuickSettingsTileView)
+                inflater.inflate(R.layout.quick_settings_tile, parent, false);
+        powerOffTile.setContent(R.layout.quick_settings_tile_poweroff, inflater);
+        powerOffTile.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                  onClickPowerOff();
+            }
+        });
+        mModel.addPowerOffTile(powerOffTile, new QuickSettingsModel.RefreshCallback() {
+            @Override
+            public void refreshView(QuickSettingsTileView view, State state) {
+                TextView tv = (TextView) view.findViewById(R.id.poweroff_tileview);
+                tv.setText(state.label);
+            }
+        });
+        parent.addView(powerOffTile);
     }
 
     private void addTemporaryTiles(final ViewGroup parent, final LayoutInflater inflater) {
@@ -832,4 +850,31 @@ class QuickSettings {
 
         }
     };
+
+    // Power off
+    // ----------------------------
+    private void onClickPowerOff() {
+        if (mBar != null) {
+            mBar.collapseAllPanels(true);
+        }
+
+        // Create dialog to get user confirmation
+        final AlertDialog dialog = new AlertDialog.Builder(mContext)
+                    .setTitle(com.android.internal.R.string.power_off)
+                    .setMessage(com.android.internal.R.string.shutdown_confirm_question)
+                    .setPositiveButton(com.android.internal.R.string.yes,
+                        new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            // Send request to start ShutdownActivity
+                            Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
+                            intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
+                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                            mContext.startActivity(intent);
+                        }
+                    })
+                    .setNegativeButton(com.android.internal.R.string.no, null)
+                    .create();
+        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
+        dialog.show();
+    }
 }
index 38c46c4..02792ae 100644 (file)
@@ -259,6 +259,10 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
     private RefreshCallback mSettingsCallback;
     private State mSettingsState = new State();
 
+    private QuickSettingsTileView mPowerOffTile;
+    private RefreshCallback mPowerOffCallback;
+    private State mPowerOffState = new State();
+
     public QuickSettingsModel(Context context) {
         mContext = context;
         mHandler = new Handler();
@@ -731,4 +735,17 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
     void refreshBrightnessTile() {
         onBrightnessLevelChanged();
     }
+
+    // Power off
+    void addPowerOffTile(QuickSettingsTileView view, RefreshCallback cb) {
+        mPowerOffTile = view;
+        mPowerOffCallback = cb;
+        refreshPowerOffTile();
+    }
+    void refreshPowerOffTile() {
+        Resources r = mContext.getResources();
+        mPowerOffState.label = r.getString(R.string.quick_settings_poweroff_label);
+        mPowerOffCallback.refreshView(mPowerOffTile, mPowerOffState);
+    }
+
 }