AccountSetupOutgoing.java revision a7bc0319a75184ad706bb35c049af107ac3688e6
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.activity.ActivityHelper;
21import com.android.emailcommon.provider.EmailContent.Account;
22
23import android.app.Activity;
24import android.app.FragmentTransaction;
25import android.content.Intent;
26import android.os.Bundle;
27import android.view.View;
28import android.view.View.OnClickListener;
29import android.widget.Button;
30
31/**
32 * Provides setup flow for SMTP (for IMAP/POP accounts).
33 *
34 * Uses AccountSetupOutgoingFragment for primary UI.  Uses AccountCheckSettingsFragment to validate
35 * the settings as entered.  If the account is OK, proceeds to AccountSetupOptions.
36 */
37public class AccountSetupOutgoing extends Activity
38        implements AccountSetupOutgoingFragment.Callback, OnClickListener {
39
40    /* package */ AccountSetupOutgoingFragment mFragment;
41    private Button mNextButton;
42    /* package */ boolean mNextButtonEnabled;
43
44    public static void actionOutgoingSettings(Activity fromActivity, int mode, Account account) {
45        SetupData.setFlowMode(mode);
46        SetupData.setAccount(account);
47        fromActivity.startActivity(new Intent(fromActivity, AccountSetupOutgoing.class));
48    }
49
50    @Override
51    public void onCreate(Bundle savedInstanceState) {
52        super.onCreate(savedInstanceState);
53        ActivityHelper.debugSetWindowFlags(this);
54        setContentView(R.layout.account_setup_outgoing);
55
56        mFragment = (AccountSetupOutgoingFragment)
57                getFragmentManager().findFragmentById(R.id.setup_fragment);
58
59        // Configure fragment
60        mFragment.setCallback(this);
61
62        mNextButton = (Button) findViewById(R.id.next);
63        mNextButton.setOnClickListener(this);
64        findViewById(R.id.previous).setOnClickListener(this);
65    }
66
67    /**
68     * Implements View.OnClickListener
69     */
70    @Override
71    public void onClick(View view) {
72        switch (view.getId()) {
73            case R.id.next:
74                mFragment.onNext();
75                break;
76            case R.id.previous:
77                onBackPressed();
78                break;
79        }
80    }
81
82    /**
83     * Implements AccountServerBaseFragment.Callback
84     *
85     * Launches the account checker.  Positive results are reported to onCheckSettingsOk().
86     */
87    public void onProceedNext(int checkMode, AccountServerBaseFragment target) {
88        AccountCheckSettingsFragment checkerFragment =
89            AccountCheckSettingsFragment.newInstance(checkMode, target);
90        FragmentTransaction transaction = getFragmentManager().beginTransaction();
91        transaction.add(checkerFragment, AccountCheckSettingsFragment.TAG);
92        transaction.addToBackStack("back");
93        transaction.commit();
94    }
95
96    /**
97     * Implements AccountServerBaseFragment.Callback
98     */
99    public void onEnableProceedButtons(boolean enable) {
100        mNextButtonEnabled = enable;
101        mNextButton.setEnabled(enable);
102    }
103
104    /**
105     * Implements AccountServerBaseFragment.Callback
106     *
107     * If the checked settings are OK, proceed to options screen
108     */
109    public void onCheckSettingsComplete(int result, int setupMode) {
110        if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
111            AccountSetupOptions.actionOptions(this);
112            finish();
113        }
114    }
115}
116