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

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

@Override
protected void initStyleable(@NonNull Context context, @NonNull AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IconRoundCornerProgressBar);

    iconResource = typedArray.getResourceId(R.styleable.IconRoundCornerProgressBar_rcIconSrc, -1);

    iconSize = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconSize, -1);
    iconWidth = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconWidth, dp2px(DEFAULT_ICON_SIZE));
    iconHeight = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconHeight, dp2px(DEFAULT_ICON_SIZE));
    iconPadding = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconPadding, -1);
    iconPaddingLeft = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconPaddingLeft, dp2px(DEFAULT_ICON_PADDING_LEFT));
    iconPaddingRight = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconPaddingRight, dp2px(DEFAULT_ICON_PADDING_RIGHT));
    iconPaddingTop = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconPaddingTop, dp2px(DEFAULT_ICON_PADDING_TOP));
    iconPaddingBottom = (int) typedArray.getDimension(R.styleable.IconRoundCornerProgressBar_rcIconPaddingBottom, dp2px(DEFAULT_ICON_PADDING_BOTTOM));

    int defaultIconBackgroundColor = context.getResources().getColor(R.color.round_corner_progress_bar_background_default);
    colorIconBackground = typedArray.getColor(R.styleable.IconRoundCornerProgressBar_rcIconBackgroundColor, defaultIconBackgroundColor);

    typedArray.recycle();
}
 
源代码2 项目: FimiX8-RE   文件: X8TabItem.java
private void readAttr(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.X8TabHost);
    this.curIndex = a.getInt(R.styleable.X8TabHost_default_index, 0);
    this.radius = a.getDimensionPixelSize(R.styleable.X8TabHost_radiusC, dpToPx(this.radius));
    this.backBg = a.getColor(R.styleable.X8TabHost_bg, -1);
    this.lineColor = a.getColor(R.styleable.X8TabHost_lineColor, -1);
    this.lineStroke = a.getDimensionPixelSize(R.styleable.X8TabHost_lineStroke, dpToPx(this.lineStroke));
    this.unSelectTabBg = a.getColor(R.styleable.X8TabHost_tab_unselect_color, Color.parseColor("#51B5EF"));
    this.selectTabBg = a.getColor(R.styleable.X8TabHost_tab_select_color, -1);
    this.unSelectTextColor = a.getColor(R.styleable.X8TabHost_text_unselect_color, -1);
    this.selectTextColor = a.getColor(R.styleable.X8TabHost_text_select_color, Color.parseColor("#51B5EF"));
    this.space = a.getDimensionPixelSize(R.styleable.X8TabHost_tab_space, 1);
    this.tabWidth = a.getDimensionPixelSize(R.styleable.X8TabHost_tab_width, dpToPx(this.tabWidth));
    this.tabHeight = a.getDimensionPixelSize(R.styleable.X8TabHost_tab_height, -1);
    this.textSize = a.getDimension(R.styleable.X8TabHost_text_sizeC, this.textSize);
    CharSequence[] arr = a.getTextArray(R.styleable.X8TabHost_src);
    if (arr != null) {
        String[] tArr = new String[arr.length];
        for (int i = 0; i < arr.length; i++) {
            tArr[i] = String.valueOf(arr[i]);
        }
        this.textArr = tArr;
    }
    a.recycle();
}
 
源代码3 项目: DanDanPlayForAndroid   文件: TextPathAnimView.java
public TextPathAnimView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TextPathAnimView, defStyle, 0);
    mAnimDuration = typedArray.getInt(R.styleable.TextPathAnimView_duration, 1500);
    mTextBgColor = typedArray.getColor(R.styleable.TextPathAnimView_text_bg_color, Color.BLACK);
    mTextFgColor = typedArray.getColor(R.styleable.TextPathAnimView_text_fg_color, Color.WHITE);
    mIsLoop = typedArray.getBoolean(R.styleable.TextPathAnimView_loop, true);

    String contentText = typedArray.getString(R.styleable.TextPathAnimView_text);
    float sizeScale = typedArray.getFloat(R.styleable.TextPathAnimView_text_size_scale, dp2px(14));
    float stokeWidth = typedArray.getFloat(R.styleable.TextPathAnimView_text_stoke_width, 3f);
    float textInterval = typedArray.getDimension(R.styleable.TextPathAnimView_text_interval, dp2px(5));
    typedArray.recycle();

    mSourceTextPath = new TextPath(contentText, sizeScale, textInterval);
    mSourcePath = mSourceTextPath.getPath();

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(stokeWidth);

    mAnimPath = new Path();
    mPathMeasure = new PathMeasure();
}
 
