Example usage for android.content.res TypedArray getDimension

List of usage examples for android.content.res TypedArray getDimension

Introduction

In this page you can find the example usage for android.content.res TypedArray getDimension.

Prototype

public float getDimension(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index.

Usage

From source file:com.example.zhangyangjing.roundcornerimageview.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);
    mCornerRadius = a.getDimension(R.styleable.BezelImageView_cornerRadius, mCornerRadius);

    a.recycle();//w w  w .j  a va 2  s . c  om

    mDesaturatePaint = new Paint();
    mMaskedPaint = new Paint();
    mMaskedPaint.setAntiAlias(true);
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static float getSupportActionBarElevation(final Context context) {
    @SuppressWarnings("ConstantConditions")
    final TypedArray a = context.obtainStyledAttributes(null, new int[] { R.attr.elevation },
            R.attr.actionBarStyle, 0);//  w w w . j a  va  2 s . c om
    try {
        return a.getDimension(0, 0);
    } finally {
        a.recycle();
    }
}

From source file:org.catrobat.paintroid.WelcomeActivity.java

private void getStyleAttributesFromXml() {
    final DisplayMetrics metrics = getBaseContext().getResources().getDisplayMetrics();
    for (TapTargetStyle text : TapTargetStyle.values()) {
        TypedArray attribute = obtainStyledAttributes(text.getResourceId(), R.styleable.IntroAttributes);

        int textSizeDp = (int) attribute.getDimension(R.styleable.IntroAttributes_android_textSize, 16);
        int textStyle = attribute.getInt(R.styleable.IntroAttributes_android_textStyle, 0);
        int color = attribute.getColor(R.styleable.IntroAttributes_android_textColor, Color.WHITE);
        String fontFamilyName = attribute.getString(R.styleable.IntroAttributes_android_fontFamily);
        Typeface typeface = Typeface.create(fontFamilyName, textStyle);

        text.setTextColor(color);//from  ww  w  .j  a  v a  2 s. co  m
        text.setTextSize(getSpFromDimension(textSizeDp, metrics));
        text.setTypeface(typeface);

        attribute.recycle();

    }
}

From source file:com.github.pedrovgs.DraggablePanel.java

/**
 * Initialize the xml configuration based on styleable attributes
 *
 * @param attrs to analyze./*from w  w  w  . j  a va 2 s.c o  m*/
 */
private final void initializeAttrs(AttributeSet attrs) {
    TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_panel);
    this.topFragmentHeight = attributes.getDimension(R.styleable.draggable_panel_top_fragment_height,
            DEFAULT_TOP_FRAGMENT_HEIGHT);
    this.xScaleFactor = attributes.getFloat(R.styleable.draggable_panel_x_scale_factor, DEFAULT_SCALE_FACTOR);
    this.yScaleFactor = attributes.getFloat(R.styleable.draggable_panel_y_scale_factor, DEFAULT_SCALE_FACTOR);
    this.topFragmentMarginRight = attributes.getDimension(R.styleable.draggable_panel_top_fragment_margin_right,
            DEFAULT_TOP_FRAGMENT_MARGIN);
    this.topFragmentMarginBottom = attributes
            .getDimension(R.styleable.draggable_panel_top_fragment_margin_bottom, DEFAULT_TOP_FRAGMENT_MARGIN);
    this.enableHorizontalAlphaEffect = attributes.getBoolean(
            R.styleable.draggable_panel_enable_horizontal_alpha_effect, DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT);
    attributes.recycle();
}

From source file:ezy.ui.view.NoticeView.java

private void initWithContext(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NoticeView);
    mIcon = a.getDrawable(R.styleable.NoticeView_nvIcon);
    mIconPadding = (int) a.getDimension(R.styleable.NoticeView_nvIconPadding, 0);

    boolean hasIconTint = a.hasValue(R.styleable.NoticeView_nvIconTint);

    if (hasIconTint) {
        mIconTint = a.getColor(R.styleable.NoticeView_nvIconTint, 0xff999999);
    }/*from w  ww.j  av a  2  s  .co m*/

    mInterval = a.getInteger(R.styleable.NoticeView_nvInterval, 4000);
    mDuration = a.getInteger(R.styleable.NoticeView_nvDuration, 900);

    mDefaultFactory.resolve(a);
    a.recycle();

    if (mIcon != null) {
        mPaddingLeft = getPaddingLeft();
        int realPaddingLeft = mPaddingLeft + mIconPadding + mIcon.getIntrinsicWidth();
        setPadding(realPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());

        if (hasIconTint) {
            mIcon = mIcon.mutate();
            DrawableCompat.setTint(mIcon, mIconTint);
        }
    }
}

