android.content.Context#obtainStyledAttributes ( )源码实例Demo

下面列出了android.content.Context#obtainStyledAttributes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bailan   文件: FlowIndicator.java
public FlowIndicator(Context context, AttributeSet attrs) {
	super(context, attrs);
	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.FlowIndicator);
	//小圆点数量
	count = a.getInteger(R.styleable.FlowIndicator_count, 4);
	//每个小圆点间隔距离
	space = a.getDimension(R.styleable.FlowIndicator_space, 4);
	//小圆点半径
	radius = a.getDimension(R.styleable.FlowIndicator_radius, 7);
	//正常 没有选中的图片
	bmp_normal = BitmapFactory.decodeResource(getResources(),
			R.drawable.hui);
	//选中的图片
	bmp_selected = BitmapFactory.decodeResource(getResources(),
			R.drawable.lan);
	a.recycle();
}
 
源代码2 项目: FriendlyDemo   文件: CustomFontTextView.java
@SuppressWarnings({"PMD.UnusedFormalParameter", "PMD.ConstructorCallsOverridableMethod"})
public CustomFontTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs);
    setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);

    String fontName = null;
    TypedArray appearance = context.obtainStyledAttributes(attrs, R.styleable.CustomFontTextView);

    if (appearance != null) {
        int indexCount = appearance.getIndexCount();
        for (int i = 0; i < indexCount; i++) {
            int attr = appearance.getIndex(i);
            if (attr == R.styleable.CustomFontTextView_font) {
                fontName = appearance.getString(attr);
            }
        }
        appearance.recycle();
    }
    setTypeface(fontName);
}
 
源代码3 项目: Collection-Android   文件: FlexboxLayout.java
public LayoutParams(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context
            .obtainStyledAttributes(attrs, R.styleable.FlexboxLayout_Layout);
    mOrder = a.getInt(R.styleable.FlexboxLayout_Layout_layout_order, ORDER_DEFAULT);
    mFlexGrow = a
            .getFloat(R.styleable.FlexboxLayout_Layout_layout_flexGrow, FLEX_GROW_DEFAULT);
    mFlexShrink = a.getFloat(R.styleable.FlexboxLayout_Layout_layout_flexShrink,
            FLEX_SHRINK_DEFAULT);
    mAlignSelf = a
            .getInt(R.styleable.FlexboxLayout_Layout_layout_alignSelf, AlignSelf.AUTO);
    mFlexBasisPercent = a
            .getFraction(R.styleable.FlexboxLayout_Layout_layout_flexBasisPercent, 1, 1,
                    FLEX_BASIS_PERCENT_DEFAULT);
    mMinWidth = a
            .getDimensionPixelSize(R.styleable.FlexboxLayout_Layout_layout_minWidth, NOT_SET);
    mMinHeight = a
            .getDimensionPixelSize(R.styleable.FlexboxLayout_Layout_layout_minHeight, NOT_SET);
    mMaxWidth = a.getDimensionPixelSize(R.styleable.FlexboxLayout_Layout_layout_maxWidth,
            MAX_SIZE);
    mMaxHeight = a.getDimensionPixelSize(R.styleable.FlexboxLayout_Layout_layout_maxHeight,
            MAX_SIZE);
    mWrapBefore = a.getBoolean(R.styleable.FlexboxLayout_Layout_layout_wrapBefore, false);
    a.recycle();
}
 
@Override
public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    final Context context = mView.getContext();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SkinCompatTextHelper,
            defStyleAttr, 0);
    if (a.hasValue(R.styleable.SkinCompatTextHelper_android_drawableStart)) {
        mDrawableStartResId = a.getResourceId(R.styleable.SkinCompatTextHelper_android_drawableStart, INVALID_ID);
        mDrawableStartResId = SkinCompatHelper.checkResourceId(mDrawableStartResId);
    }
    if (a.hasValue(R.styleable.SkinCompatTextHelper_android_drawableEnd)) {
        mDrawableEndResId = a.getResourceId(R.styleable.SkinCompatTextHelper_android_drawableEnd, INVALID_ID);
        mDrawableEndResId = SkinCompatHelper.checkResourceId(mDrawableEndResId);
    }
    a.recycle();
    super.loadFromAttributes(attrs, defStyleAttr);
}
 
