Example usage for android.content.res TypedArray getIndexCount

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

Introduction

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

Prototype

public int getIndexCount() 

Source Link

Document

Returns the number of indices in the array that actually have data.

Usage

From source file:Main.java

public static int[] getColorsFromAttributes(Context context, int... attr) {
    final TypedArray a = context.obtainStyledAttributes(attr);
    int[] colors = new int[a.getIndexCount()];
    for (int i = 0; i < a.getIndexCount(); i++) {
        colors[i] = a.getColor(i, 0);//from  w ww .  ja va 2s.co m
    }
    a.recycle();
    return colors;
}

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);
        }//from   w  ww  .  ja v a2s .c o m
    }

    a.recycle();
}

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;
        }//  w  ww . j  a  va  2  s. c  o m
    }
    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;
        }//w  w w . j  ava  2 s.  c o m
    }
    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 www  . ja  v  a 2s  . 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;//w  w w  . jav a  2  s. com
    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));
        }//from w  ww  . ja  v  a2s.  com

    }
    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  .  j  a v a2  s .  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.  jav a2 s. co  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);
}

From source file:com.albedinsky.android.ui.widget.ActionTextButton.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/*from   ww w  . j a  v a 2 s.  c  o  m*/
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this view specific data from it that can be used to configure this new view instance. The
 * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data
 * from the current theme provided by the specified <var>context</var>.
 */
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ActionTextButton,
            defStyleAttr, defStyleRes);
    if (typedArray != null) {
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_ActionTextButton_android_text) {
                setText(typedArray.getText(index));
            } else if (index == R.styleable.Ui_ActionTextButton_android_paddingLeft) {
                setPadding(typedArray.getDimensionPixelSize(index, 0), getPaddingTop(), getPaddingRight(),
                        getPaddingBottom());
            } else if (index == R.styleable.Ui_ActionTextButton_android_paddingRight) {
                setPadding(getPaddingLeft(), getPaddingTop(), typedArray.getDimensionPixelSize(index, 0),
                        getPaddingBottom());
            }
        }
        typedArray.recycle();
    }
}