Example usage for android.content.res TypedArray getResourceId

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

Introduction

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

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:com.gsclub.strategy.ui.view.CustomTabLayout.java

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

    ThemeUtils.checkAppCompatTheme(context);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);

    // Add the TabStrip
    mTabStrip = new SlidingTabStrip(context);
    super.addView(mTabStrip, 0, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.TabLayout,
            defStyleAttr, android.support.design.R.style.Widget_Design_TabLayout);

    mTabStrip.setSelectedIndicatorHeight(
            a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabIndicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(
            a.getColor(android.support.design.R.styleable.TabLayout_tabIndicatorColor, 0));

    mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
            .getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPadding, 0);
    mTabPaddingStart = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingStart,
            mTabPaddingStart);//from  w w  w.  ja  v a 2 s  .c  o m
    mTabPaddingTop = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingTop,
            mTabPaddingTop);
    mTabPaddingEnd = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingEnd,
            mTabPaddingEnd);
    mTabPaddingBottom = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabPaddingBottom,
            mTabPaddingBottom);

    mTabTextAppearance = a.getResourceId(android.support.design.R.styleable.TabLayout_tabTextAppearance,
            android.support.design.R.style.TextAppearance_Design_Tab);

    // Text colors/sizes come from the text appearance first
    final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance,
            android.support.v7.appcompat.R.styleable.TextAppearance);
    try {
        mTabTextSize = ta.getDimensionPixelSize(
                android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize, 0);
        mTabTextColors = ta
                .getColorStateList(android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor);
    } finally {
        ta.recycle();
    }

    if (a.hasValue(android.support.design.R.styleable.TabLayout_tabTextColor)) {
        // If we have an explicit text color set, use it instead
        mTabTextColors = a.getColorStateList(android.support.design.R.styleable.TabLayout_tabTextColor);
    }

    if (a.hasValue(android.support.design.R.styleable.TabLayout_tabSelectedTextColor)) {
        // We have an explicit selected text color set, so we need to make merge it with the
        // current colors. This is exposed so that developers can use theme attributes to set
        // this (theme attrs in ColorStateLists are Lollipop+)
        final int selected = a.getColor(android.support.design.R.styleable.TabLayout_tabSelectedTextColor, 0);
        mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected);
    }

    mRequestedTabMinWidth = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabMinWidth,
            INVALID_WIDTH);
    mRequestedTabMaxWidth = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabMaxWidth,
            INVALID_WIDTH);
    mTabBackgroundResId = a.getResourceId(android.support.design.R.styleable.TabLayout_tabBackground, 0);
    mContentInsetStart = a.getDimensionPixelSize(android.support.design.R.styleable.TabLayout_tabContentStart,
            0);
    mMode = a.getInt(android.support.design.R.styleable.TabLayout_tabMode, MODE_FIXED);
    mTabGravity = a.getInt(android.support.design.R.styleable.TabLayout_tabGravity, GRAVITY_FILL);
    a.recycle();

    final Resources res = getResources();
    mTabTextMultiLineSize = res
            .getDimensionPixelSize(android.support.design.R.dimen.design_tab_text_size_2line);
    mScrollableTabMinWidth = res
            .getDimensionPixelSize(android.support.design.R.dimen.design_tab_scrollable_min_width);

    // Now apply the tab mode and gravity
    applyModeAndGravity();
}

From source file:com.android.ex.chips.RecipientEditTextView.java

