Commit 67a6a397 authored by Jian Li's avatar Jian Li Committed by Commit Bot

Dismiss top snackbar move when top toolbar moves

Also do not associate the top snackbar view with bottom container
view in order to make it also work with Duet mode enabled.

Bug: 882596
Change-Id: I34ed55cc6bc90ff705e488914773d7be116087df
Reviewed-on: https://chromium-review.googlesource.com/1217590Reviewed-by: default avatarPeter Williamson <petewil@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590150}
parent 474b3cf6
......@@ -12,13 +12,15 @@ import android.view.View.OnClickListener;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener;
import org.chromium.chrome.browser.snackbar.Snackbar;
/**
* Manager for one-off snackbar showing at the top of activity.
*/
public class TopSnackbarManager
implements OnClickListener, ApplicationStatus.ActivityStateListener {
implements OnClickListener, ApplicationStatus.ActivityStateListener, FullscreenListener {
private final Handler mDismissSnackbarHandler;
private final Runnable mDismissSnackbarRunnable = new Runnable() {
@Override
......@@ -27,6 +29,7 @@ public class TopSnackbarManager
}
};
private Activity mActivity;
private Snackbar mSnackbar;
private TopSnackbarView mSnackbarView;
......@@ -46,6 +49,23 @@ public class TopSnackbarManager
}
}
@Override
public void onControlsOffsetChanged(float topOffset, float bottomOffset, boolean needsAnimate) {
// When the top toolbar offset changes, dismiss the top snackbar. Ideally we want to move
// the top snackbar together with the top toolbar, but they can't be made sync because they
// are drawn in different layers (C++ vs Android native).
dismissSnackbar(false);
}
@Override
public void onBottomControlsHeightChanged(int bottomControlsHeight) {}
@Override
public void onContentOffsetChanged(float offset) {}
@Override
public void onToggleOverlayVideoMode(boolean enabled) {}
/**
* Shows a snackbar at the top of the given activity.
*/
......@@ -55,6 +75,7 @@ public class TopSnackbarManager
return;
}
mActivity = activity;
mSnackbar = snackbar;
mSnackbarView = new TopSnackbarView(activity, this, mSnackbar, null);
......@@ -63,6 +84,11 @@ public class TopSnackbarManager
mDismissSnackbarHandler.removeCallbacks(mDismissSnackbarRunnable);
mDismissSnackbarHandler.postDelayed(mDismissSnackbarRunnable, mSnackbar.getDuration());
if (activity instanceof ChromeActivity) {
ChromeActivity chromeActivity = (ChromeActivity) activity;
chromeActivity.getFullscreenManager().addListener(this);
}
ApplicationStatus.registerStateListenerForActivity(this, activity);
}
......@@ -84,6 +110,11 @@ public class TopSnackbarManager
ApplicationStatus.unregisterActivityStateListener(this);
if (mActivity instanceof ChromeActivity) {
ChromeActivity chromeActivity = (ChromeActivity) mActivity;
chromeActivity.getFullscreenManager().removeListener(this);
}
mDismissSnackbarHandler.removeCallbacks(mDismissSnackbarRunnable);
if (mSnackbarView != null) {
mSnackbarView.dismiss();
......
......@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.offlinepages.indicator;
import android.app.Activity;
import android.content.res.Resources;
import android.support.annotation.Nullable;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
......@@ -41,7 +40,13 @@ public class TopSnackbarView extends SnackbarView {
@Override
protected int getBottomMarginForLayout() {
return mParent.getHeight() - mSnackbarView.getHeight() - getToolbarHeight();
return mParent.getHeight() - mSnackbarView.getHeight() - getOffsetFromTop();
}
@Override
protected ViewGroup findParentView(Activity activity) {
// Override this in order not to associate top snackbar view with bottom container view.
return (ViewGroup) activity.findViewById(android.R.id.content);
}
@Override
......@@ -50,7 +55,7 @@ public class TopSnackbarView extends SnackbarView {
+ mContainerView.getResources().getString(R.string.top_bar_screen_position));
}
private int getToolbarHeight() {
private int getOffsetFromTop() {
if (!(mActivity instanceof ChromeActivity)) return 0;
if (mActivity instanceof FullscreenActivity) return 0;
......@@ -59,8 +64,6 @@ public class TopSnackbarView extends SnackbarView {
if (chromeActivity.getFullscreenManager().getContentOffset() == 0) return 0;
// TODO(jianli): This may not work in Duet on the NTP.
Resources resources = chromeActivity.getResources();
return resources.getDimensionPixelSize(chromeActivity.getControlContainerHeightResource());
return chromeActivity.getFullscreenManager().getTopControlsHeight();
}
}
......@@ -298,7 +298,7 @@ public class SnackbarView {
/**
* @return The parent {@link ViewGroup} that {@link #mContainerView} will be added to.
*/
private ViewGroup findParentView(Activity activity) {
protected ViewGroup findParentView(Activity activity) {
if (activity instanceof ChromeActivity) {
return (ViewGroup) activity.findViewById(R.id.bottom_container);
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment