Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2850)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java

Issue 1557803002: [Custom Tabs] Implement Bottombar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make findbug happy Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
index dfdb7f1ddd37b2aadd539cedf173b44a3c0713bb..be34f163fe982ff72743d9c15563e1a35aae33be 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
@@ -16,7 +16,9 @@ import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import android.view.ViewStub;
import android.view.Window;
+import android.widget.ImageButton;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Log;
@@ -46,6 +48,8 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelectorImpl;
import org.chromium.chrome.browser.toolbar.ToolbarControlContainer;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.util.IntentUtils;
+import org.chromium.chrome.browser.widget.FadingShadow;
+import org.chromium.chrome.browser.widget.FadingShadowView;
import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
import org.chromium.content_public.browser.LoadUrlParams;
@@ -53,6 +57,8 @@ import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.common.Referrer;
import org.chromium.ui.base.PageTransition;
+import java.util.List;
+
/**
* The activity for custom tabs. It will be launched on top of a client's task.
*/
@@ -126,19 +132,19 @@ public class CustomTabActivity extends ChromeActivity {
/**
* Checks whether the active {@link CustomTabContentHandler} belongs to the given session, and
- * if true, update toolbar's action button.
+ * if true, update toolbar's custom button.
* @param session The {@link IBinder} that the calling client represents.
* @param bitmap The new icon for action button.
* @param description The new content description for the action button.
* @return Whether the update is successful.
*/
- static boolean updateActionButton(IBinder session, Bitmap bitmap, String description) {
+ static boolean updateCustomButton(IBinder session, int id, Bitmap bitmap, String description) {
ThreadUtils.assertOnUiThread();
// Do nothing if there is no activity or the activity does not belong to this session.
if (sActiveContentHandler == null || !sActiveContentHandler.getSession().equals(session)) {
return false;
}
- return sActiveContentHandler.updateActionButton(bitmap, description);
+ return sActiveContentHandler.updateCustomButton(id, bitmap, description);
}
@Override
@@ -175,7 +181,7 @@ public class CustomTabActivity extends ChromeActivity {
setTabModelSelector(new TabModelSelectorImpl(this, 0, getWindowAndroid(), false));
getToolbarManager().setCloseButtonDrawable(mIntentDataProvider.getCloseButtonDrawable());
getToolbarManager().setShowTitle(mIntentDataProvider.getTitleVisibilityState()
- == CustomTabIntentDataProvider.SHOW_PAGE_TITLE);
+ == CustomTabsIntent.SHOW_PAGE_TITLE);
int toolbarColor = mIntentDataProvider.getToolbarColor();
getToolbarManager().updatePrimaryColor(toolbarColor);
if (toolbarColor != ApiCompatibilityUtils.getColor(
@@ -186,7 +192,8 @@ public class CustomTabActivity extends ChromeActivity {
// Setting task title and icon to be null will preserve the client app's title and icon.
ApiCompatibilityUtils.setTaskDescription(this, null, null, toolbarColor);
- showActionButton();
+ showCustomButtonOnToolbar();
+ showBottombarIfNecessary();
}
@Override
@@ -238,9 +245,15 @@ public class CustomTabActivity extends ChromeActivity {
}
@Override
- public boolean updateActionButton(Bitmap bitmap, String description) {
- mIntentDataProvider.getActionButtonParams().update(bitmap, description);
- return showActionButton();
+ public boolean updateCustomButton(int id, Bitmap bitmap, String description) {
+ List<CustomButtonParams> list = mIntentDataProvider.getAllCustomButtons();
+ for (CustomButtonParams params : list) {
+ if (params.getId() == id) {
+ params.update(bitmap, description);
+ }
+ }
+ // TODO(ianwen): support bottombar here.
+ return showCustomButtonOnToolbar();
}
};
DataUseTabUIManager.onCustomTabInitialNavigation(mainTab,
@@ -432,12 +445,11 @@ public class CustomTabActivity extends ChromeActivity {
}
/**
- * Properly setup action button on the toolbar. Does nothing if invalid data is provided by
- * clients.
+ * Configures the custom button on toolbar. Does nothing if invalid data is provided by clients.
*/
- private boolean showActionButton() {
- if (!mIntentDataProvider.shouldShowActionButton()) return false;
- ActionButtonParams params = mIntentDataProvider.getActionButtonParams();
+ private boolean showCustomButtonOnToolbar() {
+ CustomButtonParams params = mIntentDataProvider.getCustomButtonOnToolbar();
+ if (params == null) return false;
getToolbarManager().setCustomActionButton(
params.getIcon(getResources()),
params.getDescription(),
@@ -452,6 +464,34 @@ public class CustomTabActivity extends ChromeActivity {
return true;
}
+ /**
+ * Inflates the bottom bar {@link ViewStub} and its shadow, and populates it with items.
+ */
+ private void showBottombarIfNecessary() {
gone 2016/01/07 20:16:33 Strongly encouraging you to settle on a single cap
Ian Wen 2016/01/08 05:54:46 Renamed all Bottombar to either BottomBar or Botto
+ // TODO (ianwen): if button icon is too wide, show them in overflow menu instead. If button
+ // id is not specified, the overflow sequence should be toolbar -> bottombar -> menu.
+ if (!mIntentDataProvider.shouldShowBottomBar()) return;
+
+ ViewStub bottombarStub = ((ViewStub) findViewById(R.id.bottombar_stub));
+ bottombarStub.setLayoutResource(R.layout.custom_tabs_bottombar);
gone 2016/01/07 20:16:33 Makes more sense to define the android:layout attr
Ian Wen 2016/01/08 05:54:46 Acknowledged. All android:layout attributes (weigh
+ bottombarStub.inflate();
+
+ // Unlike others, this shadow docks itself at bottom and casts graphics upwards.
+ FadingShadowView shadow = (FadingShadowView) findViewById(R.id.bottombar_shadow);
+ shadow.setVisibility(View.VISIBLE);
+ shadow.init(ApiCompatibilityUtils.getColor(getResources(),
+ R.color.bottom_bar_shadow_color), FadingShadow.POSITION_BOTTOM);
+
+ ViewGroup bottomBar = (ViewGroup) findViewById(R.id.bottombar);
+ bottomBar.setBackgroundColor(mIntentDataProvider.getToolbarColor());
+ List<CustomButtonParams> items = mIntentDataProvider.getCustomButtonsOnBottombar();
+ for (CustomButtonParams params : items) {
+ if (params.showOnToolbar()) continue;
+ ImageButton button = params.toBottomBarButton(this, bottomBar);
+ bottomBar.addView(button);
+ }
+ }
+
@Override
public boolean shouldShowAppMenu() {
return getActivityTab() != null && getToolbarManager().isInitialized();

Powered by Google App Engine
This is Rietveld 408576698