android.content.res.TypedArray#getDimensionPixelOffset()源码实例Demo

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

源代码1 项目: codeexamples-android   文件: LabelView.java
/**
 * Construct object, initializing with any attributes we understand from a
 * layout file. These attributes are defined in
 * SDK/assets/res/any/classes.xml.
 * 
 * @see android.view.View#View(android.content.Context, android.util.AttributeSet)
 */
public LabelView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initLabelView();

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

    CharSequence s = a.getString(R.styleable.LabelView_text);
    if (s != null) {
        setText(s.toString());
    }

    // Retrieve the color(s) to be used for this view and apply them.
    // Note, if you only care about supporting a single color, that you
    // can instead call a.getColor() and pass that to setTextColor().
    setTextColor(a.getColor(R.styleable.LabelView_textColor, 0xFF000000));

    int textSize = a.getDimensionPixelOffset(R.styleable.LabelView_textSize, 0);
    if (textSize > 0) {
        setTextSize(textSize);
    }

    a.recycle();
}
 
private void initAttrs(Context context, AttributeSet attr) {
    if (attr != null) {
        TypedArray typedArray = context.obtainStyledAttributes(attr, R.styleable.CustomDrawableRadioButton);
        drawableWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableWidth, 0);
        drawableHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableHeight, 0);
        drawableLeftWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableLeftWidth, 0);
        drawableLeftHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableLeftHeight, 0);
        drawableRightWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableRightWidth, 0);
        drawableRightHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableRightHeight, 0);
        drawableTopWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableTopWidth, 0);
        drawableTopHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableTopHeight, 0);
        drawableBottomWidth = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableBottomWidth, 0);
        drawableBottomHeight = typedArray.getDimensionPixelOffset(R.styleable.CustomDrawableRadioButton_r_drawableBottomHeight, 0);

        typedArray.recycle();

    }

    Drawable drawables[] = getCompoundDrawables();
    Drawable left = drawables[0];
    Drawable top = drawables[1];
    Drawable right = drawables[2];
    Drawable bottom = drawables[3];
    setCompoundDrawables(left, top, right, bottom);

}
 
源代码3 项目: WidgetCase   文件: CircleView.java
private void initCustomAttrs(Context context, AttributeSet attrs) {
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleView);
    int ordinal = typedArray.getInt(R.styleable.CircleView_cv_center_style, CircleCenterStyle.Icon.ordinal());
    mCenterStyle = CircleCenterStyle.values()[ordinal];

    mCenterBitmap = BitmapFactory.decodeResource(getResources(),
            typedArray.getResourceId(R.styleable.CircleView_cv_center_bmp, R.drawable.widget_icon_person));
    mCenterStr = typedArray.getString(R.styleable.CircleView_cv_center_txt);
    mCenterTxtSize = typedArray.getDimensionPixelSize(R.styleable.CircleView_cv_center_txt_size, DensityUtil.sp2px(context, 12));
    mCenterTxtColor = typedArray.getColor(R.styleable.CircleView_cv_center_txt_color, Color.rgb(42, 42, 42));
    mCenterTxtMargin = typedArray.getDimensionPixelOffset(R.styleable.CircleView_cv_cengter_txt_margin,DensityUtil.dp2px(4));
    mBorderW = typedArray.getDimensionPixelOffset(R.styleable.CircleView_cv_boderW, 6);
    mRadius = typedArray.getDimensionPixelOffset(R.styleable.CircleView_cv_radius, 16);

    typedArray.recycle();
}
 
源代码4 项目: DMView2   文件: DMTextureView.java
public DMTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.setSurfaceTextureListener(this);
    setOpaque(false);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DMTextureView, defStyleAttr, 0);

    final Direction direction = Direction.getType(a.getInt(R.styleable.DMTextureView_dm_direction, Direction.RIGHT_LEFT.value));
    final int span = a.getDimensionPixelOffset(R.styleable.DMTextureView_dm_span, Util.dp2px(context, 2));
    final int sleep = a.getInteger(R.styleable.DMTextureView_dm_sleep, 0);
    final int spanTime = a.getInteger(R.styleable.DMTextureView_dm_span_time, 0);
    final int vSpace = a.getDimensionPixelOffset(R.styleable.DMTextureView_dm_v_space, Util.dp2px(context, 10));
    final int hSpace = a.getDimensionPixelOffset(R.styleable.DMTextureView_dm_h_space, Util.dp2px(context, 10));

    builder = new Controller.Builder()
            .setDirection(direction)
            .setSpan(span)
            .setSleep(sleep)
            .setSpanTime(spanTime)
            .sethSpace(hSpace)
            .setvSpace(vSpace);
    a.recycle();


}
 
