1c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang/*
2c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * Copyright (C) 2013 The Android Open Source Project
3c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang *
4c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * Licensed under the Apache License, Version 2.0 (the "License");
5c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * you may not use this file except in compliance with the License.
6c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * You may obtain a copy of the License at
7c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang *
8c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang *      http://www.apache.org/licenses/LICENSE-2.0
9c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang *
10c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * Unless required by applicable law or agreed to in writing, software
11c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * distributed under the License is distributed on an "AS IS" BASIS,
12c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * See the License for the specific language governing permissions and
14c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * limitations under the License.
15c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang */
16c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang
17c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangpackage com.android.mail.ui;
18c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
19c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport com.android.mail.R;
20042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huangimport com.android.mail.analytics.Analytics;
21c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport com.android.mail.browse.ConversationCursor;
22c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport com.android.mail.preferences.MailPrefs;
23c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport com.android.mail.providers.Folder;
241591414ed6dc829852edd219c39ae430314ff538Scott Kennedyimport com.android.mail.utils.Utils;
25c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
26c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.animation.ObjectAnimator;
27c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.app.LoaderManager;
28c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.content.Context;
29c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.content.res.Resources;
3032ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedyimport android.os.Bundle;
31c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.util.AttributeSet;
32c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.view.View;
33c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.view.animation.DecelerateInterpolator;
34c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangimport android.widget.FrameLayout;
35c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
36c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang/**
37c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang * A tip to educate users about long press to enter CAB mode.  Appears on top of conversation list.
38c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang */
39c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang// TODO: this class was shamelessly copied from ConversationPhotoTeaserView.  Look into
40c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang// extracting a common base class.
41c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yangpublic class ConversationLongPressTipView extends FrameLayout
42c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        implements ConversationSpecialItemView, SwipeableItemView {
43c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
44c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private static int sScrollSlop = 0;
45c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private static int sShrinkAnimationDuration;
46c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
47c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private final MailPrefs mMailPrefs;
48c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private AnimatedAdapter mAdapter;
49c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
50c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private View mSwipeableContent;
51c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
52c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private boolean mShow;
53c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private int mAnimatedHeight = -1;
54c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
551591414ed6dc829852edd219c39ae430314ff538Scott Kennedy    private View mTeaserRightEdge;
561591414ed6dc829852edd219c39ae430314ff538Scott Kennedy    /** Whether we are on a tablet device or not */
571591414ed6dc829852edd219c39ae430314ff538Scott Kennedy    private final boolean mTabletDevice;
581591414ed6dc829852edd219c39ae430314ff538Scott Kennedy    /** When in conversation mode, true if the list is hidden */
591591414ed6dc829852edd219c39ae430314ff538Scott Kennedy    private final boolean mListCollapsible;
601591414ed6dc829852edd219c39ae430314ff538Scott Kennedy
61c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public ConversationLongPressTipView(final Context context) {
62c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        this(context, null);
63c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
64c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
65c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public ConversationLongPressTipView(final Context context, final AttributeSet attrs) {
66c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        this(context, attrs, -1);
67c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
68c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
69c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public ConversationLongPressTipView(
70c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            final Context context, final AttributeSet attrs, final int defStyle) {
71c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        super(context, attrs, defStyle);
72c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
73c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        final Resources resources = context.getResources();
74c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
75c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        if (sScrollSlop == 0) {
76c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            sScrollSlop = resources.getInteger(R.integer.swipeScrollSlop);
77c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            sShrinkAnimationDuration = resources.getInteger(
78c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang                    R.integer.shrink_animation_duration);
79c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        }
80c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
81c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        mMailPrefs = MailPrefs.get(context);
821591414ed6dc829852edd219c39ae430314ff538Scott Kennedy
831591414ed6dc829852edd219c39ae430314ff538Scott Kennedy        mTabletDevice = Utils.useTabletUI(resources);
841591414ed6dc829852edd219c39ae430314ff538Scott Kennedy        mListCollapsible = resources.getBoolean(R.bool.list_collapsible);
85c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
86c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
87c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
88c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    protected void onFinishInflate() {
89c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        mSwipeableContent = findViewById(R.id.swipeable_content);
90c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
91c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        findViewById(R.id.dismiss_button).setOnClickListener(new OnClickListener() {
92c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            @Override
93c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            public void onClick(View v) {
94c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang                dismiss();
95c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            }
96c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        });
971591414ed6dc829852edd219c39ae430314ff538Scott Kennedy
981591414ed6dc829852edd219c39ae430314ff538Scott Kennedy        mTeaserRightEdge = findViewById(R.id.teaser_right_edge);
99c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
100c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
101c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
1020e8dc84326ad3e6d146a203538665f98dd98f688Scott Kennedy    public void onUpdate(Folder folder, ConversationCursor cursor) {
103c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        // It's possible user has enabled/disabled sender images in settings, which affects
104c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        // whether we want to show this tip or not.
105c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        mShow = checkWhetherToShow();
106c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
107c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
108c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
109f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy    public void onGetView() {
110f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy        // Do nothing
111b45d1418887d8595c230788e20516bbe10c2f3eaScott Kennedy    }
112b45d1418887d8595c230788e20516bbe10c2f3eaScott Kennedy
113b45d1418887d8595c230788e20516bbe10c2f3eaScott Kennedy    @Override
114c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public boolean getShouldDisplayInList() {
115c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        mShow = checkWhetherToShow();
116c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        return mShow;
117c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
118c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
119c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private boolean checkWhetherToShow() {
120c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        // show if 1) sender images are disabled 2) there are items
121c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        return !shouldShowSenderImage() && !mAdapter.isEmpty()
122c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang                && !mMailPrefs.isLongPressToSelectTipAlreadyShown();
123c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
124c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
125c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
126c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public int getPosition() {
127c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        // We want this teaser to go before the first real conversation
1286c9845ed223ceaefd2b6e7511d04b038d63de8b3Alice Yang        return 0;
129c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
130c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
131c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
132c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public void setAdapter(AnimatedAdapter adapter) {
133c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        mAdapter = adapter;
134c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
135c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
136c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
13732ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy    public void bindFragment(final LoaderManager loaderManager, final Bundle savedInstanceState) {
138c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
139c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
140c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
141c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public void cleanup() {
142c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
143c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
144c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
145c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public void onConversationSelected() {
146c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        // DO NOTHING
147c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
148c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
149c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
150c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public void onCabModeEntered() {
151d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy        if (mShow) {
152d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy            dismiss();
153d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy        }
154c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
155c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
156cc139833bc5829ba70244519e9870de783c41848Scott Kennedy    @Override
157cc139833bc5829ba70244519e9870de783c41848Scott Kennedy    public void onCabModeExited() {
158cc139833bc5829ba70244519e9870de783c41848Scott Kennedy        // Do nothing
159cc139833bc5829ba70244519e9870de783c41848Scott Kennedy    }
160c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
161c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
16232ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy    public void onConversationListVisibilityChanged(final boolean visible) {
16332ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy        // Do nothing
16432ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy    }
16532ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy
16632ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy    @Override
16732ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy    public void saveInstanceState(final Bundle outState) {
16832ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy        // Do nothing
16932ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy    }
17032ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy
17132ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy    @Override
172c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public boolean acceptsUserTaps() {
173c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        // No, we don't allow user taps.
174c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        return false;
175c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
176c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
177c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
178c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public void dismiss() {
179c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        setDismissed();
180c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        startDestroyAnimation();
181c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
182c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
183c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private void setDismissed() {
184c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        if (mShow) {
185c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            mMailPrefs.setLongPressToSelectTipAlreadyShown();
186c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            mShow = false;
187042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huang            Analytics.getInstance().sendEvent("list_swipe", "long_press_tip", null, 0);
188c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        }
189c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
190c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
191c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    protected boolean shouldShowSenderImage() {
192c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        return mMailPrefs.getShowSenderImages();
193c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
194c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
195c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
196c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public SwipeableView getSwipeableView() {
197c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        return SwipeableView.from(mSwipeableContent);
198c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
199c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
200c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
201c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public boolean canChildBeDismissed() {
202c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        return true;
203c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
204c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
205c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
206c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public float getMinAllowScrollDistance() {
207c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        return sScrollSlop;
208c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
209c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
210c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    private void startDestroyAnimation() {
211c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        final int start = getHeight();
212c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        final int end = 0;
213c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        mAnimatedHeight = start;
214c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        final ObjectAnimator heightAnimator =
215c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang                ObjectAnimator.ofInt(this, "animatedHeight", start, end);
216c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        heightAnimator.setInterpolator(new DecelerateInterpolator(2.0f));
217c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        heightAnimator.setDuration(sShrinkAnimationDuration);
218c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        heightAnimator.start();
219d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy
220d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy        /*
221d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy         * Ideally, we would like to call mAdapter.notifyDataSetChanged() in a listener's
222d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy         * onAnimationEnd(), but we are in the middle of a touch event, and this will cause all the
223d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy         * views to get recycled, which will cause problems.
224d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy         *
225d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy         * Instead, we'll just leave the item in the list with a height of 0, and the next
226d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy         * notifyDatasetChanged() will remove it from the adapter.
227d6522ea881e80ab849f2a88565db5a6a73e7623eScott Kennedy         */
228c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
229c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
230c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    /**
231c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang     * This method is used by the animator.  It is explicitly kept in proguard.flags to prevent it
232c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang     * from being removed, inlined, or obfuscated.
233c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang     * Edit ./packages/apps/UnifiedEmail/proguard.flags
234c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang     * In the future, we want to use @Keep
235c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang     */
236c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    public void setAnimatedHeight(final int height) {
237c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        mAnimatedHeight = height;
238c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        requestLayout();
239c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
240c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang
241c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    @Override
242c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
243f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy        if (Utils.getDisplayListRightEdgeEffect(mTabletDevice, mListCollapsible,
244f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy                mAdapter.getViewMode())) {
245f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy            mTeaserRightEdge.setVisibility(VISIBLE);
246f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy        } else {
247f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy            mTeaserRightEdge.setVisibility(GONE);
248f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy        }
249f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy
250c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        if (mAnimatedHeight == -1) {
251c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
252c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        } else {
253c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang            setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mAnimatedHeight);
254c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang        }
255c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang    }
256c5567737cb40ca156ea89f169a23008524ebd1a4Alice Yang}
257