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);
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)) {
Telemetry.HistogramAdd("PLACES_PAGES_COUNT",
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.home.HomePanelPicker;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.widget.FloatingHintEditText;
@ -86,6 +87,11 @@ OnSharedPreferenceChangeListener
{
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.";
public static final String INTENT_EXTRA_RESOURCES = "resource";
public static String PREFS_HEALTHREPORT_UPLOAD_ENABLED = NON_PREF_PREFIX + "healthreport.uploadEnabled";
@ -133,6 +139,19 @@ OnSharedPreferenceChangeListener
private Locale lastLocale = Locale.getDefault();
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) {
if (Build.VERSION.SDK_INT >= 14) {
final String newTitle = getString(title);
@ -250,10 +269,10 @@ OnSharedPreferenceChangeListener
// We also don't need to update the title.
final Intent intent = (Intent) getIntent().clone();
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);
finish();
finishChoosingTransition();
}
private void checkLocale() {
@ -440,6 +459,15 @@ OnSharedPreferenceChangeListener
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
if (NO_TRANSITIONS) {
overridePendingTransition(0, 0);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
@ -494,7 +522,7 @@ OnSharedPreferenceChangeListener
// the settings screens.
// We need to start nested PreferenceScreens withStartActivityForResult().
// 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
@ -505,9 +533,12 @@ OnSharedPreferenceChangeListener
// Overriding because we want to use startActivityForResult for Fragment intents.
Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleRes, shortTitleRes);
if (resultTo == null) {
startActivityForResult(intent, REQUEST_CODE_PREF_SCREEN);
startActivityForResultChoosingTransition(intent, REQUEST_CODE_PREF_SCREEN);
} else {
resultTo.startActivityForResult(intent, resultRequestCode);
if (NO_TRANSITIONS) {
overridePendingTransition(0, 0);
}
}
}
@ -525,7 +556,7 @@ OnSharedPreferenceChangeListener
// Pass this result up to the parent activity.
setResult(RESULT_CODE_EXIT_SETTINGS);
finish();
finishChoosingTransition();
break;
}
break;
@ -690,7 +721,7 @@ OnSharedPreferenceChangeListener
@Override
public boolean onPreferenceClick(Preference preference) {
Intent dialogIntent = new Intent(GeckoPreferences.this, HomePanelPicker.class);
startActivityForResult(dialogIntent, HomePanelPicker.REQUEST_CODE_ADD_PANEL);
startActivityForResultChoosingTransition(dialogIntent, HomePanelPicker.REQUEST_CODE_ADD_PANEL);
return true;
}
});
@ -740,7 +771,7 @@ OnSharedPreferenceChangeListener
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
finish();
finishChoosingTransition();
return true;
}
@ -1007,7 +1038,7 @@ OnSharedPreferenceChangeListener
((ListPreference) preference).setSummary(newEntry);
} else if (preference instanceof LinkPreference) {
setResult(RESULT_CODE_EXIT_SETTINGS);
finish();
finishChoosingTransition();
} else if (preference instanceof FontSizePreference) {
final FontSizePreference fontSizePref = (FontSizePreference) preference;
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.sync.setup.SyncAccounts;
import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
import org.mozilla.gecko.util.HardwareUtils;
import android.content.Context;
import android.content.Intent;
@ -39,6 +40,11 @@ class SyncPreference extends Preference {
private void launchFxASetup() {
Intent intent = new Intent(mContext, FxAccountGetStartedActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (HardwareUtils.IS_KINDLE_DEVICE) {
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
}
mContext.startActivity(intent);
}

View File

@ -30,6 +30,10 @@ public final class HardwareUtils {
// Number of bytes of /proc/meminfo to read in one go.
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 boolean sInited;