java类android.graphics.DashPathEffect的实例源码

WoWoPathView.java 文件源码 项目:GitHub 阅读 29 收藏 0 点赞 0 评论 0
private void initPaint() {
    paint = new Paint();
    paint.setColor(pathColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(pathWidth);
    paint.setAntiAlias(true);

    setPath(new Path());

    if (dashPath) {
        pathEffect = new DashPathEffect(new float[]{dashSegmentLength, dashPaddingLength}, dynamicalPathPhase);
        paint.setPathEffect(pathEffect);
    }
}
ManeuversStyleKit.java 文件源码 项目:mapbox-navigation-android 阅读 32 收藏 0 点赞 0 评论 0
DashPathEffect get(float dash, float gap, float phase) {
  if (this.dash != dash || this.gap != gap || this.phase != phase) {
    this.dash = dash;
    this.gap = gap;
    this.phase = phase;
    this.effect = new DashPathEffect(new float[] {dash, gap}, phase);
  }
  return this.effect;
}
GradeProgressView.java 文件源码 项目:RunHDU 阅读 23 收藏 0 点赞 0 评论 0
private void setup() {

        mRectF = new RectF();
        mOuterRectF = new RectF();

        mOuterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mOuterPaint.setStrokeWidth(outLineWidth);
        mOuterPaint.setColor(mBackgroundColor);
        mOuterPaint.setStyle(Paint.Style.STROKE);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStrokeWidth(lineWidth);
        mPaint.setColor(mBackgroundColor);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setPathEffect(new DashPathEffect(new float[]{dashWith, dashSpace}, dashSpace));

        mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mProgressPaint.setStrokeWidth(lineWidth);
        mProgressPaint.setColor(mProgressColor);
        mProgressPaint.setStyle(Paint.Style.STROKE);
        mProgressPaint.setPathEffect(new DashPathEffect(new float[]{dashWith, dashSpace}, dashSpace));

        mPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPointerPaint.setStrokeWidth(pointLineWidth / 2);
        mPointerPaint.setColor(mProgressColor);
        mPointerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPointerPaint.setStrokeCap(Paint.Cap.ROUND);
        mPointerPaint.setShadowLayer(4, 3, 0, 0x20000000);

        mInnerCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mInnerCirclePaint.setStrokeWidth(pointLineWidth);
        mInnerCirclePaint.setColor(mProgressColor);
        mInnerCirclePaint.setStyle(Paint.Style.STROKE);
        mInnerCirclePaint.setShadowLayer(4, 3, 0, 0x20000000);
    }
GraphActivity.java 文件源码 项目:Weather-Android 阅读 31 收藏 0 点赞 0 评论 0
private void temperatureGraph() {
    LineChartView lineChartView = (LineChartView) findViewById(R.id.graph_temperature);

    // Data
    LineSet dataset = new LineSet();
    for (int i = 0; i < weatherList.size(); i++) {
        float temperature = UnitConvertor.convertTemperature(Float.parseFloat(weatherList.get(i).getTemperature()), sp);

        if (temperature < minTemp) {
            minTemp = temperature;
        }

        if (temperature > maxTemp) {
            maxTemp = temperature;
        }

        dataset.addPoint(getDateLabel(weatherList.get(i), i), (float) ((Math.ceil(temperature / 2)) * 2));
    }
    dataset.setSmooth(false);
    dataset.setColor(Color.parseColor("#FF5722"));
    dataset.setThickness(4);

    lineChartView.addData(dataset);

    // Grid
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
    paint.setColor(Color.parseColor("#333333"));
    paint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
    paint.setStrokeWidth(1);
    lineChartView.setGrid(ChartView.GridType.HORIZONTAL, paint);
    lineChartView.setBorderSpacing(Tools.fromDpToPx(10));
    lineChartView.setAxisBorderValues((int) minTemp - 2, (int) maxTemp + 2);
    lineChartView.setStep(2);
    lineChartView.setXAxis(false);
    lineChartView.setYAxis(false);

    lineChartView.show();
}
GraphActivity.java 文件源码 项目:Weather-Android 阅读 35 收藏 0 点赞 0 评论 0
private void rainGraph() {
    LineChartView lineChartView = (LineChartView) findViewById(R.id.graph_rain);

    // Data
    LineSet dataset = new LineSet();
    for (int i = 0; i < weatherList.size(); i++) {
        float rain = Float.parseFloat(weatherList.get(i).getRain());

        if (rain < minRain) {
            minRain = rain;
        }

        if (rain > maxRain) {
            maxRain = rain;
        }

        dataset.addPoint(getDateLabel(weatherList.get(i), i), rain);
    }
    dataset.setSmooth(false);
    dataset.setColor(Color.parseColor("#2196F3"));
    dataset.setThickness(4);

    lineChartView.addData(dataset);

    // Grid
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
    paint.setColor(Color.parseColor("#333333"));
    paint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
    paint.setStrokeWidth(1);
    lineChartView.setGrid(ChartView.GridType.HORIZONTAL, paint);
    lineChartView.setBorderSpacing(Tools.fromDpToPx(10));
    lineChartView.setAxisBorderValues((int) minRain - 1, (int) maxRain + 2);
    lineChartView.setStep(1);
    lineChartView.setXAxis(false);
    lineChartView.setYAxis(false);

    lineChartView.show();
}
GraphActivity.java 文件源码 项目:Weather-Android 阅读 24 收藏 0 点赞 0 评论 0
private void pressureGraph() {
    LineChartView lineChartView = (LineChartView) findViewById(R.id.graph_pressure);

    // Data
    LineSet dataset = new LineSet();
    for (int i = 0; i < weatherList.size(); i++) {
        float pressure = UnitConvertor.convertPressure(Float.parseFloat(weatherList.get(i).getPressure()), sp);

        if (pressure < minPressure) {
            minPressure = pressure;
        }

        if (pressure > maxPressure) {
            maxPressure = pressure;
        }

        dataset.addPoint(getDateLabel(weatherList.get(i), i), pressure);
    }
    dataset.setSmooth(true);
    dataset.setColor(Color.parseColor("#4CAF50"));
    dataset.setThickness(4);

    lineChartView.addData(dataset);

    // Grid
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
    paint.setColor(Color.parseColor("#333333"));
    paint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
    paint.setStrokeWidth(1);
    lineChartView.setGrid(ChartView.GridType.HORIZONTAL, paint);
    lineChartView.setBorderSpacing(Tools.fromDpToPx(10));
    lineChartView.setAxisBorderValues((int) minPressure - 1, (int) maxPressure + 1);
    lineChartView.setStep(2);
    lineChartView.setXAxis(false);
    lineChartView.setYAxis(false);

    lineChartView.show();
}
HistoryChartView.java 文件源码 项目:YiZhi 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 开启动画
 */
private void startAnimation() {
    if (mValueAnimator != null) {
        mValueAnimator.cancel();
    }
    final float targetTempLength = mTargetTempPathMeasure.getLength();
    final float roomTempLength = mRoomTempPathMeasure.getLength();
    mValueAnimator = ValueAnimator.ofFloat(1, 0);
    mValueAnimator.setDuration(ANIM_DURATION);
    // 减速插值器
    mValueAnimator.setInterpolator(new DecelerateInterpolator());
    mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float fraction = (Float) animation.getAnimatedValue();
            // 更新mtargetTempEffect
            mtargetTempEffect = new DashPathEffect(new float[]{
                    targetTempLength, targetTempLength}, fraction
                    * targetTempLength);
            targetTempPaint.setPathEffect(mtargetTempEffect);
            // 更新mRoomTempEffect
            mRoomTempEffect = new DashPathEffect(new float[]{
                    roomTempLength, roomTempLength}, fraction
                    * roomTempLength);
            roomTempPaint.setPathEffect(mRoomTempEffect);
            // 更新rect绘制fraction进度
            mRectFration = 1 - fraction;// fraction是1->0 我们需要的柱形图绘制比例是0->1
            postInvalidate();
        }
    });
    mValueAnimator.start();
}


问题


面经


文章

微信
公众号

扫码关注公众号