コード例 #1
0
        /// <summary>
        /// Add a predefined Element that the opens the Twitter app with a deep link to the specified user id
        /// If the Twitter application is not installed this will open a web page instead.
        /// </summary>
        /// <param name="id">the id of the Twitter user to display in the Twitter app</param>
        /// <param name="title">the title to display on this item</param>
        /// <returns>AboutPage instance for builder pattern support</returns>
        public AboutPage AddTwitter(string id, string title)
        {
            var intent = new Intent();

            intent.SetAction(Intent.ActionView);
            intent.AddCategory(Intent.CategoryBrowsable);

            if (AboutPageUtils.IsAppInstalled(_mContext, "com.twitter.android"))
            {
                intent.SetPackage("com.twitter.android");
                intent.SetData(Uri.Parse($"twitter://user?screen_name={id}"));
            }
            else
            {
                intent.SetData(Uri.Parse($"http://twitter.com/intent/user?screen_name={id}"));
            }

            var element = new Element
            {
                Title        = _mContext.GetString(Resource.String.about_twitter),
                IconDrawable = Resource.Drawable.about_icon_twitter,
                IconTint     = Resource.Color.about_twitter_color,
                Intent       = intent,
                Value        = id
            };

            AddItem(element);
            return(this);
        }
コード例 #2
0
        /// <summary>
        /// Add a predefined Element that the opens Facebook app with a deep link to the specified user id
        /// If the Facebook application is not installed this will open a web page instead.
        /// </summary>
        /// <param name="id">the id of the Facebook user to display in the Facebook app</param>
        /// <param name="title">the title to display on this item</param>
        /// <returns>AboutPage instance for builder pattern support</returns>
        public AboutPage AddFacebook(string id, string title)
        {
            var intent = new Intent();

            intent.SetAction(Intent.ActionView);
            intent.AddCategory(Intent.CategoryBrowsable);

            if (AboutPageUtils.IsAppInstalled(_mContext, "com.facebook.katana"))
            {
                intent.SetPackage("com.facebook.katana");
                int versionCode = 0;
                try
                {
                    versionCode = _mContext.PackageManager.GetPackageInfo("com.facebook.katana", 0).VersionCode;
                }
                catch (PackageManager.NameNotFoundException e)
                {
                    e.PrintStackTrace();
                }

                if (versionCode >= 3002850)
                {
                    var uri = Uri.Parse($"fb://facewebmodal/f?href=http://m.facebook.com/{id}");
                    intent.SetData(uri);
                }
                else
                {
                    var uri = Uri.Parse($"fb://page/{id}");
                    intent.SetData(uri);
                }
            }
            else
            {
                intent.SetData(Uri.Parse($"http://m.facebook.com/{id}"));
            }

            var element = new Element
            {
                Title        = _mContext.GetString(Resource.String.about_facebook),
                IconDrawable = Resource.Drawable.about_icon_facebook,
                IconTint     = Resource.Color.about_facebook_color,
                Intent       = intent,
                Value        = id
            };

            AddItem(element);
            return(this);
        }
コード例 #3
0
        /// <summary>
        /// Add a predefined Element that the opens the Instagram app with a deep link to the
        /// specified user id.
        /// If the Instagram app is not installed this will open the Intagram web page instead.
        /// </summary>
        /// <param name="id">the user id to deep link to</param>
        /// <param name="title">the title to display on this item</param>
        /// <returns>AboutPage instance for builder pattern support</returns>
        public AboutPage AddInstagram(string id, string title)
        {
            var intent = new Intent();

            intent.SetAction(Intent.ActionView);
            intent.SetData(Uri.Parse("http://instagram.com/_u/" + id));

            if (AboutPageUtils.IsAppInstalled(_mContext, "com.instagram.android"))
            {
                intent.SetPackage("com.instagram.android");
            }

            var element = new Element
            {
                Title        = _mContext.GetString(Resource.String.about_instagram),
                IconDrawable = Resource.Drawable.about_icon_instagram,
                IconTint     = Resource.Color.about_instagram_color,
                Intent       = intent,
                Value        = id
            };

            AddItem(element);
            return(this);
        }