源代码4 项目: 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();
}
 
源代码5 项目: PowerFileExplorer   文件: ShadowLayout.java
private void initAttributes(AttributeSet attrs) {
  TypedArray attr = getContext().obtainStyledAttributes(attrs, R.styleable.ShadowLayout, 0, 0);
  if (attr == null) return;

  try {
    cornerRadius = attr.getDimension(R.styleable.ShadowLayout_slCornerRadius,
        getResources().getDimension(R.dimen.defaultMenuDropShadowCornerRadius));
    shadowSize = attr.getDimension(R.styleable.ShadowLayout_slShadowSize,
        getResources().getDimension(R.dimen.defaultMenuDropShadowSize));
    dx = attr.getDimension(R.styleable.ShadowLayout_slDx, 0);
    dy = attr.getDimension(R.styleable.ShadowLayout_slDy, 0);
    shadowColor = attr.getColor(R.styleable.ShadowLayout_slShadowColor,
        ContextCompat.getColor(getContext(), R.color.finestBlack10));
  } finally {
    attr.recycle();
  }
}
 
public VerticalSlideColorPicker(Context context, AttributeSet attrs) {
  super(context, attrs);

  TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.VerticalSlideColorPicker, 0, 0);

  try {
    int colorsResourceId = a.getResourceId(R.styleable.VerticalSlideColorPicker_pickerColors, R.array.scribble_colors);

    colors          = a.getResources().getIntArray(colorsResourceId);
    borderColor     = a.getColor(R.styleable.VerticalSlideColorPicker_pickerBorderColor, Color.WHITE);
    borderWidth     = a.getDimension(R.styleable.VerticalSlideColorPicker_pickerBorderWidth, 10f);

  } finally {
    a.recycle();
  }

  init();
}
 
源代码7 项目: ProProgressViews   文件: CircleArcProgress.java
public CircleArcProgress(Context context, AttributeSet attrs) {
    super(context, attrs);
    paint.setStyle(Paint.Style.STROKE);
    TypedArray array=context.getTheme().obtainStyledAttributes(attrs,R.styleable.CircleArcProgress,0,0);
    try{
        in_rad=array.getDimension(R.styleable.CircleArcProgress_circle_size,50);
        colorArc=array.getColor(R.styleable.CircleArcProgress_color_circle, Color.parseColor("#5C6BC0"));
        out_rad=array.getDimension(R.styleable.CircleArcProgress_arc_radius,70);
        colorArc2=array.getColor(R.styleable.CircleArcProgress_arc_color, Color.parseColor("#1A237E"));
    }
    catch (Exception e){
        e.printStackTrace();
    }
    finally {
        array.recycle();
    }
    post(animator);
}
 
源代码8 项目: WayHoo   文件: LinePageIndicator.java
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);

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

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected.setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

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

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
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);
}
 
源代码10 项目: AndroidTvDemo   文件: ScrollTextView.java
/**
 * constructs 2
 *
 * @param context
 * @param attrs
 */