源代码5 项目: Viewer   文件: CameraPreview.java
private void initialize(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    if (getBackground() == null) {
        // Default to SurfaceView colour, so that there are less changes.
        setBackgroundColor(Color.BLACK);
    }

    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.zxing_camera_preview);
    int framingRectWidth = (int) attributes.getDimension(R.styleable.zxing_camera_preview_zxing_framing_rect_width, -1);
    int framingRectHeight = (int) attributes.getDimension(R.styleable.zxing_camera_preview_zxing_framing_rect_height, -1);
    attributes.recycle();

    if (framingRectWidth > 0 && framingRectHeight > 0) {
        this.framingRectSize = new Size(framingRectWidth, framingRectHeight);
    }

    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    stateHandler = new Handler(stateCallback);

    setupSurfaceView();

    rotationListener = new RotationListener();
}
 
源代码6 项目: FireFiles   文件: MaterialProgressBar.java
public MaterialProgressBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (isInEditMode()) {
        setIndeterminateDrawable(new MaterialProgressDrawable(getContext(), this));
        return;
    }

    Resources res = context.getResources();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressBar, defStyle, 0);

    final int color = a.getColor(R.styleable.MaterialProgressBar_color, res.getColor(R.color.accentColor));
    final float strokeWidth = a.getDimension(R.styleable.MaterialProgressBar_stroke_width, res.getDimension(R.dimen.default_stroke_width));
    final float sweepSpeed = a.getFloat(R.styleable.MaterialProgressBar_sweep_speed, Float.parseFloat(res.getString(R.string.default_sweep_speed)));
    final float rotationSpeed = a.getFloat(R.styleable.MaterialProgressBar_rotation_speed, Float.parseFloat(res.getString(R.string.default_rotation_speed)));
    final int minSweepAngle = a.getInteger(R.styleable.MaterialProgressBar_min_sweep_angle, res.getInteger(R.integer.default_min_sweep_angle));
    final int maxSweepAngle = a.getInteger(R.styleable.MaterialProgressBar_max_sweep_angle, res.getInteger(R.integer.default_max_sweep_angle));
    a.recycle();

    indeterminateDrawable = new MaterialProgressDrawable(getContext(), this);
    indeterminateDrawable.setBackgroundColor(CIRCLE_BG_LIGHT);
    indeterminateDrawable.setAlpha(255);
    indeterminateDrawable.updateSizes(MaterialProgressDrawable.LARGE);
    setColor(color);
}
 
源代码7 项目: Study_Android_Demo   文件: EaseChatExtendMenu.java
private void init(Context context, AttributeSet attrs){
    this.context = context;
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.EaseChatExtendMenu);
    int numColumns = ta.getInt(R.styleable.EaseChatExtendMenu_numColumns, 4);
    ta.recycle();
    
    setNumColumns(numColumns);
    setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    setGravity(Gravity.CENTER_VERTICAL);
    setVerticalSpacing(DensityUtil.dip2px(context, 8));
}
 
源代码8 项目: orz   文件: RoundImageView.java
public RoundImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mMatrix = new Matrix();
    mBitmapPaint = new Paint();
    mBitmapPaint.setAntiAlias(true);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundImageView);

    mBorderRadius = a.getDimensionPixelSize(R.styleable.RoundImageView_borderRadius,
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, BODER_RADIUS_DEFAULT, getResources().getDisplayMetrics()));// 默认为10dp
    mType = a.getInt(R.styleable.RoundImageView_type, TYPE_ROUND);// 默认为Round

    a.recycle();
}
 
