Example usage for android.content.res TypedArray getIndex

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

Introduction

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

Prototype

public int getIndex(int at) 

Source Link

Document

Returns an index in the array that has data.

Usage

From source file:com.facebook.litho.widget.HorizontalScrollSpec.java

@OnLoadStyle
static void onLoadStyle(ComponentContext c, Output<Boolean> scrollbarEnabled) {

    final TypedArray a = c.obtainStyledAttributes(R.styleable.HorizontalScroll, 0);

    for (int i = 0, size = a.getIndexCount(); i < size; i++) {
        final int attr = a.getIndex(i);

        if (attr == R.styleable.HorizontalScroll_android_scrollbars) {
            scrollbarEnabled.set(a.getInt(attr, 0) != 0);
        }/*w  ww .j  a v  a  2 s .  com*/
    }

    a.recycle();
}

From source file:org.xbmc.kore.utils.UIUtils.java

/**
 * Sets play/pause button icon on a ImageView, based on speed
 * @param context Activity/*from w  w w .  ja  v a  2  s  .  c  om*/
 * @param view ImageView/ImageButton
 * @param speed Current player speed
 */
public static void setPlayPauseButtonIcon(Context context, ImageView view, int speed) {

    if (!playPauseIconsLoaded) {
        TypedArray styledAttributes = context
                .obtainStyledAttributes(new int[] { R.attr.iconPause, R.attr.iconPlay });
        iconPauseResId = styledAttributes.getResourceId(styledAttributes.getIndex(0),
                R.drawable.ic_pause_white_24dp);
        iconPlayResId = styledAttributes.getResourceId(styledAttributes.getIndex(1),
                R.drawable.ic_play_arrow_white_24dp);
        styledAttributes.recycle();
        playPauseIconsLoaded = true;
    }

    view.setImageResource((speed == 1) ? iconPauseResId : iconPlayResId);
}

From source file:io.mattcarroll.hover.defaulthovermenu.toolbar.ToolbarNavigatorContent.java

private Drawable createBackArrowDrawable() {
    // Load the desired back-arrow color from the theme that we're using.
    int[] attrIds = new int[] { R.attr.colorControlNormal };
    TypedArray attrs = getContext().obtainStyledAttributes(attrIds);
    int backArrowColor = attrs.getColor(attrs.getIndex(0), 0xFF000000);
    attrs.recycle();//from   www .j a  va2 s  . c  o m

    // Apply the desired color to the back-arrow icon and return it.
    Drawable backArrowDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow_back);
    backArrowDrawable.setColorFilter(backArrowColor, PorterDuff.Mode.SRC_ATOP);
    return backArrowDrawable;
}

From source file:com.ruesga.rview.widget.ExpandableViewLayout.java

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

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.ExpandableViewLayout, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.ExpandableViewLayout_maxHeight:
            mMaxHeight = a.getDimensionPixelSize(attr, mMaxHeight);
            break;

        case R.styleable.ExpandableViewLayout_expanded:
            mExpanded = a.getBoolean(attr, false);
            break;
        }/*from  w w w . jav  a 2  s.c  om*/
    }
    a.recycle();
}

From source file:com.ruesga.rview.widget.ScoreLabelsView.java

public ScoreLabelsView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mInflater = LayoutInflater.from(context);

    mApprovedColor = ContextCompat.getColorStateList(getContext(), R.color.approved);
    mRejectedColor = ContextCompat.getColorStateList(getContext(), R.color.rejected);
    mNoScoreColor = ContextCompat.getColorStateList(getContext(), R.color.noscore);

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.ScoreLabelsView, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.ScoreLabelsView_shortLabels:
            mIsShortLabels = a.getBoolean(attr, false);
            break;
        }//from w ww  . j  a va  2  s . c  om
    }
    a.recycle();
}

From source file:ch.bretscherhochstrasser.android.stickyviewpager.StickyViewPager.java

private void readAttributes(final Context context, final AttributeSet attrs) {
    final TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.StickyViewPager);

    for (int i = 0; i < styledAttributes.getIndexCount(); ++i) {
        final int attr = styledAttributes.getIndex(i);
        if (attr == R.styleable.StickyViewPager_swipeMarginWidth) {
            swipeMarginWidth = styledAttributes.getDimensionPixelSize(attr, swipeMarginWidth);
        } else if (attr == R.styleable.StickyViewPager_stickyPositions) {
            addStickyPositions(styledAttributes.getString(attr));
        }//from   w w  w.  jav  a  2 s  .c  o m
    }
    styledAttributes.recycle();
}

