/// <summary>
        /// @return The current {@link CustomTabsSession} object.
        /// </summary>
        /// <returns>The current session.</returns>
        public static CustomTabsSession GetCurrentSession()
        {
            CustomTabsSession customTabsSession = null;

            sCurrentSession?.TryGetTarget(out customTabsSession);
            return(customTabsSession);
        }
示例#2
0
 public void OnServiceDisconnected()
 {
     mClient            = null;
     mCustomTabsSession = null;
     if (mConnectionCallback != null)
     {
         mConnectionCallback.OnCustomTabsDisconnected();
     }
 }
 private void UnbindCustomTabsService()
 {
     if (custom_tabs_service_connection == null)
     {
         return;
     }
     UnbindService(custom_tabs_service_connection);
     custom_tabs_client  = null;
     custom_tabs_session = null;
 }
示例#4
0
 void UnbindCustomTabsService()
 {
     if (mConnection == null)
     {
         return;
     }
     UnbindService(mConnection);
     mClient            = null;
     mCustomTabsSession = null;
 }
示例#5
0
        public virtual void OnServiceDisconnected()
        {
            custom_tabs_client  = null;
            custom_tabs_session = null;
            if (connection_callback != null)
            {
                connection_callback.OnCustomTabsDisconnected();
            }

            return;
        }
 public void UnbindCustomTabsService(Activity activity)
 {
     if (mConnection == null)
     {
         return;
     }
     activity.UnbindService(mConnection);
     mClient            = null;
     mCustomTabsSession = null;
     mConnection        = null;
 }
 public CustomTabsSession GetSession()
 {
     if (mClient == null)
     {
         mCustomTabsSession = null;
     }
     else if (mCustomTabsSession == null)
     {
         mCustomTabsSession = mClient.NewSession(null as CustomTabsCallback);
     }
     return(mCustomTabsSession);
 }
示例#8
0
 CustomTabsSession GetSession()
 {
     if (mClient == null)
     {
         mCustomTabsSession = null;
     }
     else if (mCustomTabsSession == null)
     {
         mCustomTabsSession = mClient.NewSession(new NavigationCallback());
         SessionHelper.setCurrentSession(mCustomTabsSession);
     }
     return(mCustomTabsSession);
 }
        /// <summary>
        /// Unbinds the Activity from the Custom Tabs Service. </summary>
        /// <param name="activity"> the activity that is connected to the service. </param>
        public virtual void UnbindCustomTabsService(Activity activity)
        {
            if (custom_tabs_service_connection == null)
            {
                return;
            }
            activity.UnbindService(custom_tabs_service_connection);
            custom_tabs_client             = null;
            custom_tabs_session            = null;
            custom_tabs_service_connection = null;

            return;
        }
        public virtual void OnServiceDisconnected()
        {
            System.Diagnostics.Debug.WriteLine("CustomTabsActivityHelper.OnServiceConnected");

            custom_tabs_client  = null;
            custom_tabs_session = null;
            if (connection_callback != null)
            {
                System.Diagnostics.Debug.WriteLine("    connection_callback.OnCustomTabsDisconnected()");

                connection_callback.OnCustomTabsDisconnected();
            }

            return;
        }
示例#11
0
        /// <summary>
        /// Warmup
        /// Tells the browser of a likely future navigation to a URL.
        /// </summary>
        /// <seealso cref= <seealso cref="CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)"/>. </seealso>
        /// <returns> true if call to mayLaunchUrl was accepted. </returns>
        public virtual bool MayLaunchUrl(Uri uri, Bundle extras, IList <Bundle> other_likely_bundles)
        {
            if (custom_tabs_client == null)
            {
                return(false);
            }

            CustomTabsSession cts = this.Session;

            if (cts == null)
            {
                return(false);
            }

            return(cts.MayLaunchUrl(uri, extras, other_likely_bundles));
        }
示例#12
0
        /// <seealso cref= <seealso cref="CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)"/>. </seealso>
        /// <returns> true if call to mayLaunchUrl was accepted. </returns>
        public virtual bool mayLaunchUrl(Uri uri, Bundle extras, IList <Bundle> otherLikelyBundles)
        {
            if (mClient == null)
            {
                return(false);
            }

            CustomTabsSession session = Session;

            if (session == null)
            {
                return(false);
            }

            return(session.MayLaunchUrl(uri, extras, otherLikelyBundles));
        }
示例#13
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;
            }
        }
