replicant-packages_apps_Email/src/com/android/email/activity/setup/AccountSetupOptions.java

167 lines
7.1 KiB
Java

/*
* Copyright (C) 2008 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.activity.setup;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.mail.Store;
import com.android.email.provider.EmailContent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Spinner;
public class AccountSetupOptions extends Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
private Spinner mCheckFrequencyView;
private Spinner mSyncWindowView;
private CheckBox mDefaultView;
private CheckBox mNotifyView;
private EmailContent.Account mAccount;
public static void actionOptions(Activity fromActivity, EmailContent.Account account,
boolean makeDefault) {
Intent i = new Intent(fromActivity, AccountSetupOptions.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
fromActivity.startActivity(i);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_options);
mCheckFrequencyView = (Spinner)findViewById(R.id.account_check_frequency);
mSyncWindowView = (Spinner) findViewById(R.id.account_sync_window);
mDefaultView = (CheckBox)findViewById(R.id.account_default);
mNotifyView = (CheckBox)findViewById(R.id.account_notify);
findViewById(R.id.next).setOnClickListener(this);
mAccount = (EmailContent.Account) getIntent().getParcelableExtra(EXTRA_ACCOUNT);
boolean makeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
// Generate spinner entries using XML arrays used by the preferences
int frequencyValuesId;
int frequencyEntriesId;
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(mAccount.getStoreUri(this), this);
if (info.mPushSupported) {
frequencyValuesId = R.array.account_settings_check_frequency_values_push;
frequencyEntriesId = R.array.account_settings_check_frequency_entries_push;
} else {
frequencyValuesId = R.array.account_settings_check_frequency_values;
frequencyEntriesId = R.array.account_settings_check_frequency_entries;
}
CharSequence[] frequencyValues = getResources().getTextArray(frequencyValuesId);
CharSequence[] frequencyEntries = getResources().getTextArray(frequencyEntriesId);
// Now create the array used by the Spinner
SpinnerOption[] checkFrequencies = new SpinnerOption[frequencyEntries.length];
for (int i = 0; i < frequencyEntries.length; i++) {
checkFrequencies[i] = new SpinnerOption(
Integer.valueOf(frequencyValues[i].toString()), frequencyEntries[i].toString());
}
ArrayAdapter<SpinnerOption> checkFrequenciesAdapter = new ArrayAdapter<SpinnerOption>(this,
android.R.layout.simple_spinner_item, checkFrequencies);
checkFrequenciesAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);
if (info.mVisibleLimitDefault == -1) {
enableEASSyncWindowSpinner();
}
// Note: It is OK to use mAccount.mIsDefault here *only* because the account
// has not been written to the DB yet. Ordinarily, call Account.getDefaultAccountId().
if (mAccount.mIsDefault || makeDefault) {
mDefaultView.setChecked(true);
}
mNotifyView.setChecked(
(mAccount.getFlags() & EmailContent.Account.FLAGS_NOTIFY_NEW_MAIL) != 0);
SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, mAccount
.getAutomaticCheckIntervalMinutes());
}
private void onDone() {
mAccount.setDescription(mAccount.getEmail());
int newFlags = mAccount.getFlags() & ~(EmailContent.Account.FLAGS_NOTIFY_NEW_MAIL);
if (mNotifyView.isChecked()) {
newFlags |= EmailContent.Account.FLAGS_NOTIFY_NEW_MAIL;
}
mAccount.setFlags(newFlags);
mAccount.setAutomaticCheckIntervalMinutes((Integer)((SpinnerOption)mCheckFrequencyView
.getSelectedItem()).value);
if (mSyncWindowView.getVisibility() == View.VISIBLE) {
int window = (Integer)((SpinnerOption)mSyncWindowView.getSelectedItem()).value;
mAccount.setSyncWindow(window);
}
mAccount.setDefaultAccount(mDefaultView.isChecked());
mAccount.saveOrUpdate(this);
Email.setServicesEnabled(this);
AccountSetupNames.actionSetNames(this, mAccount.mId);
finish();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.next:
onDone();
break;
}
}
/**
* Enable an additional spinner using the arrays normally handled by preferences
*/
private void enableEASSyncWindowSpinner() {
// Show everything
findViewById(R.id.account_sync_window_label).setVisibility(View.VISIBLE);
mSyncWindowView.setVisibility(View.VISIBLE);
// Generate spinner entries using XML arrays used by the preferences
CharSequence[] windowValues = getResources().getTextArray(
R.array.account_settings_mail_window_values);
CharSequence[] windowEntries = getResources().getTextArray(
R.array.account_settings_mail_window_entries);
// Now create the array used by the Spinner
SpinnerOption[] windowOptions = new SpinnerOption[windowEntries.length];
for (int i = 0; i < windowEntries.length; i++) {
windowOptions[i] = new SpinnerOption(
Integer.valueOf(windowValues[i].toString()), windowEntries[i].toString());
}
ArrayAdapter<SpinnerOption> windowOptionsAdapter = new ArrayAdapter<SpinnerOption>(this,
android.R.layout.simple_spinner_item, windowOptions);
windowOptionsAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSyncWindowView.setAdapter(windowOptionsAdapter);
SpinnerOption.setSpinnerOptionValue(mSyncWindowView, mAccount.getSyncWindow());
}
}