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.runmit.sweedee.view.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from   w w w .  j  a  v a  2s .  com*/

    final Resources res = getResources();
    defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    defaultCommonColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    a.recycle();
    mColorEvaluator = new ArgbEvaluator();
}

From source file:com.lovejjfg.arsenal.ui.widget.JumpBall.java

public JumpBall(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.JumpBall, defStyleAttr, 0);
    mCircleRadius = a.getDimension(R.styleable.JumpBall_ballRadius,
            getResources().getDisplayMetrics().density * 20);
    initData();//from   ww w  .ja v a 2s  .  c o m
    a.recycle();
    init();
}

From source file:ru.tinkoff.acquiring.sdk.views.KeyView.java

private void applyAttrs(AttributeSet attrs) {
    if (attrs == null) {
        return;/*from ww  w. j a  va2 s  .co m*/
    }

    final TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.KeyView, 0, 0);

    try {
        keyCode = a.getInt(R.styleable.KeyView_keyCode, -1);

        final float textSize = a.getDimension(R.styleable.KeyView_keyTextSize, -1.F);
        if (textSize != -1.F) {
            contentPaint.setTextSize(dpToPx(textSize));
        }

        final String fontFamily = a.getString(R.styleable.KeyView_keyTextFontFamily);
        if (fontFamily != null) {
            contentPaint.setTypeface(Typeface.create(fontFamily, Typeface.NORMAL));
        }

        contentText = a.getString(R.styleable.KeyView_keyText);
        if (contentText != null) {
            textWidth = contentPaint.measureText(contentText);
        }

        final int imageDrawableId = a.getResourceId(R.styleable.KeyView_keyImage, -1);
        if (imageDrawableId != -1) {
            contentImage = BitmapFactory.decodeResource(getResources(), imageDrawableId);
        }

        final int textColor = a.getColor(R.styleable.KeyView_keyTextColor, contentPaint.getColor());
        contentPaint.setColor(textColor);

        final int circleColor = a.getColor(R.styleable.KeyView_keyCircleColor, circlePaint.getColor());
        circlePaint.setColor(circleColor);
    } finally {
        a.recycle();
    }
}

From source file:io.imoji.sdk.grid.ui.ResultView.java

private int getDimension(int position) {
    Resources res = getResources();
    TypedArray dimensions = res.obtainTypedArray(
            viewSize == LARGE ? R.array.search_result_large_dimens : R.array.search_result_small_dimens);
    int dimension = (int) dimensions.getDimension(position, 0f);
    dimensions.recycle();//from   www .jav a  2  s.com
    return dimension;
}

From source file:com.freegeek.android.materialbanner.MaterialBanner.java

private void init(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialBanner);
    mIndicatorMargin = (int) a.getDimension(R.styleable.MaterialBanner_indicatorMargin, dip2Pix(context, 10));
    mIndicatorGravity = IndicatorGravity.valueOf(a.getInt(R.styleable.MaterialBanner_indicatorGravity, 0));
    mIndicatorInside = a.getBoolean(R.styleable.MaterialBanner_indicatorInside, true);
    mMatch = a.getBoolean(R.styleable.MaterialBanner_match, false);
    a.recycle();/*from  ww w.j a  v a2 s  .co  m*/

    View view = LayoutInflater.from(context).inflate(R.layout.material_banner, this, true);

    mCardView = (CardView) view.findViewById(R.id.card_view);
    mViewPager = (MaterialViewPager) view.findViewById(R.id.view_pager);
    mCardContainer = (FrameLayout) view.findViewById(R.id.container);
    mCardContainer = (FrameLayout) view.findViewById(R.id.card_container);
    mIndicatorContainer = (FrameLayout) view.findViewById(R.id.indicator_container);

    mIndicatorParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    mIndicatorParams.gravity = Gravity.CENTER;

    mCardParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    mCardParams.gravity = Gravity.TOP;

    //set Z value. bring indicator view to front,view.bringToFront does't work on 6.0
    ViewCompat.setZ(mCardView, 1);
    ViewCompat.setZ(mViewPager, 2);

    ViewCompat.setZ(mCardContainer, 1);
    ViewCompat.setZ(mIndicatorContainer, 2);

    updateMargin();
    setMatch(mMatch);
    adSwitchTask = new AdSwitchTask(this);

}

