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:com.landenlabs.all_devtool.NumBaseFragment.java

protected void addNum(String name, int attrId, String numType) {
    int[] attrs = { attrId };
    TypedArray typedArray = m_context.getTheme().obtainStyledAttributes(attrs);
    String str = "";

    if (typedArray != null) {
        TypedValue typedValue = new TypedValue();

        try {// w w  w.  j a v  a  2s  .  co  m
            str = "???";
            int cnt = typedArray.getIndexCount();
            for (int idx = 0; idx != cnt; idx++) {
                int attrIdx = typedArray.getIndex(idx);
                str = typedArray.getString(attrIdx);

                int refId = typedArray.getResourceId(attrIdx, -1);
                if (refId != -1 && refId != attrId) {
                    addNum(name, refId, numType);
                }

                if (TextUtils.isEmpty(str)) {
                    float val = typedArray.getDimension(0, -1);
                    if (val != -1)
                        str = String.valueOf(val);
                }
                if (!TextUtils.isEmpty(str))
                    m_list.add(new NumInfo(name, str, numType));
            }
            if (cnt == 0) {
                if (m_context.getTheme().resolveAttribute(attrId, typedValue, true)) {
                    str = (String) typedValue.coerceToString();
                    m_list.add(new NumInfo(name, str, numType));
                }
            }
        } catch (Exception ex) {
            m_log.e("peekValue", ex);
        }

        typedArray.recycle();
    }
}

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

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

    final Resources r = getResources();
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    int color = Color.DKGRAY;
    int textColor = Color.WHITE;

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

        case R.styleable.ActivityStatsChart_charLineTextColor:
            textColor = a.getColor(attr, textColor);
            break;
        }//from w  ww .  j  ava 2  s. c o  m
    }
    a.recycle();

    mLinePaint = new Paint();
    mLinePaint.setStyle(Paint.Style.STROKE);
    mLinePaint.setColor(color);
    mLinePaint.setStrokeWidth(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.5f, r.getDisplayMetrics()));

    mAreaPaint = new Paint(mLinePaint);
    mAreaPaint.setStyle(Paint.Style.FILL);
    mAreaPaint.setAlpha(180);

    mGridLinesPaint = new Paint();
    mGridLinesPaint.setStyle(Paint.Style.STROKE);
    mGridLinesPaint.setColor(textColor);
    mGridLinesPaint.setStrokeWidth(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f, r.getDisplayMetrics()));
    mGridLinesPaint.setAlpha(90);
    mGridLinesPaint.setPathEffect(new DashPathEffect(new float[] { 10, 10 }, 0));

    mTicksPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mTicksPaint.setColor(textColor);
    mTicksPaint.setTextAlign(Paint.Align.RIGHT);
    mTicksPaint.setAlpha(180);
    mTicksPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8f, r.getDisplayMetrics()));

    // Ensure we have a background. Otherwise it will not draw anything
    if (getBackground() == null) {
        setBackgroundColor(Color.TRANSPARENT);
    }
}

From source file:com.jungkai.slidingtabs.SlidingTabLayout.java

private void applyStyle(Context context, int styleResId) {
    TypedArray a = context.obtainStyledAttributes(styleResId, R.styleable.SlidingTabLayout);
    final float density = getResources().getDisplayMetrics().density;
    if (a != null) {
        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);

            switch (attr) {
            case R.styleable.SlidingTabLayout_tabBottomBorderHeight:
                setBottomBorderThickness(a.getDimensionPixelSize(attr,
                        (int) (SlidingTabStrip.DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density)));
                break;
            case R.styleable.SlidingTabLayout_tabIndicatorThickness:
                setIndicatorThickness(a.getDimensionPixelSize(attr,
                        (int) (SlidingTabStrip.DEFAULT_INDICATOR_THICKNESS_DIPS * density)));
                break;
            case R.styleable.SlidingTabLayout_tabIndicatorDrawable:
                setIndicatorDrawable(a.getDrawable(attr));
                break;
            case R.styleable.SlidingTabLayout_tabDividerThickness:
                setDividerThickness(a.getDimensionPixelSize(attr,
                        (int) (SlidingTabStrip.DEFAULT_DIVIDER_THICKNESS_DIPS * density)));
                break;
            default:
                break;
            }/*w w w .j a v a2  s  . c  o m*/
        }
    }
}

From source file:com.test.slidebutton.SlideButton.java

