| 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 745e0504029ed914080bd7cf0760952014036c94..266b2305f3d0e03d3a260cbfbaaa644d3d49ea6d 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
|
| @@ -22,6 +22,7 @@ import android.view.ViewGroup;
|
| import android.view.ViewStub;
|
| import android.view.Window;
|
| import android.widget.ImageButton;
|
| +import android.widget.RemoteViews;
|
|
|
| import org.chromium.base.ApiCompatibilityUtils;
|
| import org.chromium.base.Log;
|
| @@ -153,6 +154,20 @@ public class CustomTabActivity extends ChromeActivity {
|
| return sActiveContentHandler.updateCustomButton(id, bitmap, description);
|
| }
|
|
|
| + /**
|
| + * Checks whether the active {@link CustomTabContentHandler} belongs to the given session, and
|
| + * if true, updates {@link RemoteViews} on the secondary toolbar.
|
| + * @return Whether the update is successful.
|
| + */
|
| + static boolean updateRemoteViews(IBinder session, RemoteViews remoteViews) {
|
| + 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.updateRemoteViews(remoteViews);
|
| + }
|
| +
|
| @Override
|
| public boolean isCustomTab() {
|
| return true;
|
| @@ -273,6 +288,19 @@ public class CustomTabActivity extends ChromeActivity {
|
| }
|
| return true;
|
| }
|
| +
|
| + @Override
|
| + public boolean updateRemoteViews(RemoteViews rv) {
|
| + if (mIntentDataProvider.getBottomBarRemoteViews() == null) {
|
| + // Update only makes sense if we are already showing a RemoteViews.
|
| + return false;
|
| + }
|
| + ViewGroup bottomBar = (ViewGroup) findViewById(R.id.bottombar);
|
| + View view = rv.apply(CustomTabActivity.this, bottomBar);
|
| + bottomBar.removeAllViews();
|
| + bottomBar.addView(view);
|
| + return true;
|
| + }
|
| };
|
| DataUseTabUIManager.onCustomTabInitialNavigation(mainTab,
|
| CustomTabsConnection.getInstance(getApplication())
|
| @@ -506,29 +534,37 @@ public class CustomTabActivity extends ChromeActivity {
|
| shadow.setVisibility(View.VISIBLE);
|
|
|
| ViewGroup bottomBar = (ViewGroup) findViewById(R.id.bottombar);
|
| - bottomBar.setBackgroundColor(mIntentDataProvider.getBottomBarColor());
|
| - List<CustomButtonParams> items = mIntentDataProvider.getCustomButtonsOnBottombar();
|
| - for (CustomButtonParams params : items) {
|
| - if (params.showOnToolbar()) continue;
|
| - final PendingIntent pendingIntent = params.getPendingIntent();
|
| - OnClickListener clickListener = null;
|
| - if (pendingIntent != null) {
|
| - clickListener = new OnClickListener() {
|
| - @Override
|
| - public void onClick(View v) {
|
| - Intent addedIntent = new Intent();
|
| - addedIntent.setData(Uri.parse(getActivityTab().getUrl()));
|
| - try {
|
| - pendingIntent.send(CustomTabActivity.this, 0, addedIntent, null, null);
|
| - } catch (CanceledException e) {
|
| - Log.e(TAG,
|
| - "CanceledException while sending pending intent in custom tab");
|
| + RemoteViews remoteViews = mIntentDataProvider.getBottomBarRemoteViews();
|
| + if (remoteViews != null) {
|
| + //TODO(ianwen): add UMA to see the usage of RemoteViews.
|
| + View inflatedView = remoteViews.apply(this, bottomBar);
|
| + bottomBar.addView(inflatedView);
|
| + } else {
|
| + bottomBar.setBackgroundColor(mIntentDataProvider.getBottomBarColor());
|
| + List<CustomButtonParams> items = mIntentDataProvider.getCustomButtonsOnBottombar();
|
| + for (CustomButtonParams params : items) {
|
| + if (params.showOnToolbar()) continue;
|
| + final PendingIntent pendingIntent = params.getPendingIntent();
|
| + OnClickListener clickListener = null;
|
| + if (pendingIntent != null) {
|
| + clickListener = new OnClickListener() {
|
| + @Override
|
| + public void onClick(View v) {
|
| + Intent addedIntent = new Intent();
|
| + addedIntent.setData(Uri.parse(getActivityTab().getUrl()));
|
| + try {
|
| + pendingIntent.send(CustomTabActivity.this, 0, addedIntent, null,
|
| + null);
|
| + } catch (CanceledException e) {
|
| + Log.e(TAG,
|
| + "CanceledException while sending pending intent.");
|
| + }
|
| }
|
| - }
|
| - };
|
| + };
|
| + }
|
| + ImageButton button = params.buildBottomBarButton(this, bottomBar, clickListener);
|
| + bottomBar.addView(button);
|
| }
|
| - ImageButton button = params.buildBottomBarButton(this, bottomBar, clickListener);
|
| - bottomBar.addView(button);
|
| }
|
| }
|
|
|
|
|