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

Unified Diff: demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java

Issue 1603383003: color, package and action bar configuration. (Closed) Base URL: https://github.com/GoogleChrome/custom-tabs-client.git@master
Patch Set: fixes Created 4 years, 9 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: demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
diff --git a/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java b/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
index 5ce437c407c8c7f7cc1dccbd8e92ccbbb986b2dc..138975efc2af49151f11486ff63aef3970444668 100644
--- a/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
+++ b/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
@@ -17,46 +17,51 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
+import android.provider.CalendarContract;
+import android.provider.ContactsContract;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
+import org.chromium.customtabsclient.shared.CustomTabsHelper;
+
+import java.util.ArrayList;
+
/**
* Opens Chrome Custom Tabs with a customized UI.
*/
public class CustomUIActivity extends AppCompatActivity implements View.OnClickListener {
- private static final String TAG = "CustChromeTabActivity";
-
+ private String mToolbarColor;
+ private String mPackageName;
+ private ArrayList<ActionButtonParams> mActionBarItems;
private EditText mUrlEditText;
- private EditText mCustomTabColorEditText;
- private CheckBox mShowActionButtonCheckbox;
+ private CheckBox mAddActionButtonCheckbox;
private CheckBox mAddMenusCheckbox;
private CheckBox mShowTitleCheckBox;
private CheckBox mCustomBackButtonCheckBox;
private CheckBox mAutoHideAppBarCheckbox;
private CustomTabActivityHelper mCustomTabActivityHelper;
+ private int advancedUISettintRequestCode;
Ian Wen 2016/03/16 01:35:30 Member variables should start with an "m". Also th
BigBossZhiling 2016/03/18 00:59:07 Done.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_ui);
-
mCustomTabActivityHelper = new CustomTabActivityHelper();
findViewById(R.id.start_custom_tab).setOnClickListener(this);
-
+ findViewById(R.id.advanced_ui_setting).setOnClickListener(this);
mUrlEditText = (EditText) findViewById(R.id.url);
- mCustomTabColorEditText = (EditText) findViewById(R.id.custom_toolbar_color);
- mShowActionButtonCheckbox = (CheckBox) findViewById(R.id.custom_show_action_button);
+ mAddActionButtonCheckbox = (CheckBox) findViewById(R.id.custom_show_action_button);
mAddMenusCheckbox = (CheckBox) findViewById(R.id.custom_add_menus);
mShowTitleCheckBox = (CheckBox) findViewById(R.id.show_title);
mCustomBackButtonCheckBox = (CheckBox) findViewById(R.id.custom_back_button);
mAutoHideAppBarCheckbox = (CheckBox) findViewById(R.id.auto_hide_checkbox);
+ advancedUISettintRequestCode = 999;
+ makeDefaultSetting();
}
@Override
@@ -72,31 +77,97 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
}
@Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if ((requestCode == advancedUISettintRequestCode)) {
+ try {
+ mActionBarItems = (ArrayList) data.getSerializableExtra
+ (AdvancedUISettingActivity.KEY_ACTION_ITEMS);
+ mToolbarColor = (String) data.getSerializableExtra
Ian Wen 2016/03/16 01:35:30 Why is it SerializableExtra? You should use getSt
BigBossZhiling 2016/03/18 00:59:07 Done.
+ (AdvancedUISettingActivity.KEY_COLOR);
+ mPackageName = (String) data.getSerializableExtra
+ (AdvancedUISettingActivity.KEY_PACKAGE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
public void onClick(View v) {
int viewId = v.getId();
switch (viewId) {
case R.id.start_custom_tab:
openCustomTab();
break;
+ case R.id.advanced_ui_setting:
+ openUISetting();
+ break;
default:
//Unknown View Clicked
}
}
- private void openCustomTab() {
- String url = mUrlEditText.getText().toString();
+ private void makeDefaultSetting() {
+ mToolbarColor = "Red";
+ mPackageName = CustomTabsHelper.getPackageNameToUse(this,
+ CustomTabsHelper.getAllPackagesSupportingCustomTabs(this));
+ mActionBarItems = new ArrayList<ActionButtonParams>();
+ }
- int color = Color.BLUE;
- try {
- color = Color.parseColor(mCustomTabColorEditText.getText().toString());
- } catch (NumberFormatException ex) {
- Log.i(TAG, "Unable to parse Color: " + mCustomTabColorEditText.getText());
+ private void openUISetting() {
+ Intent intent = new Intent(this, AdvancedUISettingActivity.class);
+ intent.putExtra(AdvancedUISettingActivity.KEY_PACKAGE, mPackageName);
+ intent.putExtra(AdvancedUISettingActivity.KEY_COLOR, mToolbarColor);
+ intent.putExtra(AdvancedUISettingActivity.KEY_ACTION_ITEMS, mActionBarItems);
+ startActivityForResult(intent, advancedUISettintRequestCode);
+ }
+
+ private void addActionButtons(CustomTabsIntent.Builder intentBuilder) {
+ for (int i = 0; i < mActionBarItems.size(); i++) {
+ intentBuilder.addActionBarItem(i, AdvancedUISettingActivity.uriToBitMap(this,
+ Uri.parse(mActionBarItems.get(i).image)),
+ mActionBarItems.get(i).description,
+ createPendingIntent(mActionBarItems.get(i).intent));
+ }
+ }
+
+ private PendingIntent createPendingIntent(String intent) {
+ switch (intent) {
+ case "Send":
+ Intent sendIntent = new Intent();
+ sendIntent.setAction(Intent.ACTION_SEND);
+ sendIntent.setType("text/plain");
+ return PendingIntent.getActivity(this, 0, sendIntent, 0);
+ case "Select Contact":
+ Intent contact = new Intent(Intent.ACTION_PICK);
+ contact.setType(ContactsContract.Contacts.CONTENT_TYPE);
+ return PendingIntent.getActivity(this, 0, contact, 0);
+ case "Add Event":
+ Intent event = new Intent(Intent.ACTION_INSERT)
+ .setData(CalendarContract.Events.CONTENT_URI)
+ .putExtra(CalendarContract.Events.TITLE, "Great Event")
+ .putExtra(CalendarContract.Events.EVENT_LOCATION, "Googleplex 43")
+ .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, "today")
+ .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, "tomorrow");
+ return PendingIntent.getActivity(this, 0, event, 0);
+ case "Camera":
+ return PendingIntent.getActivity(this, 0, new Intent(this, Camera.class),
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ default:
+ return null;
}
+ }
+
+ private void openCustomTab() {
+ String url = mUrlEditText.getText().toString();
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
- intentBuilder.setToolbarColor(color);
- if (mShowActionButtonCheckbox.isChecked()) {
+ intentBuilder.setToolbarColor(AdvancedUISettingActivity.stringToColor(mToolbarColor));
+ intentBuilder.addDefaultShareMenuItem();
+
+ if (mAddActionButtonCheckbox.isChecked()) {
//Generally you do not want to decode bitmaps in the UI thread.
String shareLabel = getString(R.string.label_action_share);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
@@ -113,6 +184,8 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
intentBuilder.setShowTitle(mShowTitleCheckBox.isChecked());
+ addActionButtons(intentBuilder);
+
if (mAutoHideAppBarCheckbox.isChecked()) {
intentBuilder.enableUrlBarHiding();
}
@@ -127,7 +200,8 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
android.R.anim.slide_out_right);
CustomTabActivityHelper.openCustomTab(
- this, intentBuilder.build(), Uri.parse(url), new WebviewFallback());
+ this, intentBuilder.build(), Uri.parse(url), new WebviewFallback(),
+ mPackageName);
}
private PendingIntent createPendingIntent() {

Powered by Google App Engine
This is Rietveld 408576698