源代码5 项目: a   文件: FilletImageView.java
private void init(Context context, AttributeSet attrs) {
    // 读取配置
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.FilletImageView);
    int defaultRadius = 5;
    int radius = array.getDimensionPixelOffset(R.styleable.FilletImageView_radius, defaultRadius);
    leftTopRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_left_top_radius, defaultRadius);
    rightTopRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_right_top_radius, defaultRadius);
    rightBottomRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_right_bottom_radius, defaultRadius);
    leftBottomRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_left_bottom_radius, defaultRadius);

    //如果四个角的值没有设置,那么就使用通用的radius的值。
    if (defaultRadius == leftTopRadius) {
        leftTopRadius = radius;
    }
    if (defaultRadius == rightTopRadius) {
        rightTopRadius = radius;
    }
    if (defaultRadius == rightBottomRadius) {
        rightBottomRadius = radius;
    }
    if (defaultRadius == leftBottomRadius) {
        leftBottomRadius = radius;
    }
    array.recycle();

}
 
源代码6 项目: DraggableDot   文件: DotView.java
public DotView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.DotView,
            0, 0);
    try {
        mRadius = a.getDimensionPixelOffset(R.styleable.DotView_xls_radius, dp2px(10));
        mCircleColor = a.getColor(R.styleable.DotView_xls_circle_color, Color.RED);
        mMaxStretchLength = a.getDimensionPixelOffset(R.styleable.DotView_xls_max_stretch_length, dp2px(80));
        mContent = a.getString(R.styleable.DotView_xls_content);
        mTextSize = a.getDimensionPixelOffset(R.styleable.DotView_xls_text_size, dp2px(16));
        mContentColor = a.getColor(R.styleable.DotView_xls_content_color, Color.WHITE);
    } finally {
        a.recycle();
    }
    init();
}
 
public KeyPreviewDrawParams(final TypedArray mainKeyboardViewAttr) {
    mPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
            R.styleable.MainKeyboardView_keyPreviewOffset, 0);
    mPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
            R.styleable.MainKeyboardView_keyPreviewHeight, 0);
    mPreviewBackgroundResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_keyPreviewBackground, 0);
    mLingerTimeout = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0);
    mShowUpAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_keyPreviewShowUpAnimator, 0);
    mDismissAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_keyPreviewDismissAnimator, 0);
}
 
源代码8 项目: NetEasyNews   文件: IRecyclerView.java
public IRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IRecyclerView, defStyle, 0);
    @LayoutRes int refreshHeaderLayoutRes = -1;
    @LayoutRes int loadMoreFooterLayoutRes = -1;
    int refreshFinalMoveOffset = -1;
    boolean refreshEnabled;
    boolean loadMoreEnabled;

    try {
        refreshEnabled = a.getBoolean(R.styleable.IRecyclerView_refreshEnabled, false);
        loadMoreEnabled = a.getBoolean(R.styleable.IRecyclerView_loadMoreEnabled, false);
        refreshHeaderLayoutRes = a.getResourceId(R.styleable.IRecyclerView_refreshHeaderLayout, -1);
        loadMoreFooterLayoutRes = a.getResourceId(R.styleable.IRecyclerView_loadMoreFooterLayout, -1);
        refreshFinalMoveOffset = a.getDimensionPixelOffset(R.styleable.IRecyclerView_refreshFinalMoveOffset, -1);
    } finally {
        a.recycle();
    }

    setRefreshEnabled(refreshEnabled);

    setLoadMoreEnabled(loadMoreEnabled);

    if (refreshHeaderLayoutRes != -1) {
        setRefreshHeaderView(refreshHeaderLayoutRes);
    }
    if (loadMoreFooterLayoutRes != -1) {
        setLoadMoreFooterView(loadMoreFooterLayoutRes);
    }
    if (refreshFinalMoveOffset != -1) {
        setRefreshFinalMoveOffset(refreshFinalMoveOffset);
    }
    setStatus(STATUS_DEFAULT);
}
 
