AccountSetupAccountType.java revision 687f9962d7095e18ef994cd0e64337f02ed1a5bd
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 java.net.URI; 20import java.net.URISyntaxException; 21 22import android.app.Activity; 23import android.content.Context; 24import android.content.Intent; 25import android.os.Bundle; 26import android.view.View; 27import android.view.View.OnClickListener; 28import android.widget.Button; 29 30import com.android.email.Account; 31import com.android.email.R; 32 33/** 34 * Prompts the user to select an account type. The account type, along with the 35 * passed in email address, password and makeDefault are then passed on to the 36 * AccountSetupIncoming activity. 37 */ 38public class AccountSetupAccountType extends Activity implements OnClickListener { 39 private static final String EXTRA_ACCOUNT = "account"; 40 41 private static final String EXTRA_MAKE_DEFAULT = "makeDefault"; 42 43 private Account mAccount; 44 45 private boolean mMakeDefault; 46 47 public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) { 48 Intent i = new Intent(context, AccountSetupAccountType.class); 49 i.putExtra(EXTRA_ACCOUNT, account); 50 i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); 51 context.startActivity(i); 52 } 53 54 @Override 55 public void onCreate(Bundle savedInstanceState) { 56 super.onCreate(savedInstanceState); 57 setContentView(R.layout.account_setup_account_type); 58 ((Button)findViewById(R.id.pop)).setOnClickListener(this); 59 ((Button)findViewById(R.id.imap)).setOnClickListener(this); 60 61 mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); 62 mMakeDefault = (boolean)getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); 63 } 64 65 private void onPop() { 66 try { 67 URI uri = new URI(mAccount.getStoreUri()); 68 uri = new URI("pop3", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); 69 mAccount.setStoreUri(uri.toString()); 70 } catch (URISyntaxException use) { 71 /* 72 * This should not happen. 73 */ 74 throw new Error(use); 75 } 76 AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault); 77 finish(); 78 } 79 80 /** 81 * The user has selected an IMAP account type. Try to put together a URI using the entered 82 * email address. Also set the mail delete policy here, because there is no UI (for IMAP). 83 */ 84 private void onImap() { 85 try { 86 URI uri = new URI(mAccount.getStoreUri()); 87 uri = new URI("imap", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); 88 mAccount.setStoreUri(uri.toString()); 89 } catch (URISyntaxException use) { 90 /* 91 * This should not happen. 92 */ 93 throw new Error(use); 94 } 95 // Delete policy must be set explicitly, because IMAP does not provide a UI selection 96 // for it. This logic needs to be followed in the auto setup flow as well. 97 mAccount.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); 98 AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault); 99 finish(); 100 } 101 102 public void onClick(View v) { 103 switch (v.getId()) { 104 case R.id.pop: 105 onPop(); 106 break; 107 case R.id.imap: 108 onImap(); 109 break; 110 } 111 } 112} 113