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.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);//ww  w  .  jav a 2  s  .com

    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

/**
 *//*from w w w .  j  a  v a2  s .  c  om*/
@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:org.xbmc.kore.ui.sections.remote.RemoteFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_remote, container, false);
    ButterKnife.inject(this, root);

    if (hostManager.getHostInfo().getUseEventServer() && (eventServerConnection != null)) {
        // Setup d-pad to use EventServer
        setupEventServerButton(leftButton, ButtonCodes.REMOTE_LEFT);
        setupEventServerButton(rightButton, ButtonCodes.REMOTE_RIGHT);
        setupEventServerButton(upButton, ButtonCodes.REMOTE_UP);
        setupEventServerButton(downButton, ButtonCodes.REMOTE_DOWN);

        setupEventServerButton(selectButton, ButtonCodes.REMOTE_SELECT);
    } else {/*from w w w  .jav  a  2  s .  com*/
        // Otherwise, use json-rpc
        setupRepeatButton(leftButton, new Input.Left());
        setupRepeatButton(rightButton, new Input.Right());
        setupRepeatButton(upButton, new Input.Up());
        setupRepeatButton(downButton, new Input.Down());

        setupDefaultButton(selectButton, new Input.Select(), null);
    }

    // Other buttons
    setupDefaultButton(backButton, new Input.Back(), null);
    setupDefaultButton(osdButton, new Input.ExecuteAction(Input.ExecuteAction.OSD), null);
    setupDefaultButton(contextButton, new Input.ExecuteAction(Input.ExecuteAction.CONTEXTMENU), null);

    // Info button, v17 uses a different window to display codec info so check version number
    HostInfo hostInfo = hostManager.getHostInfo();
    if (hostInfo.getKodiVersionMajor() < 17) {
        setupDefaultButton(infoButton, new Input.ExecuteAction(Input.ExecuteAction.INFO),
                new Input.ExecuteAction(Input.ExecuteAction.CODECINFO));
    } else {
        setupDefaultButton(infoButton, new Input.ExecuteAction(Input.ExecuteAction.INFO),
                new Input.ExecuteAction(Input.ExecuteAction.PLAYERPROCESSINFO));
    }

    adjustRemoteButtons();

    TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
            new int[] { R.attr.iconFastForward, R.attr.iconRewind, R.attr.iconNext, R.attr.iconPrevious });
    fastForwardIcon = styledAttributes.getResourceId(styledAttributes.getIndex(0),
            R.drawable.ic_fast_forward_white_24dp);
    rewindIcon = styledAttributes.getResourceId(styledAttributes.getIndex(1),
            R.drawable.ic_fast_rewind_white_24dp);
    skipNextIcon = styledAttributes.getResourceId(styledAttributes.getIndex(2),
            R.drawable.ic_skip_next_white_24dp);
    skipPreviousIcon = styledAttributes.getResourceId(styledAttributes.getIndex(3),
            R.drawable.ic_skip_previous_white_24dp);
    styledAttributes.recycle();

    Set<String> shownItems = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getStringSet(Settings.getRemoteBarItemsPrefKey(hostInfo.getId()), new HashSet<>(
                    Arrays.asList(getResources().getStringArray(R.array.default_values_remote_bar_items))));
    ImageButton[] buttons = { homeButton, moviesButton, tvShowsButton, musicButton, pvrButton, picturesButton,
            videosButton, addonsButton, weatherButton, systemButton };
    for (int i = 0; i < buttons.length; i++) {
        if (buttons[i] != null)
            buttons[i].setVisibility(shownItems.contains(String.valueOf(i)) ? View.VISIBLE : View.GONE);
    }

    //        // Pad main content view to account for bottom system bar
    //        UIUtils.setPaddingForSystemBars(getActivity(), root, false, false, true);

    // No clipping
    //        root.setClipToPadding(false);

    return root;
}

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;/*w  w w.j  av  a 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  w w  .  jav  a  2 s  .  com
                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  av a  2  s.  c om*/
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 w  w.  java 2 s  .  c  om*/
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. j av  a  2 s  .  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>/*  ww  w  .j  av  a  2  s  .  co 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>.
 */
@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.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);//from   www  . j a v a2s  .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();
}