AccountSetupAccountType.java revision bc47398187c6ffd132435e51d8d61e6ec79a79db
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 android.app.Activity; 20import android.content.Intent; 21import android.os.Bundle; 22import android.view.View; 23import android.view.View.OnClickListener; 24import android.widget.Button; 25 26import com.android.email.R; 27import com.android.email.VendorPolicyLoader; 28import com.android.email.activity.ActivityHelper; 29import com.android.email.activity.UiUtilities; 30import com.android.email.service.EmailServiceUtils; 31import com.android.emailcommon.provider.Account; 32import com.android.emailcommon.provider.HostAuth; 33 34/** 35 * Prompts the user to select an account type. The account type, along with the 36 * passed in email address, password and makeDefault are then passed on to the 37 * AccountSetupIncoming activity. 38 */ 39public class AccountSetupAccountType extends AccountSetupActivity implements OnClickListener { 40 41 public static void actionSelectAccountType(Activity fromActivity) { 42 fromActivity.startActivity(new Intent(fromActivity, AccountSetupAccountType.class)); 43 } 44 45 @Override 46 public void onCreate(Bundle savedInstanceState) { 47 super.onCreate(savedInstanceState); 48 ActivityHelper.debugSetWindowFlags(this); 49 int flowMode = SetupData.getFlowMode(); 50 51 // If we're in account setup flow mode, for EAS, skip this screen and "click" EAS 52 if (flowMode == SetupData.FLOW_MODE_ACCOUNT_MANAGER_EAS) { 53 onExchange(); 54 return; 55 } 56 57 // Otherwise proceed into this screen 58 setContentView(R.layout.account_setup_account_type); 59 UiUtilities.getView(this, R.id.pop).setOnClickListener(this); 60 UiUtilities.getView(this, R.id.imap).setOnClickListener(this); 61 final Button exchangeButton = (Button) UiUtilities.getView(this, R.id.exchange); 62 exchangeButton.setVisibility(View.INVISIBLE); 63 final Button previousButton = (Button) findViewById(R.id.previous); // xlarge only 64 if (previousButton != null) previousButton.setOnClickListener(this); 65 66 // TODO If we decide to exclude the Exchange option in POP_IMAP mode, use the following line 67 // instead of the line that follows it 68 //if (ExchangeUtils.isExchangeAvailable(this) && flowMode != SetupData.FLOW_MODE_POP_IMAP) { 69 if (EmailServiceUtils.isExchangeAvailable(this)) { 70 exchangeButton.setOnClickListener(this); 71 exchangeButton.setVisibility(View.VISIBLE); 72 if (VendorPolicyLoader.getInstance(this).useAlternateExchangeStrings()) { 73 exchangeButton.setText( 74 R.string.account_setup_account_type_exchange_action_alternate); 75 } 76 } 77 // TODO: Dynamic creation of buttons, instead of just hiding things we don't need 78 } 79 80 /** 81 * For POP accounts, we rewrite the username to the full user@domain, and we set the 82 * default server name to pop3.domain 83 */ 84 private void onPop() { 85 Account account = SetupData.getAccount(); 86 HostAuth hostAuth = account.mHostAuthRecv; 87 hostAuth.mProtocol = HostAuth.SCHEME_POP3; 88 hostAuth.mLogin = hostAuth.mLogin + "@" + hostAuth.mAddress; 89 hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress, 90 HostAuth.SCHEME_POP3, null); 91 AccountSetupBasics.setFlagsForProtocol(account, HostAuth.SCHEME_POP3); 92 SetupData.setCheckSettingsMode(SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING); 93 AccountSetupIncoming.actionIncomingSettings(this, SetupData.getFlowMode(), account); 94 finish(); 95 } 96 97 /** 98 * The user has selected an IMAP account type. Try to put together a URI using the entered 99 * email address. Also set the mail delete policy here, because there is no UI (for IMAP). 100 */ 101 private void onImap() { 102 Account account = SetupData.getAccount(); 103 HostAuth hostAuth = account.mHostAuthRecv; 104 hostAuth.mProtocol = HostAuth.SCHEME_IMAP; 105 hostAuth.mLogin = hostAuth.mLogin + "@" + hostAuth.mAddress; 106 hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress, 107 HostAuth.SCHEME_IMAP, null); 108 AccountSetupBasics.setFlagsForProtocol(account, HostAuth.SCHEME_IMAP); 109 SetupData.setCheckSettingsMode(SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING); 110 AccountSetupIncoming.actionIncomingSettings(this, SetupData.getFlowMode(), account); 111 finish(); 112 } 113 114 /** 115 * The user has selected an exchange account type. Set the mail delete policy here, because 116 * there is no UI (for exchange), and switch the default sync interval to "push". 117 */ 118 private void onExchange() { 119 Account account = SetupData.getAccount(); 120 HostAuth recvAuth = account.getOrCreateHostAuthRecv(this); 121 recvAuth.setConnection(HostAuth.SCHEME_EAS, recvAuth.mAddress, recvAuth.mPort, 122 recvAuth.mFlags | HostAuth.FLAG_SSL); 123 HostAuth sendAuth = account.getOrCreateHostAuthSend(this); 124 sendAuth.setConnection(HostAuth.SCHEME_EAS, sendAuth.mAddress, sendAuth.mPort, 125 sendAuth.mFlags | HostAuth.FLAG_SSL); 126 AccountSetupBasics.setFlagsForProtocol(account, HostAuth.SCHEME_EAS); 127 SetupData.setCheckSettingsMode(SetupData.CHECK_AUTODISCOVER); 128 AccountSetupExchange.actionIncomingSettings(this, SetupData.getFlowMode(), account); 129 finish(); 130 } 131 132 public void onClick(View v) { 133 switch (v.getId()) { 134 case R.id.pop: 135 onPop(); 136 break; 137 case R.id.imap: 138 onImap(); 139 break; 140 case R.id.exchange: 141 onExchange(); 142 break; 143 case R.id.previous: 144 finish(); 145 break; 146 } 147 } 148} 149