/**
 * /*w ww. j a  v a  2s.co  m*/
 * @param typedArray
 */
private void initStyle(TypedArray typedArray) {
    if (typedArray.getIndexCount() > 0) {
        int typedCount = typedArray.getIndexCount();
        int typed = -1;
        for (int i = 0; i < typedCount; i++) {
            typed = typedArray.getIndex(i);
            if (R.styleable.slide_button_slideButtonStyle == typed) {
                int resId = typedArray.getResourceId(typed, 0);
                TypedArray a1 = mContext.obtainStyledAttributes(resId, R.styleable.slide_button);
                initStyle(a1);
                a1.recycle();
            } else if (R.styleable.slide_button_colorOpened == typed) {
                colorOpend = typedArray.getColor(typed, DEFAULT_COLOR_OPENED);
            } else if (R.styleable.slide_button_colorClosed == typed) {
                colorClosed = typedArray.getColor(typed, DEFAULT_COLOR_CLOSED);
            } else if (R.styleable.slide_button_colorBall == typed) {
                colorSlider = typedArray.getColor(typed, DEFAULT_COLOR_BALL);
            } else if (R.styleable.slide_button_slidable == typed) {
                slidable = typedArray.getBoolean(typed, true);
            } else if (R.styleable.slide_button_isOpen == typed) {
                isOpen = typedArray.getBoolean(typed, false);
            } else if (R.styleable.slide_button_shape == typed) {
                shape = typedArray.getInt(typed, SHAPE_RECT);
            }
        }
    }
}

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

private static void resolveStyleAttrsForTypedArray(TypedArray a, Output<TruncateAt> ellipsize,
        Output<Boolean> shouldIncludeFontPadding, Output<Float> spacingMultiplier, Output<Integer> minLines,
        Output<Integer> maxLines, Output<Integer> minEms, Output<Integer> maxEms, Output<Integer> minWidth,
        Output<Integer> maxWidth, Output<Boolean> isSingleLine, Output<CharSequence> text,
        Output<ColorStateList> textColorStateList, Output<Integer> linkColor, Output<Integer> highlightColor,
        Output<Integer> textSize, Output<Alignment> textAlignment, Output<Integer> textStyle,
        Output<Float> shadowRadius, Output<Float> shadowDx, Output<Float> shadowDy, Output<Integer> shadowColor,
        Output<VerticalGravity> verticalGravity) {
    int viewTextAlignment = View.TEXT_ALIGNMENT_GRAVITY;
    int gravity = Gravity.NO_GRAVITY;

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

        if (attr == R.styleable.Text_android_text) {
            text.set(a.getString(attr));
        } else if (attr == R.styleable.Text_android_textColor) {
            textColorStateList.set(a.getColorStateList(attr));
        } else if (attr == R.styleable.Text_android_textSize) {
            textSize.set(a.getDimensionPixelSize(attr, 0));
        } else if (attr == R.styleable.Text_android_ellipsize) {
            final int index = a.getInteger(attr, 0);
            if (index > 0) {
                ellipsize.set(TRUNCATE_AT[index - 1]);
            }//from w  w w .  j a  va  2 s.  c o m
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
                && attr == R.styleable.Text_android_textAlignment) {
            viewTextAlignment = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
        } else if (attr == R.styleable.Text_android_gravity) {
            gravity = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
            verticalGravity.set(getVerticalGravity(gravity));
        } else if (attr == R.styleable.Text_android_includeFontPadding) {
            shouldIncludeFontPadding.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_minLines) {
            minLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_maxLines) {
            maxLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_singleLine) {
            isSingleLine.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_textColorLink) {
            linkColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textColorHighlight) {
            highlightColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textStyle) {
            textStyle.set(a.getInteger(attr, 0));
        } else if (attr == R.styleable.Text_android_lineSpacingMultiplier) {
            spacingMultiplier.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDx) {
            shadowDx.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDy) {
            shadowDy.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowRadius) {
            shadowRadius.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowColor) {
            shadowColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_minEms) {
            minEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_maxEms) {
            maxEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_minWidth) {
            minWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MIN_WIDTH));
        } else if (attr == R.styleable.Text_android_maxWidth) {
            maxWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MAX_WIDTH));
        }
    }
}

From source file:universum.studios.android.dialog.ColorPickerDialog.java

/**
 *///from   w  ww .  j a  v  a 2  s. c o m
