Example usage for android.content.res TypedArray getDimensionPixelSize

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

Introduction

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

Prototype

public int getDimensionPixelSize(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index for use as a size in raw pixels.

Usage

From source file:com.ickphum.android.isoview.InteractiveLineGraphView.java

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

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.InteractiveLineGraphView,
            defStyle, defStyle);/*from   w w  w. j  a  v  a  2  s .co  m*/

    try {
        mLabelTextColor = a.getColor(R.styleable.InteractiveLineGraphView_labelTextColor, mLabelTextColor);
        mLabelTextSize = a.getDimension(R.styleable.InteractiveLineGraphView_labelTextSize, mLabelTextSize);
        mLabelSeparation = a.getDimensionPixelSize(R.styleable.InteractiveLineGraphView_labelSeparation,
                mLabelSeparation);

        mGridThickness = a.getDimension(R.styleable.InteractiveLineGraphView_gridThickness, mGridThickness);
        mGridColor = a.getColor(R.styleable.InteractiveLineGraphView_gridColor, mGridColor);

        mAxisThickness = a.getDimension(R.styleable.InteractiveLineGraphView_axisThickness, mAxisThickness);
        mAxisColor = a.getColor(R.styleable.InteractiveLineGraphView_axisColor, mAxisColor);

        mDataThickness = a.getDimension(R.styleable.InteractiveLineGraphView_dataThickness, mDataThickness);
        mDataColor = a.getColor(R.styleable.InteractiveLineGraphView_dataColor, mDataColor);
    } finally {
        a.recycle();
    }

    initPaints();

    // Sets up interactions
    if (!this.isInEditMode()) {
        mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener);
        mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
    }

    mScroller = new OverScroller(context);
    mZoomer = new Zoomer(context);

    // Sets up edge effects
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);
}

From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java

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

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.InteractiveLineGraphView,
            defStyle, defStyle);//from ww w.j  a  va  2s  .c  o m

    try {
        mLabelTextColor = a.getColor(R.styleable.InteractiveLineGraphView_labelTextColor, mLabelTextColor);
        mLabelTextSize = a.getDimension(R.styleable.InteractiveLineGraphView_labelTextSize, mLabelTextSize);
        mLabelSeparation = a.getDimensionPixelSize(R.styleable.InteractiveLineGraphView_labelSeparation,
                mLabelSeparation);

        mGridThickness = a.getDimension(R.styleable.InteractiveLineGraphView_gridThickness, mGridThickness);
        mGridColor = a.getColor(R.styleable.InteractiveLineGraphView_gridColor, mGridColor);

        mAxisThickness = a.getDimension(R.styleable.InteractiveLineGraphView_axisThickness, mAxisThickness);
        mAxisColor = a.getColor(R.styleable.InteractiveLineGraphView_axisColor, mAxisColor);

        mDataThickness = a.getDimension(R.styleable.InteractiveLineGraphView_dataThickness, mDataThickness);
        mDataColor = a.getColor(R.styleable.InteractiveLineGraphView_dataColor, mDataColor);
    } finally {
        a.recycle();
    }

    initPaints();

    // Sets up interactions
    mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener);
    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);

    mScroller = new OverScroller(context);
    mZoomer = new Zoomer(context);

    // Sets up edge effects
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);
}

