AccountSetupIncoming.java revision 1b156352f3fc160da5ba050c2437bcd1c995b326
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.Utility;
21import com.android.email.provider.EmailContent;
22
23import android.app.Activity;
24import android.content.Intent;
25import android.os.Bundle;
26import android.view.View;
27import android.view.View.OnClickListener;
28import android.widget.Button;
29
30public class AccountSetupIncoming extends AccountSetupActivity
31        implements OnClickListener, AccountSetupIncomingFragment.Callback {
32
33    private AccountSetupIncomingFragment mFragment;
34    private Button mNextButton;
35
36    public static void actionIncomingSettings(Activity fromActivity, int mode,
37            EmailContent.Account account) {
38        SetupData.init(mode, account);
39        fromActivity.startActivity(new Intent(fromActivity, AccountSetupIncoming.class));
40    }
41
42    public static void actionEditIncomingSettings(Activity fromActivity, int mode,
43            EmailContent.Account account) {
44        actionIncomingSettings(fromActivity, mode, account);
45    }
46
47    @Override
48    public void onCreate(Bundle savedInstanceState) {
49        super.onCreate(savedInstanceState);
50        setContentView(R.layout.account_setup_incoming);
51
52        mFragment = (AccountSetupIncomingFragment) findFragmentById(R.id.setup_incoming_fragment);
53        mNextButton = (Button)findViewById(R.id.next);
54        mNextButton.setOnClickListener(this);
55
56        // Configure fragment
57        mFragment.setCallback(this);
58   }
59
60    /**
61     * After verifying a new server configuration, we return here and continue.  If editing an
62     * existing account, we simply finish().  If creating a new account, we move to the next phase.
63     */
64    @Override
65    public void onActivityResult(int requestCode, int resultCode, Intent data) {
66        if (resultCode == RESULT_OK) {
67            if (SetupData.getFlowMode() == SetupData.FLOW_MODE_EDIT) {
68                mFragment.saveSettingsAfterEdit();
69            } else {
70                mFragment.saveSettingsAfterSetup();
71                AccountSetupOutgoing.actionOutgoingSettings(this, SetupData.getFlowMode(),
72                        SetupData.getAccount());
73            }
74            finish();
75        }
76    }
77
78    /**
79     * When the user clicks "next", notify the fragment that it's time to prepare the new
80     * settings to be tested.  This will call back via onProceedNext() to actually launch the test.
81     */
82    public void onClick(View v) {
83        switch (v.getId()) {
84            case R.id.next:
85                mFragment.onNext();
86                break;
87        }
88    }
89
90    /**
91     * Implements AccountSetupIncomingFragment.Listener
92     */
93    public void onProceedNext() {
94        AccountSetupCheckSettings.actionCheckSettings(this, SetupData.CHECK_INCOMING);
95    }
96
97    /**
98     * Implements AccountSetupIncomingFragment.Listener
99     */
100    public void onEnableProceedButtons(boolean enabled) {
101        mNextButton.setEnabled(enabled);
102        // Dim the next button's icon to 50% if the button is disabled.
103        // TODO this can probably be done with a stateful drawable. (check android:state_enabled
104        Utility.setCompoundDrawablesAlpha(mNextButton, enabled ? 255 : 128);
105    }
106}
107