List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs)
From source file:com.android.andryyu.lifehelper.widget.RippleView.java
/** * Method that initializes all fields and sets listeners * * @param context Context used to create this view * @param attrs Attribute used to initialize fields *//*from w w w .j a va 2 s. c om*/ private void init(final Context context, final AttributeSet attrs) { if (isInEditMode()) return; final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView); rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, Color.parseColor("#33626262")); rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0); hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false); isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false); rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration); frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate); rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha); ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0); canvasHandler = new Handler(); zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f); zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200); isListMode = typedArray.getBoolean(R.styleable.RippleView_rv_listMode, false); typedArray.recycle(); paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setColor(rippleColor); paint.setAlpha(rippleAlpha); this.setWillNotDraw(false); gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent event) { super.onLongPress(event); animateRipple(event); sendClickEvent(true); lastLongPressX = (int) event.getX(); lastLongPressY = (int) event.getY(); rippleStatus = RIPPLE_LONG_PRESS; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return true; } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); this.setDrawingCacheEnabled(true); this.setClickable(true); this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); }
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout); mLeftViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_leftViewId, mLeftViewId); mContentViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_contentViewId, mContentViewId); mRightViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_rightViewId, mRightViewId); typedArray.recycle();//from www .j a v a 2 s. c om ViewConfiguration mViewConfig = ViewConfiguration.get(getContext()); mScaledTouchSlop = mViewConfig.getScaledTouchSlop(); mScroller = new OverScroller(getContext()); mScaledMinimumFlingVelocity = mViewConfig.getScaledMinimumFlingVelocity(); mScaledMaximumFlingVelocity = mViewConfig.getScaledMaximumFlingVelocity(); }
From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java
public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setWillNotDraw(false);// ww w . j a v a2 s . c o m paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout); final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; // first check if all insets set the same titleInsetStart = titleInsetEnd = titleInsetBottom = a .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInset, 0); titleInsetTop = titleInsetStart; if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetStart)) { final int insetStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetStart, 0); if (isRtl) { titleInsetEnd = insetStart; } else { titleInsetStart = insetStart; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetTop)) { titleInsetTop = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetTop, 0); } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetEnd)) { final int insetEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetEnd, 0); if (isRtl) { titleInsetStart = insetEnd; } else { titleInsetEnd = insetEnd; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetBottom)) { titleInsetBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetBottom, 0); } final int textAppearance = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance, android.R.style.TextAppearance); TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.CollapsingTextAppearance); paint.setColor(atp.getColor(R.styleable.CollapsingTextAppearance_android_textColor, Color.WHITE)); collapsedTextSize = atp.getDimensionPixelSize(R.styleable.CollapsingTextAppearance_android_textSize, 0); if (atp.hasValue(R.styleable.CollapsingTextAppearance_font)) { paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.CollapsingTextAppearance_font))); } atp.recycle(); if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) { collapsedTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0); paint.setTextSize(collapsedTextSize); } maxExpandedTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_maxExpandedTextSize, Integer.MAX_VALUE); lineHeightHint = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_lineHeightHint, 0); maxLines = a.getInteger(R.styleable.CollapsingTitleLayout_android_maxLines, 5); a.recycle(); }
From source file:am.widget.scalerecyclerview.ScaleRecyclerView.java
private void initView(Context context, @Nullable AttributeSet attrs) { final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.ScaleRecyclerView); mScaleEnable = custom.getBoolean(R.styleable.ScaleRecyclerView_srvScaleEnable, false); mScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvScale, 1); mMinScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvMinScale, 0.000000001f); mMaxScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvMaxScale, 6); custom.recycle();//from w w w.j a va2s . c om mGestureDetector = new GestureDetectorCompat(context, new DoubleTapListener()); mScaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener()); }
From source file:com.aibasis.parent.widget.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs) { super(context, attrs); setHorizontalScrollBarEnabled(false); // ?????? if (attrs != null) { TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); if (attrsTypedArray != null) { allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false); slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock); disableViewPager = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_disableViewPager, false);/*from w w w.ja va 2 s. co m*/ attrsTypedArray.recycle(); } } }
From source file:android.support.designox.widget.BottomSheetBehavior.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}.//w w w . j ava 2 s . c o m * @param attrs The {@link AttributeSet}. */ public BottomSheetBehavior(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Params); setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Params_behavior_peekHeight_ox, 0)); setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Params_behavior_hideable_ox, false)); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:android.support.v7.app.AppCompatViewInflater.java
/** * android:onClick doesn't handle views with a ContextWrapper context. This method * backports new framework functionality to traverse the Context wrappers to find a * suitable target./* ww w . j av a 2 s . c om*/ */ private void checkOnClickListener(View view, AttributeSet attrs) { final Context context = view.getContext(); if (!(context instanceof ContextWrapper) || (Build.VERSION.SDK_INT >= 15 && !ViewCompat.hasOnClickListeners(view))) { // Skip our compat functionality if: the Context isn't a ContextWrapper, or // the view doesn't have an OnClickListener (we can only rely on this on API 15+ so // always use our compat code on older devices) return; } final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs); final String handlerName = a.getString(0); if (handlerName != null) { view.setOnClickListener(new DeclaredOnClickListener(view, handlerName)); } a.recycle(); }
From source file:cc.kenai.common.AnimatedSvgView.java
private void init(Context context, AttributeSet attrs) { mFillPaint = new Paint(); mFillPaint.setAntiAlias(true);/* w w w. j av a 2s.c o m*/ mFillPaint.setStyle(Paint.Style.FILL); mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP, getResources().getDisplayMetrics()); mTraceColors = new int[1]; mTraceColors[0] = Color.BLACK; mTraceResidueColors = new int[1]; mTraceResidueColors[0] = Color.argb(50, 0, 0, 0); if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView); mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433); Log.i(TAG, "mViewportWidth=" + mViewportWidth); mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433); mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433); mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433); mTraceTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTime, 2000); mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTimePerGlyph, 1000); mFillStart = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillStart, 1200); mFillTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillTime, 1000); a.recycle(); mViewport = new PointF(mViewportWidth, mViewportHeight); } loadConfig(); }
From source file:com.andremion.music.MusicCoverView.java
public MusicCoverView(Context context, AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MusicCoverView); @Shape//from w ww .j ava 2 s.co m int shape = a.getInt(R.styleable.MusicCoverView_shape, SHAPE_SQUARE); @ColorInt int trackColor = a.getColor(R.styleable.MusicCoverView_trackColor, TRACK_COLOR); a.recycle(); // TODO: Canvas.clipPath works wrong when running with hardware acceleration on Android N if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { setLayerType(View.LAYER_TYPE_HARDWARE, null); } final float density = getResources().getDisplayMetrics().density; mTrackSize = TRACK_SIZE * density; mTrackPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTrackPaint.setStyle(Paint.Style.STROKE); mTrackPaint.setStrokeWidth(TRACK_WIDTH * density); mDiscPaintCenterDecor = new Paint(Paint.ANTI_ALIAS_FLAG); mDiscPaintCenterDecor.setStyle(Paint.Style.FILL); mDiscPaintCenter = new Paint(Paint.ANTI_ALIAS_FLAG); mDiscPaintCenter.setStyle(Paint.Style.FILL); setShape(shape); setTrackColor(trackColor); if (getDrawable() != null && ((BitmapDrawable) getDrawable()).getBitmap() != null) { setCenterColor(DISC_CENTER_COLOR, Palette.generate(((BitmapDrawable) getDrawable()).getBitmap(), 32) .getLightVibrantColor(DISC_CENTER_DECOR_COLOR)); } else { setCenterColor(DISC_CENTER_COLOR, DISC_CENTER_DECOR_COLOR); } setScaleType(); mStartRotateAnimator = ObjectAnimator.ofFloat(this, View.ROTATION, 0, FULL_ANGLE); mStartRotateAnimator.setInterpolator(new LinearInterpolator()); if (SHAPE_SQUARE == mShape) { mStartRotateAnimator.setDuration(DURATION_SQUARE); } else { mStartRotateAnimator.setDuration(DURATION); mStartRotateAnimator.setRepeatCount(Animation.INFINITE); } mStartRotateAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { float current = getRotation(); float target = current > HALF_ANGLE ? FULL_ANGLE : 0; // Choose the shortest distance to 0 rotation float diff = target > 0 ? FULL_ANGLE - current : current; mEndRotateAnimator.setFloatValues(current, target); if (SHAPE_SQUARE == mShape) { mEndRotateAnimator.setDuration((int) (DURATION_SQUARE_PER_DEGREES * diff)); } else { mEndRotateAnimator.setDuration((int) (DURATION_PER_DEGREES * diff)); } mEndRotateAnimator.start(); } }); mEndRotateAnimator = ObjectAnimator.ofFloat(MusicCoverView.this, View.ROTATION, 0); mEndRotateAnimator.setInterpolator(new LinearInterpolator()); mEndRotateAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setRotation(0); // isRunning method return true if it's called form here. // So we need call from post method to get the right returning. post(new Runnable() { @Override public void run() { if (mCallbacks != null) { mCallbacks.onRotateEnd(MusicCoverView.this); } } }); } }); mRectToCircleTransition = new MorphTransition(SHAPE_RECTANGLE); mRectToCircleTransition.addTarget(this); mRectToCircleTransition.addListener(new TransitionAdapter() { @Override public void onTransitionStart(Transition transition) { mIsMorphing = true; } @Override public void onTransitionEnd(Transition transition) { mIsMorphing = false; mShape = SHAPE_CIRCLE; if (mCallbacks != null) { mCallbacks.onMorphEnd(MusicCoverView.this); } } }); mCircleToRectTransition = new MorphTransition(SHAPE_CIRCLE); mCircleToRectTransition.addTarget(this); mCircleToRectTransition.addListener(new TransitionAdapter() { @Override public void onTransitionStart(Transition transition) { mIsMorphing = true; } @Override public void onTransitionEnd(Transition transition) { mIsMorphing = false; mShape = SHAPE_RECTANGLE; if (mCallbacks != null) { mCallbacks.onMorphEnd(MusicCoverView.this); } } }); mSquareToSquareTransition = new MorphTransition(SHAPE_SQUARE); mSquareToSquareTransition.addTarget(this); mSquareToSquareTransition.addListener(new TransitionAdapter() { @Override public void onTransitionStart(Transition transition) { mIsMorphing = true; } @Override public void onTransitionEnd(Transition transition) { mIsMorphing = false; mShape = SHAPE_SQUARE; if (mCallbacks != null) { mCallbacks.onMorphEnd(MusicCoverView.this); } } }); }
From source file:android.support.design.widget.BottomSheetBehavior.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}./*from www . j ava 2s .c o m*/ * @param attrs The {@link AttributeSet}. */ public BottomSheetBehavior(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout); TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight); if (value != null && value.data == PEEK_HEIGHT_AUTO) { setPeekHeight(value.data); } else { setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, PEEK_HEIGHT_AUTO)); } setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false)); setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false)); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }