Bug 1369681 - CustomTab hide content to prevent flash r=JanH,sebastian
authorJulian_Chu <walkingice0204@gmail.com>
Fri, 02 Jun 2017 17:30:23 +0800
changeset 410907 b9b5c00e6352a396d0e72dd90aa1c843c30bb871
parent 410906 1df01865d1002d084da22266ab74827aa1298759
child 410908 57187d8e14337441e40c2ca33c2997e95bc7cdd0
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJanH, sebastian
bugs1369681
milestone55.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 1369681 - CustomTab hide content to prevent flash r=JanH,sebastian In some cases, user might see flash in first launch of CustomTabs. This issue could be fixed once we have GeckoView based implementation. Before it comes, we just hide content for a while as a workaround. This workaround is in SingleTabActivity since we also want to benefit WebApps. MozReview-Commit-ID: HenLSOqROA2
mobile/android/base/java/org/mozilla/gecko/SingleTabActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/SingleTabActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/SingleTabActivity.java
@@ -2,36 +2,54 @@
  * 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/. */
 
 package org.mozilla.gecko;
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.support.annotation.ColorInt;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
+import android.support.v4.content.ContextCompat;
+import android.view.View;
 
 import org.mozilla.gecko.mozglue.SafeIntent;
+import org.mozilla.gecko.util.ThreadUtils;
 
 import static org.mozilla.gecko.Tabs.INTENT_EXTRA_SESSION_UUID;
 import static org.mozilla.gecko.Tabs.INTENT_EXTRA_TAB_ID;
 import static org.mozilla.gecko.Tabs.INVALID_TAB_ID;
 
 public abstract class SingleTabActivity extends GeckoApp {
+
+    private static final long SHOW_CONTENT_DELAY = 300;
+
+    private View mainLayout;
+    private View contentView;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         final Intent externalIntent = getIntent();
 
         decideTabAction(new SafeIntent(externalIntent), savedInstanceState);
 
         super.onCreate(savedInstanceState);
         // GeckoApp's default behaviour is to reset the intent if we've got any
         // savedInstanceState, which we don't want here.
         setIntent(externalIntent);
+
+        mainLayout = findViewById(R.id.main_layout);
+        contentView = findViewById(R.id.gecko_layout);
+        if ((mainLayout != null) && (contentView != null)) {
+            @ColorInt final int bg = ContextCompat.getColor(this, android.R.color.white);
+            mainLayout.setBackgroundColor(bg);
+            contentView.setVisibility(View.INVISIBLE);
+        }
     }
 
     @Override
     protected void onNewIntent(Intent externalIntent) {
         final SafeIntent intent = new SafeIntent(externalIntent);
 
         if (decideTabAction(intent, null)) {
             // GeckoApp will handle tab selection.
@@ -140,21 +158,41 @@ public abstract class SingleTabActivity 
      * Called when an intent or onResume() has caused us to load and select a new tab.
      *
      * @param tab The new tab that has been opened and selected.
      */
     @Override
     protected void onTabOpenFromIntent(Tab tab) {
         mLastSelectedTabId = tab.getId();
         mLastSessionUUID = GeckoApplication.getSessionUUID();
+        showContentView();
     }
 
     /**
      * Called when an intent has caused us to select an already existing tab.
      *
      * @param tab The already existing tab that has been selected for this activity.
      */
     @Override
     protected void onTabSelectFromIntent(Tab tab) {
         mLastSelectedTabId = tab.getId();
         mLastSessionUUID = GeckoApplication.getSessionUUID();
+        showContentView();
+    }
+
+    // Bug 1369681 - a workaround to prevent flash in first launch.
+    // This will be removed once we have GeckoView based implementation.
+    private void showContentView() {
+        if ((contentView != null)
+                && (mainLayout != null)
+                && (contentView.getVisibility() == View.INVISIBLE)) {
+            ThreadUtils.postDelayedToUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    @ColorInt final int bg =
+                            ContextCompat.getColor(mainLayout.getContext(), android.R.color.white);
+                    mainLayout.setBackgroundColor(bg);
+                    contentView.setVisibility(View.VISIBLE);
+                }
+            }, SHOW_CONTENT_DELAY);
+        }
     }
 }