FileDocCategorySizeDatePackage
HeadsUpNotificationView.javaAPI DocAndroid 5.1 API16875Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.policy

HeadsUpNotificationView

public class HeadsUpNotificationView extends android.widget.FrameLayout implements ViewTreeObserver.OnComputeInternalInsetsListener, ExpandHelper.Callback, SwipeHelper.Callback

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
SPEW
private static final String
SETTING_HEADS_UP_SNOOZE_LENGTH_MS
android.graphics.Rect
mTmpRect
int[]
mTmpTwoArray
private final int
mTouchSensitivityDelay
private final float
mMaxAlpha
private final android.util.ArrayMap
mSnoozedPackages
private final int
mDefaultSnoozeLengthMs
private com.android.systemui.SwipeHelper
mSwipeHelper
private EdgeSwipeHelper
mEdgeSwipeHelper
private com.android.systemui.statusbar.phone.PhoneStatusBar
mBar
private long
mStartTouchTime
private android.view.ViewGroup
mContentHolder
private int
mSnoozeLengthMs
private android.database.ContentObserver
mSettingsObserver
private NotificationData.Entry
mHeadsUp
private int
mUser
private String
mMostRecentPackageName
private static final android.view.ViewOutlineProvider
CONTENT_HOLDER_OUTLINE_PROVIDER
Constructors Summary
public HeadsUpNotificationView(android.content.Context context, android.util.AttributeSet attrs)


         
        this(context, attrs, 0);
    
public HeadsUpNotificationView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
        Resources resources = context.getResources();
        mTouchSensitivityDelay = resources.getInteger(R.integer.heads_up_sensitivity_delay);
        if (DEBUG) Log.v(TAG, "create() " + mTouchSensitivityDelay);
        mSnoozedPackages = new ArrayMap<>();
        mDefaultSnoozeLengthMs = resources.getInteger(R.integer.heads_up_default_snooze_length_ms);
        mSnoozeLengthMs = mDefaultSnoozeLengthMs;
    
Methods Summary
public booleancanChildBeDismissed(android.view.View v)

        return true;
    
public booleancanChildBeExpanded(android.view.View v)

        return mHeadsUp != null && mHeadsUp.row == v && mHeadsUp.row.isExpandable();
    
public voidclear()
Discard the Heads Up notification.

        mHeadsUp = null;
        mBar.scheduleHeadsUpClose();
    
public voiddismiss()
Respond to dismissal of the Heads Up window.

        if (mHeadsUp == null) return;
        if (mHeadsUp.notification.isClearable()) {
            mBar.onNotificationClear(mHeadsUp.notification);
        } else {
            release();
        }
        mHeadsUp = null;
        mBar.scheduleHeadsUpClose();
    
public voidescalate()

        mBar.scheduleHeadsUpEscalation();
    
public voidexpansionStateChanged(boolean isExpanding)


    
public com.android.systemui.statusbar.ExpandableViewgetChildAtPosition(float x, float y)

        return mHeadsUp == null ? null : mHeadsUp.row;
    
public android.view.ViewgetChildAtPosition(android.view.MotionEvent ev)

        return mContentHolder;
    
public com.android.systemui.statusbar.ExpandableViewgetChildAtRawPosition(float x, float y)

        return getChildAtPosition(x, y);
    
public android.view.ViewgetChildContentView(android.view.View v)

        return mContentHolder;
    
public NotificationData.EntrygetEntry()

        return mHeadsUp;
    
public floatgetFalsingThresholdFactor()

        return 1.0f;
    
public android.view.ViewGroupgetHolder()

        return mContentHolder;
    
public java.lang.StringgetKey()

        return mHeadsUp == null ? null : mHeadsUp.notification.getKey();
    
public booleanisAntiFalsingNeeded()

        return false;
    
public booleanisClearable()

        return mHeadsUp == null || mHeadsUp.notification.isClearable();
    
public booleanisShowing(java.lang.String key)

        return mHeadsUp != null && mHeadsUp.key.equals(key);
    
