Merge "Create a require manual sync dialog." into ics-mr1

This commit is contained in:
Mindy Pereira 2011-11-01 16:51:37 -07:00 committed by Android (Google) Code Review
commit f4d30527c4
4 changed files with 111 additions and 1 deletions

View File

@ -1215,4 +1215,8 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
<!-- A long placeholder string to be used in template XML files message_list_item_*.xml.
Used only in layout computation, and never actually exposed to the user. -->
<string name="long_string" translatable="false">looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong</string>
<!-- This is the message warning the user that they must sync manually when roaming. [CHAR LIMIT=none]-->
<string name="require_manual_sync_message">Background sync for this account is disabled while\
roaming.</string>
</resources>

View File

@ -50,6 +50,7 @@ public class Preferences {
private static final String BACKGROUND_ATTACHMENTS = "backgroundAttachments";
private static final String TRUSTED_SENDERS = "trustedSenders";
private static final String LAST_ACCOUNT_USED = "lastAccountUsed";
private static final String REQUIRE_MANUAL_SYNC_DIALOG_SHOWN = "requireManualSyncDialogShown";
public static final int AUTO_ADVANCE_NEWER = 0;
public static final int AUTO_ADVANCE_OLDER = 1;
@ -287,6 +288,34 @@ public class Preferences {
.apply();
}
/**
* Gets whether the require manual sync dialog has been shown for the specified account.
* It should only be shown once per account.
*/
public boolean getHasShownRequireManualSync(Context context, Account account) {
return getBoolean(context, account.getEmailAddress(), REQUIRE_MANUAL_SYNC_DIALOG_SHOWN,
false);
}
/**
* Sets whether the require manual sync dialog has been shown for the specified account.
* It should only be shown once per account.
*/
public void setHasShownRequireManualSync(Context context, Account account, boolean value) {
setBoolean(context, account.getEmailAddress(), REQUIRE_MANUAL_SYNC_DIALOG_SHOWN, value);
}
/**
* Get whether to show the manual sync dialog. This dialog is shown when the user is roaming,
* connected to a mobile network, the administrator has set the RequireManualSyncWhenRoaming
* flag to true, and the dialog has not been shown before for the supplied account.
*/
public boolean shouldShowRequireManualSync(Context context, Account account) {
return Account.isAutomaticSyncDisabledByRoaming(context, account.mId)
&& !getHasShownRequireManualSync(context, account);
}
public void clear() {
mSharedPreferences.edit().clear().apply();
}
@ -298,4 +327,25 @@ public class Preferences {
}
}
}
/**
* Utility method for setting a boolean value on a per-account preference.
*/
private void setBoolean(Context context, String account, String key, Boolean value) {
mSharedPreferences.edit().putBoolean(makeKey(account, key), value).apply();
}
/**
* Utility method for getting a boolean value from a per-account preference.
*/
private boolean getBoolean(Context context, String account, String key, boolean def) {
return mSharedPreferences.getBoolean(makeKey(account, key), def);
}
/**
* Utility method for creating a per account preference key.
*/
private String makeKey(String account, String key) {
return account != null ? account + "-" + key : key;
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email;
import com.android.emailcommon.provider.Account;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources;
public class RequireManualSyncDialog extends AlertDialog implements OnClickListener {
public RequireManualSyncDialog(Context context, Account account) {
super(context);
setMessage(context.getResources().getString(R.string.require_manual_sync_message));
setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), this);
Preferences.getPreferences(context).setHasShownRequireManualSync(context, account, true);
}
/** {@inheritDoc} */
public void onClick(DialogInterface dialog, int which) {
// No-op.
}
}

View File

@ -32,6 +32,7 @@ import com.android.email.MessageListContext;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.RefreshManager;
import com.android.email.RequireManualSyncDialog;
import com.android.email.activity.setup.AccountSettings;
import com.android.email.activity.setup.MailboxSettings;
import com.android.emailcommon.Logging;
@ -206,7 +207,9 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
if (mNfcHandler != null) {
mNfcHandler.onAccountChanged(); // workaround for email not set on initial load
}
Preferences.getPreferences(mActivity).setLastUsedAccountId(getUIAccountId());
long accountId = getUIAccountId();
Preferences.getPreferences(mActivity).setLastUsedAccountId(accountId);
showAccountSpecificWarning(accountId);
}
/**
@ -558,6 +561,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
mNfcHandler.onAccountChanged();
}
Preferences.getPreferences(mActivity).setLastUsedAccountId(accountId);
showAccountSpecificWarning(accountId);
}
/**
@ -1017,6 +1021,18 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
}
}
private void showAccountSpecificWarning(long accountId) {
if (accountId != Account.NO_ACCOUNT && accountId != Account.NO_ACCOUNT) {
Account account = Account.restoreAccountWithId(mActivity, accountId);
if (account != null &&
Preferences.getPreferences(mActivity)
.shouldShowRequireManualSync(mActivity, account)) {
new RequireManualSyncDialog(mActivity, account).show();
}
}
}
@Override
public String toString() {
return getClass().getSimpleName(); // Shown on logcat