List of usage examples for android.content.res TypedArray getDimension
public float getDimension(@StyleableRes int index, float defValue)
From source file:com.limxing.library.PullToRefresh.SwipeRefreshLayout.java
/** * Constructor that is called when inflating SwipeRefreshLayout from XML. * //from w w w . j a v a2 s . co m * @param context * @param attrs */ public SwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime); setWillNotDraw(false); final DisplayMetrics metrics = getResources().getDisplayMetrics(); mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR); // screenWidth = metrics.widthPixels; trigger_angle = Math.atan((double) metrics.widthPixels / metrics.heightPixels); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.swiperefresh); // setEnabled(a.getBoolean(0, true)); setEnabled(true); ptr_drawable = a.getResourceId(R.styleable.swiperefresh_roateImage, R.drawable.default_ptr_rotate); ptr_flip_drawable = a.getResourceId(R.styleable.swiperefresh_flipImage, R.drawable.default_ptr_flip); finished_drawable = a.getResourceId(R.styleable.swiperefresh_finishedImage, R.drawable.xlistview_success); pull2refresh = a.getBoolean(R.styleable.swiperefresh_ptr, true); pull2load = a.getBoolean(R.styleable.swiperefresh_ptl, true); textSize = a.getDimension(R.styleable.swiperefresh_srlTextSize, DEFAULT_TIPS_TEXTSIZE * metrics.density); textColor = a.getColor(R.styleable.swiperefresh_srlTextColor, DEFAULT_TEXT_COLOR); type = a.getInt(R.styleable.swiperefresh_srlAnimationStyle, DEFAULT_TYPE); pullDownLabel = a.getString(R.styleable.swiperefresh_pullDownLabel); refreshingLabel = a.getString(R.styleable.swiperefresh_refreshingLabel); releaseDownLabel = a.getString(R.styleable.swiperefresh_releaseDownLabel); pullUpLabel = a.getString(R.styleable.swiperefresh_pullUpLabel); loadingLabel = a.getString(R.styleable.swiperefresh_loadingLabel); releaseUpLabel = a.getString(R.styleable.swiperefresh_releaseUpLabel); if (null == pullDownLabel || pullDownLabel.equals("")) { pullDownLabel = DEFAULT_PULL_DOWN_LABEL; } if (null == refreshingLabel || refreshingLabel.equals("")) { refreshingLabel = DEFAULT_REFRESHING_LABEL; } if (null == releaseDownLabel || releaseDownLabel.equals("")) { releaseDownLabel = DEFAULT_RELEASE_DOWN_LABEL; } if (null == pullUpLabel || pullUpLabel.equals("")) { pullUpLabel = DEFAULT_PULL_UP_LABEL; } if (null == loadingLabel || loadingLabel.equals("")) { loadingLabel = DEFAULT_LOADING_LABEL; } if (null == releaseUpLabel || releaseUpLabel.equals("")) { releaseUpLabel = DEFAULT_RELEASE_UP_LABEL; } mProgressBar = new SwipeProgressBar(this, textSize, textColor, ptr_drawable, ptr_flip_drawable, finished_drawable, type); a.recycle(); }
From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButton.java
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // ThemeUtils.checkAppCompatTheme(context); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, R.style.Widget_Design_FloatingActionButton); mBackgroundTint = a.getColorStateList(R.styleable.FloatingActionButton_android_backgroundTint); mBackgroundTintMode = ViewUtils/* w w w. j a va 2 s . c om*/ .parseTintMode(a.getInt(R.styleable.FloatingActionButton_android_backgroundTintMode, -1), null); mRippleColor = a.getColor(R.styleable.FloatingActionButton_rippleColor, 0); mSize = a.getInt(R.styleable.FloatingActionButton_fabSize, SIZE_AUTO); mCustomSize = a.getDimensionPixelSize(R.styleable.FloatingActionButton_fabCustomSize, 0); mBorderWidth = a.getDimensionPixelSize(R.styleable.FloatingActionButton_borderWidth, 0); final float elevation = a.getDimension(R.styleable.FloatingActionButton_android_elevation, 0f); final float pressedTranslationZ = a.getDimension(R.styleable.FloatingActionButton_pressedTranslationZ, 0f); mCompatPadding = a.getBoolean(R.styleable.FloatingActionButton_useCompatPadding, false); a.recycle(); /* mImageHelper = new AppCompatImageHelper(this); mImageHelper.loadFromAttributes(attrs, defStyleAttr); */ mMaxImageSize = (int) getResources().getDimension(R.dimen.design_fab_image_size); getImpl().setBackgroundDrawable(mBackgroundTint, mBackgroundTintMode, mRippleColor, mBorderWidth); getImpl().setElevation(elevation); getImpl().setPressedTranslationZ(pressedTranslationZ); }
From source file:com.tandong.sa.vpic.CirclePageIndicator.java
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;//from w ww . j av a2 s.c om // Load defaults from resources final Resources res = getResources(); final int defaultPageColor = res.getColor(context.getResources() .getIdentifier("default_circle_indicator_page_color", "color", context.getPackageName())); final int defaultFillColor = res.getColor(context.getResources() .getIdentifier("default_circle_indicator_fill_color", "color", context.getPackageName())); final int defaultOrientation = res.getInteger(context.getResources() .getIdentifier("default_circle_indicator_orientation", "integer", context.getPackageName())); final int defaultStrokeColor = res.getColor(context.getResources() .getIdentifier("default_circle_indicator_stroke_color", "color", context.getPackageName())); final float defaultStrokeWidth = res.getDimension(context.getResources() .getIdentifier("default_circle_indicator_stroke_width", "dimen", context.getPackageName())); final float defaultRadius = res.getDimension(context.getResources() .getIdentifier("default_circle_indicator_radius", "dimen", context.getPackageName())); final boolean defaultCentered = res.getBoolean(context.getResources() .getIdentifier("default_circle_indicator_centered", "bool", context.getPackageName())); final boolean defaultSnap = res.getBoolean(context.getResources() .getIdentifier("default_circle_indicator_snap", "bool", context.getPackageName())); // Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, new int[] { getResources().getIdentifier("CirclePageIndicator", "styleable", context.getPackageName()) }, defStyle, 0); mCentered = a.getBoolean( getResources().getIdentifier("CirclePageIndicator_centered", "styleable", context.getPackageName()), defaultCentered); mOrientation = a.getInt(getResources().getIdentifier("CirclePageIndicator_android_orientation", "styleable", context.getPackageName()), defaultOrientation); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_pageColor", "styleable", context.getPackageName()), defaultPageColor)); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_strokeColor", "styleable", context.getPackageName()), defaultStrokeColor)); mPaintStroke.setStrokeWidth(a.getDimension(getResources().getIdentifier("CirclePageIndicator_strokeWidth", "styleable", context.getPackageName()), defaultStrokeWidth)); mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_fillColor", "styleable", context.getPackageName()), defaultFillColor)); mRadius = a.getDimension( getResources().getIdentifier("CirclePageIndicator_radius", "styleable", context.getPackageName()), defaultRadius); mSnap = a.getBoolean( getResources().getIdentifier("CirclePageIndicator_snap", "styleable", context.getPackageName()), defaultSnap); Drawable background = a.getDrawable(getResources().getIdentifier("CirclePageIndicator_android_background", "styleable", context.getPackageName())); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:co.vn.e_alarm.customwiget.SlidingLayer.java
public SlidingLayer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Style/* w w w .j av a 2 s . c om*/ final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer); // Set the side of the screen setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO)); // Sets the shadow drawable int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1); if (shadowRes != -1) { setShadowDrawable(shadowRes); } // Sets the shadow width setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0)); // Sets the ability to close the layer by tapping in any empty space closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true); // Sets the ability to open the layout by tapping on any of the exposed closed layer openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true); // How much of the view sticks out when closed setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0)); ta.recycle(); init(); }
From source file:com.example.michaelg.myapplication.Item.discreteseekbar.internal.Marker.java
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue, int thumbSize, int separation) { super(context, attrs, defStyleAttr); //as we're reading the parent DiscreteSeekBar attributes, it may wrongly set this view's visibility. setVisibility(View.VISIBLE);/*from w w w.j av a 2 s .co m*/ DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar); int padding = (int) (PADDING_DP * displayMetrics.density) * 2; int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance, R.style.Widget_DiscreteIndicatorTextAppearance); mNumber = new TextView(context); //Add some padding to this textView so the bubble has some space to breath mNumber.setPadding(padding, 0, padding, 0); mNumber.setTextAppearance(context, textAppearanceId); mNumber.setGravity(Gravity.CENTER); mNumber.setText(maxValue); mNumber.setMaxLines(1); mNumber.setSingleLine(true); SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE); mNumber.setVisibility(View.INVISIBLE); //add some padding for the elevation shadow not to be clipped //I'm sure there are better ways of doing this... setPadding(padding, padding, padding, padding); resetSizes(maxValue); mSeparation = separation; ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor); mMarkerDrawable = new MarkerDrawable(color, thumbSize); mMarkerDrawable.setCallback(this); mMarkerDrawable.setMarkerListener(this); mMarkerDrawable.setExternalOffset(padding); //Elevation for anroid 5+ float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation, ELEVATION_DP * displayMetrics.density); ViewCompat.setElevation(this, elevation); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SeekBarCompat.setOutlineProvider(this, mMarkerDrawable); } a.recycle(); }
From source file:com.danilov.supermanga.core.view.SlidingLayer.java
/** * Constructor for the sliding layer.<br> * By default this panel will// w w w . j a va 2 s . c o m * <ol> * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}</li> * <li>Use no shadow drawable. (i.e. with width of 0)</li> * <li>Close when the panel is tapped</li> * <li>Open when the offset is tapped, but will have an offset of 0</li> * </ol> * @param context a reference to an existing context * @param attrs attribute set constructed from attributes set in android .xml file * @param defStyle style res id */ public SlidingLayer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Style final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer); // Set the side of the screen setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO)); // Sets the shadow drawable int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1); if (shadowRes != -1) { setShadowDrawable(shadowRes); } // Sets the shadow width setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0)); // Sets the ability to close the layer by tapping in any empty space closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true); // Sets the ability to open the layout by tapping on any of the exposed closed layer openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true); // How much of the view sticks out when closed setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0)); ta.recycle(); init(); }
From source file:com.glm.view.SlidingLayer.java
/** * Constructor for the sliding layer.<br> * By default this panel will//from w ww.j a v a 2 s . c o m * <ol> * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}</li> * <li>Use no shadow drawable. (i.e. with width of 0)</li> * <li>Close when the panel is tapped</li> * <li>Open when the offset is tapped, but will have an offset of 0</li> * </ol> * @param context a reference to an existing context * @param attrs attribute set constructed from attributes set in android .xml file * @param defStyle style res id */ public SlidingLayer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; // Style final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer); // Set the side of the screen setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO)); // Sets the shadow drawable int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1); if (shadowRes != -1) { setShadowDrawable(shadowRes); } // Sets the shadow width setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0)); // Sets the ability to close the layer by tapping in any empty space closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true); // Sets the ability to open the layout by tapping on any of the exposed closed layer openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true); // How much of the view sticks out when closed setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0)); ta.recycle(); init(); }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. *//*from w w w. j av a 2s .co m*/ 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.yek.keyboard.keyboards.views.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. *///from ww w . j av a 2s . c o m 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); } mXGap = 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.matthewlogan.reversedrawerlayout.library.ReverseDrawerLayout.java
public ReverseDrawerLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final float density = getResources().getDisplayMetrics().density; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ReverseDrawerLayout, 0, 0); try {/* w w w .jav a 2 s . c o m*/ mDrawerOverhang = (int) a.getDimension(R.styleable.ReverseDrawerLayout_drawerOverhang, (int) (DRAWER_OVERHANG * density + 0.5f)); } finally { a.recycle(); } final float minVel = MIN_FLING_VELOCITY * density; mLeftCallback = new ViewDragCallback(Gravity.LEFT); mRightCallback = new ViewDragCallback(Gravity.RIGHT); mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback); mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); mLeftDragger.setMinVelocity(minVel); mLeftCallback.setDragger(mLeftDragger); mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback); mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT); mRightDragger.setMinVelocity(minVel); mRightCallback.setDragger(mRightDragger); ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate()); ViewGroupCompat.setMotionEventSplittingEnabled(this, false); }