private void setChipDimensions(final Context context, final AttributeSet attrs) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecipientEditTextView, 0, 0);
    final Resources r = getContext().getResources();
    mChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_chipBackground);
    if (mChipBackground == null)
        mChipBackground = ContextCompat.getDrawable(context, R.drawable.circle_background_chips);
    mChipBackgroundPressed = a.getDrawable(R.styleable.RecipientEditTextView_chipBackgroundPressed);
    if (mChipBackgroundPressed == null)
        mChipBackgroundPressed = ContextCompat.getDrawable(context, R.drawable.chip_background_selected);
    mChipDelete = a.getDrawable(R.styleable.RecipientEditTextView_chipDelete);
    if (mChipDelete == null)
        mChipDelete = ContextCompat.getDrawable(context, R.drawable.chip_delete);
    mChipPadding = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipPadding, -1);
    if (mChipPadding == -1)
        mChipPadding = (int) r.getDimension(R.dimen.chip_padding);
    mAlternatesLayout = a.getResourceId(R.styleable.RecipientEditTextView_chipAlternatesLayout, -1);
    if (mAlternatesLayout == -1)
        mAlternatesLayout = R.layout.chips_alternate_item;
    mDefaultContactPhoto = BitmapFactory.decodeResource(r, R.drawable.ic_contact_picture);
    mMoreItem = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.more_item, null);
    mChipHeight = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipHeight, -1);
    if (mChipHeight == -1)
        mChipHeight = r.getDimension(R.dimen.chip_height);
    mChipFontSize = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipFontSize, -1);
    if (mChipFontSize == -1)
        mChipFontSize = r.getDimension(R.dimen.chip_text_size);
    mInvalidChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_invalidChipBackground);
    if (mInvalidChipBackground == null)
        mInvalidChipBackground = ContextCompat.getDrawable(context, R.drawable.chip_background_invalid);
    mLineSpacingExtra = r.getDimension(R.dimen.line_spacing_extra);
    mMaxLines = r.getInteger(R.integer.chips_max_lines);
    final TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    a.recycle();//from   w  w  w  . ja v a2  s  .com
}

From source file:android.support.design.widget.CollapsingToolbarLayout.java

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

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);

    mCollapsingTextHelper.setExpandedTextGravity(a.getInt(
            R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper/*from   ww  w  .  j a v a  2 s .  co m*/
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(
            android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(R.styleable.CollapsingToolbarLayout_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return onWindowInsetChanged(insets);
        }
    });
}

From source file:cc.flydev.launcher.Page.java

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
    setPageSpacing(a.getDimensionPixelSize(R.styleable.PagedView_pageSpacing, 0));
    if (mPageSpacing < 0) {
        mAutoComputePageSpacing = mRecomputePageSpacing = true;
    }//from   w ww . ja va 2  s . co  m
    mPageLayoutPaddingTop = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingTop, 0);
    mPageLayoutPaddingBottom = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingBottom, 0);
    mPageLayoutPaddingLeft = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingLeft, 0);
    mPageLayoutPaddingRight = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingRight, 0);
    mPageLayoutWidthGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutWidthGap, 0);
    mPageLayoutHeightGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutHeightGap, 0);
    mPageIndicatorViewId = a.getResourceId(R.styleable.PagedView_pageIndicator, -1);
    a.recycle();

    setHapticFeedbackEnabled(false);
    init();
}

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Background is always provided by the container.
    setBackgroundResource(0);/*from w ww  . ja va 2s  .  com*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionBar, R.attr.actionBarStyle,
            0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.SherlockActionBar_navigationMode,
            ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.SherlockActionBar_title);
    mSubtitle = a.getText(R.styleable.SherlockActionBar_subtitle);

    mLogo = a.getDrawable(R.styleable.SherlockActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            if (context instanceof Activity) {
                //Even though native methods existed in API 9 and 10 they don't work
                //so just parse the manifest to look for the logo pre-Honeycomb
                final int resId = loadLogoFromManifest((Activity) context);
                if (resId != 0) {
                    mLogo = context.getResources().getDrawable(resId);
                }
            }
        } else {
            if (context instanceof Activity) {
                try {
                    mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Activity component name not found!", e);
                }
            }
            if (mLogo == null) {
                mLogo = appInfo.loadLogo(pm);
            }
        }
    }

    mIcon = a.getDrawable(R.styleable.SherlockActionBar_icon);
    if (mIcon == null) {
        if (context instanceof Activity) {
            try {
                mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Activity component name not found!", e);
            }
        }
        if (mIcon == null) {
            mIcon = appInfo.loadIcon(pm);
        }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId = a.getResourceId(R.styleable.SherlockActionBar_homeLayout,
            R.layout.abs__action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abs__action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_itemPadding, 0);

    setDisplayOptions(a.getInt(R.styleable.SherlockActionBar_displayOptions, DISPLAY_DEFAULT));

    final int customNavId = a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayout, 0);
    if (customNavId != 0) {
        mCustomNavView = inflater.inflate(customNavId, this, false);
        mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
        setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionBar_height, 0);

    a.recycle();

    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);
}

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

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>//from w w  w  .  ja  v  a2s .  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("ConstantConditions")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    this.ensureRect();
    this.ensureDecorator();
    mDecorator.processAttributes(context, attrs, defStyleAttr, defStyleRes);
    this.mAnimations = Animations.get(this);

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SeekBar, defStyleAttr,
            defStyleRes);
    if (typedArray != null) {
        final Rect indicatorTextPadding = new Rect();
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_SeekBar_android_enabled) {
                setEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscrete) {
                setDiscrete(typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscretePreviewEnabled) {
                setDiscretePreviewEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalRatio) {
                setDiscreteIntervalRatio(typedArray.getFloat(index, mDiscreteIntervalRatio));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicator) {
                setDiscreteIndicator(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextAppearance) {
                setDiscreteIndicatorTextAppearance(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextGravity) {
                setDiscreteIndicatorTextGravity(
                        typedArray.getInteger(index, DISCRETE_INDICATOR_TEXT_INFO.gravity));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingStart) {
                indicatorTextPadding.left = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingTop) {
                indicatorTextPadding.top = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingEnd) {
                indicatorTextPadding.right = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingBottom) {
                indicatorTextPadding.bottom = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkColor) {
                setDiscreteIntervalTickMarkColor(typedArray.getColorStateList(index));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkRadius) {
                setDiscreteIntervalTickMarkRadius(typedArray.getDimensionPixelSize(index, 0));
            }
        }
        setDiscreteIndicatorTextPadding(indicatorTextPadding.left, indicatorTextPadding.top,
                indicatorTextPadding.right, indicatorTextPadding.bottom);
        typedArray.recycle();
    }
    this.applyProgressTints();
    this.applyThumbTint();
}

From source file:com.github.yggie.pulltorefresh.PullListFragment.java

/**
 * Applies the xml attributes sent through the Bundle object
 *
 * @param a The TypedArray object containing the xml attributes
 *//*from w w w.j av a 2 s  .co m*/

