Merge "Show power menu on tablets." into jb-dev

This commit is contained in:
Amith Yamasani
2012-05-29 11:22:32 -07:00
committed by Android (Google) Code Review
4 changed files with 93 additions and 23 deletions

View File

@ -23,9 +23,6 @@
<!-- see comment in values/config.xml --> <!-- see comment in values/config.xml -->
<dimen name="config_prefDialogWidth">440dp</dimen> <dimen name="config_prefDialogWidth">440dp</dimen>
<!-- see comment in values/config.xml -->
<integer name="config_longPressOnPowerBehavior">2</integer>
<!-- see comment in values/config.xml --> <!-- see comment in values/config.xml -->
<integer name="config_longPressOnHomeBehavior">0</integer> <integer name="config_longPressOnHomeBehavior">0</integer>

View File

@ -20,9 +20,6 @@
<!-- These resources are around just to allow their values to be customized <!-- These resources are around just to allow their values to be customized
for different hardware and product builds. --> for different hardware and product builds. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- see comment in values/config.xml -->
<integer name="config_longPressOnPowerBehavior">2</integer>
<!-- Enable lockscreen rotation --> <!-- Enable lockscreen rotation -->
<bool name="config_enableLockScreenRotation">true</bool> <bool name="config_enableLockScreenRotation">true</bool>

View File

@ -1303,6 +1303,9 @@
<java-symbol type="string" name="global_actions_airplane_mode_off_status" /> <java-symbol type="string" name="global_actions_airplane_mode_off_status" />
<java-symbol type="string" name="global_actions_airplane_mode_on_status" /> <java-symbol type="string" name="global_actions_airplane_mode_on_status" />
<java-symbol type="string" name="global_actions_toggle_airplane_mode" /> <java-symbol type="string" name="global_actions_toggle_airplane_mode" />
<java-symbol type="string" name="global_action_silent_mode_off_status" />
<java-symbol type="string" name="global_action_silent_mode_on_status" />
<java-symbol type="string" name="global_action_toggle_silent_mode" />
<java-symbol type="string" name="invalidPuk" /> <java-symbol type="string" name="invalidPuk" />
<java-symbol type="string" name="keyguard_password_enter_pin_code" /> <java-symbol type="string" name="keyguard_password_enter_pin_code" />
<java-symbol type="string" name="keyguard_password_enter_puk_code" /> <java-symbol type="string" name="keyguard_password_enter_puk_code" />

View File

