Skip to content

Commit 18d0cdd

Browse files
kufikugelcodex-corp
authored andcommitted
fb: Show heads up at the bottom of the screen (1/2)
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.
1 parent c7b1217 commit 18d0cdd

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

core/java/android/provider/Settings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,6 +4641,13 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
46414641
*/
46424642
public static final String APP_SIDEBAR_SHOW_TRIGGER = "app_sidebar_show_trigger";
46434643

4644+
/**
4645+
* Whether heads up notification is shown on the bottom of the screen (default = disabled)
4646+
*
4647+
* @hide
4648+
*/
4649+
public static final String HEADS_UP_GRAVITY_BOTTOM = "heads_up_gravity_bottom";
4650+
46444651
/**
46454652
* Whether heads up notification is expanded by default (default = disabled)
46464653
*

packages/SystemUI/res/values/probam_dimens.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,7 @@
132132

133133
<!-- Weather -->
134134
<dimen name="weather_text_margin">56dp</dimen>
135+
136+
<!-- Heads up -->
137+
<dimen name="heads_up_bottom_gap">5dp</dimen>
135138
</resources>

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
330330
private int mHeadsUpNotificationDecay;
331331
private boolean mHeadsUpExpandedByDefault;
332332
private boolean mHeadsUpNotificationViewAttached;
333+
private boolean mHeadsUpGravityBottom;
334+
private boolean mStatusBarShows = true;
335+
private boolean mImeIsShowing;
333336

334337
// on-screen navigation buttons
335338
private NavigationBarView mNavigationBarView = null;
@@ -472,6 +475,9 @@ void observe() {
472475
resolver.registerContentObserver(Settings.System.getUriFor(
473476
Settings.System.HEADS_UP_SHOW_UPDATE), false, this,
474477
UserHandle.USER_ALL);
478+
resolver.registerContentObserver(Settings.System.getUriFor(
479+
Settings.System.HEADS_UP_GRAVITY_BOTTOM), false, this,
480+
UserHandle.USER_ALL);
475481

476482
updateSettings();
477483
}
@@ -912,6 +918,14 @@ public boolean onTouch(View v, MotionEvent event) {
912918
mContext.getContentResolver(),
913919
Settings.System.HEADS_UP_SHOW_UPDATE, 0,
914920
UserHandle.USER_CURRENT) == 1;
921+
mHeadsUpGravityBottom = Settings.System.getIntForUser(
922+
mContext.getContentResolver(),
923+
Settings.System.HEADS_UP_GRAVITY_BOTTOM, 0,
924+
UserHandle.USER_CURRENT) == 1;
925+
mHeadsUpGravityBottom = Settings.System.getIntForUser(
926+
mContext.getContentResolver(),
927+
Settings.System.HEADS_UP_GRAVITY_BOTTOM, 0,
928+
UserHandle.USER_CURRENT) == 1;
915929

916930
if (MULTIUSER_DEBUG) {
917931
mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info);
@@ -1480,6 +1494,10 @@ public void onClick(View v) {
14801494
}
14811495
};
14821496

1497+
private int getBottomGap() {
1498+
return mContext.getResources().getDimensionPixelSize(R.dimen.heads_up_bottom_gap);
1499+
}
1500+
14831501
private int mShowSearchHoldoff = 0;
14841502
private Runnable mShowSearchPanel = new Runnable() {
14851503
public void run() {
@@ -1611,8 +1629,9 @@ private void addHeadsUpView() {
16111629
if (ActivityManager.isHighEndGfx()) {
16121630
lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
16131631
}
1614-
lp.gravity = Gravity.TOP;
1615-
lp.y = getStatusBarHeight();
1632+
lp.gravity = mHeadsUpGravityBottom && !mImeIsShowing ? Gravity.BOTTOM : Gravity.TOP;
1633+
lp.y = mHeadsUpGravityBottom && !mImeIsShowing
1634+
? getBottomGap() : (mStatusBarShows ? getStatusBarHeight() : 0);
16161635
lp.setTitle("Heads Up");
16171636
lp.packageName = mContext.getPackageName();
16181637
lp.windowAnimations = R.style.Animation_StatusBar_HeadsUp;
@@ -1744,6 +1763,7 @@ public void hideHeadsUp() {
17441763

17451764
@Override // CommandQueue
17461765
public void updateHeadsUpPosition(boolean statusBarShows) {
1766+
mStatusBarShows = statusBarShows;
17471767
// Change y layoutparams of heads up view when statusbar
17481768
// visibility changes.
17491769
// ToDo: We may want to animate this in future in the rare
@@ -1755,9 +1775,13 @@ public void updateHeadsUpPosition(boolean statusBarShows) {
17551775
if (mHeadsUpNotificationView != null) {
17561776
WindowManager.LayoutParams lp = (WindowManager.LayoutParams)
17571777
mHeadsUpNotificationView.getLayoutParams();
1758-
lp.y = statusBarShows ? getStatusBarHeight() : 0;
1759-
mWindowManager.updateViewLayout(mHeadsUpNotificationView, lp);
1760-
}
1778+
if (lp != null) {
1779+
lp.gravity = mHeadsUpGravityBottom && !mImeIsShowing ? Gravity.BOTTOM : Gravity.TOP;
1780+
lp.y = mHeadsUpGravityBottom && !mImeIsShowing
1781+
? getBottomGap() : (mStatusBarShows ? getStatusBarHeight() : 0);
1782+
mWindowManager.updateViewLayout(mHeadsUpNotificationView, lp);
1783+
}
1784+
}
17611785
}
17621786

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

3169+
// If IME shows and heads up gravity is at the bottom, move it to the top.
3170+
if (mImeIsShowing != altBack) {
3171+
mImeIsShowing = altBack;
3172+
updateHeadsUpPosition(mStatusBarShows);
3173+
}
3174+
31453175
setNavigationIconHints(
31463176
altBack ? (mNavigationIconHints | NAVIGATION_HINT_BACK_ALT)
31473177
: (mNavigationIconHints & ~NAVIGATION_HINT_BACK_ALT));
@@ -4457,6 +4487,13 @@ public void onChange(boolean selfChange, Uri uri) {
44574487
mContext.getContentResolver(),
44584488
Settings.System.HEADS_UP_SHOW_UPDATE, 0,
44594489
UserHandle.USER_CURRENT) == 1;
4490+
} else if (uri.equals(Settings.System.getUriFor(
4491+
Settings.System.HEADS_UP_GRAVITY_BOTTOM))) {
4492+
mHeadsUpGravityBottom = Settings.System.getIntForUser(
4493+
mContext.getContentResolver(),
4494+
Settings.System.HEADS_UP_GRAVITY_BOTTOM, 0,
4495+
UserHandle.USER_CURRENT) == 1;
4496+
updateHeadsUpPosition(mStatusBarShows);
44604497
}
44614498
updateSettings();
44624499
}

0 commit comments

Comments
 (0)