Example usage for android.graphics DashPathEffect DashPathEffect

List of usage examples for android.graphics DashPathEffect DashPathEffect

Introduction

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

Prototype

public DashPathEffect(float intervals[], float phase) 

Source Link

Document

The intervals array must contain an even number of entries (>=2), with the even indices specifying the "on" intervals, and the odd indices specifying the "off" intervals.

Usage

From source file:com.xengar.android.stocktracker.ui.DetailFragment.java

private void fillChart(Cursor data) {
    String history = data.getString(COL_QUOTE_HISTORY);
    List<HistoricalPrice> historicalPrices = parseStockHistory(history);
    List<Entry> entries = new ArrayList<Entry>();
    for (int i = 0; i < historicalPrices.size(); i++) {
        HistoricalPrice item = historicalPrices.get(i);
        // turn your data into Entry objects (x, y)
        entries.add(new Entry(i, item.getPrice()));
    }//from w  ww .  jav a  2  s .com
    LineDataSet dataSet = new LineDataSet(entries, data.getString(COL_QUOTE_SYMBOL)); // add entries to dataset
    dataSet.setColor(Color.RED);
    dataSet.setCircleColor(Color.RED);
    dataSet.setLineWidth(1f);
    dataSet.setCircleRadius(2f);
    dataSet.setDrawCircleHole(false);
    dataSet.setValueTextSize(9f);
    dataSet.setDrawFilled(true);
    dataSet.setFormLineWidth(1f);
    dataSet.setFormLineDashEffect(new DashPathEffect(new float[] { 10f, 5f }, 0f));
    dataSet.setFormSize(15.f);

    if (Utils.getSDKInt() >= 18) {
        // fill drawable only supported on api level 18 and above
        Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fade_red);
        dataSet.setFillDrawable(drawable);
    } else {
        dataSet.setFillColor(Color.parseColor("#FFCDD2"));
    }

    LineData lineData = new LineData(dataSet);
    mChart.setData(lineData); //  add values (data) to the chart,

    mChart.setOnChartGestureListener(this);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);

    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(true);

    // create a custom MarkerView (extend MarkerView) and specify the layout to use
    MyMarkerView mv = new MyMarkerView(getContext(), R.layout.custom_marker_view, historicalPrices);
    mv.setChartView(mChart); // For bounds control
    mChart.setMarker(mv); // Set the marker to the chart

    mChart.getAxisRight().setEnabled(false);
    //mChart.animateX(250);
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    // modify the legend ...
    l.setForm(Legend.LegendForm.CIRCLE);

    mChart.invalidate(); // refresh
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initGridH(ShapeDrawable drawable, Path path, int color, int width, int height) {
    path.rewind();/*  ww w.  j  a  v  a2s.co  m*/
    float cellHeight = height / NUM_ROWS;
    for (int i = 0; i < NUM_ROWS; ++i) {
        path.moveTo(0, i * cellHeight);
        path.lineTo(width, i * cellHeight);
    }

    float offset = NUM_COLUMNS * 5;
    drawable.setShape(new PathShape(path, width, height));
    drawable.getPaint().setStyle(Paint.Style.STROKE);
    drawable.getPaint().setColor(color);
    drawable.getPaint().setPathEffect(new DashPathEffect(new float[] { 1, (width - offset) / offset }, 0));
    drawable.setBounds(0, 0, width, height);
}

From source file:com.FluksoViz.FluksoVizActivity.java

