Example usage for android.graphics Paint setAlpha

List of usage examples for android.graphics Paint setAlpha

Introduction

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

Prototype

public void setAlpha(int a) 

Source Link

Document

Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.

Usage

From source file:project.pamela.slambench.fragments.FrequencyPlot.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }//from w  w  w .  ja v a  2  s  .co m

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setBackgroundColor(Color.WHITE);
    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.frequency_domain));
    plot.setBackgroundColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    //Remove legend
    //plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    for (int i = 0; i < value.getCPUCount(); i++) {

        int strokecolor = Color.rgb(i * (255 / value.getCPUCount()), 137, 192);
        int fillcolor = Color.rgb(i * (255 / value.getCPUCount()), 229, 255);

        Double frequencyNumbers[] = value.getfrequencyList(i);
        XYSeries series = new SimpleXYSeries(Arrays.asList(frequencyNumbers),
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
                this.getResources().getString(R.string.frequency_legend, i));
        LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null);

        seriesFormat.setPointLabeler(new PointLabeler() {
            @Override
            public String getLabel(XYSeries series, int index) {
                return "o";
            }
        });

        Paint lineFill = new Paint();
        lineFill.setAlpha(150);
        DisplayMetrics metrics = new DisplayMetrics();
        super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
        lineFill.setShader(new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor,
                Shader.TileMode.MIRROR));
        seriesFormat.setFillPaint(lineFill);

        plot.addSeries(series, seriesFormat);
    }

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue());
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}

From source file:project.pamela.slambench.fragments.AccuracyPlot.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }//from   w  w  w .  j  av a 2s .c o  m

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.legend_ate));
    plot.setBackgroundColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    int fillcolor = Color.rgb(255, 213, 226);
    int strokecolor = Color.rgb(225, 99, 70);

    Double accuracyNumbers[] = value.getATEList();
    XYSeries series = new SimpleXYSeries(Arrays.asList(accuracyNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
            this.getResources().getString(R.string.legend_ate));
    LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null);

    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    DisplayMetrics metrics = new DisplayMetrics();
    super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    lineFill.setShader(
            new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR));
    seriesFormat.setPointLabeler(new PointLabeler() {
        @Override
        public String getLabel(XYSeries series, int index) {
            return "o";
        }
    });
    seriesFormat.setFillPaint(lineFill);
    plot.addSeries(series, seriesFormat);

    // same as above
    LineAndPointFormatter lineFormat = new LineAndPointFormatter(Color.BLACK, null, null, null);
    //change the line width
    Paint paint = lineFormat.getLinePaint();
    paint.setStrokeWidth(5);
    lineFormat.setLinePaint(paint);

    if (SLAMBenchApplication.getBenchmark() != null) {
        Number[] line = { 0, SLAMBenchApplication.getBenchmark().getMaxAccuracyError(),
                value.test.dataset.getFrameCount() - 1,
                SLAMBenchApplication.getBenchmark().getMaxAccuracyError() };
        XYSeries expected = new SimpleXYSeries(Arrays.asList(line),
                SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED,
                getResources().getString(R.string.legend_error_limit));
        plot.addSeries(expected, lineFormat);
    }

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(0, maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @param canvasContent/* w ww  . ja  v  a2s. c om*/
 * @param paintContent
 */
private void paintBoxList(Canvas canvasContent, Paint paintContent) {
    for (Box b : boxList) {
        paintContent.setColor(Color.GREEN);
        paintContent.setStyle(Style.FILL);
        paintContent.setAlpha(50);

        for (int i = b.getNorthWest().getX(); i < b.getSouthEast().getX(); i++) {
            for (int j = b.getNorthWest().getY(); j < b.getSouthEast().getY(); j++) {
                canvasContent.drawRect(cellDimension * i, cellDimension * j, cellDimension * i + cellDimension,
                        cellDimension * j + cellDimension, paintContent);
            }
        }
    }

}

From source file:project.pamela.slambench.fragments.PowerPlot.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }/*from   www.j av  a2 s .  c  om*/

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.legend_power));
    plot.setBackgroundColor(Color.WHITE);
    plot.getBorderPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    //Remove legend
    //plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    int strokecolor = Color.rgb(91, 255, 159);
    int fillcolor = Color.rgb(91, 255, 184);

    Double powerNumbers[] = value.getPowerList();
    for (int i = 0; i < value.test.dataset.getFrameCount(); i++) {
        powerNumbers[i] = powerNumbers[i] / -1000;
    }
    XYSeries series = new SimpleXYSeries(Arrays.asList(powerNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
            this.getResources().getString(R.string.legend_power));
    LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null);

    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    DisplayMetrics metrics = new DisplayMetrics();
    super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    lineFill.setShader(
            new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR));
    seriesFormat.setPointLabeler(new PointLabeler() {
        @Override
        public String getLabel(XYSeries series, int index) {
            return "o";
        }
    });
    seriesFormat.setFillPaint(lineFill);
    plot.addSeries(series, seriesFormat);

    // same as above
    LineAndPointFormatter lineFormat = new LineAndPointFormatter(Color.BLACK, null, null, null);
    //change the line width
    Paint paint = lineFormat.getLinePaint();
    paint.setStrokeWidth(5);
    lineFormat.setLinePaint(paint);

    Number[] line = { 0, 3, value.test.dataset.getFrameCount() - 1, 3 };
    XYSeries expected = new SimpleXYSeries(Arrays.asList(line), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED,
            getResources().getString(R.string.legend_power_limit));
    plot.addSeries(expected, lineFormat);

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue());
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}

