List of usage examples for android.content.res TypedArray getColorStateList
@Nullable public ColorStateList getColorStateList(@StyleableRes int index)
From source file:com.albedinsky.android.ui.widget.BaseProgressBar.java
/** * Called from the constructor to process tint values for this view. * * @param context The context passed to constructor. * @param typedArray TypedArray obtained for styleable attributes specific for this view. *//*from w w w . j a v a 2 s. co m*/ @SuppressWarnings("All") private void processTintValues(Context context, TypedArray typedArray) { this.ensureTintInfo(); if (typedArray.hasValue(R.styleable.Ui_ProgressBar_uiProgressTint)) { mTintInfo.progressTintList = typedArray.getColorStateList(R.styleable.Ui_ProgressBar_uiProgressTint); } if (typedArray.hasValue(R.styleable.Ui_ProgressBar_uiIndeterminateTint)) { mTintInfo.indeterminateTintList = typedArray .getColorStateList(R.styleable.Ui_ProgressBar_uiIndeterminateTint); } if (typedArray.hasValue(R.styleable.Ui_ProgressBar_uiProgressBackgroundTint)) { mTintInfo.backgroundTintList = typedArray .getColorStateList(R.styleable.Ui_ProgressBar_uiProgressBackgroundTint); } mTintInfo.progressTintMode = TintManager.parseTintMode( typedArray.getInt(R.styleable.Ui_ProgressBar_uiProgressTintMode, 0), PorterDuff.Mode.SRC_IN); mTintInfo.indeterminateTintMode = TintManager.parseTintMode( typedArray.getInt(R.styleable.Ui_ProgressBar_uiIndeterminateTintMode, 0), PorterDuff.Mode.SRC_IN); mTintInfo.backgroundTintMode = TintManager.parseTintMode( typedArray.getInt(R.styleable.Ui_ProgressBar_uiProgressBackgroundTintMode, 0), PorterDuff.Mode.SRC_IN); // If there is no tint mode specified within style/xml do not tint at all. if (mTintInfo.backgroundTintMode == null) mTintInfo.backgroundTintList = null; if (mTintInfo.progressTintMode == null) mTintInfo.progressTintList = null; if (mTintInfo.indeterminateTintMode == null) mTintInfo.indeterminateTintList = null; mTintInfo.hasBackgroundTintList = mTintInfo.backgroundTintList != null; mTintInfo.hasBackgroundTinMode = mTintInfo.backgroundTintMode != null; mTintInfo.hasProgressTintList = mTintInfo.progressTintList != null; mTintInfo.hasProgressTintMode = mTintInfo.progressTintMode != null; mTintInfo.hasIndeterminateTintList = mTintInfo.indeterminateTintList != null; mTintInfo.hasIndeterminateTintMode = mTintInfo.indeterminateTintMode != null; }
From source file:com.tr4android.support.extension.picker.date.DayPickerView.java
public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePickerDialog, defStyleAttr, 0); //TODO: add default style res final int firstDayOfWeek = a.getInt(R.styleable.DatePickerDialog_firstDayOfWeek, Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek()); final String minDate = a.getString(R.styleable.DatePickerDialog_minDate); final String maxDate = a.getString(R.styleable.DatePickerDialog_maxDate); final int monthTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_monthTextAppearance, R.style.TextAppearance_Material_Widget_Calendar_Month); final int dayOfWeekTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_weekDayTextAppearance, R.style.TextAppearance_Material_Widget_Calendar_DayOfWeek); final int dayTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_dateTextAppearance, R.style.TextAppearance_Material_Widget_Calendar_Day); // Set up day selected color, if available. final ColorStateList daySelectorColor; if (a.hasValue(R.styleable.DatePickerDialog_daySelectorColor)) { daySelectorColor = a.getColorStateList(R.styleable.DatePickerDialog_daySelectorColor); } else {//from w w w . j a va 2 s . com final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlActivated }); daySelectorColor = ta.getColorStateList(0); ta.recycle(); } // Set up day highlight color, if available. final ColorStateList dayHighlightColor; if (a.hasValue(R.styleable.DatePickerDialog_dayHighlightColor)) { dayHighlightColor = a.getColorStateList(R.styleable.DatePickerDialog_dayHighlightColor); } else { final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlHighlight }); dayHighlightColor = ta.getColorStateList(0); ta.recycle(); } a.recycle(); // Set up adapter. mAdapter = new DayPickerPagerAdapter(context, R.layout.day_picker_month_item_material, R.id.month_view); mAdapter.setMonthTextAppearance(monthTextAppearanceResId); mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId); mAdapter.setDayTextAppearance(dayTextAppearanceResId); mAdapter.setDaySelectorColor(daySelectorColor); mAdapter.setDayHighlightColor(dayHighlightColor); final LayoutInflater inflater = LayoutInflater.from(context); final ViewGroup content = (ViewGroup) inflater.inflate(DEFAULT_LAYOUT, this, false); // Transfer all children from content to here. while (content.getChildCount() > 0) { final View child = content.getChildAt(0); content.removeViewAt(0); addView(child); } mPrevButton = (ImageButton) findViewById(R.id.prev); mPrevButton.setOnClickListener(mOnClickListener); mNextButton = (ImageButton) findViewById(R.id.next); mNextButton.setOnClickListener(mOnClickListener); mViewPager = (ViewPager) findViewById(R.id.day_picker_view_pager); mViewPager.setAdapter(mAdapter); mViewPager.addOnPageChangeListener(mOnPageChangedListener); // Set up background of the previous and next buttons. ViewCompatUtils.setBackground(mPrevButton, PickerThemeUtils.getNavButtonBackground(context)); ViewCompatUtils.setBackground(mNextButton, PickerThemeUtils.getNavButtonBackground(context)); // Set up min and max dates. final Calendar tempDate = Calendar.getInstance(); if (!parseDate(minDate, tempDate)) { tempDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1); } final long minDateMillis = tempDate.getTimeInMillis(); if (!parseDate(maxDate, tempDate)) { tempDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31); } final long maxDateMillis = tempDate.getTimeInMillis(); if (maxDateMillis < minDateMillis) { throw new IllegalArgumentException("maxDate must be >= minDate"); } final long setDateMillis = MathUtils.constrain(System.currentTimeMillis(), minDateMillis, maxDateMillis); setFirstDayOfWeek(firstDayOfWeek); setMinDate(minDateMillis); setMaxDate(maxDateMillis); setDate(setDateMillis, false); // Proxy selection callbacks to our own listener. mAdapter.setOnDaySelectedListener(new DayPickerPagerAdapter.OnDaySelectedListener() { @Override public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) { if (mOnDaySelectedListener != null) { mOnDaySelectedListener.onDaySelected(DayPickerView.this, day); } } }); }
From source file:com.alimuzaffar.lib.pin.PinEntryEditText.java
private void init(Context context, AttributeSet attrs) { float multi = context.getResources().getDisplayMetrics().density; mLineStroke = multi * mLineStroke;//from ww w. j a v a 2s. c o m mLineStrokeSelected = multi * mLineStrokeSelected; mSpace = multi * mSpace; //convert to pixels for our density mTextBottomPadding = multi * mTextBottomPadding; //convert to pixels for our density TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PinEntryEditText, 0, 0); try { TypedValue outValue = new TypedValue(); ta.getValue(R.styleable.PinEntryEditText_pinAnimationType, outValue); mAnimatedType = outValue.data; mMask = ta.getString(R.styleable.PinEntryEditText_pinCharacterMask); mSingleCharHint = ta.getString(R.styleable.PinEntryEditText_pinRepeatedHint); mLineStroke = ta.getDimension(R.styleable.PinEntryEditText_pinLineStroke, mLineStroke); mLineStrokeSelected = ta.getDimension(R.styleable.PinEntryEditText_pinLineStrokeSelected, mLineStrokeSelected); mSpace = ta.getDimension(R.styleable.PinEntryEditText_pinCharacterSpacing, mSpace); mTextBottomPadding = ta.getDimension(R.styleable.PinEntryEditText_pinTextBottomPadding, mTextBottomPadding); mIsDigitSquare = ta.getBoolean(R.styleable.PinEntryEditText_pinBackgroundIsSquare, mIsDigitSquare); mPinBackground = ta.getDrawable(R.styleable.PinEntryEditText_pinBackgroundDrawable); ColorStateList colors = ta.getColorStateList(R.styleable.PinEntryEditText_pinLineColors); if (colors != null) { mColorStates = colors; } } finally { ta.recycle(); } mCharPaint = new Paint(getPaint()); mLastCharPaint = new Paint(getPaint()); mSingleCharPaint = new Paint(getPaint()); mLinesPaint = new Paint(getPaint()); mLinesPaint.setStrokeWidth(mLineStroke); TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorControlActivated, outValue, true); int colorSelected = outValue.data; mColors[0] = colorSelected; int colorFocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal); mColors[1] = colorFocused; int colorUnfocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal); mColors[2] = colorUnfocused; setBackgroundResource(0); mMaxLength = attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4); mNumChars = mMaxLength; //Disable copy paste super.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); // When tapped, move cursor to end of text. super.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setSelection(getText().length()); if (mClickListener != null) { mClickListener.onClick(v); } } }); super.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { setSelection(getText().length()); return true; } }); //If input type is password and no mask is set, use a default mask if ((getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD && TextUtils.isEmpty(mMask)) { mMask = "\u25CF"; } else if ((getInputType() & InputType.TYPE_NUMBER_VARIATION_PASSWORD) == InputType.TYPE_NUMBER_VARIATION_PASSWORD && TextUtils.isEmpty(mMask)) { mMask = "\u25CF"; } if (!TextUtils.isEmpty(mMask)) { mMaskChars = getMaskChars(); } //Height of the characters, used if there is a background drawable getPaint().getTextBounds("|", 0, 1, mTextHeight); mAnimate = mAnimatedType > -1; }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
public IndicatorTabStrip(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setItemClickable(true);/*from w w w . j av a2 s. c om*/ setClickSmoothScroll(true); final float density = getResources().getDisplayMetrics().density; mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTextAlign(Align.CENTER); if (Build.VERSION.SDK_INT > 4) { updateTextPaintDensity(); } mTagLocation = new TagLocation(TagLocation.LOCATION_EDGE); final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); int n = a.getIndexCount(); int textSize = (int) (DEFAULT_TEXT_SIZE * density); ColorStateList textColors = null; Drawable divider = null; for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case 0: textSize = a.getDimensionPixelSize(attr, textSize); break; case 1: textColors = a.getColorStateList(attr); break; case 2: divider = a.getDrawable(attr); break; } } a.recycle(); float scale = 1; Drawable itemBackground = null; ColorStateList gradient = null; Drawable indicator = null; int indicatorWidthMode = INDICATOR_WIDTH_MODE_SET; int indicatorPadding = 0; int indicatorWidth = INDICATOR_WIDTH_BY_DRAWABLE; int indicatorHeight = INDICATOR_HEIGHT_BY_DRAWABLE; Drawable interval = null; int minItemWidth = (int) (DEFAULT_ITEM_WIDTH * density); int minItemHeight = (int) (DEFAULT_ITEM_HEIGHT * density); int tagTextSize = (int) (DEFAULT_TAG_TEXT_SIZE * density); int tagTextColor = DEFAULT_TAG_TEXT_COLOR; Drawable tagBackground = getDefaultTagBackground(); int tagMinSizeMode = TAG_MIN_SIZE_MODE_HAS_TEXT; int tagMinWidth = (int) (DEFAULT_TAG_MIN_SIZE * density); int tagMinHeight = (int) (DEFAULT_TAG_MIN_SIZE * density); int tagPaddingLeft = 0; int tagPaddingTop = 0; int tagPaddingRight = 0; int tagPaddingBottom = 0; int tagMarginLeft = 0; int tagMarginTop = 0; int tagMarginRight = 0; int tagMarginBottom = 0; TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.IndicatorTabStrip); textSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTextSize, textSize); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTextColor)) textColors = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsTextColor); scale = custom.getFloat(R.styleable.IndicatorTabStrip_ttsTextScale, scale); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsBackground)) itemBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsBackground); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsGradient)) gradient = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsGradient); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsDivider)) divider = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsDivider); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsIndicator)) indicator = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsIndicator); indicatorWidthMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsIndicatorWidthMode, indicatorWidthMode); indicatorPadding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorPadding, indicatorPadding); indicatorWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorWidth, indicatorWidth); indicatorHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorHeight, indicatorHeight); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsInterval)) interval = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsInterval); minItemWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemWidth, minItemWidth); minItemHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemHeight, minItemHeight); tagTextSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTagTextSize, tagTextSize); tagTextColor = custom.getColor(R.styleable.IndicatorTabStrip_ttsTagTextColor, tagTextColor); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagBackground)) tagBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsTagBackground); tagMinSizeMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsTagMinSizeMode, tagMinSizeMode); tagMinWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinWidth, tagMinWidth); tagMinHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinHeight, tagMinHeight); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagPadding)) { final int padding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPadding, 0); tagPaddingLeft = padding; tagPaddingTop = padding; tagPaddingRight = padding; tagPaddingBottom = padding; } tagPaddingLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingLeft, tagPaddingLeft); tagPaddingTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingTop, tagPaddingTop); tagPaddingRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingRight, tagPaddingRight); tagPaddingBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingBottom, tagPaddingBottom); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagMargin)) { final int margin = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMargin, 0); tagMarginLeft = margin; tagMarginTop = margin; tagMarginRight = margin; tagMarginBottom = margin; } tagMarginLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginLeft, tagMarginLeft); tagMarginTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginTop, tagMarginTop); tagMarginRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginRight, tagMarginRight); tagMarginBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginBottom, tagMarginBottom); custom.recycle(); setTextSize(textSize); if (textColors != null) { setTextColor(textColors); } else { setTextColor(DEFAULT_TEXT_COLOR); } setTextScale(scale); setItemBackground(itemBackground); setGradient(gradient); setDivider(divider); setIndicator(indicator); setIndicatorWidthMode(indicatorWidthMode); setIndicatorPadding(indicatorPadding); setIndicatorWidth(indicatorWidth); setIndicatorHeight(indicatorHeight); setInterval(interval); setMinItemWidth(minItemWidth); setMinItemHeight(minItemHeight); setTagTextSize(tagTextSize); setTagTextColor(tagTextColor); setTagBackground(tagBackground); setTagMinSizeMode(tagMinSizeMode); setTagMinWidth(tagMinWidth); setTagMinHeight(tagMinHeight); setTagPadding(tagPaddingLeft, tagPaddingTop, tagPaddingRight, tagPaddingBottom); setTagMargin(tagMarginLeft, tagMarginTop, tagMarginRight, tagMarginBottom); }
From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) { Context context = getContext(); // Pull disabled alpha from theme. final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true); mDisabledAlpha = outValue.getFloat(); // process style attributes final Resources res = getResources(); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadialTimePickerView, defStyleAttr, defStyleRes);//from ww w. j av a2s . c om mTypeface = Typeface.create("sans-serif", Typeface.NORMAL); // Initialize all alpha values to opaque. for (int i = 0; i < mAlpha.length; i++) { mAlpha[i] = new IntHolder(ALPHA_OPAQUE); } mTextColor[HOURS] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersTextColor); mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersInnerTextColor); mTextColor[MINUTES] = mTextColor[HOURS]; mPaint[HOURS] = new Paint(); mPaint[HOURS].setAntiAlias(true); mPaint[HOURS].setTextAlign(Paint.Align.CENTER); mPaint[MINUTES] = new Paint(); mPaint[MINUTES].setAntiAlias(true); mPaint[MINUTES].setTextAlign(Paint.Align.CENTER); final ColorStateList selectorColors = a .getColorStateList(R.styleable.RadialTimePickerView_spNumbersSelectorColor); int selectorActivatedColor = Color.BLACK; if (selectorColors != null) { selectorActivatedColor = selectorColors .getColorForState(SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED), 0); } mPaintCenter.setColor(selectorActivatedColor); mPaintCenter.setAntiAlias(true); final int[] activatedStateSet = SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED); mSelectorColor = selectorActivatedColor; mSelectorDotColor = mTextColor[HOURS].getColorForState(activatedStateSet, 0); mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint(); mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true); mPaintSelector[HOURS][SELECTOR_DOT] = new Paint(); mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true); mPaintSelector[HOURS][SELECTOR_LINE] = new Paint(); mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true); mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2); mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint(); mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true); mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint(); mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true); mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint(); mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true); mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2); mPaintBackground.setColor(a.getColor(R.styleable.RadialTimePickerView_spNumbersBackgroundColor, ContextCompat.getColor(context, R.color.timepicker_default_numbers_background_color_material))); mPaintBackground.setAntiAlias(true); mSelectorRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_radius); mSelectorStroke = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_stroke); mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_dot_radius); mCenterDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_center_dot_radius); mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal); mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal); mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_inner); mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal); mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal); mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_inner); mShowHours = true; mIs24HourMode = false; mAmOrPm = AM; // Set up accessibility components. mTouchHelper = new RadialPickerTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } initHoursAndMinutesText(); initData(); a.recycle(); // Initial values final Calendar calendar = Calendar.getInstance(Locale.getDefault()); final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); setCurrentHourInternal(currentHour, false, false); setCurrentMinuteInternal(currentMinute, false); setHapticFeedbackEnabled(true); }
From source file:com.kkbox.toolkit.app.KKTabFragment.java
protected void initView(View view, int[] buttonTextResourcetId, boolean showSubFragmentAnimation, int currentIndex) { fixStateForNestedFragment();/*from ww w . j a va 2 s .c o m*/ initView(view); if (this.currentIndex == -1) { this.currentIndex = currentIndex; } this.showSubFragmentAnimation = showSubFragmentAnimation; radioGroup = (RadioGroup) view.findViewById(R.id.button_radiogroup); TypedValue typedValue = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.KKTabFragmentStyle, typedValue, true); TypedArray array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { R.attr.KKTabButtonBackgroundLeft, R.attr.KKTabButtonBackgroundMiddle, R.attr.KKTabButtonBackgroundRight }); int tabButtonBackgroundLeftResourceId = array.getResourceId(0, -1); int tabButtonBackgroundMiddleResourceId = array.getResourceId(1, -1); int tabButtonBackgroundRightResourceId = array.getResourceId(2, -1); array.recycle(); array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { R.attr.KKTabBackground }); int backgroundResourceId = array.getResourceId(0, -1); FrameLayout layoutRadioBar = (FrameLayout) view.findViewById(R.id.layout_radio_bar); if (backgroundResourceId != -1) { layoutRadioBar.setBackgroundResource(backgroundResourceId); } array.recycle(); array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { R.attr.KKTabOverlay }); int overlayResourceId = array.getResourceId(0, -1); ImageView viewOverlay = (ImageView) view.findViewById(R.id.view_overlay); if (overlayResourceId != -1) { viewOverlay.setBackgroundResource(overlayResourceId); } array.recycle(); array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.textSize }); int textSize = array.getDimensionPixelSize(0, -1); array.recycle(); array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.textColor }); ColorStateList textColor = array.getColorStateList(0); array.recycle(); array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.height }); int height = array.getDimensionPixelSize(0, -1); array.recycle(); for (int i = 0; i < buttonTextResourcetId.length; i++) { RadioButton radioButton = new RadioButton(getActivity()); if (i == 0 && tabButtonBackgroundLeftResourceId != -1) { radioButton.setBackgroundResource(tabButtonBackgroundLeftResourceId); } else if (i == buttonTextResourcetId.length - 1 && tabButtonBackgroundRightResourceId != -1) { radioButton.setBackgroundResource(tabButtonBackgroundRightResourceId); } else if (tabButtonBackgroundMiddleResourceId != -1) { radioButton.setBackgroundResource(tabButtonBackgroundMiddleResourceId); } radioButton.setText(buttonTextResourcetId[i]); radioButton.setButtonDrawable(new StateListDrawable()); radioButton.setGravity(Gravity.CENTER); radioButton.setTextColor(textColor); radioButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); radioButton.setLayoutParams(new RadioGroup.LayoutParams(0, height, 1)); radioButton.setOnClickListener(buttonClickListener); radioGroup.addView(radioButton); } currentFragment = null; radioGroup.getChildAt(this.currentIndex).performClick(); }
From source file:com.albedinsky.android.ui.widget.SearchView.java
/** * Called from one of constructors of this view to perform its initialization. * <p>//from ww w .j a v a2s.c o m * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view instance. The * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data * from the current theme provided by the specified <var>context</var>. */ @SuppressWarnings("ResourceType") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.mContext = context; setOrientation(HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); this.inflateHierarchy(context, R.layout.ui_search_view); this.mProgressBarAnimator = createProgressBarAnimator(); this.mDefaultRevealAnimationHandler = createRevealAnimationHandler(); ColorStateList tintList = null; PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN; /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SearchView, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_SearchView_android_queryHint) { setQueryHint(typedArray.getText(index)); } else if (index == R.styleable.Ui_SearchView_uiTint) { tintList = typedArray.getColorStateList(index); } else if (index == R.styleable.Ui_SearchView_uiTintMode) { tintMode = TintManager.parseTintMode(typedArray.getInt(R.styleable.Ui_SearchView_uiTintMode, 0), tintList != null ? PorterDuff.Mode.SRC_IN : null); } else if (index == R.styleable.Ui_SearchView_uiRevealDuration) { mDefaultRevealAnimationHandler.revealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiConcealDuration) { mDefaultRevealAnimationHandler.concealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiRevealInterpolator) { final int resId = typedArray.getResourceId(index, 0); if (resId != 0) { mDefaultRevealAnimationHandler.interpolator = AnimationUtils.loadInterpolator(context, resId); } } } typedArray.recycle(); } if (tintList != null || tintMode != null) { this.mTintInfo = new SearchTintInfo(); this.mTintInfo.tintList = tintList; this.mTintInfo.hasTintList = tintList != null; this.mTintInfo.tintMode = tintMode; this.mTintInfo.hasTintMode = tintMode != null; } final Resources.Theme theme = context.getTheme(); final TypedValue typedValue = new TypedValue(); if (theme.resolveAttribute(R.attr.uiSearchSelectHandleColor, typedValue, true)) { if (mTintInfo == null) { this.mTintInfo = new SearchTintInfo(); } if (typedValue.resourceId > 0) { mTintInfo.textSelectHandleTintList = ResourceUtils.getColorStateList(getResources(), typedValue.resourceId, theme); } else { mTintInfo.textSelectHandleTintList = ColorStateList.valueOf(typedValue.data); } mTintInfo.hasTextSelectHandleTintList = mTintInfo.textSelectHandleTintList != null; } this.applyTint(); this.mRevealAnimationHandler = mDefaultRevealAnimationHandler; }
From source file:net.qiujuer.genius.ui.widget.GeniusAbsSeekBar.java
private void init(AttributeSet attrs, int defStyle) { final Context context = getContext(); final Resources resources = getResources(); final boolean notEdit = !isInEditMode(); ColorStateList trackColor = mAttributes.getTrackColor(); ColorStateList thumbColor = mAttributes.getThumbColor(); ColorStateList scrubberColor = mAttributes.getScrubberColor(); ColorStateList rippleColor = mAttributes.getRippleColor(); ColorStateList indicatorColor = mAttributes.getIndicatorColor(); int textAppearanceId = R.style.DefaultBalloonMarkerTextAppearanceStyle; if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GeniusSeekBar, R.attr.GeniusSeekBarStyle, defStyle); // Getting common attributes int customTheme = a.getResourceId(R.styleable.GeniusSeekBar_g_theme, Attributes.DEFAULT_THEME); mAttributes.setTheme(customTheme, resources); // Values int max = a.getInteger(R.styleable.GeniusSeekBar_g_max, mMax); int min = a.getInteger(R.styleable.GeniusSeekBar_g_min, mMin); int value = a.getInteger(R.styleable.GeniusSeekBar_g_value, mValue); mMin = min;//from w ww . j a v a 2s.c o m mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); // Colors trackColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_trackColor); thumbColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_thumbColor); scrubberColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_scrubberColor); rippleColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_rippleColor); indicatorColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_indicatorBackgroundColor); // Size int tickSize = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_tickSize, mSeekBarDrawable.getTickRadius()); int thumbSize = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_thumbSize, mSeekBarDrawable.getThumbRadius()); int touchSize = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_touchSize, mSeekBarDrawable.getTouchRadius()); int trackStroke = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_trackStroke, mSeekBarDrawable.getTrackStroke()); int scrubberStroke = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_scrubberStroke, mSeekBarDrawable.getScrubberStroke()); // Set Size setTrackStroke(trackStroke); setScrubberStroke(scrubberStroke); setThumbRadius(thumbSize); setTouchRadius(touchSize); setTickRadius(tickSize); // Other mMirrorForRtl = a.getBoolean(R.styleable.GeniusSeekBar_g_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.GeniusSeekBar_g_allowTrackClickToDrag, mAllowTrackClick); mIndicatorFormatter = a.getString(R.styleable.GeniusSeekBar_g_indicatorFormatter); textAppearanceId = a.getResourceId(R.styleable.GeniusSeekBar_g_indicatorTextAppearance, textAppearanceId); a.recycle(); } // Init Colors if (rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { mAttributes.getColor(1) }); } else { mAttributes.setRippleColor(rippleColor); } if (trackColor == null) { int[] colors = new int[] { mAttributes.getColor(4), mAttributes.getColor(5) }; int[][] states = new int[][] { new int[] { android.R.attr.state_enabled }, new int[] { -android.R.attr.state_enabled } }; trackColor = new ColorStateList(states, colors); } else { mAttributes.setTrackColor(trackColor); } if (thumbColor == null) { int[] colors = new int[] { mAttributes.getColor(2), mAttributes.getColor(3) }; int[][] states = new int[][] { new int[] { android.R.attr.state_enabled }, new int[] { -android.R.attr.state_enabled } }; thumbColor = new ColorStateList(states, colors); } else { mAttributes.setThumbColor(thumbColor); } if (scrubberColor == null) { int[] colors = new int[] { mAttributes.getColor(2), mAttributes.getColor(3) }; int[][] states = new int[][] { new int[] { android.R.attr.state_enabled }, new int[] { -android.R.attr.state_enabled } }; scrubberColor = new ColorStateList(states, colors); } else { mAttributes.setScrubberColor(scrubberColor); } if (indicatorColor == null) { int[] colors = new int[] { mAttributes.getColor(2), mAttributes.getColor(1) }; int[][] states = new int[][] { new int[] { android.R.attr.state_enabled }, new int[] { android.R.attr.state_pressed } }; indicatorColor = new ColorStateList(states, colors); } else { mAttributes.setIndicatorColor(indicatorColor); } // Set Colors mRipple.setColorStateList(rippleColor); mSeekBarDrawable.setTrackColor(trackColor); mSeekBarDrawable.setScrubberColor(scrubberColor); mSeekBarDrawable.setThumbColor(thumbColor); if (notEdit) { mIndicator.setIndicatorColor(indicatorColor); mIndicator.setIndicatorTextAppearance(textAppearanceId); } // Set Values mSeekBarDrawable.setNumSegments(mMax - mMin); updateKeyboardRange(); }
From source file:com.albedinsky.android.support.ui.widget.BaseProgressBar.java
/** * Called from the constructor to process tint values for this view. * * @param context The context passed to constructor. * @param typedArray TypedArray obtained for styleable attributes specific for this view. *//*from w ww.j a v a 2 s .c om*/ @SuppressWarnings("All") private void processTintValues(Context context, TypedArray typedArray) { this.ensureTintInfo(); // Get tint colors. if (typedArray.hasValue(R.styleable.Ui_Widget_ProgressBar_uiProgressTint)) { mTintInfo.progressTintList = typedArray .getColorStateList(R.styleable.Ui_Widget_ProgressBar_uiProgressTint); } if (typedArray.hasValue(R.styleable.Ui_Widget_ProgressBar_uiIndeterminateTint)) { mTintInfo.indeterminateTintList = typedArray .getColorStateList(R.styleable.Ui_Widget_ProgressBar_uiIndeterminateTint); } if (typedArray.hasValue(R.styleable.Ui_Widget_ProgressBar_uiProgressBackgroundTint)) { mTintInfo.backgroundTintList = typedArray .getColorStateList(R.styleable.Ui_Widget_ProgressBar_uiProgressBackgroundTint); } // Get tint modes. mTintInfo.progressTintMode = TintManager.parseTintMode( typedArray.getInt(R.styleable.Ui_Widget_ProgressBar_uiProgressTintMode, 0), PorterDuff.Mode.SRC_IN); mTintInfo.indeterminateTintMode = TintManager.parseTintMode( typedArray.getInt(R.styleable.Ui_Widget_ProgressBar_uiIndeterminateTintMode, 0), PorterDuff.Mode.SRC_IN); mTintInfo.backgroundTintMode = TintManager.parseTintMode( typedArray.getInt(R.styleable.Ui_Widget_ProgressBar_uiProgressBackgroundTintMode, 0), PorterDuff.Mode.SRC_IN); // If there is no tint mode specified within style/xml do not tint at all. if (mTintInfo.backgroundTintMode == null) { mTintInfo.backgroundTintList = null; } if (mTintInfo.progressTintMode == null) { mTintInfo.progressTintList = null; } if (mTintInfo.indeterminateTintMode == null) { mTintInfo.indeterminateTintList = null; } mTintInfo.hasBackgroundTintList = mTintInfo.backgroundTintList != null; mTintInfo.hasBackgroundTinMode = mTintInfo.backgroundTintMode != null; mTintInfo.hasProgressTintList = mTintInfo.progressTintList != null; mTintInfo.hasProgressTintMode = mTintInfo.progressTintMode != null; mTintInfo.hasIndeterminateTintList = mTintInfo.indeterminateTintList != null; mTintInfo.hasIndeterminateTintMode = mTintInfo.indeterminateTintMode != null; }
From source file:com.tr4android.support.extension.picker.time.RadialTimePickerView.java
public RadialTimePickerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs); // Pull disabled alpha from theme. final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true); mDisabledAlpha = outValue.getFloat(); // process style attributes final Resources res = getResources(); final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TimePickerDialog, defStyleAttr, defStyleRes);/* ww w .j av a2 s .co m*/ mTypeface = Typeface.create("sans-serif", Typeface.NORMAL); // Initialize all alpha values to opaque. for (int i = 0; i < mAlpha.length; i++) { mAlpha[i] = new IntHolder(ALPHA_OPAQUE); } mTextColor[HOURS] = a.getColorStateList(R.styleable.TimePickerDialog_numbersTextColor); if (mTextColor[HOURS] == null) { mTextColor[HOURS] = PickerThemeUtils.getTextColorPrimaryActivatedStateList(context); } mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.TimePickerDialog_numbersInnerTextColor); if (mTextColor[HOURS_INNER] == null) { mTextColor[HOURS_INNER] = PickerThemeUtils.getTextColorSecondaryActivatedStateList(context); } mTextColor[MINUTES] = mTextColor[HOURS]; mPaint[HOURS] = new Paint(); mPaint[HOURS].setAntiAlias(true); mPaint[HOURS].setTextAlign(Paint.Align.CENTER); mPaint[MINUTES] = new Paint(); mPaint[MINUTES].setAntiAlias(true); mPaint[MINUTES].setTextAlign(Paint.Align.CENTER); final int[] selectedStateSet = new int[] { android.R.attr.state_enabled, android.R.attr.state_selected }; // Set up number selected color, if available. final ColorStateList numbersSelectorColor; if (a.hasValue(R.styleable.TimePickerDialog_numbersSelectorColor)) { numbersSelectorColor = a.getColorStateList(R.styleable.TimePickerDialog_numbersSelectorColor); } else { final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlActivated }); numbersSelectorColor = ta.getColorStateList(0); ta.recycle(); } final int selectorActivatedColor = numbersSelectorColor.getColorForState(selectedStateSet, 0); mPaintCenter.setColor(selectorActivatedColor); mPaintCenter.setAntiAlias(true); mSelectorColor = selectorActivatedColor; mSelectorDotColor = mTextColor[HOURS].getColorForState(selectedStateSet, 0); mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint(); mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true); mPaintSelector[HOURS][SELECTOR_DOT] = new Paint(); mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true); mPaintSelector[HOURS][SELECTOR_LINE] = new Paint(); mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true); mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2); mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint(); mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true); mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint(); mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true); mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint(); mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true); mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2); mPaintBackground.setColor(a.getColor(R.styleable.TimePickerDialog_numbersBackgroundColor, ContextCompat.getColor(context, android.R.color.transparent))); mPaintBackground.setAntiAlias(true); mSelectorRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_radius); mSelectorStroke = res.getDimensionPixelSize(R.dimen.timepicker_selector_stroke); mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_dot_radius); mCenterDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_center_dot_radius); mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_normal); mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_normal); mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_inner); mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_normal); mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_normal); mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_inner); mShowHours = true; mIs24HourMode = false; mAmOrPm = AM; // Set up accessibility components. mTouchHelper = new RadialPickerTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } initHoursAndMinutesText(); initData(); a.recycle(); // Initial values final Calendar calendar = Calendar.getInstance(Locale.getDefault()); final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); setCurrentHourInternal(currentHour, false, false); setCurrentMinuteInternal(currentMinute, false); setHapticFeedbackEnabled(true); }