源代码9 项目: TikTok   文件: RecordStudioAdjustSeekBar.java
public RecordStudioAdjustSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RecordStudioAdjustSeekBar, defStyleAttr, 0);
    mTidalPatAdjustThumbSize = array.getDimensionPixelSize(R.styleable.RecordStudioAdjustSeekBar_RecordStudioAdjustThumbSize, DensityUtils
            .dp2px(27));
    mTidalPatAdjustThumbColor = array.getColor(R.styleable.RecordStudioAdjustSeekBar_RecordStudioAdjustThumbColor, context.getResources().getColor(R.color.white));
    mTidalPatAdjustThumbDefaultColor = array.getColor(R.styleable.RecordStudioAdjustSeekBar_RecordStudioAdjustThumbDefaultColor, context.getResources().getColor(R.color.gray_normal));
    mTidalPatAdjustProgressColor = array.getColor(R.styleable.RecordStudioAdjustSeekBar_RecordStudioAdjustProgressColor, context.getResources().getColor(R.color.white));
    mTidalPatAdjustProgressSelectedColor = array.getColor(R.styleable.RecordStudioAdjustSeekBar_RecordStudioAdjustProgressSelectedColor, 0xFFFACE15);
    mTidalPatAdjustProgressDefaultColor = array.getColor(R.styleable.RecordStudioAdjustSeekBar_TRecordStudioAdjustProgressDefaultColor, context.getResources().getColor(R.color.few_10_transparency_white));
    mTidalPatAdjustProgressHeight = array.getDimensionPixelOffset(R.styleable.RecordStudioAdjustSeekBar_RecordStudioAdjustProgressHeight, DensityUtils.dp2px(3));
    mOnAdjustSeekBarScrollListener = new OnAdjustSeekBarScrollListener() {
        @Override
        public void onProgress(int progress) {

        }

        @Override
        public void onEventUp(int progress) {

        }

        @Override
        public void onEventDown() {

        }
    };
}
 
源代码10 项目: libcommon   文件: Keyboard.java
static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
	TypedValue value = a.peekValue(index);
	if (value == null) return defValue;
	if (value.type == TypedValue.TYPE_DIMENSION) {
		return a.getDimensionPixelOffset(index, defValue);
	} else if (value.type == TypedValue.TYPE_FRACTION) {
		// Round it to avoid values like 47.9999 from getting truncated
		return Math.round(a.getFraction(index, base, base, defValue));
	}
	return defValue;
}
 
源代码11 项目: EhViewer   文件: DividerView.java
private void init(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DividerView);
    int color = a.getColor(R.styleable.DividerView_dividerColor, Color.BLACK);
    mDividerWidth = a.getDimensionPixelOffset(R.styleable.DividerView_dividerWidth, 0);
    mDividerHeight = a.getDimensionPixelOffset(R.styleable.DividerView_dividerHeight, 0);
    a.recycle();

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(color);
    mRect = new Rect();
}
 
