AccountSetupOutgoing.java revision 5b2424bf6f32fdfd65b02a9a311e7226dc48f1c1
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 com.android.email.R;
20import com.android.email.provider.EmailContent.Account;
21
22import android.app.Activity;
23import android.app.FragmentTransaction;
24import android.content.Intent;
25import android.os.Bundle;
26
27/**
28 * Provides setup flow for SMTP (for IMAP/POP accounts).
29 *
30 * Uses AccountSetupOutgoingFragment for primary UI.  Uses AccountCheckSettingsFragment to validate
31 * the settings as entered.  If the account is OK, proceeds to AccountSetupOptions.
32 */
33public class AccountSetupOutgoing extends Activity
34        implements AccountSetupOutgoingFragment.Callback {
35
36    private AccountSetupOutgoingFragment mFragment;
37    /* package */ boolean mNextButtonEnabled;
38
39    public static void actionOutgoingSettings(Activity fromActivity, int mode, Account account) {
40        SetupData.setFlowMode(mode);
41        SetupData.setAccount(account);
42        fromActivity.startActivity(new Intent(fromActivity, AccountSetupOutgoing.class));
43    }
44
45    @Override
46    public void onCreate(Bundle savedInstanceState) {
47        super.onCreate(savedInstanceState);
48        setContentView(R.layout.account_setup_outgoing);
49
50        mFragment = (AccountSetupOutgoingFragment)
51                getFragmentManager().findFragmentById(R.id.setup_fragment);
52
53        // Configure fragment
54        mFragment.setCallback(this);
55    }
56
57    /**
58     * Implements AccountServerBaseFragment.Callback
59     *
60     * Launches the account checker.  Positive results are reported to onCheckSettingsOk().
61     */
62    public void onProceedNext(int checkMode, AccountServerBaseFragment target) {
63        AccountCheckSettingsFragment checkerFragment =
64            AccountCheckSettingsFragment.newInstance(checkMode, target);
65        FragmentTransaction transaction = getFragmentManager().openTransaction();
66        transaction.replace(R.id.setup_fragment, checkerFragment);
67        transaction.addToBackStack("back");
68        transaction.commit();
69    }
70
71    /**
72     * Implements AccountServerBaseFragment.Callback
73     */
74    public void onEnableProceedButtons(boolean enable) {
75        boolean wasEnabled = mNextButtonEnabled;
76        mNextButtonEnabled = enable;
77
78        if (enable != wasEnabled) {
79            invalidateOptionsMenu();
80        }
81    }
82
83    /**
84     * Implements AccountServerBaseFragment.Callback
85     *
86     * If the checked settings are OK, proceed to options screen
87     */
88    public void onCheckSettingsComplete(int result, int setupMode) {
89        if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
90            AccountSetupOptions.actionOptions(this);
91            finish();
92        }
93    }
94}
95