From source file:project.pamela.slambench.fragments.DurationPlot.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }//  w w w.ja va2s .  c  om

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.legend_duration));
    plot.setBackgroundColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    //Remove legend
    //plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    // Prepare Data (fill stack and add lines)

    KFusion.FieldIndex[] stackIndex = new KFusion.FieldIndex[] { (KFusion.FieldIndex.AQUISITION_DURATION),
            (KFusion.FieldIndex.PREPROCESSING_DURATION), (KFusion.FieldIndex.TRACKING_DURATION),
            (KFusion.FieldIndex.INTEGRATION_DURATION), (KFusion.FieldIndex.RAYCASTING_DURATION),
            (KFusion.FieldIndex.RENDERING_DURATION), (KFusion.FieldIndex.TOTAL_DURATION) };

    Double[][] stackNumbers = new Double[][] { value.getField(stackIndex[0]), value.getField(stackIndex[1]),
            value.getField(stackIndex[2]), value.getField(stackIndex[3]), value.getField(stackIndex[4]),
            value.getField(stackIndex[5]) };

    Double[][] stack = new Double[stackNumbers.length + 1][stackNumbers[0].length];

    int[] stackColor = new int[] { Color.rgb(240, 0, 0), Color.rgb(255, 155, 0), Color.rgb(255, 255, 0),
            Color.rgb(155, 255, 98), Color.rgb(0, 212, 255), Color.rgb(0, 155, 255), Color.rgb(0, 0, 127) };

    stack[0] = stackNumbers[0];

    for (int i = 0; i < stackNumbers[0].length; ++i) {
        for (int j = 1; j < stackNumbers.length; ++j) {
            stack[j][i] = stack[j - 1][i] + stackNumbers[j][i];
        }
    }
    stack[stackNumbers.length] = value.getField(KFusion.FieldIndex.TOTAL_DURATION);

    for (int i = stack.length - 1; i >= 0; --i) {
        // Turn the above arrays into XYSeries':
        XYSeries series = new SimpleXYSeries(Arrays.asList(stack[i]), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
                stackIndex[i].getName());

        LineAndPointFormatter seriesFormat = new LineAndPointFormatter(Color.rgb(73, 73, 73), null,
                stackColor[i], null);
        Paint paint = seriesFormat.getLinePaint();
        paint.setStrokeWidth(1.0f);
        seriesFormat.setLinePaint(paint);

        // setup our line fill paint to be a slightly transparent gradient:
        //Paint lineFill = new Paint();
        // lineFill.setAlpha(200);
        //lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, stackColor[i], Shader.TileMode.MIRROR));
        //seriesFormat.setFillPaint(lineFill);

        plot.addSeries(series, seriesFormat);

    }

    // same as above
    LineAndPointFormatter lineFormat = new LineAndPointFormatter(Color.BLACK, null, null, null);
    //change the line width
    Paint paint = lineFormat.getLinePaint();
    paint.setStrokeWidth(5);
    lineFormat.setLinePaint(paint);

    Number[] line = { 0, 0.033, stack[0].length - 1, 0.033 };
    XYSeries expected = new SimpleXYSeries(Arrays.asList(line), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED,
            getResources().getString(R.string.legend_realtime_limit));
    plot.addSeries(expected, lineFormat);

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(0, maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @return//ww  w .j ava  2s  .co m
 */
private Picture drawBarreds() {
    Picture pictureContent = new Picture();
    Canvas canvasContent = pictureContent.beginRecording(getWidth(), getHeight());
    Paint paintContent = new Paint(Paint.ANTI_ALIAS_FLAG);
    canvasContent.save();

    paintContent.setColor(Color.BLUE);
    paintContent.setStyle(Style.STROKE);
    paintContent.setStrokeWidth(2);
    paintContent.setAlpha(50);

    try {
        cellDimension = block.getCellDimension();
        JSONArray barred = block.getBarred();

        int rows = block.getShape().getInt(0);
        int cols = block.getShape().getInt(1);

        // this code draws all the shape:
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {

                canvasContent.drawRect(cellDimension * j, cellDimension * i, cellDimension * j + cellDimension,
                        cellDimension * i + cellDimension, paintContent);
            }
        }
        paintContent.setColor(Color.RED);
        paintContent.setStyle(Style.FILL);
        paintContent.setAlpha(50);

        for (int i = 0; i < barred.length(); i++) {
            JSONArray pos = barred.getJSONArray(i);
            canvasContent.drawRect(cellDimension * pos.getInt(1), cellDimension * pos.getInt(0),
                    cellDimension * pos.getInt(1) + cellDimension,
                    cellDimension * pos.getInt(0) + cellDimension, paintContent);
        }

        this.paintBoxList(canvasContent, paintContent);

    } catch (JSONException e) {
        e.printStackTrace();
        Log.e("Exception in DrawComponents.drawBarreds", "" + e.getMessage());
    }

    canvasContent.restore();
    pictureContent.endRecording();
    return pictureContent;

}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.AlmostRippleDrawable.java