源代码12 项目: NewFastFrame   文件: SuperRecyclerView.java
public SuperRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuperRecyclerView, defStyle, 0);
    @LayoutRes int refreshHeaderLayoutRes = -1;
    @LayoutRes int loadMoreFooterLayoutRes = -1;
    int refreshFinalMoveOffset = -1;
    boolean refreshEnabled;
    boolean loadMoreEnabled;

    try {
        refreshEnabled = a.getBoolean(R.styleable.SuperRecyclerView_refreshEnabled, false);
        loadMoreEnabled = a.getBoolean(R.styleable.SuperRecyclerView_loadMoreEnabled, false);
        refreshHeaderLayoutRes = a.getResourceId(R.styleable.SuperRecyclerView_refreshHeaderLayout, -1);
        loadMoreFooterLayoutRes = a.getResourceId(R.styleable.SuperRecyclerView_loadMoreFooterLayout, -1);
        refreshFinalMoveOffset = a.getDimensionPixelOffset(R.styleable.SuperRecyclerView_refreshFinalMoveOffset, -1);
    } finally {
        a.recycle();
    }

    setRefreshEnabled(refreshEnabled);

    setLoadMoreEnabled(loadMoreEnabled);

    if (refreshHeaderLayoutRes != -1) {
        setRefreshHeaderView(refreshHeaderLayoutRes);
    }
    if (loadMoreFooterLayoutRes != -1) {
        setLoadMoreFooterView(loadMoreFooterLayoutRes);
    }
    if (refreshFinalMoveOffset != -1) {
        setRefreshFinalMoveOffset(refreshFinalMoveOffset);
    }
    setStatus(STATUS_DEFAULT);
}
 
源代码13 项目: EhViewer   文件: SimpleGridLayout.java
private void init(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SimpleGridLayout);
    mColumnCount = a.getInteger(R.styleable.SimpleGridLayout_columnCount, DEFAULT_COLUMN_COUNT);
    mItemMargin = a.getDimensionPixelOffset(R.styleable.SimpleGridLayout_itemMargin, 0);
    a.recycle();
}
 
源代码14 项目: KUAS-AP-Material   文件: MaterialProgressBar.java
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
	final TypedArray a =
			context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressBar, defStyleAttr,
					0);

	final float density = getContext().getResources().getDisplayMetrics().density;

	mBackGroundColor = a.getColor(R.styleable.MaterialProgressBar_background_color,
			DEFAULT_CIRCLE_BG_LIGHT);

	mProgressColor =
			a.getColor(R.styleable.MaterialProgressBar_progress_color, DEFAULT_CIRCLE_BG_LIGHT);

	mColors = new int[]{ContextCompat.getColor(getContext(), R.color.progress_red),
			ContextCompat.getColor(getContext(), R.color.progress_blue),
			ContextCompat.getColor(getContext(), R.color.progress_yellow),
			ContextCompat.getColor(getContext(), R.color.progress_green)};

	mInnerRadius = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_inner_radius, -1);

	mProgressStokeWidth =
			a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_stoke_width,
					(int) (STROKE_WIDTH_LARGE * density));
	mArrowWidth = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_width, -1);
	mArrowHeight = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_arrow_height, -1);
	mTextSize = a.getDimensionPixelOffset(R.styleable.MaterialProgressBar_progress_text_size,
			(int) (DEFAULT_TEXT_SIZE * density));
	mTextColor = a.getColor(R.styleable.MaterialProgressBar_progress_text_color, Color.BLACK);

	mShowArrow = a.getBoolean(R.styleable.MaterialProgressBar_show_arrow, false);
	mCircleBackgroundEnabled =
			a.getBoolean(R.styleable.MaterialProgressBar_enable_circle_background, true);

	mOverallSize = a.getInt(R.styleable.MaterialProgressBar_progress_overall_size, 2);

	mProgress = a.getInt(R.styleable.MaterialProgressBar_progress, 0);
	mMax = a.getInt(R.styleable.MaterialProgressBar_max, 100);
	int textVisible = a.getInt(R.styleable.MaterialProgressBar_progress_text_visibility, 1);
	if (textVisible != 1) {
		mIfDrawText = true;
	}

	mTextPaint = new Paint();
	mTextPaint.setStyle(Paint.Style.FILL);
	mTextPaint.setColor(mTextColor);
	mTextPaint.setTextSize(mTextSize);
	mTextPaint.setAntiAlias(true);
	a.recycle();
	mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
	super.setImageDrawable(mProgressDrawable);
}
 
