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.bei.test.view.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from   www . j  a  v a  2s . c om*/
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

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

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabNormalTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabNormalTextSize, dm);
    mTabSelectTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabSelectTextSize, dm);

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            mTabBackgroundResId);
    mTabNormalTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabNormalTextSize,
            mTabNormalTextSize);
    mTabSelectTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabSelectTextSize,
            mTabSelectTextSize);

    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextStyle, mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:com.hanbing.library.android.view.CustomTabLayout23.java

public CustomTabLayout23(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);
    addView(mTabStrip, LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

    TypedArray a = context.obtainStyledAttributes(attrs, com.hanbing.library.android.R.styleable.TabLayout,
            defStyleAttr, com.hanbing.library.android.R.style.Widget_Design_TabLayout);

    mTabStrip.setSelectedIndicatorHeight(
            a.getDimensionPixelSize(com.hanbing.library.android.R.styleable.TabLayout_tabIndicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(
            a.getColor(com.hanbing.library.android.R.styleable.TabLayout_tabIndicatorColor, 0));

    mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
            .getDimensionPixelSize(com.hanbing.library.android.R.styleable.TabLayout_tabPadding, 0);
    mTabPaddingStart = a.getDimensionPixelSize(
            com.hanbing.library.android.R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart);
    mTabPaddingTop = a.getDimensionPixelSize(com.hanbing.library.android.R.styleable.TabLayout_tabPaddingTop,
            mTabPaddingTop);/*from   ww w .  ja  v  a 2s.co  m*/
    mTabPaddingEnd = a.getDimensionPixelSize(com.hanbing.library.android.R.styleable.TabLayout_tabPaddingEnd,
            mTabPaddingEnd);
    mTabPaddingBottom = a.getDimensionPixelSize(
            com.hanbing.library.android.R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom);

    mTabTextAppearance = a.getResourceId(com.hanbing.library.android.R.styleable.TabLayout_tabTextAppearance,
            com.hanbing.library.android.R.style.TextAppearance_Design_Tab);

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

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

    if (a.hasValue(com.hanbing.library.android.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(com.hanbing.library.android.R.styleable.TabLayout_tabSelectedTextColor,
                0);
        mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected);
    }

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

    // TODO add attr for these
    final Resources res = getResources();
    mTabTextMultiLineSize = spToPx(12);//res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line);
    mScrollableTabMinWidth = dpToPx(72);//res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width);

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

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

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

    ThemeUtils.checkAppCompatTheme(context);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout, defStyleAttr,
            R.style.Widget_Design_CoordinatorLayout);
    final int keylineArrayRes = a.getResourceId(R.styleable.CoordinatorLayout_keylines, 0);
    if (keylineArrayRes != 0) {
        final Resources res = context.getResources();
        mKeylines = res.getIntArray(keylineArrayRes);
        final float density = res.getDisplayMetrics().density;
        final int count = mKeylines.length;
        for (int i = 0; i < count; i++) {
            mKeylines[i] *= density;/*from   ww w.  jav  a 2 s  .c om*/
        }
    }
    mStatusBarBackground = a.getDrawable(R.styleable.CoordinatorLayout_statusBarBackground);
    a.recycle();

    setupForInsets();
    super.setOnHierarchyChangeListener(new HierarchyChangeListener());
}

From source file:android.support.v7.internal.widget.ActionBarView.java

public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;//from   w w w  . j  a  v a  2  s. c o m

    // Background is always provided by the container.
    setBackgroundResource(0);

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

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.ActionBar_title);
    mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
    mLogo = a.getDrawable(R.styleable.ActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            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);
            }
        }
    }

    // TODO(trevorjohns): Should these use the android namespace
    mIcon = a.getDrawable(R.styleable.ActionBar_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.ActionBar_homeLayout, R.layout.abc_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.abc_action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.ActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0);

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

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

    mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_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:android.support.design.widget.RaeTabLayout.java

public RaeTabLayout(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, R.styleable.TabLayout, defStyleAttr,
            R.style.Widget_Design_TabLayout);

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

    mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a
            .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0);
    mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart);
    mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop);
    mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd);
    mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom);

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

    // rae attrs/*from  w w  w . j  a va 2 s  . c o m*/
    TypedArray array = context.obtainStyledAttributes(attrs,
            android.support.design.widget.R.styleable.RaeTabLayout);
    setIndicatorWidth(array.getDimensionPixelSize(
            android.support.design.widget.R.styleable.RaeTabLayout_tabIndicatorWidth, 0));
    setIndicatorRaduis(array.getDimensionPixelSize(
            android.support.design.widget.R.styleable.RaeTabLayout_tabIndicatorRadius, 0));
    array.recycle();

    // 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(R.styleable.TabLayout_tabTextColor)) {
        // If we have an explicit text color set, use it instead
        mTabTextColors = a.getColorStateList(R.styleable.TabLayout_tabTextColor);
    }

    if (a.hasValue(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(R.styleable.TabLayout_tabSelectedTextColor, 0);
        mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected);
    }

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

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

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