public ScrollTextView(Context context, AttributeSet attrs)
{
    super(context, attrs);
    surfaceHolder = this.getHolder(); // get The surface holder
    surfaceHolder.addCallback(this);
    paint = new Paint();
    TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.ScrollText);
    clickEnable = arr.getBoolean(R.styleable.ScrollText_clickEnable, clickEnable);
    isHorizontal = arr.getBoolean(R.styleable.ScrollText_isHorizontal, isHorizontal);
    speed = arr.getInteger(R.styleable.ScrollText_speed, speed);
    text = arr.getString(R.styleable.ScrollText_text);
    textColor = arr.getColor(R.styleable.ScrollText_textColor, textColor);
    textSize = arr.getDimension(R.styleable.ScrollText_textSize, textSize);
    defScrolltimes = arr.getInteger(R.styleable.ScrollText_times, defScrolltimes);
    
    needScrollTimes = defScrolltimes;
    paint.setColor(textColor);
    paint.setTextSize(textSize);
    
    setZOrderOnTop(true); // Control whether the surface view's surface is placed on top of its window.
    getHolder().setFormat(PixelFormat.TRANSLUCENT);
    
    DisplayMetrics metric = new DisplayMetrics();
    ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(metric);
    density = metric.density;
    
    setFocusable(true);
}
 
源代码11 项目: Collection-Android   文件: OutSideFrameTabLayout.java
public OutSideFrameTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag
    setClipChildren(false);
    setClipToPadding(false);
    this.mContext = context;
    mTabsContainer = new LinearLayout(context);
    super.addView(mTabsContainer, 0, new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));


    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.OutSideFrameTabLayout);

    mIndicatorColor = ta.getColor(R.styleable.OutSideFrameTabLayout_tab_tabIndicatorColor, Color.parseColor("#222831"));
    mIndicatorCornerRadius = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_indicator_corner, -1);
    mIndicatorMarginLeft = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_indicator_marginLeft, 0);
    mIndicatorMarginTop = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_indicator_marginTop, 0);
    mIndicatorMarginRight = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_indicator_marginRight, 0);
    mIndicatorMarginBottom = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_indicator_marginBottom, 0);

    mTextSelectColor = ta.getColor(R.styleable.OutSideFrameTabLayout_tab_tabSelectedTextColor, 0);
    mTextUnSelectColor = ta.getColor(R.styleable.OutSideFrameTabLayout_tab_tabTextColor, 0);
    mTextSize = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_tabTextSize, DisplayUtils.dip2px(context, 14));
    mTextAllCaps = ta.getBoolean(R.styleable.OutSideFrameTabLayout_tab_textAllCaps, false);

    tabWidth = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_width, 0);
    mTabPadding = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_padding, DisplayUtils.dip2px(context,10));

    mBarColor = ta.getColor(R.styleable.OutSideFrameTabLayout_tab_bar_color, Color.TRANSPARENT);
    mBarStrokeColor = ta.getColor(R.styleable.OutSideFrameTabLayout_tab_bar_stroke_color, mIndicatorColor);
    mBarStrokeWidth = ta.getDimension(R.styleable.OutSideFrameTabLayout_tab_bar_stroke_width, DisplayUtils.dip2px(context, 1));

    ta.recycle();
}
 
源代码12 项目: RoundImageView   文件: AbsRoundImageView.java
protected void initAttrs(AttributeSet attrs){
    if (attrs != null) {
        TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.AbsRoundImageView);
        borderWidth = ta.getDimension(R.styleable.AbsRoundImageView_riv_borderWidth, 0);
        borderColor = ta.getColor(R.styleable.AbsRoundImageView_riv_borderColor, 0);
        ta.recycle();
    }
}
 
源代码13 项目: GeometricWeather   文件: RoundCornerTransition.java
public RoundCornerTransition(Context context, AttributeSet attrs) {
    super(context, attrs);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerTransition);
    radiusFrom = a.getDimension(R.styleable.RoundCornerTransition_radius_from, 0f);
    radiusTo = a.getDimension(R.styleable.RoundCornerTransition_radius_to, 0f);
    a.recycle();
}
 
