Ejemplo n.º 1
0
        /// <summary>
        /// Launches a Chrome custom tab to the specified url
        /// </summary>
        /// <param name="url">The url to launch in a Chrome custom tab</param>
        private void LaunchBrowser(string url)
        {
            CustomTabsIntent.Builder builder          = new CustomTabsIntent.Builder();
            CustomTabsIntent         customTabsIntent = builder.Build();

            customTabsIntent.LaunchUrl(AndroidContext, global::Android.Net.Uri.Parse(url));
        }
Ejemplo n.º 2
0
        void Initialize()
        {
            var webViewClient = new ARWebViewClient((e) =>
            {
                var tabsBuilder = new CustomTabsIntent.Builder();
                tabsBuilder.SetShowTitle(false);

                var intent = tabsBuilder.Build();
                intent.LaunchUrl(this.Context, Android.Net.Uri.Parse(e.Url));

                return(true);
            });

            SetWebViewClient(webViewClient);

            _chromeClient = new ARWebChromeClient();
            _chromeClient.ShowCustomView = (arg1, arg2) =>
            {
                this.Visibility = ViewStates.Gone;
                OnShowCustomView?.Invoke(arg1, arg2);
            };
            _chromeClient.HideCustomView = () =>
            {
                this.Visibility = ViewStates.Visible;
                OnHideCustomView?.Invoke();
            };

            SetWebChromeClient(_chromeClient);

            Settings.JavaScriptEnabled = true;
        }
        private void LaunchCustomTabs(string url)
        {
            var packageName = CustomTabsHelper.GetPackageNameToUse(this);

            if (string.IsNullOrEmpty(packageName))
            {
                // in case custom tabs are not supported, use the browser

                StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse(url)));
            }
            else
            {
                // use custom tabs

                var mgr              = new CustomTabsActivityManager(this);
                var builder          = new CustomTabsIntent.Builder(mgr.Session);
                var customTabsIntent = builder
                                       .SetToolbarColor(new Color(0x34, 0x98, 0xDB))
                                       .SetShowTitle(true)
                                       .EnableUrlBarHiding()
                                       .Build();
                customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);
                customTabsIntent.Intent.SetPackage(packageName);

                customTabsIntent.LaunchUrl(this, Android.Net.Uri.Parse(url));
            }
        }
Ejemplo n.º 4
0
        protected void custom_tabs_activit_manager_CustomTabsServiceConnected
        (
            Content.ComponentName name,
            CustomTabsClient client
        )
        {
            builder = new CustomTabsIntent.Builder(custom_tabs_activit_manager.Session);
            builder.EnableUrlBarHiding();

            if (CustomTabsConfiguration.IsWarmUpUsed)
            {
                long flags = -1;
                client.Warmup(flags);
            }

            if (CustomTabsConfiguration.AreAnimationsUsed)
            {
                builder.SetStartAnimations
                (
                    activity,
                    Xamarin.Auth.Resource.Animation.slide_in_right,
                    Xamarin.Auth.Resource.Animation.slide_out_left
                );
                builder.SetExitAnimations
                (
                    activity,
                    global::Android.Resource.Animation.SlideInLeft,
                    global::Android.Resource.Animation.SlideOutRight
                );
            }

            custom_tabs_activit_manager.LaunchUrl(uri.ToString(), builder.Build());

            return;
        }
