Bug 1352004 - Fix doorhangers missing background. r?dale,sebastian
MozReview-Commit-ID: 6vrY17fYXD6
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -224,17 +224,17 @@ public class BrowserApp extends GeckoApp
private BrowserSearch mBrowserSearch;
private View mBrowserSearchContainer;
public ViewGroup mBrowserChrome;
public ViewFlipper mActionBarFlipper;
public ActionModeCompatView mActionBar;
private VideoPlayer mVideoPlayer;
private BrowserToolbar mBrowserToolbar;
- private View mDoorhangerOverlay;
+ private View doorhangerOverlay;
// We can't name the TabStrip class because it's not included on API 9.
private TabStripInterface mTabStrip;
private ToolbarProgressView mProgressView;
private FirstrunAnimationContainer mFirstrunAnimationContainer;
private HomeScreen mHomeScreen;
private TabsPanel mTabsPanel;
/**
* Container for the home screen implementation. This will be populated with any valid
@@ -724,17 +724,17 @@ public class BrowserApp extends GeckoApp
mBrowserSearch.setUserVisibleHint(false);
}
setBrowserToolbarListeners();
mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
mMediaCastingBar = (MediaCastingBar) findViewById(R.id.media_casting);
- mDoorhangerOverlay = findViewById(R.id.doorhanger_overlay);
+ doorhangerOverlay = findViewById(R.id.doorhanger_overlay);
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Search:Keyword",
null);
EventDispatcher.getInstance().registerUiThreadListener(this,
"Menu:Open",
"Menu:Update",
@@ -1614,29 +1614,17 @@ public class BrowserApp extends GeckoApp
onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
invalidateOptionsMenu();
}
}
@Override
public void onDoorHangerShow() {
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
-
- final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 1);
- alphaAnimator.setDuration(250);
-
- alphaAnimator.start();
- }
-
- @Override
- public void onDoorHangerHide() {
- final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 0);
- alphaAnimator.setDuration(200);
-
- alphaAnimator.start();
+ super.onDoorHangerShow();
}
private void setToolbarMargin(int margin) {
((RelativeLayout.LayoutParams) mGeckoLayout.getLayoutParams()).topMargin = margin;
mGeckoLayout.requestLayout();
}
@Override
@@ -4070,16 +4058,21 @@ public class BrowserApp extends GeckoApp
@Override
public void onEditSuggestion(String suggestion) {
mBrowserToolbar.onEditSuggestion(suggestion);
}
@Override
public int getLayout() { return R.layout.gecko_app; }
+ @Override
+ public View getDoorhangerOverlay() {
+ return doorhangerOverlay;
+ }
+
public SearchEngineManager getSearchEngineManager() {
return mSearchEngineManager;
}
// For use from tests only.
@RobocopTarget
public ReadingListHelper getReadingListHelper() {
return mReadingListHelper;
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -43,16 +43,18 @@ import org.mozilla.gecko.util.ColorUtil;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.FileUtils;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.PrefUtils;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.webapps.WebAppActivity;
+import android.animation.Animator;
+import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -104,16 +106,17 @@ import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.util.ViewUtil;
+import org.mozilla.gecko.widget.AnchoredPopup;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.ArrayList;
@@ -132,17 +135,18 @@ public abstract class GeckoApp
implements
BundleEventListener,
ContextGetter,
GeckoAppShell.GeckoInterface,
ScreenOrientationDelegate,
GeckoMenu.Callback,
GeckoMenu.MenuPresenter,
Tabs.OnTabsChangedListener,
- ViewTreeObserver.OnGlobalLayoutListener {
+ ViewTreeObserver.OnGlobalLayoutListener,
+ AnchoredPopup.OnVisibilityChangeListener {
private static final String LOGTAG = "GeckoApp";
private static final long ONE_DAY_MS = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
public static final String ACTION_ALERT_CALLBACK = "org.mozilla.gecko.ALERT_CALLBACK";
public static final String ACTION_HOMESCREEN_SHORTCUT = "org.mozilla.gecko.BOOKMARK";
public static final String ACTION_WEBAPP = "org.mozilla.gecko.WEBAPP";
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
@@ -346,16 +350,18 @@ public abstract class GeckoApp
private volatile Locale mLastLocale;
protected Intent mRestartIntent;
private boolean mWasFirstTabShownAfterActivityUnhidden;
abstract public int getLayout();
+ abstract public View getDoorhangerOverlay();
+
protected void processTabQueue() {};
protected void openQueuedTabs() {};
@SuppressWarnings("serial")
class SessionRestoreException extends Exception {
public SessionRestoreException(Exception e) {
super(e);
@@ -1559,20 +1565,43 @@ public abstract class GeckoApp
// We don't call this.onConfigurationChanged, because (a) that does
// work that's unnecessary after this locale action, and (b) it can
// cause a loop! See Bug 1011008, Comment 12.
super.onConfigurationChanged(getResources().getConfiguration());
}
protected void initializeChrome() {
mDoorHangerPopup = new DoorHangerPopup(this);
+ mDoorHangerPopup.setOnVisibilityChangeListener(this);
mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);
mFormAssistPopup = (FormAssistPopup) findViewById(R.id.form_assist_popup);
}
+ @Override
+ public void onDoorHangerShow() {
+ final View overlay = getDoorhangerOverlay();
+ if (overlay != null) {
+ final Animator alphaAnimator = ObjectAnimator.ofFloat(overlay, "alpha", 1);
+ alphaAnimator.setDuration(250);
+
+ alphaAnimator.start();
+ }
+ }
+
+ @Override
+ public void onDoorHangerHide() {
+ final View overlay = getDoorhangerOverlay();
+ if (overlay != null) {
+ final Animator alphaAnimator = ObjectAnimator.ofFloat(overlay, "alpha", 0);
+ alphaAnimator.setDuration(200);
+
+ alphaAnimator.start();
+ }
+ }
+
/**
* Loads the initial tab at Fennec startup. If we don't restore tabs, this
* tab will be about:home, or the homepage if the user has set one.
* If we've temporarily disabled restoring to break out of a crash loop, we'll show
* the Recent Tabs folder of the Combined History panel, so the user can manually
* restore tabs as needed.
* If we restore tabs, we don't need to create a new tab, unless launch intent specify action
* to be #android.Intent.ACTION_VIEW, which is launched from widget to create a new tab.
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -49,16 +49,17 @@ import org.mozilla.gecko.widget.GeckoPop
import java.util.List;
public class CustomTabsActivity extends GeckoApp implements Tabs.OnTabsChangedListener {
private static final String LOGTAG = "CustomTabsActivity";
private static final String SAVED_START_INTENT = "saved_intent_which_started_this_activity";
private final SparseArrayCompat<PendingIntent> menuItemsIntent = new SparseArrayCompat<>();
private GeckoPopupMenu popupMenu;
+ private View doorhangerOverlay;
private ActionBarPresenter actionBarPresenter;
private ProgressBar mProgressView;
// A state to indicate whether this activity is finishing with customize animation
private boolean usingCustomAnimation = false;
// Bug 1351605 - getIntent() not always returns the intent which started this activity.
// Therefore we make a copy in case of this Activity is re-created.
private Intent startIntent;
@@ -73,16 +74,18 @@ public class CustomTabsActivity extends
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab");
startIntent = getIntent();
final String host = getReferrerHost();
recordCustomTabUsage(host);
}
setThemeFromToolbarColor();
+ doorhangerOverlay = findViewById(R.id.custom_tabs_doorhanger_overlay);
+
mProgressView = (ProgressBar) findViewById(R.id.page_progress);
final Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
bindNavigationCallback(toolbar);
actionBarPresenter = new ActionBarPresenter(actionBar);
actionBarPresenter.displayUrlOnly(startIntent.getDataString());
@@ -150,16 +153,21 @@ public class CustomTabsActivity extends
}
@Override
public int getLayout() {
return R.layout.customtabs_activity;
}
@Override
+ public View getDoorhangerOverlay() {
+ return doorhangerOverlay;
+ }
+
+ @Override
protected void onDone() {
finish();
}
@Override
public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
if (!Tabs.getInstance().isSelectedTab(tab)) {
return;
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -37,25 +37,28 @@ import org.mozilla.gecko.icons.decoders.
import org.mozilla.gecko.mozglue.SafeIntent;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.util.ColorUtil;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.FileUtils;
import org.mozilla.gecko.util.GeckoBundle;
+import org.mozilla.gecko.widget.AnchoredPopup;
public class WebAppActivity extends GeckoApp {
public static final String INTENT_KEY = "IS_A_WEBAPP";
public static final String MANIFEST_PATH = "MANIFEST_PATH";
private static final String LOGTAG = "WebAppActivity";
private TextView mUrlView;
+ private View doorhangerOverlay;
+
private String mManifestPath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "webapp");
@@ -73,28 +76,35 @@ public class WebAppActivity extends Geck
progressBar.setVisibility(View.GONE);
final ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.webapps_action_bar_custom_view);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.hide();
+ doorhangerOverlay = findViewById(R.id.custom_tabs_doorhanger_overlay);
+
final View customView = actionBar.getCustomView();
mUrlView = (TextView) customView.findViewById(R.id.webapps_action_bar_url);
EventDispatcher.getInstance().registerUiThreadListener(this,
- "Website:AppEntered",
- "Website:AppLeft",
- null);
+ "Website:AppEntered",
+ "Website:AppLeft",
+ null);
Tabs.registerOnTabsChangedListener(this);
}
@Override
+ public View getDoorhangerOverlay() {
+ return doorhangerOverlay;
+ }
+
+ @Override
public int getLayout() {
return R.layout.customtabs_activity;
}
@Override
public void handleMessage(final String event, final GeckoBundle message,
final EventCallback callback) {
switch (event) {
@@ -125,19 +135,19 @@ public class WebAppActivity extends Geck
outState.putString(WebAppActivity.MANIFEST_PATH, mManifestPath);
}
@Override
public void onDestroy() {
super.onDestroy();
EventDispatcher.getInstance().unregisterUiThreadListener(this,
- "Website:AppEntered",
- "Website:AppLeft",
- null);
+ "Website:AppEntered",
+ "Website:AppLeft",
+ null);
Tabs.unregisterOnTabsChangedListener(this);
}
@Override
protected int getNewTabFlags() {
return Tabs.LOADURL_WEBAPP | super.getNewTabFlags();
}
@@ -150,17 +160,17 @@ public class WebAppActivity extends Geck
protected void onNewIntent(Intent externalIntent) {
restoreLastSelectedTab();
final SafeIntent intent = new SafeIntent(externalIntent);
final String launchUrl = intent.getDataString();
final String currentUrl = Tabs.getInstance().getSelectedTab().getURL();
final boolean isSameDomain = Uri.parse(currentUrl).getHost()
- .equals(Uri.parse(launchUrl).getHost());
+ .equals(Uri.parse(launchUrl).getHost());
if (!isSameDomain) {
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "webapp");
mManifestPath = externalIntent.getStringExtra(WebAppActivity.MANIFEST_PATH);
loadManifest(mManifestPath);
Tabs.getInstance().loadUrl(launchUrl);
}
}
@@ -178,18 +188,18 @@ public class WebAppActivity extends Geck
try {
final File manifestFile = new File(manifestPath);
final JSONObject manifest = FileUtils.readJSONObjectFromFile(manifestFile);
final JSONObject manifestField = manifest.getJSONObject("manifest");
final Integer color = readColorFromManifest(manifestField);
final String name = readNameFromManifest(manifestField);
final Bitmap icon = readIconFromManifest(manifest);
final ActivityManager.TaskDescription taskDescription = (color == null)
- ? new ActivityManager.TaskDescription(name, icon)
- : new ActivityManager.TaskDescription(name, icon, color);
+ ? new ActivityManager.TaskDescription(name, icon)
+ : new ActivityManager.TaskDescription(name, icon, color);
updateStatusBarColor(color);
setTaskDescription(taskDescription);
} catch (IOException | JSONException e) {
Log.e(LOGTAG, "Failed to read manifest", e);
}
}
@@ -220,14 +230,14 @@ public class WebAppActivity extends Geck
}
return name;
}
private Bitmap readIconFromManifest(JSONObject manifest) {
final String iconStr = manifest.optString("cached_icon", null);
if (iconStr != null) {
return FaviconDecoder
- .decodeDataURI(getContext(), iconStr)
- .getBestBitmap(GeckoAppShell.getPreferredIconSize());
+ .decodeDataURI(getContext(), iconStr)
+ .getBestBitmap(GeckoAppShell.getPreferredIconSize());
}
return null;
}
}
--- a/mobile/android/base/resources/layout/customtabs_activity.xml
+++ b/mobile/android/base/resources/layout/customtabs_activity.xml
@@ -53,9 +53,15 @@
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignTop="@id/main_layout"
android:background="@drawable/url_bar_bg"
android:progressDrawable="@drawable/progressbar"
tools:progress="70"/>
+ <View android:id="@+id/custom_tabs_doorhanger_overlay"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/dark_transparent_overlay"
+ android:alpha="0"
+ android:layerType="hardware"/>
</RelativeLayout>
\ No newline at end of file