From 8bcb572ccfdac6974c111fe6dfc753a5e0d4e7ca Mon Sep 17 00:00:00 2001 From: Andrew Stadler Date: Wed, 8 Sep 2010 23:27:05 -0700 Subject: [PATCH] Convert setup to actionbars, and holo theme * All setup activities given UI makeover: * Remove legacy themes from manifest - exposes default holo theme * Remove bottom row button(s) * Replace with action bar button(s) * No change to workflow or activity/fragment organization Change-Id: I07ce11a0a2b4b767b5ac111d466e68400fe0f30b --- AndroidManifest.xml | 8 -- res/layout/account_setup_basics.xml | 39 +----- res/layout/account_setup_exchange.xml | 2 +- res/layout/account_setup_incoming.xml | 31 +---- res/layout/account_setup_names.xml | 79 +++++------- res/layout/account_setup_options.xml | 119 ++++++++---------- res/layout/account_setup_outgoing.xml | 31 +---- res/menu/account_setup_manual_next_option.xml | 27 ++++ ...tion.xml => account_setup_next_option.xml} | 2 +- .../setup/AccountServerBaseFragment.java | 2 +- .../activity/setup/AccountSetupBasics.java | 77 ++++++++---- .../activity/setup/AccountSetupExchange.java | 39 ++---- .../activity/setup/AccountSetupIncoming.java | 37 ++---- .../activity/setup/AccountSetupNames.java | 58 ++++++--- .../activity/setup/AccountSetupOptions.java | 50 +++++--- .../activity/setup/AccountSetupOutgoing.java | 37 ++---- 16 files changed, 282 insertions(+), 356 deletions(-) create mode 100644 res/menu/account_setup_manual_next_option.xml rename res/menu/{account_settings_next_option.xml => account_setup_next_option.xml} (91%) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 27509ff67..6336f5df4 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -80,26 +80,22 @@ @@ -108,7 +104,6 @@ @@ -116,13 +111,11 @@ + + + + + + diff --git a/res/menu/account_settings_next_option.xml b/res/menu/account_setup_next_option.xml similarity index 91% rename from res/menu/account_settings_next_option.xml rename to res/menu/account_setup_next_option.xml index 59e094beb..e60cf088f 100644 --- a/res/menu/account_settings_next_option.xml +++ b/res/menu/account_setup_next_option.xml @@ -14,7 +14,7 @@ limitations under the License. --> - + next is appropriate - mManualSetupButton.setVisibility(View.GONE); + mManualButtonDisplayed = false; // Swap welcome text for EAS-specific text alternateStrings = VendorPolicyLoader.getInstance(this).useAlternateExchangeStrings(); setTitle(alternateStrings @@ -141,7 +136,7 @@ public class AccountSetupBasics extends AccountSetupActivity mFragment.setCallback(this, alternateStrings); } - /** + /** * This is used in automatic setup mode to jump directly down to the names screen. * * NOTE: With this organization, it is *not* possible to auto-create an exchange account, @@ -156,28 +151,58 @@ public class AccountSetupBasics extends AccountSetupActivity } } - public void onClick(View v) { - switch (v.getId()) { + /** + * Add "Next" & "Manual" buttons when this activity is displayed + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + int menuId = mManualButtonDisplayed + ? R.menu.account_setup_manual_next_option + : R.menu.account_setup_next_option; + getMenuInflater().inflate(menuId, menu); + return super.onCreateOptionsMenu(menu); + } + + /** + * Enable/disable "Next" & "Manual" buttons + */ + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + menu.findItem(R.id.next).setEnabled(mNextButtonEnabled); + if (mManualButtonDisplayed) { + menu.findItem(R.id.manual_setup).setEnabled(mNextButtonEnabled); + } + return super.onPrepareOptionsMenu(menu); + } + + /** + * Respond to clicks in the "Next" button + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { case R.id.next: mFragment.onNext(); - break; + return true; case R.id.manual_setup: // no AutoDiscover - user clicked "manual" mFragment.onManualSetup(false); - break; + return true; } + return super.onOptionsItemSelected(item); } /** * Implements AccountSetupBasicsFragment.Callback */ @Override - public void onEnableProceedButtons(boolean enable) { - mNextButton.setEnabled(enable); - mManualSetupButton.setEnabled(enable); - // Dim the next button's icon to 50% if the button is disabled. - // TODO this can probably be done with a stateful drawable. (check android:state_enabled - Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128); + public void onEnableProceedButtons(boolean enabled) { + boolean wasEnabled = mNextButtonEnabled; + mNextButtonEnabled = enabled; + + if (enabled != wasEnabled) { + invalidateOptionsMenu(); + } } /** diff --git a/src/com/android/email/activity/setup/AccountSetupExchange.java b/src/com/android/email/activity/setup/AccountSetupExchange.java index 2edb82702..d989432b5 100644 --- a/src/com/android/email/activity/setup/AccountSetupExchange.java +++ b/src/com/android/email/activity/setup/AccountSetupExchange.java @@ -18,7 +18,6 @@ package com.android.email.activity.setup; import com.android.email.R; import com.android.email.SecurityPolicy.PolicySet; -import com.android.email.Utility; import com.android.email.provider.EmailContent.Account; import com.android.email.provider.EmailContent.HostAuth; import com.android.email.service.EmailServiceProxy; @@ -27,9 +26,6 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; /** * Provides generic setup for Exchange accounts. The following fields are supported: @@ -71,10 +67,10 @@ import android.widget.Button; * What we really need here is a more "sticky" way to prevent that problem. */ public class AccountSetupExchange extends AccountSetupActivity - implements OnClickListener, AccountSetupExchangeFragment.Callback { + implements AccountSetupExchangeFragment.Callback { /* package */ AccountSetupExchangeFragment mFragment; - private Button mNextButton; + private boolean mNextButtonEnabled; public static void actionIncomingSettings(Activity fromActivity, int mode, Account acct) { SetupData.init(mode, acct); @@ -98,10 +94,8 @@ public class AccountSetupExchange extends AccountSetupActivity super.onCreate(savedInstanceState); setContentView(R.layout.account_setup_exchange); - mFragment = (AccountSetupExchangeFragment) findFragmentById(R.id.setup_exchange_fragment); - mNextButton = (Button)findViewById(R.id.next); - mNextButton.setOnClickListener(this); - + mFragment = (AccountSetupExchangeFragment) + getFragmentManager().findFragmentById(R.id.setup_fragment); mFragment.setCallback(this); startAutoDiscover(); @@ -126,7 +120,6 @@ public class AccountSetupExchange extends AccountSetupActivity // If we've got a username and password and we're NOT editing, try autodiscover String username = account.mHostAuthRecv.mLogin; String password = account.mHostAuthRecv.mPassword; - Intent intent = getIntent(); if (username != null && password != null) { AccountSetupCheckSettings.actionAutoDiscover(this, account.mEmailAddress, password); } @@ -208,11 +201,15 @@ public class AccountSetupExchange extends AccountSetupActivity // Otherwise, proceed into this activity for manual setup } - public void onClick(View v) { - switch (v.getId()) { - case R.id.next: - mFragment.onNext(); - break; + /** + * Implements AccountServerBaseFragment.Callback + */ + public void onEnableProceedButtons(boolean enabled) { + boolean wasEnabled = mNextButtonEnabled; + mNextButtonEnabled = enabled; + + if (enabled != wasEnabled) { + invalidateOptionsMenu(); } } @@ -222,14 +219,4 @@ public class AccountSetupExchange extends AccountSetupActivity public void onProceedNext(int checkMode) { AccountSetupCheckSettings.actionCheckSettings(this, checkMode); } - - /** - * Implements AccountServerBaseFragment.Callback - */ - public void onEnableProceedButtons(boolean enabled) { - mNextButton.setEnabled(enabled); - // Dim the next button's icon to 50% if the button is disabled. - // TODO this can probably be done with a stateful drawable. (check android:state_enabled) - Utility.setCompoundDrawablesAlpha(mNextButton, enabled ? 255 : 128); - } } diff --git a/src/com/android/email/activity/setup/AccountSetupIncoming.java b/src/com/android/email/activity/setup/AccountSetupIncoming.java index a3d14470b..2aa60ae46 100644 --- a/src/com/android/email/activity/setup/AccountSetupIncoming.java +++ b/src/com/android/email/activity/setup/AccountSetupIncoming.java @@ -17,21 +17,17 @@ package com.android.email.activity.setup; import com.android.email.R; -import com.android.email.Utility; import com.android.email.provider.EmailContent; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; public class AccountSetupIncoming extends AccountSetupActivity - implements OnClickListener, AccountSetupIncomingFragment.Callback { + implements AccountSetupIncomingFragment.Callback { private AccountSetupIncomingFragment mFragment; - private Button mNextButton; + private boolean mNextButtonEnabled; public static void actionIncomingSettings(Activity fromActivity, int mode, EmailContent.Account account) { @@ -49,9 +45,8 @@ public class AccountSetupIncoming extends AccountSetupActivity super.onCreate(savedInstanceState); setContentView(R.layout.account_setup_incoming); - mFragment = (AccountSetupIncomingFragment) findFragmentById(R.id.setup_incoming_fragment); - mNextButton = (Button)findViewById(R.id.next); - mNextButton.setOnClickListener(this); + mFragment = (AccountSetupIncomingFragment) + getFragmentManager().findFragmentById(R.id.setup_fragment); // Configure fragment mFragment.setCallback(this); @@ -76,14 +71,14 @@ public class AccountSetupIncoming extends AccountSetupActivity } /** - * When the user clicks "next", notify the fragment that it's time to prepare the new - * settings to be tested. This will call back via onProceedNext() to actually launch the test. + * Implements AccountServerBaseFragment.Callback */ - public void onClick(View v) { - switch (v.getId()) { - case R.id.next: - mFragment.onNext(); - break; + public void onEnableProceedButtons(boolean enabled) { + boolean wasEnabled = mNextButtonEnabled; + mNextButtonEnabled = enabled; + + if (enabled != wasEnabled) { + invalidateOptionsMenu(); } } @@ -93,14 +88,4 @@ public class AccountSetupIncoming extends AccountSetupActivity public void onProceedNext(int checkMode) { AccountSetupCheckSettings.actionCheckSettings(this, checkMode); } - - /** - * Implements AccountServerBaseFragment.Callback - */ - public void onEnableProceedButtons(boolean enabled) { - mNextButton.setEnabled(enabled); - // Dim the next button's icon to 50% if the button is disabled. - // TODO this can probably be done with a stateful drawable. (check android:state_enabled) - Utility.setCompoundDrawablesAlpha(mNextButton, enabled ? 255 : 128); - } } diff --git a/src/com/android/email/activity/setup/AccountSetupNames.java b/src/com/android/email/activity/setup/AccountSetupNames.java index e2b67bb91..67693c5fc 100644 --- a/src/com/android/email/activity/setup/AccountSetupNames.java +++ b/src/com/android/email/activity/setup/AccountSetupNames.java @@ -25,28 +25,26 @@ import com.android.email.provider.EmailContent.AccountColumns; import com.android.email.provider.EmailContent.HostAuth; import android.app.Activity; -import android.content.ContentUris; import android.content.ContentValues; import android.content.Intent; -import android.database.Cursor; import android.os.AsyncTask; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.text.method.TextKeyListener; import android.text.method.TextKeyListener.Capitalize; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; import android.widget.EditText; -public class AccountSetupNames extends AccountSetupActivity implements OnClickListener { +public class AccountSetupNames extends AccountSetupActivity { private static final int REQUEST_SECURITY = 0; private EditText mDescription; private EditText mName; - private Button mDoneButton; private boolean mEasAccount = false; + private boolean mNextButtonEnabled; private CheckAccountStateTask mCheckAccountStateTask; @@ -60,8 +58,6 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi setContentView(R.layout.account_setup_names); mDescription = (EditText)findViewById(R.id.account_description); mName = (EditText)findViewById(R.id.account_name); - mDoneButton = (Button)findViewById(R.id.done); - mDoneButton.setOnClickListener(this); TextWatcher validationTextWatcher = new TextWatcher() { public void afterTextChanged(Editable s) { @@ -121,14 +117,46 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi } } + /** + * Add "Next" button when this activity is displayed + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.account_setup_next_option, menu); + return super.onCreateOptionsMenu(menu); + } + + /** + * Enable/disable "Next" button + */ + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + menu.findItem(R.id.next).setEnabled(mNextButtonEnabled); + return super.onPrepareOptionsMenu(menu); + } + + /** + * Respond to clicks in the "Next" button + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.next: + onNext(); + return true; + } + return super.onOptionsItemSelected(item); + } + /** * TODO: Validator should also trim the name string before checking it. */ private void validateFields() { - if (!mEasAccount) { - mDoneButton.setEnabled(Utility.isTextViewNotEmpty(mName)); + boolean newEnabled = !mEasAccount || Utility.isTextViewNotEmpty(mName); + if (newEnabled != mNextButtonEnabled) { + mNextButtonEnabled = newEnabled; + invalidateOptionsMenu(); } - Utility.setCompoundDrawablesAlpha(mDoneButton, mDoneButton.isEnabled() ? 255 : 128); } @Override @@ -175,14 +203,6 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi mCheckAccountStateTask.execute(); } - public void onClick(View v) { - switch (v.getId()) { - case R.id.done: - onNext(); - break; - } - } - /** * This async task is launched just before exiting. It's a last chance test, before leaving * this activity, for the account being in a "hold" state, and gives the user a chance to diff --git a/src/com/android/email/activity/setup/AccountSetupOptions.java b/src/com/android/email/activity/setup/AccountSetupOptions.java index 09d0951c2..0664cbcdf 100644 --- a/src/com/android/email/activity/setup/AccountSetupOptions.java +++ b/src/com/android/email/activity/setup/AccountSetupOptions.java @@ -36,15 +36,16 @@ import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.Spinner; import java.io.IOException; -public class AccountSetupOptions extends AccountSetupActivity implements OnClickListener { +public class AccountSetupOptions extends AccountSetupActivity { private Spinner mCheckFrequencyView; private Spinner mSyncWindowView; @@ -78,7 +79,6 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick mSyncCalendarView = (CheckBox) findViewById(R.id.account_sync_calendar); mSyncEmailView = (CheckBox) findViewById(R.id.account_sync_email); mSyncEmailView.setChecked(true); - findViewById(R.id.next).setOnClickListener(this); // Generate spinner entries using XML arrays used by the preferences int frequencyValuesId; @@ -135,6 +135,36 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick } } + /** + * Add "Next" button when this activity is displayed + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.account_setup_next_option, menu); + return super.onCreateOptionsMenu(menu); + } + + /** + * Respond to clicks in the "Next" button + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.next: + // Don't allow this more than once (Exchange accounts call an async method + // before finish()'ing the Activity, which allows this code to potentially be + // executed multiple times + if (!mDonePressed) { + onDone(); + mDonePressed = true; + } + return true; + } + return super.onOptionsItemSelected(item); + } + + + AccountManagerCallback mAccountManagerCallback = new AccountManagerCallback() { public void run(AccountManagerFuture future) { try { @@ -248,20 +278,6 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick } } - public void onClick(View v) { - switch (v.getId()) { - case R.id.next: - // Don't allow this more than once (Exchange accounts call an async method - // before finish()'ing the Activity, which allows this code to potentially be - // executed multiple times - if (!mDonePressed) { - onDone(); - mDonePressed = true; - } - break; - } - } - /** * Enable an additional spinner using the arrays normally handled by preferences */ diff --git a/src/com/android/email/activity/setup/AccountSetupOutgoing.java b/src/com/android/email/activity/setup/AccountSetupOutgoing.java index 05b1742c6..c10a71c1b 100644 --- a/src/com/android/email/activity/setup/AccountSetupOutgoing.java +++ b/src/com/android/email/activity/setup/AccountSetupOutgoing.java @@ -17,22 +17,18 @@ package com.android.email.activity.setup; import com.android.email.R; -import com.android.email.Utility; import com.android.email.provider.EmailContent; import com.android.email.provider.EmailContent.Account; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; public class AccountSetupOutgoing extends Activity - implements OnClickListener, AccountSetupOutgoingFragment.Callback { + implements AccountSetupOutgoingFragment.Callback { private AccountSetupOutgoingFragment mFragment; - private Button mNextButton; + private boolean mNextButtonEnabled; public static void actionOutgoingSettings(Activity fromActivity, int mode, Account acct) { SetupData.init(mode, acct); @@ -48,9 +44,8 @@ public class AccountSetupOutgoing extends Activity super.onCreate(savedInstanceState); setContentView(R.layout.account_setup_outgoing); - mFragment = (AccountSetupOutgoingFragment) findFragmentById(R.id.setup_outgoing_fragment); - mNextButton = (Button)findViewById(R.id.next); - mNextButton.setOnClickListener(this); + mFragment = (AccountSetupOutgoingFragment) + getFragmentManager().findFragmentById(R.id.setup_fragment); // Configure fragment mFragment.setCallback(this); @@ -74,14 +69,14 @@ public class AccountSetupOutgoing extends Activity } /** - * When the user clicks "next", notify the fragment that it's time to prepare the new - * settings to be tested. This will call back via onProceedNext() to actually launch the test. + * Implements AccountServerBaseFragment.Callback */ - public void onClick(View v) { - switch (v.getId()) { - case R.id.next: - mFragment.onNext(); - break; + public void onEnableProceedButtons(boolean enabled) { + boolean wasEnabled = mNextButtonEnabled; + mNextButtonEnabled = enabled; + + if (enabled != wasEnabled) { + invalidateOptionsMenu(); } } @@ -91,14 +86,4 @@ public class AccountSetupOutgoing extends Activity public void onProceedNext(int checkMode) { AccountSetupCheckSettings.actionCheckSettings(this, checkMode); } - - /** - * Implements AccountServerBaseFragment.Callback - */ - public void onEnableProceedButtons(boolean enabled) { - mNextButton.setEnabled(enabled); - // Dim the next button's icon to 50% if the button is disabled. - // TODO this can probably be done with a stateful drawable. (check android:state_enabled) - Utility.setCompoundDrawablesAlpha(mNextButton, enabled ? 255 : 128); - } }