Skip to content

Commit 366f32c

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 366f32c

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-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: 38 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,10 @@ 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;
915925

916926
if (MULTIUSER_DEBUG) {
917927
mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info);
@@ -1480,6 +1490,10 @@ public void onClick(View v) {
14801490
}
14811491
};
14821492

1493+
private int getBottomGap() {
1494+
return mContext.getResources().getDimensionPixelSize(R.dimen.heads_up_bottom_gap);
1495+
}
1496+
14831497
private int mShowSearchHoldoff = 0;
14841498
private Runnable mShowSearchPanel = new Runnable() {
14851499
public void run() {
@@ -1611,8 +1625,9 @@ private void addHeadsUpView() {
16111625
if (ActivityManager.isHighEndGfx()) {
16121626
lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
16131627
}
1614-
lp.gravity = Gravity.TOP;
1615-
lp.y = getStatusBarHeight();
1628+
lp.gravity = mHeadsUpGravityBottom && !mImeIsShowing ? Gravity.BOTTOM : Gravity.TOP;
1629+
lp.y = mHeadsUpGravityBottom && !mImeIsShowing
1630+
? getBottomGap() : (mStatusBarShows ? getStatusBarHeight() : 0);
16161631
lp.setTitle("Heads Up");
16171632
lp.packageName = mContext.getPackageName();
16181633
lp.windowAnimations = R.style.Animation_StatusBar_HeadsUp;
@@ -1744,6 +1759,7 @@ public void hideHeadsUp() {
17441759

17451760
@Override // CommandQueue
17461761
public void updateHeadsUpPosition(boolean statusBarShows) {
1762+
mStatusBarShows = statusBarShows;
17471763
// Change y layoutparams of heads up view when statusbar
17481764
// visibility changes.
17491765
// ToDo: We may want to animate this in future in the rare
@@ -1755,9 +1771,13 @@ public void updateHeadsUpPosition(boolean statusBarShows) {
17551771
if (mHeadsUpNotificationView != null) {
17561772
WindowManager.LayoutParams lp = (WindowManager.LayoutParams)
17571773
mHeadsUpNotificationView.getLayoutParams();
1758-
lp.y = statusBarShows ? getStatusBarHeight() : 0;
1759-
mWindowManager.updateViewLayout(mHeadsUpNotificationView, lp);
1760-
}
1774+
if (lp != null) {
1775+
lp.gravity = mHeadsUpGravityBottom && !mImeIsShowing ? Gravity.BOTTOM : Gravity.TOP;
1776+
lp.y = mHeadsUpGravityBottom && !mImeIsShowing
1777+
? getBottomGap() : (mStatusBarShows ? getStatusBarHeight() : 0);
1778+
mWindowManager.updateViewLayout(mHeadsUpNotificationView, lp);
1779+
}
1780+
}
17611781
}
17621782

17631783
public void removeNotification(IBinder key) {
@@ -3142,6 +3162,12 @@ public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
31423162
boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS)
31433163
|| mImeShowing;
31443164

3165+
// If IME shows and heads up gravity is at the bottom, move it to the top.
3166+
if (mImeIsShowing != altBack) {
3167+
mImeIsShowing = altBack;
3168+
updateHeadsUpPosition(mStatusBarShows);
3169+
}
3170+
31453171
setNavigationIconHints(
31463172
altBack ? (mNavigationIconHints | NAVIGATION_HINT_BACK_ALT)
31473173
: (mNavigationIconHints & ~NAVIGATION_HINT_BACK_ALT));
@@ -4457,6 +4483,13 @@ public void onChange(boolean selfChange, Uri uri) {
44574483
mContext.getContentResolver(),
44584484
Settings.System.HEADS_UP_SHOW_UPDATE, 0,
44594485
UserHandle.USER_CURRENT) == 1;
4486+
} else if (uri.equals(Settings.System.getUriFor(
4487+
Settings.System.HEADS_UP_GRAVITY_BOTTOM))) {
4488+
mHeadsUpGravityBottom = Settings.System.getIntForUser(
4489+
mContext.getContentResolver(),
4490+
Settings.System.HEADS_UP_GRAVITY_BOTTOM, 0,
4491+
UserHandle.USER_CURRENT) == 1;
4492+
updateHeadsUpPosition(mStatusBarShows);
44604493
}
44614494
updateSettings();
44624495
}

0 commit comments

Comments
 (0)