StackIndentationFunctor.java revision 67b2260093774f5866f781aede52830440f4ed0e
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 17package com.android.systemui.statusbar.stack; 18 19/** 20 * A functor which can be queried for offset given the number of items before it. 21 */ 22public abstract class StackIndentationFunctor { 23 24 protected final int mTotalTransitionDistance; 25 protected final 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 totalTransitionDistance is equal to this, we directly start at the peek, 41 * otherwise the first element transitions between 0 and 42 * totalTransitionDistance - peekSize. 43 * Visualization: 44 * --------------------------------------------------- --- 45 * | | | 46 * | FIRST ITEM | | <- totalTransitionDistance 47 * | | | 48 * |---------------------------------------------------| | --- 49 * |__________________SECOND ITEM______________________| | | <- peekSize 50 * |===================================================| _|_ _|_ 51 * 52 * @param totalTransitionDistance The total transition distance an element has to go through 53 */ 54 StackIndentationFunctor(int maxItemsInStack, int peekSize, int totalTransitionDistance) { 55 mTotalTransitionDistance = totalTransitionDistance; 56 mDistanceToPeekStart = mTotalTransitionDistance - peekSize; 57 mStackStartsAtPeek = mDistanceToPeekStart == 0; 58 mMaxItemsInStack = maxItemsInStack; 59 mPeekSize = peekSize; 60 61 } 62 63 public void setPeekSize(int mPeekSize) { 64 this.mPeekSize = mPeekSize; 65 } 66 67 /** 68 * Gets the offset of this Functor given a the quantity of items before it 69 * 70 * @param itemsBefore how many items are already in the stack before this element 71 * @return the offset 72 */ 73 public abstract float getValue(float itemsBefore); 74} 75