List of usage examples for android.content.res TypedArray getString
@Nullable public String getString(@StyleableRes int index)
From source file:com.glview.transition.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. *///from ww w .j av a2s . c om 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); } long startDelay = a.getInt(R.styleable.Transition_startDelay, -1); if (startDelay > 0) { setStartDelay(startDelay); } final int resID = a.getResourceId(com.glview.R.styleable.Animator_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:com.stepstone.stepper.StepperLayout.java
private void extractValuesFromAttributes(AttributeSet attrs, @AttrRes int defStyleAttr) { if (attrs != null) { final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StepperLayout, defStyleAttr, 0);/*w ww . j a v a 2s . co m*/ if (a.hasValue(R.styleable.StepperLayout_ms_backButtonColor)) { mBackButtonColor = a.getColorStateList(R.styleable.StepperLayout_ms_backButtonColor); } if (a.hasValue(R.styleable.StepperLayout_ms_nextButtonColor)) { mNextButtonColor = a.getColorStateList(R.styleable.StepperLayout_ms_nextButtonColor); } if (a.hasValue(R.styleable.StepperLayout_ms_completeButtonColor)) { mCompleteButtonColor = a.getColorStateList(R.styleable.StepperLayout_ms_completeButtonColor); } if (a.hasValue(R.styleable.StepperLayout_ms_activeStepColor)) { mSelectedColor = a.getColor(R.styleable.StepperLayout_ms_activeStepColor, mSelectedColor); } if (a.hasValue(R.styleable.StepperLayout_ms_inactiveStepColor)) { mUnselectedColor = a.getColor(R.styleable.StepperLayout_ms_inactiveStepColor, mUnselectedColor); } if (a.hasValue(R.styleable.StepperLayout_ms_errorColor)) { mErrorColor = a.getColor(R.styleable.StepperLayout_ms_errorColor, mErrorColor); } if (a.hasValue(R.styleable.StepperLayout_ms_bottomNavigationBackground)) { mBottomNavigationBackground = a.getResourceId( R.styleable.StepperLayout_ms_bottomNavigationBackground, mBottomNavigationBackground); } if (a.hasValue(R.styleable.StepperLayout_ms_backButtonBackground)) { mBackButtonBackground = a.getResourceId(R.styleable.StepperLayout_ms_backButtonBackground, 0); } if (a.hasValue(R.styleable.StepperLayout_ms_nextButtonBackground)) { mNextButtonBackground = a.getResourceId(R.styleable.StepperLayout_ms_nextButtonBackground, 0); } if (a.hasValue(R.styleable.StepperLayout_ms_completeButtonBackground)) { mCompleteButtonBackground = a.getResourceId(R.styleable.StepperLayout_ms_completeButtonBackground, 0); } if (a.hasValue(R.styleable.StepperLayout_ms_backButtonText)) { mBackButtonText = a.getString(R.styleable.StepperLayout_ms_backButtonText); } if (a.hasValue(R.styleable.StepperLayout_ms_nextButtonText)) { mNextButtonText = a.getString(R.styleable.StepperLayout_ms_nextButtonText); } if (a.hasValue(R.styleable.StepperLayout_ms_completeButtonText)) { mCompleteButtonText = a.getString(R.styleable.StepperLayout_ms_completeButtonText); } if (a.hasValue(R.styleable.StepperLayout_ms_tabStepDividerWidth)) { mTabStepDividerWidth = a.getDimensionPixelOffset(R.styleable.StepperLayout_ms_tabStepDividerWidth, -1); } mShowBackButtonOnFirstStep = a.getBoolean(R.styleable.StepperLayout_ms_showBackButtonOnFirstStep, false); mShowErrorState = a.getBoolean(R.styleable.StepperLayout_ms_showErrorState, false); if (a.hasValue(R.styleable.StepperLayout_ms_stepperType)) { mTypeIdentifier = a.getInt(R.styleable.StepperLayout_ms_stepperType, DEFAULT_TAB_DIVIDER_WIDTH); } mShowErrorStateOnBack = a.getBoolean(R.styleable.StepperLayout_ms_showErrorStateOnBack, false); a.recycle(); } }
From source file:com.flashgugu.library.widgets.paginationseekbar.PaginationSeekBar.java
public PaginationSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true);//from w w w .j a va2 s . c o m setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaginationSeekBar, R.attr.paginationSeekBarStyle, defStyle); int max = 100; int min = 0; int value = 1; mMirrorForRtl = a.getBoolean(R.styleable.PaginationSeekBar_psb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.PaginationSeekBar_psb_allowTrackClickToDrag, mAllowTrackClick); int indexMax = R.styleable.PaginationSeekBar_psb_max; int indexMin = R.styleable.PaginationSeekBar_psb_min; int indexValue = R.styleable.PaginationSeekBar_psb_value; pageCountPerOneBoard = R.styleable.PaginationSeekBar_psb_pageCountPerOneBoard; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } if (a.getValue(pageCountPerOneBoard, out)) { pageCountPerOneBoard = a.getInteger(pageCountPerOneBoard, pageCountPerOneBoard); } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.PaginationSeekBar_psb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_rippleColor); int thumbTextColor = a.getColor(R.styleable.PaginationSeekBar_psb_thumbTextColor, Color.WHITE); boolean editMode = isInEditMode(); if (editMode && rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode && trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode && progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { 0xff009688 }); } if (editMode && thumbTextColor == 0) { thumbTextColor = Color.WHITE; } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); ThumbDrawable thumbDrawable = new ThumbDrawable(progressColor, thumbTextColor, thumbSize, mValue); mThumb = thumbDrawable; mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyle, convertValueToMessage(mMax)); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); initPagecountPerOneboard(pageCountPerOneBoard); }
From source file:com.doodle.android.chips.ChipsView.java
private void initAttr(Context context, AttributeSet attrs) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ChipsView, 0, 0); try {//from ww w . j a va 2 s .c o m mMaxHeight = a.getDimensionPixelSize(R.styleable.ChipsView_cv_max_height, DEFAULT_MAX_HEIGHT); mVerticalSpacing = a.getDimensionPixelSize(R.styleable.ChipsView_cv_vertical_spacing, (int) (DEFAULT_VERTICAL_SPACING * mDensity)); mChipsColor = a.getColor(R.styleable.ChipsView_cv_color, ContextCompat.getColor(context, R.color.base30)); mChipsColorClicked = a.getColor(R.styleable.ChipsView_cv_color_clicked, ContextCompat.getColor(context, R.color.colorPrimaryDark)); mChipsColorErrorClicked = a.getColor(R.styleable.ChipsView_cv_color_error_clicked, ContextCompat.getColor(context, R.color.color_error)); mChipsBgColor = a.getColor(R.styleable.ChipsView_cv_bg_color, ContextCompat.getColor(context, R.color.base10)); mChipsBgColorClicked = a.getColor(R.styleable.ChipsView_cv_bg_color_clicked, ContextCompat.getColor(context, R.color.blue)); mChipsBgColorIndelible = a.getColor(R.styleable.ChipsView_cv_bg_color_indelible, mChipsBgColor); mChipsBgColorErrorClicked = a.getColor(R.styleable.ChipsView_cv_bg_color_clicked, ContextCompat.getColor(context, R.color.color_error)); mChipsTextColor = a.getColor(R.styleable.ChipsView_cv_text_color, Color.BLACK); mChipsTextColorClicked = a.getColor(R.styleable.ChipsView_cv_text_color_clicked, Color.WHITE); mChipsTextColorErrorClicked = a.getColor(R.styleable.ChipsView_cv_text_color_clicked, Color.WHITE); mChipsTextColorIndelible = a.getColor(R.styleable.ChipsView_cv_text_color_indelible, mChipsTextColor); mChipsPlaceholderResId = a.getResourceId(R.styleable.ChipsView_cv_icon_placeholder, R.drawable.ic_person_24dp); mChipsPlaceholderTint = a.getColor(R.styleable.ChipsView_cv_icon_placeholder_tint, 0); mChipsDeleteResId = a.getResourceId(R.styleable.ChipsView_cv_icon_delete, R.drawable.ic_close_24dp); mChipsHintText = a.getString(R.styleable.ChipsView_cv_text_hint); mChipsMargin = a.getDimensionPixelSize(R.styleable.ChipsView_cv_chips_margin, 0); } finally { a.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/*from w w w . j a v a2 s. com*/ // 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.tengio.FloatingSearchView.java
private void applyXmlAttributes(AttributeSet attrs) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView); try {//w w w. j a v a 2 s . com int searchBarWidth = a.getDimensionPixelSize( R.styleable.FloatingSearchView_floatingSearch_searchBarWidth, ViewGroup.LayoutParams.MATCH_PARENT); mQuerySection.getLayoutParams().width = searchBarWidth; mDivider.getLayoutParams().width = searchBarWidth; int searchBarLeftMargin = a.getDimensionPixelSize( R.styleable.FloatingSearchView_floatingSearch_searchBarMarginLeft, ATTRS_SEARCH_BAR_MARGIN_DEFAULT); int searchBarTopMargin = a.getDimensionPixelSize( R.styleable.FloatingSearchView_floatingSearch_searchBarMarginTop, ATTRS_SEARCH_BAR_MARGIN_DEFAULT); int searchBarRightMargin = a.getDimensionPixelSize( R.styleable.FloatingSearchView_floatingSearch_searchBarMarginRight, ATTRS_SEARCH_BAR_MARGIN_DEFAULT); LayoutParams querySectionLP = (LayoutParams) mQuerySection.getLayoutParams(); LayoutParams dividerLP = (LayoutParams) mDivider.getLayoutParams(); int cardPadding = Util.dpToPx(CARD_VIEW_TOP_BOTTOM_SHADOW_HEIGHT); querySectionLP.setMargins(searchBarLeftMargin, searchBarTopMargin, searchBarRightMargin, 0); dividerLP.setMargins(searchBarLeftMargin + cardPadding, 0, searchBarRightMargin + cardPadding, ((MarginLayoutParams) mDivider.getLayoutParams()).bottomMargin); mQuerySection.setLayoutParams(querySectionLP); mDivider.setLayoutParams(dividerLP); setSearchHint(a.getString(R.styleable.FloatingSearchView_floatingSearch_searchHint)); setShowSearchKey(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showSearchKey, ATTRS_SEARCH_BAR_SHOW_SEARCH_KEY_DEFAULT)); setCloseSearchOnKeyboardDismiss( a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_close_search_on_keyboard_dismiss, ATTRS_DISMISS_ON_KEYBOARD_DISMISS_DEFAULT)); setDismissOnOutsideClick( a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_dismissOnOutsideTouch, ATTRS_DISMISS_ON_OUTSIDE_TOUCH_DEFAULT)); //noinspection ResourceType mLeftActionMode = a.getInt(R.styleable.FloatingSearchView_floatingSearch_leftActionMode, ATTRS_SEARCH_BAR_LEFT_ACTION_MODE_DEFAULT); if (a.hasValue(R.styleable.FloatingSearchView_floatingSearch_menu)) { mMenuId = a.getResourceId(R.styleable.FloatingSearchView_floatingSearch_menu, -1); } setBackgroundColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_backgroundColor, Util.getColor(getContext(), R.color.background))); setLeftActionIconColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_leftActionColor, Util.getColor(getContext(), R.color.left_action_icon))); setActionMenuOverflowColor( a.getColor(R.styleable.FloatingSearchView_floatingSearch_actionMenuOverflowColor, Util.getColor(getContext(), R.color.overflow_icon_color))); setMenuItemIconColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_menuItemIconColor, Util.getColor(getContext(), R.color.menu_icon_color))); setDividerColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_dividerColor, Util.getColor(getContext(), R.color.divider))); setClearBtnColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_clearBtnColor, Util.getColor(getContext(), R.color.clear_btn_color))); setViewTextColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_viewTextColor, Util.getColor(getContext(), R.color.dark_gray))); setHintTextColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_hintTextColor, Util.getColor(getContext(), R.color.hint_color))); setFont(a.getString(R.styleable.FloatingSearchView_floatingSearch_textFont)); } finally { a.recycle(); } }
From source file:me.philio.pinentry.PinEntryView.java
public PinEntryView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Get style information TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.PinEntryView); mDigits = array.getInt(R.styleable.PinEntryView_numDigits, 4); mAccentType = array.getInt(R.styleable.PinEntryView_accentType, ACCENT_NONE); // Dimensions DisplayMetrics metrics = getResources().getDisplayMetrics(); mDigitWidth = array.getDimensionPixelSize(R.styleable.PinEntryView_digitWidth, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, metrics)); mDigitHeight = array.getDimensionPixelSize(R.styleable.PinEntryView_digitHeight, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, metrics)); mDigitSpacing = array.getDimensionPixelSize(R.styleable.PinEntryView_digitSpacing, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, metrics)); mDigitTextSize = array.getDimensionPixelSize(R.styleable.PinEntryView_digitTextSize, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, metrics)); mAccentWidth = array.getDimensionPixelSize(R.styleable.PinEntryView_accentWidth, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, metrics)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mDigitElevation = array.getDimensionPixelSize(R.styleable.PinEntryView_digitElevation, 0); }/*from w w w.j ava 2 s.com*/ // Get theme to resolve defaults Resources.Theme theme = getContext().getTheme(); // Background colour, default to android:windowBackground from theme TypedValue background = new TypedValue(); theme.resolveAttribute(android.R.attr.windowBackground, background, true); mDigitBackground = array.getResourceId(R.styleable.PinEntryView_digitBackground, background.resourceId); // Text colour, default to android:textColorPrimary from theme TypedValue textColor = new TypedValue(); theme.resolveAttribute(android.R.attr.textColorPrimary, textColor, true); mDigitTextColor = array.getColor(R.styleable.PinEntryView_digitTextColor, textColor.resourceId > 0 ? ContextCompat.getColor(context, textColor.resourceId) : textColor.data); // Accent colour, default to android:colorAccent from theme TypedValue accentColor = new TypedValue(); theme.resolveAttribute(R.attr.colorAccent, accentColor, true); mAccentColor = array.getColor(R.styleable.PinEntryView_pinAccentColor, accentColor.resourceId > 0 ? ContextCompat.getColor(context, accentColor.resourceId) : accentColor.data); // Mask character String maskCharacter = array.getString(R.styleable.PinEntryView_mask); if (maskCharacter != null) { mMask = maskCharacter; } mAccentRequiresFocus = array.getBoolean(R.styleable.PinEntryView_accentRequiresFocus, true); // Recycle the typed array array.recycle(); // Add child views addViews(); }
From source file:com.supermonkey.lifeassistant.view.pager.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // ?View???/*from w ww . ja v a 2 s . c om*/ setFillViewport(true); // onDraw? setWillNotDraw(false); // tab tabsContainer = new LinearLayout(context); // tab? tabsContainer.setOrientation(LinearLayout.HORIZONTAL); // tabmacth_parent,match_parent tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // HorizontalScrollViewtab addView(tabsContainer); // ?? DisplayMetrics dm = getResources().getDisplayMetrics(); //?dip?? 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); // selectedTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstSelectedTextColor, selectedTabTextColor); // ? indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); // ?/ underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); // ? dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); // ?tab tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); // tab 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); // ?/? controlStyle = a.getString(R.styleable.PagerSlidingTabStrip_pstsControlStyle); 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:me.ccrama.redditslide.Views.SubsamplingScaleImageView.java
public SubsamplingScaleImageView(Context context, AttributeSet attr) { super(context, attr); setMinimumDpi(160);/*www .j ava 2 s.co m*/ setDoubleTapZoomDpi(160); setGestureDetector(context); this.handler = new Handler(new Handler.Callback() { public boolean handleMessage(Message message) { if (message.what == MESSAGE_LONG_CLICK && onLongClickListener != null) { maxTouchCount = 0; SubsamplingScaleImageView.super.setOnLongClickListener(onLongClickListener); performLongClick(); SubsamplingScaleImageView.super.setOnLongClickListener(null); } return true; } }); // Handle XML attributes if (attr != null) { TypedArray typedAttr = getContext().obtainStyledAttributes(attr, styleable.SubsamplingScaleImageView); if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_assetName)) { String assetName = typedAttr.getString(styleable.SubsamplingScaleImageView_assetName); if (assetName != null && assetName.length() > 0) { setImage(ImageSource.asset(assetName).tilingEnabled()); } } if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_src)) { int resId = typedAttr.getResourceId(styleable.SubsamplingScaleImageView_src, 0); if (resId > 0) { setImage(ImageSource.resource(resId).tilingEnabled()); } } if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_panEnabled)) { setPanEnabled(typedAttr.getBoolean(styleable.SubsamplingScaleImageView_panEnabled, true)); } if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_zoomEnabled)) { setZoomEnabled(typedAttr.getBoolean(styleable.SubsamplingScaleImageView_zoomEnabled, true)); } if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_quickScaleEnabled)) { setQuickScaleEnabled( typedAttr.getBoolean(styleable.SubsamplingScaleImageView_quickScaleEnabled, true)); } if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_tileBackgroundColor)) { setTileBackgroundColor(typedAttr.getColor(styleable.SubsamplingScaleImageView_tileBackgroundColor, Color.argb(0, 0, 0, 0))); } typedAttr.recycle(); } quickScaleThreshold = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, context.getResources().getDisplayMetrics()); }
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
private void init(Context context, AttributeSet attrs) { detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override/*from w w w . jav a 2 s.co m*/ public boolean onDown(MotionEvent event) { boolean isMarkerInChord = false; int fret = NO_FRET, string = -1; fret = getSelectedFret(event); string = getSelectedString(event); touchEventMarker = new ChordMarker(string, fret, NO_FINGER); return true; } @Override public void onLongPress(MotionEvent event) { if (editable && touchEventMarker != null && chord != null && chord.contains(touchEventMarker)) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(GuitarChordView.this, InputMethodManager.SHOW_IMPLICIT); } } }); chord = new Chord(); showFretNumbers = true; showFingerNumbers = true; editable = false; stringCount = 6; listeners = new ArrayList<>(); fretNumberListeners = new ArrayList<>(); stringListeners = new ArrayList<>(); touchEventMarker = null; mutedText = MUTED_TEXT; openStringText = OPEN_STRING_TEXT; initPaint(); if (attrs != null) { //TODO handle custom attribute values TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.GuitarChordView, 0, 0); try { bridgeNutColor = a.getColor(R.styleable.GuitarChordView_bridgeNutColor, DEFAULT_COLOR); bridgeNutPaint.setColor(bridgeNutColor); fretMarkerColor = a.getColor(R.styleable.GuitarChordView_fretMarkerColor, DEFAULT_COLOR); fretMarkerPaint.setColor(fretMarkerColor); stringColor = a.getColor(R.styleable.GuitarChordView_stringColor, DEFAULT_COLOR); stringPaint.setColor(stringColor); fretNumberColor = a.getColor(R.styleable.GuitarChordView_fretNumberColor, DEFAULT_COLOR); fretNumberPaint.setColor(fretNumberColor); stringMarkerColor = a.getColor(R.styleable.GuitarChordView_stringMarkerColor, DEFAULT_COLOR); stringMarkerPaint.setColor(stringMarkerColor); noteColor = a.getColor(R.styleable.GuitarChordView_noteColor, DEFAULT_COLOR); notePaint.setColor(noteColor); noteNumberColor = a.getColor(R.styleable.GuitarChordView_noteNumberColor, WHITE); noteNumberPaint.setColor(noteNumberColor); barLineColor = a.getColor(R.styleable.GuitarChordView_barLineColor, DEFAULT_COLOR); barLinePaint.setColor(barLineColor); mutedText = a.getString(R.styleable.GuitarChordView_mutedText); mutedText = (mutedText == null) ? MUTED_TEXT : mutedText; openStringText = a.getString(R.styleable.GuitarChordView_openStringText); openStringText = (openStringText == null) ? OPEN_STRING_TEXT : openStringText; stringCount = a.getInt(R.styleable.GuitarChordView_stringAmount, 6); editable = a.getBoolean(R.styleable.GuitarChordView_editable, false); showFingerNumbers = a.getBoolean(R.styleable.GuitarChordView_showFingerNumbers, true); showFretNumbers = a.getBoolean(R.styleable.GuitarChordView_showFretNumbers, true); } catch (Exception e) { e.printStackTrace(); } finally { a.recycle(); } } }