源代码9 项目: android_9.0.0_r45   文件: GridLayout.java
private void reInitSuper(Context context, AttributeSet attrs) {
    TypedArray a =
            context.obtainStyledAttributes(attrs, R.styleable.ViewGroup_MarginLayout);
    try {
        int margin = a.getDimensionPixelSize(MARGIN, DEFAULT_MARGIN);

        this.leftMargin = a.getDimensionPixelSize(LEFT_MARGIN, margin);
        this.topMargin = a.getDimensionPixelSize(TOP_MARGIN, margin);
        this.rightMargin = a.getDimensionPixelSize(RIGHT_MARGIN, margin);
        this.bottomMargin = a.getDimensionPixelSize(BOTTOM_MARGIN, margin);
    } finally {
        a.recycle();
    }
}
 
源代码10 项目: android-recipes-app   文件: FragmentTabHost.java
private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();

    super.setOnTabChangedListener(this);
}
 
源代码11 项目: android-project-wo2b   文件: CirclePageIndicator.java
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    if (background != null) {
      setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
源代码12 项目: Stylish-Widget-for-Android   文件: ARadioButton.java
private void setCustomTypeface(Context context, AttributeSet attrs) {
    if (isInEditMode())
        return;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextAppearance);
    int style = a.getInt(R.styleable.TextAppearance_android_textStyle, Typeface.NORMAL);

    setTextStyle(style);
    a.recycle();

}
 
源代码13 项目: v2ex   文件: FlexibleRecyclerView.java
public FlexibleRecyclerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (attrs != null) {
        final TypedArray xmlArgs = context.obtainStyledAttributes(attrs,
                R.styleable.FlexibleRecyclerView, defStyle, 0);
        mContentTopClearance = xmlArgs.getDimensionPixelSize(
                R.styleable.FlexibleRecyclerView_topClearance, 0);
        xmlArgs.recycle();
    }
}
 
源代码14 项目: fingerpoetry-android   文件: RippleLayout.java
public RippleLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setWillNotDraw(false);
    gestureDetector = new GestureDetector(context, longClickListener);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialRippleLayout);
    rippleColor = a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleColor, DEFAULT_COLOR);
    rippleDiameter = a.getDimensionPixelSize(
            R.styleable.MaterialRippleLayout_mrl_rippleDimension,
            (int) dpToPx(getResources(), DEFAULT_DIAMETER_DP)
    );
    rippleOverlay = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleOverlay, DEFAULT_RIPPLE_OVERLAY);
    rippleHover = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleHover, DEFAULT_HOVER);
    rippleDuration = a.getInt(R.styleable.MaterialRippleLayout_mrl_rippleDuration, DEFAULT_DURATION);
    rippleAlpha = (int) (255 * a.getFloat(R.styleable.MaterialRippleLayout_mrl_rippleAlpha, DEFAULT_ALPHA));
    rippleDelayClick = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleDelayClick, DEFAULT_DELAY_CLICK);
    rippleFadeDuration = a.getInteger(R.styleable.MaterialRippleLayout_mrl_rippleFadeDuration, DEFAULT_FADE_DURATION);
    rippleBackground = new ColorDrawable(a.getColor(R.styleable.MaterialRippleLayout_mrl_rippleBackground, DEFAULT_BACKGROUND));
    ripplePersistent = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_ripplePersistent, DEFAULT_PERSISTENT);
    rippleInAdapter = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleInAdapter, DEFAULT_SEARCH_ADAPTER);
    rippleRoundedCorners = a.getDimensionPixelSize(R.styleable.MaterialRippleLayout_mrl_rippleRoundedCorners, DEFAULT_ROUNDED_CORNERS);

    a.recycle();

    paint.setColor(rippleColor);
    paint.setAlpha(rippleAlpha);

    enableClipPathSupportIfNecessary();
}
 