源代码15 项目: ProjectX   文件: GradientTabStrip.java
private void initView(Context context, @Nullable AttributeSet attrs) {
    final float density = getResources().getDisplayMetrics().density;
    final TypedArray custom = context.obtainStyledAttributes(attrs,
            R.styleable.GradientTabStrip);
    final Drawable divider = custom.getDrawable(R.styleable.GradientTabStrip_gtsDivider);
    final int showDividers = custom.getInt(R.styleable.GradientTabStrip_gtsShowDividers,
            SHOW_DIVIDER_NONE);
    final int dividerPadding = custom.getDimensionPixelOffset(
            R.styleable.GradientTabStrip_gtsDividerPadding, 0);
    final Drawable center = custom.getDrawable(R.styleable.GradientTabStrip_gtsCenterInterval);
    final boolean centerAsItem = custom.getBoolean(
            R.styleable.GradientTabStrip_gtsCenterIntervalAsItem, false);
    final int centerPadding = custom.getDimensionPixelOffset(
            R.styleable.GradientTabStrip_gtsCenterIntervalPadding, 0);
    final boolean smoothScroll = custom.getBoolean(
            R.styleable.GradientTabStrip_gtsClickSmoothScroll, false);
    mItemBackgroundId = custom.getResourceId(R.styleable.GradientTabStrip_gtsItemBackground,
            NO_ID);
    mTextSize = custom.getDimension(R.styleable.GradientTabStrip_gtsTextSize,
            DEFAULT_TEXT_SIZE * density);
    mTextColorNormal = custom.getColor(R.styleable.GradientTabStrip_gtsTextColorNormal,
            DEFAULT_TEXT_COLOR_NORMAL);
    mTextColorSelected = custom.getColor(R.styleable.GradientTabStrip_gtsTextColorSelected,
            DEFAULT_TEXT_COLOR_SELECTED);
    mDrawablePadding = custom.getDimensionPixelOffset(
            R.styleable.GradientTabStrip_gtsDrawablePadding, 0);
    mDotCenterToViewCenterX = custom.getDimension(
            R.styleable.GradientTabStrip_gtsDotCenterToViewCenterX,
            DEFAULT_DOT_MARGIN * density);
    mDotCenterToViewCenterY = custom.getDimension(
            R.styleable.GradientTabStrip_gtsDotCenterToViewCenterY,
            -DEFAULT_DOT_MARGIN * density);
    mDotCanGoOutside = custom.getBoolean(R.styleable.GradientTabStrip_gtsDotCanGoOutside,
            false);
    mDotAutoChangeWidth = custom.getBoolean(R.styleable.GradientTabStrip_gtsDotAutoChangeWidth,
            true);
    final int color = custom.getColor(R.styleable.GradientTabStrip_gtsDotColor,
            DEFAULT_DOT_BACKGROUND_COLOR);
    final Drawable background =
            custom.getDrawable(R.styleable.GradientTabStrip_gtsDotBackground);
    mDotTextSize = custom.getDimension(R.styleable.GradientTabStrip_gtsDotTextSize,
            DEFAULT_DOT_TEXT_SIZE * density);
    mDotTextColor = custom.getColor(R.styleable.GradientTabStrip_gtsDotTextColor,
            DEFAULT_DOT_TEXT_COLOR);
    custom.recycle();
    set(divider, showDividers, dividerPadding, center, centerAsItem, centerPadding);
    setItemClickSmoothScroll(smoothScroll);
    mDotBackground = background == null ? getDefaultDotBackground(color) : background;
}
 
