Example usage for android.content Context obtainStyledAttributes

List of usage examples for android.content Context obtainStyledAttributes

Introduction

In this page you can find the example usage for android.content Context obtainStyledAttributes.

Prototype

public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java

public PagerGradientTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    density = getResources().getDisplayMetrics().density;
    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    textSize = a.getDimensionPixelSize(0, (int) (16 * density));
    textColorSelected = a.getColor(1, Color.BLACK);
    textColorNormal = Color.argb(Color.alpha(0x80000000), Color.red(textColorSelected),
            Color.green(textColorSelected), Color.blue(textColorSelected));
    a.recycle();//from  w  w w .j  ava2s .  c  om
    mTextPaint.setAntiAlias(true);

    intervalWidth = (int) (0 * density);
    indicatorPadding = (int) (10 * density);
    indicatorHeight = (int) (3 * density);
    underLineHeight = (int) (2 * density);
}

From source file:com.achenging.view.SlidingTabLayout.java

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

    mTabStrip = new SlidingTabStrip(context);
    int defaultBackgroundColor = mTabStrip.getSolidColor();

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(true);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//  www.  j  a v  a  2s  .  c o  m
    //?
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);

    //
    mTabSelectedTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabSelectedTextColor, 0);
    mTabTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabTextColor, 0);

    //
    int selectedIndicatorThickness = (int) typedArray.getDimension(
            R.styleable.SlidingTabLayout_tabIndicatorThickness, SELECTED_INDICATOR_THICKNESS_DIPS);
    //
    int tabIndicatorColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabIndicatorColor,
            DEFAULT_SELECTED_INDICATOR_COLOR);

    //tab
    int tabDividerThickness = (int) typedArray.getDimension(R.styleable.SlidingTabLayout_dividerThickness,
            DEFAULT_DIVIDER_THICKNESS_DIPS);
    //tab
    int tabDividerColor = typedArray.getColor(R.styleable.SlidingTabLayout_dividerColor,
            defaultBackgroundColor);

    //tab??
    int tabBottomBorderThickness = (int) typedArray.getDimension(
            R.styleable.SlidingTabLayout_bottomBorderThickness, DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS);
    int tabBottomBorderColor = typedArray.getColor(R.styleable.SlidingTabLayout_bottomBorderColor,
            defaultBackgroundColor);

    //?tab?
    boolean showAsDivider = typedArray.getBoolean(R.styleable.SlidingTabLayout_showAsDivider, false);

    typedArray.recycle();
    //

    //        mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTextPadding = (int) (DEFAULT_TEXT_PADDING * getResources().getDisplayMetrics().density);

    //
    setSelectedTitleColors(mTabSelectedTextColor);
    setUnSelectedTitleColors(mTabTextColor);
    setDividerColors(tabDividerColor);
    setSelectedIndicatorColors(tabIndicatorColor);
    setTabBottomBorderColor(tabBottomBorderColor);
    setTabDividerColor(tabDividerColor);
    //
    setSelectedIndicatorThickness(selectedIndicatorThickness);
    setTabBottomBorderThickness(tabBottomBorderThickness);
    setTabDividerThickness(tabDividerThickness);
    setShowAsDivider(showAsDivider);
    setShowTabDivider(false);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    addView(mTabStrip);
}

From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java

/**
 * Default constructor for inflating ViewPagerBottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//  w w w  . j  a va 2 s  .co  m
 * @param attrs   The {@link AttributeSet}.
 */
public ViewPagerBottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    scrollableViews = new ArrayList<>();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
    setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java