private void make_graph_pretty(XYPlot p) {

    p.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 56); // Reduce the number
    // of range labels
    // Plot1.setTicksPerDomainLabel(1);
    p.setDomainValueFormat(new DateFormat_p1());

    p.setRangeStep(XYStepMode.SUBDIVIDE, 5);// Skala Y pionowa
    // Plot1.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 1);
    // Plot1.setTicksPerRangeLabel(1);
    p.getTitleWidget().setClippingEnabled(false);

    p.getTitleWidget().pack();//  w w  w .  j a  va2 s  .  c  o m
    int axis_font_size = 15;
    int title_font_size = 15;
    int domain_font_size = 12;

    if (screen_width == 320) {
        axis_font_size = 12;
        title_font_size = 9;
        domain_font_size = 10;
    }

    p.getTitleWidget().getLabelPaint().setTextSize(title_font_size);
    p.getGraphWidget().getDomainLabelPaint().setTextSize(domain_font_size);
    p.getGraphWidget().getDomainLabelPaint().setColor(Color.WHITE);
    p.getGraphWidget().getRangeLabelPaint().setColor(Color.WHITE);
    p.getGraphWidget().getRangeLabelPaint().setTextSize(axis_font_size);
    p.getGraphWidget().getDomainOriginLabelPaint().setTextSize(domain_font_size);
    p.getGraphWidget().getRangeOriginLabelPaint().setTextSize(axis_font_size);
    p.getGraphWidget().setClippingEnabled(false);

    p.setDomainValueFormat(new DecimalFormat("#"));

    p.getLegendWidget().setVisible(false);
    p.getDomainLabelWidget().setVisible(false);
    p.getRangeLabelWidget().setVisible(false);
    p.getGraphWidget().getGridLinePaint().setPathEffect(new DashPathEffect(new float[] { 1, 2, 1, 2 }, 0));
    p.getBackgroundPaint().setColor(Color.TRANSPARENT);
    p.getGraphWidget().getBackgroundPaint().setColor(Color.TRANSPARENT);
    p.getGraphWidget().getGridBackgroundPaint().setColor(Color.TRANSPARENT);
    p.setGridPadding(0, 10, 0, 0); // left top right bottom
    p.getGraphWidget().getGridLinePaint().setColor(Color.TRANSPARENT);

    if (sensor_number != 4) {
        p.setRangeLowerBoundary(0, BoundaryMode.GROW);// to ustawia
    }

    if (sensor_number == 4) {
        p.addMarker(new YValueMarker(0, "0", new XPositionMetric(-11, XLayoutStyle.ABSOLUTE_FROM_LEFT),
                Color.WHITE, Color.WHITE));
        p.setRangeStep(XYStepMode.SUBDIVIDE, 2);
        p.getGraphWidget().getRangeOriginLinePaint().setAlpha(0);

        series1mFormat = new LineAndPointFormatter( // FAZA
                Color.rgb(0, 220, 0), // line color
                Color.rgb(0, 150, 0), // point color
                null);

        line1mFill.setShader(
                new LinearGradient(0, 0, 0, 200, Color.rgb(0, 200, 0), Color.BLACK, Shader.TileMode.MIRROR));
        series1mFormat.getLinePaint().setStrokeWidth(4);
        series1mFormat.setFillPaint(line1mFill);

        series2mFormat = new LineAndPointFormatter( // faza 2 solar
                Color.rgb(200, 200, 0), // line
                Color.rgb(100, 100, 0), // point color
                null);
        line2mFill.setShader(
                new LinearGradient(0, 150, 0, 120, Color.rgb(250, 250, 0), Color.BLACK, Shader.TileMode.CLAMP));
        series2mFormat.setFillDirection(FillDirection.TOP);
        series2mFormat.setFillPaint(line2mFill);
        series2mFormat.getLinePaint().setStrokeWidth(5);

        series3mFormat = new LineAndPointFormatter( // FAZA 3 formater
                Color.rgb(0, 220, 0), // line color
                Color.rgb(0, 150, 0), // point color
                null);
        line3mFill.setAlpha(255);
        line3mFill.setShader(new LinearGradient(0, 0, 0, 50, Color.BLACK, Color.BLACK, Shader.TileMode.MIRROR));
        series3mFormat.getLinePaint().setStrokeWidth(7);
        series3mFormat.setFillPaint(line3mFill);

        series4mFormat = new LineAndPointFormatter(Color.rgb(0, 140, 220), // line
                Color.rgb(0, 120, 190), // point color
                null);
        line4mFill = new Paint();
        line4mFill.setAlpha(190);
        line4mFill.setShader(new LinearGradient(0, 0, 0, 50, Color.BLACK, Color.BLACK, Shader.TileMode.MIRROR));
        series4mFormat.getLinePaint().setStrokeWidth(5);
        series4mFormat.setFillPaint(line4mFill);
        series4mFormat.setFillDirection(FillDirection.TOP);

        // XYRegionFormatter region4Formatter = new
        // XYRegionFormatter(Color.BLUE);
        // series4mFormat.addRegion(new RectRegion(Double.NEGATIVE_INFINITY,
        // Double.POSITIVE_INFINITY, 0, -1000, "R1"), region4Formatter);

    }

    // p.setRangeLowerBoundary(0, BoundaryMode.GROW);// to ustawia
    // min i max
    // Plot1.setRangeUpperBoundary(11, BoundaryMode.FIXED);

    p.setRangeValueFormat(new DecimalFormat("#"));
    p.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);
    p.setBorderPaint(null);
    p.disableAllMarkup(); // To get rid of them call disableAllMarkup():

}