AccountSetupOptions.java revision 687f9962d7095e18ef994cd0e64337f02ed1a5bd
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.email.activity.setup;
18
19import android.app.Activity;
20import android.content.Context;
21import android.content.Intent;
22import android.os.Bundle;
23import android.view.View;
24import android.view.View.OnClickListener;
25import android.widget.ArrayAdapter;
26import android.widget.CheckBox;
27import android.widget.Spinner;
28
29import com.android.email.Account;
30import com.android.email.Email;
31import com.android.email.Preferences;
32import com.android.email.R;
33
34public class AccountSetupOptions extends Activity implements OnClickListener {
35    private static final String EXTRA_ACCOUNT = "account";
36
37    private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
38
39    private Spinner mCheckFrequencyView;
40
41    private CheckBox mDefaultView;
42
43    private CheckBox mNotifyView;
44
45    private Account mAccount;
46
47    public static void actionOptions(Context context, Account account, boolean makeDefault) {
48        Intent i = new Intent(context, AccountSetupOptions.class);
49        i.putExtra(EXTRA_ACCOUNT, account);
50        i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
51        context.startActivity(i);
52    }
53
54    @Override
55    public void onCreate(Bundle savedInstanceState) {
56        super.onCreate(savedInstanceState);
57        setContentView(R.layout.account_setup_options);
58
59        mCheckFrequencyView = (Spinner)findViewById(R.id.account_check_frequency);
60        mDefaultView = (CheckBox)findViewById(R.id.account_default);
61        mNotifyView = (CheckBox)findViewById(R.id.account_notify);
62
63        findViewById(R.id.next).setOnClickListener(this);
64
65        // NOTE: If you change these values, confirm that the new intervals exist in arrays.xml
66        // NOTE: It would be cleaner if the numeric values were obtained from  the
67        //       account_settings_check_frequency_values, array, so the options could be controlled
68        //       entirely via XML.
69        SpinnerOption checkFrequencies[] = {
70                new SpinnerOption(-1,
71                        getString(R.string.account_setup_options_mail_check_frequency_never)),
72                new SpinnerOption(5,
73                        getString(R.string.account_setup_options_mail_check_frequency_5min)),
74                new SpinnerOption(10,
75                        getString(R.string.account_setup_options_mail_check_frequency_10min)),
76                new SpinnerOption(15,
77                        getString(R.string.account_setup_options_mail_check_frequency_15min)),
78                new SpinnerOption(30,
79                        getString(R.string.account_setup_options_mail_check_frequency_30min)),
80                new SpinnerOption(60,
81                        getString(R.string.account_setup_options_mail_check_frequency_1hour)),
82        };
83
84        ArrayAdapter<SpinnerOption> checkFrequenciesAdapter = new ArrayAdapter<SpinnerOption>(this,
85                android.R.layout.simple_spinner_item, checkFrequencies);
86        checkFrequenciesAdapter
87                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
88        mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);
89
90        mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
91        boolean makeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
92
93        if (mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()) || makeDefault) {
94            mDefaultView.setChecked(true);
95        }
96        mNotifyView.setChecked(mAccount.isNotifyNewMail());
97        SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, mAccount
98                .getAutomaticCheckIntervalMinutes());
99    }
100
101    private void onDone() {
102        mAccount.setDescription(mAccount.getEmail());
103        mAccount.setNotifyNewMail(mNotifyView.isChecked());
104        mAccount.setAutomaticCheckIntervalMinutes((Integer)((SpinnerOption)mCheckFrequencyView
105                .getSelectedItem()).value);
106        mAccount.save(Preferences.getPreferences(this));
107        if (mDefaultView.isChecked()) {
108            Preferences.getPreferences(this).setDefaultAccount(mAccount);
109        }
110        Email.setServicesEnabled(this);
111        AccountSetupNames.actionSetNames(this, mAccount);
112        finish();
113    }
114
115    public void onClick(View v) {
116        switch (v.getId()) {
117            case R.id.next:
118                onDone();
119                break;
120        }
121    }
122}
123