public booleanisSnoozed(java.lang.String packageName)

        final String key = snoozeKey(packageName, mUser);
        Long snoozedUntil = mSnoozedPackages.get(key);
        if (snoozedUntil != null) {
            if (snoozedUntil > SystemClock.elapsedRealtime()) {
                if (DEBUG) Log.v(TAG, key + " snoozed");
                return true;
            }
            mSnoozedPackages.remove(packageName);
        }
        return false;
    
public voidonAttachedToWindow()


    
       
        final ViewConfiguration viewConfiguration = ViewConfiguration.get(getContext());
        float touchSlop = viewConfiguration.getScaledTouchSlop();
        mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, getContext());
        mSwipeHelper.setMaxSwipeProgress(mMaxAlpha);
        mEdgeSwipeHelper = new EdgeSwipeHelper(touchSlop);

        int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height);
        int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height);

        mContentHolder = (ViewGroup) findViewById(R.id.content_holder);
        mContentHolder.setOutlineProvider(CONTENT_HOLDER_OUTLINE_PROVIDER);

        mSnoozeLengthMs = Settings.Global.getInt(mContext.getContentResolver(),
                SETTING_HEADS_UP_SNOOZE_LENGTH_MS, mDefaultSnoozeLengthMs);
        mSettingsObserver = new ContentObserver(getHandler()) {
            @Override
            public void onChange(boolean selfChange) {
                final int packageSnoozeLengthMs = Settings.Global.getInt(
                        mContext.getContentResolver(), SETTING_HEADS_UP_SNOOZE_LENGTH_MS, -1);
                if (packageSnoozeLengthMs > -1 && packageSnoozeLengthMs != mSnoozeLengthMs) {
                    mSnoozeLengthMs = packageSnoozeLengthMs;
                    if (DEBUG) Log.v(TAG, "mSnoozeLengthMs = " + mSnoozeLengthMs);
                }
            }
        };
        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(SETTING_HEADS_UP_SNOOZE_LENGTH_MS), false,
                mSettingsObserver);
        if (DEBUG) Log.v(TAG, "mSnoozeLengthMs = " + mSnoozeLengthMs);

        if (mHeadsUp != null) {
            // whoops, we're on already!
            showNotification(mHeadsUp);
        }

        getViewTreeObserver().addOnComputeInternalInsetsListener(this);
    
public voidonBeginDrag(android.view.View v)

    
public voidonChildDismissed(android.view.View v)

        Log.v(TAG, "User swiped heads up to dismiss");
        mBar.onHeadsUpDismissed();
    
public voidonChildSnappedBack(android.view.View animView)

    
public voidonComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo info)

        mContentHolder.getLocationOnScreen(mTmpTwoArray);

        info.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
        info.touchableRegion.set(mTmpTwoArray[0], mTmpTwoArray[1],
                mTmpTwoArray[0] + mContentHolder.getWidth(),
                mTmpTwoArray[1] + mContentHolder.getHeight());
    
protected voidonConfigurationChanged(android.content.res.Configuration newConfig)

        super.onConfigurationChanged(newConfig);
        float densityScale = getResources().getDisplayMetrics().density;
        mSwipeHelper.setDensityScale(densityScale);
        float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
        mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
    
protected voidonDetachedFromWindow()

        mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
    
public voidonDragCancelled(android.view.View v)

        mContentHolder.setAlpha(mMaxAlpha); // sometimes this isn't quite reset
    
public voidonDraw(android.graphics.Canvas c)

        super.onDraw(c);
        if (DEBUG) {
            //Log.d(TAG, "onDraw: canvas height: " + c.getHeight() + "px; measured height: "
            //        + getMeasuredHeight() + "px");
            c.save();
            c.clipRect(6, 6, c.getWidth() - 6, getMeasuredHeight() - 6,
                    android.graphics.Region.Op.DIFFERENCE);
            c.drawColor(0xFFcc00cc);
            c.restore();
        }
    
public booleanonInterceptTouchEvent(android.view.MotionEvent ev)

        if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
        if (SystemClock.elapsedRealtime() < mStartTouchTime) {
            return true;
        }
        return mEdgeSwipeHelper.onInterceptTouchEvent(ev)
                || mSwipeHelper.onInterceptTouchEvent(ev)
                || super.onInterceptTouchEvent(ev);
    
