Home | History | Annotate | Download | only in stack
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.systemui.statusbar.stack;
     18 
     19 import android.content.Context;
     20 import android.view.View;
     21 
     22 import com.android.systemui.R;
     23 import com.android.systemui.statusbar.ActivatableNotificationView;
     24 import com.android.systemui.statusbar.NotificationShelf;
     25 import com.android.systemui.statusbar.StatusBarState;
     26 import com.android.systemui.statusbar.policy.HeadsUpManager;
     27 
     28 import java.util.ArrayList;
     29 
     30 /**
     31  * A global state to track all input states for the algorithm.
     32  */
     33 public class AmbientState {
     34     private ArrayList<View> mDraggedViews = new ArrayList<View>();
     35     private int mScrollY;
     36     private boolean mDimmed;
     37     private ActivatableNotificationView mActivatedChild;
     38     private float mOverScrollTopAmount;
     39     private float mOverScrollBottomAmount;
     40     private int mSpeedBumpIndex = -1;
     41     private boolean mDark;
     42     private boolean mHideSensitive;
     43     private HeadsUpManager mHeadsUpManager;
     44     private float mStackTranslation;
     45     private int mLayoutHeight;
     46     private int mTopPadding;
     47     private boolean mShadeExpanded;
     48     private float mMaxHeadsUpTranslation;
     49     private boolean mDismissAllInProgress;
     50     private int mLayoutMinHeight;
     51     private NotificationShelf mShelf;
     52     private int mZDistanceBetweenElements;
     53     private int mBaseZHeight;
     54     private int mMaxLayoutHeight;
     55     private ActivatableNotificationView mLastVisibleBackgroundChild;
     56     private float mCurrentScrollVelocity;
     57     private int mStatusBarState;
     58     private float mExpandingVelocity;
     59     private boolean mPanelTracking;
     60     private boolean mExpansionChanging;
     61     private boolean mPanelFullWidth;
     62     private boolean mHasPulsingNotifications;
     63     private boolean mUnlockHintRunning;
     64 
     65     public AmbientState(Context context) {
     66         reload(context);
     67     }
     68 
     69     /**
     70      * Reload the dimens e.g. if the density changed.
     71      */
     72     public void reload(Context context) {
     73         mZDistanceBetweenElements = Math.max(1, context.getResources()
     74                 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
     75         mBaseZHeight = 4 * mZDistanceBetweenElements;
     76     }
     77 
     78     /**
     79      * @return the basic Z height on which notifications remain.
     80      */
     81     public int getBaseZHeight() {
     82         return mBaseZHeight;
     83     }
     84 
     85     /**
     86      * @return the distance in Z between two overlaying notifications.
     87      */
     88     public int getZDistanceBetweenElements() {
     89         return mZDistanceBetweenElements;
     90     }
     91 
     92     public int getScrollY() {
     93         return mScrollY;
     94     }
     95 
     96     public void setScrollY(int scrollY) {
     97         this.mScrollY = scrollY;
     98     }
     99 
    100     public void onBeginDrag(View view) {
    101         mDraggedViews.add(view);
    102     }
    103 
    104     public void onDragFinished(View view) {
    105         mDraggedViews.remove(view);
    106     }
    107 
    108     public ArrayList<View> getDraggedViews() {
    109         return mDraggedViews;
    110     }
    111 
    112     /**
    113      * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
    114      *               translucent and everything is scaled back a bit.
    115      */
    116     public void setDimmed(boolean dimmed) {
    117         mDimmed = dimmed;
    118     }
    119 
    120     /** In dark mode, we draw as little as possible, assuming a black background */
    121     public void setDark(boolean dark) {
    122         mDark = dark;
    123     }
    124 
    125     public void setHideSensitive(boolean hideSensitive) {
    126         mHideSensitive = hideSensitive;
    127     }
    128 
    129     /**
    130      * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
    131      * interaction. This child is then scaled normally and its background is fully opaque.
    132      */
    133     public void setActivatedChild(ActivatableNotificationView activatedChild) {
    134         mActivatedChild = activatedChild;
    135     }
    136 
    137     public boolean isDimmed() {
    138         return mDimmed;
    139     }
    140 
    141     public boolean isDark() {
    142         return mDark;
    143     }
    144 
    145     public boolean isHideSensitive() {
    146         return mHideSensitive;
    147     }
    148 
    149     public ActivatableNotificationView getActivatedChild() {
    150         return mActivatedChild;
    151     }
    152 
    153     public void setOverScrollAmount(float amount, boolean onTop) {
    154         if (onTop) {
    155             mOverScrollTopAmount = amount;
    156         } else {
    157             mOverScrollBottomAmount = amount;
    158         }
    159     }
    160 
    161     public float getOverScrollAmount(boolean top) {
    162         return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
    163     }
    164 
    165     public int getSpeedBumpIndex() {
    166         return mSpeedBumpIndex;
    167     }
    168 
    169     public void setSpeedBumpIndex(int shelfIndex) {
    170         mSpeedBumpIndex = shelfIndex;
    171     }
    172 
    173     public void setHeadsUpManager(HeadsUpManager headsUpManager) {
    174         mHeadsUpManager = headsUpManager;
    175     }
    176 
    177     public float getStackTranslation() {
    178         return mStackTranslation;
    179     }
    180 
    181     public void setStackTranslation(float stackTranslation) {
    182         mStackTranslation = stackTranslation;
    183     }
    184 
    185     public void setLayoutHeight(int layoutHeight) {
    186         mLayoutHeight = layoutHeight;
    187     }
    188 
    189     public float getTopPadding() {
    190         return mTopPadding;
    191     }
    192 
    193     public void setTopPadding(int topPadding) {
    194         mTopPadding = topPadding;
    195     }
    196 
    197     public int getInnerHeight() {
    198         return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
    199     }
    200 
    201     public boolean isShadeExpanded() {
    202         return mShadeExpanded;
    203     }
    204 
    205     public void setShadeExpanded(boolean shadeExpanded) {
    206         mShadeExpanded = shadeExpanded;
    207     }
    208 
    209     public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
    210         mMaxHeadsUpTranslation = maxHeadsUpTranslation;
    211     }
    212 
    213     public float getMaxHeadsUpTranslation() {
    214         return mMaxHeadsUpTranslation;
    215     }
    216 
    217     public void setDismissAllInProgress(boolean dismissAllInProgress) {
    218         mDismissAllInProgress = dismissAllInProgress;
    219     }
    220 
    221     public boolean isDismissAllInProgress() {
    222         return mDismissAllInProgress;
    223     }
    224 
    225     public void setLayoutMinHeight(int layoutMinHeight) {
    226         mLayoutMinHeight = layoutMinHeight;
    227     }
    228 
    229     public void setShelf(NotificationShelf shelf) {
    230         mShelf = shelf;
    231     }
    232 
    233     public NotificationShelf getShelf() {
    234         return mShelf;
    235     }
    236 
    237     public void setLayoutMaxHeight(int maxLayoutHeight) {
    238         mMaxLayoutHeight = maxLayoutHeight;
    239     }
    240 
    241     /**
    242      * Sets the last visible view of the host layout, that has a background, i.e the very last
    243      * view in the shade, without the clear all button.
    244      */
    245     public void setLastVisibleBackgroundChild(
    246             ActivatableNotificationView lastVisibleBackgroundChild) {
    247         mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
    248     }
    249 
    250     public ActivatableNotificationView getLastVisibleBackgroundChild() {
    251         return mLastVisibleBackgroundChild;
    252     }
    253 
    254     public void setCurrentScrollVelocity(float currentScrollVelocity) {
    255         mCurrentScrollVelocity = currentScrollVelocity;
    256     }
    257 
    258     public float getCurrentScrollVelocity() {
    259         return mCurrentScrollVelocity;
    260     }
    261 
    262     public boolean isOnKeyguard() {
    263         return mStatusBarState == StatusBarState.KEYGUARD;
    264     }
    265 
    266     public void setStatusBarState(int statusBarState) {
    267         mStatusBarState = statusBarState;
    268     }
    269 
    270     public void setExpandingVelocity(float expandingVelocity) {
    271         mExpandingVelocity = expandingVelocity;
    272     }
    273 
    274     public void setExpansionChanging(boolean expansionChanging) {
    275         mExpansionChanging = expansionChanging;
    276     }
    277 
    278     public boolean isExpansionChanging() {
    279         return mExpansionChanging;
    280     }
    281 
    282     public float getExpandingVelocity() {
    283         return mExpandingVelocity;
    284     }
    285 
    286     public void setPanelTracking(boolean panelTracking) {
    287         mPanelTracking = panelTracking;
    288     }
    289 
    290     public boolean hasPulsingNotifications() {
    291         return mHasPulsingNotifications;
    292     }
    293 
    294     public void setHasPulsingNotifications(boolean hasPulsing) {
    295         mHasPulsingNotifications = hasPulsing;
    296     }
    297 
    298     public boolean isPanelTracking() {
    299         return mPanelTracking;
    300     }
    301 
    302     public boolean isPanelFullWidth() {
    303         return mPanelFullWidth;
    304     }
    305 
    306     public void setPanelFullWidth(boolean panelFullWidth) {
    307         mPanelFullWidth = panelFullWidth;
    308     }
    309 
    310     public void setUnlockHintRunning(boolean unlockHintRunning) {
    311         mUnlockHintRunning = unlockHintRunning;
    312     }
    313 
    314     public boolean isUnlockHintRunning() {
    315         return mUnlockHintRunning;
    316     }
    317 }
    318