示例#14
0
        public override void OnReceive(Context context, Intent intent)
        {
            int clickedId = intent.GetIntExtra(CustomTabsIntent.ExtraRemoteviewsClickedId, -1);

            Toast.MakeText(context, "Clicked", global::Android.Widget.ToastLength.Long).Show();

            CustomTabsSession session = SessionHelper.GetCurrentSession();

            if (session == null)
            {
                return;
            }

            if (clickedId == Resource.Id.play_pause)
            {
                MediaPlayer player = null;
                sMediaPlayerWeakRef.TryGetTarget(out player);

                if (player != null)
                {
                    bool isPlaying = player.IsPlaying;
                    if (isPlaying)
                    {
                        player.Pause();
                    }
                    else
                    {
                        player.Start();
                    }
                    // Update the play/stop icon to respect the current state.
                    session.SetSecondaryToolbarViews(CreateRemoteViews(context, isPlaying), ClickableIDs, GetOnClickPendingIntent(context));
                }
            }

            /*
             *          else if (clickedId == Resource.Id.cover)
             *          {
             *                  // Clicking on the cover image will dismiss the bottom bar.
             *                  session.SetSecondaryToolbarViews(null, null, null);
             *          }
             */
        }
        /// <summary>
        /// Warmup
        /// Tells the browser of a likely future navigation to a URL.
        /// </summary>
        /// <seealso cref= <seealso cref="CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)"/>. </seealso>
        /// <returns> true if call to mayLaunchUrl was accepted. </returns>
        public virtual bool MayLaunchUrl
        (
            Android.Net.Uri uri,
            Bundle extras,
            IList <Bundle> other_likely_bundles
        )
        {
            if (custom_tabs_client == null)
            {
                return(false);
            }

            custom_tabs_session = custom_tabs_activity_manager.Session;

            if (custom_tabs_session == null)
            {
                return(false);
            }

            return(custom_tabs_session.MayLaunchUrl(uri, extras, other_likely_bundles));
        }
示例#16
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;
            }
        }
 /// <summary>
 /// Sets the current session to the given one.
 /// </summary>
 /// <param name="session">Session.</param>
 public static void setCurrentSession(CustomTabsSession session)
 {
     sCurrentSession = new WeakReference <CustomTabsSession>(session);
 }
        /// <summary>
        /// Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
        /// </summary>
        /// <param name="activity"> The host activity. </param>
        /// <param name="custom_tabs_intent"> a CustomTabsIntent to be used if Custom Tabs is available. </param>
        /// <param name="uri"> the Uri to be opened. </param>
        /// <param name="fallback"> a CustomTabFallback to be used if Custom Tabs is not available. </param>
        public /*static*/ void LaunchUrlWithCustomTabsOrFallback
        (
            Activity a,
            CustomTabsIntent custom_tabs_intent,
            string package_name_for_custom_tabs,
            Android.Net.Uri u,
            ICustomTabFallback fallback
        )
        {
            uri      = u;
            activity = a;
            bool fallback_neccessary = false;

            //If we cant find a package name, it means theres no browser that supports
            //Chrome Custom Tabs installed. So, we fallback to the webview
            if (package_name_for_custom_tabs == null)
            {
                fallback_neccessary = true;
            }
            else
            {
                custom_tabs_activity_manager = new CustomTabsActivityManager(this.activity);

                custom_tabs_activity_manager.BindService(package_name_for_custom_tabs);
                //custom_tabs_intent.Intent.SetPackage(package_name_for_custom_tabs);

                custom_tabs_session = custom_tabs_activity_manager.Session;

                custom_tabs_intent_builder = new CustomTabsIntent.Builder(custom_tabs_session);


                // direct call to CustomtTasIntent.LaunchUrl was ported from java samples and refactored
                // seems like API changed
                //------------------------------------------------------------------------------
                //custom_tabs_intent.LaunchUrl(activity, uri);
                //return;
                //------------------------------------------------------------------------------
                custom_tabs_activity_manager = new CustomTabsActivityManager(activity);
                custom_tabs_intent           = custom_tabs_intent_builder.Build();

                CustomTabsHelper.AddKeepAliveExtra(activity, custom_tabs_intent.Intent);

                custom_tabs_intent.LaunchUrl(activity, uri);
                custom_tabs_activity_manager.CustomTabsServiceConnected +=
                    // custom_tabs_activit_manager_CustomTabsServiceConnected
                    delegate
                {
                    System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager.CustomTabsServiceConnected");

                    custom_tabs_activity_manager.LaunchUrl(uri.ToString());

                    System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager.LaunchUrl");

                    return;
                }
                ;
                System.Diagnostics.Debug.WriteLine($"CustomTabsActivityManager.BindService({package_name_for_custom_tabs})");
                service_bound = custom_tabs_activity_manager.BindService(package_name_for_custom_tabs);
                //custom_tabs_activity_manager.LaunchUrl(uri.ToString());
                //------------------------------------------------------------------------------

                if (service_bound == false)
                {
                    System.Diagnostics.Debug.WriteLine($"FALLBACK: No Packages that support CustomTabs");
                    // No Packages that support CustomTabs
                    fallback_neccessary = true;
                }
            }

            if (fallback_neccessary == true && fallback != null)
            {
                fallback.OpenUri(activity, uri);
            }

            return;
        }
示例#19
0
 public override void OnCustomTabsServiceConnected(ComponentName name, CustomTabsClient client)
 {
     Client = client;
     Client.Warmup(0L);
     Session = Client.NewSession(callback: null);
 }