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 17c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangpackage com.android.mail.ui; 18c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 19272900135906067c383b0960881293f769114494Scott Kennedyimport android.animation.Animator; 20c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.animation.ObjectAnimator; 21272900135906067c383b0960881293f769114494Scott Kennedyimport android.animation.Animator.AnimatorListener; 22ce7f645638c56e097781664c101fac392b6072e1Alice Yangimport android.app.Activity; 23c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.app.LoaderManager; 24c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.content.ContentResolver; 25c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.content.Context; 26c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.content.res.Resources; 2732ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedyimport android.os.Bundle; 280e627fd594f3809e2bede76379a3348267185196Alice Yangimport android.text.SpannableString; 29db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yangimport android.text.TextUtils; 300e627fd594f3809e2bede76379a3348267185196Alice Yangimport android.text.style.TextAppearanceSpan; 31c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.util.AttributeSet; 32c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.view.View; 33c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.view.animation.DecelerateInterpolator; 34c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.widget.FrameLayout; 35c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport android.widget.TextView; 36c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 37c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport com.android.mail.R; 38042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huangimport com.android.mail.analytics.Analytics; 39c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport com.android.mail.browse.ConversationCursor; 40c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport com.android.mail.preferences.AccountPreferences; 41174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yangimport com.android.mail.preferences.MailPrefs; 42c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport com.android.mail.providers.Account; 43c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport com.android.mail.providers.Folder; 44174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yangimport com.android.mail.utils.LogTag; 45174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yangimport com.android.mail.utils.LogUtils; 46c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangimport com.android.mail.utils.Utils; 47c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 48c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang/** 49c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * A tip displayed on top of conversation view to indicate that Gmail sync is 50c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * currently disabled on this account. 51c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang */ 52c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yangpublic class ConversationSyncDisabledTipView extends FrameLayout 53c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang implements ConversationSpecialItemView, SwipeableItemView { 54c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 55174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private static final String LOG_TAG = LogTag.getLogTag(); 56174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 57c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private static int sScrollSlop = 0; 58c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private static int sShrinkAnimationDuration; 59c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 60c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private Account mAccount = null; 610e627fd594f3809e2bede76379a3348267185196Alice Yang private Folder mFolder = null; 62174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private final MailPrefs mMailPrefs; 63c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private AccountPreferences mAccountPreferences; 64c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private AnimatedAdapter mAdapter; 65ce7f645638c56e097781664c101fac392b6072e1Alice Yang private Activity mActivity; 66c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 67c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private View mSwipeableContent; 68174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private TextView mText1; 69174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private TextView mText2; 700e627fd594f3809e2bede76379a3348267185196Alice Yang private View mTextArea; 710e627fd594f3809e2bede76379a3348267185196Alice Yang private SpannableString mEnableSyncInAccountSettingsText; 72174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private final OnClickListener mAutoSyncOffTextClickedListener; 73174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private final OnClickListener mAccountSyncOffTextClickedListener; 74c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 75c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private int mAnimatedHeight = -1; 76c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 77174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private int mReasonSyncOff = ReasonSyncOff.NONE; 78174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 791591414ed6dc829852edd219c39ae430314ff538Scott Kennedy private View mTeaserRightEdge; 801591414ed6dc829852edd219c39ae430314ff538Scott Kennedy /** Whether we are on a tablet device or not */ 811591414ed6dc829852edd219c39ae430314ff538Scott Kennedy private final boolean mTabletDevice; 821591414ed6dc829852edd219c39ae430314ff538Scott Kennedy /** When in conversation mode, true if the list is hidden */ 831591414ed6dc829852edd219c39ae430314ff538Scott Kennedy private final boolean mListCollapsible; 841591414ed6dc829852edd219c39ae430314ff538Scott Kennedy 85174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang public interface ReasonSyncOff { 86174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Background sync is enabled for current account, do not display this tip 87174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang public static final int NONE = 0; 88174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Global auto-sync (affects all apps and all accounts) is turned off 89174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang public static final int AUTO_SYNC_OFF = 1; 90174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Global auto-sync is on, but Gmail app level sync is disabled for this particular account 91174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang public static final int ACCOUNT_SYNC_OFF = 2; 92174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 93174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 94c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public ConversationSyncDisabledTipView(final Context context) { 95c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang this(context, null); 96c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 97c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 98c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public ConversationSyncDisabledTipView(final Context context, final AttributeSet attrs) { 99c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang this(context, attrs, -1); 100c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 101c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 102c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public ConversationSyncDisabledTipView( 103c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang final Context context, final AttributeSet attrs, final int defStyle) { 104c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang super(context, attrs, defStyle); 105c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 106c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang final Resources resources = context.getResources(); 107c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 108c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang if (sScrollSlop == 0) { 109c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang sScrollSlop = resources.getInteger(R.integer.swipeScrollSlop); 110c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang sShrinkAnimationDuration = resources.getInteger( 111c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang R.integer.shrink_animation_duration); 112c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 113174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 114174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mMailPrefs = MailPrefs.get(context); 115174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 116174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mAutoSyncOffTextClickedListener = new OnClickListener() { 117174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang @Override 118174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang public void onClick(View v) { 119ce7f645638c56e097781664c101fac392b6072e1Alice Yang final TurnAutoSyncOnDialog dialog = TurnAutoSyncOnDialog.newInstance( 1203e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler mAccount.getAccountManagerAccount(), mAccount.syncAuthority); 121ce7f645638c56e097781664c101fac392b6072e1Alice Yang dialog.show(mActivity.getFragmentManager(), TurnAutoSyncOnDialog.DIALOG_TAG); 122174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 123174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang }; 124174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 125174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mAccountSyncOffTextClickedListener = new OnClickListener() { 126174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang @Override 127174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang public void onClick(View v) { 1280e627fd594f3809e2bede76379a3348267185196Alice Yang Utils.showAccountSettings(getContext(), mAccount); 129174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 130174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang }; 1310e627fd594f3809e2bede76379a3348267185196Alice Yang 1320e627fd594f3809e2bede76379a3348267185196Alice Yang // Create the "Turn on in Account settings." text where "Account settings" appear as 1330e627fd594f3809e2bede76379a3348267185196Alice Yang // a blue link. 1340e627fd594f3809e2bede76379a3348267185196Alice Yang final String subString = resources.getString(R.string.account_settings_param); 1350e627fd594f3809e2bede76379a3348267185196Alice Yang final String entireString = resources.getString( 1360e627fd594f3809e2bede76379a3348267185196Alice Yang R.string.enable_sync_in_account_settings, subString); 1370e627fd594f3809e2bede76379a3348267185196Alice Yang mEnableSyncInAccountSettingsText = new SpannableString(entireString); 1380e627fd594f3809e2bede76379a3348267185196Alice Yang final int index = entireString.indexOf(subString); 1390e627fd594f3809e2bede76379a3348267185196Alice Yang mEnableSyncInAccountSettingsText.setSpan( 1400e627fd594f3809e2bede76379a3348267185196Alice Yang new TextAppearanceSpan(context, R.style.LinksInTipTextAppearance), 1410e627fd594f3809e2bede76379a3348267185196Alice Yang index, 1420e627fd594f3809e2bede76379a3348267185196Alice Yang index + subString.length(), 1430e627fd594f3809e2bede76379a3348267185196Alice Yang 0); 1441591414ed6dc829852edd219c39ae430314ff538Scott Kennedy 1451591414ed6dc829852edd219c39ae430314ff538Scott Kennedy mTabletDevice = Utils.useTabletUI(resources); 1461591414ed6dc829852edd219c39ae430314ff538Scott Kennedy mListCollapsible = resources.getBoolean(R.bool.list_collapsible); 147c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 148c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 149ce7f645638c56e097781664c101fac392b6072e1Alice Yang public void bindAccount(Account account, ControllableActivity activity) { 150c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang mAccount = account; 151afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler mAccountPreferences = AccountPreferences.get(getContext(), account.getEmailAddress()); 152ce7f645638c56e097781664c101fac392b6072e1Alice Yang mActivity = (Activity) activity; 153c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 154c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 155c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 156f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy public void onGetView() { 157f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy // Do nothing 1585fa9ab969f614def668a963eba9c926b0a5ee11fAlice Yang } 1595fa9ab969f614def668a963eba9c926b0a5ee11fAlice Yang 1605fa9ab969f614def668a963eba9c926b0a5ee11fAlice Yang @Override 161c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang protected void onFinishInflate() { 162c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang mSwipeableContent = findViewById(R.id.swipeable_content); 163c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 164174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mText1 = (TextView) findViewById(R.id.text_line1); 165174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mText2 = (TextView) findViewById(R.id.text_line2); 1660e627fd594f3809e2bede76379a3348267185196Alice Yang mTextArea = findViewById(R.id.text_area); 167c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 168c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang findViewById(R.id.dismiss_button).setOnClickListener(new OnClickListener() { 169c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 170c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public void onClick(View v) { 171c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang dismiss(); 172c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 173c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang }); 1741591414ed6dc829852edd219c39ae430314ff538Scott Kennedy 1751591414ed6dc829852edd219c39ae430314ff538Scott Kennedy mTeaserRightEdge = findViewById(R.id.teaser_right_edge); 176c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 177c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 178c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 1790e8dc84326ad3e6d146a203538665f98dd98f688Scott Kennedy public void onUpdate(Folder folder, ConversationCursor cursor) { 1800e627fd594f3809e2bede76379a3348267185196Alice Yang mFolder = folder; 181c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 182c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 183c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 184c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public boolean getShouldDisplayInList() { 185c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang if (mAccount == null || mAccount.syncAuthority == null) { 186c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang return false; 187c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 188174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 1890e627fd594f3809e2bede76379a3348267185196Alice Yang // Do not show this message for folders/labels that are not set to sync. 1900e627fd594f3809e2bede76379a3348267185196Alice Yang if (mFolder == null || mFolder.syncWindow <= 0) { 1910e627fd594f3809e2bede76379a3348267185196Alice Yang return false; 1920e627fd594f3809e2bede76379a3348267185196Alice Yang } 193174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 1940e8dc84326ad3e6d146a203538665f98dd98f688Scott Kennedy setReasonSyncOff(calculateReasonSyncOff(mMailPrefs, mAccount, mAccountPreferences)); 195174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 196174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang if (mReasonSyncOff != ReasonSyncOff.NONE) { 197174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang LogUtils.i(LOG_TAG, "Sync is off with reason %d", mReasonSyncOff); 198174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 199174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 200174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang switch (mReasonSyncOff) { 201174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang case ReasonSyncOff.AUTO_SYNC_OFF: 202174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang return (mMailPrefs.getNumOfDismissesForAutoSyncOff() == 0); 203174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang case ReasonSyncOff.ACCOUNT_SYNC_OFF: 204174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang return (mAccountPreferences.getNumOfDismissesForAccountSyncOff() == 0); 205174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang default: 206174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang return false; 207174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 208174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 209174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 2100e8dc84326ad3e6d146a203538665f98dd98f688Scott Kennedy public static int calculateReasonSyncOff(MailPrefs mailPrefs, 211174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang Account account, AccountPreferences accountPreferences) { 212174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang if (!ContentResolver.getMasterSyncAutomatically()) { 213174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Global sync is turned off 214174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang accountPreferences.resetNumOfDismissesForAccountSyncOff(); 2150e627fd594f3809e2bede76379a3348267185196Alice Yang // Logging to track down bug where this tip is being showing when it shouldn't be. 2160e627fd594f3809e2bede76379a3348267185196Alice Yang LogUtils.i(LOG_TAG, "getMasterSyncAutomatically() return false"); 217174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang return ReasonSyncOff.AUTO_SYNC_OFF; 218c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } else { 219174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Global sync is on, clear the number of times users has dismissed this 220174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // warning so that next time global sync is off, warning gets displayed again. 221174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mailPrefs.resetNumOfDismissesForAutoSyncOff(); 222174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 223174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Now check for whether account level sync is on/off. 2243e16687b074895bc6cc63a1ed93abf7033586fd2Tony Mantler android.accounts.Account acct = account.getAccountManagerAccount(); 225db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang if (!TextUtils.isEmpty(account.syncAuthority) && 226db77b36aa9bdda2ebadccc4188715563a95f9bf0Alice Yang !ContentResolver.getSyncAutomatically(acct, account.syncAuthority)) { 227174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Account level sync is off 228174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang return ReasonSyncOff.ACCOUNT_SYNC_OFF; 229174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } else { 230174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Account sync is on, clear the number of times users has dismissed this 231174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // warning so that next time sync is off, warning gets displayed again. 232174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang accountPreferences.resetNumOfDismissesForAccountSyncOff(); 23388efa47f9833e2cb091fa033a55573b0d637dac9Alice Yang return ReasonSyncOff.NONE; 234174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 235174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 236174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 237174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang 238174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang private void setReasonSyncOff(int reason) { 239174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang if (mReasonSyncOff != reason) { 240174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mReasonSyncOff = reason; 241174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang switch (mReasonSyncOff) { 242174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang case ReasonSyncOff.AUTO_SYNC_OFF: 243174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mText1.setText(R.string.auto_sync_off); 2440e627fd594f3809e2bede76379a3348267185196Alice Yang mText2.setText(R.string.tap_to_enable_sync); 245174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mText2.setVisibility(View.VISIBLE); 2460e627fd594f3809e2bede76379a3348267185196Alice Yang mTextArea.setClickable(true); 2470e627fd594f3809e2bede76379a3348267185196Alice Yang mTextArea.setOnClickListener(mAutoSyncOffTextClickedListener); 248174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang break; 249174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang case ReasonSyncOff.ACCOUNT_SYNC_OFF: 250174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mText1.setText(R.string.account_sync_off); 2510e627fd594f3809e2bede76379a3348267185196Alice Yang mText2.setText(mEnableSyncInAccountSettingsText); 252174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mText2.setVisibility(View.VISIBLE); 2530e627fd594f3809e2bede76379a3348267185196Alice Yang mTextArea.setClickable(true); 2540e627fd594f3809e2bede76379a3348267185196Alice Yang mTextArea.setOnClickListener(mAccountSyncOffTextClickedListener); 255174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang break; 256174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang default: 257174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang // Doesn't matter what mText is since this view is not displayed 258174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 259c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 260c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 261c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 262c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 263c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public int getPosition() { 264c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang // We want this teaser to go before the first real conversation 2656c9845ed223ceaefd2b6e7511d04b038d63de8b3Alice Yang return 0; 266c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 267c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 268c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 269c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public void setAdapter(AnimatedAdapter adapter) { 270c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang mAdapter = adapter; 271c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 272c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 273c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 27432ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy public void bindFragment(LoaderManager loaderManager, final Bundle savedInstanceState) { 275c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 276c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 277c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 278c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public void cleanup() { 279c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 280c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 281c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 282c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public void onConversationSelected() { 283c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang // DO NOTHING 284c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 285c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 286c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 287c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public void onCabModeEntered() { 288c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 289c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 290c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 291cc139833bc5829ba70244519e9870de783c41848Scott Kennedy public void onCabModeExited() { 292cc139833bc5829ba70244519e9870de783c41848Scott Kennedy // Do nothing 293cc139833bc5829ba70244519e9870de783c41848Scott Kennedy } 294cc139833bc5829ba70244519e9870de783c41848Scott Kennedy 295cc139833bc5829ba70244519e9870de783c41848Scott Kennedy @Override 29632ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy public void onConversationListVisibilityChanged(final boolean visible) { 29732ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy // Do nothing 29832ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy } 29932ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy 30032ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy @Override 30132ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy public void saveInstanceState(final Bundle outState) { 30232ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy // Do nothing 30332ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy } 30432ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy 30532ddb84f2d4f53bfc4b53656461068c0c69d6325Scott Kennedy @Override 306c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public boolean acceptsUserTaps() { 3070e627fd594f3809e2bede76379a3348267185196Alice Yang return true; 308c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 309c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 310c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 311c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public void dismiss() { 312042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huang final String reason; 313174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang switch (mReasonSyncOff) { 314174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang case ReasonSyncOff.AUTO_SYNC_OFF: 315174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mMailPrefs.incNumOfDismissesForAutoSyncOff(); 316042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huang reason = "auto_sync_off"; 317174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang break; 318174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang case ReasonSyncOff.ACCOUNT_SYNC_OFF: 319174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang mAccountPreferences.incNumOfDismissesForAccountSyncOff(); 320042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huang reason = "account_sync_off"; 321174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang break; 322042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huang default: 323042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huang reason = null; 324174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang break; 325174b5d5afdaea22df9fc52b52082e36cd7fd6923Alice Yang } 326042a530b2296487fa5899a3e871214ac4a47e3d8Andy Huang Analytics.getInstance().sendEvent("list_swipe", "sync_disabled_tip", reason, 0); 327c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang startDestroyAnimation(); 328c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 329c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 330c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 331c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public SwipeableView getSwipeableView() { 332c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang return SwipeableView.from(mSwipeableContent); 333c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 334c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 335c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 336c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public boolean canChildBeDismissed() { 337c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang return true; 338c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 339c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 340c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 341c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public float getMinAllowScrollDistance() { 342c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang return sScrollSlop; 343c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 344c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 345c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang private void startDestroyAnimation() { 346c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang final int start = getHeight(); 347c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang final int end = 0; 348c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang mAnimatedHeight = start; 349c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang final ObjectAnimator heightAnimator = 350c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang ObjectAnimator.ofInt(this, "animatedHeight", start, end); 351c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang heightAnimator.setInterpolator(new DecelerateInterpolator(2.0f)); 352c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang heightAnimator.setDuration(sShrinkAnimationDuration); 353272900135906067c383b0960881293f769114494Scott Kennedy heightAnimator.addListener(new AnimatorListener() { 354272900135906067c383b0960881293f769114494Scott Kennedy @Override 355272900135906067c383b0960881293f769114494Scott Kennedy public void onAnimationStart(final Animator animation) { 356272900135906067c383b0960881293f769114494Scott Kennedy // Do nothing 357272900135906067c383b0960881293f769114494Scott Kennedy } 358272900135906067c383b0960881293f769114494Scott Kennedy 359272900135906067c383b0960881293f769114494Scott Kennedy @Override 360272900135906067c383b0960881293f769114494Scott Kennedy public void onAnimationRepeat(final Animator animation) { 361272900135906067c383b0960881293f769114494Scott Kennedy // Do nothing 362272900135906067c383b0960881293f769114494Scott Kennedy } 363272900135906067c383b0960881293f769114494Scott Kennedy 364272900135906067c383b0960881293f769114494Scott Kennedy @Override 365272900135906067c383b0960881293f769114494Scott Kennedy public void onAnimationEnd(final Animator animation) { 366272900135906067c383b0960881293f769114494Scott Kennedy // We should no longer exist, so notify the adapter 367272900135906067c383b0960881293f769114494Scott Kennedy mAdapter.notifyDataSetChanged(); 368272900135906067c383b0960881293f769114494Scott Kennedy } 369272900135906067c383b0960881293f769114494Scott Kennedy 370272900135906067c383b0960881293f769114494Scott Kennedy @Override 371272900135906067c383b0960881293f769114494Scott Kennedy public void onAnimationCancel(final Animator animation) { 372272900135906067c383b0960881293f769114494Scott Kennedy // Do nothing 373272900135906067c383b0960881293f769114494Scott Kennedy } 374272900135906067c383b0960881293f769114494Scott Kennedy }); 375c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang heightAnimator.start(); 376c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 377c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 378c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang /** 379c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * This method is used by the animator. It is explicitly kept in proguard.flags to prevent it 380c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * from being removed, inlined, or obfuscated. 381c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * Edit ./vendor/unbundled/packages/apps/UnifiedGmail/proguard.flags 382c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang * In the future, we want to use @Keep 383c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang */ 384c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang public void setAnimatedHeight(final int height) { 385c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang mAnimatedHeight = height; 386c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang requestLayout(); 387c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 388c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang 389c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang @Override 390c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { 391f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy if (Utils.getDisplayListRightEdgeEffect(mTabletDevice, mListCollapsible, 392f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy mAdapter.getViewMode())) { 393f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy mTeaserRightEdge.setVisibility(VISIBLE); 394f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy } else { 395f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy mTeaserRightEdge.setVisibility(GONE); 396f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy } 397f45e0e7f65eb421fc5c2acf7bb76a714e12dc68bScott Kennedy 398c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang if (mAnimatedHeight == -1) { 399c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang super.onMeasure(widthMeasureSpec, heightMeasureSpec); 400c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } else { 401c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mAnimatedHeight); 402c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 403c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang } 404c86b1fbcea43513ea903bb2ca14573423a72d7b5Alice Yang} 405