@Override
protected void onProcessOptionsStyle(@NonNull Context context, @StyleRes int optionsStyle) {
    super.onProcessOptionsStyle(context, optionsStyle);
    if (mOptions instanceof ColorOptions) {
        final TypedArray attributes = context.obtainStyledAttributes(optionsStyle,
                R.styleable.Dialog_Options_Color);
        final ColorOptions options = (ColorOptions) mOptions;
        for (int i = 0; i < attributes.getIndexCount(); i++) {
            int index = attributes.getIndex(i);
            if (index == R.styleable.Dialog_Options_Color_dialogColor) {
                if (!options.isSet(ColorOptions.COLOR)) {
                    options.color(attributes.getColor(index, options.color));
                }
            } else if (index == R.styleable.Dialog_Options_Color_dialogColorCanvas) {
                if (!options.isSet(ColorOptions.CANVAS_COLOR)) {
                    options.canvasColor(attributes.getColor(index, options.canvasColor));
                }
            }
        }
        attributes.recycle();
    }
}

From source file:com.googlecode.eyesfree.example.bargraph.BarGraphView.java

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

    // Load styled attributes.
    final int defStyleRes = (isInEditMode() ? 0 : R.style.BarGraph);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BarGraph, defStyle, defStyleRes);

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

        switch (attr) {
        case R.styleable.BarGraph_barMargin:
            mBarMargin = a.getDimension(attr, mBarMargin);
            break;
        case R.styleable.BarGraph_barMinWidth:
            mBarMinHeight = a.getDimension(attr, mBarMinHeight);
            break;
        case R.styleable.BarGraph_barMinHeight:
            mBarMinWidth = a.getDimension(attr, mBarMinWidth);
            break;
        case R.styleable.BarGraph_title:
            setTitle(a.getText(attr));//from ww w  .  j  ava  2 s . c  o m
            break;
        case R.styleable.BarGraph_titleSize:
            mTitleSize = a.getDimension(attr, mTitleSize);
            break;
        case R.styleable.BarGraph_values:
            if (!isInEditMode()) {
                setData(context.getResources().getIntArray(a.getResourceId(attr, 0)));
            }
            break;
        }
    }

    a.recycle();

    if (isInEditMode()) {
        // Special considerations for edit mode.
        mBarGraphAccessHelper = null;
        setData(new int[] { 1, 1, 2, 3, 5, 8 });
        setSelection(3);
    } else {
        // Set up accessibility helper class.
        mBarGraphAccessHelper = new BarGraphAccessHelper(this);
        ViewCompat.setAccessibilityDelegate(this, mBarGraphAccessHelper);
    }
}

From source file:com.wit.and.dialog.EditDialog.java

/**
 *///from  w  w  w. j a  v a2 s . com
@Override
protected void onStyleDialog(View dialogView, TypedArray parsedArray) {
    final Context context = getActivity();

    Log.d(TAG, "onStyleDialog() START");

    final int editDialogStyle = parsedArray.getResourceId(R.styleable.And_Theme_Dialog_editDialogStyle,
            R.style.And_Dialog_EditDialog);
    final TypedArray dialogArray = context.obtainStyledAttributes(editDialogStyle,
            R.styleable.And_Theme_Dialog_EditDialog);
    if (dialogArray != null) {
        final int n = dialogArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = dialogArray.getIndex(i);
            /**
             * Obtain edit dialog sub-dialog style.
             */
            if (attr == R.styleable.And_Theme_Dialog_EditDialog_dialogStyle) {
                /**
                 * Let super to process edit dialog sub-dialog style.
                 */
                super.onStyleDialog(dialogView, dialogArray.getResourceId(attr, R.style.And_Dialog_Dialog));
            }
            // Set up edit dialog edit.
            else if (attr == R.styleable.And_Theme_Dialog_EditDialog_android_editTextStyle) {
                final int editStyle = dialogArray.getResourceId(attr, R.style.And_Dialog_EditText);
                EDIT_STYLER.performStyling(editStyle, mEdit);
            }
        }
        dialogArray.recycle();
    }

    Log.d(TAG, "onStyleDialog() set up edit style from options");

    // Set up edit text.
    if (mEditStyle > 0) {
        Log.d(TAG, "onStyleDialog() edit style(" + mEditStyle + ")");

        EDIT_STYLER.performStyling(mEditStyle, mEdit);
    }
    if (mHint != null) {
        mEdit.setHint(mHint);
    }

    /**
     * Set type face to text views.
     */
    Typeface typeface = obtainTypeface(editDialogStyle);
    if (typeface != null) {
        applyTypeface(typeface, mEdit);
    }

    Log.d(TAG, "onStyleDialog() FINISH");
}

