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.github.shareme.gwsmaterialuikit.library.material.widget.TabPageIndicator.java

protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPageIndicator, defStyleAttr,
            defStyleRes);/*  w  ww  . j av a2  s .  co m*/

    int textAppearance = 0;
    int mode = -1;
    int rippleStyle = 0;

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.TabPageIndicator_tpi_tabPadding)
            mTabPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabRipple)
            rippleStyle = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorColor)
            mPaint.setColor(a.getColor(attr, 0));
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorHeight)
            mIndicatorHeight = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorAtTop)
            mIndicatorAtTop = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabSingleLine)
            mTabSingleLine = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_android_textAppearance)
            textAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_mode)
            mode = a.getInteger(attr, 0);
    }

    a.recycle();

    if (mTabPadding < 0)
        mTabPadding = ThemeUtil.dpToPx(context, 12);

    if (mIndicatorHeight < 0)
        mIndicatorHeight = ThemeUtil.dpToPx(context, 2);

    if (mode >= 0) {
        if (mMode != mode || getChildCount() == 0) {
            mMode = mode;
            removeAllViews();
            if (mMode == MODE_SCROLL) {
                addView(mTabContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
                setFillViewport(false);
            } else if (mMode == MODE_FIXED) {
                addView(mTabContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
                setFillViewport(true);
            }
        }
    }

    if (textAppearance != 0 && mTextAppearance != textAppearance) {
        mTextAppearance = textAppearance;
        for (int i = 0, count = mTabContainer.getChildCount(); i < count; i++) {
            CheckedTextView tv = (CheckedTextView) mTabContainer.getChildAt(i);
            tv.setTextAppearance(context, mTextAppearance);
        }
    }

    if (rippleStyle != 0 && rippleStyle != mTabRippleStyle) {
        mTabRippleStyle = rippleStyle;
        for (int i = 0, count = mTabContainer.getChildCount(); i < count; i++)
            ViewUtil.setBackground(mTabContainer.getChildAt(i),
                    new RippleDrawable.Builder(getContext(), mTabRippleStyle).build());
    }

    if (mViewPager != null)
        notifyDataSetChanged();
    requestLayout();
}

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

/**
 *///w w w .ja  va  2s .co m
@Override
protected void onStyleDialog(View dialogView, TypedArray parsedArray) {
    final Context context = getActivity();

    final int listDialogStyle = parsedArray.getResourceId(R.styleable.And_Theme_Dialog_listDialogStyle,
            R.style.And_Dialog_ListDialog);
    final TypedArray dialogArray = context.obtainStyledAttributes(listDialogStyle,
            R.styleable.And_Theme_Dialog_ListDialog);
    if (dialogArray != null) {
        final int n = dialogArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = dialogArray.getIndex(i);
            /**
             * Obtain list dialog sub-dialog style.
             */
            if (attr == R.styleable.And_Theme_Dialog_ListDialog_dialogStyle) {
                final int dialogStyle = dialogArray.getResourceId(attr, R.style.And_Dialog_Dialog);
                /**
                 * Let super to process list dialog sub-dialog style.
                 */
                super.onStyleDialog(dialogView, dialogStyle);

                // Set up empty text view style.
                if (mEmptyTextView != null) {
                    final TypedArray bodyArray = context.obtainStyledAttributes(dialogStyle,
                            new int[] { R.attr.dialogBodyStyle });
                    if (bodyArray != null) {
                        final int bodyStyle = bodyArray.getResourceId(0, R.style.And_Dialog_Body);

                        // Apply body style to get some padding.
                        TEXT_STYLER.performStyling(bodyStyle, mEmptyTextView);

                        final TypedArray textArray = context.obtainStyledAttributes(bodyStyle,
                                new int[] { android.R.attr.textViewStyle });
                        if (textArray != null) {
                            // Apply message text style.
                            TEXT_STYLER.performStyling(textArray.getResourceId(0, R.style.And_Dialog_TextView),
                                    mEmptyTextView);
                            textArray.recycle();
                        }
                        bodyArray.recycle();
                    }
                }
            }
            /**
             * Set up list dialog list view style.
             */
            else if (attr == R.styleable.And_Theme_Dialog_ListDialog_android_listViewStyle) {
                if (mListView != null) {
                    LIST_STYLER.performStyling(dialogArray.getResourceId(attr, R.style.And_Dialog_ListView),
                            mListView);
                }
            }
        }
        dialogArray.recycle();
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.SimpleDialog.java

@Override
public Dialog applyStyle(int resId) {
    super.applyStyle(resId);

    if (resId == 0)
        return this;

    TypedArray a = getContext().obtainStyledAttributes(resId, R.styleable.SimpleDialog);
    int textAppearance = 0;
    int textColor = 0;
    boolean textColorDefined = false;

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

        if (attr == R.styleable.SimpleDialog_di_messageTextAppearance)
            textAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.SimpleDialog_di_messageTextColor) {
            textColor = a.getColor(attr, 0);
            textColorDefined = true;/*from www. ja va 2s.  c o  m*/
        } else if (attr == R.styleable.SimpleDialog_di_radioButtonStyle)
            radioButtonStyle(a.getResourceId(attr, 0));
        else if (attr == R.styleable.SimpleDialog_di_checkBoxStyle)
            checkBoxStyle(a.getResourceId(attr, 0));
        else if (attr == R.styleable.SimpleDialog_di_itemHeight)
            itemHeight(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SimpleDialog_di_itemTextAppearance)
            itemTextAppearance(a.getResourceId(attr, 0));
    }

    a.recycle();

    if (textAppearance != 0)
        messageTextAppearance(textAppearance);

    if (textColorDefined)
        messageTextColor(textColor);

    return this;
}