@Override
public void doDraw(Canvas canvas, Paint paint) {
    Rect bounds = getBounds();/*from  w  w w.  j a  v a  2 s.  co  m*/
    int size = Math.min(bounds.width(), bounds.height());
    float scale = mCurrentScale;
    int rippleColor = mRippleColor;
    int bgColor = mRippleBgColor;
    float radius = (size / 2);
    float radiusAnimated = radius * scale;
    if (scale > INACTIVE_SCALE) {
        if (bgColor != 0) {
            paint.setColor(bgColor);
            paint.setAlpha(decreasedAlpha(Color.alpha(bgColor)));
            canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius, paint);
        }
        if (rippleColor != 0) {
            paint.setColor(rippleColor);
            paint.setAlpha(modulateAlpha(Color.alpha(rippleColor)));
            canvas.drawCircle(bounds.centerX(), bounds.centerY(), radiusAnimated, paint);
        }
    }
}

From source file:com.heneryh.aquanotes.ui.controllers.GraphsFragment.java

/**
 * Handle {@link VendorsQuery} {@link Cursor}.
 *///from ww  w . ja  v  a2 s  . c o m
private void onProbeDataQueryComplete(Cursor cursor) {
    if (mCursor != null) {
        // In case cancelOperation() doesn't work and we end up with consecutive calls to this
        // callback.
        getActivity().stopManagingCursor(mCursor);
        mCursor = null;
    }
    mySimpleXYPlot = (XYPlot) mRootView.findViewById(R.id.mySimpleXYPlot);
    mySimpleXYPlot.setOnTouchListener(this);
    mySimpleXYPlot.clear();

    //Creation of the series
    final Vector<Double> vector = new Vector<Double>();
    int numDataPoints = 0;
    String probeName = null;
    Long timestamp = (long) 0;
    String valueS = null;
    try {
        /** For each datapoint in the database, */
        while (cursor.moveToNext()) {
            probeName = cursor.getString(ProbeDataViewQuery.NAME);
            timestamp = cursor.getLong(ProbeDataViewQuery.TIMESTAMP);
            valueS = cursor.getString(ProbeDataViewQuery.VALUE);
            Double valueD = Double.valueOf(valueS);
            vector.add(timestamp.doubleValue());
            vector.add(valueD);
            numDataPoints++;
        } // end of while()
    } finally {
        cursor.close();
        if (numDataPoints < 2)
            return;
    }
    // create our series from our array of nums:
    mySeries = new SimpleXYSeries(vector, ArrayFormat.XY_VALS_INTERLEAVED, probeName);

    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot.getGraphWidget().getGridLinePaint()
            .setPathEffect(new DashPathEffect(new float[] { 1, 1 }, 1));
    mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);
    mySimpleXYPlot.getBorderPaint().setStrokeWidth(1);
    mySimpleXYPlot.getBorderPaint().setAntiAlias(false);
    mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE);

    // Create a formatter to use for drawing a series using LineAndPointRenderer:
    LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.rgb(0, 100, 0), // line color
            Color.rgb(0, 100, 0), // point color
            Color.rgb(100, 200, 0)); // fill color

    // setup our line fill paint to be a slightly transparent gradient:
    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    //lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));

    LineAndPointFormatter formatter = new LineAndPointFormatter(Color.rgb(0, 0, 0), Color.BLUE, Color.RED);
    //       formatter.setFillPaint(lineFill);
    formatter.setFillPaint(null);
    //       formatter.setVertexPaint(null);
    formatter.getLinePaint().setShadowLayer(0, 0, 0, 0);
    mySimpleXYPlot.getGraphWidget().setPaddingRight(2);
    mySimpleXYPlot.addSeries(mySeries, formatter);

    // draw a domain tick for each year:
    //mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, numDataPoints);

    // customize our domain/range labels
    mySimpleXYPlot.setDomainLabel("Time");
    mySimpleXYPlot.setRangeLabel(probeName);

    // get rid of decimal points in our range labels:
    mySimpleXYPlot.setRangeValueFormat(new DecimalFormat("#0.00"));

    mySimpleXYPlot.setDomainValueFormat(new MyDateFormat());

    // by default, AndroidPlot displays developer guides to aid in laying out your plot.
    // To get rid of them call disableAllMarkup():
    mySimpleXYPlot.disableAllMarkup();

    //Set of internal variables for keeping track of the boundaries
    mySimpleXYPlot.calculateMinMaxVals();
    minXY = new PointF(mySimpleXYPlot.getCalculatedMinX().floatValue(),
            mySimpleXYPlot.getCalculatedMinY().floatValue()); //initial minimum data point
    absMinX = minXY.x; //absolute minimum data point
    //absolute minimum value for the domain boundary maximum
    minNoError = Math.round(mySeries.getX(1).floatValue() + 2);
    maxXY = new PointF(mySimpleXYPlot.getCalculatedMaxX().floatValue(),
            mySimpleXYPlot.getCalculatedMaxY().floatValue()); //initial maximum data point
    absMaxX = maxXY.x; //absolute maximum data point
    //absolute maximum value for the domain boundary minimum
    maxNoError = (float) Math.round(mySeries.getX(mySeries.size() - 1).floatValue()) - 2;

    //Check x data to find the minimum difference between two neighboring domain values
    //Will use to prevent zooming further in than this distance
    double temp1 = mySeries.getX(0).doubleValue();
    double temp2 = mySeries.getX(1).doubleValue();
    double temp3;
    double thisDif;
    minDif = 100000000; //increase if necessary for domain values
    for (int i = 2; i < mySeries.size(); i++) {
        temp3 = mySeries.getX(i).doubleValue();
        thisDif = Math.abs(temp1 - temp3);
        if (thisDif < minDif)
            minDif = thisDif;
        temp1 = temp2;
        temp2 = temp3;
    }
    minDif = minDif + difPadding; //with padding, the minimum difference

    mySimpleXYPlot.redraw();

}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java