From source file:com.albedinsky.android.setting.SettingSelectionDialogPreference.java

/**
 *//*from w w  w.  j av  a2s. c o  m*/
@Override
@SuppressWarnings("ResourceType")
protected void onConfigureDialogOptions(@NonNull SelectionDialog.SelectionOptions options,
        @NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr,
        @StyleRes int defStyleRes) {
    super.onConfigureDialogOptions(options, context, attrs, defStyleAttr, defStyleRes);
    final TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.Ui_Settings_SelectionDialogPreference, defStyleAttr, defStyleRes);
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
        final int index = typedArray.getIndex(i);
        if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogSelectionMode) {
            options.selectionMode(typedArray.getInt(index, options.selectionMode()));
        } else if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogEmptySelectionAllowed) {
            options.emptySelectionAllowed(typedArray.getBoolean(index, options.shouldAllowEmptySelection()));
        }
    }
    typedArray.recycle();
}

From source file:com.edgar.banner.BannerPagerView.java

private void init(AttributeSet attrs, int defStyle) {
    Context context = getContext();
    Resources resource = context.getResources();
    LayoutInflater.from(getContext()).inflate(R.layout.banner_layout, this, true);
    mViewPage = (LoopViewPager) findViewById(R.id.carouse_viewpager);
    setBannerScroller(new BannerScroller(getContext()));
    mViewPage.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mViewPage.setOnPageChangeListener(mCarousePageListener);
    mBannerPageAdapter = new DefaultBannerPageViewAdapter();
    mIndicatorParams.gravity = Gravity.BOTTOM;
    mPointPadding = resource.getDimensionPixelOffset(R.dimen.point_margin);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BannerPagerView, defStyle, 0);
    int N = a.getIndexCount();
    for (int i = 0; i < N; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.BannerPagerView_bannerAnimation) {
            int transformerType = a.getInt(attr, 0);
            setBannerPageTransformer(true, TransformerType.convert(transformerType));
        } else if (attr == R.styleable.BannerPagerView_enableAutoPlayer) {
            setEnableAutoPlay(a.getBoolean(attr, false));
        } else if (attr == R.styleable.BannerPagerView_indicatorStyle) {
            mIndicatorStyle = a.getInt(attr, IndicatorStyle.CIRCLE_INDICATOR);
        } else if (attr == R.styleable.BannerPagerView_indicatorLayout) {
            int resId = a.getResourceId(attr, 0);
            if (resId != 0) {
                View indicatorView = LayoutInflater.from(context).inflate(resId, this, false);
                if (!(indicatorView instanceof BannerIndicator)) {
                    throw new IllegalArgumentException("Your indicator must implements BannerIndicator.");
                }//  w ww.  j ava  2 s .c  om
                mIndicatorView = indicatorView;
                mBannerIndicator = (BannerIndicator) indicatorView;
                addView(mIndicatorView);
            }
        } else if (attr == R.styleable.BannerPagerView_unSelectDrawable) {
            mUnSelectedDrawable = a.getDrawable(attr);
        } else if (attr == R.styleable.BannerPagerView_selectedDrawable) {
            mSelectedDrawable = a.getDrawable(attr);
        } else if (attr == R.styleable.BannerPagerView_indicatorGravity) {
            mIndicatorGravity = a.getInt(attr, Gravity.CENTER);
        } else if (attr == R.styleable.BannerPagerView_pointPadding) {
            mPointPadding = a.getDimensionPixelOffset(attr, mPointPadding);
        } else if (attr == R.styleable.BannerPagerView_indicatorBackground) {
            mIndicatorBackground = a.getDrawable(attr);
        }
    }

    if (mUnSelectedDrawable == null) {
        mUnSelectedDrawable = ContextCompat.getDrawable(context, R.drawable.def_circle_normal_background);
    }
    if (mSelectedDrawable == null) {
        mSelectedDrawable = ContextCompat.getDrawable(context, R.drawable.def_circle_selected_background);
    }
    if (mIndicatorBackground == null) {
        mIndicatorBackground = new ColorDrawable(resource.getColor(R.color.indicator_background));
    }
    if (mBannerIndicator == null) {
        setIndicatorStyle(mIndicatorStyle);
    }

    a.recycle();
}