ExpandableView.java revision e32010ac6120278fea41e49b9832af79b1b5463e
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
3624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    private final int mMaxNotificationHeight;
37be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
38be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    private OnHeightChangedListener mOnHeightChangedListener;
39be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    protected int mActualHeight;
40be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    protected int mClipTopAmount;
41be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    private boolean mActualHeightInitialized;
4224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    private ArrayList<View> mMatchParentViews = new ArrayList<View>();
43be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
44be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public ExpandableView(Context context, AttributeSet attrs) {
45be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        super(context, attrs);
4624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        mMaxNotificationHeight = getResources().getDimensionPixelSize(
4724d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                R.dimen.notification_max_height);
48be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
49be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
50be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    @Override
5124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
5224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int ownMaxHeight = mMaxNotificationHeight;
5324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
5424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        boolean hasFixedHeight = heightMode == MeasureSpec.EXACTLY;
5524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        boolean isHeightLimited = heightMode == MeasureSpec.AT_MOST;
5624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        if (hasFixedHeight || isHeightLimited) {
5724d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            int size = MeasureSpec.getSize(heightMeasureSpec);
5824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            ownMaxHeight = Math.min(ownMaxHeight, size);
5924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        }
6024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int newHeightSpec = MeasureSpec.makeMeasureSpec(ownMaxHeight, MeasureSpec.AT_MOST);
6124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int maxChildHeight = 0;
6224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int childCount = getChildCount();
6324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        for (int i = 0; i < childCount; i++) {
64c9c00ae2fa5fb787e9f12705f8cd8de445ecde4bSelim Cinek            View child = getChildAt(i);
6524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            int childHeightSpec = newHeightSpec;
6624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            ViewGroup.LayoutParams layoutParams = child.getLayoutParams();
6724d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            if (layoutParams.height != ViewGroup.LayoutParams.MATCH_PARENT) {
6824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                if (layoutParams.height >= 0) {
6924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                    // An actual height is set
7024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                    childHeightSpec = layoutParams.height > ownMaxHeight
7124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                        ? MeasureSpec.makeMeasureSpec(ownMaxHeight, MeasureSpec.EXACTLY)
7224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                        : MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
7324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                }
74b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                child.measure(
75b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                        getChildMeasureSpec(widthMeasureSpec, 0 /* padding */, layoutParams.width),
76b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                        childHeightSpec);
7724d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                int childHeight = child.getMeasuredHeight();
7824d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                maxChildHeight = Math.max(maxChildHeight, childHeight);
7924d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            } else {
8024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek                mMatchParentViews.add(child);
8124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek            }
8224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        }
8324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int ownHeight = hasFixedHeight ? ownMaxHeight : maxChildHeight;
8424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        newHeightSpec = MeasureSpec.makeMeasureSpec(ownHeight, MeasureSpec.EXACTLY);
8524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        for (View child : mMatchParentViews) {
86b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi            child.measure(getChildMeasureSpec(
87b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                    widthMeasureSpec, 0 /* padding */, child.getLayoutParams().width),
88b741f053394b6e8f59bdf72bb47e9f4484fbb808Jorim Jaggi                    newHeightSpec);
89c9c00ae2fa5fb787e9f12705f8cd8de445ecde4bSelim Cinek        }
9024d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        mMatchParentViews.clear();
9124d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        int width = MeasureSpec.getSize(widthMeasureSpec);
9224d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        setMeasuredDimension(width, ownHeight);
9324d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    }
9424d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek
9524d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    @Override
9624d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
9724d7cfa4d6a3331708bb7b37f551b4f534b02f7cSelim Cinek        super.onLayout(changed, left, top, right, bottom);
98be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        if (!mActualHeightInitialized && mActualHeight == 0) {
993c3c3fc38c474924629aa591c98d6dc190ed4e83Jorim Jaggi            setActualHeight(getInitialHeight());
100be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        }
101be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
102be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
103c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    protected int getInitialHeight() {
104c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek        return getHeight();
105c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    }
106c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek
10700ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    @Override
10800ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    public boolean dispatchTouchEvent(MotionEvent ev) {
10900ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        if (filterMotionEvent(ev)) {
11000ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi            return super.dispatchTouchEvent(ev);
11100ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        }
11200ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        return false;
11300ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    }
11400ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi
11500ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    private boolean filterMotionEvent(MotionEvent event) {
11600ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi        return event.getActionMasked() != MotionEvent.ACTION_DOWN
11700ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi                || event.getY() > mClipTopAmount && event.getY() < mActualHeight;
11800ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi    }
11900ebdfe8ba98c05a767660de2ed7c9a19fb49d74Jorim Jaggi
120be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
121be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * Sets the actual height of this notification. This is different than the laid out
122be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * {@link View#getHeight()}, as we want to avoid layouting during scrolling and expanding.
123d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     *
124d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param actualHeight The height of this notification.
125d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param notifyListeners Whether the listener should be informed about the change.
126be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
127d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    public void setActualHeight(int actualHeight, boolean notifyListeners) {
1282580a976ec93a01ed00fae51364ad872bc591d95Jorim Jaggi        mActualHeightInitialized = true;
129be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        mActualHeight = actualHeight;
130d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi        if (notifyListeners) {
131d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi            notifyHeightChanged();
132d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi        }
133d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    }
134d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi
135d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    public void setActualHeight(int actualHeight) {
136d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi        setActualHeight(actualHeight, true);
137be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
138be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
139be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
140be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * See {@link #setActualHeight}.
141be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     *
1429cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi     * @return The current actual height of this notification.
143be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
144be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public int getActualHeight() {
145be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        return mActualHeight;
146be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
147be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
148be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
149be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * @return The maximum height of this notification.
150be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
1514222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    public int getMaxHeight() {
1524222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi        return getHeight();
1534222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    }
1544222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi
1554222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    /**
1564222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi     * @return The minimum height of this notification.
1574222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi     */
1584222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    public int getMinHeight() {
1594222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi        return getHeight();
1604222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    }
161be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
162be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
163d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * Sets the notification as dimmed. The default implementation does nothing.
164d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     *
165d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param dimmed Whether the notification should be dimmed.
166d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     * @param fade Whether an animation should be played to change the state.
167d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi     */
168d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    public void setDimmed(boolean dimmed, boolean fade) {
169d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    }
170d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi
171d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi    /**
172bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     * Sets the notification as dark. The default implementation does nothing.
173bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     *
174bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     * @param dark Whether the notification should be dark.
175bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     * @param fade Whether an animation should be played to change the state.
176bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock     */
177bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock    public void setDark(boolean dark, boolean fade) {
178bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock    }
179bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock
180bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock    /**
181ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * See {@link #setHideSensitive}. This is a variant which notifies this view in advance about
182ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * the upcoming state of hiding sensitive notifications. It gets called at the very beginning
183ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * of a stack scroller update such that the updated intrinsic height (which is dependent on
184ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * whether private or public layout is showing) gets taken into account into all layout
185ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * calculations.
186ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     */
187ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
188ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    }
189ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi
190ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    /**
191ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     * Sets whether the notification should hide its private contents if it is sensitive.
192ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi     */
193ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
194ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi            long duration) {
195ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    }
196ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi
197ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi    /**
1989cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi     * @return The desired notification height.
1999cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi     */
2009cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    public int getIntrinsicHeight() {
201a5eaa6034dd48fab0f5a232c09ebed35f359963eSelim Cinek        return getHeight();
2029cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    }
2039cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi
2049cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    /**
205be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * Sets the amount this view should be clipped from the top. This is used when an expanded
206be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * notification is scrolling in the top or bottom stack.
207be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     *
208be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * @param clipTopAmount The amount of pixels this view should be clipped from top.
209be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
210be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public void setClipTopAmount(int clipTopAmount) {
211be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        mClipTopAmount = clipTopAmount;
212be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
213be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
214eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek    public int getClipTopAmount() {
215eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek        return mClipTopAmount;
216eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek    }
217eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek
218be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public void setOnHeightChangedListener(OnHeightChangedListener listener) {
219be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        mOnHeightChangedListener = listener;
220be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
221be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
222be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
2234222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi     * @return Whether we can expand this views content.
224be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
2254222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi    public boolean isContentExpandable() {
2264222d9a7fb87d73e1443ec1a2de9782b05741af6Jorim Jaggi        return false;
227be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
228be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi
2299cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    public void notifyHeightChanged() {
2309cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi        if (mOnHeightChangedListener != null) {
2319cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi            mOnHeightChangedListener.onHeightChanged(this);
2329cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi        }
2339cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi    }
2349cbadd3c08a7d7dd3412743dd04aecb16c5a1595Jorim Jaggi
235c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    public boolean isTransparent() {
236c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek        return false;
237c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek    }
238c27437b7fd04e682ae2abdf0727a99bf5c6e409dSelim Cinek
239be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    /**
2408efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     * Perform a remove animation on this view.
2418efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *
24260d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi     * @param duration The duration of the remove animation.
2438efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     * @param translationDirection The direction value from [-1 ... 1] indicating in which the
2448efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             animation should be performed. A value of -1 means that The
2458efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             remove animation should be performed upwards,
2468efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             such that the  child appears to be going away to the top. 1
2478efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     *                             Should mean the opposite.
2488efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     * @param onFinishedRunnable A runnable which should be run when the animation is finished.
2498efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek     */
25060d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi    public abstract void performRemoveAnimation(long duration, float translationDirection,
2518efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek            Runnable onFinishedRunnable);
2528efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek
25360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi    public abstract void performAddAnimation(long delay, long duration);
2548efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek
255f54090e9bb23e9ed1b4d9e500d856f80d2fbe775Selim Cinek    public abstract void setScrimAmount(float scrimAmount);
256f54090e9bb23e9ed1b4d9e500d856f80d2fbe775Selim Cinek
2573d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek    public void setBelowSpeedBump(boolean below) {
2583d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek    }
2593d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek
26031094df5c6e3cb3a4a4faacb091e35eea1f6a5deSelim Cinek    public void onHeightReset() {
261e34c6513bb1a4d3e246866c2a7f0619914f18bd3Selim Cinek        if (mOnHeightChangedListener != null) {
262e34c6513bb1a4d3e246866c2a7f0619914f18bd3Selim Cinek            mOnHeightChangedListener.onReset(this);
263e34c6513bb1a4d3e246866c2a7f0619914f18bd3Selim Cinek        }
264a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek    }
265a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek
2668efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek    /**
267e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * This method returns the drawing rect for the view which is different from the regular
268e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * drawing rect, since we layout all children in the {@link NotificationStackScrollLayout} at
269e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * position 0 and usually the translation is neglected. Since we are manually clipping this
270e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * view,we also need to subtract the clipTopAmount from the top. This is needed in order to
271e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * ensure that accessibility and focusing work correctly.
272e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     *
273e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     * @param outRect The (scrolled) drawing bounds of the view.
274e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek     */
275e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    @Override
276e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    public void getDrawingRect(Rect outRect) {
277e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        super.getDrawingRect(outRect);
278e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.left += getTranslationX();
279e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.right += getTranslationX();
280e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.bottom = (int) (outRect.top + getTranslationY() + getActualHeight());
281e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek        outRect.top += getTranslationY() + getClipTopAmount();
282e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    }
283e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek
284e32010ac6120278fea41e49b9832af79b1b5463eSelim Cinek    /**
285be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     * A listener notifying when {@link #getActualHeight} changes.
286be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi     */
287be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    public interface OnHeightChangedListener {
28830c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi
28930c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi        /**
29030c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi         * @param view the view for which the height changed, or {@code null} if just the top
29130c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi         *             padding or the padding between the elements changed
29230c305ce6283ce1380ad91ef0d221696b32d5a6bJorim Jaggi         */
293be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi        void onHeightChanged(ExpandableView view);
294a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek
295a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek        /**
296a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         * Called when the view is reset and therefore the height will change abruptly
297a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         *
298a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         * @param view The view which was reset.
299a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek         */
300a5e211b1f2a8d055b369dadc464dc5d5bc3dd9c1Selim Cinek        void onReset(ExpandableView view);
301be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi    }
302be565dfc1c17b7ddafa9753851b8f82849fd3f42Jorim Jaggi}
303