void loadFromAttributes(@NonNull TypedArray attributes) {
  insetLeft = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetLeft, 0);
  insetRight =
      attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetRight, 0);
  insetTop = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetTop, 0);
  insetBottom =
      attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetBottom, 0);

  // cornerRadius should override whatever corner radius is set in shapeAppearanceModel
  if (attributes.hasValue(R.styleable.MaterialButton_cornerRadius)) {
    cornerRadius = attributes.getDimensionPixelSize(R.styleable.MaterialButton_cornerRadius, -1);
    setShapeAppearanceModel(shapeAppearanceModel.withCornerSize(cornerRadius));
    cornerRadiusSet = true;
  }

  strokeWidth = attributes.getDimensionPixelSize(R.styleable.MaterialButton_strokeWidth, 0);

  backgroundTintMode =
      ViewUtils.parseTintMode(
          attributes.getInt(R.styleable.MaterialButton_backgroundTintMode, -1), Mode.SRC_IN);
  backgroundTint =
      MaterialResources.getColorStateList(
          materialButton.getContext(), attributes, R.styleable.MaterialButton_backgroundTint);
  strokeColor =
      MaterialResources.getColorStateList(
          materialButton.getContext(), attributes, R.styleable.MaterialButton_strokeColor);
  rippleColor =
      MaterialResources.getColorStateList(
          materialButton.getContext(), attributes, R.styleable.MaterialButton_rippleColor);

  checkable = attributes.getBoolean(R.styleable.MaterialButton_android_checkable, false);
  int elevation = attributes.getDimensionPixelSize(R.styleable.MaterialButton_elevation, 0);

  // Store padding before setting background, since background overwrites padding values
  int paddingStart = ViewCompat.getPaddingStart(materialButton);
  int paddingTop = materialButton.getPaddingTop();
  int paddingEnd = ViewCompat.getPaddingEnd(materialButton);
  int paddingBottom = materialButton.getPaddingBottom();

  // Update materialButton's background without triggering setBackgroundOverwritten()
  if (attributes.hasValue(R.styleable.MaterialButton_android_background)) {
    setBackgroundOverwritten();
  } else {
    materialButton.setInternalBackground(createBackground());
    MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable();
    if (materialShapeDrawable != null) {
      materialShapeDrawable.setElevation(elevation);
    }
  }
  // Set the stored padding values
  ViewCompat.setPaddingRelative(
      materialButton,
      paddingStart + insetLeft,
      paddingTop + insetTop,
      paddingEnd + insetRight,
      paddingBottom + insetBottom);
}
 
源代码17 项目: Genius-Android   文件: CheckBox.java
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final Context context = getContext();
    final Resources resource = getResources();
    final float density = resource.getDisplayMetrics().density;
    final int baseSize = (int) (density * 2);

    if (attrs == null) {
        mMarkDrawable = new CircleCheckDrawable(resource.getColorStateList(R.color.g_default_check_box));
        setButtonDrawable(mMarkDrawable);
        return;
    }

    // Load attributes
    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.CheckBox, defStyleAttr, defStyleRes);

    int borderSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gBorderSize, baseSize);
    int intervalSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gIntervalSize, baseSize);
    int markSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gMarkSize, -1);
    ColorStateList color = a.getColorStateList(R.styleable.CheckBox_gMarkColor);
    String fontFile = a.getString(R.styleable.CheckBox_gFont);

    a.recycle();

    if (color == null)
        color = resource.getColorStateList(R.color.g_default_check_box);

    boolean isCustom = true;

    if (markSize < 0) {
        markSize = (int) (density * 22);
        isCustom = false;
    }

    mMarkDrawable = new CircleCheckDrawable(color);
    mMarkDrawable.setBorderSize(borderSize);
    mMarkDrawable.setIntervalSize(intervalSize);
    mMarkDrawable.setMarkSize(markSize, isCustom);
    mMarkDrawable.inEditMode(isInEditMode());
    setButtonDrawable(mMarkDrawable);

    // Check for IDE preview render
    if (!this.isInEditMode()) {
        // Font
        if (fontFile != null && fontFile.length() > 0) {
            Typeface typeface = Ui.getFont(getContext(), fontFile);
            if (typeface != null) setTypeface(typeface);
        }
    }
}
 
源代码18 项目: recent-images   文件: TwoWayGridView.java
public TwoWayGridView(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.TwoWayGridView, defStyle, 0);

	int hSpacing = a.getDimensionPixelOffset(
			R.styleable.TwoWayGridView_horizontalSpacing, 0);
	setHorizontalSpacing(hSpacing);

	int vSpacing = a.getDimensionPixelOffset(
			R.styleable.TwoWayGridView_verticalSpacing, 0);
	setVerticalSpacing(vSpacing);

	int index = a.getInt(R.styleable.TwoWayGridView_stretchMode, STRETCH_COLUMN_WIDTH);
	if (index >= 0) {
		setStretchMode(index);
	}

	int columnWidth = a.getDimensionPixelOffset(R.styleable.TwoWayGridView_columnWidth, -1);
	if (columnWidth > 0) {
		setColumnWidth(columnWidth);
	}

	int rowHeight = a.getDimensionPixelOffset(R.styleable.TwoWayGridView_rowHeight, -1);
	if (rowHeight > 0) {
		setRowHeight(rowHeight);
	}

	int numColumns = a.getInt(R.styleable.TwoWayGridView_numColumns, 1);
	setNumColumns(numColumns);

	int numRows = a.getInt(R.styleable.TwoWayGridView_numRows, 1);
	setNumRows(numRows);

	index = a.getInt(R.styleable.TwoWayGridView_gravity, -1);
	if (index >= 0) {
		setGravity(index);
	}

	a.recycle();
	setupGridType();
}
 