From source file:com.akshay.protocol10.asplayer.widget.SlidingUpPanelLayout.java

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

    if (isInEditMode()) {
        mShadowDrawable = null;// w  w  w  . j  a v  a 2 s .co m
        mDragHelper = null;
        return;
    }

    if (attrs != null) {
        TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS);

        if (defAttrs != null) {
            int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY);
            if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) {
                throw new IllegalArgumentException("gravity must be set to either top or bottom");
            }
            mIsSlidingUp = gravity == Gravity.BOTTOM;
        }

        defAttrs.recycle();

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

        if (ta != null) {
            mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_panelHeight, -1);
            mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_shadowHeight, -1);
            mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_paralaxOffset, -1);

            mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_flingVelocity,
                    DEFAULT_MIN_FLING_VELOCITY);
            mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_fadeColor, DEFAULT_FADE_COLOR);

            mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_dragView, -1);

            mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_overlay, DEFAULT_OVERLAY_FLAG);

            mAnchorPoint = ta.getFloat(R.styleable.SlidingUpPanelLayout_anchorPoint, DEFAULT_ANCHOR_POINT);

            mSlideState = SlideState.values()[ta.getInt(R.styleable.SlidingUpPanelLayout_initialState,
                    DEFAULT_SLIDE_STATE.ordinal())];
        }

        ta.recycle();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    if (mPanelHeight == -1) {
        mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f);
    }
    if (mShadowHeight == -1) {
        mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f);
    }
    if (mParallaxOffset == -1) {
        mParallaxOffset = (int) (DEFAULT_PARALAX_OFFSET * density);
    }
    // If the shadow height is zero, don't show the shadow
    if (mShadowHeight > 0) {
        if (mIsSlidingUp) {
            mShadowDrawable = getResources().getDrawable(R.drawable.above_shadow);
        } else {
            mShadowDrawable = getResources().getDrawable(R.drawable.below_shadow);
        }

    } else {
        mShadowDrawable = null;
    }

    setWillNotDraw(false);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(mMinFlingVelocity * density);

    mIsSlidingEnabled = true;
}

From source file:com.google.android.apps.gutenberg.widget.TabLayout.java

public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Set us to fill the View port
    setFillViewport(true);/*from w  w w  .j  a  v  a  2 s .com*/

    // Add the TabStrip
    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr,
            R.style.Widget_Design_TabLayout);

    mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(R.styleable.TabLayout_tabIndicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.TabLayout_tabIndicatorColor, 0));

    mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance,
            R.style.TextAppearance_Design_Tab);

    mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
            .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0);
    mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart);
    mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop);
    mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd);
    mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom);

    if (a.hasValue(R.styleable.TabLayout_tabSelectedTextColor)) {
        mTabSelectedTextColor = a.getColor(R.styleable.TabLayout_tabSelectedTextColor, 0);
        mTabSelectedTextColorSet = true;
    }

    mTabMinWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, 0);
    mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMaxWidth, 0);
    mTabBackgroundResId = a.getResourceId(R.styleable.TabLayout_tabBackground, 0);
    mContentInsetStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabContentStart, 0);
    mMode = a.getInt(R.styleable.TabLayout_tabMode, MODE_FIXED);
    mTabGravity = a.getInt(R.styleable.TabLayout_tabGravity, GRAVITY_FILL);
    a.recycle();

    // Now apply the tab mode and gravity
    applyModeAndGravity();
}

From source file:android.support.v7.widget.SwitchCompat.java

/**
 * Sets the switch text color, size, style, hint color, and highlight color
 * from the specified TextAppearance resource.
 *///w  ww.  j  av a  2s  . c  o  m
public void setSwitchTextAppearance(Context context, int resid) {
    TypedArray appearance = context.obtainStyledAttributes(resid, R.styleable.TextAppearance);

    ColorStateList colors;
    int ts;

    colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColor);
    if (colors != null) {
        mTextColors = colors;
    } else {
        // If no color set in TextAppearance, default to the view's textColor
        mTextColors = getTextColors();
    }

    ts = appearance.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0);
    if (ts != 0) {
        if (ts != mTextPaint.getTextSize()) {
            mTextPaint.setTextSize(ts);
            requestLayout();
        }
    }

    int typefaceIndex, styleIndex;
    typefaceIndex = appearance.getInt(R.styleable.TextAppearance_android_typeface, -1);
    styleIndex = appearance.getInt(R.styleable.TextAppearance_android_textStyle, -1);

    setSwitchTypefaceByIndex(typefaceIndex, styleIndex);

    boolean allCaps = appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false);
    if (allCaps) {
        mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext());
    } else {
        mSwitchTransformationMethod = null;
    }

    appearance.recycle();
}

From source file:com.devbrackets.android.recyclerext.widget.FastScroll.java

/**
 * Retrieves the xml attributes associated with the popup bubble.
 * This includes the drawable, tint color, alignment, font options, etc.
 *
 * @param typedArray The array of attributes to use
 *///  w  w  w  .j  a  v  a2s  . co m
