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