源代码19 项目: deltachat-android   文件: RangeSliderView.java
public RangeSliderView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RangeSliderView);
    trackTintColor = typedArray.getColor(
            R.styleable.RangeSliderView_trackTintColor,
            ContextCompat.getColor(context, R.color.trackTintColor)
    );
    trackHighlightTintColor = typedArray.getColor(
            R.styleable.RangeSliderView_trackHighlightTintColor,
            ContextCompat.getColor(context, R.color.trackHighlightTintColor)
    );

    Resources resources = context.getResources();
    trackHeight = typedArray.getDimension(
            R.styleable.RangeSliderView_trackHeight,
            resources.getDimension(R.dimen.slider_trackHeight)
    );
    thumbInnerRadius = typedArray.getDimension(
            R.styleable.RangeSliderView_thumbRadius,
            resources.getDimension(R.dimen.slider_thumbRadius)
    );
    thumbOutlineSize = typedArray.getDimension(
            R.styleable.RangeSliderView_thumbOutlineSize,
            resources.getDimension(R.dimen.slider_thumbOutlineSize)
    );
    displayTextFontSize = typedArray.getDimension(
            R.styleable.RangeSliderView_displayTextFontSize,
            resources.getDimension(R.dimen.slider_displayTextFontSize)
    );
    displayTextBasicOffsetY = resources.getDimension(R.dimen.slider_displayTextBasicOffsetY);
    minValue = typedArray.getInt(
            R.styleable.RangeSliderView_minValue,
            100
    );
    maxValue = typedArray.getInt(
            R.styleable.RangeSliderView_maxValue,
            100
    );

    sliderPaddingRight = typedArray.getDimensionPixelOffset(R.styleable.RangeSliderView_paddingRight, 20);
    sliderPaddingLeft = typedArray.getDimensionPixelOffset(R.styleable.RangeSliderView_paddingLeft, 20);

    typedArray.recycle();

    minValueThumb = new ThumbLayer(thumbInnerRadius, thumbOutlineSize, trackHighlightTintColor, trackTintColor);
    minValueDisplayLabel = new TextLayer(displayTextFontSize, trackHighlightTintColor);

    maxValueThumb = new ThumbLayer(thumbInnerRadius, thumbOutlineSize, trackHighlightTintColor, trackTintColor);
    maxValueDisplayLabel = new TextLayer(displayTextFontSize, trackHighlightTintColor);

    track = new TrackLayer(sliderPaddingLeft, sliderPaddingRight, trackHeight, trackTintColor, trackHighlightTintColor);

    values = new ArrayList<>();
    for (int index = 1; index <= 100; index++) {
        values.add(index);
    }
    deltaValue = 0;

    longPressDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {
            if (minValue == maxValue && (minValueThumb.isHighlight || maxValueThumb.isHighlight)) {
                isThumbViewLocked = true;
                minValueThumb.isHighlight = true;
                maxValueThumb.isHighlight = true;
                invalidate();
            }
        }
    });
}
 
源代码20 项目: IndicatorBox   文件: FlashBorderView.java
private void initTypeArray(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FlashBorderView);
    mBorderColor = typedArray.getColor(R.styleable.FlashBorderView_border_color, getResources().getColor(R.color.colorAccent));
    mBorderWidth = typedArray.getDimensionPixelOffset(R.styleable.FlashBorderView_border_width, 5);
    typedArray.recycle();
}