Ejemplo n.º 5
0
        public static Task OpenAsync(Uri uri, BrowserLaunchType launchType)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri), "Uri cannot be null.");
            }

            var nativeUri = AndroidUri.Parse(uri.OriginalString);

            switch (launchType)
            {
            case BrowserLaunchType.SystemPreferred:
                var tabsBuilder = new CustomTabsIntent.Builder();
                var tabsIntent  = tabsBuilder.Build();
                tabsBuilder.SetShowTitle(true);
                tabsIntent.LaunchUrl(Platform.CurrentContext, nativeUri);
                break;

            case BrowserLaunchType.External:
                var intent = new Intent(Intent.ActionView, nativeUri);
                intent.SetFlags(ActivityFlags.ClearTop);
                intent.SetFlags(ActivityFlags.NewTask);

                if (!Platform.IsIntentSupported(intent))
                {
                    throw new FeatureNotSupportedException();
                }

                Platform.CurrentContext.StartActivity(intent);
                break;
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
        public Task <InvokeResult> InvokeAsync(InvokeOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.StartUrl))
            {
                throw new ArgumentException("Missing StartUrl", nameof(options));
            }

            if (string.IsNullOrWhiteSpace(options.EndUrl))
            {
                throw new ArgumentException("Missing EndUrl", nameof(options));
            }

            // must be able to wait for the intent to be finished to continue
            // with setting the task result
            var _tcs = new TaskCompletionSource <InvokeResult>();

            // create & open chrome custom tab
            _customTabs = new CustomTabsActivityManager(_context);

            // build custom tab
            var builder = new CustomTabsIntent.Builder(_customTabs.Session)
                          .SetToolbarColor(Color.Argb(255, 52, 152, 219))
                          .SetShowTitle(true)
                          .EnableUrlBarHiding();

            var customTabsIntent = builder.Build();

            // ensures the intent is not kept in the history stack, which makes
            // sure navigating away from it will close it
            customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);

            ActivityMediator.MessageReceivedEventHandler callback = null;
            callback = (response) =>
            {
                // remove handler
                AndroidClientChromeCustomTabsApplication
                .Mediator.ActivityMessageReceived -= callback;

                // set result
                _tcs.SetResult(new InvokeResult
                {
                    Response   = response,
                    ResultType = InvokeResultType.Success
                });

                // start MainActivity (will close the custom tab)
                _context.StartActivity(typeof(MainActivity));
            };

            // attach handler
            AndroidClientChromeCustomTabsApplication.Mediator.ActivityMessageReceived
                += callback;

            // launch
            customTabsIntent.LaunchUrl(_context, Android.Net.Uri.Parse(options.StartUrl));

            // need an intent to be triggered when browsing to the "io.identitymodel.native://callback"
            // scheme/URI => CallbackInterceptorActivity
            return(_tcs.Task);
        }
Ejemplo n.º 7
0
        public Task <string> InvokeAsync(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentException("Missing url", nameof(url));
            }

            // Use a TCS to set the task result after the intent finishes
            var tcs = new TaskCompletionSource <string>();

            customTabs = new CustomTabsActivityManager(activity);
            var builder = new CustomTabsIntent.Builder(customTabs.Session)
                          .SetToolbarColor(Color.Argb(255, 52, 152, 219))
                          .SetShowTitle(true)
                          .EnableUrlBarHiding();
            var customTabsIntent = builder.Build();

            // Ensure the intent is not kept in the history stack, which ensures navigating away will close it
            customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);

            //MainActivity.CustomUrlSchemeCallbackHandler = (response) =>
            //{
            //    activity.StartActivity(typeof(MainActivity));
            //    tcs.SetResult(response);
            //};

            // Launch
            customTabsIntent.LaunchUrl(activity, Android.Net.Uri.Parse(url));

            return(tcs.Task);
        }
        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.º 9
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));
        }
Ejemplo n.º 10
0
        public Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
        {
            var task = new TaskCompletionSource <BrowserResult>();

            var builder = new CustomTabsIntent.Builder(_manager.Session)
                          .SetToolbarColor(Color.Argb(255, 52, 152, 219))
                          .SetShowTitle(true)
                          .EnableUrlBarHiding();

            var customTabsIntent = builder.Build();

            // ensures the intent is not kept in the history stack, which makes
            // sure navigating away from it will close it
            customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);

            Action <string> callback = null;

            callback = url =>
            {
                OidcCallbackActivity.Callbacks -= callback;

                task.SetResult(new BrowserResult()
                {
                    Response = url
                });
            };

            OidcCallbackActivity.Callbacks += callback;

            customTabsIntent.LaunchUrl(_context, Android.Net.Uri.Parse(options.StartUrl));

            return(task.Task);
        }