From source file:com.github.czy1121.view.CornerLabelView.java

public void init(Context context, AttributeSet attrs) {

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

    mPaddingTop = ta.getDimension(R.styleable.CornerLabelView_clvPaddingTop, dp2px(10));
    mPaddingCenter = ta.getDimension(R.styleable.CornerLabelView_clvPaddingCenter, dp2px(0));
    mPaddingBottom = ta.getDimension(R.styleable.CornerLabelView_clvPaddingBottom, dp2px(3));

    mText1.text = ta.getString(R.styleable.CornerLabelView_clvText1);
    mText1.height = ta.getDimension(R.styleable.CornerLabelView_clvText1Height, dp2px(12));
    mText1.color = ta.getColor(R.styleable.CornerLabelView_clvText1Color, 0xffffffff);
    mText1.init();/*from  w  w  w  .  ja va  2 s .c o m*/
    mText1.reset();

    mText2.text = ta.getString(R.styleable.CornerLabelView_clvText2);
    mText2.height = ta.getDimension(R.styleable.CornerLabelView_clvText2Height, dp2px(8));
    mText2.color = ta.getColor(R.styleable.CornerLabelView_clvText2Color, 0x66ffffff);
    mText2.init();
    mText2.reset();

    int fillColor = ta.getColor(R.styleable.CornerLabelView_clvFillColor, 0x66000000);
    int flags = ta.getInteger(R.styleable.CornerLabelView_clvFlags, 0);

    ta.recycle();

    mIsLeft = (flags & 1) == 0;
    mIsTop = (flags & 2) == 0;
    mIsTriangle = (flags & 4) > 0;

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
    mPaint.setAntiAlias(true);
    mPaint.setColor(fillColor);

}

From source file:com.unovo.frame.uikit.base.title.SimpleBackActivity.java

@SuppressWarnings("all")
private void initContainerViewByAttrs() {
    TypedArray typedArray = getTheme().obtainStyledAttributes(ATTRS);
    boolean visible = typedArray.getBoolean(2, true);
    if (visible) {
        boolean overly = typedArray.getBoolean(0, false);
        // ?toolbar
        int toolBarSize = (int) typedArray.getDimension(1,
                (int) mContext.getResources().getDimension(R.dimen.titlebar_size));

        typedArray.recycle();/*w ww  .ja va  2  s  .c o  m*/
        // ????
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        params.topMargin = overly ? 0 : toolBarSize;

        mContainer.setLayoutParams(params);
    } else {
        mTitleBar.setVisibility(View.GONE);
    }
}

From source file:com.snowpuppet.alert.formclock.FormClockView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FormClockView, defStyleAttr,
            defStyleRes);//  w ww  .java2  s .c om

    // Configure renderers
    mHourMinOptions = new FormClockRenderer.Options();
    mHourMinOptions.textSize = a.getDimension(R.styleable.FormClockView_textSize,
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 55, getResources().getDisplayMetrics()));
    mHourMinOptions.charSpacing = a.getDimension(R.styleable.FormClockView_charSpacing,
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8, getResources().getDisplayMetrics()));
    mHourMinOptions.is24hour = DateFormat.is24HourFormat(context);

    mHourMinOptions.glyphAnimAverageDelay = 500;
    mHourMinOptions.glyphAnimDuration = 2000;

    mSecondsOptions = new FormClockRenderer.Options(mHourMinOptions);
    mSecondsOptions.onlySeconds = true;
    mSecondsOptions.textSize /= 2;
    mSecondsOptions.glyphAnimAverageDelay = 0;
    mSecondsOptions.glyphAnimDuration = 750;

    mColor1 = a.getColor(R.styleable.FormClockView_color1, getColorFromRes(context, R.color.colorAccent));
    mColor2 = a.getColor(R.styleable.FormClockView_color2, getColorFromRes(context, R.color.colorPrimary));
    mColor3 = a.getColor(R.styleable.FormClockView_color3, getColorFromRes(context, R.color.clockColor1));

    a.recycle();

    regenerateRenderers();
}

From source file:com.learn.mobile.customview.henrytao.SmoothCollapsingToolbarLayout.java

