Bug 977336 - Support action bar 'up' for FxAccountStatusActivity. r=rnewman

This commit is contained in:
Nick Alexander 2014-03-03 15:20:19 -08:00
parent 62718468ec
commit 8882caff5a
5 changed files with 69 additions and 11 deletions

View File

@ -9,9 +9,13 @@ import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import android.accounts.Account;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;
/**
* Activity which displays account status.
@ -31,6 +35,29 @@ public class FxAccountStatusActivity extends FragmentActivity {
.beginTransaction()
.replace(android.R.id.content, statusFragment)
.commit();
maybeSetHomeButtonEnabled();
}
/**
* Sufficiently recent Android versions need additional code to receive taps
* on the status bar to go "up". See <a
* href="http://stackoverflow.com/a/8953148">this stackoverflow answer</a> for
* more information.
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected void maybeSetHomeButtonEnabled() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Logger.debug(LOG_TAG, "Not enabling home button; version too low.");
return;
}
final ActionBar actionBar = getActionBar();
if (actionBar != null) {
Logger.debug(LOG_TAG, "Enabling home button.");
actionBar.setHomeButtonEnabled(true);
return;
}
Logger.debug(LOG_TAG, "Not enabling home button.");
}
@Override
@ -65,4 +92,15 @@ public class FxAccountStatusActivity extends FragmentActivity {
}
return new AndroidFxAccount(this, account);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- FxAccountStatusActivity ActionBar -->
<style name="ActionBar.FxAccountStatusActivity">
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
</style>
<style name="FxAccountTheme" parent="@style/Gecko" />
<style name="FxAccountTheme.FxAccountStatusActivity" parent="@FxAccountTheme">
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
<item name="android:actionBarStyle">@style/ActionBar.FxAccountStatusActivity</item>
</style>
</resources>

View File

@ -9,6 +9,10 @@
<style name="FxAccountTheme" parent="@style/Gecko" />
<style name="FxAccountTheme.FxAccountStatusActivity" parent="@style/FxAccountTheme">
<item name="android:windowNoTitle">false</item>
</style>
<style name="FxAccountMiddle">
<item name="android:background">@android:color/white</item>
<item name="android:orientation">vertical</item>

View File

@ -1,7 +1,6 @@
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:label="Status"
android:theme="@style/FxAccountTheme.FxAccountStatusActivity"
android:label="@string/fxaccount_status_activity_label"
android:clearTaskOnLaunch="true"
android:taskAffinity="@ANDROID_PACKAGE_NAME@.FXA"
android:name="org.mozilla.gecko.fxa.activities.FxAccountStatusActivity"
@ -16,8 +15,7 @@
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:label="Setup"
android:label="@string/sync_app_name"
android:clearTaskOnLaunch="true"
android:taskAffinity="@ANDROID_PACKAGE_NAME@.FXA"
android:name="org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity"
@ -32,42 +30,36 @@
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:name="org.mozilla.gecko.fxa.activities.FxAccountCreateAccountActivity"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:name="org.mozilla.gecko.fxa.activities.FxAccountConfirmAccountActivity"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:name="org.mozilla.gecko.fxa.activities.FxAccountSignInActivity"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:name="org.mozilla.gecko.fxa.activities.FxAccountVerifiedAccountActivity"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:name="org.mozilla.gecko.fxa.activities.FxAccountUpdateCredentialsActivity"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:theme="@style/FxAccountTheme"
android:icon="@drawable/fxaccount_icon"
android:name="org.mozilla.gecko.fxa.activities.FxAccountCreateAccountNotAllowedActivity"
android:windowSoftInputMode="adjustResize">
</activity>

View File

@ -165,6 +165,7 @@
<string name="fxaccount_update_credentials_button_label">&fxaccount_update_credentials_button_label;</string>
<string name="fxaccount_update_credentials_unknown_error">&fxaccount_update_credentials_unknown_error;</string>
<string name="fxaccount_status_activity_label">&syncBrand.shortName.label;</string>
<string name="fxaccount_status_header">&fxaccount_status_header;</string>
<string name="fxaccount_status_sync">&fxaccount_status_sync;</string>
<string name="fxaccount_status_sync_enabled">&fxaccount_status_sync_enabled;</string>