Ejemplo n.º 11
0
        static Task PlatformOpenAsync(Uri uri, BrowserLaunchMode launchMode)
        {
            var nativeUri = AndroidUri.Parse(uri.AbsoluteUri);

            switch (launchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                var tabsBuilder = new CustomTabsIntent.Builder();
                tabsBuilder.SetShowTitle(true);
                var tabsIntent = tabsBuilder.Build();
                tabsIntent.Intent.SetFlags(ActivityFlags.ClearTop);
                tabsIntent.Intent.SetFlags(ActivityFlags.NewTask);
                tabsIntent.LaunchUrl(Platform.AppContext, nativeUri);
                break;

            case BrowserLaunchMode.External:
                var intent = new Intent(Intent.ActionView, nativeUri);
                intent.SetFlags(ActivityFlags.ClearTop);
                intent.SetFlags(ActivityFlags.NewTask);

                if (!Platform.IsIntentSupported(intent))
                {
                    throw new FeatureNotSupportedException();
                }

                Platform.AppContext.StartActivity(intent);
                break;
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 12
0
        protected override void OnResume()
        {
            base.OnResume();

            if (!started)
            {
                started = true;
                var uri  = Android.Net.Uri.Parse(Intent.GetStringExtra(BrowserImpl.StartUrlKey));
                var name = CustomTabsHelper.GetPackageNameToUse(this);
                if (name != null)
                {
                    var manager = new CustomTabsActivityManager(this);
                    var intent  = new CustomTabsIntent.Builder(manager.Session).Build();
                    intent.Intent.SetPackage(name);
                    intent.Intent.AddFlags(ActivityFlags.NoHistory);
                    intent.LaunchUrl(this, uri);
                }
                else
                {
                    var intent = new Intent(Intent.ActionView, uri);
                    StartActivity(intent);
                }
                return;
            }

            started = false;
            Callbacks?.Invoke(Intent.DataString ?? BrowserImpl.UserCancelResponse);
            Finish();
        }
Ejemplo n.º 13
0
        /// <inheritdoc/>
        public void OpenWebsiteInApp(string url)
        {
            // Use the Android custom tabs to display the webpage inside the app.
            CustomTabsIntent.Builder builder          = new CustomTabsIntent.Builder();
            CustomTabsIntent         customTabsIntent = builder.Build();

            customTabsIntent.LaunchUrl(_applicationContext, Uri.Parse(url));
        }
Ejemplo n.º 14
0
        protected override void LaunchBrowser(Android.Net.Uri uri)
        {
            var builder          = new CustomTabsIntent.Builder();
            var customTabsIntent = builder.Build();

            customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);
            customTabsIntent.LaunchUrl(Application.Context, uri);
        }
        public static void Initialize(global::Android.App.Activity a)
        {
            activity = a;
            CustomTabsActivityManager = new CustomTabsActivityManager(a);
            CustomTabsIntentBuilder   = new CustomTabsIntent.Builder(CustomTabsActivityManager.Session);
            CustomTabActivityHelper   = new CustomTabActivityHelper();

            return;
        }
Ejemplo n.º 16
0
        static void LaunchChromeTabs(BrowserLaunchOptions options, AndroidUri?nativeUri)
        {
            var tabsBuilder = new CustomTabsIntent.Builder();

            tabsBuilder.SetShowTitle(true);
#pragma warning disable CS0618 // Type or member is obsolete
            if (options.PreferredToolbarColor != null)
            {
                tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.ToInt());
            }
#pragma warning restore CS0618 // Type or member is obsolete
            if (options.TitleMode != BrowserTitleMode.Default)
            {
                tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show);
            }

            var           tabsIntent = tabsBuilder.Build();
            ActivityFlags?tabsFlags  = null;

            Context?context = ActivityStateManager.Default.GetCurrentActivity(false);

            if (context == null)
            {
                context = Application.Context;

                // If using ApplicationContext we need to set ClearTop/NewTask (See #225)
                tabsFlags = ActivityFlags.ClearTop | ActivityFlags.NewTask;
            }

#if __ANDROID_24__
            if (OperatingSystem.IsAndroidVersionAtLeast(24))
            {
                if (options.HasFlag(BrowserLaunchFlags.LaunchAdjacent))
                {
                    if (tabsFlags.HasValue)
                    {
                        tabsFlags |= ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask;
                    }
                    else
                    {
                        tabsFlags = ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask;
                    }
                }
            }
#endif

            // Check if there's flags specified to use
            if (tabsFlags.HasValue)
            {
                tabsIntent.Intent.SetFlags(tabsFlags.Value);
            }

            if (nativeUri != null)
            {
                tabsIntent.LaunchUrl(context, nativeUri);
            }
        }
