| 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..4d0c065535e35a982fc0b75f39eee5395ab43628 100644
|
| --- a/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
|
| +++ b/demos/src/main/java/org/chromium/customtabsdemos/CustomUIActivity.java
|
| @@ -17,16 +17,20 @@ 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.
|
| */
|
| @@ -34,29 +38,37 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
|
| private static final String TAG = "CustChromeTabActivity";
|
|
|
| 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 String toolbarColor;
|
| + private String packageName;
|
| + private ArrayList<String> itemsDescriptions;
|
| + private ArrayList<Uri> itemsImage;
|
| + private ArrayList<String> allSupportingPackageNames;
|
| + private ArrayList<String> itemsIntent;
|
| +
|
| + private int advancedUISettintRequestCode;
|
| @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
|
| @@ -78,25 +90,93 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
|
| 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();
|
| + @Override
|
| + public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
| + super.onActivityResult(requestCode, resultCode, data);
|
| + if (requestCode == advancedUISettintRequestCode && data != null) {
|
| + packageName = data.getStringExtra("packageName");
|
| + toolbarColor = data.getStringExtra("color");
|
| + itemsDescriptions = (ArrayList<String>) data.getSerializableExtra("itemsDescription");
|
| + itemsImage = (ArrayList<Uri>) data.getSerializableExtra("itemsImage");
|
| + itemsIntent = (ArrayList<String>) data.getSerializableExtra("itemsIntent");
|
| + } else {
|
|
|
| - 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 makeDefaultSetting() {
|
| + toolbarColor = "Red";
|
| + allSupportingPackageNames = CustomTabsHelper.getAllPackagesSupportingCustomTabs(this);
|
| + packageName = CustomTabsHelper.getPackageNameToUse(this, allSupportingPackageNames);
|
| + itemsIntent = new ArrayList<String>();
|
| + itemsDescriptions = new ArrayList<String>();
|
| + itemsImage = new ArrayList<Uri>();
|
| + }
|
| +
|
| + private void openUISetting() {
|
| + Intent intent = new Intent(this, AdvancedUISettingActivity.class);
|
| + intent.putExtra("packageNameList", allSupportingPackageNames);
|
| + intent.putExtra("packageName", packageName);
|
| + intent.putExtra("color", toolbarColor);
|
| + intent.putExtra("itemsDescription", itemsDescriptions);
|
| + intent.putExtra("itemsImage", itemsImage);
|
| + intent.putExtra("itemsIntent", itemsIntent);
|
| + startActivityForResult(intent, advancedUISettintRequestCode);
|
| + }
|
| +
|
| + private void addActionButtons(CustomTabsIntent.Builder intentBuilder) {
|
| + for (int i = 0; i < itemsDescriptions.size(); i++) {
|
| + intentBuilder.addActionBarItem(i,
|
| + AdvancedUISettingActivity.uriToBitMap(this, itemsImage.get(i)),
|
| + itemsDescriptions.get(i),
|
| + createPendingIntent(itemsIntent.get(i)));
|
| + }
|
| + }
|
| +
|
| + 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(CustomTabsHelper.stringToColor(toolbarColor));
|
| + 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 +193,8 @@ public class CustomUIActivity extends AppCompatActivity implements View.OnClickL
|
|
|
| intentBuilder.setShowTitle(mShowTitleCheckBox.isChecked());
|
|
|
| + addActionButtons(intentBuilder);
|
| +
|
| if (mAutoHideAppBarCheckbox.isChecked()) {
|
| intentBuilder.enableUrlBarHiding();
|
| }
|
| @@ -127,7 +209,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(),
|
| + packageName);
|
| }
|
|
|
| private PendingIntent createPendingIntent() {
|
|
|