public booleanonTouchEvent(android.view.MotionEvent ev)

        if (SystemClock.elapsedRealtime() < mStartTouchTime) {
            return false;
        }
        mBar.resetHeadsUpDecayTimer();
        return mEdgeSwipeHelper.onTouchEvent(ev)
                || mSwipeHelper.onTouchEvent(ev)
                || super.onTouchEvent(ev);
    
protected voidonVisibilityChanged(android.view.View changedView, int visibility)

        super.onVisibilityChanged(changedView, visibility);
        if (changedView.getVisibility() == VISIBLE) {
            sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
        }
    
public voidrelease()
Push any current Heads Up notification down into the shade.

        if (mHeadsUp != null) {
            mBar.displayNotificationFromHeadsUp(mHeadsUp.notification);
        }
        mHeadsUp = null;
    
public voidreleaseAndClose()

        release();
        mBar.scheduleHeadsUpClose();
    
public voidsetBar(com.android.systemui.statusbar.phone.PhoneStatusBar bar)

        mBar = bar;
    
public voidsetUser(int user)

        mUser = user;
    
public voidsetUserExpandedChild(android.view.View v, boolean userExpanded)

        if (mHeadsUp != null && mHeadsUp.row == v) {
            mHeadsUp.row.setUserExpanded(userExpanded);
        }
    
public voidsetUserLockedChild(android.view.View v, boolean userLocked)

        if (mHeadsUp != null && mHeadsUp.row == v) {
            mHeadsUp.row.setUserLocked(userLocked);
        }
    
public booleanshowNotification(NotificationData.Entry headsUp)

        if (mHeadsUp != null && headsUp != null && !mHeadsUp.key.equals(headsUp.key)) {
            // bump any previous heads up back to the shade
            release();
        }

        mHeadsUp = headsUp;
        if (mContentHolder != null) {
            mContentHolder.removeAllViews();
        }

        if (mHeadsUp != null) {
            mMostRecentPackageName = mHeadsUp.notification.getPackageName();
            mHeadsUp.row.setSystemExpanded(true);
            mHeadsUp.row.setSensitive(false);
            mHeadsUp.row.setHeadsUp(true);
            mHeadsUp.row.setHideSensitive(
                    false, false /* animated */, 0 /* delay */, 0 /* duration */);
            if (mContentHolder == null) {
                // too soon!
                return false;
            }
            mContentHolder.setX(0);
            mContentHolder.setVisibility(View.VISIBLE);
            mContentHolder.setAlpha(mMaxAlpha);
            mContentHolder.addView(mHeadsUp.row);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);

            mSwipeHelper.snapChild(mContentHolder, 1f);
            mStartTouchTime = SystemClock.elapsedRealtime() + mTouchSensitivityDelay;

            mHeadsUp.setInterruption();

            // 2. Animate mHeadsUpNotificationView in
            mBar.scheduleHeadsUpOpen();

            // 3. Set alarm to age the notification off
            mBar.resetHeadsUpDecayTimer();
        }
        return true;
    
private voidsnooze()

        if (mMostRecentPackageName != null) {
            mSnoozedPackages.put(snoozeKey(mMostRecentPackageName, mUser),
                    SystemClock.elapsedRealtime() + mSnoozeLengthMs);
        }
        releaseAndClose();
    
private static java.lang.StringsnoozeKey(java.lang.String packageName, int user)

        return user + "," + packageName;
    
public voidupdateResources()

        if (mContentHolder != null) {
            final LayoutParams lp = (LayoutParams) mContentHolder.getLayoutParams();
            lp.width = getResources().getDimensionPixelSize(R.dimen.notification_panel_width);
            lp.gravity = getResources().getInteger(R.integer.notification_panel_layout_gravity);
            mContentHolder.setLayoutParams(lp);
        }
    
public booleanupdateSwipeProgress(android.view.View animView, boolean dismissable, float swipeProgress)

        getBackground().setAlpha((int) (255 * swipeProgress));
        return false;