protected void retrieveBubbleAttributes(@NonNull TypedArray typedArray) {
    showBubble = typedArray.getBoolean(R.styleable.FastScroll_re_show_bubble, true);
    bubbleAlignment = BubbleAlignment.get(typedArray.getInt(R.styleable.FastScroll_re_bubble_alignment, 3));

    int textColor = getColor(R.color.recyclerext_fast_scroll_bubble_text_color_default);
    textColor = typedArray.getColor(R.styleable.FastScroll_re_bubble_text_color, textColor);

    int textSize = getResources()
            .getDimensionPixelSize(R.dimen.recyclerext_fast_scroll_bubble_text_size_default);
    textSize = typedArray.getDimensionPixelSize(R.styleable.FastScroll_re_bubble_text_size, textSize);

    Drawable backgroundDrawable = getDrawable(typedArray, R.styleable.FastScroll_re_bubble_background);
    int backgroundColor = getColor(R.color.recyclerext_fast_scroll_bubble_color_default);
    backgroundColor = typedArray.getColor(R.styleable.FastScroll_re_bubble_color, backgroundColor);

    if (backgroundDrawable == null) {
        backgroundDrawable = tint(getDrawable(R.drawable.recyclerext_fast_scroll_bubble), backgroundColor);
    }

    bubble.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    bubble.setTextColor(textColor);
    bubble.setBackground(backgroundDrawable);
}

From source file:co.codecrunch.musicplayerlite.slidinguppanelhelper.SlidingUpPanelLayout.java

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

    if (isInEditMode()) {
        mShadowDrawable = null;/*from   w ww  .  j  a va  2 s  . c  o m*/
        mDragHelper = null;
        return;
    }

    if (attrs != null) {
        TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS);

        if (defAttrs != null) {
            int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY);
            setGravity(gravity);
        }

        defAttrs.recycle();

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

        if (ta != null) {
            mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoPanelHeight, -1);
            mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoShadowHeight, -1);
            mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoParalaxOffset, -1);

            mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_umanoFlingVelocity,
                    DEFAULT_MIN_FLING_VELOCITY);
            mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_umanoFadeColor,
                    DEFAULT_FADE_COLOR);

            mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_umanoDragView, -1);

            mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoOverlay,
                    DEFAULT_OVERLAY_FLAG);
            mClipPanel = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoClipPanel,
                    DEFAULT_CLIP_PANEL_FLAG);

            mAnchorPoint = ta.getFloat(R.styleable.SlidingUpPanelLayout_umanoAnchorPoint, DEFAULT_ANCHOR_POINT);

            mSlideState = PanelState.values()[ta.getInt(R.styleable.SlidingUpPanelLayout_umanoInitialState,
                    DEFAULT_SLIDE_STATE.ordinal())];
        }

        ta.recycle();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    if (mPanelHeight == -1) {
        mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f);
    }
    if (mShadowHeight == -1) {
        mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f);
    }
    if (mParallaxOffset == -1) {
        mParallaxOffset = (int) (DEFAULT_PARALAX_OFFSET * density);
    }
    // If the shadow height is zero, don't show the shadow
    if (mShadowHeight > 0) {
        if (mIsSlidingUp) {
            mShadowDrawable = getResources().getDrawable(R.drawable.above_shadow);
        } else {
            mShadowDrawable = getResources().getDrawable(R.drawable.below_shadow);
        }

    } else {
        mShadowDrawable = null;
    }

    setWillNotDraw(false);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(mMinFlingVelocity * density);

    mIsTouchEnabled = true;
}

From source file:android.support.v7.app.WindowDecorActionBar.java

private void init(View decor) {
    mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(R.id.decor_content_parent);
    if (mOverlayLayout != null) {
        mOverlayLayout.setActionBarVisibilityCallback(this);
    }/*from  w  w  w  .  j ava  2s  .  co  m*/
    mDecorToolbar = getDecorToolbar(decor.findViewById(R.id.action_bar));
    mContextView = (ActionBarContextView) decor.findViewById(R.id.action_context_bar);
    mContainerView = (ActionBarContainer) decor.findViewById(R.id.action_bar_container);

    if (mDecorToolbar == null || mContextView == null || mContainerView == null) {
        throw new IllegalStateException(
                getClass().getSimpleName() + " can only be used " + "with a compatible window decor layout");
    }

    mContext = mDecorToolbar.getContext();

    // This was initially read from the action bar style
    final int current = mDecorToolbar.getDisplayOptions();
    final boolean homeAsUp = (current & DISPLAY_HOME_AS_UP) != 0;
    if (homeAsUp) {
        mDisplayHomeAsUpSet = true;
    }

    ActionBarPolicy abp = ActionBarPolicy.get(mContext);
    setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
    setHasEmbeddedTabs(abp.hasEmbeddedTabs());

    final TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar, R.attr.actionBarStyle, 0);
    if (a.getBoolean(R.styleable.ActionBar_hideOnContentScroll, false)) {
        setHideOnContentScrollEnabled(true);
    }
    final int elevation = a.getDimensionPixelSize(R.styleable.ActionBar_elevation, 0);
    if (elevation != 0) {
        setElevation(elevation);
    }
    a.recycle();
}