From source file:eu.long1.spacetablayout.SpaceTabLayout.java

private void initArrts(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpaceTabLayout);
    for (int i = 0; i < a.getIndexCount(); ++i) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.SpaceTabLayout_number_of_tabs) {
            numberOfTabs = a.getInt(attr, 3);
            if (numberOfTabs == 0) {
                numberOfTabs = 3;//from w  ww . ja  va2 s.c  om
                iconOnly = true;
            }
        } else if (attr == R.styleable.SpaceTabLayout_starting_position) {
            startingPosition = a.getInt(attr, 0);
            int test = startingPosition + 1;
            if (test > numberOfTabs) {
                switch (numberOfTabs) {
                case 3:
                    startingPosition = 1;
                    actionButton.setImageDrawable(defaultTabTwoButtonIcon);
                    actionButton.setOnClickListener(tabTwoOnClickListener);
                    break;
                case 4:
                    startingPosition = 0;
                    actionButton.setImageDrawable(defaultTabOneButtonIcon);
                    actionButton.setOnClickListener(tabOneOnClickListener);
                    break;
                case 5:
                    startingPosition = 2;
                    actionButton.setImageDrawable(defaultTabThreeButtonIcon);
                    actionButton.setOnClickListener(tabThreeOnClickListener);
                    break;
                }
            } else {
                switch (startingPosition) {
                case 0:
                    actionButton.setImageDrawable(defaultTabOneButtonIcon);
                    actionButton.setOnClickListener(tabOneOnClickListener);
                    break;
                case 1:
                    actionButton.setImageDrawable(defaultTabTwoButtonIcon);
                    actionButton.setOnClickListener(tabTwoOnClickListener);
                    break;
                case 2:
                    actionButton.setImageDrawable(defaultTabThreeButtonIcon);
                    actionButton.setOnClickListener(tabThreeOnClickListener);
                    break;
                case 3:
                    actionButton.setImageDrawable(defaultTabFourButtonIcon);
                    actionButton.setOnClickListener(tabFourOnClickListener);
                    break;
                case 4:
                    actionButton.setImageDrawable(defaultTabFiveButtonIcon);
                    actionButton.setOnClickListener(tabFiveOnClickListener);
                    break;
                }
            }
        } else if (attr == R.styleable.SpaceTabLayout_tab_color) {
            defaultTabColor = a.getColor(attr, getContext().getResources().getIdentifier("colorAccent", "color",
                    getContext().getPackageName()));

        } else if (attr == R.styleable.SpaceTabLayout_button_color) {
            defaultButtonColor = a.getColor(attr, getContext().getResources().getIdentifier("colorPrimary",
                    "color", getContext().getPackageName()));

        } else if (attr == R.styleable.SpaceTabLayout_text_color) {
            defaultTextColor = a.getColor(attr,
                    ContextCompat.getColor(getContext(), android.R.color.primary_text_dark));

        } else if (attr == R.styleable.SpaceTabLayout_icon_one) {
            defaultTabOneButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_two) {
            defaultTabTwoButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_three) {
            defaultTabThreeButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_four) {
            if (numberOfTabs > 3)
                defaultTabFourButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_icon_five) {
            if (numberOfTabs > 4)
                defaultTabFiveButtonIcon = a.getDrawable(attr);

        } else if (attr == R.styleable.SpaceTabLayout_text_one) {
            text_one = a.getString(attr);

        } else if (attr == R.styleable.SpaceTabLayout_text_two) {
            text_two = a.getString(attr);

        } else if (attr == R.styleable.SpaceTabLayout_text_three) {
            text_three = a.getString(attr);

        }
    }
    a.recycle();
}