private void parseXmlAttributes(final TypedArray a) {
    if (a != null) {
        /** apply the background color */
        final int backgroundColor = a.getColor(R.styleable.PullListFragment_list_backgroundColor, 0);
        if (backgroundColor != 0) {
            setListViewBackgroundColor(backgroundColor);
        }

        /**
         * Applies the padding, more specific padding has higher priority
         */

        int paddingTop = listView.getPaddingTop();
        int paddingBottom = listView.getPaddingBottom();
        int paddingLeft = listView.getPaddingLeft();
        int paddingRight = listView.getPaddingRight();

        final int padding = a.getDimensionPixelSize(R.styleable.PullListFragment_list_padding, -1);
        if (padding != -1) {
            paddingTop = padding;
            paddingBottom = padding;
            paddingLeft = padding;
            paddingRight = padding;
        }

        paddingTop = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingTop, paddingTop);
        paddingBottom = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingBottom, paddingBottom);
        paddingLeft = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingLeft, paddingLeft);
        paddingRight = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingRight, paddingRight);

        listView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);

        /**
         * apply pull modes
         */

        final int topMode = a.getInt(R.styleable.PullListFragment_top_mode, MODE_PULL);
        if (topMode != MODE_PULL) {
            enableTopPull(false);
        }

        final int bottomMode = a.getInt(R.styleable.PullListFragment_bottom_mode, MODE_PULL);
        if (bottomMode != MODE_PULL) {
            enableBottomPull(false);
        }

        /**
         * apply custom pulled views
         */

        final int topViewResId = a.getResourceId(R.styleable.PullListFragment_top_view, -1);
        if (topViewResId != -1) {
            setTopPulledView(topViewResId);
        }

        final int bottomViewResId = a.getResourceId(R.styleable.PullListFragment_bottom_view, -1);
        if (bottomViewResId != -1) {
            setBottomPulledView(bottomViewResId);
        }

        /**
         * apply custom text to default views
         */

        if (topManager != null) {
            final String pullStartedText = a.getString(R.styleable.PullListFragment_top_pullStartedText);
            if (pullStartedText != null) {
                topManager.setPullStartedText(pullStartedText);
            }

            final String pullThresholdText = a.getString(R.styleable.PullListFragment_top_pullThresholdText);
            if (pullThresholdText != null) {
                topManager.setPullThresholdText(pullThresholdText);
            }

            final String refreshingText = a.getString(R.styleable.PullListFragment_top_refreshingText);
            if (refreshingText != null) {
                topManager.setRefreshingText(refreshingText);
            }

            final String refreshSuccessText = a.getString(R.styleable.PullListFragment_top_refreshSuccessText);
            if (refreshSuccessText != null) {
                topManager.setRefreshSuccessText(refreshSuccessText);
            }

            final String refreshFailedText = a.getString(R.styleable.PullListFragment_top_refreshFailedText);
            if (refreshFailedText != null) {
                topManager.setRefreshFailedText(refreshFailedText);
            }

            final int bgColor = a.getInt(R.styleable.PullListFragment_top_backgroundColor, -1);
            if (bgColor != -1) {
                topManager.setBackgroundColor(bgColor);
            }

            final int innerBgColor = a.getInt(R.styleable.PullListFragment_top_innerBackgroundColor, -1);
            if (innerBgColor != -1) {
                topManager.setInnerBackgroundColor(innerBgColor);
            }

            final int textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_top_textSize,
                    (int) topManager.getTextSize());
            topManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

            final int textColor = a.getInt(R.styleable.PullListFragment_top_textColor,
                    topManager.getTextColor());
            topManager.setTextColor(textColor);
        }

        if (bottomManager != null) {
            final String pullStartedText = a.getString(R.styleable.PullListFragment_bottom_pullStartedText);
            if (pullStartedText != null) {
                bottomManager.setPullStartedText(pullStartedText);
            }

            final String pullThresholdText = a.getString(R.styleable.PullListFragment_bottom_pullThresholdText);
            if (pullThresholdText != null) {
                bottomManager.setPullThresholdText(pullThresholdText);
            }

            final String refreshingText = a.getString(R.styleable.PullListFragment_bottom_refreshingText);
            if (refreshingText != null) {
                bottomManager.setRefreshingText(refreshingText);
            }

            final String refreshSuccessText = a
                    .getString(R.styleable.PullListFragment_bottom_refreshSuccessText);
            if (refreshSuccessText != null) {
                bottomManager.setRefreshSuccessText(refreshSuccessText);
            }

            final String refreshFailedText = a.getString(R.styleable.PullListFragment_bottom_refreshFailedText);
            if (refreshFailedText != null) {
                bottomManager.setRefreshFailedText(refreshFailedText);
            }

            final int bgColor = a.getInt(R.styleable.PullListFragment_bottom_backgroundColor, -1);
            if (bgColor != -1) {
                bottomManager.setBackgroundColor(bgColor);
            }

            final int innerBgColor = a.getInt(R.styleable.PullListFragment_bottom_innerBackgroundColor, -1);
            if (innerBgColor != -1) {
                bottomManager.setInnerBackgroundColor(innerBgColor);
            }

            final float textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_bottom_textSize,
                    (int) bottomManager.getTextSize());
            bottomManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

            final int textColor = a.getInt(R.styleable.PullListFragment_bottom_textSize,
                    bottomManager.getTextColor());
            bottomManager.setTextColor(textColor);
        }

        /**
         * Apply custom empty view configurations
         */

        final int emptyViewId = a.getResourceId(R.styleable.PullListFragment_empty_view, -1);
        if (emptyViewId != -1) {
            setEmptyView(emptyViewId);
        } else {
            final String emptyText = a.getString(R.styleable.PullListFragment_empty_text);
            if (emptyText != null) {
                setEmptyText(emptyText);
            }
        }

        /**
         * Apply custom behaviour to scroller
         */

        final int delay = a.getInt(R.styleable.PullListFragment_pull_delay,
                scroller.getOnRequestCompleteDelay());
        scroller.setOnRequestCompleteDelay(delay);

        final float damping = a.getFloat(R.styleable.PullListFragment_pull_damping, scroller.getDamping());
        scroller.setDamping(damping);

        final float easing = a.getFloat(R.styleable.PullListFragment_release_easing, scroller.getEasing());
        scroller.setEasing(easing);

        a.recycle();
    }
}

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

