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 /**
     20  * A functor which can be queried for offset given the number of items before it.
     21  */
     22 public abstract class StackIndentationFunctor {
     23 
     24     protected int mTotalTransitionDistance;
     25     protected int mDistanceToPeekStart;
     26     protected int mMaxItemsInStack;
     27     protected int mPeekSize;
     28     protected boolean mStackStartsAtPeek;
     29 
     30     /**
     31      * @param maxItemsInStack The maximum number of items which should be visible at the same time,
     32      *                        i.e the function returns totalTransitionDistance for the element with
     33      *                        index maxItemsInStack
     34      * @param peekSize The visual appearance of this is how far the cards in the stack peek
     35      *                 out below the top card and it is measured in real pixels.
     36      *                 Note that the visual appearance does not necessarily always correspond to
     37      *                 the actual visual distance below the top card but is a maximum,
     38      *                 achieved when the next card just starts transitioning into the stack and
     39      *                 the stack is full.
     40      *                 If distanceToPeekStart is 0, we directly start at the peek, otherwise the
     41      *                 first element transitions between 0 and distanceToPeekStart.
     42      *                 Visualization:
     43      *           ---------------------------------------------------   ---
     44      *          |                                                   |   |
     45      *          |                  FIRST ITEM                       |   | <- distanceToPeekStart
     46      *          |                                                   |   |
     47      *          |---------------------------------------------------|  ---  ---
     48      *          |__________________SECOND ITEM______________________|        |  <- peekSize
     49      *          |===================================================|       _|_
     50      *
     51      * @param distanceToPeekStart The distance to the start of the peak.
     52      */
     53     StackIndentationFunctor(int maxItemsInStack, int peekSize, int distanceToPeekStart) {
     54         mDistanceToPeekStart = distanceToPeekStart;
     55         mStackStartsAtPeek = mDistanceToPeekStart == 0;
     56         mMaxItemsInStack = maxItemsInStack;
     57         mPeekSize = peekSize;
     58         updateTotalTransitionDistance();
     59 
     60     }
     61 
     62     private void updateTotalTransitionDistance() {
     63         mTotalTransitionDistance = mDistanceToPeekStart + mPeekSize;
     64     }
     65 
     66     public void setPeekSize(int mPeekSize) {
     67         this.mPeekSize = mPeekSize;
     68         updateTotalTransitionDistance();
     69     }
     70 
     71     public void setDistanceToPeekStart(int distanceToPeekStart) {
     72         mDistanceToPeekStart = distanceToPeekStart;
     73         mStackStartsAtPeek = mDistanceToPeekStart == 0;
     74         updateTotalTransitionDistance();
     75     }
     76 
     77     /**
     78      * Gets the offset of this Functor given a the quantity of items before it
     79      *
     80      * @param itemsBefore how many items are already in the stack before this element
     81      * @return the offset
     82      */
     83     public abstract float getValue(float itemsBefore);
     84 }
     85