From source file:android.support.v7ox.app.WindowDecorActionBar.java

private void init(View decor) {
    mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(R.id.decor_content_parent);
    if (mOverlayLayout != null) {
        mOverlayLayout.setActionBarVisibilityCallback(this);
    }//from w w w . j a v  a2 s .c  o  m
    mDecorToolbar = getDecorToolbar(decor.findViewById(R.id.action_bar));
    mContextView = (ActionBarContextView) decor.findViewById(R.id.action_context_bar);
    mContainerView = (ActionBarContainer) decor.findViewById(R.id.action_bar_container);

    if (mDecorToolbar == null || mContextView == null || mContainerView == null) {
        throw new IllegalStateException(
                getClass().getSimpleName() + " can only be used " + "with a compatible window decor layout");
    }

    mContext = mDecorToolbar.getContext();

    // This was initially read from the action bar style
    final int current = mDecorToolbar.getDisplayOptions();
    final boolean homeAsUp = (current & DISPLAY_HOME_AS_UP) != 0;
    if (homeAsUp) {
        mDisplayHomeAsUpSet = true;
    }

    ActionBarPolicy abp = ActionBarPolicy.get(mContext);
    setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
    setHasEmbeddedTabs(abp.hasEmbeddedTabs());

    final TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar, R.attr.actionBarStyle_ox,
            0);
    if (a.getBoolean(R.styleable.ActionBar_hideOnContentScroll, false)) {
        setHideOnContentScrollEnabled(true);
    }
    final int elevation = a.getDimensionPixelSize(R.styleable.ActionBar_elevation, 0);
    if (elevation != 0) {
        setElevation(elevation);
    }
    a.recycle();
}

From source file:android.support.v7.internal.app.WindowDecorActionBar.java

private void init(View decor) {
    mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(R.id.decor_content_parent);
    if (mOverlayLayout != null) {
        mOverlayLayout.setActionBarVisibilityCallback(this);
    }/*from w ww .ja v  a  2s . com*/
    mDecorToolbar = getDecorToolbar(decor.findViewById(R.id.action_bar));
    mContextView = (ActionBarContextView) decor.findViewById(R.id.action_context_bar);
    mContainerView = (ActionBarContainer) decor.findViewById(R.id.action_bar_container);

    mSplitView = (ActionBarContainer) decor.findViewById(R.id.split_action_bar);

    if (mDecorToolbar == null || mContextView == null || mContainerView == null) {
        throw new IllegalStateException(
                getClass().getSimpleName() + " can only be used " + "with a compatible window decor layout");
    }

    mContext = mDecorToolbar.getContext();
    mContextDisplayMode = mDecorToolbar.isSplit() ? CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL;

    // This was initially read from the action bar style
    final int current = mDecorToolbar.getDisplayOptions();
    final boolean homeAsUp = (current & DISPLAY_HOME_AS_UP) != 0;
    if (homeAsUp) {
        mDisplayHomeAsUpSet = true;
    }

    ActionBarPolicy abp = ActionBarPolicy.get(mContext);
    setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
    setHasEmbeddedTabs(abp.hasEmbeddedTabs());

    final TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar, R.attr.actionBarStyle, 0);
    if (a.getBoolean(R.styleable.ActionBar_hideOnContentScroll, false)) {
        setHideOnContentScrollEnabled(true);
    }
    final int elevation = a.getDimensionPixelSize(R.styleable.ActionBar_elevation, 0);
    if (elevation != 0) {
        setElevation(elevation);
    }
    a.recycle();
}