void OpenCustomTab() { string url = mUrlEditText.Text; int color = GetColor(mCustomTabColorEditText); int secondaryColor = GetColor(mCustomTabSecondaryColorEditText); CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder(); intentBuilder.SetToolbarColor(color); intentBuilder.SetSecondaryToolbarColor(secondaryColor); if (mShowActionButtonCheckbox.Checked) { //Generally you do not want to decode bitmaps in the UI thread. Decoding it in the //UI thread to keep the example short. string actionLabel = GetString(Resource.String.label_action); Bitmap icon = BitmapFactory.DecodeResource(Resources, Android.Resource.Drawable.IcMenuShare); PendingIntent pendingIntent = CreatePendingIntent(ActionBroadcastReceiver.ACTION_ACTION_BUTTON); intentBuilder.SetActionButton(icon, actionLabel, pendingIntent); } if (mAddMenusCheckbox.Checked) { string menuItemTitle = GetString(Resource.String.menu_item_title); PendingIntent menuItemPendingIntent = CreatePendingIntent(ActionBroadcastReceiver.ACTION_MENU_ITEM); intentBuilder.AddMenuItem(menuItemTitle, menuItemPendingIntent); } if (mAddDefaultShareCheckbox.Checked) { intentBuilder.AddDefaultShareMenuItem(); } if (mToolbarItemCheckbox.Checked) { //Generally you do not want to decode bitmaps in the UI thread. Decoding it in the //UI thread to keep the example short. string actionLabel = GetString(Resource.String.label_action); Bitmap icon = BitmapFactory.DecodeResource(Resources, Android.Resource.Drawable.IcMenuShare); PendingIntent pendingIntent = CreatePendingIntent(ActionBroadcastReceiver.ACTION_TOOLBAR); intentBuilder.AddToolbarItem(TOOLBAR_ITEM_ID, icon, actionLabel, pendingIntent); } intentBuilder.SetShowTitle(mShowTitleCheckBox.Checked); if (mAutoHideAppBarCheckbox.Checked) { intentBuilder.EnableUrlBarHiding(); } if (mCustomBackButtonCheckBox.Checked) { intentBuilder.SetCloseButtonIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_arrow_back)); } intentBuilder.SetStartAnimations(this, Resource.Animation.slide_in_right, Resource.Animation.slide_out_left); intentBuilder.SetExitAnimations(this, Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight); CustomTabActivityHelper.OpenCustomTab( this, intentBuilder.Build(), Uri.Parse(url), new WebviewFallback()); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_serviceconnection); customTabActivityHelper = new CustomTabActivityHelper(); customTabActivityHelper.SetConnectionCallback(this); mUrlEditText = (EditText)FindViewById(Resource.Id.url); mMayLaunchUrlButton = FindViewById(Resource.Id.button_may_launch_url); mMayLaunchUrlButton.Enabled = false; mMayLaunchUrlButton.SetOnClickListener(this); FindViewById(Resource.Id.start_custom_tab).SetOnClickListener(this); }
public void OnClick(View v) { int viewId = v.Id; switch (viewId) { case Resource.Id.start_custom_tab: var url = mUrlEditText.Text; var customTabsIntent = new CustomTabsIntent.Builder().Build(); CustomTabActivityHelper.OpenCustomTab(this, customTabsIntent, Uri.Parse(url), new WebviewFallback()); break; default: throw new Exception("Unknown View Clicked"); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_custom_ui); mCustomTabActivityHelper = new CustomTabActivityHelper(); FindViewById(Resource.Id.start_custom_tab).SetOnClickListener(this); mUrlEditText = (EditText)FindViewById(Resource.Id.url); mCustomTabColorEditText = (EditText)FindViewById(Resource.Id.custom_toolbar_color); mCustomTabSecondaryColorEditText = (EditText)FindViewById(Resource.Id.custom_toolbar_secondary_color); mShowActionButtonCheckbox = (CheckBox)FindViewById(Resource.Id.custom_show_action_button); mAddMenusCheckbox = (CheckBox)FindViewById(Resource.Id.custom_add_menus); mShowTitleCheckBox = (CheckBox)FindViewById(Resource.Id.show_title); mCustomBackButtonCheckBox = (CheckBox)FindViewById(Resource.Id.custom_back_button); mAutoHideAppBarCheckbox = (CheckBox)FindViewById(Resource.Id.auto_hide_checkbox); mAddDefaultShareCheckbox = (CheckBox)FindViewById(Resource.Id.add_default_share); mToolbarItemCheckbox = (CheckBox)FindViewById(Resource.Id.add_toolbar_item); }
public void OnClick(View view) { Uri uri = Uri.Parse(mUrlEditText.Text); switch (view.Id) { case Resource.Id.button_may_launch_url: customTabActivityHelper.MayLaunchUrl(uri, null, null); break; case Resource.Id.start_custom_tab: CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder(customTabActivityHelper.GetSession()).Build(); CustomTabsHelper.AddKeepAliveExtra(this, customTabsIntent.Intent); CustomTabActivityHelper.OpenCustomTab(this, customTabsIntent, uri, new WebviewFallback()); break; default: throw new Exception("Unkown View Clicked"); } }