private void setupWayOverlay() {
    Path p = new Path();
    p.moveTo(4.f, 0.f);// w w w . j  a v a2s  .  c  om
    p.lineTo(0.f, -4.f);
    p.lineTo(8.f, -4.f);
    p.lineTo(12.f, 0.f);
    p.lineTo(8.f, 4.f);
    p.lineTo(0.f, 4.f);

    Paint fastWayOverlayColor = new Paint(Paint.ANTI_ALIAS_FLAG);
    fastWayOverlayColor.setStyle(Paint.Style.STROKE);
    fastWayOverlayColor.setColor(Color.BLUE);
    fastWayOverlayColor.setAlpha(160);
    fastWayOverlayColor.setStrokeWidth(5.f);
    fastWayOverlayColor.setStrokeJoin(Paint.Join.ROUND);
    fastWayOverlayColor.setPathEffect(new ComposePathEffect(
            new PathDashPathEffect(p, 12.f, 0.f, PathDashPathEffect.Style.ROTATE), new CornerPathEffect(30.f)));

    // create the WayOverlay and add the ways
    this.fastWayOverlay = new FastWayOverlay(session, fastWayOverlayColor);
    mapView.getOverlays().add(this.fastWayOverlay);
    Result result = session.getResult();
    if (result != null) {
        addPathToMap(result.getWay());
    }
}

From source file:net.osmand.plus.views.controls.DynamicListView.java

/**
 * Returns a bitmap showing a screenshot of the view passed in.
 *//*from  w w  w .  j  ava2s  . c  om*/
private Bitmap getBitmapFromView(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);

    Bitmap bitmapOut = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvasOut = new Canvas(bitmapOut);
    canvasOut.drawColor(Color.TRANSPARENT);
    Paint p = new Paint();
    p.setAlpha(200);
    canvasOut.drawBitmap(bitmap, 0, 0, p);

    return bitmapOut;
}