From source file:com.albedinsky.android.support.ui.widget.ScrollViewWidget.java

/**
 * Creates a new instance of ScrollViewWidget within the given <var>context</var>.
 *
 * @param context      Context in which will be this view presented.
 * @param attrs        Set of Xml attributes used to configure the new instance of this view.
 * @param defStyleAttr An attribute which contains a reference to a default style resource for
 *                     this view within a theme of the given context.
 *///  w w  w .j a  va 2  s  . c  o  m
public ScrollViewWidget(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ScrollView,
            defStyleAttr, 0);
    if (typedArray != null) {
        this.ensurePullController();
        mPullController.setUpFromAttrs(context, attrs, defStyleAttr);

        this.processTintValues(context, typedArray);
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_Widget_ScrollView_uiPullEnabled) {
                setPullEnabled(typedArray.getBoolean(index, false));
            }
        }
        typedArray.recycle();
    }

    this.applyBackgroundTint();
}

From source file:com.albedinsky.android.support.ui.widget.HorizontalScrollViewWidget.java

/**
 * Creates a new instance of HorizontalScrollViewWidget within the given <var>context</var>.
 *
 * @param context      Context in which will be this view presented.
 * @param attrs        Set of Xml attributes used to configure the new instance of this view.
 * @param defStyleAttr An attribute which contains a reference to a default style resource for
 *                     this view within a theme of the given context.
 *///from  w ww.j  a  v a  2s .c o  m
public HorizontalScrollViewWidget(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.Ui_Widget_HorizontalScrollView, defStyleAttr, 0);
    if (typedArray != null) {
        this.ensurePullController();
        mPullController.setUpFromAttrs(context, attrs, defStyleAttr);

        this.processTintValues(context, typedArray);
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_Widget_HorizontalScrollView_uiPullEnabled) {
                setPullEnabled(typedArray.getBoolean(index, false));
            }
        }
        typedArray.recycle();
    }

    this.applyBackgroundTint();
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static int[] getSystemColors() {
    // attrsAppearance[] must correspond to AndroidSystemColors structure in android/AndroidBridge.h
    final int[] attrsAppearance = { android.R.attr.textColor, android.R.attr.textColorPrimary,
            android.R.attr.textColorPrimaryInverse, android.R.attr.textColorSecondary,
            android.R.attr.textColorSecondaryInverse, android.R.attr.textColorTertiary,
            android.R.attr.textColorTertiaryInverse, android.R.attr.textColorHighlight,
            android.R.attr.colorForeground, android.R.attr.colorBackground, android.R.attr.panelColorForeground,
            android.R.attr.panelColorBackground };

    int[] result = new int[attrsAppearance.length];

    final ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(GeckoApp.mAppContext,
            android.R.style.TextAppearance);

    final TypedArray appearance = contextThemeWrapper.getTheme().obtainStyledAttributes(attrsAppearance);

    if (appearance != null) {
        for (int i = 0; i < appearance.getIndexCount(); i++) {
            int idx = appearance.getIndex(i);
            int color = appearance.getColor(idx, 0);
            result[idx] = color;/*w w w  .jav a  2s.c om*/
        }
        appearance.recycle();
    }

    return result;
}

From source file:com.albedinsky.android.ui.navigation.NavigationLayout.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/*from  www  .  j  a va2s .  c  om*/
 * 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>.
 */