源代码15 项目: SeekArc   文件: SeekArc.java
private void init(Context context, AttributeSet attrs, int defStyle) {

		Log.d(TAG, "Initialising SeekArc");
		final Resources res = getResources();
		float density = context.getResources().getDisplayMetrics().density;

		// Defaults, may need to link this into theme settings
		int arcColor = res.getColor(R.color.progress_gray);
		int progressColor = res.getColor(R.color.default_blue_light);
		int thumbHalfheight = 0;
		int thumbHalfWidth = 0;
		mThumb = res.getDrawable(R.drawable.seek_arc_control_selector);
		// Convert progress width to pixels for current density
		mProgressWidth = (int) (mProgressWidth * density);

		
		if (attrs != null) {
			// Attribute initialization
			final TypedArray a = context.obtainStyledAttributes(attrs,
					R.styleable.SeekArc, defStyle, 0);

			Drawable thumb = a.getDrawable(R.styleable.SeekArc_thumb);
			if (thumb != null) {
				mThumb = thumb;
			}

			
			
			thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
			thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
			mThumb.setBounds(-thumbHalfWidth, -thumbHalfheight, thumbHalfWidth,
					thumbHalfheight);

			mMax = a.getInteger(R.styleable.SeekArc_max, mMax);
			mProgress = a.getInteger(R.styleable.SeekArc_progress, mProgress);
			mProgressWidth = (int) a.getDimension(
					R.styleable.SeekArc_progressWidth, mProgressWidth);
			mArcWidth = (int) a.getDimension(R.styleable.SeekArc_arcWidth,
					mArcWidth);
			mStartAngle = a.getInt(R.styleable.SeekArc_startAngle, mStartAngle);
			mSweepAngle = a.getInt(R.styleable.SeekArc_sweepAngle, mSweepAngle);
			mRotation = a.getInt(R.styleable.SeekArc_rotation, mRotation);
			mRoundedEdges = a.getBoolean(R.styleable.SeekArc_roundEdges,
					mRoundedEdges);
			mTouchInside = a.getBoolean(R.styleable.SeekArc_touchInside,
					mTouchInside);
			mClockwise = a.getBoolean(R.styleable.SeekArc_clockwise,
					mClockwise);
			mEnabled = a.getBoolean(R.styleable.SeekArc_enabled, mEnabled);

			arcColor = a.getColor(R.styleable.SeekArc_arcColor, arcColor);
			progressColor = a.getColor(R.styleable.SeekArc_progressColor,
					progressColor);

			a.recycle();
		}

		mProgress = (mProgress > mMax) ? mMax : mProgress;
		mProgress = (mProgress < 0) ? 0 : mProgress;

		mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle;
		mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle;

		mProgressSweep = (float) mProgress / mMax * mSweepAngle;

		mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle;
		mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle;

		mArcPaint = new Paint();
		mArcPaint.setColor(arcColor);
		mArcPaint.setAntiAlias(true);
		mArcPaint.setStyle(Paint.Style.STROKE);
		mArcPaint.setStrokeWidth(mArcWidth);
		//mArcPaint.setAlpha(45);

		mProgressPaint = new Paint();
		mProgressPaint.setColor(progressColor);
		mProgressPaint.setAntiAlias(true);
		mProgressPaint.setStyle(Paint.Style.STROKE);
		mProgressPaint.setStrokeWidth(mProgressWidth);

		if (mRoundedEdges) {
			mArcPaint.setStrokeCap(Paint.Cap.ROUND);
			mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
		}
	}
 
/**
 * The contructor used with an inflater
 * 
 * @param context
 * @param attrs
 */