From source file:com.ruesga.rview.widget.MergedStatusChart.java

public MergedStatusChart(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    final Resources res = getResources();
    mHeightBarPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, res.getDisplayMetrics());
    mMinBarWidth = 0f;/*from  w w  w. ja v a  2 s .  c  om*/
    int openColor = Color.DKGRAY;
    int mergedColor = Color.DKGRAY;
    int abandonedColor = Color.DKGRAY;
    int textColor = Color.WHITE;

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.MergedStatusChart, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.MergedStatusChart_heightBarPadding:
            mHeightBarPadding = a.getDimension(attr, mHeightBarPadding);
            break;

        case R.styleable.MergedStatusChart_minBarWidth:
            mMinBarWidth = a.getDimension(attr, mMinBarWidth);
            break;

        case R.styleable.MergedStatusChart_openColor:
            openColor = a.getColor(attr, openColor);
            break;

        case R.styleable.MergedStatusChart_mergedColor:
            mergedColor = a.getColor(attr, mergedColor);
            break;

        case R.styleable.MergedStatusChart_abandonedColor:
            abandonedColor = a.getColor(attr, abandonedColor);
            break;

        case R.styleable.MergedStatusChart_statusLabelTextColor:
            textColor = a.getColor(attr, textColor);
            break;
        }
    }
    a.recycle();

    mOpenPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mOpenPaint.setStyle(Paint.Style.FILL);
    mMergedPaint = new Paint(mOpenPaint);
    mAbandonedPaint = new Paint(mOpenPaint);
    mOpenPaint.setColor(openColor);
    mMergedPaint.setColor(mergedColor);
    mAbandonedPaint.setColor(abandonedColor);

    mLabelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mLabelPaint.setTextAlign(Paint.Align.LEFT);
    mLabelPaint.setFakeBoldText(true);
    mLabelPaint.setColor(textColor);
    mLabelPaint
            .setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10f, res.getDisplayMetrics()));
    mLabelPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 2f, res.getDisplayMetrics());
    Rect bounds = new Rect();
    mLabelPaint.getTextBounds("0", 0, 1, bounds);
    mLabelHeight = bounds.height();

    if (getBackground() == null) {
        setBackgroundColor(Color.TRANSPARENT);
    }
}

From source file:util.android.viewpagerindicator.FontableTabPageIndicator.java

private void init(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FontableTabPageIndicator);
    final int n = a.getIndexCount();
    for (int i = 0; i < n; ++i) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.FontableTabPageIndicator_fontFamilyNormal) {
            normalText = setATypeface(a.getString(attr));
        } else if (attr == R.styleable.FontableTabPageIndicator_fontFamilySelected) {
            selectedText = setATypeface(a.getString(attr));
        }/* w  ww.  j  av a 2s  .  c  o  m*/

    }
    a.recycle();
}

From source file:com.ycdyng.onemulti.MultiFragment.java

public int getColorPrimaryDark(Resources.Theme theme) {
    int color = 0; // a default
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        try {/*from  w  w  w  . jav a  2s .  c  o m*/
            final TypedArray appearance = theme
                    .obtainStyledAttributes(new int[] { android.R.attr.colorPrimaryDark });
            if (0 < appearance.getIndexCount()) {
                int attr = appearance.getIndex(0);
                color = appearance.getColor(attr, color);
            }
            appearance.recycle();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return color;
}

From source file:com.leo.tablayout.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TabView, defStyle, 0);
    int n = a.getIndexCount();

    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.TabView_selected_indicator_width) {
            mSelectedIndicatorWidth = a.getDimensionPixelSize(attr, -1);
        } else if (attr == R.styleable.TabView_selected_indicator_height) {
            mSelectedIndicatorheight = a.getDimensionPixelSize(attr, -1);
        }//from w w  w  .j  a v a 2 s  . c  o m

    }
    a.recycle();
    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);

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

    mTabStrip = new SlidingTabStrip(context, mSelectedIndicatorWidth, mSelectedIndicatorheight);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}