From source file:com.yahoo.mobile.client.android.yodel.ui.PostListFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (mTagQuery == null) {
        mPostListAdapter = new PostListAdapter(getActivity());
        setListAdapter(mPostListAdapter);
    } else {/*w  w w . j a  v  a  2  s . c om*/
        View footer = getActivity().getLayoutInflater().inflate(R.layout.view_more_web_footer, getListView(),
                false);
        mPostSearchListAdapter = new PostSearchListAdapter(getActivity());
        getListView().addFooterView(footer);
        setListAdapter(mPostSearchListAdapter);
    }

    // If blog post list wasn't persisted during config change or is just empty...
    if (mBlogPostList == null || mBlogPostList.size() > 0) {
        refreshPosts();
    }

    /*
    Account for the overlay Toolbar. Warning: makes it hard to re-use this fragment
    (which is the whole point of fragments, isn't it?)
    */
    final TypedArray styledAttributes = getActivity().getTheme()
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    int actionBarSize = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();
    int mediumViewMargin = getResources().getDimensionPixelSize(R.dimen.view_margin_medium);
    int lvTopPadding = mediumViewMargin + actionBarSize;
    getListView().setPadding(0, lvTopPadding, 0, mediumViewMargin);
    mSwipeView.setProgressViewOffset(true, mediumViewMargin, lvTopPadding);
}

From source file:com.umeitime.common.views.ScrollableLayout.java

private void init(Context context, AttributeSet attrs) {
    float scale = context.getResources().getDisplayMetrics().density;
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    // ???/*w  ww  . java2 s  .c o  m*/
    int statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    TypedArray actionbarSizeTypedArray = context
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    float actionbarHeight = actionbarSizeTypedArray.getDimension(0, 0);
    headerDistance = actionbarHeight + statusBarHeight;
    mHelper = new ScrollableHelper();
    mScroller = new Scroller(context);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.telenav.expandablepager.ExpandablePager.java

public ExpandablePager(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();//  www.jav  a  2 s.c  o m
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ExpandablePager, 0, 0);
    setAnimationDuration(a.getInt(R.styleable.ExpandablePager_animation_duration, 200));
    collapsedHeight = (int) a.getDimension(R.styleable.ExpandablePager_collapsed_height,
            80 * getResources().getDisplayMetrics().density);
    a.recycle();
}

From source file:com.github.ppamorim.cult.CultView.java

/**
 * Initialize some attributes to provide
 * the height, padding and content to CultView
 *//*from ww w  .j  a v a 2  s  . co  m*/
private void getStyle(Context context, AttributeSet attrs, int defStyleAttr) {
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.cult_view, defStyleAttr, 0);
        toolbarHeight = (int) a.getDimension(R.styleable.cult_view_toolbar_height, DEFAULT_HEIGHT);
        innerPadding = (int) a.getDimension(R.styleable.cult_view_inner_padding, DEFAULT_PADDING);
        contentResId = a.getResourceId(R.styleable.cult_view_content_view, 0);
        a.recycle();
    }
}

From source file:com.github.rubensousa.stackview.StackView.java

public StackView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mViews = new ArrayList<>();
    mRandom = new Random();
    mHardwareAccelerationEnabled = true;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StackView, 0, 0);
    mSize = a.getInteger(R.styleable.StackView_stackview_size, 4);
    mHorizontalSpacing = a.getDimension(R.styleable.StackView_stackview_horizontalSpacing, 0f);
    mVerticalSpacing = a.getDimension(R.styleable.StackView_stackview_verticalSpacing, VERTICAL_SPACING);
    mElevationSpacing = a.getDimension(R.styleable.StackView_stackview_elevationSpacing, ELEVATION_SPACING);
    mItemMaxRotation = a.getInteger(R.styleable.StackView_stackview_rotationRandomMagnitude, 0);
    mScaleXFactor = a.getFloat(R.styleable.StackView_stackview_horizontalScalingFactor, SCALE_X_FACTOR);

    if (mScaleXFactor < 0 || mScaleXFactor > 1) {
        throw new IllegalArgumentException(
                "horizontalScalingFactor must be greater than 0" + "and less than 1");
    }/*from w w w  .j  av  a2 s .  com*/

    mCyclicLooping = a.getBoolean(R.styleable.StackView_stackview_cyclicLooping, false);
    mLayout = a.getResourceId(R.styleable.StackView_stackview_adapterLayout, 0);
    mAnimator = new StackDefaultAnimator();
    mAnimator.setStackView(this);
    mAnimator.setStackAnimationListener(this);
    a.recycle();

    setClipToPadding(false);
    setClipChildren(false);

    if (isInEditMode()) {
        addViews();
    }

}