Ejemplo n.º 1
0
        static Task <bool> 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.FromResult(true));
        }
        public Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
        {
            var task = new TaskCompletionSource <BrowserResult>();

            var builder = new CustomTabsIntent.Builder(_manager.Session)
                          //.SetToolbarColor(Color.FromArgb(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.º 3
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.º 4
0
        public static Task OpenAsync(Uri uri, BrowserLaunchType launchType)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            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.º 5
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);
        }
Ejemplo n.º 6
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.º 7
0
        public Task <BrowserResult> InvokeAsync(BrowserOptions 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 <BrowserResult>();

            // 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
                HbrApplication.Mediator.ActivityMessageReceived -= callback;

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

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

            // attach handler
            HbrApplication.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);
        }
            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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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);
         }
 }
        static void CustomTabsActivityManager_CustomTabsServiceConnected(ComponentName name, CustomTabsClient client)
        {
            var builder = new CustomTabsIntent.Builder(CustomTabsActivityManager.Session)
                          .SetShowTitle(true);

            var customTabsIntent = builder.Build();

            customTabsIntent.Intent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.NoHistory | ActivityFlags.NewTask);

            CustomTabsHelper.AddKeepAliveExtra(ParentActivity, customTabsIntent.Intent);

            customTabsIntent.LaunchUrl(ParentActivity, global::Android.Net.Uri.Parse(uri.OriginalString));
        }
        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.º 19
0
        public Task OpenBrowser(string url)
        {
            var tabsBuilder = new CustomTabsIntent.Builder();

            tabsBuilder.SetShowTitle(true);
            tabsBuilder.SetToolbarColor(ColorConstants.BrowserNavigationBarBackgroundColor.ToAndroid());
            tabsBuilder.SetSecondaryToolbarColor(ColorConstants.BrowserNavigationBarTextColor.ToAndroid());

            var intent = tabsBuilder.Build();

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

            return(Task.CompletedTask);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Open intent Browser From App using Url
 /// </summary>
 /// <param name="url"></param>
 public void OpenBrowserFromApp(string url)
 {
     try
     {
         CustomTabsIntent.Builder builder          = new CustomTabsIntent.Builder();
         CustomTabsIntent         customTabsIntent = builder.Build();
         customTabsIntent.Intent.AddFlags(ActivityFlags.NewTask);
         customTabsIntent.LaunchUrl(Context, Uri.Parse(url));
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
     }
 }
 /// <summary>
 /// Open intent Browser From App using Url
 /// </summary>
 /// <param name="url"></param>
 public void OpenBrowserFromApp(string url)
 {
     try
     {
         CustomTabsIntent.Builder builder          = new CustomTabsIntent.Builder();
         CustomTabsIntent         customTabsIntent = builder.Build();
         customTabsIntent.Intent.AddFlags(ActivityFlags.NewTask);
         customTabsIntent.LaunchUrl(Context, Uri.Parse(url));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
        public virtual async Task <IOAuth1Account> AuthenticateAsync(IOAuth1Options options)
        {
            // Set the current expected redirect uri
            oauth = new OAuth1(options);

            var url = await oauth.GetInitialUrlAsync();

            tcsAuth = new TaskCompletionSource <IOAuth1Account>();

            // DO TABS
            authSession = new CustomTabsAuthSession();
            authSession.AuthTaskCompletionSource = new TaskCompletionSource <IOAuth1Account>();

            authSession.ParentActivity            = Plugin.SocialAuth.Droid.SocialAuth.CurrentActivity;
            authSession.CustomTabsActivityManager = new CustomTabsActivityManager(authSession.ParentActivity);
            authSession.CustomTabsActivityManager.NavigationEvent += (navigationEvent, extras) =>
            {
                if (navigationEvent == CustomTabsCallback.TabHidden)
                {
                    if (authSession.AuthTaskCompletionSource != null)
                    {
                        authSession.AuthTaskCompletionSource.TrySetCanceled();
                    }
                }
            };

            authSession.CustomTabsActivityManager.CustomTabsServiceConnected += delegate
            {
                var ctam = authSession.CustomTabsActivityManager;
                var ses  = ctam.Session;

                var builder = new CustomTabsIntent.Builder(ses)
                              .SetShowTitle(true);

                var customTabsIntent = builder.Build();
                customTabsIntent.Intent.AddFlags(Android.Content.ActivityFlags.SingleTop | ActivityFlags.NoHistory | ActivityFlags.NewTask);

                CustomTabsHelper.AddKeepAliveExtra(authSession.ParentActivity, customTabsIntent.Intent);

                customTabsIntent.LaunchUrl(authSession.ParentActivity, Android.Net.Uri.Parse(url.AbsoluteUri));
            };

            if (!authSession.CustomTabsActivityManager.BindService())
            {
                tcsAuth.TrySetException(new Exception("CustomTabs not supported."));
            }

            return(await tcsAuth.Task);
        }
Ejemplo n.º 23
0
        /// <inheritdoc/>
        protected override void OpenBrowser(Android.Net.Uri uri, Context context = null, CancellationToken cancellationToken = default)
        {
            //using (var builder = new CustomTabsIntent.Builder(_customTabsServiceConnection.Session))
            using (var builder = new CustomTabsIntent.Builder())
                using (var customTabsIntent = builder.Build())
                {
                    customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory);
                    if (IsNewTask)
                    {
                        customTabsIntent.Intent.AddFlags(ActivityFlags.NewTask);
                    }
                    customTabsIntent.LaunchUrl(context, uri);

                    //TrustedWebUtils.LaunchAsTrustedWebActivity(context, customTabsIntent, uri);
                }
        }
        /// <summary>
        /// Open a browser to a specific url
        /// </summary>
        /// <param name="url">Url to open</param>
        /// <param name="options">Platform specific options</param>
        /// <returns>True if the operation was successful, false otherwise</returns>
        public Task <bool> OpenBrowser(string url, BrowserOptions options = null)
        {
            try
            {
                options = options switch
                {
                    null => new BrowserOptions(),
                    _ => options
                };

                switch (CrossCurrentActivity.Current.Activity)
                {
                case null:
                {
                    var intent = new Intent(Intent.ActionView);
                    intent.SetData(Android.Net.Uri.Parse(url));

                    intent.SetFlags(ActivityFlags.ClearTop);
                    intent.SetFlags(ActivityFlags.NewTask);
                    Application.Context.StartActivity(intent);
                    break;
                }

                default:
                {
                    var tabsBuilder = new CustomTabsIntent.Builder();
                    tabsBuilder.SetShowTitle(options?.ChromeShowTitle ?? false);

                    //var toolBarColor = options?.ChromeToolbarColor;
                    //if (toolbarColor != null)
                    //    tabsBuilder.SetToolbarColor(toolbarColor.ToNativeColor());

                    var intent = tabsBuilder.Build();
                    intent.LaunchUrl(CrossCurrentActivity.Current.Activity, Android.Net.Uri.Parse(url));
                    break;
                }
                }

                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to open browser: " + ex.Message);
                return(Task.FromResult(false));
            }
        }
Ejemplo n.º 25
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;
            }
        }
        private static void CustomTabsActivityManager_CustomTabsServiceConnected(ComponentName name, CustomTabsClient client)
        {
            var builder = new CustomTabsIntent.Builder(_customTabs.Session)
                          .SetToolbarColor(Color.Rgb(255, 255, 255))
                          .SetShowTitle(true)
                          .EnableUrlBarHiding();

            var customTabsIntent = builder.Build();

            //THESE FLAGS ARE VERY IMPORTANT. PLEASE READ DOCUMENTATION: https://developer.android.com/reference/android/content/Intent
            customTabsIntent.Intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);

            var ctx = Platform.CurrentActivity;

            CustomTabsHelper.AddKeepAliveExtra(ctx, customTabsIntent.Intent);

            customTabsIntent.LaunchUrl(ctx, global::Android.Net.Uri.Parse(_uri.OriginalString));
        }
        protected void custom_tabs_activit_manager_CustomTabsServiceConnected
        (
            Content.ComponentName name,
            CustomTabsClient client
        )
        {
            custom_tabs_intent_builder = new CustomTabsIntent.Builder(custom_tabs_activity_manager.Session);

            custom_tabs_intent_builder.EnableUrlBarHiding();

            if (CustomTabsConfiguration.IsWarmUpUsed)
            {
                System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager.WarmUp()");
                client.Warmup(0);
                //custom_tabs_activity_manager.Warmup();
            }

            if (CustomTabsConfiguration.IsPrefetchUsed)
            {
                System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager PREFETCH");
                custom_tabs_activity_manager.MayLaunchUrl(uri.ToString(), null, null);
            }

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

            custom_tabs_activity_manager.LaunchUrl(uri.ToString(), custom_tabs_intent_builder.Build());

            return;
        }
