am d85413e9
: Merge "Handle UI part of enforcing email lookback limit"
* commit 'd85413e946d19d11a53136780bf1ee255665f371': Handle UI part of enforcing email lookback limit
This commit is contained in:
commit
896d5e654a
@ -1262,6 +1262,10 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
|
||||
<!-- A policy requiring a maximum amount of time the device can sit idle before the lock screen
|
||||
is activated [CHAR LIMIT=50] -->
|
||||
<string name="policy_screen_timeout">Require an idle device to lock its screen</string>
|
||||
<!-- A policy limiting the number of old calendar events synced [CHAR LIMIT=50] -->
|
||||
<string name="policy_calendar_age">Limit the number of calendar events synced</string>
|
||||
<!-- A policy limiting the number of emails synced [CHAR LIMIT=50] -->
|
||||
<string name="policy_email_age">Limit the number of emails synced</string>
|
||||
|
||||
<!-- The four strings below represent "quick responses" which the user can insert into a
|
||||
message being composed with just a couple of taps. These four responses MUST be defined,
|
||||
|
@ -443,6 +443,12 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
||||
if (policy.mDontAllowCamera) {
|
||||
policies.add(res.getString(R.string.policy_dont_allow_camera));
|
||||
}
|
||||
if (policy.mMaxEmailLookback != 0) {
|
||||
policies.add(res.getString(R.string.policy_email_age));
|
||||
}
|
||||
if (policy.mMaxCalendarLookback != 0) {
|
||||
policies.add(res.getString(R.string.policy_calendar_age));
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
||||
@ -517,10 +523,9 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
||||
if (HostAuth.SCHEME_EAS.equals(protocol)) {
|
||||
mSyncWindow = new ListPreference(mContext);
|
||||
mSyncWindow.setTitle(R.string.account_setup_options_mail_window_label);
|
||||
mSyncWindow.setEntries(R.array.account_settings_mail_window_entries);
|
||||
mSyncWindow.setEntryValues(R.array.account_settings_mail_window_values);
|
||||
mSyncWindow.setValue(String.valueOf(mAccount.getSyncLookback()));
|
||||
mSyncWindow.setSummary(mSyncWindow.getEntry());
|
||||
MailboxSettings.setupLookbackPreferenceOptions(mContext, mSyncWindow, mAccount);
|
||||
|
||||
// Must correspond to the hole in the XML file that's reserved.
|
||||
mSyncWindow.setOrder(2);
|
||||
|
@ -44,6 +44,7 @@ import com.android.email.service.MailService;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Policy;
|
||||
import com.android.emailcommon.service.SyncWindow;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
@ -389,10 +390,24 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
||||
CharSequence[] windowEntries = getResources().getTextArray(
|
||||
R.array.account_settings_mail_window_entries);
|
||||
|
||||
// Find a proper maximum for email lookback, based on policy (if we have one)
|
||||
int maxEntry = windowEntries.length;
|
||||
Policy policy = SetupData.getAccount().mPolicy;
|
||||
if (policy != null) {
|
||||
int maxLookback = policy.mMaxEmailLookback;
|
||||
if (maxLookback != 0) {
|
||||
// Offset/Code 0 1 2 3 4 5
|
||||
// Entries auto, 1 day, 3 day, 1 week, 2 week, 1 month
|
||||
// Lookback N/A 1 day, 3 day, 1 week, 2 week, 1 month
|
||||
// Since our test below is i < maxEntry, we must set maxEntry to maxLookback + 1
|
||||
maxEntry = maxLookback + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Now create the array used by the Spinner
|
||||
SpinnerOption[] windowOptions = new SpinnerOption[windowEntries.length];
|
||||
SpinnerOption[] windowOptions = new SpinnerOption[maxEntry];
|
||||
int defaultIndex = -1;
|
||||
for (int i = 0; i < windowEntries.length; i++) {
|
||||
for (int i = 0; i < maxEntry; i++) {
|
||||
final int value = Integer.valueOf(windowValues[i].toString());
|
||||
windowOptions[i] = new SpinnerOption(value, windowEntries[i].toString());
|
||||
if (value == SYNC_WINDOW_EAS_DEFAULT) {
|
||||
|
@ -22,6 +22,7 @@ import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
@ -37,6 +38,7 @@ import com.android.email.R;
|
||||
import com.android.email.RefreshManager;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.Policy;
|
||||
import com.android.emailcommon.provider.EmailContent.AccountColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
@ -177,6 +179,42 @@ public class MailboxSettings extends PreferenceActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the entries and entry values for the sync lookback preference
|
||||
* @param context the caller's context
|
||||
* @param pref a ListPreference to be set up
|
||||
* @param account the Account (or owner of a Mailbox) whose preference is being set
|
||||
*/
|
||||
public static void setupLookbackPreferenceOptions(Context context, ListPreference pref,
|
||||
Account account) {
|
||||
Resources resources = context.getResources();
|
||||
// Load the complete list of entries/values
|
||||
CharSequence[] entries =
|
||||
resources.getTextArray(R.array.account_settings_mail_window_entries);
|
||||
CharSequence[] values =
|
||||
resources.getTextArray(R.array.account_settings_mail_window_values);
|
||||
// If we have a maximum lookback policy, enforce it
|
||||
if (account.mPolicyKey > 0) {
|
||||
Policy policy = Policy.restorePolicyWithId(context, account.mPolicyKey);
|
||||
if (policy != null && (policy.mMaxEmailLookback != 0)) {
|
||||
int maxEntry = policy.mMaxEmailLookback + 1;
|
||||
// Copy the proper number of values into new entries/values array
|
||||
CharSequence[] policyEntries = new CharSequence[maxEntry];
|
||||
CharSequence[] policyValues = new CharSequence[maxEntry];
|
||||
for (int i = 0; i < maxEntry; i++) {
|
||||
policyEntries[i] = entries[i];
|
||||
policyValues[i] = values[i];
|
||||
}
|
||||
// Point entries/values to the new arrays
|
||||
entries = policyEntries;
|
||||
values = policyValues;
|
||||
}
|
||||
}
|
||||
// Set up the preference
|
||||
pref.setEntries(entries);
|
||||
pref.setEntryValues(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when {@link #mAccount} and {@link #mMailbox} are loaded (either by the async task
|
||||
* or from the saved state).
|
||||
@ -195,12 +233,7 @@ public class MailboxSettings extends PreferenceActivity {
|
||||
setTitle(getString(R.string.mailbox_settings_activity_title_with_mailbox, mailboxName));
|
||||
}
|
||||
|
||||
|
||||
// Special case: If setting inbox, don't show "Use account's default".
|
||||
if (mMailbox.mType == Mailbox.TYPE_INBOX) {
|
||||
mSyncLookbackPref.setEntries(R.array.account_settings_mail_window_entries);
|
||||
mSyncLookbackPref.setEntryValues(R.array.account_settings_mail_window_values);
|
||||
}
|
||||
setupLookbackPreferenceOptions(this, mSyncLookbackPref, mAccount);
|
||||
|
||||
// Set default value & update summary
|
||||
mSyncIntervalPref.setValue(String.valueOf(getSyncInterval()));
|
||||
@ -210,7 +243,6 @@ public class MailboxSettings extends PreferenceActivity {
|
||||
|
||||
// Make then enabled
|
||||
enablePreferences(true);
|
||||
|
||||
}
|
||||
|
||||
private void updatePreferenceSummary() {
|
||||
|
Loading…
Reference in New Issue
Block a user