From source file:com.github.shareme.gwspagerslidingtabstrip.library.PagerSlidingTabStrip.java

@SuppressWarnings("deprecation")
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//w w w.  j  a v  a2 s .  co  m
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

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

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm);

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    //TODO: getColor(int) depreciated fix
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            mTabBackgroundResId);
    mTabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabTextSize, mTabTextSize);
    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextStyle, mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:com.beijing.ocean.multmediademo.view.mytab.TabLayout.java

public TabLayout(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 HorizontalScrollView.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);/*w w  w  .  j  a va2  s. co  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.design.R.styleable.TextAppearance);
    try {
        mTabTextSize = ta
                .getDimensionPixelSize(android.support.design.R.styleable.TextAppearance_android_textSize, 0);
        mTabTextColors = ta
                .getColorStateList(android.support.design.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();

    // TODO add attr for these
    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.server.MountService.java

private void readStorageListLocked() {
    mVolumes.clear();//from ww  w .java  2  s .c o  m
    mVolumeStates.clear();

    Resources resources = mContext.getResources();

    int id = com.android.internal.R.xml.storage_list;
    XmlResourceParser parser = resources.getXml(id);
    AttributeSet attrs = Xml.asAttributeSet(parser);

    try {
        XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
        while (true) {
            XmlUtils.nextElement(parser);

            String element = parser.getName();
            if (element == null)
                break;

            if (TAG_STORAGE.equals(element)) {
                TypedArray a = resources.obtainAttributes(attrs, com.android.internal.R.styleable.Storage);

                String path = a.getString(com.android.internal.R.styleable.Storage_mountPoint);
                int descriptionId = a.getResourceId(com.android.internal.R.styleable.Storage_storageDescription,
                        -1);
                CharSequence description = a
                        .getText(com.android.internal.R.styleable.Storage_storageDescription);
                boolean primary = a.getBoolean(com.android.internal.R.styleable.Storage_primary, false);
                boolean removable = a.getBoolean(com.android.internal.R.styleable.Storage_removable, false);
                boolean emulated = a.getBoolean(com.android.internal.R.styleable.Storage_emulated, false);
                int mtpReserve = a.getInt(com.android.internal.R.styleable.Storage_mtpReserve, 0);
                boolean allowMassStorage = a
                        .getBoolean(com.android.internal.R.styleable.Storage_allowMassStorage, false);
                boolean allowMtp = a.getBoolean(com.android.internal.R.styleable.Storage_allowMtp, true);
                // resource parser does not support longs, so XML value is in megabytes
                long maxFileSize = a.getInt(com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L
                        * 1024L;

                Slog.d(TAG,
                        "got storage path: " + path + " description: " + description + " primary: " + primary
                                + " removable: " + removable + " emulated: " + emulated + " mtpReserve: "
                                + mtpReserve + " allowMassStorage: " + allowMassStorage + " maxFileSize: "
                                + maxFileSize + " allowMtp: " + allowMtp);

                if (emulated) {
                    // For devices with emulated storage, we create separate
                    // volumes for each known user.
                    mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false, true, mtpReserve,
                            false, maxFileSize, null, allowMtp);

                    final UserManagerService userManager = UserManagerService.getInstance();
                    for (UserInfo user : userManager.getUsers(false)) {
                        createEmulatedVolumeForUserLocked(user.getUserHandle());
                    }

                } else {
                    if (path == null || description == null) {
                        Slog.e(TAG, "Missing storage path or description in readStorageList");
                    } else {
                        final StorageVolume volume = new StorageVolume(new File(path), descriptionId, primary,
                                removable, emulated, mtpReserve, allowMassStorage, maxFileSize, null, allowMtp);
                        addVolumeLocked(volume);

                        // Until we hear otherwise, treat as unmounted
                        mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED);
                        volume.setState(Environment.MEDIA_UNMOUNTED);
                    }
                }

                a.recycle();
            }
        }
    } catch (XmlPullParserException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        // Compute storage ID for each physical volume; emulated storage is
        // always 0 when defined.
        int index = isExternalStorageEmulated() ? 1 : 0;
        for (StorageVolume volume : mVolumes) {
            if (!volume.isEmulated()) {
                volume.setStorageId(index++);
            }
        }
        parser.close();
    }
}

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

public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB/*from   ww w. java2s . c  om*/

    // 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));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));
        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, ALL_INDEX));
        setBadgePosition(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, RIGHT_INDEX));
        setBadgeGravity(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, TOP_INDEX));
        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(null, Color.parseColor(previewColor)));
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:android.support.designox.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  w  w  w.java 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(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));
    }

    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.v4ox.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return setWindowInsets(insets);
                }
            });
}