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

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

Issue 1716683002: [Custom Tabs] Allow clients to display RemoteViews on the bottom bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make findbug happy Created 4 years, 10 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 0c00788997a518239244fc8f632828e5c67a17ec..61cd46d1023f43f929f1e1f9bc28cf1dd1471f19 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;
@@ -274,6 +289,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,
connection.getClientPackageNameForSession(mSession),
@@ -507,29 +535,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);
}
}

Powered by Google App Engine
This is Rietveld 408576698