public Dialog applyStyle(int resId) {
    Context context = getContext();
    TypedArray a = context.obtainStyledAttributes(resId, R.styleable.Dialog);

    int layout_width = mLayoutWidth;
    int layout_height = mLayoutHeight;
    boolean layoutParamsDefined = false;
    int titleTextAppearance = 0;
    int titleTextColor = 0;
    boolean titleTextColorDefined = false;
    int actionBackground = 0;
    int actionRipple = 0;
    int actionTextAppearance = 0;
    ColorStateList actionTextColors = null;
    int positiveActionBackground = 0;
    int positiveActionRipple = 0;
    int positiveActionTextAppearance = 0;
    ColorStateList positiveActionTextColors = null;
    int negativeActionBackground = 0;
    int negativeActionRipple = 0;
    int negativeActionTextAppearance = 0;
    ColorStateList negativeActionTextColors = null;
    int neutralActionBackground = 0;
    int neutralActionRipple = 0;
    int neutralActionTextAppearance = 0;
    ColorStateList neutralActionTextColors = null;

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

        if (attr == R.styleable.Dialog_android_layout_width) {
            layout_width = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;//from  ww  w  .j  a  v  a2s.c o  m
        } else if (attr == R.styleable.Dialog_android_layout_height) {
            layout_height = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;
        } else if (attr == R.styleable.Dialog_di_maxWidth)
            maxWidth(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxHeight)
            maxHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_dimAmount)
            dimAmount(a.getFloat(attr, 0));
        else if (attr == R.styleable.Dialog_di_backgroundColor)
            backgroundColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxElevation)
            maxElevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_elevation)
            elevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cornerRadius)
            cornerRadius(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_layoutDirection)
            layoutDirection(a.getInteger(attr, 0));
        else if (attr == R.styleable.Dialog_di_titleTextAppearance)
            titleTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_titleTextColor) {
            titleTextColor = a.getColor(attr, 0);
            titleTextColorDefined = true;
        } else if (attr == R.styleable.Dialog_di_actionBackground)
            actionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionRipple)
            actionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextAppearance)
            actionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextColor)
            actionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_positiveActionBackground)
            positiveActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionRipple)
            positiveActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextAppearance)
            positiveActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextColor)
            positiveActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_negativeActionBackground)
            negativeActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionRipple)
            negativeActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextAppearance)
            negativeActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextColor)
            negativeActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_neutralActionBackground)
            neutralActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionRipple)
            neutralActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextAppearance)
            neutralActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextColor)
            neutralActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_inAnimation)
            inAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_outAnimation)
            outAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerColor)
            dividerColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerHeight)
            dividerHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cancelable)
            cancelable(a.getBoolean(attr, true));
        else if (attr == R.styleable.Dialog_di_canceledOnTouchOutside)
            canceledOnTouchOutside(a.getBoolean(attr, true));
    }

    a.recycle();

    if (layoutParamsDefined)
        layoutParams(layout_width, layout_height);

    if (titleTextAppearance != 0)
        titleTextAppearance(titleTextAppearance);

    if (titleTextColorDefined)
        titleColor(titleTextColor);

    if (actionBackground != 0)
        actionBackground(actionBackground);

    if (actionRipple != 0)
        actionRipple(actionRipple);

    if (actionTextAppearance != 0)
        actionTextAppearance(actionTextAppearance);

    if (actionTextColors != null)
        actionTextColor(actionTextColors);

    if (positiveActionBackground != 0)
        positiveActionBackground(positiveActionBackground);

    if (positiveActionRipple != 0)
        positiveActionRipple(positiveActionRipple);

    if (positiveActionTextAppearance != 0)
        positiveActionTextAppearance(positiveActionTextAppearance);

    if (positiveActionTextColors != null)
        positiveActionTextColor(positiveActionTextColors);

    if (negativeActionBackground != 0)
        negativeActionBackground(negativeActionBackground);

    if (negativeActionRipple != 0)
        negativeActionRipple(negativeActionRipple);

    if (negativeActionTextAppearance != 0)
        negativeActionTextAppearance(negativeActionTextAppearance);

    if (negativeActionTextColors != null)
        negativeActionTextColor(negativeActionTextColors);

    if (neutralActionBackground != 0)
        neutralActionBackground(neutralActionBackground);

    if (neutralActionRipple != 0)
        neutralActionRipple(neutralActionRipple);

    if (neutralActionTextAppearance != 0)
        neutralActionTextAppearance(neutralActionTextAppearance);

    if (neutralActionTextColors != null)
        neutralActionTextColor(neutralActionTextColors);

    return this;
}

From source file:com.gigamole.library.ntb.NavigationTabBar.java

public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//w ww. j a v  a  2s.  c  o  m

    // Always draw
    setWillNotDraw(false);
    // More speed!
    setLayerType(LAYER_TYPE_HARDWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, 0));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, 0));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.cocoa.cocoautils.widget.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//www .  j av  a2 s.com

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, -2f));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, -2f));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}