源代码14 项目: android_9.0.0_r45   文件: SuggestionSpan.java
private void initStyle(Context context) {
    if (context == null) {
        mMisspelledUnderlineThickness = 0;
        mEasyCorrectUnderlineThickness = 0;
        mAutoCorrectionUnderlineThickness = 0;
        mMisspelledUnderlineColor = Color.BLACK;
        mEasyCorrectUnderlineColor = Color.BLACK;
        mAutoCorrectionUnderlineColor = Color.BLACK;
        return;
    }

    int defStyleAttr = com.android.internal.R.attr.textAppearanceMisspelledSuggestion;
    TypedArray typedArray = context.obtainStyledAttributes(
            null, com.android.internal.R.styleable.SuggestionSpan, defStyleAttr, 0);
    mMisspelledUnderlineThickness = typedArray.getDimension(
            com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
    mMisspelledUnderlineColor = typedArray.getColor(
            com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);

    defStyleAttr = com.android.internal.R.attr.textAppearanceEasyCorrectSuggestion;
    typedArray = context.obtainStyledAttributes(
            null, com.android.internal.R.styleable.SuggestionSpan, defStyleAttr, 0);
    mEasyCorrectUnderlineThickness = typedArray.getDimension(
            com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
    mEasyCorrectUnderlineColor = typedArray.getColor(
            com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);

    defStyleAttr = com.android.internal.R.attr.textAppearanceAutoCorrectionSuggestion;
    typedArray = context.obtainStyledAttributes(
            null, com.android.internal.R.styleable.SuggestionSpan, defStyleAttr, 0);
    mAutoCorrectionUnderlineThickness = typedArray.getDimension(
            com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
    mAutoCorrectionUnderlineColor = typedArray.getColor(
            com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);
}
 
源代码15 项目: MultiColumnList   文件: ColumnListView.java
private void readAttrs(final Context context, final AttributeSet attrs) {
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ColumnListView);

    mNumberOfColumns = attributes.getInt(R.styleable.ColumnListView_columns, 2);
    mPadding = (int) attributes.getDimension(R.styleable.ColumnListView_column_padding, 0);
    mOverscroll = attributes.getBoolean(R.styleable.ColumnListView_overscroll, true);
    mFlingDamping = attributes.getFloat(R.styleable.ColumnListView_fling_damping, 1.5f);
    mSnapSpring = attributes.getInt(R.styleable.ColumnListView_snap_spring, 100);
    mSnapDamping = 2 * FloatMath.sqrt(mSnapSpring);
    mRubberbandFactor = attributes.getFloat(R.styleable.ColumnListView_rubberband_factor, 0.4f);

    attributes.recycle();
}
 
源代码16 项目: MyWeather   文件: MainActivity.java
private void initWidget() {
    contentMian = (ScrollView) findViewById(R.id.content_main);
    contentMian.setVisibility(View.INVISIBLE);

    mCurrentAreaTv = (TextView) findViewById(R.id.tv_topCity);
    mCurrentAreaTv.setText("正在刷新");

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
    swipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            swipeRefreshLayout.setRefreshing(true);
        }
    });

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refresh(false);
        }
    });

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle("");
    setSupportActionBar(mToolbar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawLayout);

    mFirstShowRl = findViewById(R.id.first_show_rl);

    TypedArray actionbarSizeTypedArray = this.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize});
    int h = (int) actionbarSizeTypedArray.getDimension(0, 0);
    mFirstShowRl.getLayoutParams().height = ScreenUtil.getScreenHeight(this) - h - ScreenUtil.getStatusBarHeight(this);

    setDrawerLayout();
    setRealWeather();
    setForeCast();
    setWind();
    setAqi();
    setSunRiseView();
    setZhiShu();
}
 