private void initAttributes(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ImageCoverFlowView);

    int totalVisibleChildren = a.getInt(R.styleable.ImageCoverFlowView_visibleImage, 2);

    if (totalVisibleChildren % 2 == 0) {
        throw new IllegalArgumentException("visible image must be an odd number");
    }/*from w ww  .  jav  a 2  s .c  o m*/

    VISIBLE_VIEWS = totalVisibleChildren >> 1;

    reflectHeightFraction = a.getFraction(R.styleable.ImageCoverFlowView_reflectionHeight, 100, 0, 0.0f);
    if (reflectHeightFraction > 100) {
        reflectHeightFraction = 100;
    }
    reflectHeightFraction /= 100;
    reflectGap = a.getDimensionPixelSize(R.styleable.ImageCoverFlowView_reflectionGap, 0);

    mGravity = CoverFlowGravity.values()[a.getInt(R.styleable.ImageCoverFlowView_coverflowGravity,
            CoverFlowGravity.CENTER_VERTICAL.ordinal())];

    mLayoutMode = CoverFlowLayoutMode.values()[a.getInt(R.styleable.ImageCoverFlowView_coverflowLayoutMode,
            CoverFlowLayoutMode.WRAP_CONTENT.ordinal())];

    a.recycle();
}

From source file:bhav.swipeaction.SwipeAction.java

private void initStyle(Context context, AttributeSet attrs) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeAction);
    if (a != null) {
        if (a.hasValue(R.styleable.SwipeAction_src)) {
            icon = a.getDrawable(R.styleable.SwipeAction_src);
        } else {//from  w w w .java  2s. c  o m
            //default back to available icon
            icon = getResources().getDrawable(android.R.drawable.ic_delete);
        }
        iconPaddingBottom = Math
                .round(a.getDimension(R.styleable.SwipeAction_iconPaddingBottom, DEF_PADDING_BOTTOM));
        iconPaddingTop = Math.round(a.getDimension(R.styleable.SwipeAction_iconPaddingTop, DEF_PADDING_TOP));
        iconPaddingLeft = Math
                .round(a.getDimension(R.styleable.SwipeAction_iconPaddingLeft, DEF_PADDING_START));
        iconPaddingRight = Math
                .round(a.getDimension(R.styleable.SwipeAction_iconPaddingRight, DEF_PADDING_END));
        a.recycle();
    }
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

private void initAttributes(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ImageCoverFlowView);

    int totalVisibleChildren = a.getInt(R.styleable.ImageCoverFlowView_visibleImage, 3);
    setVisibleImage(totalVisibleChildren);

    reflectHeightFraction = a.getFraction(R.styleable.ImageCoverFlowView_reflectionHeight, 100, 0, 0.0f);
    if (reflectHeightFraction > 100) {
        reflectHeightFraction = 100;//from ww w  .ja v  a 2 s . c om
    }
    reflectHeightFraction /= 100;
    reflectGap = a.getDimensionPixelSize(R.styleable.ImageCoverFlowView_reflectionGap, 0);

    mGravity = CoverFlowGravity.values()[a.getInt(R.styleable.ImageCoverFlowView_coverflowGravity,
            CoverFlowGravity.CENTER_VERTICAL.ordinal())];

    mLayoutMode = CoverFlowLayoutMode.values()[a.getInt(R.styleable.ImageCoverFlowView_coverflowLayoutMode,
            CoverFlowLayoutMode.WRAP_CONTENT.ordinal())];

    a.recycle();
}

From source file:com.aiga.events.android.views.NoScrollSwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * /*from w  w w  . j  ava 2  s .c o  m*/
 * @param context
 * @param attrs
 */
public NoScrollSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mProgressBar = new SwipeProgressBar(this);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();
}

From source file:android.support.design.widget.SheetBehavior.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}./*from w w  w  .j ava2 s.c  om*/
 * @param attrs   The {@link AttributeSet}.
 */
public SheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SheetBehavior);
    setPeekHeight(a.getDimensionPixelSize(R.styleable.SheetBehavior_peekHeight, 0));
    setHideable(a.getBoolean(R.styleable.SheetBehavior_hiddenEnable, false));
    mSlideModel = a.getInt(R.styleable.SheetBehavior_slideMode, BOTTOM_SHEET);
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * @param context//from  w ww.  ja  v a  2 s. c o  m
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mProgressBar = new SwipeProgressBar(this);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();
}

From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from ww  w .ja v  a  2  s.com
 * @param attrs
 */
public OldSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mProgressBar = new SwipeProgressBar(this);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();
}