コード例 #4
0
        /// <summary>
        /// Add a predefined Element that the opens the Youtube app with a deep link to the
        /// specified channel id.
        /// If the Youtube app is not installed this will open the Youtube web page instead.
        /// </summary>
        /// <param name="id">the id of the channel to deep link to</param>
        /// <param name="title">the title to display on this item</param>
        /// <returns>AboutPage instance for builder pattern support</returns>
        public AboutPage AddYoutube(string id, string title)
        {
            var intent = new Intent();

            intent.SetAction(Intent.ActionView);
            intent.SetData(Uri.Parse($"http://youtube.com/channel/{id}"));

            if (AboutPageUtils.IsAppInstalled(_mContext, "com.google.android.youtube"))
            {
                intent.SetPackage("com.google.android.youtube");
            }

            var element = new Element
            {
                Title        = _mContext.GetString(Resource.String.about_youtube),
                IconDrawable = Resource.Drawable.about_icon_youtube,
                IconTint     = Resource.Color.about_youtube_color,
                Intent       = intent,
                Value        = id
            };

            AddItem(element);
            return(this);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private View CreateItem(Element element)
        {
            var wrapper = new LinearLayout(_mContext);

            wrapper.Orientation = Orientation.Horizontal;
            wrapper.Clickable   = true;

            if (element.ClickHandler != null)
            {
                wrapper.Click += element.ClickHandler;
            }
            else if (element.Intent != null)
            {
                wrapper.Click += (sender, args) =>
                {
                    try
                    {
                        _mContext.StartActivity(element.Intent);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                };
            }

            var outValue = new TypedValue();

            _mContext.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, outValue, true);
            wrapper.SetBackgroundResource(outValue.ResourceId);

            int padding = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_text_padding);

            wrapper.SetPadding(padding, padding, padding, padding);
            var wrapperParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

            wrapper.LayoutParameters = wrapperParams;

            var textView = new TextView(_mContext);

            TextViewCompat.SetTextAppearance(textView, Resource.Style.about_elementTextAppearance);
            var textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            textView.LayoutParameters = textParams;
            if (_mCustomFont != null)
            {
                textView.Typeface = _mCustomFont;
            }

            ImageView iconView = null;

            if (element.IconDrawable != 0)
            {
                iconView = new ImageView(_mContext);
                int size       = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_icon_size);
                var iconParams = new LinearLayout.LayoutParams(size, size);
                iconView.LayoutParameters = iconParams;

                int iconPadding = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_icon_padding);
                iconView.SetPadding(iconPadding, 0, iconPadding, 0);

                if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
                {
                    var drawable = VectorDrawableCompat.Create(iconView.Resources, element.IconDrawable, iconView.Context.Theme);
                    iconView.SetImageDrawable(drawable);
                }
                else
                {
                    iconView.SetImageResource(element.IconDrawable);
                }

                var wrappedDrawable = DrawableCompat.Wrap(iconView.Drawable);
                wrappedDrawable = wrappedDrawable.Mutate();

                if (element.AutoApplyIconTint)
                {
                    // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
                    var currentNightMode = _mContext.Resources.Configuration.UiMode & UiMode.NightMask;
                    if (currentNightMode != UiMode.NightYes)
                    {
                        if (element.IconTint != 0)
                        {
                            DrawableCompat.SetTint(wrappedDrawable, ContextCompat.GetColor(_mContext, element.IconTint));
                        }
                        else
                        {
                            DrawableCompat.SetTint(wrappedDrawable, ContextCompat.GetColor(_mContext, Resource.Color.about_item_icon_color));
                        }
                    }
                    else if (element.IconNightTint != 0)
                    {
                        DrawableCompat.SetTint(wrappedDrawable, ContextCompat.GetColor(_mContext, element.IconNightTint));
                    }
                    else
                    {
                        DrawableCompat.SetTint(wrappedDrawable, AboutPageUtils.GetThemeAccentColor(_mContext));
                    }
                }
            }
            else
            {
                int iconPadding = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_icon_padding);
                textView.SetPadding(iconPadding, iconPadding, iconPadding, iconPadding);
            }

            textView.Text = element.Title;

            if (_mIsRtl)
            {
                var gravity = element.Gravity != GravityFlags.NoGravity ? element.Gravity : GravityFlags.Right;

                wrapper.SetGravity(gravity | GravityFlags.CenterVertical);
                textParams.Gravity = gravity | GravityFlags.CenterVertical;
                wrapper.AddView(textView);
                if (element.IconDrawable != 0)
                {
                    wrapper.AddView(iconView);
                }
            }
            else
            {
                var gravity = element.Gravity != GravityFlags.NoGravity ? element.Gravity : GravityFlags.Left;

                wrapper.SetGravity(gravity | GravityFlags.CenterVertical);
                textParams.Gravity = gravity | GravityFlags.CenterVertical;
                if (element.IconDrawable != 0)
                {
                    wrapper.AddView(iconView);
                }
                wrapper.AddView(textView);
            }

            return(wrapper);
        }