Skip to content

Commit

Permalink
fb: Show heads up at the bottom of the screen (1/2)
Browse files Browse the repository at this point in the history
Due of user requests and indeed especially on hw key devices for a better
workflow we add an option to show heads up notifications on the bottom instead
of the top.

Animation we leave as is due that if it slide from the bottom into the screen it happens
to often that the user accidentaly interacts with it. If it comes from the top of the
container we add, the user has enough time to realize it. Sometimes a ms can make a big difference.

As well this commit fixes the wrong gap on the top if user boots up directly
into immersive mode.

PS:
- if IME keyboard is showing show the heads up on the top to do not disturb the typing.
PS:
- NPE if updatePosition is called to early from the system.
  • Loading branch information
kufikugel authored and codex-corp committed Sep 5, 2014
1 parent c7b1217 commit 18d0cdd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
7 changes: 7 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4641,6 +4641,13 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
*/
public static final String APP_SIDEBAR_SHOW_TRIGGER = "app_sidebar_show_trigger";

/**
* Whether heads up notification is shown on the bottom of the screen (default = disabled)
*
* @hide
*/
public static final String HEADS_UP_GRAVITY_BOTTOM = "heads_up_gravity_bottom";

/**
* Whether heads up notification is expanded by default (default = disabled)
*
Expand Down
3 changes: 3 additions & 0 deletions packages/SystemUI/res/values/probam_dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@

<!-- Weather -->
<dimen name="weather_text_margin">56dp</dimen>

<!-- Heads up -->
<dimen name="heads_up_bottom_gap">5dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
private int mHeadsUpNotificationDecay;
private boolean mHeadsUpExpandedByDefault;
private boolean mHeadsUpNotificationViewAttached;
private boolean mHeadsUpGravityBottom;
private boolean mStatusBarShows = true;
private boolean mImeIsShowing;

// on-screen navigation buttons
private NavigationBarView mNavigationBarView = null;
Expand Down Expand Up @@ -472,6 +475,9 @@ void observe() {
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.HEADS_UP_SHOW_UPDATE), false, this,
UserHandle.USER_ALL);
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.HEADS_UP_GRAVITY_BOTTOM), false, this,
UserHandle.USER_ALL);

updateSettings();
}
Expand Down Expand Up @@ -912,6 +918,14 @@ public boolean onTouch(View v, MotionEvent event) {
mContext.getContentResolver(),
Settings.System.HEADS_UP_SHOW_UPDATE, 0,
UserHandle.USER_CURRENT) == 1;
mHeadsUpGravityBottom = Settings.System.getIntForUser(
mContext.getContentResolver(),
Settings.System.HEADS_UP_GRAVITY_BOTTOM, 0,
UserHandle.USER_CURRENT) == 1;
mHeadsUpGravityBottom = Settings.System.getIntForUser(
mContext.getContentResolver(),
Settings.System.HEADS_UP_GRAVITY_BOTTOM, 0,
UserHandle.USER_CURRENT) == 1;

if (MULTIUSER_DEBUG) {
mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info);
Expand Down Expand Up @@ -1480,6 +1494,10 @@ public void onClick(View v) {
}
};

private int getBottomGap() {
return mContext.getResources().getDimensionPixelSize(R.dimen.heads_up_bottom_gap);
}

private int mShowSearchHoldoff = 0;
private Runnable mShowSearchPanel = new Runnable() {
public void run() {
Expand Down Expand Up @@ -1611,8 +1629,9 @@ private void addHeadsUpView() {
if (ActivityManager.isHighEndGfx()) {
lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
}
lp.gravity = Gravity.TOP;
lp.y = getStatusBarHeight();
lp.gravity = mHeadsUpGravityBottom && !mImeIsShowing ? Gravity.BOTTOM : Gravity.TOP;
lp.y = mHeadsUpGravityBottom && !mImeIsShowing
? getBottomGap() : (mStatusBarShows ? getStatusBarHeight() : 0);
lp.setTitle("Heads Up");
lp.packageName = mContext.getPackageName();
lp.windowAnimations = R.style.Animation_StatusBar_HeadsUp;
Expand Down Expand Up @@ -1744,6 +1763,7 @@ public void hideHeadsUp() {

@Override // CommandQueue
public void updateHeadsUpPosition(boolean statusBarShows) {
mStatusBarShows = statusBarShows;
// Change y layoutparams of heads up view when statusbar
// visibility changes.
// ToDo: We may want to animate this in future in the rare
Expand All @@ -1755,9 +1775,13 @@ public void updateHeadsUpPosition(boolean statusBarShows) {
if (mHeadsUpNotificationView != null) {
WindowManager.LayoutParams lp = (WindowManager.LayoutParams)
mHeadsUpNotificationView.getLayoutParams();
lp.y = statusBarShows ? getStatusBarHeight() : 0;
mWindowManager.updateViewLayout(mHeadsUpNotificationView, lp);
}
if (lp != null) {
lp.gravity = mHeadsUpGravityBottom && !mImeIsShowing ? Gravity.BOTTOM : Gravity.TOP;
lp.y = mHeadsUpGravityBottom && !mImeIsShowing
? getBottomGap() : (mStatusBarShows ? getStatusBarHeight() : 0);
mWindowManager.updateViewLayout(mHeadsUpNotificationView, lp);
}
}
}

public void removeNotification(IBinder key) {
Expand Down Expand Up @@ -3142,6 +3166,12 @@ public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS)
|| mImeShowing;

// If IME shows and heads up gravity is at the bottom, move it to the top.
if (mImeIsShowing != altBack) {
mImeIsShowing = altBack;
updateHeadsUpPosition(mStatusBarShows);
}

setNavigationIconHints(
altBack ? (mNavigationIconHints | NAVIGATION_HINT_BACK_ALT)
: (mNavigationIconHints & ~NAVIGATION_HINT_BACK_ALT));
Expand Down Expand Up @@ -4457,6 +4487,13 @@ public void onChange(boolean selfChange, Uri uri) {
mContext.getContentResolver(),
Settings.System.HEADS_UP_SHOW_UPDATE, 0,
UserHandle.USER_CURRENT) == 1;
} else if (uri.equals(Settings.System.getUriFor(
Settings.System.HEADS_UP_GRAVITY_BOTTOM))) {
mHeadsUpGravityBottom = Settings.System.getIntForUser(
mContext.getContentResolver(),
Settings.System.HEADS_UP_GRAVITY_BOTTOM, 0,
UserHandle.USER_CURRENT) == 1;
updateHeadsUpPosition(mStatusBarShows);
}
updateSettings();
}
Expand Down

0 comments on commit 18d0cdd

Please sign in to comment.