Esempio n. 1
0
        public static bool IsHidesFooterIfEmptyEnabled(Context context, IAttributeSet attrs)
        {
            TryInitializeBindingResourcePaths();

            TypedArray typedArray         = null;
            bool       hidesFooterIfEmpty = true;

            try
            {
                typedArray = context.ObtainStyledAttributes(attrs, MvxRecyclerViewGroupId);
                int numberOfStyles = typedArray.IndexCount;

                for (int i = 0; i < numberOfStyles; ++i)
                {
                    var attributeId = typedArray.GetIndex(i);

                    if (attributeId == MvxRecyclerViewHidesFooterIfEmpty)
                    {
                        hidesFooterIfEmpty = typedArray.GetBoolean(attributeId, true);
                        break;
                    }
                }

                return(hidesFooterIfEmpty);
            }
            finally
            {
                typedArray.Recycle();
            }
        }
Esempio n. 2
0
        private static string ReadRecyclerViewItemTemplateSelectorClassName(Context context, IAttributeSet attrs)
        {
            TryInitializeBindingResourcePaths();

            TypedArray typedArray = null;

            string className = string.Empty;

            try
            {
                typedArray = context.ObtainStyledAttributes(attrs, MvxRecyclerViewItemTemplateSelectorGroupId);
                int numberOfStyles = typedArray.IndexCount;

                for (int i = 0; i < numberOfStyles; ++i)
                {
                    var attributeId = typedArray.GetIndex(i);

                    if (attributeId == MvxRecyclerViewItemTemplateSelector)
                    {
                        className = typedArray.GetString(attributeId);
                    }
                }
            }
            finally
            {
                typedArray?.Recycle();
            }

            if (string.IsNullOrEmpty(className))
            {
                return(typeof(MvxDefaultTemplateSelector).FullName);
            }

            return(className);
        }
Esempio n. 3
0
        private static string ReadItemTemplateSelectorClassName(Context context, IAttributeSet attrs)
        {
            TypedArray typedArray = null;

            string className = string.Empty;

            try
            {
                typedArray = context.ObtainStyledAttributes(attrs, GroupId);
                int numberOfStyles = typedArray.IndexCount;

                for (int i = 0; i < numberOfStyles; ++i)
                {
                    var attributeId = typedArray.GetIndex(i);

                    if (attributeId == ItemTemplateSelector)
                    {
                        className = typedArray.GetString(attributeId);
                    }
                }
            }
            finally
            {
                typedArray?.Recycle();
            }

            return(className);
        }
Esempio n. 4
0
        private void init(IAttributeSet attrs, int defStyle)
        {
            TypedArray a = Context.ObtainStyledAttributes(attrs,
                                                          Resource.Styleable.ColorBars, defStyle, 0);
            Resources b = Context.Resources;

            mBarThickness = a.GetDimensionPixelSize(
                Resource.Styleable.ColorBars_bar_thickness,
                b.GetDimensionPixelSize(Resource.Dimension.bar_thickness));
            mBarLength = a.GetDimensionPixelSize(Resource.Styleable.ColorBars_bar_length,
                                                 b.GetDimensionPixelSize(Resource.Dimension.bar_length));
            mPreferredBarLength = mBarLength;
            mBarPointerRadius   = a.GetDimensionPixelSize(
                Resource.Styleable.ColorBars_bar_pointer_radius,
                b.GetDimensionPixelSize(Resource.Dimension.bar_pointer_radius));
            mBarPointerHaloRadius = a.GetDimensionPixelSize(
                Resource.Styleable.ColorBars_bar_pointer_halo_radius,
                b.GetDimensionPixelSize(Resource.Dimension.bar_pointer_halo_radius));
            mOrientation = a.GetBoolean(
                Resource.Styleable.ColorBars_bar_orientation_horizontal, ORIENTATION_DEFAULT);

            int n = a.IndexCount;

            for (int i = 0; i < n; i++)
            {
                int attributeIndex = a.GetIndex(i);
                switch (attributeIndex)
                {
                case Resource.Attribute.bar_corner_radius:
                case Resource.Styleable.ColorBars_bar_corner_radius:
                    try {
                        mCornerRadius = a.GetFloat(attributeIndex, CORNER_RADIUS_DEFAULT);
                    } catch (Exception e) {
                        System.Console.Error.WriteLine(e + ": " + e.Message);
                    }
                    break;

                default:
                    break;
                }
            }


            a.Recycle();

            mBarPaint = new Paint(PaintFlags.AntiAlias);
            mBarPaint.SetShader(shader);

            mBarPointerPosition = (mBarLength / 2) + mBarPointerHaloRadius;

            mBarPointerHaloPaint       = new Paint(PaintFlags.AntiAlias);
            mBarPointerHaloPaint.Color = (Color.Black);
            mBarPointerHaloPaint.Alpha = (0x50);

            mBarPointerPaint       = new Paint(PaintFlags.AntiAlias);
            mBarPointerPaint.Color = new Color(unchecked ((int)(0xff81ff00)));

            mPosToSVFactor = 1 / ((float)mBarLength / 2);
            mSVToPosFactor = ((float)mBarLength / 2) / 1;
        }
