frameworks/base
修订版 | 2d0e5e5fdeb786c91b55560b92067a3830adc7f7 (tree) |
---|---|
时间 | 2014-08-27 19:18:37 |
作者 | Daniel Leung <daniel.leung@inte...> |
Commiter | Chih-Wei Huang |
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>
@@ -41,6 +41,7 @@ | ||
41 | 41 | <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> |
42 | 42 | <uses-permission android:name="android.permission.MASTER_CLEAR" /> |
43 | 43 | <uses-permission android:name="android.permission.VIBRATE" /> |
44 | + <uses-permission android:name="android.permission.SHUTDOWN" /> | |
44 | 45 | |
45 | 46 | <!-- ActivityManager --> |
46 | 47 | <uses-permission android:name="android.permission.GET_TASKS" /> |
@@ -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 |
@@ -496,6 +496,8 @@ | ||
496 | 496 | <string name="quick_settings_brightness_dialog_title">Brightness</string> |
497 | 497 | <!-- QuickSettings: Brightness dialog auto brightness button [CHAR LIMIT=NONE] --> |
498 | 498 | <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> | |
499 | 501 | |
500 | 502 | |
501 | 503 | <!-- Glyph to be overlaid atop the battery when the level is extremely low. Do not translate. --> |
@@ -647,6 +647,25 @@ class QuickSettings { | ||
647 | 647 | } |
648 | 648 | }); |
649 | 649 | 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); | |
650 | 669 | } |
651 | 670 | |
652 | 671 | private void addTemporaryTiles(final ViewGroup parent, final LayoutInflater inflater) { |
@@ -918,4 +937,31 @@ class QuickSettings { | ||
918 | 937 | } |
919 | 938 | } |
920 | 939 | } |
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 | + } | |
921 | 967 | } |
@@ -301,6 +301,10 @@ class QuickSettingsModel implements BluetoothStateChangeCallback, | ||
301 | 301 | |
302 | 302 | private RotationLockController mRotationLockController; |
303 | 303 | |
304 | + private QuickSettingsTileView mPowerOffTile; | |
305 | + private RefreshCallback mPowerOffCallback; | |
306 | + private State mPowerOffState = new State(); | |
307 | + | |
304 | 308 | public QuickSettingsModel(Context context) { |
305 | 309 | mContext = context; |
306 | 310 | mHandler = new Handler(); |
@@ -865,4 +869,16 @@ class QuickSettingsModel implements BluetoothStateChangeCallback, | ||
865 | 869 | mSslCaCertWarningState.label = r.getString(R.string.ssl_ca_cert_warning); |
866 | 870 | mSslCaCertWarningCallback.refreshView(mSslCaCertWarningTile, mSslCaCertWarningState); |
867 | 871 | } |
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 | + } | |
868 | 884 | } |