167b2260093774f5866f781aede52830440f4ed0eSelim Cinek/*
267b2260093774f5866f781aede52830440f4ed0eSelim Cinek * Copyright (C) 2014 The Android Open Source Project
367b2260093774f5866f781aede52830440f4ed0eSelim Cinek *
467b2260093774f5866f781aede52830440f4ed0eSelim Cinek * Licensed under the Apache License, Version 2.0 (the "License");
567b2260093774f5866f781aede52830440f4ed0eSelim Cinek * you may not use this file except in compliance with the License.
667b2260093774f5866f781aede52830440f4ed0eSelim Cinek * You may obtain a copy of the License at
767b2260093774f5866f781aede52830440f4ed0eSelim Cinek *
867b2260093774f5866f781aede52830440f4ed0eSelim Cinek *      http://www.apache.org/licenses/LICENSE-2.0
967b2260093774f5866f781aede52830440f4ed0eSelim Cinek *
1067b2260093774f5866f781aede52830440f4ed0eSelim Cinek * Unless required by applicable law or agreed to in writing, software
1167b2260093774f5866f781aede52830440f4ed0eSelim Cinek * distributed under the License is distributed on an "AS IS" BASIS,
1267b2260093774f5866f781aede52830440f4ed0eSelim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1367b2260093774f5866f781aede52830440f4ed0eSelim Cinek * See the License for the specific language governing permissions and
1467b2260093774f5866f781aede52830440f4ed0eSelim Cinek * limitations under the License
1567b2260093774f5866f781aede52830440f4ed0eSelim Cinek */
1667b2260093774f5866f781aede52830440f4ed0eSelim Cinek
1767b2260093774f5866f781aede52830440f4ed0eSelim Cinekpackage com.android.systemui.statusbar.stack;
1867b2260093774f5866f781aede52830440f4ed0eSelim Cinek
1967b2260093774f5866f781aede52830440f4ed0eSelim Cinek/**
2067b2260093774f5866f781aede52830440f4ed0eSelim Cinek * A functor which can be queried for offset given the number of items before it.
2167b2260093774f5866f781aede52830440f4ed0eSelim Cinek */
2267b2260093774f5866f781aede52830440f4ed0eSelim Cinekpublic abstract class StackIndentationFunctor {
2367b2260093774f5866f781aede52830440f4ed0eSelim Cinek
2434c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek    protected int mTotalTransitionDistance;
2534c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek    protected int mDistanceToPeekStart;
2667b2260093774f5866f781aede52830440f4ed0eSelim Cinek    protected int mMaxItemsInStack;
2767b2260093774f5866f781aede52830440f4ed0eSelim Cinek    protected int mPeekSize;
2867b2260093774f5866f781aede52830440f4ed0eSelim Cinek    protected boolean mStackStartsAtPeek;
2967b2260093774f5866f781aede52830440f4ed0eSelim Cinek
3067b2260093774f5866f781aede52830440f4ed0eSelim Cinek    /**
3167b2260093774f5866f781aede52830440f4ed0eSelim Cinek     * @param maxItemsInStack The maximum number of items which should be visible at the same time,
3267b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                        i.e the function returns totalTransitionDistance for the element with
3367b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                        index maxItemsInStack
3467b2260093774f5866f781aede52830440f4ed0eSelim Cinek     * @param peekSize The visual appearance of this is how far the cards in the stack peek
3567b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                 out below the top card and it is measured in real pixels.
3667b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                 Note that the visual appearance does not necessarily always correspond to
3767b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                 the actual visual distance below the top card but is a maximum,
3867b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                 achieved when the next card just starts transitioning into the stack and
3967b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                 the stack is full.
4034c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek     *                 If distanceToPeekStart is 0, we directly start at the peek, otherwise the
4134c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek     *                 first element transitions between 0 and distanceToPeekStart.
4267b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *                 Visualization:
4367b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *           ---------------------------------------------------   ---
4467b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *          |                                                   |   |
4534c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek     *          |                  FIRST ITEM                       |   | <- distanceToPeekStart
4667b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *          |                                                   |   |
4734c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek     *          |---------------------------------------------------|  ---  ---
4834c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek     *          |__________________SECOND ITEM______________________|        |  <- peekSize
4934c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek     *          |===================================================|       _|_
5067b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *
5134c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek     * @param distanceToPeekStart The distance to the start of the peak.
5267b2260093774f5866f781aede52830440f4ed0eSelim Cinek     */
5334c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek    StackIndentationFunctor(int maxItemsInStack, int peekSize, int distanceToPeekStart) {
5434c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek        mDistanceToPeekStart = distanceToPeekStart;
5567b2260093774f5866f781aede52830440f4ed0eSelim Cinek        mStackStartsAtPeek = mDistanceToPeekStart == 0;
5667b2260093774f5866f781aede52830440f4ed0eSelim Cinek        mMaxItemsInStack = maxItemsInStack;
5767b2260093774f5866f781aede52830440f4ed0eSelim Cinek        mPeekSize = peekSize;
5834c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek        updateTotalTransitionDistance();
5967b2260093774f5866f781aede52830440f4ed0eSelim Cinek
6067b2260093774f5866f781aede52830440f4ed0eSelim Cinek    }
6167b2260093774f5866f781aede52830440f4ed0eSelim Cinek
6234c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek    private void updateTotalTransitionDistance() {
6334c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek        mTotalTransitionDistance = mDistanceToPeekStart + mPeekSize;
6434c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek    }
6534c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek
6667b2260093774f5866f781aede52830440f4ed0eSelim Cinek    public void setPeekSize(int mPeekSize) {
6767b2260093774f5866f781aede52830440f4ed0eSelim Cinek        this.mPeekSize = mPeekSize;
6834c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek        updateTotalTransitionDistance();
6934c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek    }
7034c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek
7134c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek    public void setDistanceToPeekStart(int distanceToPeekStart) {
7234c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek        mDistanceToPeekStart = distanceToPeekStart;
7334c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek        mStackStartsAtPeek = mDistanceToPeekStart == 0;
7434c0a8d72aee1867cf7b6d04531c7faec76ab473Selim Cinek        updateTotalTransitionDistance();
7567b2260093774f5866f781aede52830440f4ed0eSelim Cinek    }
7667b2260093774f5866f781aede52830440f4ed0eSelim Cinek
7767b2260093774f5866f781aede52830440f4ed0eSelim Cinek    /**
7867b2260093774f5866f781aede52830440f4ed0eSelim Cinek     * Gets the offset of this Functor given a the quantity of items before it
7967b2260093774f5866f781aede52830440f4ed0eSelim Cinek     *
8067b2260093774f5866f781aede52830440f4ed0eSelim Cinek     * @param itemsBefore how many items are already in the stack before this element
8167b2260093774f5866f781aede52830440f4ed0eSelim Cinek     * @return the offset
8267b2260093774f5866f781aede52830440f4ed0eSelim Cinek     */
8367b2260093774f5866f781aede52830440f4ed0eSelim Cinek    public abstract float getValue(float itemsBefore);
8467b2260093774f5866f781aede52830440f4ed0eSelim Cinek}
85