List of usage examples for android.content.res TypedArray getDimensionPixelSize
public int getDimensionPixelSize(@StyleableRes int index, int defValue)
From source file:com.commonsware.cwac.crossport.design.widget.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, 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); // Text colors/sizes come from the text appearance first final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, R.styleable.TextAppearance); try {//from w w w .j a v a2 s . co m mTabTextSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); mTabTextColors = ta.getColorStateList(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(); // TODO add attr for these 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:android.support.design.widget.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 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); // Text colors/sizes come from the text appearance first final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, android.support.v7.appcompat.R.styleable.TextAppearance); try {// w w w . ja v a 2 s.com 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(); // TODO add attr for these 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: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/* w w w . j a v a 2s .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.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);/* ww w. j a v a 2 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.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.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
protected boolean setValueFromTheme(TypedArray remoteTypedArray, final int[] padding, final int localAttrId, final int remoteTypedArrayIndex) { try {//from ww w.j a v a 2 s . com switch (localAttrId) { case android.R.attr.background: Drawable keyboardBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (keyboardBackground == null) return false; CompatUtils.setViewBackgroundDrawable(this, keyboardBackground); break; case android.R.attr.paddingLeft: padding[0] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[0] == -1) return false; break; case android.R.attr.paddingTop: padding[1] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[1] == -1) return false; break; case android.R.attr.paddingRight: padding[2] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[2] == -1) return false; break; case android.R.attr.paddingBottom: padding[3] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[3] == -1) return false; break; case R.attr.keyBackground: mKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (mKeyBackground == null) return false; break; case R.attr.keyHysteresisDistance: mKeyHysteresisDistance = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (mKeyHysteresisDistance == -1) return false; break; case R.attr.verticalCorrection: mOriginalVerticalCorrection = mVerticalCorrection = remoteTypedArray .getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (mOriginalVerticalCorrection == -1) return false; break; case R.attr.keyTextSize: mKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mKeyTextSize == -1) return false; // you might ask yourself "why did Menny sqrt root the factor?" // I'll tell you; the factor is mostly for the height, not the // font size, // but I also factorize the font size because I want the text to // be a little like // the key size. // the whole factor maybe too much, so I ease that a bit. if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyTextSize = (float) (mKeyTextSize * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInLandscape())); else mKeyTextSize = (float) (mKeyTextSize * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInPortrait())); Logger.d(TAG, "AnySoftKeyboardTheme_keyTextSize " + mKeyTextSize); break; case R.attr.keyTextColor: mKeyTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mKeyTextColor == null) { mKeyTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } break; case R.attr.labelTextSize: mLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mLabelTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.keyboardNameTextSize: mKeyboardNameTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mKeyboardNameTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.keyboardNameTextColor: mKeyboardNameTextColor = remoteTypedArray.getColor(remoteTypedArrayIndex, Color.WHITE); break; case R.attr.shadowColor: mShadowColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0); break; case R.attr.shadowRadius: mShadowRadius = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.shadowOffsetX: mShadowOffsetX = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.shadowOffsetY: mShadowOffsetY = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.backgroundDimAmount: mBackgroundDimAmount = remoteTypedArray.getFloat(remoteTypedArrayIndex, -1f); if (mBackgroundDimAmount == -1f) return false; break; case R.attr.keyPreviewBackground: Drawable keyPreviewBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (keyPreviewBackground == null) return false; mPreviewPopupTheme.setPreviewKeyBackground(keyPreviewBackground); break; case R.attr.keyPreviewTextColor: mPreviewPopupTheme.setPreviewKeyTextColor(remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFF)); break; case R.attr.keyPreviewTextSize: mPreviewPopupTheme .setPreviewKeyTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0)); break; case R.attr.keyPreviewLabelTextSize: mPreviewPopupTheme .setPreviewLabelTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0)); break; case R.attr.keyPreviewOffset: mPreviewPopupTheme .setVerticalOffset(remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0)); break; case R.attr.previewAnimationType: int previewAnimationType = remoteTypedArray.getInteger(remoteTypedArrayIndex, -1); if (previewAnimationType == -1) return false; mPreviewPopupTheme.setPreviewAnimationType(previewAnimationType); break; case R.attr.keyTextStyle: int textStyle = remoteTypedArray.getInt(remoteTypedArrayIndex, 0); switch (textStyle) { case 0: mKeyTextStyle = Typeface.DEFAULT; break; case 1: mKeyTextStyle = Typeface.DEFAULT_BOLD; break; case 2: mKeyTextStyle = Typeface.defaultFromStyle(Typeface.ITALIC); break; default: mKeyTextStyle = Typeface.defaultFromStyle(textStyle); break; } mPreviewPopupTheme.setKeyStyle(mKeyTextStyle); break; case R.attr.keyHorizontalGap: float themeHorizontalKeyGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeHorizontalKeyGap == -1) return false; mKeyboardDimens.setHorizontalKeyGap(themeHorizontalKeyGap); break; case R.attr.keyVerticalGap: float themeVerticalRowGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeVerticalRowGap == -1) return false; mKeyboardDimens.setVerticalRowGap(themeVerticalRowGap); break; case R.attr.keyNormalHeight: int themeNormalKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeNormalKeyHeight == -1) return false; mKeyboardDimens.setNormalKeyHeight(themeNormalKeyHeight); break; case R.attr.keyLargeHeight: int themeLargeKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeLargeKeyHeight == -1) return false; mKeyboardDimens.setLargeKeyHeight(themeLargeKeyHeight); break; case R.attr.keySmallHeight: int themeSmallKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeSmallKeyHeight == -1) return false; mKeyboardDimens.setSmallKeyHeight(themeSmallKeyHeight); break; case R.attr.hintTextSize: mHintTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mHintTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.hintTextColor: mHintTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mHintTextColor == null) { mHintTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } break; case R.attr.hintLabelVAlign: mHintLabelVAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.BOTTOM); break; case R.attr.hintLabelAlign: mHintLabelAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.RIGHT); break; case R.attr.hintOverflowLabel: mHintOverflowLabel = remoteTypedArray.getString(remoteTypedArrayIndex); break; } return true; } catch (Exception e) { // on API changes, so the incompatible themes wont crash me.. e.printStackTrace(); return false; } }
From source file:com.aosijia.dragonbutler.ui.widget.ActionSheet.java
private Attributes readAttribute() { Attributes attrs = new Attributes(getActivity()); TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.ActionSheet, R.attr.actionSheetStyle, 0); Drawable background = a.getDrawable(R.styleable.ActionSheet_actionSheetBackground); if (background != null) { attrs.background = background;/*from w w w . j av a 2 s . c o m*/ } Drawable cancelButtonBackground = a.getDrawable(R.styleable.ActionSheet_cancelButtonBackground); if (cancelButtonBackground != null) { attrs.cancelButtonBackground = cancelButtonBackground; } Drawable otherButtonTopBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonTopBackground); if (otherButtonTopBackground != null) { attrs.otherButtonTopBackground = otherButtonTopBackground; } Drawable otherButtonMiddleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonMiddleBackground); if (otherButtonMiddleBackground != null) { attrs.otherButtonMiddleBackground = otherButtonMiddleBackground; } Drawable otherButtonBottomBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonBottomBackground); if (otherButtonBottomBackground != null) { attrs.otherButtonBottomBackground = otherButtonBottomBackground; } Drawable otherButtonSingleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonSingleBackground); if (otherButtonSingleBackground != null) { attrs.otherButtonSingleBackground = otherButtonSingleBackground; } attrs.cancelButtonTextColor = a.getColor(R.styleable.ActionSheet_cancelButtonTextColor, attrs.cancelButtonTextColor); attrs.otherButtonTextColor = a.getColor(R.styleable.ActionSheet_otherButtonTextColor, attrs.otherButtonTextColor); attrs.padding = (int) a.getDimension(R.styleable.ActionSheet_actionSheetPadding, attrs.padding); attrs.otherButtonSpacing = (int) a.getDimension(R.styleable.ActionSheet_otherButtonSpacing, attrs.otherButtonSpacing); attrs.cancelButtonMarginTop = (int) a.getDimension(R.styleable.ActionSheet_cancelButtonMarginTop, attrs.cancelButtonMarginTop); attrs.actionSheetTextSize = a.getDimensionPixelSize(R.styleable.ActionSheet_actionSheetTextSize, (int) attrs.actionSheetTextSize); a.recycle(); return attrs; }
From source file:com.base.view.slidemenu.SlideMenu.java
public SlideMenu(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // we want to draw drop shadow of content mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mVelocityTracker = VelocityTracker.obtain(); mContentHitRect = new Rect(); mEdgeSlideDetectRect = new Rect(); STATUS_BAR_HEIGHT = (int) getStatusBarHeight(context); setWillNotDraw(false);/*from w w w .j a v a 2 s. c om*/ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlideMenu, defStyle, 0); // Set the shadow attributes setPrimaryShadowWidth(a.getDimension(R.styleable.SlideMenu_primaryShadowWidth, 30)); setSecondaryShadowWidth(a.getDimension(R.styleable.SlideMenu_secondaryShadowWidth, 30)); Drawable primaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_primaryShadowDrawable); if (null == primaryShadowDrawable) { primaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT, new int[] { Color.TRANSPARENT, Color.argb(99, 0, 0, 0) }); } setPrimaryShadowDrawable(primaryShadowDrawable); Drawable secondaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_secondaryShadowDrawable); if (null == secondaryShadowDrawable) { secondaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT, new int[] { Color.argb(99, 0, 0, 0), Color.TRANSPARENT }); } setSecondaryShadowDrawable(secondaryShadowDrawable); int interpolatorResId = a.getResourceId(R.styleable.SlideMenu_interpolator, -1); setInterpolator(-1 == interpolatorResId ? DEFAULT_INTERPOLATOR : AnimationUtils.loadInterpolator(context, interpolatorResId)); mSlideDirectionFlag = a.getInt(R.styleable.SlideMenu_slideDirection, FLAG_DIRECTION_LEFT | FLAG_DIRECTION_RIGHT); setEdgeSlideEnable(a.getBoolean(R.styleable.SlideMenu_edgeSlide, false)); setEdgetSlideWidth(a.getDimensionPixelSize(R.styleable.SlideMenu_edgeSlideWidth, 100)); a.recycle(); setFocusable(true); setFocusableInTouchMode(true); }
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 ww w . jav a 2 s. c o 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.mci.firstidol.view.ActionSheet.java
private Attributes readAttribute() { Attributes attrs = new Attributes(getActivity()); TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.ActionSheet, R.attr.actionSheetStyle, 0); Drawable background = a.getDrawable(R.styleable.ActionSheet_actionSheetBackground); if (background != null) { attrs.background = background;//from w ww .j a v a2 s. c om } Drawable cancelButtonBackground = a.getDrawable(R.styleable.ActionSheet_cancelButtonBackground); if (cancelButtonBackground != null) { attrs.cancelButtonBackground = cancelButtonBackground; } Drawable otherButtonTopBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonTopBackground); if (otherButtonTopBackground != null) { attrs.otherButtonTopBackground = otherButtonTopBackground; } Drawable otherButtonMiddleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonMiddleBackground); if (otherButtonMiddleBackground != null) { attrs.otherButtonMiddleBackground = otherButtonMiddleBackground; } Drawable otherButtonBottomBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonBottomBackground); if (otherButtonBottomBackground != null) { attrs.otherButtonBottomBackground = otherButtonBottomBackground; } Drawable otherButtonSingleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonSingleBackground); if (otherButtonSingleBackground != null) { attrs.otherButtonSingleBackground = otherButtonSingleBackground; } Drawable actionSheetTitleBackground = a.getDrawable(R.styleable.ActionSheet_titleTXTBackground); if (actionSheetTitleBackground != null) { attrs.actionSheetTitleBackground = actionSheetTitleBackground; } attrs.cancelButtonTextColor = a.getColor(R.styleable.ActionSheet_cancelButtonTextColor, attrs.cancelButtonTextColor); attrs.otherButtonTextColor = a.getColor(R.styleable.ActionSheet_otherButtonTextColor, attrs.otherButtonTextColor); attrs.padding = (int) a.getDimension(R.styleable.ActionSheet_actionSheetPadding, attrs.padding); attrs.otherButtonSpacing = (int) a.getDimension(R.styleable.ActionSheet_otherButtonSpacing, attrs.otherButtonSpacing); attrs.cancelButtonMarginTop = (int) a.getDimension(R.styleable.ActionSheet_cancelButtonMarginTop, attrs.cancelButtonMarginTop); attrs.actionSheetTextSize = a.getDimensionPixelSize(R.styleable.ActionSheet_actionSheetTextSize, (int) attrs.actionSheetTextSize); a.recycle(); return attrs; }
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 ww w . j av a2s. com*/ 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(); } }