Ejemplo n.º 17
0
        public static void ShowWebPage(Activity activity, string url)
        {
            var intent = new CustomTabsIntent.Builder()
                         .SetShowTitle(true)
                         .SetToolbarColor(ContextCompat.GetColor(activity, Resource.Color.theme500))
                         .Build();

            intent.LaunchUrl(activity, Android.Net.Uri.Parse(url));
        }
Ejemplo n.º 18
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            var activity             = this.Context as Activity;
            OAuth2Authenticator auth = null;

            if (Config.IsUsingNativeUI)
            {
                auth = new OAuth2Authenticator(
                    clientId: Config.ClientId,
                    clientSecret: Config.ClientSecret,
                    scope: Config.Scope,
                    authorizeUrl: new Uri(Config.AuthorizeUrl),
                    redirectUrl: new Uri(Config.RedirectUrl),
                    accessTokenUrl: new Uri(Config.AccesTokenUrl),
                    getUsernameAsync: null,
                    isUsingNativeUI: Config.IsUsingNativeUI
                    );
            }
            else
            {
                auth = new OAuth2Authenticator(
                    clientId: Config.ClientId,
                    scope: Config.Scope,
                    authorizeUrl: new Uri(Config.AuthorizeUrl),
                    redirectUrl: new Uri(Config.RedirectUrl),
                    getUsernameAsync: null,
                    isUsingNativeUI: Config.IsUsingNativeUI
                    );
            }



            auth.Completed += (sender, eventArgs) =>
            {
                if (eventArgs.IsAuthenticated)
                {
                    var oAuthToken = new OAuthToken()
                    {
                        AccessToken = eventArgs.Account.Properties["access_token"]
                    };
                    MessagingCenter.Send <object, OAuthToken>(this, "GetUser", oAuthToken);
                }
                else
                {
                    App.Current.MainPage = new NavigationPage(new LoginPage());
                }
            };

            var authActivity = new CustomTabsIntent.Builder().Build();

            authActivity.Intent = auth.GetUI(activity);
            authActivity.LaunchUrl(activity, Android.Net.Uri.Parse(Config.AuthorizeUrl));
            Forms.Context.StartActivity(authActivity.Intent);
            //activity.StartActivity(auth.GetUI(activity));
        }
            public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
            {
                CustomTabsIntent.Builder builder   = new CustomTabsIntent.Builder();
                CustomTabsIntent         customTab = builder.Build();

                customTab.LaunchUrl(view.Context, request.Url);

                return(true);
            }
Ejemplo n.º 20
0
        static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options)
        {
            var nativeUri = AndroidUri.Parse(uri.AbsoluteUri);

            switch (options.LaunchMode)
            {
            case BrowserLaunchMode.SystemPreferred:
                var tabsBuilder = new CustomTabsIntent.Builder();
                tabsBuilder.SetShowTitle(true);
                if (options.PreferredToolbarColor.HasValue)
                {
                    tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.Value.ToInt());
                }
                if (options.TitleMode != BrowserTitleMode.Default)
                {
                    tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show);
                }

                var tabsIntent = tabsBuilder.Build();
                var flags      = ActivityFlags.ClearTop | ActivityFlags.NewTask;
#if __ANDROID_24__
                if (Platform.HasApiLevelN)
                {
                    flags |= ActivityFlags.LaunchAdjacent;
                }
#endif
                tabsIntent.Intent.SetFlags(flags);

#if __ANDROID_25__
                tabsIntent.LaunchUrl(Platform.AppContext, nativeUri);
#else
                tabsIntent.LaunchUrl(Platform.GetCurrentActivity(true), nativeUri);
#endif
                break;

            case BrowserLaunchMode.External:
                var intent = new Intent(Intent.ActionView, nativeUri);
                flags = ActivityFlags.ClearTop | ActivityFlags.NewTask;
#if __ANDROID_24__
                if (Platform.HasApiLevelN)
                {
                    flags |= ActivityFlags.LaunchAdjacent;
                }
#endif
                intent.SetFlags(flags);

                if (!Platform.IsIntentSupported(intent))
                {
                    throw new FeatureNotSupportedException();
                }

                Platform.AppContext.StartActivity(intent);
                break;
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 21
0
        void IUrlHandler.LaunchBrowser(Uri uri)
        {
            var builder = new CustomTabsIntent.Builder();

            builder.SetShowTitle(true);
            builder.SetUrlBarHidingEnabled(true);
            var customTabs = builder.Build();

            customTabs.LaunchUrl(this, uri);
        }