Esempio n. 5
0
        public TitleImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
        {
            image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon);

            TypedArray typedArray = Context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.TitleImageView, defStyle, 0);
            int        count      = typedArray.IndexCount;

            try
            {
                for (int i = 0; i < count; i++)
                {
                    int index = typedArray.GetIndex(i);
                    switch (index)
                    {
                    case Resource.Styleable.TitleImageView_image:
                        image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon);
                        //image = BitmapFactory.DecodeResource(Resources, typedArray.GetResourceId(index, Resource.Drawable.Icon));
                        break;

                    case Resource.Styleable.TitleImageView_imageScaleType:
                        imageScaleType = (ImageScale)typedArray.GetInt(index, 0);
                        break;

                    case Resource.Styleable.TitleImageView_titleText:
                        titleText = typedArray.GetString(index);
                        break;

                    case Resource.Styleable.TitleImageView_titleTextColor:
                        titleTextColor = typedArray.GetColor(index, Color.Black);
                        break;

                    case Resource.Styleable.TitleImageView_titleTextSize:
                        //获取尺寸三个方法的介绍:http://my.oschina.net/ldhy/blog/496420
                        titleTextSize = typedArray.GetDimensionPixelSize(index, (int)TypedValue.ApplyDimension(ComplexUnitType.Sp, 16, Resources.DisplayMetrics));
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                typedArray.Recycle();
            }

            Init();
        }
Esempio n. 6
0
        private void ApplyCustomAttributes(Context context, IAttributeSet attrs)
        {
            TypedArray attributeArray = context.ObtainStyledAttributes(attrs,
                                                                       Resource.Styleable.EditTextSpinner);

            _allowEmptySelection = false;

            for (int i = 0; i < attributeArray.IndexCount; ++i)
            {
                int attr = attributeArray.GetIndex(i);

                switch (attr)
                {
                case Resource.Styleable.EditTextSpinner_allowEmptySelection:
                    _allowEmptySelection = attributeArray.GetBoolean(attr, false);
                    break;
                }
            }

            attributeArray.Recycle();
        }
Esempio n. 7
0
        private static MvxRecyclerViewTemplateSelectorAttributes ReadRecyclerViewItemTemplateSelectorAttributes(Context context, IAttributeSet attrs)
        {
            TryInitializeBindingResourcePaths();

            TypedArray typedArray = null;

            string templateSelectorClassName     = string.Empty;
            string groupedDataConverterClassName = string.Empty;
            int    headerLayoutId       = 0;
            int    footerLayoutId       = 0;
            int    groupSectionLayoutId = 0;

            try
            {
                typedArray = context.ObtainStyledAttributes(attrs, MvxRecyclerViewGroupId);
                int numberOfStyles = typedArray.IndexCount;

                for (int i = 0; i < numberOfStyles; ++i)
                {
                    var attributeId = typedArray.GetIndex(i);

                    if (attributeId == MvxRecyclerViewItemTemplateSelector)
                    {
                        templateSelectorClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewHeaderLayoutId)
                    {
                        headerLayoutId = typedArray.GetResourceId(attributeId, 0);
                    }
                    if (attributeId == MvxRecyclerViewFooterLayoutId)
                    {
                        footerLayoutId = typedArray.GetResourceId(attributeId, 0);
                    }
                    if (attributeId == MvxRecyclerViewGroupSectionLayoutId)
                    {
                        groupSectionLayoutId = typedArray.GetResourceId(attributeId, 0);
                    }
                    if (attributeId == MvxRecyclerViewGroupedDataConverter)
                    {
                        groupedDataConverterClassName = typedArray.GetString(attributeId);
                    }
                }
            }
            finally
            {
                typedArray?.Recycle();
            }

            if (string.IsNullOrEmpty(templateSelectorClassName))
            {
                templateSelectorClassName = typeof(MvxDefaultTemplateSelector).FullName;
            }

            return(new MvxRecyclerViewTemplateSelectorAttributes()
            {
                TemplateSelectorClassName = templateSelectorClassName,
                FooterLayoutId = footerLayoutId,
                HeaderLayoutId = headerLayoutId,
                GroupSectionLayoutId = groupSectionLayoutId,
                GroupedDataConverterClassName = groupedDataConverterClassName
            });
        }