@ -28,7 +28,9 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message; import android.os.Message;
@ -73,7 +75,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
private ArrayList<Action> mItems; private ArrayList<Action> mItems;
private AlertDialog mDialog; private AlertDialog mDialog;
private SilentModeAction mSilentModeAction; private Action mSilentModeAction;
private ToggleAction mAirplaneModeOn; private ToggleAction mAirplaneModeOn;
private MyAdapter mAdapter; private MyAdapter mAdapter;
@ -82,6 +84,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
private boolean mDeviceProvisioned = false; private boolean mDeviceProvisioned = false;
private ToggleAction.State mAirplaneState = ToggleAction.State.Off; private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
private boolean mIsWaitingForEcmExit = false; private boolean mIsWaitingForEcmExit = false;
private boolean mHasTelephony;
private boolean mHasVibrator;
private IWindowManager mIWindowManager; private IWindowManager mIWindowManager;
@ -104,6 +108,14 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
TelephonyManager telephonyManager = TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE); telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
ConnectivityManager cm = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.AIRPLANE_MODE_ON), true,
mAirplaneModeObserver);
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
mHasVibrator = vibrator != null && vibrator.hasVibrator();
} }
/** /**
@ -130,13 +142,18 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
mDialog.show(); mDialog.show();
mDialog.getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_DISABLE_EXPAND); mDialog.getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_DISABLE_EXPAND);
} }
/** /**
* Create the global actions dialog. * Create the global actions dialog.
* @return A new dialog. * @return A new dialog.
*/ */
private AlertDialog createDialog() { private AlertDialog createDialog() {
mSilentModeAction = new SilentModeAction(mContext, mAudioManager, mHandler); // Simple toggle style if there's no vibrator, otherwise use a tri-state
if (!mHasVibrator) {
mSilentModeAction = new SilentModeToggleAction();
} else {
mSilentModeAction = new SilentModeTriStateAction(mContext, mAudioManager, mHandler);
}
mAirplaneModeOn = new ToggleAction( mAirplaneModeOn = new ToggleAction(
R.drawable.ic_lock_airplane_mode, R.drawable.ic_lock_airplane_mode,
R.drawable.ic_lock_airplane_mode_off, R.drawable.ic_lock_airplane_mode_off,
@ -145,7 +162,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
R.string.global_actions_airplane_mode_off_status) { R.string.global_actions_airplane_mode_off_status) {
void onToggle(boolean on) { void onToggle(boolean on) {
if (Boolean.parseBoolean( if (mHasTelephony && Boolean.parseBoolean(
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
mIsWaitingForEcmExit = true; mIsWaitingForEcmExit = true;
// Launch ECM exit dialog // Launch ECM exit dialog
@ -160,6 +177,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
@Override @Override
protected void changeStateFromPress(boolean buttonOn) { protected void changeStateFromPress(boolean buttonOn) {
if (!mHasTelephony) return;
// In ECM mode airplane state cannot be changed // In ECM mode airplane state cannot be changed
if (!(Boolean.parseBoolean( if (!(Boolean.parseBoolean(
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) { SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
@ -176,6 +195,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
return false; return false;
} }
}; };
onAirplaneModeChanged();
mItems = new ArrayList<Action>(); mItems = new ArrayList<Action>();
@ -247,6 +267,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
mItems.add(switchToUser); mItems.add(switchToUser);
} }
} }
mAdapter = new MyAdapter(); mAdapter = new MyAdapter();
final AlertDialog.Builder ab = new AlertDialog.Builder(mContext); final AlertDialog.Builder ab = new AlertDialog.Builder(mContext);
@ -273,8 +294,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
} }
private void prepareDialog() { private void prepareDialog() {
final boolean silentModeOn = refreshSilentMode();
mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
mAirplaneModeOn.updateState(mAirplaneState); mAirplaneModeOn.updateState(mAirplaneState);
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
if (mKeyguardShowing) { if (mKeyguardShowing) {
@ -288,6 +308,15 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
} }
} }
private void refreshSilentMode() {
if (!mHasVibrator) {
final boolean silentModeOn =
mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
((ToggleAction)mSilentModeAction).updateState(
silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
}
}
/** {@inheritDoc} */ /** {@inheritDoc} */
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
if (SHOW_SILENT_TOGGLE) { if (SHOW_SILENT_TOGGLE) {
@ -297,7 +326,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
/** {@inheritDoc} */ /** {@inheritDoc} */
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (!(mAdapter.getItem(which) instanceof SilentModeAction)) { if (!(mAdapter.getItem(which) instanceof SilentModeTriStateAction)) {
dialog.dismiss(); dialog.dismiss();
} }
mAdapter.getItem(which).onPress(); mAdapter.getItem(which).onPress();
@ -495,12 +524,12 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
*/ */
public ToggleAction(int enabledIconResId, public ToggleAction(int enabledIconResId,
int disabledIconResid, int disabledIconResid,
int essage, int message,
int enabledStatusMessageResId, int enabledStatusMessageResId,
int disabledStatusMessageResId) { int disabledStatusMessageResId) {
mEnabledIconResId = enabledIconResId; mEnabledIconResId = enabledIconResId;
mDisabledIconResid = disabledIconResid; mDisabledIconResid = disabledIconResid;
mMessageResId = essage; mMessageResId = message;
mEnabledStatusMessageResId = enabledStatusMessageResId; mEnabledStatusMessageResId = enabledStatusMessageResId;
mDisabledStatusMessageResId = disabledStatusMessageResId; mDisabledStatusMessageResId = disabledStatusMessageResId;
} }
@ -583,21 +612,44 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
} }
} }
private static class SilentModeAction implements Action, View.OnClickListener { private class SilentModeToggleAction extends ToggleAction {
public SilentModeToggleAction() {
super(R.drawable.ic_audio_vol_mute,
R.drawable.ic_audio_vol,
R.string.global_action_toggle_silent_mode,
R.string.global_action_silent_mode_on_status,
R.string.global_action_silent_mode_off_status);
}
void onToggle(boolean on) {
if (on) {
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
} else {
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return false;
}
}
private static class SilentModeTriStateAction implements Action, View.OnClickListener {
private final int[] ITEM_IDS = { R.id.option1, R.id.option2, R.id.option3 }; private final int[] ITEM_IDS = { R.id.option1, R.id.option2, R.id.option3 };
private final AudioManager mAudioManager; private final AudioManager mAudioManager;
private final Handler mHandler; private final Handler mHandler;
private final boolean mHasVibrator;
private final Context mContext; private final Context mContext;
SilentModeAction(Context context, AudioManager audioManager, Handler handler) { SilentModeTriStateAction(Context context, AudioManager audioManager, Handler handler) {
mAudioManager = audioManager; mAudioManager = audioManager;
mHandler = handler; mHandler = handler;
mContext = context; mContext = context;
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
mHasVibrator = vibrator != null && vibrator.hasVibrator();
} }
private int ringerModeToIndex(int ringerMode) { private int ringerModeToIndex(int ringerMode) {
@ -621,9 +673,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
// Set up click handler // Set up click handler
itemView.setTag(i); itemView.setTag(i);
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
if (itemView.getId() == R.id.option2 && !mHasVibrator) {
itemView.setVisibility(View.GONE);
}
} }
return v; return v;
} }
@ -683,6 +732,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
PhoneStateListener mPhoneStateListener = new PhoneStateListener() { PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
@Override @Override
public void onServiceStateChanged(ServiceState serviceState) { public void onServiceStateChanged(ServiceState serviceState) {
if (!mHasTelephony) return;
final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF; final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off; mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
mAirplaneModeOn.updateState(mAirplaneState); mAirplaneModeOn.updateState(mAirplaneState);
@ -699,6 +749,13 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
} }
}; };
private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
onAirplaneModeChanged();
}
};
private static final int MESSAGE_DISMISS = 0; private static final int MESSAGE_DISMISS = 0;
private static final int MESSAGE_REFRESH = 1; private static final int MESSAGE_REFRESH = 1;
private static final int MESSAGE_SHOW = 2; private static final int MESSAGE_SHOW = 2;
@ -713,6 +770,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
} }
break; break;
case MESSAGE_REFRESH: case MESSAGE_REFRESH:
refreshSilentMode();
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
break; break;
case MESSAGE_SHOW: case MESSAGE_SHOW:
@ -722,6 +780,18 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
} }
}; };
private void onAirplaneModeChanged() {
// Let the service state callbacks handle the state.
if (mHasTelephony) return;
boolean airplaneModeOn = Settings.System.getInt(
mContext.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON,
0) == 1;
mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
mAirplaneModeOn.updateState(mAirplaneState);
}
/** /**
* Change the airplane mode system setting * Change the airplane mode system setting
*/ */
@ -734,6 +804,9 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
intent.putExtra("state", on); intent.putExtra("state", on);
mContext.sendBroadcast(intent); mContext.sendBroadcast(intent);
if (!mHasTelephony) {
mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
}
} }
private IWindowManager getWindowManager() { private IWindowManager getWindowManager() {