源代码17 项目: monolog-android   文件: TitlePageIndicator.java
public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
    final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res.getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res.getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res.getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position);
    final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
    final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
    final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
    final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);
    final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding);

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

    //Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight, defaultFooterLineHeight);
    mFooterIndicatorStyle = IndicatorStyle.fromValue(a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
    mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight, defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding, defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
    mLinePosition = LinePosition.fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition));
    mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding);
    mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
    mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor);
    mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor);
    mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold);

    final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize);
    final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(footerColor);

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

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
源代码18 项目: JsWebView   文件: NumberProgressBar.java
public NumberProgressBar(Context context, AttributeSet attrs,
                         int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    default_reached_bar_height = dp2px(1.5f);
    default_unreached_bar_height = dp2px(1.0f);
    default_text_size = sp2px(10);
    default_progress_text_offset = dp2px(3.0f);

    // load styled attributes.
    final TypedArray attributes = context.getTheme()
            .obtainStyledAttributes(attrs, R.styleable.NumberProgressBar,
                    defStyleAttr, 0);

    mReachedBarColor = attributes.getColor(
            R.styleable.NumberProgressBar_progress_reached_color,
            default_reached_color);
    mUnreachedBarColor = attributes.getColor(
            R.styleable.NumberProgressBar_progress_unreached_color,
            default_unreached_color);
    mTextColor = attributes.getColor(
            R.styleable.NumberProgressBar_progress_text_color,
            default_text_color);
    mTextSize = attributes.getDimension(
            R.styleable.NumberProgressBar_progress_text_size,
            default_text_size);

    mReachedBarHeight = attributes.getDimension(
            R.styleable.NumberProgressBar_progress_reached_bar_height,
            default_reached_bar_height);
    mUnreachedBarHeight = attributes.getDimension(
            R.styleable.NumberProgressBar_progress_unreached_bar_height,
            default_unreached_bar_height);
    mOffset = attributes.getDimension(
            R.styleable.NumberProgressBar_progress_text_offset,
            default_progress_text_offset);

    int textVisible = attributes.getInt(
            R.styleable.NumberProgressBar_progress_text_visibility,
            PROGRESS_TEXT_VISIBLE);
    if (textVisible != PROGRESS_TEXT_VISIBLE) {
        mIfDrawText = false;
    }

    setProgress(attributes
            .getInt(R.styleable.NumberProgressBar_progress, 0));
    setMax(attributes.getInt(R.styleable.NumberProgressBar_max, 100));

    attributes.recycle();
    initializePainters();
}
 
源代码19 项目: Musicoco   文件: Marker.java
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue, int thumbSize, int separation) {
    super(context, attrs, defStyleAttr);
    //as we're reading the parent DiscreteSeekBar attributes, it may wrongly set this view's visibility.
    setVisibility(View.VISIBLE);
    
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance,
            R.style.Widget_DiscreteIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textViewLimit so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = separation;
    ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor);
    mMarkerDrawable = new MarkerDrawable(color, thumbSize);
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation, ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}
 