Ejemplo n.º 22
0
        void OpenChromeCustomTabs(string url)
        {
            var tabsBuilder = new CustomTabsIntent.Builder();

            tabsBuilder.SetShowTitle(true);

            var intent = tabsBuilder.Build();

            intent.LaunchUrl(CurrentActivity, Android.Net.Uri.Parse(url));
        }
Ejemplo n.º 23
0
        private void LoginActivity_Click(object sender, EventArgs e)
        {
            View dialogLayout = LayoutInflater.Inflate(Resource.Layout.DialogButtonsX2, null);
            var  termsButton  = dialogLayout.FindViewById <Button>(Resource.Id.dialogBtn1);

            termsButton.Text   = Resources.GetString(Resource.String.LoginOpenTerms);
            termsButton.Click += (args, o) =>
            {
                Intent browserIntent =
                    new Intent(Intent.ActionView, global::Android.Net.Uri.Parse(
                                   ConfidentialData.api + "terms"));
                StartActivity(browserIntent);
            };

            var privacyButton = dialogLayout.FindViewById <Button>(Resource.Id.dialogBtn2);

            privacyButton.Text   = Resources.GetString(Resource.String.LoginOpenPrivacy);
            privacyButton.Click += (args, o) =>
            {
                Intent browserIntent =
                    new Intent(Intent.ActionView, global::Android.Net.Uri.Parse(
                                   ConfidentialData.api + "privacypolicy"));
                StartActivity(browserIntent);
            };

            new global::Android.Support.V7.App.AlertDialog.Builder(this)
            .SetTitle(Resource.String.LoginTermsTitle)
            .SetMessage(Resource.String.LoginTerms)
            .SetView(dialogLayout)
            .SetNegativeButton(Resource.String.dialog_cancel, (a, args) => { })
            .SetPositiveButton(Resource.String.LoginAgreeTerms, (a, args) =>
            {
                string buttonText = ((Button)sender).Text;

                ExternalLogin chosen = providers.FirstOrDefault(prov => prov.Name == buttonText);

                if (chosen == null)
                {
                    return;
                }

                chromeManager = new CustomTabsActivityManager(this);

                // build custom tab
                var builder = new CustomTabsIntent.Builder(chromeManager.Session)
                              .SetShowTitle(true)
                              .EnableUrlBarHiding();

                var customTabsIntent = builder.Build();
                customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);
                chromeManager.Warmup(0L);
                customTabsIntent.LaunchUrl(this, global::Android.Net.Uri.Parse(ConfidentialData.api + chosen.Url));
            })
            .Show();
        }
Ejemplo n.º 24
0
        public Task <string> LoginAsync()
        {
            TaskCompletionSource = new TaskCompletionSource <string>();

            string url = "https://oauthdemo.000webhostapp.com/test.html?" +
                         "scope=email%20profile&" +
                         "response_type=code&" +
                         "redirect_uri=com.companyname.xamarinformsauth%3A/oauth2redirect&" +
                         "client_id=1056433391892-gboradv67bghftbf41iee3q5ueflp6gb.apps.googleusercontent.com";


            Intent             activityIntent       = new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://oauthdemo.000webhostapp.com/test.html"));
            PackageManager     pm                   = CrossCurrentActivity.Current.Activity.PackageManager;
            List <ResolveInfo> resolvedActivityList = pm.QueryIntentActivities(
                activityIntent, PackageInfoFlags.MatchAll).ToList();

            foreach (var info in resolvedActivityList)
            {
                Intent serviceIntent = new Intent();
                serviceIntent.SetAction("android.support.customtabs.action.CustomTabsService");
                serviceIntent.SetPackage(info.ActivityInfo.PackageName);
                if (pm.ResolveService(serviceIntent, 0) != null)
                {
                    System.Diagnostics.Debug.WriteLine($"{info.ActivityInfo.PackageName} supports custom tabs");
                }
            }



            var ok = CustomTabsClient.BindCustomTabsService(Android.App.Application.Context, "org.mozilla.firefox", new MyServiceConnection((c) =>
            {
                client = c;

                var session = client.NewSession(new CallBackHandler((e, b) =>
                {
                    System.Diagnostics.Debug.WriteLine(e);
                }));



                CustomTabsIntent.Builder builder  = new CustomTabsIntent.Builder(session);
                CustomTabsIntent customTabsIntent = builder.Build();
                TrustedWebUtils.LaunchAsTrustedWebActivity(CrossCurrentActivity.Current.Activity, customTabsIntent, Android.Net.Uri.Parse(url));
                //customTabsIntent.LaunchUrl(Android.App.Application.Context, Android.Net.Uri.Parse(url));
            }));

            CustomTabsIntent.Builder builder          = new CustomTabsIntent.Builder();
            CustomTabsIntent         customTabsIntent = builder.Build();

            customTabsIntent.LaunchUrl(CrossCurrentActivity.Current.Activity, Android.Net.Uri.Parse(url));


            return(TaskCompletionSource.Task);
        }
