List of usage examples for android.text TextPaint TextPaint
public TextPaint(Paint p)
From source file:com.ruesga.rview.widget.ActivityStatsChart.java
public ActivityStatsChart(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final Resources r = getResources(); setLayerType(View.LAYER_TYPE_SOFTWARE, null); int color = Color.DKGRAY; int textColor = Color.WHITE; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.ActivityStatsChart, defStyleAttr, 0); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.ActivityStatsChart_charLineColor: color = a.getColor(attr, color); break; case R.styleable.ActivityStatsChart_charLineTextColor: textColor = a.getColor(attr, textColor); break; }/* w ww . j a v a 2 s . com*/ } a.recycle(); mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setColor(color); mLinePaint.setStrokeWidth( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.5f, r.getDisplayMetrics())); mAreaPaint = new Paint(mLinePaint); mAreaPaint.setStyle(Paint.Style.FILL); mAreaPaint.setAlpha(180); mGridLinesPaint = new Paint(); mGridLinesPaint.setStyle(Paint.Style.STROKE); mGridLinesPaint.setColor(textColor); mGridLinesPaint.setStrokeWidth( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f, r.getDisplayMetrics())); mGridLinesPaint.setAlpha(90); mGridLinesPaint.setPathEffect(new DashPathEffect(new float[] { 10, 10 }, 0)); mTicksPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mTicksPaint.setColor(textColor); mTicksPaint.setTextAlign(Paint.Align.RIGHT); mTicksPaint.setAlpha(180); mTicksPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8f, r.getDisplayMetrics())); // Ensure we have a background. Otherwise it will not draw anything if (getBackground() == null) { setBackgroundColor(Color.TRANSPARENT); } }
From source file:rikka.akashitoolkit.ui.widget.IconSwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. *///w w w.j a va 2s.co m @SuppressLint("PrivateResource") public IconSwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; TintTypedArray a; a = TintTypedArray.obtainStyledAttributes(context, attrs, android.support.v7.appcompat.R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_android_thumb); if (mThumbDrawable != null) { mThumbDrawable.setCallback(this); } mTrackDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_track); if (mTrackDrawable != null) { mTrackDrawable.setCallback(this); } mTextOn = a.getText(android.support.v7.appcompat.R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(android.support.v7.appcompat.R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(android.support.v7.appcompat.R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_thumbTextPadding, 0); /*mSwitchMinWidth = a.getDimensionPixelSize( android.support.v7.appcompat.R.styleable.SwitchCompat_switchMinWidth, 0);*/ mSwitchPadding = a .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(android.support.v7.appcompat.R.styleable.SwitchCompat_splitTrack, false); final int appearance = a .getResourceId(android.support.v7.appcompat.R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mDrawableManager = AppCompatDrawableManager.get(); a.recycle(); a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.IconSwitchCompat, defStyleAttr, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.IconSwitchCompat_minWidth, 0); Drawable icon = a.getDrawable(R.styleable.IconSwitchCompat_iconDrawable); Drawable iconChecked = a.getDrawable(R.styleable.IconSwitchCompat_iconDrawableChecked); DrawableCompat.setTintList(icon, a.getColorStateList(R.styleable.IconSwitchCompat_iconColor)); DrawableCompat.setTintList(iconChecked, a.getColorStateList(R.styleable.IconSwitchCompat_iconColor)); mIconDrawable = new StateListDrawable(); ((StateListDrawable) mIconDrawable).addState(CHECKED_STATE_SET, iconChecked); ((StateListDrawable) mIconDrawable).addState(new int[] {}, icon); if (mIconDrawable != null) { mIconDrawable.setCallback(this); } /*if (mThumbDrawable != null) { DrawableCompat.setTintList(mThumbDrawable, a.getColorStateList(R.styleable.IconSwitchCompat_thumbColor)); } if (mTrackDrawable != null) { DrawableCompat.setTintList(mTrackDrawable, a.getColorStateList(R.styleable.IconSwitchCompat_trackColor)); }*/ a.recycle(); ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:lewa.support.v7.widget.SwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. *//*from w w w . j a v a 2 s . c o m*/ public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(R.styleable.SwitchCompat_android_thumb); mTrackDrawable = a.getDrawable(R.styleable.SwitchCompat_track); mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mTintManager = a.getTintManager(); a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:android.support.v7ox.widget.SwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. *//* ww w . ja va2s . c o m*/ public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(R.styleable.SwitchCompat_android_thumb); if (mThumbDrawable != null) { mThumbDrawable.setCallback(this); } mTrackDrawable = a.getDrawable(R.styleable.SwitchCompat_track); if (mTrackDrawable != null) { mTrackDrawable.setCallback(this); } mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mDrawableManager = AppCompatDrawableManager.get(); a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:android.support.v7.widget.SwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. */// ww w . ja v a 2 s . co m public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(R.styleable.SwitchCompat_android_thumb); if (mThumbDrawable != null) { mThumbDrawable.setCallback(this); } mTrackDrawable = a.getDrawable(R.styleable.SwitchCompat_track); if (mTrackDrawable != null) { mTrackDrawable.setCallback(this); } mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mTintManager = a.getTintManager(); a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr) { mUiHandler = new Handler(Looper.getMainLooper(), mMessenger); final Resources res = getResources(); final ViewConfiguration vc = ViewConfiguration.get(ctx); mTouchSlop = vc.getScaledTouchSlop() / 2; mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); mScroller = new OverScroller(ctx); int footerLabelColor = ContextCompat.getColor(getContext(), R.color.tlcStepsFooterLabelColor); int barItemBg = ContextCompat.getColor(getContext(), R.color.tlcStepsBarItemBg); int highlightBarItemBg = ContextCompat.getColor(getContext(), R.color.tlcStepsHighlightBarItemBg); mBarItemBgPaint = new Paint(); mBarItemBgPaint.setColor(barItemBg); mHighlightBarItemBgPaint = new Paint(); mHighlightBarItemBgPaint.setColor(highlightBarItemBg); mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight); mViewAreaBgPaint = new Paint(); mGraphAreaBgPaint = new Paint(); mGraphAreaBgPaint.setColor(Color.TRANSPARENT); mFooterAreaBgPaint = new Paint(); mFooterAreaBgPaint.setColor(Color.TRANSPARENT); mGraphBottomLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mGraphBottomLinePaint.setColor(Color.WHITE); mGraphBottomLinePaint.setStrokeWidth(1); // /*from w w w.j av a 2 s . co m*/ mGraphTargetDashedLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mGraphTargetDashedLinePaint.setStyle(Paint.Style.STROKE); mGraphTargetDashedLinePaint.setColor(Color.WHITE); mGraphTargetDashedLinePaint.setStrokeWidth(1); PathEffect pathEffect = new DashPathEffect(new float[] { 9, 3 }, 1); mGraphTargetDashedLinePaint.setPathEffect(pathEffect); // labelPaint?? mLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mLabelFgPaint.setColor(footerLabelColor); // DisplayMetrics dp = getResources().getDisplayMetrics(); // float labelSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.tlcDefFooterLabelSize), dp); mLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mHighlightLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mHighlightLabelFgPaint.setColor(Color.WHITE); mHighlightLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth); mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace); mTopSpaceHeight = res.getDimension(R.dimen.tlcDefTopSpace); // SurfaceView requires a background if (getBackground() == null) { setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); } // Initialize stuff setupBackgroundHandler(); setupTickLabels(); // Initialize the drawing refs (this will be update when we have // the real size of the canvas) computeBoundAreas(); }
From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr) { mUiHandler = new Handler(Looper.getMainLooper(), mMessenger); final Resources res = getResources(); final ViewConfiguration vc = ViewConfiguration.get(ctx); mTouchSlop = vc.getScaledTouchSlop() / 2; mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); mScroller = new OverScroller(ctx); int footerLabelColor = ContextCompat.getColor(getContext(), R.color.tlcSleepFooterLabelColor); int barItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepBarItemBg); int highlightBarItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepHighlightBarItemBg); int barDeepItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepBarDeepItemBg); int highlightBarDeepItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepHighlightBarDeepItemBg); mBarItemBgPaint = new Paint(); mBarItemBgPaint.setColor(barItemBg); mHighlightBarItemBgPaint = new Paint(); mHighlightBarItemBgPaint.setColor(highlightBarItemBg); mBarDeepItemBgPaint = new Paint(); mBarDeepItemBgPaint.setColor(barDeepItemBg); mHighlightBarDeepItemBgPaint = new Paint(); mHighlightBarDeepItemBgPaint.setColor(highlightBarDeepItemBg); mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight); mViewAreaBgPaint = new Paint(); mGraphAreaBgPaint = new Paint(); mGraphAreaBgPaint.setColor(Color.TRANSPARENT); mFooterAreaBgPaint = new Paint(); mFooterAreaBgPaint.setColor(Color.TRANSPARENT); mGraphBottomLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mGraphBottomLinePaint.setColor(Color.WHITE); mGraphBottomLinePaint.setStrokeWidth(1); // labelPaint?? mLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mLabelFgPaint.setColor(footerLabelColor); // DisplayMetrics dp = getResources().getDisplayMetrics(); // float labelSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.tlcDefFooterLabelSize), dp); mLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mHighlightLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mHighlightLabelFgPaint.setColor(Color.WHITE); mHighlightLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth); mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace); mTopSpaceHeight = res.getDimension(R.dimen.tlcDefTopSpace); // SurfaceView requires a background if (getBackground() == null) { setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); }//ww w . j ava2s . co m // Initialize stuff setupBackgroundHandler(); setupTickLabels(); // Initialize the drawing refs (this will be update when we have // the real size of the canvas) computeBoundAreas(); }
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
/** * Construct a new Switch with a default style determined by the given theme * attribute, overriding specific style attributes as requested. * /*from w w w .j a v a2s.c o m*/ * @param context * The Context that will determine this widget's theming. * @param attrs * Specification of attributes that should deviate from the * default styling. * @param defStyleAttr * An attribute in the current theme that contains a reference to * a style resource that supplies default values for the view. * Can be 0 to not look for defaults. */ public SmoothSwitch(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); final float density = res.getDisplayMetrics().density; mTextPaint.density = density;//res.getDisplayMetrics().density; final int thumbSize = (int) (Default.DEFAULT_SIZE_DP * density + 0.5f);// truckSize = 15dp final int thumbWidth = thumbSize;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbWidth, thumbSize); mThumbColorOn = Default.DEFAULT_THUMB_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOn, Default.DEFAULT_THUMB_ON_COLOR); mThumbColorOff = Default.DEFAULT_THUMB_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOff, Default.DEFAULT_THUMB_OFF_COLOR); mTrackColorOn = Default.DEFAULT_TRACK_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOn, Default.DEFAULT_TRACK_ON_COLOR); mTrackColorOff = Default.DEFAULT_TRACK_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOff, Default.DEFAULT_TRACK_OFF_COLOR); final float radius = thumbSize * Default.DEFAULT_RADIUS_PERCENT_OF_SIZE;//a.getFloat(R.styleable.SwitchCompat_radiusPercentOfThumbSize, // Default.DEFAULT_RADIUS_PERCENT_OF_SIZE); final int thumbPadding = (int) (thumbSize * Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_thumbPaddingPercentOfThumbSize, // Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE) + 0.5f); final int trackPadding = (int) (thumbSize * Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_trackPaddingPercentOfThumbSize, // Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE) + 0.5f); final int curThumbColor = isChecked() ? mThumbColorOn : mThumbColorOff; final int curTrackColor = isChecked() ? mTrackColorOn : mTrackColorOff; mThumbDrawable = makeThumbDrawable(curThumbColor, thumbWidth, thumbSize, radius, thumbPadding); mTrackDrawable = makeTrackDrawable(curTrackColor, thumbWidth, thumbSize, radius, trackPadding); // final int onDisableColor = getDisableColor(onColor); // final int offDisableColor = getDisableColor(offColor); // final StateListDrawable thumbDrawable = new StateListDrawable(); // thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked}, // makeThumbDrawable(onDisableColor, thumbSize));// Disabled ON // thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked}, // makeThumbDrawable(offDisableColor, thumbSize));// Disabled OFF // thumbDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked }, // makeThumbDrawable(onColor, thumbSize)); // thumbDrawable.addState(new int[] {}, makeThumbDrawable(offColor, thumbSize)); // mThumbDrawable = thumbDrawable; // // final StateListDrawable trackDrawable = new StateListDrawable(); // trackDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked}, // makeTrackDrawable(onDisableColor, thumbSize));// Disabled ON // trackDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked}, // makeTrackDrawable(offDisableColor, thumbSize));// Disabled OFF // trackDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked }, // makeTrackDrawable(onColor, thumbSize)); // trackDrawable.addState(new int[] {}, makeTrackDrawable(offColor, thumbSize)); // mTrackDrawable = trackDrawable; // mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); // mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = false;//a.getBoolean(R.styleable.SwitchCompat_showText, false); mThumbTextPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); // mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchMinWidth = Math.max(mSwitchMinWidth, thumbWidth * 2); mSwitchPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); // mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); // final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); // if (appearance != 0) { // setSwitchTextAppearance(context, appearance); // }else{ // ColorStateList colors = a.getColorStateList(R.styleable.SwitchCompat_switchTextColor); // if (colors != null) { // mTextColors = colors; // } else { // // If no color set in TextAppearance, default to the view's textColor // mTextColors = getTextColors(); // } // float ts = a.getDimension(R.styleable.SwitchCompat_switchTextSize, 0); // if (ts != 0) { // if (ts != mTextPaint.getTextSize()) { // mTextPaint.setTextSize(ts); // requestLayout(); // } // } // } // mTintManager = a.getTintManager(); // a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:com.dongdong.wheel.WheelView.java
/** * Initializes resources/*w ww .j a v a 2 s.c o m*/ */ private void initResourcesIfNecessary() { if (mItemsPaint == null) { mItemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG); //mItemsPaint.density = getResources().getDisplayMetrics().density; mItemsPaint.setTextSize(TEXT_SIZE); } if (mValuePaint == null) { mValuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG); //mValuePaint.density = getResources().getDisplayMetrics().density; mValuePaint.setTextSize(TEXT_SIZE); mValuePaint.setShadowLayer(0.1f, 0, 0.1f, 0xFFC0C0C0); } if (mCenterDrawable == null) { mCenterDrawable = ContextCompat.getDrawable(getContext(), R.drawable.wheel_val); } if (mTopShadow == null) { mTopShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS); } if (mBottomShadow == null) { mBottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS); } setBackgroundResource(R.drawable.wheel_bg); }
From source file:com.ruesga.rview.widget.TagEditTextView.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr) { mHandler = new Handler(mTagMessenger); mTriggerTagCreationThreshold = CREATE_CHIP_DEFAULT_DELAYED_TIMEOUT; Resources.Theme theme = ctx.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TagEditTextView, defStyleAttr, 0); mReadOnly = a.getBoolean(R.styleable.TagEditTextView_readonly, false); mDefaultTagMode = TAG_MODE.HASH;//from w w w . jav a 2 s. com // Create the internal EditText that holds the tag logic mTagEdit = mReadOnly ? new TagEditText(ctx, attrs, defStyleAttr) : new TagEditText(ctx, attrs); mTagEdit.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0)); mTagEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); mTagEdit.addTextChangedListener(mEditListener); mTagEdit.setTextIsSelectable(false); mTagEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); mTagEdit.setOnFocusChangeListener((v, hasFocus) -> { // Remove any pending message mHandler.removeMessages(MESSAGE_CREATE_CHIP); }); mTagEdit.setCustomSelectionActionModeCallback(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { } }); addView(mTagEdit); // Configure the window mode for landscape orientation, to disallow hide the // EditText control, and show characters instead of chips int orientation = ctx.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (ctx instanceof Activity) { Window window = ((Activity) ctx).getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); mTagEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); } } } // Save the keyListener for later restore mEditModeKeyListener = mTagEdit.getKeyListener(); // Initialize resources for chips mChipBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mChipFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mChipFgPaint.setTextSize(mTagEdit.getTextSize() * (mReadOnly ? 1 : 0.8f)); if (CHIP_TYPEFACE != null) { mChipFgPaint.setTypeface(CHIP_TYPEFACE); } mChipFgPaint.setTextAlign(Paint.Align.LEFT); // Calculate the width area used to remove the tag in the chip mChipRemoveAreaWidth = (int) (mChipFgPaint.measureText(CHIP_REMOVE_TEXT) + 0.5f); if (ONE_PIXEL <= 0) { Resources res = getResources(); ONE_PIXEL = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics()); } int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.TagEditTextView_supportUserTags: setSupportsUserTags(a.getBoolean(attr, false)); break; case R.styleable.TagEditTextView_chipBackgroundColor: mChipBackgroundColor = a.getColor(attr, mChipBackgroundColor); break; case R.styleable.TagEditTextView_chipTextColor: mChipFgPaint.setColor(a.getColor(attr, Color.WHITE)); break; } } a.recycle(); }