Commit e60cd0c3 authored by ianwen's avatar ianwen Committed by Commit bot

[Custom Tabs]Unbreak buttons on bottom bar

After thre refactoring related to remoteviews based bottom bar, the old
API stopped working. This CL fixes the breakage.

BUG=604849

Review URL: https://codereview.chromium.org/1895813004

Cr-Commit-Position: refs/heads/master@{#388559}
parent 7e308e6f
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<item name="refine_view_id" type="id"/> <item name="refine_view_id" type="id"/>
<item name="tabswitcher_multiple_drawable" type="id"/> <item name="tabswitcher_multiple_drawable" type="id"/>
<item name="tabswitcher_single_drawable" type="id"/> <item name="tabswitcher_single_drawable" type="id"/>
<item name="custom_tab_bottom_bar_wrapper" type="id"/>
<!-- InfoBar constants --> <!-- InfoBar constants -->
<item type="id" name="button_primary" /> <item type="id" name="button_primary" />
......
...@@ -18,6 +18,7 @@ import android.view.ViewStub; ...@@ -18,6 +18,7 @@ import android.view.ViewStub;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams; import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import org.chromium.base.Log; import org.chromium.base.Log;
...@@ -70,8 +71,11 @@ class CustomTabBottomBarDelegate { ...@@ -70,8 +71,11 @@ class CustomTabBottomBarDelegate {
mClickPendingIntent = mDataProvider.getRemoteViewsPendingIntent(); mClickPendingIntent = mDataProvider.getRemoteViewsPendingIntent();
showRemoteViews(remoteViews); showRemoteViews(remoteViews);
} else { } else {
getBottomBarView().setBackgroundColor(mDataProvider.getBottomBarColor());
List<CustomButtonParams> items = mDataProvider.getCustomButtonsOnBottombar(); List<CustomButtonParams> items = mDataProvider.getCustomButtonsOnBottombar();
if (items.isEmpty()) return;
LinearLayout layout = new LinearLayout(mActivity);
layout.setId(R.id.custom_tab_bottom_bar_wrapper);
layout.setBackgroundColor(mDataProvider.getBottomBarColor());
for (CustomButtonParams params : items) { for (CustomButtonParams params : items) {
if (params.showOnToolbar()) continue; if (params.showOnToolbar()) continue;
final PendingIntent pendingIntent = params.getPendingIntent(); final PendingIntent pendingIntent = params.getPendingIntent();
...@@ -84,10 +88,10 @@ class CustomTabBottomBarDelegate { ...@@ -84,10 +88,10 @@ class CustomTabBottomBarDelegate {
} }
}; };
} }
ImageButton button = params.buildBottomBarButton(mActivity, getBottomBarView(), layout.addView(
clickListener); params.buildBottomBarButton(mActivity, getBottomBarView(), clickListener));
getBottomBarView().addView(button);
} }
getBottomBarView().addView(layout);
} }
} }
......
...@@ -621,18 +621,23 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { ...@@ -621,18 +621,23 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
intent.putExtra(CustomTabsIntent.EXTRA_SECONDARY_TOOLBAR_COLOR, barColor); intent.putExtra(CustomTabsIntent.EXTRA_SECONDARY_TOOLBAR_COLOR, barColor);
startCustomTabActivityWithIntent(intent); startCustomTabActivityWithIntent(intent);
ViewGroup bottomBar = (ViewGroup) getActivity().findViewById(R.id.bottombar); ViewGroup bottomBar = (ViewGroup) getActivity()
.findViewById(R.id.custom_tab_bottom_bar_wrapper);
assertNotNull(bottomBar); assertNotNull(bottomBar);
assertTrue("Bottom Bar wrapper is not visible.", bottomBar.getVisibility() == View.VISIBLE
&& bottomBar.getHeight() > 0 && bottomBar.getWidth() > 0);
assertEquals("Bottom Bar showing incorrect number of buttons.", assertEquals("Bottom Bar showing incorrect number of buttons.",
numItems + 1, bottomBar.getChildCount()); numItems, bottomBar.getChildCount());
assertEquals("Bottom bar not showing correct color", barColor, assertEquals("Bottom bar not showing correct color", barColor,
((ColorDrawable) bottomBar.getBackground()).getColor()); ((ColorDrawable) bottomBar.getBackground()).getColor());
for (int i = 1; i <= numItems; i++) { for (int i = 0; i < numItems; i++) {
ImageButton button = (ImageButton) bottomBar.getChildAt(i); ImageButton button = (ImageButton) bottomBar.getChildAt(i);
assertTrue("Bottom Bar button does not have the correct bitmap.", assertTrue("Bottom Bar button does not have the correct bitmap.",
expectedIcon.sameAs(((BitmapDrawable) button.getDrawable()).getBitmap())); expectedIcon.sameAs(((BitmapDrawable) button.getDrawable()).getBitmap()));
assertTrue("Bottom Bar button is not visible.", button.getVisibility() == View.VISIBLE
&& button.getHeight() > 0 && button.getWidth() > 0);
assertEquals("Bottom Bar button does not have correct content description", assertEquals("Bottom Bar button does not have correct content description",
Integer.toString(i), button.getContentDescription()); Integer.toString(i + 1), button.getContentDescription());
} }
} }
......
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