Ejemplo n.º 1
0
        internal static void OpenLogin(Activity context, string provider)
        {
            if (string.IsNullOrEmpty(provider) && Bootlegger.BootleggerClient.CurrentUser != null)
            {
                provider = Bootlegger.BootleggerClient.CurrentUser.profile["provider"].ToString();
            }

            var builder = new CustomTabsIntent.Builder()
                          .SetToolbarColor(ContextCompat.GetColor(context, Resource.Color.blue))
                          .SetSecondaryToolbarColor(Android.Resource.Color.White)
                          .SetShowTitle(true);
            Bitmap icon;

            if (ViewCompat.GetLayoutDirection(context.FindViewById <ViewGroup>(Android.Resource.Id.Content).GetChildAt(0)) != ViewCompat.LayoutDirectionRtl)
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_back_white_24dp);
            }
            else
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_forward_white_24dp);
            }

            builder.SetCloseButtonIcon(icon);
            var intent = builder.Build();

            intent.Intent.PutExtra(Intent.ExtraReferrer, Android.Net.Uri.Parse("app://" + context.PackageName));
            intent.LaunchUrl(context, Android.Net.Uri.Parse(Bootlegger.BootleggerClient.LoginUrl.ToString() + "/" + provider + "?cbid=" + WhiteLabelConfig.DATASCHEME));
        }
        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());
        }
Ejemplo n.º 3
0
        public void OnClick(View view)
        {
            string url = mEditText.Text;
            bool   success;

            switch (view.Id)
            {
            case Resource.Id.connect_button:
                BindCustomTabsService();
                break;

            case Resource.Id.warmup_button:
                success = false;
                if (mClient != null)
                {
                    success = mClient.Warmup(0);
                }
                mWarmupButton.Enabled &= success;
                break;

            case Resource.Id.may_launch_button:
                CustomTabsSession session = GetSession();
                success = false;
                if (mClient != null)
                {
                    success = session.MayLaunchUrl(Uri.Parse(url), null, null);
                }
                mMayLaunchButton.Enabled &= success;
                break;

            case Resource.Id.launch_button:
                var builder = new CustomTabsIntent.Builder(GetSession());
                builder.SetToolbarColor(Color.ParseColor(TOOLBAR_COLOR)).SetShowTitle(true);
                PrepareMenuItems(builder);
                PrepareActionButton(builder);
                PrepareBottombar(builder);
                builder.SetStartAnimations(this, Resource.Animation.slide_in_right, Resource.Animation.slide_out_left);
                builder.SetExitAnimations(this, Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                builder.SetCloseButtonIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_arrow_back));
                CustomTabsIntent customTabsIntent = builder.Build();
                CustomTabsHelper.AddKeepAliveExtra(this, customTabsIntent.Intent);
                customTabsIntent.LaunchUrl(this, Uri.Parse(url));
                break;
            }
        }
Ejemplo n.º 4
0
        public static void ShowHelp(Android.App.Activity context, string link)
        {
            var builder = new CustomTabsIntent.Builder()
                          .SetToolbarColor(ContextCompat.GetColor(context, Resource.Color.blue))
                          .SetSecondaryToolbarColor(Android.Resource.Color.White)
                          .SetShowTitle(true);
            Bitmap icon;

            if (ViewCompat.GetLayoutDirection(context.FindViewById <ViewGroup>(Android.Resource.Id.Content).GetChildAt(0)) != ViewCompat.LayoutDirectionRtl)
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_back_white_24dp);
            }
            else
            {
                icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_arrow_forward_white_24dp);
            }

            builder.SetCloseButtonIcon(icon);
            var intent = builder.Build();

            intent.Intent.PutExtra(Intent.ExtraReferrer, Android.Net.Uri.Parse("app://" + context.PackageName));
            intent.LaunchUrl(context, Android.Net.Uri.Parse(context.Resources.GetString(Resource.String.HelpLink) + link));
        }
Ejemplo n.º 5
0
        public void OnClick(View v)
        {
            string url    = mEditText.Text.ToString();
            int    viewId = v.Id;

            if (viewId == Resource.Id.connect_button)
            {
                BindCustomTabsService();
            }
            else if (viewId == Resource.Id.warmup_button)
            {
                bool success = false;
                if (custom_tabs_client != null)
                {
                    success = custom_tabs_client.Warmup(0);
                }
                if (!success)
                {
                    mWarmupButton.Enabled = false;
                }
            }
            else if (viewId == Resource.Id.may_launch_button)
            {
                CustomTabsSession session = Session;
                bool success = false;
                if (custom_tabs_client != null)
                {
                    success = session.MayLaunchUrl(Android.Net.Uri.Parse(url), null, null);
                }
                if (!success)
                {
                    mMayLaunchButton.Enabled = false;
                }
            }
            else if (viewId == Resource.Id.launch_button)
            {
                CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(Session);
                builder.SetToolbarColor(Color.ParseColor(TOOLBAR_COLOR)).SetShowTitle(true);
                PrepareMenuItems(builder);
                PrepareActionButton(builder);
                PrepareBottomBar(builder);

                builder.SetStartAnimations
                (
                    this,
                    Resource.Animation.slide_in_right,
                    Resource.Animation.slide_out_left
                );
                builder.SetExitAnimations
                (
                    this,
                    Android.Resource.Animation.SlideInLeft,
                    Android.Resource.Animation.SlideOutRight
                );
                builder.SetCloseButtonIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_arrow_back));


                CustomTabsIntent customTabsIntent = builder.Build();
                // derived class used - thus FQNS
                HolisticWare.Android.Support.CustomTabs.Chromium.SharedUtilities.
                CustomTabsHelper.AddKeepAliveExtra(this, customTabsIntent.Intent);

                try
                {
                    customTabsIntent.LaunchUrl(this, Android.Net.Uri.Parse(url));
                }
                catch (System.Exception exc)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("CustomTabsIntent.LaunchUrl Exception");
                }
                return;
            }
        }