protected void init(AttributeSet attrs) {
    setOrientation(HORIZONTAL);//  ww w  .java 2 s . c om
    TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs,
            R.styleable.SmoothCollapsingToolbarLayout, 0, 0);
    try {
        mCollapsedOffsetX = a.getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_collapsed_offsetX, 0);
        mCollapsedOffsetY = a.getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_collapsed_offsetY, 0);
        mCollapsedAvatarSize = a
                .getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_collapsed_avatarSize, -1);
        mCollapsedTitleTextSize = a
                .getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_collapsed_titleTextSize, -1);
        mCollapsedSubTitleTextSize = a
                .getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_collapsed_subtitleTextSize, -1);

        mExpandedOffsetX = a.getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_expanded_offsetX, 0);
        mExpandedOffsetY = a.getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_expanded_offsetY, 0);
        mExpandedAvatarSize = a.getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_expanded_avatarSize,
                -1);
        mExpandedTitleTextSize = a
                .getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_expanded_titleTextSize, -1);
        mExpandedSubtitleTextSize = a
                .getDimension(R.styleable.SmoothCollapsingToolbarLayout_sctl_expanded_subtitleTextSize, -1);

        mAvatarId = a.getResourceId(R.styleable.SmoothCollapsingToolbarLayout_sctl_avatar_id, 0);
        mTitleId = a.getResourceId(R.styleable.SmoothCollapsingToolbarLayout_sctl_title_id, 0);
        mSubtitleId = a.getResourceId(R.styleable.SmoothCollapsingToolbarLayout_sctl_subtitle_id, 0);
    } finally {
        a.recycle();
    }
}

From source file:com.vinaysshenoy.okulus.OkulusImageView.java

/**
 * @param context//from  www  . ja  v a2s .com
 * @param attrs
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
private void init(Context context, AttributeSet attrs) {

    mViewRect = new Rect();
    mCornerRadius = dpToPx(DEFAULT_CORNER_RADIUS);
    float borderWidthInDips = DEFAULT_BORDER_WIDTH;
    mBorderColor = DEFAULT_BORDER_COLOR;
    mFullCircle = DEFAULT_FULL_CIRCLE;
    float shadowWidthInDips = DEFAULT_SHADOW_WIDTH;
    mShadowColor = DEFAULT_SHADOW_COLOR;
    mShadowRadius = DEFAULT_SHADOW_RADIUS;
    mTouchSelectorColor = DEFAULT_TOUCH_SELECTOR_COLOR;
    mTouchSelectorEnabled = DEFAULT_TOUCH_SELECTOR_ENABLED;

    if (attrs != null) {

        TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.OkulusImageView);
        mCornerRadius = styledAttrs.getDimension(R.styleable.OkulusImageView_cornerRadius, mCornerRadius);
        mBorderColor = styledAttrs.getColor(R.styleable.OkulusImageView_borderColor, mBorderColor);
        mFullCircle = styledAttrs.getBoolean(R.styleable.OkulusImageView_fullCircle, mFullCircle);
        mShadowColor = styledAttrs.getColor(R.styleable.OkulusImageView_shadowColor, mShadowColor);
        mShadowRadius = styledAttrs.getFloat(R.styleable.OkulusImageView_shadowRadius, mShadowRadius);
        mTouchSelectorColor = styledAttrs.getColor(R.styleable.OkulusImageView_touchSelectorColor,
                mTouchSelectorColor);
        mTouchSelectorEnabled = styledAttrs.getBoolean(R.styleable.OkulusImageView_touchSelectorEnabled,
                mTouchSelectorEnabled);

        float dimension = styledAttrs.getDimension(R.styleable.OkulusImageView_borderWidth, borderWidthInDips);
        borderWidthInDips = pxToDp(dimension);
        dimension = styledAttrs.getDimension(R.styleable.OkulusImageView_shadowWidth, shadowWidthInDips);
        shadowWidthInDips = pxToDp(dimension);

        styledAttrs.recycle();
    }

    clampBorderAndShadowWidths(borderWidthInDips, shadowWidthInDips);
    mBorderWidth = dpToPx(borderWidthInDips);
    mShadowWidth = dpToPx(shadowWidthInDips);

    if (mShadowWidth > 0f) {

        if (Build.VERSION.SDK_INT >= 14) {
            /* We need to set layer type for shadows to work
             * on ICS and above
             */
            setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
    }
    setOkulusDrawable(null);

}