Commit 814b46a3 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Ephemeral tab : Some UI polish

This CL adds
1 - Fixes default favicon to show the globe icon
2 - Fixes vertical alignment of favicon
3 - Adds the close button back
4 - Makes open_in_new_tab button visible only when in full state

Bug: 1025085, 1025084, 1025088, 1023659
Change-Id: I2dff5b9949fb33dba4c0b6f009ca5ee92503d8d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1918646
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarJinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716364}
parent 47048a4f
......@@ -29,11 +29,12 @@
<org.chromium.ui.widget.ChromeImageView
android:id="@+id/favicon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="12dp"
android:padding="12dp"
android:layout_alignParentStart="true"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentBottom="true"
android:layout_marginStart="18dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="14dp"
android:scaleType="fitCenter"
tools:ignore="ContentDescription" />
......@@ -48,14 +49,28 @@
android:src="@drawable/drag_handlebar" />
<org.chromium.ui.widget.ChromeImageView
android:id="@+id/open_in_new_tab"
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/close"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:padding="12dp"
android:layout_alignParentBottom="true"
android:layout_marginEnd="16dp"
android:layout_marginBottom="14dp"
android:src="@drawable/btn_close"
android:contentDescription="@string/close"
app:tint="@color/default_icon_color" />
<org.chromium.ui.widget.ChromeImageView
android:id="@+id/open_in_new_tab"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_toStartOf="@+id/close"
android:layout_alignParentBottom="true"
android:layout_marginEnd="16dp"
android:layout_marginBottom="14dp"
android:src="@drawable/open_in_new_tab"
android:contentDescription="@string/contextmenu_open_in_new_tab"
android:visibility="gone"
app:tint="@color/default_icon_color" />
<TextView
......
......@@ -33,6 +33,7 @@ import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.ui.UiUtils;
import org.chromium.ui.base.PageTransition;
/**
......@@ -66,7 +67,13 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener {
mBottomSheetController.addObserver(new EmptyBottomSheetObserver() {
@Override
public void onSheetStateChanged(int newState) {
if (newState == BottomSheetController.SheetState.HIDDEN) destroyContent();
if (newState == SheetState.HIDDEN) {
destroyContent();
return;
}
if (mSheetContent == null) return;
mSheetContent.showOpenInNewTabButton(newState == SheetState.FULL);
}
});
}
......@@ -141,6 +148,10 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener {
}
}
private void onCloseButtonClick() {
mBottomSheetController.hideContent(mSheetContent, /* animate= */ true);
}
private boolean canPromoteToNewTab() {
return !mActivity.isCustomTab();
}
......@@ -151,8 +162,8 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener {
}
private EphemeralTabSheetContent createSheetContent() {
mSheetContent = new EphemeralTabSheetContent(
mActivity, () -> openInNewTab(), () -> onToolbarClick(), getMaxSheetHeight());
mSheetContent = new EphemeralTabSheetContent(mActivity, this::openInNewTab,
this::onToolbarClick, this::onCloseButtonClick, getMaxSheetHeight());
mActivity.getWindow().getDecorView().addOnLayoutChangeListener(this);
return mSheetContent;
......@@ -284,7 +295,6 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener {
private static class FaviconLoader {
private final Context mContext;
private final FaviconHelper mFaviconHelper;
private final FaviconHelper.DefaultFaviconHelper mDefaultFaviconHelper;
private final RoundedIconGenerator mIconGenerator;
private final int mFaviconSize;
......@@ -292,7 +302,6 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener {
public FaviconLoader(Context context) {
mContext = context;
mFaviconHelper = new FaviconHelper();
mDefaultFaviconHelper = new FaviconHelper.DefaultFaviconHelper();
mIconGenerator = FaviconUtils.createCircularIconGenerator(mContext.getResources());
mFaviconSize =
mContext.getResources().getDimensionPixelSize(R.dimen.preview_tab_favicon_size);
......@@ -311,8 +320,8 @@ public class EphemeralTabCoordinator implements View.OnLayoutChangeListener {
drawable = FaviconUtils.createRoundedBitmapDrawable(
mContext.getResources(), bitmap);
} else {
drawable = mDefaultFaviconHelper.getDefaultFaviconDrawable(
mContext.getResources(), iconUrl, true);
drawable = UiUtils.getTintedDrawable(
mContext, R.drawable.ic_globe_24dp, R.color.standard_mode_tint);
}
callback.onResult(drawable);
......
......@@ -40,6 +40,7 @@ public class EphemeralTabSheetContent implements BottomSheetContent {
private final Context mContext;
private final Runnable mOpenNewTabCallback;
private final Runnable mToolbarClickCallback;
private final Runnable mCloseButtonCallback;
private final int mToolbarHeightPx;
private ViewGroup mToolbarView;
......@@ -57,13 +58,15 @@ public class EphemeralTabSheetContent implements BottomSheetContent {
* @param context An Android context.
* @param openNewTabCallback Callback invoked to open a new tab.
* @param toolbarClickCallback Callback invoked when user clicks on the toolbar.
* @param closeButtonCallback Callback invoked when user clicks on the close button.
* @param maxSheetHeight The height of the sheet in full height position.
*/
public EphemeralTabSheetContent(Context context, Runnable openNewTabCallback,
Runnable toolbarClickCallback, int maxSheetHeight) {
Runnable toolbarClickCallback, Runnable closeButtonCallback, int maxSheetHeight) {
mContext = context;
mOpenNewTabCallback = openNewTabCallback;
mToolbarClickCallback = toolbarClickCallback;
mCloseButtonCallback = closeButtonCallback;
mToolbarHeightPx =
mContext.getResources().getDimensionPixelSize(R.dimen.sheet_tab_toolbar_height);
......@@ -113,6 +116,9 @@ public class EphemeralTabSheetContent implements BottomSheetContent {
View toolbar = mToolbarView.findViewById(R.id.toolbar);
toolbar.setOnClickListener(view -> mToolbarClickCallback.run());
View closeButton = mToolbarView.findViewById(R.id.close);
closeButton.setOnClickListener(view -> mCloseButtonCallback.run());
mFaviconView = mToolbarView.findViewById(R.id.favicon);
mCurrentFavicon = mFaviconView.getDrawable();
}
......@@ -181,6 +187,12 @@ public class EphemeralTabSheetContent implements BottomSheetContent {
progressBar.setVisibility(visible ? View.VISIBLE : View.GONE);
}
/** Called to show or hide the open in new tab button. */
public void showOpenInNewTabButton(boolean show) {
View openInNewTabButton = mToolbarView.findViewById(R.id.open_in_new_tab);
openInNewTabButton.setVisibility(show ? View.VISIBLE : View.GONE);
}
@Override
public View getContentView() {
return mSheetContentView;
......
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