FileDocCategorySizeDatePackage
KeyguardClockPositionAlgorithm.javaAPI DocAndroid 5.1 API8258Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.phone

KeyguardClockPositionAlgorithm

public class KeyguardClockPositionAlgorithm extends Object
Utility class to calculate the clock position and top padding of notifications on Keyguard.

Fields Summary
private static final float
SLOW_DOWN_FACTOR
private static final float
CLOCK_RUBBERBAND_FACTOR_MIN
private static final float
CLOCK_RUBBERBAND_FACTOR_MAX
private static final float
CLOCK_SCALE_FADE_START
private static final float
CLOCK_SCALE_FADE_END
private static final float
CLOCK_SCALE_FADE_END_NO_NOTIFS
private static final float
CLOCK_ADJ_TOP_PADDING_MULTIPLIER_MIN
private static final float
CLOCK_ADJ_TOP_PADDING_MULTIPLIER_MAX
private int
mClockNotificationsMarginMin
private int
mClockNotificationsMarginMax
private float
mClockYFractionMin
private float
mClockYFractionMax
private int
mMaxKeyguardNotifications
private int
mMaxPanelHeight
private float
mExpandedHeight
private int
mNotificationCount
private int
mHeight
private int
mKeyguardStatusHeight
private float
mEmptyDragAmount
private float
mDensity
private float
mMoreCardNotificationAmount
The number (fractional) of notifications the "more" card counts when calculating how many notifications are currently visible for the y positioning of the clock.
private static final android.view.animation.PathInterpolator
sSlowDownInterpolator
private android.view.animation.AccelerateInterpolator
mAccelerateInterpolator
Constructors Summary
Methods Summary
private floatgetClockAlpha(float scale)

        float fadeEnd = getNotificationAmountT() == 0.0f
                ? CLOCK_SCALE_FADE_END_NO_NOTIFS
                : CLOCK_SCALE_FADE_END;
        float alpha = (scale - fadeEnd)
                / (CLOCK_SCALE_FADE_START - fadeEnd);
        return Math.max(0, Math.min(1, alpha));
    
private intgetClockNotificationsPadding()

        float t = getNotificationAmountT();
        t = Math.min(t, 1.0f);
        return (int) (t * mClockNotificationsMarginMin + (1 - t) * mClockNotificationsMarginMax);
    
private floatgetClockScale(int notificationPadding, int clockY, int startPadding)

        float scaleMultiplier = getNotificationAmountT() == 0 ? 6.0f : 5.0f;
        float scaleEnd = clockY - mKeyguardStatusHeight * scaleMultiplier;
        float distanceToScaleEnd = notificationPadding - scaleEnd;
        float progress = distanceToScaleEnd / (startPadding - scaleEnd);
        progress = Math.max(0.0f, Math.min(progress, 1.0f));
        progress = mAccelerateInterpolator.getInterpolation(progress);
        progress *= Math.pow(1 + mEmptyDragAmount / mDensity / 300, 0.3f);
        return progress;
    
private intgetClockY()

        return (int) (getClockYFraction() * mHeight);
    
private floatgetClockYExpansionAdjustment()

        float rubberbandFactor = getClockYExpansionRubberbandFactor();
        float value = (rubberbandFactor * (mMaxPanelHeight - mExpandedHeight));
        float t = value / mMaxPanelHeight;
        float slowedDownValue = -sSlowDownInterpolator.getInterpolation(t) * SLOW_DOWN_FACTOR
                * mMaxPanelHeight;
        if (mNotificationCount == 0) {
            return (-2*value + slowedDownValue)/3;
        } else {
            return slowedDownValue;
        }
    
private floatgetClockYExpansionRubberbandFactor()

        float t = getNotificationAmountT();
        t = Math.min(t, 1.0f);
        t = (float) Math.pow(t, 0.3f);
        return (1 - t) * CLOCK_RUBBERBAND_FACTOR_MAX + t * CLOCK_RUBBERBAND_FACTOR_MIN;
    
private floatgetClockYFraction()

        float t = getNotificationAmountT();
        t = Math.min(t, 1.0f);
        return (1 - t) * mClockYFractionMax + t * mClockYFractionMin;
    
private floatgetNotificationAmountT()

return
a value from 0 to 1 depending on how many notification there are

        return mNotificationCount
                / (mMaxKeyguardNotifications + mMoreCardNotificationAmount);
    
private floatgetTopPaddingAdjMultiplier()

        float t = getNotificationAmountT();
        t = Math.min(t, 1.0f);
        return (1 - t) * CLOCK_ADJ_TOP_PADDING_MULTIPLIER_MIN
                + t * CLOCK_ADJ_TOP_PADDING_MULTIPLIER_MAX;
    
public voidloadDimens(android.content.res.Resources res)
Refreshes the dimension values.


             
        
        mClockNotificationsMarginMin = res.getDimensionPixelSize(
                R.dimen.keyguard_clock_notifications_margin_min);
        mClockNotificationsMarginMax = res.getDimensionPixelSize(
                R.dimen.keyguard_clock_notifications_margin_max);
        mClockYFractionMin = res.getFraction(R.fraction.keyguard_clock_y_fraction_min, 1, 1);
        mClockYFractionMax = res.getFraction(R.fraction.keyguard_clock_y_fraction_max, 1, 1);
        mMoreCardNotificationAmount =
                (float) res.getDimensionPixelSize(R.dimen.notification_summary_height) /
                        res.getDimensionPixelSize(R.dimen.notification_min_height);
        mDensity = res.getDisplayMetrics().density;
    
public voidrun(com.android.systemui.statusbar.phone.KeyguardClockPositionAlgorithm$Result result)

        int y = getClockY() - mKeyguardStatusHeight / 2;
        float clockAdjustment = getClockYExpansionAdjustment();
        float topPaddingAdjMultiplier = getTopPaddingAdjMultiplier();
        result.stackScrollerPaddingAdjustment = (int) (clockAdjustment*topPaddingAdjMultiplier);
        int clockNotificationsPadding = getClockNotificationsPadding()
                + result.stackScrollerPaddingAdjustment;
        int padding = y + clockNotificationsPadding;
        result.clockY = y;
        result.stackScrollerPadding = mKeyguardStatusHeight + padding;
        result.clockScale = getClockScale(result.stackScrollerPadding,
                result.clockY,
                y + getClockNotificationsPadding() + mKeyguardStatusHeight);
        result.clockAlpha = getClockAlpha(result.clockScale);
    
public voidsetup(int maxKeyguardNotifications, int maxPanelHeight, float expandedHeight, int notificationCount, int height, int keyguardStatusHeight, float emptyDragAmount)

        mMaxKeyguardNotifications = maxKeyguardNotifications;
        mMaxPanelHeight = maxPanelHeight;
        mExpandedHeight = expandedHeight;
        mNotificationCount = notificationCount;
        mHeight = height;
        mKeyguardStatusHeight = keyguardStatusHeight;
        mEmptyDragAmount = emptyDragAmount;