AccountSetupBasics.java revision 57f125a01b5fbb5860b144b3057153a50d07ddd1
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.VendorPolicyLoader; 22import com.android.email.activity.ActivityHelper; 23import com.android.email.activity.Welcome; 24import com.android.email.provider.EmailContent.Account; 25 26import android.app.Activity; 27import android.content.Context; 28import android.content.Intent; 29import android.os.Bundle; 30import android.view.View; 31import android.view.View.OnClickListener; 32import android.widget.Button; 33 34/** 35 * Prompts the user for the email address and password. Also prompts for 36 * "Use this account as default" if this is the 2nd+ account being set up. 37 * Attempts to lookup default settings for the domain the user specified. If the 38 * domain is known the settings are handed off to the AccountSetupCheckSettings 39 * activity. If no settings are found the settings are handed off to the 40 * AccountSetupAccountType activity. 41 */ 42public class AccountSetupBasics extends AccountSetupActivity 43 implements OnClickListener, AccountSetupBasicsFragment.Callback { 44 45 private AccountSetupBasicsFragment mFragment; 46 private Button mNextButton; 47 private Button mManualSetupButton; 48 49 public static void actionNewAccount(Activity fromActivity) { 50 SetupData.init(SetupData.FLOW_MODE_NORMAL); 51 fromActivity.startActivity(new Intent(fromActivity, AccountSetupBasics.class)); 52 } 53 54 public static void actionNewAccountWithCredentials(Activity fromActivity, 55 String username, String password, int accountFlowMode) { 56 SetupData.init(accountFlowMode, username, password); 57 fromActivity.startActivity(new Intent(fromActivity, AccountSetupBasics.class)); 58 } 59 60 /** 61 * This generates setup data that can be used to start a self-contained account creation flow 62 * for exchange accounts. 63 */ 64 public static Intent actionSetupExchangeIntent(Context context) { 65 SetupData.init(SetupData.FLOW_MODE_ACCOUNT_MANAGER_EAS); 66 return new Intent(context, AccountSetupBasics.class); 67 } 68 69 /** 70 * This generates setup data that can be used to start a self-contained account creation flow 71 * for pop/imap accounts. 72 */ 73 public static Intent actionSetupPopImapIntent(Context context) { 74 SetupData.init(SetupData.FLOW_MODE_ACCOUNT_MAANGER_POP_IMAP); 75 return new Intent(context, AccountSetupBasics.class); 76 } 77 78 public static void actionAccountCreateFinishedAccountFlow(Activity fromActivity) { 79 Intent i= new Intent(fromActivity, AccountSetupBasics.class); 80 // If we're in the "account flow" (from AccountManager), we want to return to the caller 81 // (in the settings app) 82 SetupData.init(SetupData.FLOW_MODE_RETURN_TO_CALLER); 83 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 84 fromActivity.startActivity(i); 85 } 86 87 public static void actionAccountCreateFinished(final Activity fromActivity, 88 final long accountId) { 89 Utility.runAsync(new Runnable() { 90 public void run() { 91 Intent i = new Intent(fromActivity, AccountSetupBasics.class); 92 // If we're not in the "account flow" (from AccountManager), we want to show the 93 // message list for the new inbox 94 Account account = Account.restoreAccountWithId(fromActivity, accountId); 95 SetupData.init(SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account); 96 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 97 fromActivity.startActivity(i); 98 }}); 99 } 100 101 @Override 102 public void onCreate(Bundle savedInstanceState) { 103 super.onCreate(savedInstanceState); 104 105 int flowMode = SetupData.getFlowMode(); 106 if (flowMode == SetupData.FLOW_MODE_RETURN_TO_CALLER) { 107 // Return to the caller who initiated account creation 108 finish(); 109 return; 110 } else if (flowMode == SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST) { 111 Account account = SetupData.getAccount(); 112 if (account != null && account.mId >= 0) { 113 // Show the message list for the new account 114 Welcome.actionOpenAccountInbox(this, account.mId); 115 finish(); 116 return; 117 } 118 } 119 120 setContentView(R.layout.account_setup_basics); 121 122 mFragment = (AccountSetupBasicsFragment) findFragmentById(R.id.setup_basics_fragment); 123 mNextButton = (Button) findViewById(R.id.next); 124 mManualSetupButton = (Button) findViewById(R.id.manual_setup); 125 126 mNextButton.setOnClickListener(this); 127 mManualSetupButton.setOnClickListener(this); 128 129 boolean alternateStrings = false; 130 if (flowMode == SetupData.FLOW_MODE_ACCOUNT_MANAGER_EAS) { 131 // No need for manual button -> next is appropriate 132 mManualSetupButton.setVisibility(View.GONE); 133 // Swap welcome text for EAS-specific text 134 alternateStrings = VendorPolicyLoader.getInstance(this).useAlternateExchangeStrings(); 135 setTitle(alternateStrings 136 ? R.string.account_setup_basics_exchange_title_alternate 137 : R.string.account_setup_basics_exchange_title); 138 } 139 140 // Configure fragment 141 mFragment.setCallback(this, alternateStrings); 142 } 143 144 /** 145 * This is used in automatic setup mode to jump directly down to the names screen. 146 * 147 * NOTE: With this organization, it is *not* possible to auto-create an exchange account, 148 * because certain necessary actions happen during AccountSetupOptions (which we are 149 * skipping here). 150 */ 151 @Override 152 public void onActivityResult(int requestCode, int resultCode, Intent data) { 153 if (resultCode == RESULT_OK) { 154 AccountSetupOptions.actionOptions(this); 155 finish(); 156 } 157 } 158 159 public void onClick(View v) { 160 switch (v.getId()) { 161 case R.id.next: 162 mFragment.onNext(); 163 break; 164 case R.id.manual_setup: 165 // no AutoDiscover - user clicked "manual" 166 mFragment.onManualSetup(false); 167 break; 168 } 169 } 170 171 /** 172 * Implements AccountSetupBasicsFragment.Callback 173 */ 174 @Override 175 public void onEnableProceedButtons(boolean enable) { 176 mNextButton.setEnabled(enable); 177 mManualSetupButton.setEnabled(enable); 178 // Dim the next button's icon to 50% if the button is disabled. 179 // TODO this can probably be done with a stateful drawable. (check android:state_enabled 180 Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128); 181 } 182 183 /** 184 * Implements AccountSetupBasicsFragment.Callback 185 */ 186 @Override 187 public void onProceedAutomatic() { 188 AccountSetupCheckSettings.actionCheckSettings(this, 189 SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING); 190 } 191 192 /** 193 * Implements AccountSetupBasicsFragment.Callback 194 */ 195 @Override 196 public void onProceedDebugSettings() { 197 AccountSettingsXL.actionSettingsWithDebug(this); 198 } 199 200 /** 201 * Implements AccountSetupBasicsFragment.Callback 202 */ 203 @Override 204 public void onProceedManual() { 205 AccountSetupAccountType.actionSelectAccountType(this); 206 } 207} 208