Bug 1072831 - Firefox becomes unresponsive at start-up with "Don't keep activities" enabled due to first run experience. r=lucasr
authorChenxia Liu <liuche@mozilla.com>
Mon, 27 Oct 2014 16:05:49 -0700
changeset 212543 9e878bc102e3fe538f4bdf71bc9ca93c96627446
parent 212522 908b844c13c874cc44f3a915656245edb451d5d6
child 212544 9eea6cacf02a17e156e9b9bfc013cb6cd9a26e15
push id27720
push usercbook@mozilla.com
push dateTue, 28 Oct 2014 14:51:21 +0000
treeherdermozilla-central@a2d58c6420f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs1072831
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1072831 - Firefox becomes unresponsive at start-up with "Don't keep activities" enabled due to first run experience. r=lucasr
mobile/android/base/BrowserApp.java
mobile/android/base/StartPane.java
mobile/android/base/resources/layout/onboard_start_pane.xml
mobile/android/base/resources/values-large-v11/styles.xml
mobile/android/base/resources/values/styles.xml
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -98,16 +98,17 @@ import android.graphics.drawable.Drawabl
 import android.net.Uri;
 import android.nfc.NdefMessage;
 import android.nfc.NdefRecord;
 import android.nfc.NfcAdapter;
 import android.nfc.NfcEvent;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.StrictMode;
+import android.support.v4.app.DialogFragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.content.LocalBroadcastManager;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.InputDevice;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
@@ -147,16 +148,17 @@ public class BrowserApp extends GeckoApp
     private static final int TABS_ANIMATION_DURATION = 450;
 
     private static final String ADD_SHORTCUT_TOAST = "add_shortcut_toast";
     public static final String GUEST_BROWSING_ARG = "--guest";
 
     private static final String STATE_ABOUT_HOME_TOP_PADDING = "abouthome_top_padding";
 
     private static final String BROWSER_SEARCH_TAG = "browser_search";
+    private static final String ONBOARD_STARTPANE_TAG = "startpane_dialog";
 
     // Request ID for startActivityForResult.
     private static final int ACTIVITY_REQUEST_PREFERENCES = 1001;
 
     public static final String PREF_STARTPANE_ENABLED = "startpane_enabled";
 
     private BrowserSearch mBrowserSearch;
     private View mBrowserSearchContainer;
