ExpandableView.java revision a272dfed9a4f31d8245099c0d99a73e79b90670c
1be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi/*
2be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Copyright (C) 2014 The Android Open Source Project
3be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi *
4be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Licensed under the Apache License, Version 2.0 (the "License");
5be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * you may not use this file except in compliance with the License.
6be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * You may obtain a copy of the License at
7be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi *
8be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi *      http://www.apache.org/licenses/LICENSE-2.0
9be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi *
10be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * Unless required by applicable law or agreed to in writing, software
11be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * distributed under the License is distributed on an "AS IS" BASIS,
12be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * See the License for the specific language governing permissions and
14be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * limitations under the License
15be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */
16be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
17be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggipackage com.android.systemui.statusbar;
18be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
19be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.content.Context;
20e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinekimport android.graphics.Rect;
21be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.util.AttributeSet;
2200ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggiimport android.view.MotionEvent;
23be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggiimport android.view.View;
24c9c00ae2fa5fb787e9f12705f8cd8de445ecde4bSelim Cinekimport android.view.ViewGroup;
2524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinekimport android.widget.FrameLayout;
2624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinekimport com.android.systemui.R;
27e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinekimport com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
2824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek
2924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinekimport java.util.ArrayList;
30be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
31be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi/**
32be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi * An abstract view for expandable views.
33be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi */
3424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinekpublic abstract class ExpandableView extends FrameLayout {
3524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek
36be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
37be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    private OnHeightChangedListener mOnHeightChangedListener;
38379ff8f6b18b236b679a59a2dc14c0baeede3baeSelim Cinek    protected int mMaxViewHeight;
39310df3127aace5a82cdc107fdb1e2d6957f38bccChris Wren    private int mActualHeight;
40be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    protected int mClipTopAmount;
41be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    private boolean mActualHeightInitialized;
424e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    private boolean mDark;
4324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    private ArrayList<View> mMatchParentViews = new ArrayList<View>();
44a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    private int mClipTopOptimization;
45a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    private static Rect mClipRect = new Rect();
46be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
47be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public ExpandableView(Context context, AttributeSet attrs) {
48be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        super(context, attrs);
49379ff8f6b18b236b679a59a2dc14c0baeede3baeSelim Cinek        mMaxViewHeight = getResources().getDimensionPixelSize(
5024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                R.dimen.notification_max_height);
51be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
52be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
53be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    @Override
5424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
55379ff8f6b18b236b679a59a2dc14c0baeede3baeSelim Cinek        int ownMaxHeight = mMaxViewHeight;
5624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
5724d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        boolean hasFixedHeight = heightMode == MeasureSpec.EXACTLY;
5824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        boolean isHeightLimited = heightMode == MeasureSpec.AT_MOST;
5924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        if (hasFixedHeight || isHeightLimited) {
6024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            int size = MeasureSpec.getSize(heightMeasureSpec);
6124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            ownMaxHeight = Math.min(ownMaxHeight, size);
6224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        }
6324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int newHeightSpec = MeasureSpec.makeMeasureSpec(ownMaxHeight, MeasureSpec.AT_MOST);
6424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int maxChildHeight = 0;
6524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int childCount = getChildCount();
6624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        for (int i = 0; i < childCount; i++) {
67c9c00ae2fa5fb787e9f12705f8cd8de445ecde4bSelim Cinek            View child = getChildAt(i);
6824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            int childHeightSpec = newHeightSpec;
6924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            ViewGroup.LayoutParams layoutParams = child.getLayoutParams();
7024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            if (layoutParams.height != ViewGroup.LayoutParams.MATCH_PARENT) {
7124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                if (layoutParams.height >= 0) {
7224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                    // An actual height is set
7324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                    childHeightSpec = layoutParams.height > ownMaxHeight
7424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                        ? MeasureSpec.makeMeasureSpec(ownMaxHeight, MeasureSpec.EXACTLY)
7524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                        : MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
7624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                }
77b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                child.measure(
78b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                        getChildMeasureSpec(widthMeasureSpec, 0 /* padding */, layoutParams.width),
79b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                        childHeightSpec);
8024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                int childHeight = child.getMeasuredHeight();
8124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                maxChildHeight = Math.max(maxChildHeight, childHeight);
8224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            } else {
8324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                mMatchParentViews.add(child);
8424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            }
8524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        }
86379ff8f6b18b236b679a59a2dc14c0baeede3baeSelim Cinek        int ownHeight = hasFixedHeight ? ownMaxHeight :
87379ff8f6b18b236b679a59a2dc14c0baeede3baeSelim Cinek                isHeightLimited ? Math.min(ownMaxHeight, maxChildHeight) : maxChildHeight;
8824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        newHeightSpec = MeasureSpec.makeMeasureSpec(ownHeight, MeasureSpec.EXACTLY);
8924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        for (View child : mMatchParentViews) {
90b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi            child.measure(getChildMeasureSpec(
91b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                    widthMeasureSpec, 0 /* padding */, child.getLayoutParams().width),
92b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                    newHeightSpec);
93c9c00ae2fa5fb787e9f12705f8cd8de445ecde4bSelim Cinek        }
9424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        mMatchParentViews.clear();
9524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int width = MeasureSpec.getSize(widthMeasureSpec);
9624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        setMeasuredDimension(width, ownHeight);
9724d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    }
9824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek
9924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    @Override
10024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
10124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        super.onLayout(changed, left, top, right, bottom);
102be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        if (!mActualHeightInitialized && mActualHeight == 0) {
103d2319fbe6a53ac4c38ca02e4d8e32da86ed0994bSelim Cinek            int initialHeight = getInitialHeight();
104d2319fbe6a53ac4c38ca02e4d8e32da86ed0994bSelim Cinek            if (initialHeight != 0) {
105d2319fbe6a53ac4c38ca02e4d8e32da86ed0994bSelim Cinek                setActualHeight(initialHeight);
106d2319fbe6a53ac4c38ca02e4d8e32da86ed0994bSelim Cinek            }
107be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        }
108be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
109be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
1101a521f3ea841f6db9686bbec7f950a3883d075aaSelim Cinek    /**
1111a521f3ea841f6db9686bbec7f950a3883d075aaSelim Cinek     * Resets the height of the view on the next layout pass
1121a521f3ea841f6db9686bbec7f950a3883d075aaSelim Cinek     */
1131a521f3ea841f6db9686bbec7f950a3883d075aaSelim Cinek    protected void resetActualHeight() {
114310df3127aace5a82cdc107fdb1e2d6957f38bccChris Wren        mActualHeight = 0;
115310df3127aace5a82cdc107fdb1e2d6957f38bccChris Wren        mActualHeightInitialized = false;
1161a521f3ea841f6db9686bbec7f950a3883d075aaSelim Cinek        requestLayout();
117310df3127aace5a82cdc107fdb1e2d6957f38bccChris Wren    }
118310df3127aace5a82cdc107fdb1e2d6957f38bccChris Wren
119c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    protected int getInitialHeight() {
120c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek        return getHeight();
121c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    }
122c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek
12300ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    @Override
12400ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    public boolean dispatchTouchEvent(MotionEvent ev) {
12500ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        if (filterMotionEvent(ev)) {
12600ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi            return super.dispatchTouchEvent(ev);
12700ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        }
12800ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        return false;
12900ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    }
13000ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi
1311a521f3ea841f6db9686bbec7f950a3883d075aaSelim Cinek    protected boolean filterMotionEvent(MotionEvent event) {
13200ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        return event.getActionMasked() != MotionEvent.ACTION_DOWN
13300ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi                || event.getY() > mClipTopAmount && event.getY() < mActualHeight;
13400ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    }
13500ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi
136be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
137be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * Sets the actual height of this notification. This is different than the laid out
138be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * {@link View#getHeight()}, as we want to avoid layouting during scrolling and expanding.
139d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     *
140d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param actualHeight The height of this notification.
141d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param notifyListeners Whether the listener should be informed about the change.
142be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
143d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    public void setActualHeight(int actualHeight, boolean notifyListeners) {
1442580a976ec93a01ed00fae51364ad872bc591d95Jorim Jaggi        mActualHeightInitialized = true;
145be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        mActualHeight = actualHeight;
146a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek        updateClipping();
147d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi        if (notifyListeners) {
148d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi            notifyHeightChanged();
149d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi        }
150d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    }
151d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi
152d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    public void setActualHeight(int actualHeight) {
153d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi        setActualHeight(actualHeight, true);
154be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
155be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
156be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
157be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * See {@link #setActualHeight}.
158be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     *
1599cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi     * @return The current actual height of this notification.
160be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
161be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public int getActualHeight() {
162be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        return mActualHeight;
163be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
164be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
165be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
166be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * @return The maximum height of this notification.
167be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
1684222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    public int getMaxHeight() {
1694222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi        return getHeight();
1704222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    }
1714222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi
1724222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    /**
1734222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi     * @return The minimum height of this notification.
1744222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi     */
1754222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    public int getMinHeight() {
1764222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi        return getHeight();
1774222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    }
178be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
179be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
180d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * Sets the notification as dimmed. The default implementation does nothing.
181d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     *
182d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param dimmed Whether the notification should be dimmed.
183d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param fade Whether an animation should be played to change the state.
184d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     */
185d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    public void setDimmed(boolean dimmed, boolean fade) {
186d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    }
187d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi
188d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    /**
189bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     * Sets the notification as dark. The default implementation does nothing.
190bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     *
191bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     * @param dark Whether the notification should be dark.
192bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     * @param fade Whether an animation should be played to change the state.
1934e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi     * @param delay If fading, the delay of the animation.
194bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     */
1954e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    public void setDark(boolean dark, boolean fade, long delay) {
1964e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi        mDark = dark;
1974e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    }
1984e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi
1994e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi    public boolean isDark() {
2004e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi        return mDark;
201bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock    }
202bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock
203bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock    /**
204ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * See {@link #setHideSensitive}. This is a variant which notifies this view in advance about
205ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * the upcoming state of hiding sensitive notifications. It gets called at the very beginning
206ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * of a stack scroller update such that the updated intrinsic height (which is dependent on
207ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * whether private or public layout is showing) gets taken into account into all layout
208ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * calculations.
209ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     */
210ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
211ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    }
212ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi
213ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    /**
214ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * Sets whether the notification should hide its private contents if it is sensitive.
215ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     */
216ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
217ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi            long duration) {
218ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    }
219ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi
220ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    /**
2219cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi     * @return The desired notification height.
2229cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi     */
2239cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    public int getIntrinsicHeight() {
224a5eaa6034dd48fab0f5a232c09ebed35f359963eSelim Cinek        return getHeight();
2259cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    }
2269cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi
2279cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    /**
228be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * Sets the amount this view should be clipped from the top. This is used when an expanded
229be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * notification is scrolling in the top or bottom stack.
230be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     *
231be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * @param clipTopAmount The amount of pixels this view should be clipped from top.
232be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
233be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public void setClipTopAmount(int clipTopAmount) {
234be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        mClipTopAmount = clipTopAmount;
235be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
236be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
237eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek    public int getClipTopAmount() {
238eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek        return mClipTopAmount;
239eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek    }
240eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek
241be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public void setOnHeightChangedListener(OnHeightChangedListener listener) {
242be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        mOnHeightChangedListener = listener;
243be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
244be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
245be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
2464222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi     * @return Whether we can expand this views content.
247be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
2484222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    public boolean isContentExpandable() {
2494222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi        return false;
250be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
251be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
2529cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    public void notifyHeightChanged() {
2539cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi        if (mOnHeightChangedListener != null) {
2549cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi            mOnHeightChangedListener.onHeightChanged(this);
2559cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi        }
2569cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    }
2579cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi
258c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    public boolean isTransparent() {
259c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek        return false;
260c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    }
261c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek
262be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
2638efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     * Perform a remove animation on this view.
2648efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *
26560d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi     * @param duration The duration of the remove animation.
2668efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     * @param translationDirection The direction value from [-1 ... 1] indicating in which the
2678efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             animation should be performed. A value of -1 means that The
2688efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             remove animation should be performed upwards,
2698efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             such that the  child appears to be going away to the top. 1
2708efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             Should mean the opposite.
2718efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     * @param onFinishedRunnable A runnable which should be run when the animation is finished.
2728efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     */
27360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi    public abstract void performRemoveAnimation(long duration, float translationDirection,
2748efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek            Runnable onFinishedRunnable);
2758efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek
27660d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi    public abstract void performAddAnimation(long delay, long duration);
2778efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek
2783d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek    public void setBelowSpeedBump(boolean below) {
2793d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek    }
2803d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek
28131094df5c6e3cb3a4a4faacb091e35eea1f6a5deSelim Cinek    public void onHeightReset() {
282e34c6513bb1a4d3e246866c2a7f0619914f18bd3Selim Cinek        if (mOnHeightChangedListener != null) {
283e34c6513bb1a4d3e246866c2a7f0619914f18bd3Selim Cinek            mOnHeightChangedListener.onReset(this);
284e34c6513bb1a4d3e246866c2a7f0619914f18bd3Selim Cinek        }
285a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek    }
286a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek
2878efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek    /**
288e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * This method returns the drawing rect for the view which is different from the regular
289e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * drawing rect, since we layout all children in the {@link NotificationStackScrollLayout} at
290e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * position 0 and usually the translation is neglected. Since we are manually clipping this
291e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * view,we also need to subtract the clipTopAmount from the top. This is needed in order to
292e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * ensure that accessibility and focusing work correctly.
293e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     *
294e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * @param outRect The (scrolled) drawing bounds of the view.
295e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     */
296e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    @Override
297e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    public void getDrawingRect(Rect outRect) {
298e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        super.getDrawingRect(outRect);
299e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.left += getTranslationX();
300e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.right += getTranslationX();
301e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.bottom = (int) (outRect.top + getTranslationY() + getActualHeight());
302e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.top += getTranslationY() + getClipTopAmount();
303e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    }
304e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek
305a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    private void updateClipping() {
306a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek        mClipRect.set(0, mClipTopOptimization, getWidth(), getActualHeight());
307a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek        setClipBounds(mClipRect);
308a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    }
309a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek
310a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    public int getClipTopOptimization() {
311a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek        return mClipTopOptimization;
312a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    }
313a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek
314a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    /**
315a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek     * Set that the view will be clipped by a given amount from the top. Contrary to
316a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek     * {@link #setClipTopAmount} this amount doesn't effect shadows and the background.
317a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek     *
318a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek     * @param clipTopOptimization the amount to clip from the top
319a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek     */
320a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    public void setClipTopOptimization(int clipTopOptimization) {
321a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek        mClipTopOptimization = clipTopOptimization;
322a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek        updateClipping();
323a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek    }
324a272dfed9a4f31d8245099c0d99a73e79b90670cSelim Cinek
325e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    /**
326be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * A listener notifying when {@link #getActualHeight} changes.
327be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
328be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public interface OnHeightChangedListener {
32930c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi
33030c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi        /**
33130c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi         * @param view the view for which the height changed, or {@code null} if just the top
33230c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi         *             padding or the padding between the elements changed
33330c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi         */
334be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        void onHeightChanged(ExpandableView view);
335a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek
336a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek        /**
337a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         * Called when the view is reset and therefore the height will change abruptly
338a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         *
339a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         * @param view The view which was reset.
340a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         */
341a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek        void onReset(ExpandableView view);
342be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
343be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi}
344