Example usage for android.graphics Paint LINEAR_TEXT_FLAG

List of usage examples for android.graphics Paint LINEAR_TEXT_FLAG

Introduction

In this page you can find the example usage for android.graphics Paint LINEAR_TEXT_FLAG.

Prototype

int LINEAR_TEXT_FLAG

To view the source code for android.graphics Paint LINEAR_TEXT_FLAG.

Click Source Link

Document

Paint flag that enables smooth linear scaling of text.

Usage

From source file:com.ruesga.rview.widget.MergedStatusChart.java

public MergedStatusChart(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    final Resources res = getResources();
    mHeightBarPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, res.getDisplayMetrics());
    mMinBarWidth = 0f;//  w  ww .  j  a va2 s.  c o m
    int openColor = Color.DKGRAY;
    int mergedColor = Color.DKGRAY;
    int abandonedColor = Color.DKGRAY;
    int textColor = Color.WHITE;

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.MergedStatusChart, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.MergedStatusChart_heightBarPadding:
            mHeightBarPadding = a.getDimension(attr, mHeightBarPadding);
            break;

        case R.styleable.MergedStatusChart_minBarWidth:
            mMinBarWidth = a.getDimension(attr, mMinBarWidth);
            break;

        case R.styleable.MergedStatusChart_openColor:
            openColor = a.getColor(attr, openColor);
            break;

        case R.styleable.MergedStatusChart_mergedColor:
            mergedColor = a.getColor(attr, mergedColor);
            break;

        case R.styleable.MergedStatusChart_abandonedColor:
            abandonedColor = a.getColor(attr, abandonedColor);
            break;

        case R.styleable.MergedStatusChart_statusLabelTextColor:
            textColor = a.getColor(attr, textColor);
            break;
        }
    }
    a.recycle();

    mOpenPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mOpenPaint.setStyle(Paint.Style.FILL);
    mMergedPaint = new Paint(mOpenPaint);
    mAbandonedPaint = new Paint(mOpenPaint);
    mOpenPaint.setColor(openColor);
    mMergedPaint.setColor(mergedColor);
    mAbandonedPaint.setColor(abandonedColor);

    mLabelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mLabelPaint.setTextAlign(Paint.Align.LEFT);
    mLabelPaint.setFakeBoldText(true);
    mLabelPaint.setColor(textColor);
    mLabelPaint
            .setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10f, res.getDisplayMetrics()));
    mLabelPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 2f, res.getDisplayMetrics());
    Rect bounds = new Rect();
    mLabelPaint.getTextBounds("0", 0, 1, bounds);
    mLabelHeight = bounds.height();

    if (getBackground() == null) {
        setBackgroundColor(Color.TRANSPARENT);
    }
}

From source file:com.microsoft.mimickeralarm.mimics.ProgressButton.java

