List of usage examples for android.content.res TypedArray getDrawable
@Nullable public Drawable getDrawable(@StyleableRes int index)
From source file:com.bvhloc.numpicker.widget.NumberPicker.java
public NumberPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mStart = DEFAULT_START;/* w w w . j a va2 s. co m*/ mEnd = DEFAULT_END; mCurrent = mStart; boolean vertical = true; int displayedValues = 0; if (attrs != null && !isInEditMode()) { // this crashes in edit mode (?!) TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NumberPicker); mStart = a.getInt(R.styleable.NumberPicker_rangeStart, DEFAULT_START); mEnd = a.getInt(R.styleable.NumberPicker_rangeEnd, DEFAULT_END); mSpeed = a.getInt(R.styleable.NumberPicker_speed, (int) mSpeed); mSpeedUp = mSpeed; mCurrent = a.getInt(R.styleable.NumberPicker_current, mCurrent); mNumColor = a.getColor(R.styleable.NumberPicker_numColor, ContextCompat.getColor(context, android.R.color.primary_text_light)); mNumBackground = a.getDrawable(R.styleable.NumberPicker_numBackground); mNumSize = a.getDimension(R.styleable.NumberPicker_numSize, mNumSize); mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numHorizontalPadding, mNumSize); mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numVeticalPadding, mNumSize); mIncrementDrawable = a.getDrawable(R.styleable.NumberPicker_incrementDrawable); mDecrementDrawable = a.getDrawable(R.styleable.NumberPicker_decrementDrawable); mKeyboardInput = a.getBoolean(R.styleable.NumberPicker_keyboardInput, mKeyboardInput); String orientation = a.getString(R.styleable.NumberPicker_android_orientation); displayedValues = a.getResourceId(R.styleable.NumberPicker_displayedValues, 0); if (orientation != null) { vertical = !"0".equals(orientation); } a.recycle(); } else if (attrs != null && isInEditMode()) { // fix orientation attribute for editor String orientation = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "orientation"); if (orientation != null) { vertical = !"horizontal".equals(orientation); } } // set a wrong orientation so our own orientation method will perform changes super.setOrientation(!vertical ? VERTICAL : HORIZONTAL); setOrientation(vertical ? VERTICAL : HORIZONTAL); mChangeHandler = new Handler(); InputFilter inputFilter = new NumberPickerInputFilter(); mNumberInputFilter = new NumberRangeKeyListener(); mIncrementButton = (NumberPickerButton) findViewById(R.id.increment); mIncrementButton.setOnClickListener(this); mIncrementButton.setOnLongClickListener(this); mIncrementButton.setNumberPicker(this); mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement); mDecrementButton.setOnClickListener(this); mDecrementButton.setOnLongClickListener(this); mDecrementButton.setNumberPicker(this); mIncrementButton.setBackground(null); mDecrementButton.setBackground(null); mIncrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER); mDecrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER); if (mIncrementDrawable != null) { mIncrementButton.setImageDrawable(mIncrementDrawable); } if (mDecrementDrawable != null) { mDecrementButton.setImageDrawable(mDecrementDrawable); } mText = (EditText) findViewById(R.id.timepicker_input); mText.setOnFocusChangeListener(this); mText.setFilters(new InputFilter[] { inputFilter }); mText.setRawInputType(InputType.TYPE_CLASS_NUMBER); LayoutParams params = (LayoutParams) mText.getLayoutParams(); params.weight = 1; mText.setLayoutParams(params); mText.setPadding(mNumHorizontalPadding, mNumVerticalPadding, mNumHorizontalPadding, mNumVerticalPadding); mText.setTextSize(mNumSize); if (mNumBackground != null) { mText.setBackground(mNumBackground); } else { mText.setBackground(ContextCompat.getDrawable(context, android.R.drawable.edit_text)); } if (!mKeyboardInput) { mText.setEnabled(false); } mText.setTextColor(mNumColor); if (!isEnabled()) { setEnabled(false); } if (displayedValues != 0) { setDisplayedRange(mStart, displayedValues); } else { setRange(mStart, mEnd); } }
From source file:com.aretha.slidemenu.SlideMenu.java
public SlideMenu(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // we want to draw drop shadow of content mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mVelocityTracker = VelocityTracker.obtain(); mScroller = new Scroller(context, mInterpolator); mContentHitRect = new Rect(); STATUS_BAR_HEIGHT = (int) getStatusBarHeight(context); setWillNotDraw(false);//from w w w . ja va2 s. c o m TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlideMenu, defStyle, 0); // Set the shadow attributes setPrimaryShadowWidth(a.getDimension(R.styleable.SlideMenu_primaryShadowWidth, 30)); setSecondaryShadowWidth(a.getDimension(R.styleable.SlideMenu_secondaryShadowWidth, 30)); Drawable primaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_primaryShadowDrawable); if (null == primaryShadowDrawable) { primaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT, new int[] { Color.TRANSPARENT, Color.argb(99, 0, 0, 0) }); } setPrimaryShadowDrawable(primaryShadowDrawable); Drawable secondaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_primaryShadowDrawable); if (null == secondaryShadowDrawable) { secondaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT, new int[] { Color.argb(99, 0, 0, 0), Color.TRANSPARENT }); } setSecondaryShadowDrawable(secondaryShadowDrawable); mSlideDirectionFlag = a.getInt(R.styleable.SlideMenu_slideDirection, FLAG_DIRECTION_LEFT | FLAG_DIRECTION_RIGHT); setFocusable(true); setFocusableInTouchMode(true); a.recycle(); }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. */// www .ja v a 2s .com public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed); mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary); // themed final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0, theme.getThemeResId()); int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal); int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended); int colorOther = ContextCompat.getColor(context, R.color.candidate_other); float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height); try { colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal); colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor, colorRecommended); colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther); mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage); final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage); if (stripImage == null) setBackgroundColor(Color.BLACK); else setBackgroundDrawable(stripImage); fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel); } catch (Exception e) { Logger.w(TAG, "Got an exception while reading theme data", e); } mHorizontalGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20); a.recycle(); mColorNormal = colorNormal; mColorRecommended = colorRecommended; mColorOther = colorOther; if (mDivider == null) mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider); // end of themed mPaint = new Paint(); mPaint.setColor(mColorNormal); mPaint.setAntiAlias(true); mPaint.setTextSize(fontSizePixel); mPaint.setStrokeWidth(0); mPaint.setTextAlign(Align.CENTER); mTextPaint = new TextPaint(mPaint); final int minTouchableWidth = context.getResources() .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width); mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth)); setWillNotDraw(false); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); scrollTo(0, getScrollY()); }
From source file:com.example.anumbrella.viewpager.LinePagerIndicator.java
public LinePagerIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); ///*from ww w . j a va2 s . co m*/ if (isInEditMode()) { return; } //?? final Resources res = getResources(); // //? final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); // final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); // final float defalutLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); //? final float defalutGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); // final float defalutStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); //?? final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); //xml TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.LinePagerIndicator, defStyle, 0); mCentered = array.getBoolean(R.styleable.LinePagerIndicator_centered, defaultCentered); mLineWidth = array.getDimension(R.styleable.LinePagerIndicator_lineWidth, defalutLineWidth); mGapWidth = array.getDimension(R.styleable.LinePagerIndicator_gapWidth, defalutGapWidth); //? setStrokeWidth(array.getDimension(R.styleable.LinePagerIndicator_strokeWidth, defalutStrokeWidth)); mPaintUnselected .setColor(array.getColor(R.styleable.LinePagerIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(array.getColor(R.styleable.LinePagerIndicator_selectedColor, defaultSelectedColor)); Drawable background = array.getDrawable(R.styleable.LinePagerIndicator_android_background); // if (background != null) { setBackgroundDrawable(background); } array.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); //????(?????) mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.scsy150.util.HorizontalListView.java
/** * Parse the XML configuration for this widget * * @param context Context used for extracting attributes * @param attrs The Attribute Set containing the ColumnView attributes *///from w ww.ja va 2s .co m private void retrieveXmlConfiguration(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HorizontalListView); final Drawable d = a.getDrawable(R.styleable.HorizontalListView_android_divider); if (d != null) { setDivider(d); } // If a width is explicitly specified then use that width final int dividerWidth = a.getDimensionPixelSize(R.styleable.HorizontalListView_dividerWidth, 0); if (dividerWidth != 0) { setDividerWidth(dividerWidth); } a.recycle(); } }
From source file:com.maedi.user.godok.v1.viewpagerindicator.LinePageIndicator.java
@SuppressWarnings("deprecation") public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;//from ww w .ja va2 s . c o m final Resources res = getResources(); //Load defaults from resources final int defaultSelectedColor = res .getColor(com.viewpagerindicator.R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res .getColor(com.viewpagerindicator.R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res .getDimension(com.viewpagerindicator.R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res .getDimension(com.viewpagerindicator.R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res .getDimension(com.viewpagerindicator.R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res .getBoolean(com.viewpagerindicator.R.bool.default_line_indicator_centered); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, com.viewpagerindicator.R.styleable.LinePageIndicator, defStyle, 0); mCentered = a.getBoolean(com.viewpagerindicator.R.styleable.LinePageIndicator_centered, defaultCentered); mLineWidth = a.getDimension(com.viewpagerindicator.R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); mGapWidth = a.getDimension(com.viewpagerindicator.R.styleable.LinePageIndicator_gapWidth, defaultGapWidth); setStrokeWidth(a.getDimension(com.viewpagerindicator.R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintUnselected.setColor(a.getColor(com.viewpagerindicator.R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(a.getColor(com.viewpagerindicator.R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); Drawable background = a .getDrawable(com.viewpagerindicator.R.styleable.LinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:android.support.designox.widget.AppBarLayout.java
public AppBarLayout(Context context, AttributeSet attrs) { super(context, attrs); setOrientation(VERTICAL);// w w w.jav a 2 s . com ThemeUtils.checkAppCompatTheme(context); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppBarLayout, 0, R.style.Widget_Design_AppBarLayout); mTargetElevation = a.getDimensionPixelSize(R.styleable.AppBarLayout_elevation, 0); setBackgroundDrawable(a.getDrawable(R.styleable.AppBarLayout_android_background)); if (a.hasValue(R.styleable.AppBarLayout_expanded)) { setExpanded(a.getBoolean(R.styleable.AppBarLayout_expanded, false)); } a.recycle(); // Use the bounds view outline provider so that we cast a shadow, even without a background ViewUtils.setBoundsViewOutlineProvider(this); mListeners = new ArrayList<>(); ViewCompat.setElevation(this, mTargetElevation); ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4ox.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return onWindowInsetChanged(insets); } }); }
From source file:com.majestyk.gamedate.view.HorizontalListView.java
/** * Parse the XML configuration for this widget * * @param context Context used for extracting attributes * @param attrs The Attribute Set containing the ColumnView attributes *//*w w w . j a v a 2 s .c o m*/ private void retrieveXmlConfiguration(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HorizontalListView); // Get the provided drawable from the XML final Drawable d = a.getDrawable( com.meetme.android.horizontallistview.R.styleable.HorizontalListView_android_divider); if (d != null) { // If a drawable is provided to use as the divider then use its intrinsic width for the divider width setDivider(d); } // If a width is explicitly specified then use that width // final int dividerWidth = a.getDimensionPixelSize(R.styleable.HorizontalListView_dividerWidth, 0); // (dividerWidth != 0) { // setDividerWidth(dividerWidth); } //a.recycle(); }
From source file:com.example.stickablelistview.StickListView.java
/** * Parse the XML configuration for this widget * * @param context Context used for extracting attributes * @param attrs The Attribute Set containing the ColumnView attributes *///from w w w .j a va2 s .c o m private void retrieveXmlConfiguration(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StickListView); // Get the provided drawable from the XML final Drawable d = a.getDrawable(R.styleable.StickListView_android_divider); if (d != null) { // If a drawable is provided to use as the divider then use its intrinsic width for the divider width setDivider(d); } // If a width is explicitly specified then use that width final int dividerHeight = a.getDimensionPixelSize(R.styleable.StickListView_dividerHeight, 0); if (dividerHeight != 0) { setDividerHeight(dividerHeight); } a.recycle(); } }
From source file:aksha.upcomingdemo.HorizontalListView.java
/** * Parse the XML configuration for this widget * * @param context Context used for extracting attributes * @param attrs The Attribute Set containing the ColumnView attributes *//*from w ww . java2 s. com*/ private void retrieveXmlConfiguration(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HorizontalListView); // Get the provided drawable from the XML final Drawable d = a.getDrawable(R.styleable.HorizontalListView_android_divider); if (d != null) { // If a drawable is provided to use as the divider then use its intrinsic width for the divider width setDivider(d); } // If a width is explicitly specified then use that width final int dividerWidth = a.getDimensionPixelSize(R.styleable.HorizontalListView_dividerWidth, 0); if (dividerWidth != 0) { setDividerWidth(dividerWidth); } a.recycle(); } }