Home | History | Annotate | Download | only in setup
      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 AccountSetupActivity
     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, SetupData setupData) {
     46         Intent intent = new Intent(fromActivity, AccountSetupOutgoing.class);
     47         intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
     48         fromActivity.startActivity(intent);
     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 = 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 AccountSetupOugoingFragment.Callback
     85      *
     86      * Launches the account checker.  Positive results are reported to onCheckSettingsOk().
     87      */
     88     @Override
     89     public void onProceedNext(int checkMode, AccountServerBaseFragment target) {
     90         final AccountCheckSettingsFragment checkerFragment =
     91             AccountCheckSettingsFragment.newInstance(checkMode, target);
     92         final FragmentTransaction transaction = getFragmentManager().beginTransaction();
     93         transaction.add(checkerFragment, AccountCheckSettingsFragment.TAG);
     94         transaction.addToBackStack("back");
     95         transaction.commit();
     96     }
     97 
     98     /**
     99      * Implements AccountSetupOugoingFragment.Callback
    100      */
    101     @Override
    102     public void onEnableProceedButtons(boolean enable) {
    103         mNextButtonEnabled = enable;
    104         mNextButton.setEnabled(enable);
    105     }
    106 
    107     /**
    108      * Implements AccountServerBaseFragment.Callback
    109      *
    110      * If the checked settings are OK, proceed to options screen
    111      */
    112     @Override
    113     public void onCheckSettingsComplete(int result, SetupData setupData) {
    114         mSetupData = setupData;
    115         if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
    116             AccountSetupOptions.actionOptions(this, mSetupData);
    117             finish();
    118         }
    119     }
    120 }
    121