List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs)
From source file:brostore.maquillage.custom.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);// ww w . ja va2 s .com setWillNotDraw(false); tabTypeface = DataManager.getInstance(getContext()).getFont("ElleNovaC-Light.otf"); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); tabsContainer.setClickable(false); tabsContainer.setFocusable(false); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java
@SuppressWarnings("ResourceAsColor") public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB/*from w ww. j av a 2 s .co m*/ // 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, AUTO_SIZE)); 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, AUTO_SIZE)); 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(); } }
From source file:be.blinkt.openvpn.views.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/* www . j ava2 s .com*/ setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); //Default color will be 'textColorPrimary' int colorPrimary = context.getResources().getColor(android.R.color.primary_text_dark); setTextColor(colorPrimary); underlineColor = colorPrimary; dividerColor = colorPrimary; indicatorColor = colorPrimary; DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize); ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX); if (colorStateList != null) { tabTextColor = colorStateList; } paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, paddingLeft); paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, paddingRight); a.recycle(); //In case we have the padding they must be equal so we take the biggest if (paddingRight < paddingLeft) { paddingRight = paddingLeft; } if (paddingLeft < paddingRight) { paddingLeft = paddingRight; } // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle); tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.BOLD); tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.BOLD); tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP); tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.astuetz.PagerSlidingTabStripMenu.java
public PagerSlidingTabStripMenu(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // setFillViewport(true); setWillNotDraw(false);/*from w w w . j av a 2s . c o m*/ tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); tabsContainer.setGravity(Gravity.CENTER); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); mTabPaddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabPaddingTop, dm); mTabPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabPaddingBottom, dm); mTabDrawablePadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabDrawablePadding, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); mIconPostion = IconPosition .fromValue(a.getInteger(R.styleable.PagerSlidingTabStrip_pstsIconPosition, mIconPostion.value)); mTabPaddingTop = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingTop, mTabPaddingTop); mTabPaddingBottom = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingBottom, mTabPaddingBottom); mTabDrawablePadding = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabDrawablePadding, mTabDrawablePadding); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:android.transitions.everywhere.Transition.java
/** * Perform inflation from XML and apply a class-specific base style from a * theme attribute or style resource. This constructor of Transition allows * subclasses to use their own base style when they are inflating. * * @param context The Context the transition is running in, through which it can * access the current theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the transition. *///w ww . j av a2 s . c o m public Transition(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Transition); long duration = a.getInt(R.styleable.Transition_duration, -1); if (duration >= 0) { setDuration(duration); } else { duration = a.getInt(R.styleable.Transition_android_duration, -1); if (duration >= 0) { setDuration(duration); } } long startDelay = a.getInt(R.styleable.Transition_startDelay, -1); if (startDelay > 0) { setStartDelay(startDelay); } int resID = a.getResourceId(R.styleable.Transition_interpolator, 0); if (resID > 0) { setInterpolator(AnimationUtils.loadInterpolator(context, resID)); } else { resID = a.getResourceId(R.styleable.Transition_android_interpolator, 0); if (resID > 0) { setInterpolator(AnimationUtils.loadInterpolator(context, resID)); } } String matchOrder = a.getString(R.styleable.Transition_matchOrder); if (matchOrder != null) { setMatchOrder(parseMatchOrder(matchOrder)); } a.recycle(); }
From source file:android.app.FragmentManager.java
@Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { if (!"fragment".equals(name)) { return null; }//from w ww . j a va2 s.com String fname = attrs.getAttributeValue(null, "class"); TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment); if (fname == null) { fname = a.getString(com.android.internal.R.styleable.Fragment_name); } int id = a.getResourceId(com.android.internal.R.styleable.Fragment_id, View.NO_ID); String tag = a.getString(com.android.internal.R.styleable.Fragment_tag); a.recycle(); int containerId = parent != null ? parent.getId() : 0; if (containerId == View.NO_ID && id == View.NO_ID && tag == null) { throw new IllegalArgumentException(attrs.getPositionDescription() + ": Must specify unique android:id, android:tag, or have a parent with" + " an id for " + fname); } // If we restored from a previous state, we may already have // instantiated this fragment from the state and should use // that instance instead of making a new one. Fragment fragment = id != View.NO_ID ? findFragmentById(id) : null; if (fragment == null && tag != null) { fragment = findFragmentByTag(tag); } if (fragment == null && containerId != View.NO_ID) { fragment = findFragmentById(containerId); } if (FragmentManagerImpl.DEBUG) Log.v(TAG, "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment); if (fragment == null) { fragment = Fragment.instantiate(context, fname); fragment.mFromLayout = true; fragment.mFragmentId = id != 0 ? id : containerId; fragment.mContainerId = containerId; fragment.mTag = tag; fragment.mInLayout = true; fragment.mFragmentManager = this; fragment.onInflate(mActivity, attrs, fragment.mSavedFragmentState); addFragment(fragment, true); } else if (fragment.mInLayout) { // A fragment already exists and it is not one we restored from // previous state. throw new IllegalArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x" + Integer.toHexString(id) + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId) + " with another fragment for " + fname); } else { // This fragment was retained from a previous instance; get it // going now. fragment.mInLayout = true; // If this fragment is newly instantiated (either right now, or // from last saved state), then give it the attributes to // initialize itself. if (!fragment.mRetaining) { fragment.onInflate(mActivity, attrs, fragment.mSavedFragmentState); } } // If we haven't finished entering the CREATED state ourselves yet, // push the inflated child fragment along. if (mCurState < Fragment.CREATED && fragment.mFromLayout) { moveToState(fragment, Fragment.CREATED, 0, 0, false); } else { moveToState(fragment); } if (fragment.mView == null) { throw new IllegalStateException("Fragment " + fname + " did not create a view."); } if (id != 0) { fragment.mView.setId(id); } if (fragment.mView.getTag() == null) { fragment.mView.setTag(tag); } return fragment.mView; }
From source file:com.astuetz.PagerSlidingTabStripPlus.java
public PagerSlidingTabStripPlus(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true); // ScrollView stretch his content height to fill his viewport setWillNotDraw(false);/*from w w w. j a v a 2s . c o m*/ // Layout parameters tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); // Converting values to floating point value scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPaddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingLeft, dm); tabPaddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingRight, dm); tabPaddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingTop, dm); tabPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingBottom, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStripPlus); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStripPlus_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStripPlus_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStripPlus_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsDividerPadding, dividerPadding); tabPaddingLeft = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingLeft, tabPaddingLeft); tabPaddingRight = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingRight, tabPaddingRight); tabPaddingTop = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingTop, tabPaddingTop); tabPaddingBottom = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingBottom, tabPaddingBottom); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStripPlus_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStripPlus_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStripPlus_pstsTextAllCaps, textAllCaps); textColorTab = a.getColorStateList(R.styleable.PagerSlidingTabStripPlus_pstsTextColorTab); indicatorAlpha = a.getInteger(R.styleable.PagerSlidingTabStripPlus_pstsIndicatorAlpha, indicatorAlpha); hasDivider = a.getBoolean(R.styleable.PagerSlidingTabStripPlus_pstsHasDivider, hasDivider); tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsTabTextSize, tabTextSize); tabsGravity = a.getInteger(R.styleable.PagerSlidingTabStripPlus_pstsTabsTitleGravity, tabsGravity); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:android.support.v7.widget.GridLayout.java
/** * {@inheritDoc}//from www .j a v a2 s . c o m */ public GridLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDefaultGap = context.getResources().getDimensionPixelOffset(R.dimen.default_gap); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridLayout); try { setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT)); setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT)); setOrientation(a.getInt(ORIENTATION, DEFAULT_ORIENTATION)); setUseDefaultMargins(a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS)); setAlignmentMode(a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE)); setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED)); setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED)); } finally { a.recycle(); } }
From source file:android.app.Activity.java
/** * Standard implementation of//from w w w . ja va 2 s. c o m * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)} * used when inflating with the LayoutInflater returned by {@link #getSystemService}. * This implementation handles <fragment> tags to embed fragments inside * of the activity. * * @see android.view.LayoutInflater#createView * @see android.view.Window#getLayoutInflater */ public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { if (!"fragment".equals(name)) { return onCreateView(name, context, attrs); } String fname = attrs.getAttributeValue(null, "class"); TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment); if (fname == null) { fname = a.getString(com.android.internal.R.styleable.Fragment_name); } int id = a.getResourceId(com.android.internal.R.styleable.Fragment_id, View.NO_ID); String tag = a.getString(com.android.internal.R.styleable.Fragment_tag); a.recycle(); int containerId = parent != null ? parent.getId() : 0; if (containerId == View.NO_ID && id == View.NO_ID && tag == null) { throw new IllegalArgumentException(attrs.getPositionDescription() + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname); } // If we restored from a previous state, we may already have // instantiated this fragment from the state and should use // that instance instead of making a new one. Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null; if (fragment == null && tag != null) { fragment = mFragments.findFragmentByTag(tag); } if (fragment == null && containerId != View.NO_ID) { fragment = mFragments.findFragmentById(containerId); } if (FragmentManagerImpl.DEBUG) Log.v(TAG, "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment); if (fragment == null) { fragment = Fragment.instantiate(this, fname); fragment.mFromLayout = true; fragment.mFragmentId = id != 0 ? id : containerId; fragment.mContainerId = containerId; fragment.mTag = tag; fragment.mInLayout = true; fragment.mFragmentManager = mFragments; fragment.onInflate(this, attrs, fragment.mSavedFragmentState); mFragments.addFragment(fragment, true); } else if (fragment.mInLayout) { // A fragment already exists and it is not one we restored from // previous state. throw new IllegalArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x" + Integer.toHexString(id) + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId) + " with another fragment for " + fname); } else { // This fragment was retained from a previous instance; get it // going now. fragment.mInLayout = true; // If this fragment is newly instantiated (either right now, or // from last saved state), then give it the attributes to // initialize itself. if (!fragment.mRetaining) { fragment.onInflate(this, attrs, fragment.mSavedFragmentState); } mFragments.moveToState(fragment); } if (fragment.mView == null) { throw new IllegalStateException("Fragment " + fname + " did not create a view."); } if (id != 0) { fragment.mView.setId(id); } if (fragment.mView.getTag() == null) { fragment.mView.setTag(tag); } return fragment.mView; }