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.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;
        }/*www.jav  a2s  .  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.albedinsky.android.ui.widget.ActionTextButton.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/*from w ww . j  av  a 2  s  . com*/
 * 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();
    }
}

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 {/* www. j  a v  a 2  s .  c  o  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.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;
            }/*from   w  w  w . j  a v a 2  s  . c o  m*/
        }
    }
}

From source file:org.xbmc.kore.ui.sections.video.TVShowProgressFragment.java

/**
 * Display the seasons list// ww  w.j a  va  2s  .co m
 *
 * @param cursor Cursor with the data
 */
private void displaySeasonList(Cursor cursor) {
    TextView seasonsListTitle = (TextView) getActivity().findViewById(R.id.seasons_title);
    GridLayout seasonsList = (GridLayout) getActivity().findViewById(R.id.seasons_list);

    if (cursor.moveToFirst()) {
        seasonsListTitle.setVisibility(View.VISIBLE);
        seasonsList.setVisibility(View.VISIBLE);

        HostManager hostManager = HostManager.getInstance(getActivity());

        View.OnClickListener seasonListClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerActivity.onSeasonSelected(itemId, (int) v.getTag());
            }
        };

        // Get the art dimensions
        Resources resources = getActivity().getResources();
        int artWidth = (int) (resources.getDimension(R.dimen.seasonlist_art_width)
                / UIUtils.IMAGE_RESIZE_FACTOR);
        int artHeight = (int) (resources.getDimension(R.dimen.seasonlist_art_heigth)
                / UIUtils.IMAGE_RESIZE_FACTOR);

        // Get theme colors
        Resources.Theme theme = getActivity().getTheme();
        TypedArray styledAttributes = theme
                .obtainStyledAttributes(new int[] { R.attr.colorinProgress, R.attr.colorFinished });

        int inProgressColor = styledAttributes.getColor(styledAttributes.getIndex(0),
                resources.getColor(R.color.orange_500));
        int finishedColor = styledAttributes.getColor(styledAttributes.getIndex(1),
                resources.getColor(R.color.green_400));
        styledAttributes.recycle();

        seasonsList.removeAllViews();
        do {
            int seasonNumber = cursor.getInt(SeasonsListQuery.SEASON);
            String thumbnail = cursor.getString(SeasonsListQuery.THUMBNAIL);
            int numEpisodes = cursor.getInt(SeasonsListQuery.EPISODE);
            int watchedEpisodes = cursor.getInt(SeasonsListQuery.WATCHEDEPISODES);

            View seasonView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item_season, seasonsList,
                    false);

            ImageView seasonPictureView = (ImageView) seasonView.findViewById(R.id.art);
            TextView seasonNumberView = (TextView) seasonView.findViewById(R.id.season);
            TextView seasonEpisodesView = (TextView) seasonView.findViewById(R.id.episodes);
            ProgressBar seasonProgressBar = (ProgressBar) seasonView.findViewById(R.id.season_progress_bar);

            seasonNumberView
                    .setText(String.format(getActivity().getString(R.string.season_number), seasonNumber));
            seasonEpisodesView.setText(String.format(getActivity().getString(R.string.num_episodes),
                    numEpisodes, numEpisodes - watchedEpisodes));
            seasonProgressBar.setMax(numEpisodes);
            seasonProgressBar.setProgress(watchedEpisodes);

            if (Utils.isLollipopOrLater()) {
                int watchedColor = (numEpisodes - watchedEpisodes == 0) ? finishedColor : inProgressColor;
                seasonProgressBar.setProgressTintList(ColorStateList.valueOf(watchedColor));
            }

            UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail,
                    String.valueOf(seasonNumber), seasonPictureView, artWidth, artHeight);

            seasonView.setTag(seasonNumber);
            seasonView.setOnClickListener(seasonListClickListener);
            seasonsList.addView(seasonView);
        } while (cursor.moveToNext());
    } else {
        // No seasons, hide views
        seasonsListTitle.setVisibility(View.GONE);
        seasonsList.setVisibility(View.GONE);
    }
}

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]);
            }// www .j a v a 2s .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:org.xbmc.kore.ui.AddonDetailsFragment.java

private void setupPinButton(boolean bookmarked) {
    Resources.Theme theme = getActivity().getTheme();
    TypedArray styledAttributes = theme
            .obtainStyledAttributes(new int[] { R.attr.defaultButtonColorFilter, R.attr.colorAccent });
    Resources resources = getActivity().getResources();
    // Bookmarked button
    if (bookmarked) {
        pinButton.setColorFilter(styledAttributes.getColor(styledAttributes.getIndex(1),
                resources.getColor(R.color.accent_default)));
    } else {/* w w  w . j a  va 2 s . co m*/
        pinButton.setColorFilter(
                styledAttributes.getColor(styledAttributes.getIndex(0), resources.getColor(R.color.white)));
    }
    styledAttributes.recycle();
    pinButton.setTag(bookmarked);
    pinButton.setVisibility(View.VISIBLE);
}

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

/**
 *///from  w w w .  ja v a 2  s . c om
@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.test.slidebutton.SlideButton.java

/**
 * /*from  ww w  .  j av a 2 s .c o  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.myf.PagerSlidingTabStripEx.java

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

    setFillViewport(true);//from w ww  .  jav a2  s .c o  m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);

    tabTextColor = a.getColor(a.getIndex(1), tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextColor, tabTextColor);
    tabCurTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextSelectColor, tabCurTextColor);
    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTextSize, tabTextSize);
    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}