private void prepareDrawText(int color) {
    mBrush.setFlags(Paint.LINEAR_TEXT_FLAG);
    mBrush.setStyle(Paint.Style.STROKE);
    mBrush.setColor(color);//from  w ww. j av  a 2 s. c  o  m
    mBrush.setTextAlign(Paint.Align.CENTER);
    mBrush.setStrokeWidth(0f);
    mBrush.setTextSize(mInitialRadius);
}

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;
        }/*from   ww w  .  ja v a  2s.c  o  m*/
    }
    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: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  ww  .  ja  v a 2  s . c  o  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));
    }/*from w  ww .j av  a  2 s . c  o  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.ruesga.timelinechart.TimelineChartView.java

private void init(Context ctx, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mUiHandler = new Handler(Looper.getMainLooper(), mMessenger);
    if (!isInEditMode()) {
        mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    }//from w  w w  .  jav  a  2s  .  c o  m

    final Resources res = getResources();
    final Resources.Theme theme = ctx.getTheme();

    mTickFormats = getResources().getStringArray(R.array.tlcDefTickLabelFormats);
    mTickLabels = getResources().getStringArray(R.array.tlcDefTickLabelValues);

    final DisplayMetrics dp = getResources().getDisplayMetrics();
    mSize8 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8, dp);
    mSize12 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, dp);
    mSize20 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, dp);

    final ViewConfiguration vc = ViewConfiguration.get(ctx);
    mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
    mTouchSlop = vc.getScaledTouchSlop() / 2;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mScroller = new OverScroller(ctx);

    int graphBgColor = ContextCompat.getColor(ctx, R.color.tlcDefGraphBackgroundColor);
    int footerBgColor = ContextCompat.getColor(ctx, R.color.tlcDefFooterBackgroundColor);

    mDefFooterBarHeight = mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight);
    mShowFooter = res.getBoolean(R.bool.tlcDefShowFooter);
    mGraphMode = res.getInteger(R.integer.tlcDefGraphMode);
    mPlaySelectionSoundEffect = res.getBoolean(R.bool.tlcDefPlaySelectionSoundEffect);
    mSelectionSoundEffectSource = res.getInteger(R.integer.tlcDefSelectionSoundEffectSource);
    mAnimateCursorTransition = res.getBoolean(R.bool.tlcDefAnimateCursorTransition);
    mFollowCursorPosition = res.getBoolean(R.bool.tlcDefFollowCursorPosition);
    mAlwaysEnsureSelection = res.getBoolean(R.bool.tlcDefAlwaysEnsureSelection);

    mGraphAreaBgPaint = new Paint();
    mGraphAreaBgPaint.setColor(graphBgColor);
    mFooterAreaBgPaint = new Paint();
    mFooterAreaBgPaint.setColor(footerBgColor);
    mTickLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mTickLabelFgPaint.setFakeBoldText(true);
    mTickLabelFgPaint.setColor(MaterialPaletteHelper.isDarkColor(footerBgColor) ? Color.LTGRAY : Color.DKGRAY);

    mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth);
    mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace);

    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.tlcTimelineChartView, defStyleAttr,
            defStyleRes);
    try {
        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.tlcTimelineChartView_tlcGraphBackground) {
                graphBgColor = a.getColor(attr, graphBgColor);
                mGraphAreaBgPaint.setColor(graphBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcShowFooter) {
                mShowFooter = a.getBoolean(attr, mShowFooter);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBackground) {
                footerBgColor = a.getColor(attr, footerBgColor);
                mFooterAreaBgPaint.setColor(footerBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBarHeight) {
                mFooterBarHeight = a.getDimension(attr, mFooterBarHeight);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcGraphMode) {
                mGraphMode = a.getInt(attr, mGraphMode);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAnimateCursorTransition) {
                mAnimateCursorTransition = a.getBoolean(attr, mAnimateCursorTransition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFollowCursorPosition) {
                mFollowCursorPosition = a.getBoolean(attr, mFollowCursorPosition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAlwaysEnsureSelection) {
                mAlwaysEnsureSelection = a.getBoolean(attr, mAlwaysEnsureSelection);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemWidth) {
                mBarItemWidth = a.getDimension(attr, mBarItemWidth);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemSpace) {
                mBarItemSpace = a.getDimension(attr, mBarItemSpace);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcPlaySelectionSoundEffect) {
                mPlaySelectionSoundEffect = a.getBoolean(attr, mPlaySelectionSoundEffect);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcSelectionSoundEffectSource) {
                mSelectionSoundEffectSource = a.getInt(attr, mSelectionSoundEffectSource);
            }
        }
    } finally {
        a.recycle();
    }

    // SurfaceView requires a background
    if (getBackground() == null) {
        setBackgroundColor(ContextCompat.getColor(ctx, android.R.color.transparent));
    }

    // Minimize the impact of create dynamic layouts by assume that in most case
    // we will have a day formatter
    mTickHasDayFormat = true;

    // Initialize stuff
    setupBackgroundHandler();
    setupTickLabels();
    if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        setupEdgeEffects();
    }
    setupAnimators();
    setupSoundEffects();

    // Initialize the drawing refs (this will be update when we have
    // the real size of the canvas)
    computeBoundAreas();

    // Create a fake data for the edit mode
    if (isInEditMode()) {
        setupViewInEditMode();
    }
}