Commit 8b2addc4 authored by Mia Glaese's avatar Mia Glaese Committed by Commit Bot

[Start Surface] Incognito mode for single and two pane surface.

Bug: 982018

Change-Id: I1a9f44df3b737e9829f5766744e0c4e0a88e45f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1763232
Commit-Queue: Mia Glaese <glamia@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693110}
parent e1cdc843
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/default_icon_color_disabled" />
<item android:state_selected="true" android:color="@color/light_active_color" />
<item android:state_focused="true" android:color="@color/light_active_color" />
<item android:state_pressed="true" android:color="@color/light_active_color" />
<item android:state_activated="true" android:color="@color/default_icon_color" />
<item android:color="@color/default_icon_color"/>
</selector>
......@@ -5,25 +5,18 @@
package org.chromium.chrome.features.start_surface;
import android.content.Context;
import android.content.res.ColorStateList;
import android.support.design.widget.TabLayout;
import android.support.v7.content.res.AppCompatResources;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.start_surface.R;
import org.chromium.ui.widget.ChromeImageView;
/** The bottom bar view. */
// TODO(crbug.com/982018): Support dark mode.
class BottomBarView extends FrameLayout {
private final ColorStateList mNormalButtonTintColor;
private final ColorStateList mNormalIndicatorColor;
private final ColorStateList mIncognitoButtonTintColor;
private final ColorStateList mIncognitoIndicatorColor;
private TabLayout mTabLayout;
private TabLayout.Tab mHomeTab;
......@@ -36,15 +29,6 @@ class BottomBarView extends FrameLayout {
public BottomBarView(Context context, AttributeSet attrs) {
super(context, attrs);
mNormalIndicatorColor =
AppCompatResources.getColorStateList(context, R.color.light_active_color);
mNormalButtonTintColor =
AppCompatResources.getColorStateList(context, R.color.ss_normal_bottom_button_tint);
mIncognitoButtonTintColor =
AppCompatResources.getColorStateList(context, R.color.white_alpha_70);
mIncognitoIndicatorColor =
AppCompatResources.getColorStateList(context, R.color.white_mode_tint);
}
@Override
......@@ -54,10 +38,6 @@ class BottomBarView extends FrameLayout {
mTabLayout = (TabLayout) findViewById(R.id.bottom_tab_layout);
mHomeTab = mTabLayout.getTabAt(0);
mExploreTab = mTabLayout.getTabAt(1);
mHomeButton = (ChromeImageView) mTabLayout.findViewById(R.id.ss_home_button);
mHomeButtonLabel = (TextView) mTabLayout.findViewById(R.id.ss_home_button_label);
mExploreButton = (ChromeImageView) mTabLayout.findViewById(R.id.ss_explore_button);
mExploreButtonLabel = (TextView) mTabLayout.findViewById(R.id.ss_explore_button_label);
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
......@@ -82,30 +62,6 @@ class BottomBarView extends FrameLayout {
});
}
/**
* Set the incognito state.
* @param isIncognito Whether is in incognito mode.
*/
public void setIncognito(boolean isIncognito) {
// TODO(crbug.com/982018): Support dark mode.
setBackgroundColor(
ColorUtils.getPrimaryBackgroundColor(getContext().getResources(), isIncognito));
if (isIncognito) {
// TODO(crbug.com/982018): Distinguish selected and unselected state in incognito mode.
mTabLayout.setSelectedTabIndicatorColor(mIncognitoIndicatorColor.getDefaultColor());
ApiCompatibilityUtils.setImageTintList(mHomeButton, mIncognitoButtonTintColor);
mHomeButtonLabel.setTextColor(mIncognitoButtonTintColor);
ApiCompatibilityUtils.setImageTintList(mExploreButton, mIncognitoButtonTintColor);
mExploreButtonLabel.setTextColor(mIncognitoButtonTintColor);
} else {
mTabLayout.setSelectedTabIndicatorColor(mNormalIndicatorColor.getDefaultColor());
ApiCompatibilityUtils.setImageTintList(mHomeButton, mNormalButtonTintColor);
mHomeButtonLabel.setTextColor(mNormalButtonTintColor);
ApiCompatibilityUtils.setImageTintList(mExploreButton, mNormalButtonTintColor);
mExploreButtonLabel.setTextColor(mNormalButtonTintColor);
}
}
/**
* Set the visibility of this bottom bar.
* @param shown Whether set the visibility to visible or not.
......@@ -132,4 +88,4 @@ class BottomBarView extends FrameLayout {
if (index == mTabLayout.getSelectedTabPosition()) return;
mTabLayout.getTabAt(index).select();
}
}
\ No newline at end of file
}
......@@ -6,7 +6,7 @@ package org.chromium.chrome.features.start_surface;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_CLICKLISTENER;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_SELECTED_TAB_POSITION;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_INCOGNITO;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_BOTTOM_BAR_VISIBLE;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_SHOWING_OVERVIEW;
import org.chromium.ui.modelutil.PropertyKey;
......@@ -19,10 +19,10 @@ class BottomBarViewBinder {
view.setOnClickListener(model.get(BOTTOM_BAR_CLICKLISTENER));
} else if (BOTTOM_BAR_SELECTED_TAB_POSITION == propertyKey) {
view.selectTabAt(model.get(BOTTOM_BAR_SELECTED_TAB_POSITION));
} else if (IS_INCOGNITO == propertyKey) {
view.setIncognito(model.get(IS_INCOGNITO));
} else if (IS_BOTTOM_BAR_VISIBLE == propertyKey) {
view.setVisibility(model.get(IS_SHOWING_OVERVIEW) && model.get(IS_BOTTOM_BAR_VISIBLE));
} else if (IS_SHOWING_OVERVIEW == propertyKey) {
view.setVisibility(model.get(IS_SHOWING_OVERVIEW));
view.setVisibility(model.get(IS_SHOWING_OVERVIEW) && model.get(IS_BOTTOM_BAR_VISIBLE));
}
}
}
\ No newline at end of file
}
......@@ -37,10 +37,9 @@ class ExploreSurfaceCoordinator implements FeedSurfaceCoordinator.FeedSurfaceDel
interface FeedSurfaceCreator {
/**
* Creates the {@link FeedSurfaceCoordinator} for the specified mode.
* @param isIncognito Whether it is in incognito mode.
* @return The {@link FeedSurfaceCoordinator}.
*/
FeedSurfaceCoordinator createFeedSurfaceCoordinator(boolean isIncognito);
FeedSurfaceCoordinator createFeedSurfaceCoordinator();
}
ExploreSurfaceCoordinator(ChromeActivity activity, ViewGroup parentView,
......@@ -57,8 +56,8 @@ class ExploreSurfaceCoordinator implements FeedSurfaceCoordinator.FeedSurfaceDel
ExploreSurfaceViewBinder::bind);
mFeedSurfaceCreator = new FeedSurfaceCreator() {
@Override
public FeedSurfaceCoordinator createFeedSurfaceCoordinator(boolean isIncognito) {
return internalCreateFeedSurfaceCoordinator(isIncognito);
public FeedSurfaceCoordinator createFeedSurfaceCoordinator() {
return internalCreateFeedSurfaceCoordinator();
}
};
}
......@@ -82,22 +81,19 @@ class ExploreSurfaceCoordinator implements FeedSurfaceCoordinator.FeedSurfaceDel
return false;
}
private FeedSurfaceCoordinator internalCreateFeedSurfaceCoordinator(boolean isIncognito) {
private FeedSurfaceCoordinator internalCreateFeedSurfaceCoordinator() {
if (mExploreSurfaceNavigationDelegate == null)
mExploreSurfaceNavigationDelegate = new ExploreSurfaceNavigationDelegate(mActivity);
mExploreSurfaceNavigationDelegate.setIncognito(isIncognito);
ExploreSurfaceActionHandler exploreSurfaceActionHandler =
new ExploreSurfaceActionHandler(mExploreSurfaceNavigationDelegate,
FeedProcessScopeFactory.getFeedConsumptionObserver(),
FeedProcessScopeFactory.getFeedOfflineIndicator(),
OfflinePageBridge.getForProfile(isIncognito
? Profile.getLastUsedProfile().getOffTheRecordProfile()
: Profile.getLastUsedProfile()),
OfflinePageBridge.getForProfile(Profile.getLastUsedProfile()),
FeedProcessScopeFactory.getFeedLoggingBridge());
return new FeedSurfaceCoordinator(
mActivity, null, null, null, exploreSurfaceActionHandler, isIncognito, this);
mActivity, null, null, null, exploreSurfaceActionHandler, false, this);
// TODO(crbug.com/982018): Customize surface background for incognito and dark mode.
// TODO(crbug.com/982018): Hide signin promo UI in incognito mode.
}
}
\ No newline at end of file
}
......@@ -21,7 +21,6 @@ import androidx.browser.customtabs.CustomTabsIntent;
/** Implementation of the {@link NativePageNavigationDelegate} for the explore surface. */
class ExploreSurfaceNavigationDelegate implements NativePageNavigationDelegate {
private final Context mContext;
private boolean mIsInCognito;
ExploreSurfaceNavigationDelegate(Context context) {
mContext = context;
......@@ -43,9 +42,7 @@ class ExploreSurfaceNavigationDelegate implements NativePageNavigationDelegate {
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setPackage(mContext.getPackageName());
customTabsIntent.intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB,
(windowOpenDisposition == WindowOpenDisposition.OFF_THE_RECORD || mIsInCognito)
? true
: false);
(windowOpenDisposition == WindowOpenDisposition.OFF_THE_RECORD) ? true : false);
customTabsIntent.intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
customTabsIntent.launchUrl(mContext, Uri.parse(loadUrlParams.getUrl()));
......@@ -53,8 +50,4 @@ class ExploreSurfaceNavigationDelegate implements NativePageNavigationDelegate {
// mode accordingly (note that payment window supports incognito mode).
return null;
}
public void setIncognito(boolean isIncognito) {
mIsInCognito = isIncognito;
}
}
......@@ -45,16 +45,11 @@ class ExploreSurfaceViewBinder {
public static void bind(PropertyModel model, ViewHolder view, PropertyKey propertyKey) {
if (propertyKey == IS_EXPLORE_SURFACE_VISIBLE) {
setVisibility(view, model, model.get(IS_EXPLORE_SURFACE_VISIBLE));
setVisibility(view, model,
model.get(IS_EXPLORE_SURFACE_VISIBLE) && model.get(IS_SHOWING_OVERVIEW));
} else if (propertyKey == IS_SHOWING_OVERVIEW) {
if (!model.get(IS_EXPLORE_SURFACE_VISIBLE)) return;
if (model.get(IS_SHOWING_OVERVIEW)) {
// Set the initial state if the explore surface is selected previously.
setVisibility(view, model, true);
} else {
setVisibility(view, model, false);
}
setVisibility(view, model,
model.get(IS_EXPLORE_SURFACE_VISIBLE) && model.get(IS_SHOWING_OVERVIEW));
}
}
......@@ -103,4 +98,4 @@ class ExploreSurfaceViewBinder {
UiUtils.removeViewFromParent(feedSurfaceView);
}
}
}
\ No newline at end of file
}
......@@ -5,14 +5,12 @@
package org.chromium.chrome.features.start_surface;
import static org.chromium.chrome.browser.tasks.TasksSurfaceProperties.MORE_TABS_CLICK_LISTENER;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_HEIGHT;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.TOP_BAR_HEIGHT;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.view.ViewGroup;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.tasks.ReturnToChromeExperimentsUtil;
......@@ -193,7 +191,11 @@ public class StartSurfaceCoordinator implements StartSurface {
}
mPropertyModel = new PropertyModel(StartSurfaceProperties.ALL_KEYS);
if (mSurfaceMode == SurfaceMode.TWO_PANES) createAndSetBottomBar();
if (mSurfaceMode == SurfaceMode.TWO_PANES) {
mBottomBarCoordinator = new BottomBarCoordinator(
mActivity, mActivity.getCompositorViewHolder(), mPropertyModel);
}
int toolbarHeight =
mActivity.getResources().getDimensionPixelSize(R.dimen.toolbar_height_no_shadow);
......@@ -217,19 +219,6 @@ public class StartSurfaceCoordinator implements StartSurface {
mPropertyModel);
}
private void createAndSetBottomBar() {
// Margin the bottom of the Tab grid to save space for the bottom bar.
int bottomBarHeight =
ContextUtils.getApplicationContext().getResources().getDimensionPixelSize(
R.dimen.ss_bottom_bar_height);
mTasksSurface.getTabListDelegate().setBottomControlsHeight(bottomBarHeight);
mPropertyModel.set(BOTTOM_BAR_HEIGHT, bottomBarHeight);
// Create the bottom bar.
mBottomBarCoordinator = new BottomBarCoordinator(
mActivity, mActivity.getCompositorViewHolder(), mPropertyModel);
}
private TabSwitcher.Controller initializeSecondaryTasksSurface() {
assert mSurfaceMode == SurfaceMode.SINGLE_PANE;
assert mSecondaryTasksSurface == null;
......
......@@ -28,9 +28,9 @@ class StartSurfaceProperties {
new PropertyModel.WritableIntPropertyKey();
public static final PropertyModel.WritableIntPropertyKey BOTTOM_BAR_SELECTED_TAB_POSITION =
new PropertyModel.WritableIntPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_EXPLORE_SURFACE_VISIBLE =
public static final PropertyModel.WritableBooleanPropertyKey IS_BOTTOM_BAR_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_INCOGNITO =
public static final PropertyModel.WritableBooleanPropertyKey IS_EXPLORE_SURFACE_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_SHOWING_OVERVIEW =
new PropertyModel.WritableBooleanPropertyKey();
......@@ -40,6 +40,7 @@ class StartSurfaceProperties {
public static final PropertyModel.WritableIntPropertyKey TOP_BAR_HEIGHT =
new PropertyModel.WritableIntPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {BOTTOM_BAR_CLICKLISTENER,
BOTTOM_BAR_HEIGHT, BOTTOM_BAR_SELECTED_TAB_POSITION, IS_EXPLORE_SURFACE_VISIBLE,
IS_INCOGNITO, IS_SHOWING_OVERVIEW, FEED_SURFACE_COORDINATOR, TOP_BAR_HEIGHT};
}
\ No newline at end of file
BOTTOM_BAR_HEIGHT, BOTTOM_BAR_SELECTED_TAB_POSITION, IS_BOTTOM_BAR_VISIBLE,
IS_EXPLORE_SURFACE_VISIBLE, IS_SHOWING_OVERVIEW, FEED_SURFACE_COORDINATOR,
TOP_BAR_HEIGHT};
}
......@@ -99,6 +99,12 @@ public interface TabSwitcher {
* @return Whether or not the TabSwitcher consumed the event.
*/
boolean onBackPressed();
/**
* Set the bottom control height to margin the bottom of the TabListRecyclerView.
* @param bottomControlsHeight The bottom control height in pixel.
*/
void setBottomControlsHeight(int bottomControlsHeight);
}
/**
......@@ -122,12 +128,6 @@ public interface TabSwitcher {
*/
long getLastDirtyTimeForTesting();
/**
* Set the bottom control height to margin the bottom of the TabListRecyclerView.
* @param bottomControlsHeight The bottom control height in pixel.
*/
void setBottomControlsHeight(int bottomControlsHeight);
/**
* Before calling {@link Controller#showOverview} to start showing the
* TabSwitcher {@link TabListRecyclerView}, call this to populate it without making it
......
......@@ -149,11 +149,6 @@ public class TabSwitcherCoordinator implements Destroyable, TabSwitcher,
return this;
}
@Override
public void setBottomControlsHeight(int bottomControlsHeight) {
mMediator.setBottomControlsHeight(bottomControlsHeight);
}
@Override
public boolean prepareOverview() {
boolean quick = mMediator.prepareOverview();
......
......@@ -262,10 +262,6 @@ class TabSwitcherMediator implements TabSwitcher.Controller, TabListRecyclerView
mShowTabsInMruOrder = feature.equals("twopanes") || feature.equals("single");
}
void setBottomControlsHeight(int bottomControlsHeight) {
mContainerViewModel.set(BOTTOM_CONTROLS_HEIGHT, bottomControlsHeight);
}
/**
* Set the handler of the Grid Dialog so that it can be directly controlled.
* @param tabGridDialogResetHandler The handler of the Grid Dialog
......@@ -482,6 +478,11 @@ class TabSwitcherMediator implements TabSwitcher.Controller, TabListRecyclerView
return true;
}
@Override
public void setBottomControlsHeight(int bottomControlsHeight) {
mContainerViewModel.set(BOTTOM_CONTROLS_HEIGHT, bottomControlsHeight);
}
/**
* Do clean-up work after the overview hiding animation is finished.
* @see TabSwitcher#postHiding
......
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