• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Revision2d0e5e5fdeb786c91b55560b92067a3830adc7f7 (tree)
Time2014-08-27 19:18:37
AuthorDaniel Leung <daniel.leung@inte...>
CommiterChih-Wei Huang

Log Message

Add power off button to quick settings dropdown box

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>

Change Summary

Incremental Difference

--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -41,6 +41,7 @@
4141 <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
4242 <uses-permission android:name="android.permission.MASTER_CLEAR" />
4343 <uses-permission android:name="android.permission.VIBRATE" />
44+ <uses-permission android:name="android.permission.SHUTDOWN" />
4445
4546 <!-- ActivityManager -->
4647 <uses-permission android:name="android.permission.GET_TASKS" />
--- /dev/null
+++ b/packages/SystemUI/res/layout/quick_settings_tile_poweroff.xml
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+<TextView
17+ xmlns:android="http://schemas.android.com/apk/res/android"
18+ style="@style/TextAppearance.QuickSettings.TileView"
19+ android:id="@+id/poweroff_tileview"
20+ android:layout_width="wrap_content"
21+ android:layout_height="wrap_content"
22+ android:layout_gravity="center"
23+ android:gravity="center"
24+ android:drawableTop="@android:drawable/ic_lock_power_off"
25+ />
\ No newline at end of file
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -496,6 +496,8 @@
496496 <string name="quick_settings_brightness_dialog_title">Brightness</string>
497497 <!-- QuickSettings: Brightness dialog auto brightness button [CHAR LIMIT=NONE] -->
498498 <string name="quick_settings_brightness_dialog_auto_brightness_label">AUTO</string>
499+ <!-- QuickSettings: Power Off [CHAR LIMIT=NONE] -->
500+ <string name="quick_settings_poweroff_label">Power Off</string>
499501
500502
501503 <!-- Glyph to be overlaid atop the battery when the level is extremely low. Do not translate. -->
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
@@ -647,6 +647,25 @@ class QuickSettings {
647647 }
648648 });
649649 parent.addView(locationTile);
650+
651+ // Power off
652+ QuickSettingsTileView powerOffTile = (QuickSettingsTileView)
653+ inflater.inflate(R.layout.quick_settings_tile, parent, false);
654+ powerOffTile.setContent(R.layout.quick_settings_tile_poweroff, inflater);
655+ powerOffTile.setOnClickListener(new View.OnClickListener() {
656+ @Override
657+ public void onClick(View v) {
658+ onClickPowerOff();
659+ }
660+ });
661+ mModel.addPowerOffTile(powerOffTile, new QuickSettingsModel.RefreshCallback() {
662+ @Override
663+ public void refreshView(QuickSettingsTileView view, State state) {
664+ TextView tv = (TextView) view.findViewById(R.id.poweroff_tileview);
665+ tv.setText(state.label);
666+ }
667+ });
668+ parent.addView(powerOffTile);
650669 }
651670
652671 private void addTemporaryTiles(final ViewGroup parent, final LayoutInflater inflater) {
@@ -918,4 +937,31 @@ class QuickSettings {
918937 }
919938 }
920939 }
940+
941+ // Power off
942+ // ----------------------------
943+ private void onClickPowerOff() {
944+ if (mBar != null) {
945+ mBar.collapseAllPanels(true);
946+ }
947+
948+ // Create dialog to get user confirmation
949+ final AlertDialog dialog = new AlertDialog.Builder(mContext)
950+ .setTitle(com.android.internal.R.string.power_off)
951+ .setMessage(com.android.internal.R.string.shutdown_confirm_question)
952+ .setPositiveButton(com.android.internal.R.string.yes,
953+ new DialogInterface.OnClickListener() {
954+ public void onClick(DialogInterface dialog, int which) {
955+ // Send request to start ShutdownActivity
956+ Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
957+ intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
958+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
959+ mContext.startActivity(intent);
960+ }
961+ })
962+ .setNegativeButton(com.android.internal.R.string.no, null)
963+ .create();
964+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
965+ dialog.show();
966+ }
921967 }
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java
@@ -301,6 +301,10 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
301301
302302 private RotationLockController mRotationLockController;
303303
304+ private QuickSettingsTileView mPowerOffTile;
305+ private RefreshCallback mPowerOffCallback;
306+ private State mPowerOffState = new State();
307+
304308 public QuickSettingsModel(Context context) {
305309 mContext = context;
306310 mHandler = new Handler();
@@ -865,4 +869,16 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
865869 mSslCaCertWarningState.label = r.getString(R.string.ssl_ca_cert_warning);
866870 mSslCaCertWarningCallback.refreshView(mSslCaCertWarningTile, mSslCaCertWarningState);
867871 }
872+
873+ // Power off
874+ void addPowerOffTile(QuickSettingsTileView view, RefreshCallback cb) {
875+ mPowerOffTile = view;
876+ mPowerOffCallback = cb;
877+ refreshPowerOffTile();
878+ }
879+ void refreshPowerOffTile() {
880+ Resources r = mContext.getResources();
881+ mPowerOffState.label = r.getString(R.string.quick_settings_poweroff_label);
882+ mPowerOffCallback.refreshView(mPowerOffTile, mPowerOffState);
883+ }
868884 }