Ejemplo n.º 25
0
        void PrepareMenuItems(CustomTabsIntent.Builder builder)
        {
            var menuIntent = new Intent();

            menuIntent.SetClass(ApplicationContext, Class);
            // Optional animation configuration when the user clicks menu items.
            var menuBundle = ActivityOptions.MakeCustomAnimation(this, Android.Resource.Animation.SlideInLeft,
                                                                 Android.Resource.Animation.SlideOutRight).ToBundle();
            var pi = PendingIntent.GetActivity(ApplicationContext, 0, menuIntent, 0, menuBundle);

            builder.AddMenuItem("Menu entry 1", pi);
        }
Ejemplo n.º 26
0
    /// <summary>
    /// OpenBrowser
    /// </summary>
    /// <param name="url"></param>
    public static void OpenUrl(Activity activity, string url)
    {
        var builder = new CustomTabsIntent.Builder()
                      .SetToolbarColor(System.Drawing.Color.Black.ToArgb());
        var intent = builder.Build();
        var mgr    = new CustomTabsActivityManager(activity);

        mgr.CustomTabsServiceConnected += delegate {
            mgr.LaunchUrl(url, intent);
        };
        mgr.BindService();
    }
Ejemplo n.º 27
0
        private void PrepareBottomBar(CustomTabsIntent.Builder builder)
        {
            BottomBarManager.MediaPlayer = mMediaPlayer;
            builder.SetSecondaryToolbarViews
            (
                BottomBarManager.CreateRemoteViews(this, true),
                BottomBarManager.ClickableIDs,
                BottomBarManager.GetOnClickPendingIntent(this)
            );

            return;
        }
Ejemplo n.º 28
0
 /// <inheritdoc/>
 protected override void OpenBrowser(Android.Net.Uri uri, Context context = null)
 {
     using (var builder = new CustomTabsIntent.Builder())
         using (var customTabsIntent = builder.Build())
         {
             if (IsNewTask)
             {
                 customTabsIntent.Intent.AddFlags(ActivityFlags.NewTask);
             }
             customTabsIntent.LaunchUrl(context, uri);
         }
 }
Ejemplo n.º 29
0
        public void LaunchUrl(string url, CustomTabsIntent customTabsIntent = null)
        {
            if (customTabsIntent == null)
            {
                customTabsIntent = new CustomTabsIntent.Builder()
                                   .Build();
            }

            CustomTabsHelper.AddKeepAliveExtra(ParentActivity, customTabsIntent.Intent);

            customTabsIntent.LaunchUrl(ParentActivity, Android.Net.Uri.Parse(url));
        }
        protected override async Task LaunchBrowserCore(
            WebAuthenticationOptions options,
            Uri requestUri,
            Uri callbackUri,
            CancellationToken ct)
        {
            var builder = new CustomTabsIntent.Builder();
            var intent  = builder.Build();

            intent.LaunchUrl(
                ContextHelper.Current,
                Android.Net.Uri.Parse(requestUri.OriginalString));
        }
Ejemplo n.º 31
0
        public static void ShowWebPage(Activity activity, string url)
        {
            var intent = new CustomTabsIntent.Builder()
                .SetShowTitle(true)
                .SetToolbarColor(ContextCompat.GetColor(activity, Resource.Color.theme500))
                .Build();

            intent.LaunchUrl(activity, Android.Net.Uri.Parse(url));
        }