List of usage examples for android.content.res TypedArray getResources
public Resources getResources()
From source file:nz.org.winters.android.custompreference.ColorPickerPreferenceCompat.java
private void initAttrs(AttributeSet attrs, int defStyle) { TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference, defStyle, defStyle);/*from ww w . j a va 2 s. c om*/ try { mItemLayoutId = a.getResourceId(R.styleable.ColorPickerPreference_cal_itemLayout, mItemLayoutId); mNumColumns = a.getInteger(R.styleable.ColorPickerPreference_cal_numColumns, mNumColumns); int choicesResId = a.getResourceId(R.styleable.ColorPickerPreference_cal_choices, R.array.default_color_choice_values); if (choicesResId > 0) { String[] choices = a.getResources().getStringArray(choicesResId); mColorChoices = new int[choices.length]; for (int i = 0; i < choices.length; i++) { mColorChoices[i] = Color.parseColor(choices[i]); } } } finally { a.recycle(); } setWidgetLayoutResource(mItemLayoutId); }
From source file:com.fast.access.kam.widget.colorpicker.dashclockpicker.ColorPreference.java
private void initAttrs(AttributeSet attrs, int defStyle) { TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ColorPreference, defStyle, defStyle);// www. jav a 2s. c om try { mItemLayoutId = a.getResourceId(R.styleable.ColorPreference_itemLayout, mItemLayoutId); mNumColumns = a.getInteger(R.styleable.ColorPreference_numColumns, mNumColumns); int choicesResId = a.getResourceId(R.styleable.ColorPreference_choices, R.array.default_color_choice_values); if (choicesResId > 0) { String[] choices = a.getResources().getStringArray(choicesResId); mColorChoices = new int[choices.length]; for (int i = 0; i < choices.length; i++) { mColorChoices[i] = Color.parseColor(choices[i]); } } } finally { a.recycle(); } setWidgetLayoutResource(mItemLayoutId); }
From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java
void loadFromAttributes(AttributeSet attrs, int defStyleAttr) { float autoSizeMinTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE; float autoSizeMaxTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE; float autoSizeStepGranularityInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE; TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0); if (a.hasValue(R.styleable.AppCompatTextView_autoSizeTextType)) { mAutoSizeTextType = a.getInt(R.styleable.AppCompatTextView_autoSizeTextType, TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE); }/*from ww w . ja v a2s . co m*/ if (a.hasValue(R.styleable.AppCompatTextView_autoSizeStepGranularity)) { autoSizeStepGranularityInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeStepGranularity, UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE); } if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMinTextSize)) { autoSizeMinTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMinTextSize, UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE); } if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMaxTextSize)) { autoSizeMaxTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMaxTextSize, UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE); } if (a.hasValue(R.styleable.AppCompatTextView_autoSizePresetSizes)) { final int autoSizeStepSizeArrayResId = a .getResourceId(R.styleable.AppCompatTextView_autoSizePresetSizes, 0); if (autoSizeStepSizeArrayResId > 0) { final TypedArray autoSizePreDefTextSizes = a.getResources() .obtainTypedArray(autoSizeStepSizeArrayResId); setupAutoSizeUniformPresetSizes(autoSizePreDefTextSizes); autoSizePreDefTextSizes.recycle(); } } a.recycle(); if (supportsAutoSizeText()) { if (mAutoSizeTextType == TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM) { // If uniform auto-size has been specified but preset values have not been set then // replace the auto-size configuration values that have not been specified with the // defaults. if (!mHasPresetAutoSizeValues) { final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); if (autoSizeMinTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) { autoSizeMinTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_AUTO_SIZE_MIN_TEXT_SIZE_IN_SP, displayMetrics); } if (autoSizeMaxTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) { autoSizeMaxTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_AUTO_SIZE_MAX_TEXT_SIZE_IN_SP, displayMetrics); } if (autoSizeStepGranularityInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) { autoSizeStepGranularityInPx = DEFAULT_AUTO_SIZE_GRANULARITY_IN_PX; } validateAndSetAutoSizeTextTypeUniformConfiguration(autoSizeMinTextSizeInPx, autoSizeMaxTextSizeInPx, autoSizeStepGranularityInPx); } setupAutoSizeText(); } } else { mAutoSizeTextType = TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE; } }
From source file:com.wl.tabguidance.utils.TabLayoutTitleStrip.java
public TabLayoutTitleStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTS//from w ww . j a v a 2s . 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.TabTitleStrip); try { setStripColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_color, DEFAULT_STRIP_COLOR)); setTitleSize(typedArray.getDimension(R.styleable.TabTitleStrip_nts_size, DEFAULT_TITLE_SIZE)); setStripWeight(typedArray.getDimension(R.styleable.TabTitleStrip_nts_weight, DEFAULT_STRIP_WEIGHT)); setStripFactor(typedArray.getFloat(R.styleable.TabTitleStrip_nts_factor, DEFAULT_STRIP_FACTOR)); setStripType(typedArray.getInt(R.styleable.TabTitleStrip_nts_type, StripType.LINE_INDEX)); setStripGravity(typedArray.getInt(R.styleable.TabTitleStrip_nts_gravity, StripGravity.BOTTOM_INDEX)); setTypeface(typedArray.getString(R.styleable.TabTitleStrip_nts_typeface)); setInactiveColor( typedArray.getColor(R.styleable.TabTitleStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.TabTitleStrip_nts_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius( typedArray.getDimension(R.styleable.TabTitleStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS)); // Get titles String[] titles = null; try { final int titlesResId = typedArray.getResourceId(R.styleable.TabTitleStrip_nts_titles, 0); titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId); } catch (Exception exception) { titles = null; exception.printStackTrace(); } finally { if (titles == null) { if (isInEditMode()) { titles = new String[new Random().nextInt(5) + 1]; Arrays.fill(titles, PREVIEW_TITLE); } else titles = new String[0]; } setTitles(titles); } // 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()); } }); } finally { typedArray.recycle(); } }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTS//from ww w. j ava 2 s .c o m // Always draw setWillNotDraw(false); // More speed! setLayerType(LAYER_TYPE_HARDWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabStrip); try { setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR)); setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE)); setStripWeight( typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT)); setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR)); setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX)); setStripGravity( typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX)); setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS)); // Get titles String[] titles = null; try { final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0); titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId); } catch (Exception exception) { titles = null; exception.printStackTrace(); } finally { if (titles == null) { if (isInEditMode()) { titles = new String[new Random().nextInt(5) + 1]; Arrays.fill(titles, PREVIEW_TITLE); } else titles = new String[0]; } setTitles(titles); } // 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()); } }); } finally { typedArray.recycle(); } }
From source file:com.gigamole.navigationtabstrip.NavigationTabStrip.java
public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTS//w ww . ja v a 2 s . c o 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.NavigationTabStrip); try { setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR)); setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE)); setStripWeight( typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT)); setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR)); setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX)); setStripGravity( typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX)); setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS)); // Get titles String[] titles = null; try { final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0); titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId); } catch (Exception exception) { titles = null; exception.printStackTrace(); } finally { if (titles == null) { if (isInEditMode()) { titles = new String[new Random().nextInt(5) + 1]; Arrays.fill(titles, PREVIEW_TITLE); } else titles = new String[0]; } setTitles(titles); } // 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()); } }); } finally { typedArray.recycle(); } }
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 . j ava 2s . c o m*/ // Always draw setWillNotDraw(false); // More speed! setLayerType(LAYER_TYPE_HARDWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false)); setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false)); 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:talex.zsw.baselibrary.widget.NavigationTabBar.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB//from w ww . j a v a 2 s . c om // Always draw setWillNotDraw(false); // More speed! setLayerType(LAYER_TYPE_HARDWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, false)); 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:com.gigamole.library.ntb.NavigationTabBar.java
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB// w ww . j a v a 2 s. co m // Always draw setWillNotDraw(false); // More speed! setLayerType(LAYER_TYPE_HARDWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false)); setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false)); setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true)); setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true)); setIsBadgeUseTypeface( typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false)); setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX)); setBadgePosition( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX)); setBadgeGravity( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX)); setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, 0)); setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, 0)); setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F)); // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); // Set preview models if (isInEditMode()) { // Get preview colors String[] previewColors = null; try { final int previewColorsId = typedArray .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0); previewColors = previewColorsId == 0 ? null : typedArray.getResources().getStringArray(previewColorsId); } catch (Exception exception) { previewColors = null; exception.printStackTrace(); } finally { if (previewColors == null) previewColors = typedArray.getResources().getStringArray(R.array.default_preview); for (String previewColor : previewColors) mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build()); requestLayout(); } } } finally { typedArray.recycle(); } }
From source file:com.cocoa.cocoautils.widget.navigationtabbar.ntb.NavigationTabBar.java
@SuppressWarnings("ResourceAsColor") public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB/*w w w. ja va2 s . c o 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, -2f)); setIsBadgeUseTypeface( typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false)); setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX)); setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, -2f)); setBadgePosition( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX)); setBadgeGravity( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX)); setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR)); setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR)); setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR)); setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F)); setIconSizeFraction( typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE)); // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); // Set preview models if (isInEditMode()) { // Get preview colors String[] previewColors = null; try { final int previewColorsId = typedArray .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0); previewColors = previewColorsId == 0 ? null : typedArray.getResources().getStringArray(previewColorsId); } catch (Exception exception) { previewColors = null; exception.printStackTrace(); } finally { if (previewColors == null) previewColors = typedArray.getResources().getStringArray(R.array.default_preview); for (String previewColor : previewColors) mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build()); requestLayout(); } } } finally { typedArray.recycle(); } }