Ejemplo n.º 28
0
        void BeginLoadingInitialUrl()
        {
            var initalUri = state.Authenticator.GetInitialUrlAsync().Result;
            var mgr       = new CustomTabsActivityManager(this);

            mgr.CustomTabsServiceConnected += delegate {
                var builder = new CustomTabsIntent.Builder(mgr.Session);
                builder.EnableUrlBarHiding();
                builder.SetStartAnimations(this, Resource.Animation.slide_in_right, Resource.Animation.slide_out_left);
                builder.SetExitAnimations(this, global::Android.Resource.Animation.SlideInLeft, global::Android.Resource.Animation.SlideOutRight);
                mgr.LaunchUrl(initalUri.AbsoluteUri, builder.Build());
            };
            if (!mgr.BindService())
            {
                var intent = new Intent(Intent.ActionView);
                intent.SetData(global::Android.Net.Uri.Parse(initalUri.AbsoluteUri));
                StartActivity(intent);
            }
        }
Ejemplo n.º 29
0
        public Task <bool> OpenBrowser(string url, BrowserOptions options = null)
        {
            try
            {
                if (options == null)
                {
                    options = new BrowserOptions();
                }

                if (Platform.CurrentActivity == null)
                {
                    var intent = new Intent(Intent.ActionView);
                    intent.SetData(global::Android.Net.Uri.Parse(url));

                    intent.SetFlags(ActivityFlags.ClearTop);
                    intent.SetFlags(ActivityFlags.NewTask);
                    Platform.CurrentContext.StartActivity(intent);
                }
                else
                {
                    var tabsBuilder = new CustomTabsIntent.Builder();
                    tabsBuilder.SetShowTitle(options?.ChromeShowTitle ?? false);

                    var toolbarColor = options?.ChromeToolbarColor;
                    if (toolbarColor != null)
                    {
                        tabsBuilder.SetToolbarColor(toolbarColor.ToNativeColor());
                    }

                    var intent = tabsBuilder.Build();
                    intent.LaunchUrl(Platform.CurrentActivity, global::Android.Net.Uri.Parse(url));
                }

                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to open browser: " + ex.Message);
                return(Task.FromResult(false));
            }
        }
Ejemplo n.º 30
0
        void UseCustomTabsActivityManagerWithIntent()
        {
            // create & open chrome custom tab
            CustomTabsActivityManager mgr = new CustomTabsActivityManager(this);

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

            CustomTabsIntent 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(Android.Content.ActivityFlags.NoHistory);
            customTabsIntent.LaunchUrl(this, Android.Net.Uri.Parse(url));

            return;
        }