Exemplo n.º 1
0
        public SliderLayout(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
        {
            mh = new HandlerAnonymousInnerClassHelper(this);
            var _PresetIndicatorsToViewIdAccordance = new Dictionary <PresetIndicators, int>
            {
                { PresetIndicators.Center_Bottom, R.Id.default_center_bottom_indicator },
                { PresetIndicators.Right_Bottom, R.Id.default_bottom_right_indicator },
                { PresetIndicators.Left_Bottom, R.Id.default_bottom_left_indicator },
                { PresetIndicators.Center_Top, R.Id.default_center_top_indicator },
                { PresetIndicators.Right_Top, R.Id.default_center_top_right_indicator },
                { PresetIndicators.Left_Top, R.Id.default_center_top_left_indicator }
            };

            mContext = context;
            LayoutInflater.From(context).Inflate(R.Layout.slider_layout, this, true);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final android.content.res.TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs,R.styleable.SliderLayout, defStyle,0);
            TypedArray attributes = context.Theme.ObtainStyledAttributes(attrs, R.Styleable.SliderLayout, defStyle, 0);

            mTransformerSpan = attributes.GetInteger(R.Styleable.SliderLayout_pager_animation_span, 1100);
            mTransformerId   = attributes.GetInt(R.Styleable.SliderLayout_pager_animation, Transformer.Default.Ordinal());
            mAutoCycle       = attributes.GetBoolean(R.Styleable.SliderLayout_auto_cycle, true);
            int visibility = attributes.GetInt(R.Styleable.SliderLayout_indicator_visibility, 0);

            foreach (IndicatorVisibility v in Enum.GetValues(typeof(IndicatorVisibility)))
            {
                if (v.Ordinal() == visibility)
                {
                    mIndicatorVisibility = v;
                    break;
                }
            }
            mSliderAdapter = new SliderAdapter(mContext);
            PagerAdapter wrappedAdapter = new InfinitePagerAdapter(mSliderAdapter);

            mViewPager         = FindViewById <InfiniteViewPager>(R.Id.daimajia_slider_viewpager);
            mViewPager.Adapter = wrappedAdapter;

            mViewPager.SetOnTouchListener(new OnTouchListenerAnonymousInnerClassHelper(this));

            attributes.Recycle();
            SetPresetIndicator(PresetIndicators.Center_Bottom);
            SetPresetTransformer(mTransformerId);
            setSliderTransformDuration(mTransformerSpan, null);
            IndicatorVisibility = mIndicatorVisibility;
            if (mAutoCycle)
            {
                startAutoCycle();
            }
        }
Exemplo n.º 2
0
        public PagerIndicator(Context context, IAttributeSet attrs) : base(context, attrs)
        {
            dataChangeObserver = new DataSetObserverAnonymousInnerClassHelper(this);
            mContext           = context;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final android.content.res.TypedArray attributes = context.obtainStyledAttributes(attrs,com.daimajia.slider.library.R.styleable.PagerIndicator,0,0);
            TypedArray attributes = context.ObtainStyledAttributes(attrs, Resource.Styleable.PagerIndicator, 0, 0);

            int visibility = attributes.GetInt(Resource.Styleable.PagerIndicator_visibility, IndicatorVisibility.Visible.Ordinal());

            foreach (IndicatorVisibility v in System.Enum.GetValues(typeof(IndicatorVisibility)))
            {
                if (v.Ordinal() == visibility)
                {
                    mVisibility = v;
                    break;
                }
            }

            int shape = attributes.GetInt(Resource.Styleable.PagerIndicator_shape, Shape.Oval.Ordinal());

            foreach (Shape s in System.Enum.GetValues(typeof(Shape)))
            {
                if (s.Ordinal() == shape)
                {
                    mIndicatorShape = s;
                    break;
                }
            }

            mUserSetSelectedIndicatorResId   = attributes.GetResourceId(Resource.Styleable.PagerIndicator_selected_drawable, 0);
            mUserSetUnSelectedIndicatorResId = attributes.GetResourceId(Resource.Styleable.PagerIndicator_unselected_drawable, 0);

            mDefaultSelectedColor   = attributes.GetColor(Resource.Styleable.PagerIndicator_selected_color, Color.Rgb(255, 255, 255));
            mDefaultUnSelectedColor = attributes.GetColor(Resource.Styleable.PagerIndicator_unselected_color, Color.Argb(33, 255, 255, 255));

            mDefaultSelectedWidth  = attributes.GetDimension(Resource.Styleable.PagerIndicator_selected_width, (int)pxFromDp(6));
            mDefaultSelectedHeight = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_selected_height, (int)pxFromDp(6));

            mDefaultUnSelectedWidth  = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_unselected_width, (int)pxFromDp(6));
            mDefaultUnSelectedHeight = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_unselected_height, (int)pxFromDp(6));

            mSelectedGradientDrawable   = new GradientDrawable();
            mUnSelectedGradientDrawable = new GradientDrawable();

            mPadding_left   = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_padding_left, (int)pxFromDp(3));
            mPadding_right  = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_padding_right, (int)pxFromDp(3));
            mPadding_top    = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_padding_top, (int)pxFromDp(0));
            mPadding_bottom = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_padding_bottom, (int)pxFromDp(0));

            mSelectedPadding_Left   = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_selected_padding_left, (int)mPadding_left);
            mSelectedPadding_Right  = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_selected_padding_right, (int)mPadding_right);
            mSelectedPadding_Top    = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_selected_padding_top, (int)mPadding_top);
            mSelectedPadding_Bottom = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_selected_padding_bottom, (int)mPadding_bottom);

            mUnSelectedPadding_Left   = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_unselected_padding_left, (int)mPadding_left);
            mUnSelectedPadding_Right  = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_unselected_padding_right, (int)mPadding_right);
            mUnSelectedPadding_Top    = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_unselected_padding_top, (int)mPadding_top);
            mUnSelectedPadding_Bottom = attributes.GetDimensionPixelSize(Resource.Styleable.PagerIndicator_unselected_padding_bottom, (int)mPadding_bottom);

            mSelectedLayerDrawable   = new LayerDrawable(new Drawable[] { mSelectedGradientDrawable });
            mUnSelectedLayerDrawable = new LayerDrawable(new Drawable[] { mUnSelectedGradientDrawable });


            setIndicatorStyleResource(mUserSetSelectedIndicatorResId, mUserSetUnSelectedIndicatorResId);
            DefaultIndicatorShape = mIndicatorShape;
            setDefaultSelectedIndicatorSize(mDefaultSelectedWidth, mDefaultSelectedHeight, Unit.Px);
            setDefaultUnselectedIndicatorSize(mDefaultUnSelectedWidth, mDefaultUnSelectedHeight, Unit.Px);
            setDefaultIndicatorColor(mDefaultSelectedColor, mDefaultUnSelectedColor);
            IndicatorVisibility = mVisibility;
            attributes.Recycle();
        }