Java Code Examples for android.content.res.TypedArray#getDimensionPixelOffset()

The following examples show how to use android.content.res.TypedArray#getDimensionPixelOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DotView.java    From DraggableDot with MIT License 6 votes vote down vote up
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();
}
 
Example 2
Source File: LabelView.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: CustomDrawableRadioButton.java    From QuickDevFramework with Apache License 2.0 6 votes vote down vote up
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);

}
 
Example 4
Source File: FilletImageView.java    From a with GNU General Public License v3.0 6 votes vote down vote up
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();

}
 
Example 5
Source File: DMTextureView.java    From DMView2 with Apache License 2.0 6 votes vote down vote up
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();


}
 
Example 6
Source File: CircleView.java    From WidgetCase with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 7
Source File: Keyboard.java    From libcommon with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: SuperRecyclerView.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: DividerView.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 10
Source File: RecordStudioAdjustSeekBar.java    From TikTok with Apache License 2.0 5 votes vote down vote up
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() {

        }
    };
}
 
Example 11
Source File: IRecyclerView.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: KeyPreviewDrawParams.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: SimpleGridLayout.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 14
Source File: CheckBox.java    From Genius-Android with Apache License 2.0 4 votes vote down vote up
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);
        }
    }
}
 
Example 15
Source File: TwoWayGridView.java    From recent-images with MIT License 4 votes vote down vote up
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();
}
 
Example 16
Source File: MaterialButtonHelper.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 17
Source File: RangeSliderView.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
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();
            }
        }
    });
}
 
Example 18
Source File: GradientTabStrip.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 19
Source File: FlashBorderView.java    From IndicatorBox with MIT License 4 votes vote down vote up
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();
}
 
Example 20
Source File: MaterialProgressBar.java    From KUAS-AP-Material with MIT License 4 votes vote down vote up
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);
}