public CircleFlowIndicator(Context context, AttributeSet attrs) {
	super(context, attrs);
	// Retrieve styles attributs
	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.CircleFlowIndicator);

	// Gets the active circle type, defaulting to "fill"
	int activeType = a.getInt(R.styleable.CircleFlowIndicator_activeType,
			STYLE_FILL);

	int activeDefaultColor = 0xFF7DC62D;

	// Get a custom active color if there is one
	int activeColor = a
			.getColor(R.styleable.CircleFlowIndicator_activeColor,
					activeDefaultColor);

	// Gets the inactive circle type, defaulting to "stroke"
	int inactiveType = a.getInt(
			R.styleable.CircleFlowIndicator_inactiveType, STYLE_STROKE);

	int inactiveDefaultColor = 0xFF9D9D9D;
	// Get a custom inactive color if there is one
	int inactiveColor = a.getColor(
			R.styleable.CircleFlowIndicator_inactiveColor,
			inactiveDefaultColor);

	// Retrieve the radius
	mRadius = a.getDimension(R.styleable.CircleFlowIndicator_radius, 4.0f);
	mRadiusActive = mRadius;
	mRadiusInactive = mRadius;

	// Retrieve the spacing
	spacing = a.getDimension(R.styleable.CircleFlowIndicator_spacing, 4.0f);
	// We want the spacing to be center-to-center
	spacing += 2 * mRadiusActive;

	// Retrieve the fade out time
	fadeOutTime = a.getInt(R.styleable.CircleFlowIndicator_fadeOut, 0);

	mCentered = a.getBoolean(R.styleable.CircleFlowIndicator_centered,
			false);

	mSnap = a.getBoolean(R.styleable.CircleFlowIndicator_snap, true);

	initColors(activeColor, inactiveColor, activeType, inactiveType);
}
 
public DividerItemDecoration(Context context, int orientation) {
    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    mDivider = a.getDrawable(0);
    a.recycle();
    setOrientation(orientation);
}
 
源代码18 项目: PowerFileExplorer   文件: TextAppearanceSpan.java
/**
 * Uses the specified TextAppearance resource to determine the
 * text appearance, and the specified text color resource
 * to determine the color.  The <code>appearance</code> should be,
 * for example, <code>android.R.style.TextAppearance_Small</code>,
 * and the <code>colorList</code> should be, for example,
 * <code>android.R.styleable.Theme_textColorDim</code>.
 */
public TextAppearanceSpan(Context context, int appearance,
                          int colorList) {
    ColorStateList textColor;

    TypedArray a =
        context.obtainStyledAttributes(appearance,
                                       com.android.internal.R.styleable.TextAppearance);

    textColor = a.getColorStateList(com.android.internal.R.styleable.
                                    TextAppearance_textColor);
    mTextColorLink = a.getColorStateList(com.android.internal.R.styleable.
                                    TextAppearance_textColorLink);
    mTextSize = a.getDimensionPixelSize(com.android.internal.R.styleable.
                                    TextAppearance_textSize, -1);

    mStyle = a.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, 0);
    int tf = a.getInt(com.android.internal.R.styleable.TextAppearance_typeface, 0);

    switch (tf) {
        case 1:
            mTypeface = "sans";
            break;

        case 2:
            mTypeface = "serif";
            break;

        case 3:
            mTypeface = "monospace";
            break;

        default:
            mTypeface = null;
            break;
    }

    a.recycle();

    if (colorList >= 0) {
        a = context.obtainStyledAttributes(com.android.internal.R.style.Theme,
                                        com.android.internal.R.styleable.Theme);

        textColor = a.getColorStateList(colorList);
        a.recycle();
    }

    mTextColor = textColor;
}
 
源代码19 项目: Girls   文件: DividerItemDecoration.java
public DividerItemDecoration(Context context, int orientation) {
    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    mDivider = a.getDrawable(0);
    a.recycle();
    setOrientation(orientation);
}
 
源代码20 项目: android   文件: DividerItemDecoration.java
public DividerItemDecoration(Context context, AttributeSet attrs) {
  final TypedArray a = context
      .obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider});
  mDivider = a.getDrawable(0);
  a.recycle();
}
 
 方法所在类
 同类方法