Bug 1031872 - Don't use transitions for GeckoPreferences on Kindle Fire. r=lucasr

The Kindle always uses a black background for transitions. On all-white screens
like our Settings panes, this looks awful. This patch skips transitions on
those devices.
This commit is contained in:
Richard Newman 2014-07-14 14:26:54 -07:00
parent 73bd274fb7
commit 65b9de5d79
4 changed files with 55 additions and 8 deletions

View File

@ -1310,6 +1310,12 @@ public class BrowserApp extends GeckoApp
GeckoPreferences.setResourceToOpen(settingsIntent, resource); GeckoPreferences.setResourceToOpen(settingsIntent, resource);
startActivityForResult(settingsIntent, ACTIVITY_REQUEST_PREFERENCES); startActivityForResult(settingsIntent, ACTIVITY_REQUEST_PREFERENCES);
// Don't use a transition to settings if we're on a device where that
// would look bad.
if (HardwareUtils.IS_KINDLE_DEVICE) {
overridePendingTransition(0, 0);
}
} else if ("Telemetry:Gather".equals(event)) { } else if ("Telemetry:Gather".equals(event)) {
Telemetry.HistogramAdd("PLACES_PAGES_COUNT", Telemetry.HistogramAdd("PLACES_PAGES_COUNT",
BrowserDB.getCount(getContentResolver(), "history")); BrowserDB.getCount(getContentResolver(), "history"));

View File

@ -33,6 +33,7 @@ import org.mozilla.gecko.background.healthreport.HealthReportConstants;
import org.mozilla.gecko.db.BrowserContract.SuggestedSites; import org.mozilla.gecko.db.BrowserContract.SuggestedSites;
import org.mozilla.gecko.home.HomePanelPicker; import org.mozilla.gecko.home.HomePanelPicker;
import org.mozilla.gecko.util.GeckoEventListener; import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.widget.FloatingHintEditText; import org.mozilla.gecko.widget.FloatingHintEditText;
@ -86,6 +87,11 @@ OnSharedPreferenceChangeListener
{ {
private static final String LOGTAG = "GeckoPreferences"; private static final String LOGTAG = "GeckoPreferences";
// We have a white background, which makes transitions on
// some devices look bad. Don't use transitions on those
// devices.
private static final boolean NO_TRANSITIONS = HardwareUtils.IS_KINDLE_DEVICE;
private static final String NON_PREF_PREFIX = "android.not_a_preference."; private static final String NON_PREF_PREFIX = "android.not_a_preference.";
public static final String INTENT_EXTRA_RESOURCES = "resource"; public static final String INTENT_EXTRA_RESOURCES = "resource";
public static String PREFS_HEALTHREPORT_UPLOAD_ENABLED = NON_PREF_PREFIX + "healthreport.uploadEnabled"; public static String PREFS_HEALTHREPORT_UPLOAD_ENABLED = NON_PREF_PREFIX + "healthreport.uploadEnabled";
@ -133,6 +139,19 @@ OnSharedPreferenceChangeListener
private Locale lastLocale = Locale.getDefault(); private Locale lastLocale = Locale.getDefault();
private boolean localeSwitchingIsEnabled; private boolean localeSwitchingIsEnabled;
private void startActivityForResultChoosingTransition(final Intent intent, final int requestCode) {
startActivityForResult(intent, requestCode);
if (NO_TRANSITIONS) {
overridePendingTransition(0, 0);
}
}
private void finishChoosingTransition() {
finish();
if (NO_TRANSITIONS) {
overridePendingTransition(0, 0);
}
}
private void updateActionBarTitle(int title) { private void updateActionBarTitle(int title) {
if (Build.VERSION.SDK_INT >= 14) { if (Build.VERSION.SDK_INT >= 14) {
final String newTitle = getString(title); final String newTitle = getString(title);
@ -250,10 +269,10 @@ OnSharedPreferenceChangeListener
// We also don't need to update the title. // We also don't need to update the title.
final Intent intent = (Intent) getIntent().clone(); final Intent intent = (Intent) getIntent().clone();
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, REQUEST_CODE_PREF_SCREEN); startActivityForResultChoosingTransition(intent, REQUEST_CODE_PREF_SCREEN);
setResult(RESULT_CODE_LOCALE_DID_CHANGE); setResult(RESULT_CODE_LOCALE_DID_CHANGE);
finish(); finishChoosingTransition();
} }
private void checkLocale() { private void checkLocale() {
@ -440,6 +459,15 @@ OnSharedPreferenceChangeListener
} }
} }
@Override
public void onBackPressed() {
super.onBackPressed();
if (NO_TRANSITIONS) {
overridePendingTransition(0, 0);
}
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -494,7 +522,7 @@ OnSharedPreferenceChangeListener
// the settings screens. // the settings screens.
// We need to start nested PreferenceScreens withStartActivityForResult(). // We need to start nested PreferenceScreens withStartActivityForResult().
// Android doesn't let us do that (see Preference.onClick), so we're overriding here. // Android doesn't let us do that (see Preference.onClick), so we're overriding here.
startActivityForResult(intent, REQUEST_CODE_PREF_SCREEN); startActivityForResultChoosingTransition(intent, REQUEST_CODE_PREF_SCREEN);
} }
@Override @Override
@ -505,9 +533,12 @@ OnSharedPreferenceChangeListener
// Overriding because we want to use startActivityForResult for Fragment intents. // Overriding because we want to use startActivityForResult for Fragment intents.
Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleRes, shortTitleRes); Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleRes, shortTitleRes);
if (resultTo == null) { if (resultTo == null) {
startActivityForResult(intent, REQUEST_CODE_PREF_SCREEN); startActivityForResultChoosingTransition(intent, REQUEST_CODE_PREF_SCREEN);
} else { } else {
resultTo.startActivityForResult(intent, resultRequestCode); resultTo.startActivityForResult(intent, resultRequestCode);
if (NO_TRANSITIONS) {
overridePendingTransition(0, 0);
}
} }
} }
@ -525,7 +556,7 @@ OnSharedPreferenceChangeListener
// Pass this result up to the parent activity. // Pass this result up to the parent activity.
setResult(RESULT_CODE_EXIT_SETTINGS); setResult(RESULT_CODE_EXIT_SETTINGS);
finish(); finishChoosingTransition();
break; break;
} }
break; break;
@ -690,7 +721,7 @@ OnSharedPreferenceChangeListener
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
Intent dialogIntent = new Intent(GeckoPreferences.this, HomePanelPicker.class); Intent dialogIntent = new Intent(GeckoPreferences.this, HomePanelPicker.class);
startActivityForResult(dialogIntent, HomePanelPicker.REQUEST_CODE_ADD_PANEL); startActivityForResultChoosingTransition(dialogIntent, HomePanelPicker.REQUEST_CODE_ADD_PANEL);
return true; return true;
} }
}); });
@ -740,7 +771,7 @@ OnSharedPreferenceChangeListener
int itemId = item.getItemId(); int itemId = item.getItemId();
switch (itemId) { switch (itemId) {
case android.R.id.home: case android.R.id.home:
finish(); finishChoosingTransition();
return true; return true;
} }
@ -1007,7 +1038,7 @@ OnSharedPreferenceChangeListener
((ListPreference) preference).setSummary(newEntry); ((ListPreference) preference).setSummary(newEntry);
} else if (preference instanceof LinkPreference) { } else if (preference instanceof LinkPreference) {
setResult(RESULT_CODE_EXIT_SETTINGS); setResult(RESULT_CODE_EXIT_SETTINGS);
finish(); finishChoosingTransition();
} else if (preference instanceof FontSizePreference) { } else if (preference instanceof FontSizePreference) {
final FontSizePreference fontSizePref = (FontSizePreference) preference; final FontSizePreference fontSizePref = (FontSizePreference) preference;
fontSizePref.setSummary(fontSizePref.getSavedFontSizeName()); fontSizePref.setSummary(fontSizePref.getSavedFontSizeName());

View File

@ -8,6 +8,7 @@ package org.mozilla.gecko.preferences;
import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity; import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity;
import org.mozilla.gecko.sync.setup.SyncAccounts; import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity; import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
import org.mozilla.gecko.util.HardwareUtils;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -39,6 +40,11 @@ class SyncPreference extends Preference {
private void launchFxASetup() { private void launchFxASetup() {
Intent intent = new Intent(mContext, FxAccountGetStartedActivity.class); Intent intent = new Intent(mContext, FxAccountGetStartedActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (HardwareUtils.IS_KINDLE_DEVICE) {
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
}
mContext.startActivity(intent); mContext.startActivity(intent);
} }

View File

@ -30,6 +30,10 @@ public final class HardwareUtils {
// Number of bytes of /proc/meminfo to read in one go. // Number of bytes of /proc/meminfo to read in one go.
private static final int MEMINFO_BUFFER_SIZE_BYTES = 256; private static final int MEMINFO_BUFFER_SIZE_BYTES = 256;
private static final boolean IS_AMAZON_DEVICE = Build.MANUFACTURER.equalsIgnoreCase("Amazon");
public static final boolean IS_KINDLE_DEVICE = IS_AMAZON_DEVICE &&
(Build.MODEL.equals("Kindle Fire") ||
Build.MODEL.startsWith("KF"));
private static volatile int sTotalRAM = -1; private static volatile int sTotalRAM = -1;
private static volatile boolean sInited; private static volatile boolean sInited;