源代码20 项目: HandyWidgets   文件: CenterTitleSideButtonBar.java
private void initAttrs(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray a = context.getTheme()
            .obtainStyledAttributes(attrs, R.styleable.CenterTitleSideButtonBar, defStyleAttr,
                    0);

    mHasLeftButton = a.getBoolean(R.styleable.CenterTitleSideButtonBar_hasLeftButton, false);
    mLeftButtonId = a.getResourceId(R.styleable.CenterTitleSideButtonBar_leftButtonId, -1);
    mLeftButtonShownDefault =
            a.getBoolean(R.styleable.CenterTitleSideButtonBar_leftButtonShownDefault, true);
    mLeftButtonAsText =
            a.getBoolean(R.styleable.CenterTitleSideButtonBar_leftButtonAsText, false);
    mLeftButtonText = a.getString(R.styleable.CenterTitleSideButtonBar_leftButtonText);
    mLeftButtonTextColor =
            a.getColorStateList(R.styleable.CenterTitleSideButtonBar_leftButtonTextColor);
    mLeftButtonTextSize =
            (int) a.getDimension(R.styleable.CenterTitleSideButtonBar_leftButtonTextSize, 20);
    mLeftButtonSrc = a.getResourceId(R.styleable.CenterTitleSideButtonBar_leftButtonSrc, 0);
    mLeftButtonBg = a.getResourceId(R.styleable.CenterTitleSideButtonBar_leftButtonBg, 0);

    mHasRightButton = a.getBoolean(R.styleable.CenterTitleSideButtonBar_hasRightButton, false);
    mRightButtonId = a.getResourceId(R.styleable.CenterTitleSideButtonBar_rightButtonId, -1);
    mRightButtonShownDefault =
            a.getBoolean(R.styleable.CenterTitleSideButtonBar_rightButtonShownDefault, false);
    mRightButtonAsText =
            a.getBoolean(R.styleable.CenterTitleSideButtonBar_rightButtonAsText, false);
    mRightButtonText = a.getString(R.styleable.CenterTitleSideButtonBar_rightButtonText);
    mRightButtonTextColor =
            a.getColorStateList(R.styleable.CenterTitleSideButtonBar_rightButtonTextColor);
    mRightButtonTextSize =
            (int) a.getDimension(R.styleable.CenterTitleSideButtonBar_rightButtonTextSize, 20);
    mRightButtonSrc = a.getResourceId(R.styleable.CenterTitleSideButtonBar_rightButtonSrc, 0);
    mRightButtonBg = a.getResourceId(R.styleable.CenterTitleSideButtonBar_rightButtonBg, 0);
    mRightButtonAsSearchView =
            a.getBoolean(R.styleable.CenterTitleSideButtonBar_rightButtonAsSearchView, false);
    mRightButtonClickToSearch = a
            .getBoolean(R.styleable.CenterTitleSideButtonBar_rightButtonClickToSearch, true);
    if (mRightButtonAsSearchView) {
        mCloseSearchViewId =
                a.getResourceId(R.styleable.CenterTitleSideButtonBar_closeSearchViewId, -1);
        mSearchViewDefaultShown =
                a.getBoolean(R.styleable.CenterTitleSideButtonBar_searchViewDefaultShown,
                        false);
        mSearchViewBg = a.getResourceId(R.styleable.CenterTitleSideButtonBar_searchViewBg, 0);
        mSearchViewHeight =
                a.getDimensionPixelSize(R.styleable.CenterTitleSideButtonBar_searchViewHeight,
                        ViewGroup.LayoutParams.MATCH_PARENT);
        mSearchViewMarginLeft = a.getDimensionPixelSize(
                R.styleable.CenterTitleSideButtonBar_searchViewMarginLeft, 0);
        mSearchViewMarginRight = a.getDimensionPixelSize(
                R.styleable.CenterTitleSideButtonBar_searchViewMarginRight, 0);
        mCloseSearchViewText =
                a.getString(R.styleable.CenterTitleSideButtonBar_closeSearchViewText);
        mCloseSearchViewTextColor = a.getColorStateList(
                R.styleable.CenterTitleSideButtonBar_closeSearchViewTextColor);
        mCloseSearchViewTextSize = (int) a.getDimension(
                R.styleable.CenterTitleSideButtonBar_closeSearchViewTextSize, 20);
    }

    mHasTitle = a.getBoolean(R.styleable.CenterTitleSideButtonBar_hasTitle, true);
    mTitleId = a.getResourceId(R.styleable.CenterTitleSideButtonBar_titleId, -1);
    mTitle = a.getString(R.styleable.CenterTitleSideButtonBar_centerTitle);
    mTitleColor =
            a.getColor(R.styleable.CenterTitleSideButtonBar_centerTitleTextColor, 0xFF333333);
    mTitleSize =
            (int) a.getDimension(R.styleable.CenterTitleSideButtonBar_centerTitleTextSize, 20);
    mTitleGravity =
            a.getInteger(R.styleable.CenterTitleSideButtonBar_centerTitleTextGravity, 0);
    mTitleEllipsize =
            a.getInteger(R.styleable.CenterTitleSideButtonBar_centerTitleEllipsize, 0);

    mHasDivider = a.getBoolean(R.styleable.CenterTitleSideButtonBar_hasDivider, false);
    mDividerId = a.getResourceId(R.styleable.CenterTitleSideButtonBar_dividerId, -1);
    mDividerColor = a.getColor(R.styleable.CenterTitleSideButtonBar_dividerColor, 0x19FFFFFF);
    mDividerHeight =
            a.getDimensionPixelSize(R.styleable.CenterTitleSideButtonBar_dividerHeight, 2);

    a.recycle();
}