@@ -623,26 +625,26 @@ public class BrowserApp extends GeckoApp
     private void checkStartPane(Context context, String intentAction) {
         final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
 
         try {
             final SharedPreferences prefs = GeckoSharedPrefs.forProfile(this);
 
             if (prefs.getBoolean(PREF_STARTPANE_ENABLED, false)) {
                 if (!Intent.ACTION_VIEW.equals(intentAction)) {
-                    final Intent startIntent = new Intent(this, StartPane.class);
-                    context.startActivity(startIntent);
+                    final DialogFragment dialog = new StartPane();
+                    dialog.show(getSupportFragmentManager(), ONBOARD_STARTPANE_TAG);
                 }
                 // Don't bother trying again to show the v1 minimal first run.
                 prefs.edit().putBoolean(PREF_STARTPANE_ENABLED, false).apply();
             }
         } finally {
             StrictMode.setThreadPolicy(savedPolicy);
         }
-      }
+    }
 
     private Class<?> getMediaPlayerManager() {
         if (AppConstants.MOZ_MEDIA_PLAYER) {
             try {
                 return Class.forName("org.mozilla.gecko.MediaPlayerManager");
             } catch(Exception ex) {
                 // Ignore failures
                 Log.e(LOGTAG, "No native casting support", ex);
--- a/mobile/android/base/StartPane.java
+++ b/mobile/android/base/StartPane.java
@@ -1,77 +1,75 @@
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity;
-import org.mozilla.gecko.util.HardwareUtils;
 
-import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
 import android.view.GestureDetector;
+import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.View.OnTouchListener;
+import android.view.ViewGroup;
 import android.widget.Button;
 
-public class StartPane extends Activity {
+public class StartPane extends DialogFragment {
 
     @Override
-    public void onCreate(Bundle bundle) {
-        super.onCreate(bundle);
-        setContentView(R.layout.onboard_start_pane);
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
+    }
 
-        final Button accountButton = (Button) findViewById(R.id.button_account);
-        accountButton.setOnClickListener(new OnClickListener() {
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
+        final View view = inflater.inflate(R.layout.onboard_start_pane, container, false);
+        final Button browserButton = (Button) view.findViewById(R.id.button_browser);
+        browserButton.setOnClickListener(new OnClickListener() {
 
             @Override
             public void onClick(View v) {
                 Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-sync");
-                showAccountSetup();
+
+                // StartPane is on the stack above the browser, so just dismiss this Fragment.
+                StartPane.this.dismiss();
             }
         });
 
-        final Button browserButton = (Button) findViewById(R.id.button_browser);
-        browserButton.setOnClickListener(new OnClickListener() {
+        final Button accountButton = (Button) view.findViewById(R.id.button_account);
+        accountButton.setOnClickListener(new OnClickListener() {
 
             @Override
             public void onClick(View v) {
                 Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-browser");
-                showBrowser();
+
+                final Intent intent = new Intent(getActivity(), FxAccountGetStartedActivity.class);
+                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                startActivity(intent);
+                StartPane.this.dismiss();
             }
         });
 
-        if (!HardwareUtils.isTablet() && !HardwareUtils.isTelevision()) {
-            addDismissHandler();
-        }
-    }
-
-    private void showBrowser() {
-        // StartPane is on the stack above the browser, so just kill this activity.
-        finish();
-    }
-
-    private void showAccountSetup() {
-        final Intent intent = new Intent(this, FxAccountGetStartedActivity.class);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        startActivity(intent);
-        finish();
+        addDismissHandler(view);
+        return view;
     }
 
     // Add handler for dismissing the StartPane on a single click.
-    private void addDismissHandler() {
-        final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
+    private void addDismissHandler(View view) {
+        final GestureDetector gestureDetector = new GestureDetector(getActivity(), new GestureDetector.SimpleOnGestureListener() {
             @Override
             public boolean onSingleTapUp(MotionEvent e) {
-                StartPane.this.finish();
+                StartPane.this.dismiss();
                 return true;
             }
         });
 
-        findViewById(R.id.onboard_content).setOnTouchListener(new OnTouchListener() {
+        view.findViewById(R.id.onboard_content).setOnTouchListener(new OnTouchListener() {
             @Override
             public boolean onTouch(View v, MotionEvent event) {
                 return gestureDetector.onTouchEvent(event);
             }
         });
     }
 }
--- a/mobile/android/base/resources/layout/onboard_start_pane.xml
+++ b/mobile/android/base/resources/layout/onboard_start_pane.xml
@@ -1,37 +1,37 @@
 <?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/. -->
 
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              style="@style/OnboardStartLayout"
+              android:layout_height="match_parent"
+              android:layout_width="wrap_content"
               android:orientation="vertical"
-              android:background="@color/onboard_start"
-              android:windowIsFloating="true">
+              android:background="@color/onboard_start">
 
     <ScrollView android:id="@+id/onboard_content"
                 android:layout_width="match_parent"
                 android:layout_height="0dp"
                 android:layout_weight="1"
                 android:fillViewport="true" >
 
         <LinearLayout android:orientation="vertical"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content">
 
             <!-- Empty spacer view -->
             <View android:layout_width="0dp"
                   android:layout_height="0dp"
                   android:layout_weight="1"/>
 
-            <RelativeLayout android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
+            <RelativeLayout android:layout_width="wrap_content"
+                            android:layout_height="match_parent"
                             android:paddingTop="15dp">
 
                 <ImageView android:id="@+id/image_shield"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentTop="true"
                            android:layout_centerHorizontal="true"
                            android:paddingRight="92dp"
@@ -54,44 +54,45 @@
                            android:layout_below="@id/image_shield"
                            android:layout_marginTop="23dp"
                            android:src="@drawable/large_icon"
                            android:contentDescription="@string/onboard_empty_contentDescription"/>
 
                 <ImageView android:id="@+id/image_sync"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
+                           android:layout_centerHorizontal="true"
                            android:layout_below="@id/image_shield"
-                           android:layout_toLeftOf="@id/image_logo"
-                           android:layout_marginRight="30dp"
+                           android:paddingRight="200dp"
                            android:src="@drawable/onboard_start_sync"
                            android:contentDescription="@string/onboard_empty_contentDescription"/>
 
                 <ImageView android:id="@+id/image_addon"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
-                           android:layout_below="@id/image_private"
-                           android:layout_toRightOf="@id/image_logo"
-                           android:layout_marginLeft="30dp"
+                           android:layout_centerHorizontal="true"
+                           android:layout_below="@id/image_shield"
+                           android:paddingLeft="200dp"
                            android:src="@drawable/onboard_start_addon"
                            android:contentDescription="@string/onboard_empty_contentDescription"/>
 
                 <TextView android:id="@+id/text_message"
-                          android:layout_width="wrap_content"
+                          android:layout_width="match_parent"
                           android:layout_height="wrap_content"
                           android:layout_below="@id/image_logo"
                           android:layout_centerHorizontal="true"
                           android:layout_marginTop="30dp"
+                          android:gravity="center"
                           android:padding="10sp"
                           android:text="@string/onboard_start_message"
                           android:textAppearance="@style/OnboardStartTextAppearance"
                           android:textSize="23sp" />
 
                 <TextView android:layout_width="295dp"
-                          android:layout_height="wrap_content"
+                          android:layout_height="match_parent"
                           android:layout_gravity="center"
                           android:gravity="center"
                           android:layout_below="@id/text_message"
                           android:layout_centerHorizontal="true"
                           android:lineSpacingExtra="12sp"
                           android:padding="10sp"
                           android:text="@string/onboard_start_subtext"
                           android:textAppearance="@style/OnboardStartTextAppearance.Subtext" />
@@ -119,9 +120,9 @@
                 android:text="@string/onboard_start_button_account"/>
 
         <Button android:id="@+id/button_browser"
                 style="@style/Widget.Onboard.Start.Button"
                 android:layout_marginTop="3px"
                 android:text="@string/onboard_start_button_browser"/>
 
     </LinearLayout>
-</LinearLayout>
+</LinearLayout>
\ No newline at end of file
--- a/mobile/android/base/resources/values-large-v11/styles.xml
+++ b/mobile/android/base/resources/values-large-v11/styles.xml
@@ -163,18 +163,13 @@
     </style>
 
     <style name="TabsPanelItem.TextAppearance.Linkified.LearnMore">
         <item name="android:layout_height">match_parent</item>
         <item name="android:gravity">center</item>
         <item name="android:layout_gravity">center</item>
     </style>
 
-    <style name="OnboardStartLayout">
-        <item name="android:layout_height">wrap_content</item>
-        <item name="android:layout_width">400dp</item>
-    </style>
-
     <style name="TextAppearance.UrlBar.Title" parent="TextAppearance.Medium">
         <item name="android:textSize">16sp</item>
     </style>
 
 </resources>
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -830,20 +830,16 @@
 
     <!-- Make the share overlay activity appear like an overlay. -->
     <style name="ShareOverlayActivity">
         <item name="android:windowBackground">@android:color/transparent</item>
         <item name="android:windowNoTitle">true</item>
         <item name="android:windowIsTranslucent">true</item>
         <item name="android:backgroundDimEnabled">true</item>
     </style>
-    <style name="OnboardStartLayout">
-        <item name="android:layout_width">match_parent</item>
-        <item name="android:layout_height">match_parent</item>
-    </style>
 
     <style name="OnboardStartTextAppearance">
         <item name="android:textColor">#5F636B</item>
     </style>
 
     <style name="OnboardStartTextAppearance.Subtext">
         <item name="android:textSize">18sp</item>
     </style>