Esempio n. 8
0
 public int GetIndex(int at)
 {
     return(_array.GetIndex(at));
 }
        static MvxAdvancedRecyclerViewAttributes ReadRecyclerViewItemTemplateSelectorAttributes(Context context, IAttributeSet attrs)
        {
            TryInitializeBindingResourcePaths();

            TypedArray typedArray = null;

            string templateSelectorClassName       = string.Empty;
            string groupedDataConverterClassName   = string.Empty;
            string groupExpandControllerClassName  = string.Empty;
            string swipeableTemplateClassName      = string.Empty;
            string uniqueItemIdProviderClassName   = string.Empty;
            string groupSwipeableTemplateClassName = string.Empty;
            string childSwipeableTemplateClassName = string.Empty;

            int headerLayoutId = 0;
            int footerLayoutId = 0;

            try
            {
                typedArray = context.ObtainStyledAttributes(attrs, MvxRecyclerViewGroupId);
                int numberOfStyles = typedArray.IndexCount;

                for (int i = 0; i < numberOfStyles; ++i)
                {
                    var attributeId = typedArray.GetIndex(i);

                    if (attributeId == MvxRecyclerViewGroupExpandController)
                    {
                        groupExpandControllerClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewItemTemplateSelector)
                    {
                        templateSelectorClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewHeaderLayoutId)
                    {
                        headerLayoutId = typedArray.GetResourceId(attributeId, 0);
                    }
                    if (attributeId == MvxRecyclerViewFooterLayoutId)
                    {
                        footerLayoutId = typedArray.GetResourceId(attributeId, 0);
                    }
                    if (attributeId == MvxRecyclerViewGroupedDataConverter)
                    {
                        groupedDataConverterClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewSwipeableTemplate)
                    {
                        swipeableTemplateClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewUniqueItemIdProvider)
                    {
                        uniqueItemIdProviderClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewGroupSwipeableTemplate)
                    {
                        groupSwipeableTemplateClassName = typedArray.GetString(attributeId);
                    }
                    if (attributeId == MvxRecyclerViewChildSwipeableTemplate)
                    {
                        childSwipeableTemplateClassName = typedArray.GetString(attributeId);
                    }
                }
            }
            finally
            {
                typedArray?.Recycle();
            }

            if (string.IsNullOrEmpty(templateSelectorClassName))
            {
                templateSelectorClassName = typeof(MvxDefaultTemplateSelector).FullName;
            }
            if (string.IsNullOrEmpty(groupExpandControllerClassName))
            {
                groupExpandControllerClassName = typeof(DefaultMvxGroupExpandController).FullName;
            }

            return(new MvxAdvancedRecyclerViewAttributes()
            {
                TemplateSelectorClassName = templateSelectorClassName,
                ItemTemplateLayoutId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs),
                FooterLayoutId = footerLayoutId,
                HeaderLayoutId = headerLayoutId,
                GroupedDataConverterClassName = groupedDataConverterClassName,
                GroupExpandControllerClassName = groupExpandControllerClassName,
                SwipeableTemplateClassName = swipeableTemplateClassName,
                UniqueItemIdProviderClassName = uniqueItemIdProviderClassName,
                GroupSwipeableTemplateClassName = groupSwipeableTemplateClassName,
                ChildSwipeableTemplateClassName = childSwipeableTemplateClassName
            });
        }
Esempio n. 10
0
        protected void Initialize(Context context)
        {
            _context = context;
            //Used to load and scale resource items
            _resources = context.Resources;
            //Definition of this drawables size
            _textBounds = new Rect();
            //Paint to use for the text
            _textPaint         = new TextPaint(PaintFlags.AntiAlias);
            _textPaint.Density = _resources.DisplayMetrics.Density;
            _textPaint.Dither  = true;

            int            textSize      = 15;
            ColorStateList textColor     = null;
            TypefaceStyle  styleIndex    = TypefaceStyle.Normal;
            int            typefaceIndex = -1;

            //Set default parameters from the current theme
            TypedArray a            = context.Theme.ObtainStyledAttributes(_themeAttributes);
            int        appearanceId = a.GetResourceId(0, -1);

            a.Recycle();

            TypedArray ap = null;

            if (appearanceId != -1)
            {
                ap = context.ObtainStyledAttributes(appearanceId, _appearanceAttributes);
            }
            if (ap != null)
            {
                for (int i = 0; i < ap.IndexCount; i++)
                {
                    int attr = ap.GetIndex(i);
                    switch (attr)
                    {
                    case 0:     //Text Size
                        textSize = a.GetDimensionPixelSize(attr, textSize);
                        break;

                    case 1:     //Typeface
                        typefaceIndex = a.GetInt(attr, typefaceIndex);
                        break;

                    case 2:     //Text Style
                        styleIndex = (TypefaceStyle)a.GetInt(attr, (int)styleIndex);
                        break;

                    case 3:     //Text Color
                        textColor = a.GetColorStateList(attr);
                        break;

                    default:
                        break;
                    }
                }

                ap.Recycle();
            }

            this.SetTextColor(textColor != null ? textColor : ColorStateList.ValueOf(Color.Black));
            this.SetRawTextSize(textSize);

            Typeface tf = null;

            switch (typefaceIndex)
            {
            case SANS:
                tf = Typeface.SansSerif;
                break;

            case SERIF:
                tf = Typeface.Serif;
                break;

            case MONOSPACE:
                tf = Typeface.Monospace;
                break;
            }

            this.SetTypeface(tf, styleIndex);
        }