Merge "Notifications now support runtime density changes" into nyc-dev

This commit is contained in:
Selim Cinek
2016-02-11 04:45:48 +00:00
committed by Android (Google) Code Review
5 changed files with 122 additions and 31 deletions

View File

@@ -194,6 +194,7 @@ public abstract class BaseStatusBar extends SystemUI implements
private final SparseBooleanArray mUsersAllowingPrivateNotifications = new SparseBooleanArray();
private UserManager mUserManager;
private int mDensity;
// UI-specific methods
@@ -633,6 +634,7 @@ public abstract class BaseStatusBar extends SystemUI implements
mLocale = currentConfig.locale;
mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale);
mFontScale = currentConfig.fontScale;
mDensity = currentConfig.densityDpi;
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
@@ -813,8 +815,13 @@ public abstract class BaseStatusBar extends SystemUI implements
final Locale locale = mContext.getResources().getConfiguration().locale;
final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
final float fontScale = newConfig.fontScale;
if (! locale.equals(mLocale) || ld != mLayoutDirection || fontScale != mFontScale) {
final int density = newConfig.densityDpi;
if (density != mDensity || mFontScale != fontScale) {
reInflateViews();
mDensity = density;
mFontScale = fontScale;
}
if (! locale.equals(mLocale) || ld != mLayoutDirection) {
if (DEBUG) {
Log.v(TAG, String.format(
"config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
@@ -826,6 +833,21 @@ public abstract class BaseStatusBar extends SystemUI implements
}
}
protected void reInflateViews() {
ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications();
for (int i = 0; i < activeNotifications.size(); i++) {
Entry entry = activeNotifications.get(i);
boolean exposedGuts = entry.row.getGuts() == mNotificationGutsExposed;
entry.row.reInflateViews();
if (exposedGuts) {
mNotificationGutsExposed = entry.row.getGuts();
bindGuts(entry.row);
}
entry.cacheContentViews(mContext, null /* updatedNotification */);
inflateViews(entry, mStackScroller);
}
}
protected View bindVetoButtonClickListener(View row, StatusBarNotification n) {
View vetoButton = row.findViewById(R.id.veto);
final String _pkg = n.getPackageName();

View File

@@ -25,6 +25,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.service.notification.StatusBarNotification;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.NotificationHeaderView;
import android.view.View;
@@ -50,11 +51,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
private static final int COLORED_DIVIDER_ALPHA = 0x7B;
private final int mNotificationMinHeightLegacy;
private final int mMaxHeadsUpHeightLegacy;
private final int mMaxHeadsUpHeight;
private final int mNotificationMinHeight;
private final int mNotificationMaxHeight;
private int mNotificationMinHeightLegacy;
private int mMaxHeadsUpHeightLegacy;
private int mMaxHeadsUpHeight;
private int mNotificationMinHeight;
private int mNotificationMaxHeight;
/** Does this row contain layouts that can adapt to row expansion */
private boolean mExpandable;
@@ -507,6 +508,27 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
mHeadsUpManager = headsUpManager;
}
public void reInflateViews() {
initDimens();
if (mIsSummaryWithChildren) {
removeView(mNotificationHeader);
mNotificationHeader = null;
recreateNotificationHeader();
if (mChildrenContainer != null) {
mChildrenContainer.reInflateViews();
}
}
if (mGuts != null) {
View oldGuts = mGuts;
int index = indexOfChild(oldGuts);
removeView(oldGuts);
mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
R.layout.notification_guts, this, false);
mGuts.setVisibility(oldGuts.getVisibility());
addView(mGuts, index);
}
}
public interface ExpansionLogger {
public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
}
@@ -514,6 +536,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
public ExpandableNotificationRow(Context context, AttributeSet attrs) {
super(context, attrs);
mFalsingManager = FalsingManager.getInstance(context);
initDimens();
}
private void initDimens() {
mNotificationMinHeightLegacy = getResources().getDimensionPixelSize(
R.dimen.notification_min_height_legacy);
mNotificationMinHeight = getResources().getDimensionPixelSize(

View File

@@ -754,19 +754,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mStackScroller.setOverflowContainer(mKeyguardIconOverflowContainer);
mEmptyShadeView = (EmptyShadeView) LayoutInflater.from(mContext).inflate(
R.layout.status_bar_no_notifications, mStackScroller, false);
mStackScroller.setEmptyShadeView(mEmptyShadeView);
mDismissView = (DismissView) LayoutInflater.from(mContext).inflate(
R.layout.status_bar_notification_dismiss_all, mStackScroller, false);
mDismissView.setOnButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MetricsLogger.action(mContext, MetricsEvent.ACTION_DISMISS_ALL_NOTES);
clearAllNotifications();
}
});
mStackScroller.setDismissView(mDismissView);
inflateEmptyShadeView();
inflateDismissView();
mExpandedContents = mStackScroller;
mBackdrop = (BackDropView) mStatusBarWindow.findViewById(R.id.backdrop);
@@ -930,6 +919,34 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
return mStatusBarView;
}
@Override
protected void reInflateViews() {
super.reInflateViews();
inflateDismissView();
updateClearAll();
inflateEmptyShadeView();
updateEmptyShadeView();
}
private void inflateEmptyShadeView() {
mEmptyShadeView = (EmptyShadeView) LayoutInflater.from(mContext).inflate(
R.layout.status_bar_no_notifications, mStackScroller, false);
mStackScroller.setEmptyShadeView(mEmptyShadeView);
}
private void inflateDismissView() {
mDismissView = (DismissView) LayoutInflater.from(mContext).inflate(
R.layout.status_bar_notification_dismiss_all, mStackScroller, false);
mDismissView.setOnButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MetricsLogger.action(mContext, MetricsEvent.ACTION_DISMISS_ALL_NOTES);
clearAllNotifications();
}
});
mStackScroller.setDismissView(mDismissView);
}
protected void createUserSwitcher() {
mKeyguardUserSwitcher = new KeyguardUserSwitcher(mContext,
(ViewStub) mStatusBarWindow.findViewById(R.id.keyguard_user_switcher),

View File

@@ -43,16 +43,16 @@ public class NotificationChildrenContainer extends ViewGroup {
private static final int NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED = 5;
private static final int NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED = 8;
private final int mChildPadding;
private final int mDividerHeight;
private final int mMaxNotificationHeight;
private final List<View> mDividers = new ArrayList<>();
private final List<ExpandableNotificationRow> mChildren = new ArrayList<>();
private final int mNotificationHeaderHeight;
private final int mNotificationAppearDistance;
private final int mNotificatonTopPadding;
private final HybridNotificationViewManager mHybridViewManager;
private final float mCollapsedBottompadding;
private int mChildPadding;
private int mDividerHeight;
private int mMaxNotificationHeight;
private int mNotificationHeaderHeight;
private int mNotificationAppearDistance;
private int mNotificatonTopPadding;
private float mCollapsedBottompadding;
private ViewInvertHelper mOverflowInvertHelper;
private boolean mChildrenExpanded;
private ExpandableNotificationRow mNotificationParent;
@@ -76,6 +76,11 @@ public class NotificationChildrenContainer extends ViewGroup {
public NotificationChildrenContainer(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initDimens();
mHybridViewManager = new HybridNotificationViewManager(getContext(), this);
}
private void initDimens() {
mChildPadding = getResources().getDimensionPixelSize(
R.dimen.notification_children_padding);
mDividerHeight = Math.max(1, getResources().getDimensionPixelSize(
@@ -89,7 +94,6 @@ public class NotificationChildrenContainer extends ViewGroup {
mNotificatonTopPadding = getResources().getDimensionPixelSize(
R.dimen.notification_children_container_top_padding);
mCollapsedBottompadding = 11.5f * getResources().getDisplayMetrics().density;
mHybridViewManager = new HybridNotificationViewManager(getContext(), this);
}
@Override
@@ -461,4 +465,16 @@ public class NotificationChildrenContainer extends ViewGroup {
mOverflowInvertHelper.setInverted(dark, fade, delay);
}
}
public void reInflateViews() {
initDimens();
for (int i = 0; i < mDividers.size(); i++) {
View prevDivider = mDividers.get(i);
int index = indexOfChild(prevDivider);
removeView(prevDivider);
View divider = inflateDivider();
addView(divider, index);
mDividers.set(i, divider);
}
}
}

View File

@@ -2138,7 +2138,7 @@ public class NotificationStackScrollLayout extends ViewGroup
}
private void updateAnimationState(View child) {
updateAnimationState((mAnimationsEnabled || isPinnedHeadsUp(child)) && mIsExpanded, child);
updateAnimationState(mAnimationsEnabled && (mIsExpanded || isPinnedHeadsUp(child)), child);
}
@@ -2874,13 +2874,23 @@ public class NotificationStackScrollLayout extends ViewGroup
}
public void setDismissView(DismissView dismissView) {
int index = -1;
if (mDismissView != null) {
index = indexOfChild(mDismissView);
removeView(mDismissView);
}
mDismissView = dismissView;
addView(mDismissView);
addView(mDismissView, index);
}
public void setEmptyShadeView(EmptyShadeView emptyShadeView) {
int index = -1;
if (mEmptyShadeView != null) {
index = indexOfChild(mEmptyShadeView);
removeView(mEmptyShadeView);
}
mEmptyShadeView = emptyShadeView;
addView(mEmptyShadeView);
addView(mEmptyShadeView, index);
}
public void updateEmptyShadeView(boolean visible) {