Skip to content

Commit

Permalink
status bar power menu
Browse files Browse the repository at this point in the history
  • Loading branch information
rascarlo committed Dec 9, 2014
1 parent a4c4cf2 commit d764686
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 6 deletions.
8 changes: 8 additions & 0 deletions core/java/android/content/Intent.java
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,14 @@ public class Intent implements Parcelable, Cloneable {
public static final String EXTRA_SHORTCUT_ICON_RESOURCE =
"android.intent.extra.shortcut.ICON_RESOURCE";

/**
* Global Action: Shows power menu dialog
* <p>Input: nothing
* <p>Output: nothing
* @hide
*/
public static final String ACTION_POWER_MENU = "android.intent.action.POWER_MENU";

/**
* Represents a shortcut/live folder icon resource.
*
Expand Down
9 changes: 9 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,15 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
*/
public static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";

/**
* Status bar power menu
* 0 - disabled (default)
* 1 - screen off / power menu
* 2 - power menu - screen off
* @hide
*/
public static final String STATUS_BAR_POWER_MENU = "status_bar_power_menu";

/**
* Settings to backup. This is here so that it's in the same place as the settings
* keys and easy to update.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions packages/SystemUI/res/layout/status_bar_expanded_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
android:id="@+id/clock"
/>

<ImageView
android:id="@+id/status_bar_power_menu"
android:background="@drawable/ripple_drawable"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="@dimen/clock_collapsed_bottom_margin"
android:layout_marginEnd="16dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_lock_power_off_alpha"
android:scaleType="centerInside" />

<Button android:id="@+id/alarm_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.PowerManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.content.Intent;
import android.content.res.Configuration;
Expand Down Expand Up @@ -56,7 +59,8 @@
* The view to manage the header area in the expanded status bar.
*/
public class StatusBarHeaderView extends RelativeLayout implements View.OnClickListener,
BatteryController.BatteryStateChangeCallback, NextAlarmController.NextAlarmChangeCallback {
View.OnLongClickListener, BatteryController.BatteryStateChangeCallback,
NextAlarmController.NextAlarmChangeCallback {

private boolean mExpanded;
private boolean mListening;
Expand All @@ -81,6 +85,7 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL
private TextView mEmergencyCallsOnly;
private TextView mBatteryLevel;
private TextView mAlarmStatus;
private ImageView mStatusBarPowerMenu;

private boolean mShowEmergencyCallsOnly;
private boolean mAlarmShowing;
Expand Down Expand Up @@ -125,21 +130,31 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL
private boolean mShowingDetail;

private boolean mShowBatteryPercent;
private int mStatusBarPowerMenuStyle;

private ContentObserver mObserver = new ContentObserver(new Handler()) {
private ContentObserver mContentObserver = new ContentObserver(new Handler()) {
public void onChange(boolean selfChange, Uri uri) {
loadShowBatteryTextSetting();
loadShowStatusBarPowerMenuSettings();
}
};

public StatusBarHeaderView(Context context, AttributeSet attrs) {
super(context, attrs);
loadShowBatteryTextSetting();
loadShowStatusBarPowerMenuSettings();
}

private void loadShowBatteryTextSetting() {
mShowBatteryPercent = 0 != Settings.System.getInt(
getContext().getContentResolver(), Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
ContentResolver resolver = getContext().getContentResolver();
mShowBatteryPercent = 0 != Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
}

private void loadShowStatusBarPowerMenuSettings() {
ContentResolver resolver = getContext().getContentResolver();
mStatusBarPowerMenuStyle = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_POWER_MENU, 0);
}

@Override
Expand All @@ -165,6 +180,10 @@ protected void onFinishInflate() {
mQsDetailHeaderProgress = (ImageView) findViewById(R.id.qs_detail_header_progress);
mEmergencyCallsOnly = (TextView) findViewById(R.id.header_emergency_calls_only);
mBatteryLevel = (TextView) findViewById(R.id.battery_level);
mStatusBarPowerMenu = (ImageView) findViewById(R.id.status_bar_power_menu);
mStatusBarPowerMenu.setOnClickListener(this);
mStatusBarPowerMenu.setLongClickable(true);
mStatusBarPowerMenu.setOnLongClickListener(this);
mAlarmStatus = (TextView) findViewById(R.id.alarm_status);
mAlarmStatus.setOnClickListener(this);
mSignalCluster = findViewById(R.id.signal_cluster);
Expand Down Expand Up @@ -347,6 +366,7 @@ private void updateVisibilities() {
}
mEmergencyCallsOnly.setVisibility(mExpanded && mShowEmergencyCallsOnly ? VISIBLE : GONE);
mBatteryLevel.setVisibility((mExpanded || mShowBatteryPercent) ? View.VISIBLE : View.GONE);
mStatusBarPowerMenu.setVisibility(mExpanded && (mStatusBarPowerMenuStyle > 0) ? View.VISIBLE : View.GONE);
}

private void updateSignalClusterDetachment() {
Expand Down Expand Up @@ -519,6 +539,8 @@ public void onClick(View v) {
if (showIntent != null && showIntent.isActivity()) {
mActivityStarter.startActivity(showIntent.getIntent(), true /* dismissShade */);
}
} else if (v == mStatusBarPowerMenu) {
statusBarPowerMenuAction();
}
}

Expand All @@ -532,6 +554,21 @@ private void startBatteryActivity() {
true /* dismissShade */);
}

private void triggerPowerMenuDialog() {
Intent intent = new Intent(Intent.ACTION_POWER_MENU);
mContext.sendBroadcast(intent); /* broadcast action */
mActivityStarter.startActivity(intent,
true /* dismissShade */);
}

private void statusBarPowerMenuAction() {
if (mStatusBarPowerMenuStyle == 1) {
goToSleep();
} else if (mStatusBarPowerMenuStyle == 2) {
triggerPowerMenuDialog();
}
}

public void setQSPanel(QSPanel qsp) {
mQSPanel = qsp;
if (mQSPanel != null) {
Expand Down Expand Up @@ -573,6 +610,7 @@ private void captureLayoutValues(LayoutValues target) {
target.avatarScale = mMultiUserAvatar.getScaleX();
target.avatarX = mMultiUserSwitch.getLeft() + mMultiUserAvatar.getLeft();
target.avatarY = mMultiUserSwitch.getTop() + mMultiUserAvatar.getTop();
target.statusBarPowerMenuY = mClock.getTop();
if (getLayoutDirection() == LAYOUT_DIRECTION_LTR) {
target.batteryX = mSystemIconsSuperContainer.getLeft()
+ mSystemIconsContainer.getRight();
Expand Down Expand Up @@ -611,6 +649,7 @@ private void applyLayoutValues(LayoutValues values) {
mTime.setScaleY(values.timeScale);
mClock.setY(values.clockY - mClock.getHeight());
mDateGroup.setY(values.dateY);
mStatusBarPowerMenu.setY(values.statusBarPowerMenuY);
mAlarmStatus.setY(values.dateY - mAlarmStatus.getPaddingTop());
mMultiUserAvatar.setScaleX(values.avatarScale);
mMultiUserAvatar.setScaleY(values.avatarScale);
Expand Down Expand Up @@ -649,6 +688,7 @@ private void applyLayoutValues(LayoutValues values) {
applyAlpha(mDateExpanded, values.dateExpandedAlpha);
applyAlpha(mBatteryLevel, values.batteryLevelAlpha);
applyAlpha(mSettingsButton, values.settingsAlpha);
applyAlpha(mStatusBarPowerMenu, values.settingsAlpha);
applyAlpha(mSignalCluster, values.signalClusterAlpha);
if (!mExpanded) {
mTime.setScaleX(1f);
Expand Down Expand Up @@ -680,6 +720,7 @@ private static final class LayoutValues {
float settingsTranslation;
float signalClusterAlpha;
float settingsRotation;
float statusBarPowerMenuY;

public void interpoloate(LayoutValues v1, LayoutValues v2, float t) {
timeScale = v1.timeScale * (1 - t) + v2.timeScale * t;
Expand All @@ -691,6 +732,7 @@ public void interpoloate(LayoutValues v1, LayoutValues v2, float t) {
batteryX = v1.batteryX * (1 - t) + v2.batteryX * t;
batteryY = v1.batteryY * (1 - t) + v2.batteryY * t;
settingsTranslation = v1.settingsTranslation * (1 - t) + v2.settingsTranslation * t;
statusBarPowerMenuY = v1.statusBarPowerMenuY * (1 - t) + v2.statusBarPowerMenuY * t;

float t1 = Math.max(0, t - 0.5f) * 2;
settingsRotation = v1.settingsRotation * (1 - t1) + v2.settingsRotation * t1;
Expand Down Expand Up @@ -763,6 +805,7 @@ private void handleShowingDetail(final QSTile.DetailAdapter detail) {
final boolean showingDetail = detail != null;
transition(mClock, !showingDetail);
transition(mDateGroup, !showingDetail);
transition(mStatusBarPowerMenu, !showingDetail);
if (mAlarmShowing) {
transition(mAlarmStatus, !showingDetail);
}
Expand Down Expand Up @@ -813,8 +856,13 @@ public void run() {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
"status_bar_show_battery_percent"), false, mObserver);
ContentResolver resolver = getContext().getContentResolver();
// status bar battery percent text
resolver.registerContentObserver(Settings.System.getUriFor(
"status_bar_show_battery_percent"), false, mContentObserver);
// status bar power menu
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.STATUS_BAR_POWER_MENU), false, mContentObserver);
}

@Override
Expand All @@ -825,4 +873,21 @@ public void onDetachedFromWindow() {
mBatteryController.removeStateChangedCallback(this);
}
}

private void goToSleep() {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
pm.goToSleep(SystemClock.uptimeMillis());
}

@Override
public boolean onLongClick(View v) {
if (v == mStatusBarPowerMenu) {
if (mStatusBarPowerMenuStyle == 1) {
triggerPowerMenuDialog();
} else if (mStatusBarPowerMenuStyle == 2) {
goToSleep();
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,9 @@ public void onDebug() {
if (!mPowerManager.isInteractive()) {
goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
}
// power menu register broadcast receiver for power menu intent
mPowerMenuReceiver = new PowerMenuReceiver(context);
mPowerMenuReceiver.registerSelf();
}

/**
Expand Down Expand Up @@ -6138,4 +6141,36 @@ public void dump(String prefix, PrintWriter pw, String[] args) {
mOrientationListener.dump(pw, prefix);
}
}

private PowerMenuReceiver mPowerMenuReceiver;
class PowerMenuReceiver extends BroadcastReceiver {
private boolean mIsRegistered = false;

public PowerMenuReceiver(Context context) {
}

@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_POWER_MENU)) {
showGlobalActionsInternal();
}
}

private void registerSelf() {
if (!mIsRegistered) {
mIsRegistered = true;
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_POWER_MENU);
mContext.registerReceiver(mPowerMenuReceiver, filter);
}
}

private void unregisterSelf() {
if (mIsRegistered) {
mIsRegistered = false;
mContext.unregisterReceiver(this);
}
}
}
}

0 comments on commit d764686

Please sign in to comment.