@SuppressWarnings("ResourceType")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mLayoutInflater = LayoutInflater.from(context);
    int initialLayout = 0;

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_NavigationLayout,
            defStyleAttr, defStyleRes);
    if (typedArray != null) {
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_NavigationLayout_android_initialLayout) {
                initialLayout = typedArray.getResourceId(index, initialLayout);
            } else if (index == R.styleable.Ui_NavigationLayout_uiNavigationDrawerShadow) {
                final int resId = typedArray.getResourceId(index, -1);
                if (resId != -1)
                    setDrawerShadow(resId, NAVIGATION_DRAWER_GRAVITY);
            } else if (index == R.styleable.Ui_NavigationLayout_uiColorScrim) {
                setScrimColor(typedArray.getColor(index, Color.TRANSPARENT));
            }
        }
        typedArray.recycle();
    }

    if (initialLayout != 0) {
        mLayoutInflater.inflate(initialLayout, this);
        this.handleInflationFinished();
    }
}

From source file:com.steve.wanqureader.presentation.ui.CanRefreshLayout.java

public CanRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CanRefreshLayout, defStyleAttr, 0);

    try {/*ww w  .  ja v  a2 s.c  o m*/
        final int N = a.getIndexCount();
        for (int i = 0; i < N; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.CanRefreshLayout_can_enabled_up) {
                setRefreshEnabled(a.getBoolean(attr, true));

            } else if (attr == R.styleable.CanRefreshLayout_can_enabled_down) {
                setLoadMoreEnabled(a.getBoolean(attr, true));

            } else if (attr == R.styleable.CanRefreshLayout_can_style_up) {
                mHeadStyle = a.getInt(attr, CLASSIC);

            } else if (attr == R.styleable.CanRefreshLayout_can_style_down) {
                mFootStyle = a.getInt(attr, CLASSIC);

            } else if (attr == R.styleable.CanRefreshLayout_can_friction) {
                setFriction(a.getFloat(attr, DEFAULT_FRICTION));

            } else if (attr == R.styleable.CanRefreshLayout_can_duration) {
                mDuration = a.getInt(attr, DEFAULT_DURATION);

            } else if (attr == R.styleable.CanRefreshLayout_can_smooth_duration) {
                mSmoothDuration = a.getInt(attr, DEFAULT_SMOOTH_DURATION);

            } else if (attr == R.styleable.CanRefreshLayout_can_smooth_length) {
                mSmoothLength = a.getInt(attr, DEFAULT_SMOOTH_LENGTH);
            }
        }
    } finally {
        a.recycle();
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.TabIndicatorView.java

protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPageIndicator, defStyleAttr,
            defStyleRes);//  ww w .  j  ava 2s .c  o m

    int tabPadding = -1;
    int textAppearance = 0;
    int mode = -1;
    int rippleStyle = 0;
    boolean tabSingleLine = false;
    boolean singleLineDefined = false;

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.TabPageIndicator_tpi_tabPadding)
            tabPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabRipple)
            rippleStyle = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorColor)
            mPaint.setColor(a.getColor(attr, 0));
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorHeight)
            mIndicatorHeight = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorAtTop)
            mIndicatorAtTop = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabSingleLine) {
            tabSingleLine = a.getBoolean(attr, true);
            singleLineDefined = true;
        } else if (attr == R.styleable.TabPageIndicator_tpi_centerCurrentTab)
            mCenterCurrentTab = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_android_textAppearance)
            textAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_mode)
            mode = a.getInteger(attr, 0);
    }

    a.recycle();

    if (mIndicatorHeight < 0)
        mIndicatorHeight = ThemeUtil.dpToPx(context, 2);

    boolean shouldNotify = false;

    if (tabPadding >= 0 && mTabPadding != tabPadding) {
        mTabPadding = tabPadding;
        shouldNotify = true;
    }

    if (singleLineDefined && mTabSingleLine != tabSingleLine) {
        mTabSingleLine = tabSingleLine;
        shouldNotify = true;
    }

    if (mode >= 0 && mMode != mode) {
        mMode = mode;
        mAdapter.setFixedWidth(0, 0);
        shouldNotify = true;
    }

    if (textAppearance != 0 && mTextAppearance != textAppearance) {
        mTextAppearance = textAppearance;
        shouldNotify = true;
    }

    if (rippleStyle != 0 && rippleStyle != mTabRippleStyle) {
        mTabRippleStyle = rippleStyle;
        shouldNotify = true;
    }

    if (shouldNotify)
        mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount());

    invalidate();
}