Example usage for android.graphics Bitmap prepareToDraw

List of usage examples for android.graphics Bitmap prepareToDraw

Introduction

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

Prototype

public void prepareToDraw() 

Source Link

Document

Builds caches associated with the bitmap that are used for drawing it.

Usage

From source file:com.wildplot.android.ankistats.CardsTypes.java

public Bitmap renderChart(int type) {
    calculateCardsTypes(type);//  ww  w. j  ava 2 s .c o m
    int height = mImageView.getMeasuredHeight();
    int width = mImageView.getMeasuredWidth();

    if (height <= 0 || width <= 0) {
        return null;
    }

    BufferedImage bufferedFrameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedFrameImage.createGraphics();
    Rectangle rect = new Rectangle(width, height);
    g.setClip(rect);
    g.setColor(Color.BLACK);
    float textSize = AnkiStatsApplication.getInstance().getmStandardTextSize() * 0.75f;
    g.setFontSize(textSize);

    float FontHeigth = g.getFontMetrics().getHeight(true);
    mFrameThickness = Math.round(FontHeigth * 4.0f);
    //System.out.println("frame thickness: " + mFrameThickness);

    PlotSheet plotSheet = new PlotSheet(0, 15, 0, 15);
    plotSheet.setFrameThickness(mFrameThickness);
    plotSheet.unsetBorder();
    PieChart pieChart = new PieChart(plotSheet, mSeriesList[0]);

    Color[] colors = { new Color(mImageView.getResources().getColor(mColors[0])),
            new Color(mImageView.getResources().getColor(mColors[1])),
            new Color(mImageView.getResources().getColor(mColors[2])),
            new Color(mImageView.getResources().getColor(mColors[3])) };
    pieChart.setColors(colors);
    pieChart.setName(mImageView.getResources().getString(mValueLabels[0]) + ": " + (int) mSeriesList[0][0]);
    LegendDrawable legendDrawable1 = new LegendDrawable();
    LegendDrawable legendDrawable2 = new LegendDrawable();
    LegendDrawable legendDrawable3 = new LegendDrawable();
    legendDrawable1.setColor(new Color(mImageView.getResources().getColor(mColors[1])));
    legendDrawable2.setColor(new Color(mImageView.getResources().getColor(mColors[2])));
    legendDrawable3.setColor(new Color(mImageView.getResources().getColor(mColors[3])));

    legendDrawable1
            .setName(mImageView.getResources().getString(mValueLabels[1]) + ": " + (int) mSeriesList[0][1]);
    legendDrawable2
            .setName(mImageView.getResources().getString(mValueLabels[2]) + ": " + (int) mSeriesList[0][2]);
    legendDrawable3
            .setName(mImageView.getResources().getString(mValueLabels[3]) + ": " + (int) mSeriesList[0][3]);

    plotSheet.setFontSize(textSize);
    plotSheet.addDrawable(pieChart);
    plotSheet.addDrawable(legendDrawable1);
    plotSheet.addDrawable(legendDrawable2);
    plotSheet.addDrawable(legendDrawable3);

    plotSheet.paint(g);
    Bitmap bitmap = bufferedFrameImage.getBitmap();
    bitmap.prepareToDraw();
    return bitmap;
}

From source file:com.wildplot.android.ankistats.Intervals.java

public Bitmap renderChart(int type) {
    calculateIntervals(type);/*ww  w .j  av  a 2  s  .  c  o  m*/
    int height = mImageView.getMeasuredHeight();
    int width = mImageView.getMeasuredWidth();

    if (height <= 0 || width <= 0) {
        return null;
    }

    BufferedImage bufferedFrameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedFrameImage.createGraphics();
    Rectangle rect = new Rectangle(width, height);
    g.setClip(rect);
    g.setColor(Color.BLACK);
    float textSize = AnkiStatsApplication.getInstance().getmStandardTextSize() * 0.75f;
    g.setFontSize(textSize);

    float FontHeigth = g.getFontMetrics().getHeight(true);
    mFrameThickness = Math.round(FontHeigth * 4.0f);
    //System.out.println("frame thickness: " + mFrameThickness);

    PlotSheet plotSheet = new PlotSheet(mSeriesList[0][0] - 0.5,
            mSeriesList[0][mSeriesList[0].length - 1] + 0.5, 0, mMaxCards * 1.1);
    plotSheet.setFrameThickness(mFrameThickness);

    //no title because of tab title
    //plotSheet.setTitle(mImageView.getResources().getString(mTitle));

    double xTics = ticsCalcX(targetPixelDistanceBetweenTics, rect);
    double yTics = ticsCalcY(targetPixelDistanceBetweenTics, rect);

    XAxis xaxis = new XAxis(plotSheet, 0, xTics, xTics / 2.0);
    YAxis yaxis = new YAxis(plotSheet, 0, yTics, yTics / 2.0);
    xaxis.setOnFrame();
    xaxis.setName(mImageView.getResources().getStringArray(R.array.due_x_axis_title)[mAxisTitles[0]]);
    xaxis.setIntegerNumbering(true);
    yaxis.setIntegerNumbering(true);
    yaxis.setName(mImageView.getResources().getString(mAxisTitles[1]));
    yaxis.setOnFrame();

    BarGraph[] barGraphs = new BarGraph[mSeriesList.length - 1];
    for (int i = 1; i < mSeriesList.length; i++) {
        double[][] bars = new double[2][];
        bars[0] = mSeriesList[0];
        bars[1] = mSeriesList[i];

        barGraphs[i - 1] = new BarGraph(plotSheet, barThickness, bars,
                new Color(mImageView.getResources().getColor(mColors[i - 1])));
        barGraphs[i - 1].setFilling(true);
        barGraphs[i - 1].setName(mImageView.getResources().getString(mValueLabels[i - 1]));
        //barGraph.setFillColor(Color.GREEN.darker());
        barGraphs[i - 1].setFillColor(new Color(mImageView.getResources().getColor(mColors[i - 1])));
    }

    //double maxCumulative = mCumulative[1][mCumulative[1].length-1];
    PlotSheet hiddenPlotSheet = new PlotSheet(mSeriesList[0][0] - 0.5,
            mSeriesList[0][mSeriesList[0].length - 1] + 0.5, 0, 105.0); //for second y-axis
    hiddenPlotSheet.setFrameThickness(mFrameThickness);

    Lines lines = new Lines(hiddenPlotSheet, mCumulative, Color.BLACK);
    lines.setSize(3f);
    lines.setName(mImageView.getResources().getString(R.string.stats_cumulative_percentage));
    lines.setShadow(5f, 3f, 3f, Color.BLACK);

    double rightYtics = ticsCalc(targetPixelDistanceBetweenTics, rect, 105.0);
    YAxis rightYaxis = new YAxis(hiddenPlotSheet, 0, rightYtics, rightYtics / 2.0);
    rightYaxis.setIntegerNumbering(true);
    rightYaxis.setName(mImageView.getResources().getString(mAxisTitles[2]));
    rightYaxis.setOnRightSideFrame();

    int red = Color.LIGHT_GRAY.getRed();
    int green = Color.LIGHT_GRAY.getGreen();
    int blue = Color.LIGHT_GRAY.getBlue();

    Color newGridColor = new Color(red, green, blue, 222);

    XGrid xGrid = new XGrid(plotSheet, 0, targetPixelDistanceBetweenTics);
    YGrid yGrid = new YGrid(plotSheet, 0, targetPixelDistanceBetweenTics);

    xGrid.setColor(newGridColor);
    yGrid.setColor(newGridColor);
    plotSheet.setFontSize(textSize);

    for (BarGraph barGraph : barGraphs) {
        plotSheet.addDrawable(barGraph);
    }

    plotSheet.addDrawable(lines);
    plotSheet.addDrawable(xaxis);
    plotSheet.addDrawable(yaxis);
    plotSheet.addDrawable(rightYaxis);
    plotSheet.addDrawable(xGrid);
    plotSheet.addDrawable(yGrid);
    plotSheet.paint(g);
    Bitmap bitmap = bufferedFrameImage.getBitmap();
    bitmap.prepareToDraw();
    return bitmap;
}

From source file:com.wildplot.android.ankistats.WeeklyBreakdown.java

public Bitmap renderChart(int type) {
    calculateBreakdown(type);//from  w  w  w. j a  va2 s. com
    int height = mImageView.getMeasuredHeight();
    int width = mImageView.getMeasuredWidth();

    if (height <= 0 || width <= 0) {
        return null;
    }

    BufferedImage bufferedFrameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedFrameImage.createGraphics();
    Rectangle rect = new Rectangle(width, height);
    g.setClip(rect);
    g.setColor(Color.BLACK);
    float textSize = AnkiStatsApplication.getInstance().getmStandardTextSize() * 0.75f;
    g.setFontSize(textSize);

    float FontHeigth = g.getFontMetrics().getHeight(true);
    mFrameThickness = Math.round(FontHeigth * 4.0f);
    //System.out.println("frame thickness: " + mFrameThickness);

    PlotSheet plotSheet = new PlotSheet(mSeriesList[0][0] - 0.5,
            mSeriesList[0][mSeriesList[0].length - 1] + 0.5, 0, mPeak * 1.03);
    plotSheet.setFrameThickness(mFrameThickness);

    //no title because of tab title
    //plotSheet.setTitle(mImageView.getResources().getString(mTitle));

    double xTics = ticsCalcX(targetPixelDistanceBetweenTics, rect);
    double yTics = ticsCalcY(targetPixelDistanceBetweenTics, rect);

    XAxis xaxis = new XAxis(plotSheet, 0, xTics, xTics / 2.0);
    YAxis yaxis = new YAxis(plotSheet, 0, yTics, yTics / 2.0);
    double[] timePositions = { 0, 1, 2, 3, 4, 5, 6 };
    xaxis.setExplicitTics(timePositions, mImageView.getResources().getStringArray(R.array.stats_week_days));
    xaxis.setOnFrame();
    xaxis.setName(mImageView.getResources().getString(mAxisTitles[0]));
    xaxis.setIntegerNumbering(true);
    yaxis.setIntegerNumbering(true);
    yaxis.setName(mImageView.getResources().getString(mAxisTitles[1]));
    yaxis.setOnFrame();

    //double maxCumulative = mCumulative[1][mCumulative[1].length-1];
    PlotSheet hiddenPlotSheet = new PlotSheet(mSeriesList[0][0] - 0.5,
            mSeriesList[0][mSeriesList[0].length - 1] + 0.5, 0, mMcount * 1.03); //for second y-axis
    hiddenPlotSheet.setFrameThickness(mFrameThickness);
    BarGraph[] barGraphs = new BarGraph[2];
    for (int i = 1; i < 3; i++) {
        double[][] bars = new double[2][];
        bars[0] = mSeriesList[0];
        bars[1] = mSeriesList[i];

        PlotSheet usedPlotSheet = (i == 2) ? hiddenPlotSheet : plotSheet;
        double barThickness = (i == 1) ? mBarThickness : 0.2;
        barGraphs[i - 1] = new BarGraph(usedPlotSheet, barThickness, bars,
                new Color(mImageView.getResources().getColor(mColors[i - 1])));
        barGraphs[i - 1].setFilling(true);
        barGraphs[i - 1].setName(mImageView.getResources().getString(mValueLabels[i - 1]));
        //barGraph.setFillColor(Color.GREEN.darker());
        barGraphs[i - 1].setFillColor(new Color(mImageView.getResources().getColor(mColors[i - 1])));
    }

    double rightYtics = ticsCalc(targetPixelDistanceBetweenTics, rect, mMcount);
    YAxis rightYaxis = new YAxis(hiddenPlotSheet, 0, rightYtics, rightYtics / 2.0);
    rightYaxis.setIntegerNumbering(true);
    rightYaxis.setName(mImageView.getResources().getString(mAxisTitles[2]));
    rightYaxis.setOnRightSideFrame();

    int red = Color.LIGHT_GRAY.getRed();
    int green = Color.LIGHT_GRAY.getGreen();
    int blue = Color.LIGHT_GRAY.getBlue();

    Color newGridColor = new Color(red, green, blue, 222);

    XGrid xGrid = new XGrid(plotSheet, 0, targetPixelDistanceBetweenTics);
    YGrid yGrid = new YGrid(plotSheet, 0, targetPixelDistanceBetweenTics);

    xGrid.setColor(newGridColor);
    yGrid.setColor(newGridColor);
    yGrid.setExplicitTics(timePositions);
    plotSheet.setFontSize(textSize);

    for (BarGraph barGraph : barGraphs) {
        plotSheet.addDrawable(barGraph);
    }

    plotSheet.addDrawable(xaxis);
    plotSheet.addDrawable(yaxis);
    plotSheet.addDrawable(rightYaxis);
    plotSheet.addDrawable(xGrid);
    plotSheet.addDrawable(yGrid);
    plotSheet.paint(g);
    Bitmap bitmap = bufferedFrameImage.getBitmap();
    bitmap.prepareToDraw();
    return bitmap;
}

From source file:com.wildplot.android.ankistats.Forecast.java

public Bitmap renderChart(int type) {
    calculateDue(type);/*from  w  w w .ja  v a  2  s.c o  m*/
    int height = mImageView.getMeasuredHeight();
    int width = mImageView.getMeasuredWidth();

    Log.d(AnkiStatsApplication.TAG, "heigth: " + height + ", width: " + width + ", " + mImageView.getWidth());

    if (height <= 0 || width <= 0) {
        return null;
    }

    BufferedImage bufferedFrameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedFrameImage.createGraphics();
    Rectangle rect = new Rectangle(width, height);
    g.setClip(rect);
    g.setColor(Color.BLACK);
    float textSize = AnkiStatsApplication.getInstance().getmStandardTextSize() * 0.75f;
    g.setFontSize(textSize);

    float FontHeigth = g.getFontMetrics().getHeight(true);
    mFrameThickness = Math.round(FontHeigth * 4.0f);
    //System.out.println("frame thickness: " + mFrameThickness);

    int end = 0;
    switch (mType) {
    case Utils.TYPE_MONTH:
        end = 31;
        break;
    case Utils.TYPE_YEAR:
        end = 52;
        break;
    default:
    case Utils.TYPE_LIFE:
        end = (int) mLastElement;
        break;

    }

    PlotSheet plotSheet = new PlotSheet(-0.5, end + 0.5, 0, mMaxCards * 1.1);
    double xTics = ticsCalcX(150, rect, 0, end);
    double yTics = ticsCalcY(150, rect, 0, mMaxCards);

    plotSheet.setFrameThickness(mFrameThickness);

    //no title because of tab title
    //plotSheet.setTitle(mImageView.getResources().getString(mTitle));

    XAxis xaxis = new XAxis(plotSheet, 0, xTics, xTics / 2.0);
    YAxis yaxis = new YAxis(plotSheet, 0, yTics, yTics / 2.0);
    xaxis.setOnFrame();
    xaxis.setName(mImageView.getResources().getStringArray(R.array.due_x_axis_title)[mAxisTitles[0]]);
    xaxis.setIntegerNumbering(true);
    yaxis.setIntegerNumbering(true);
    yaxis.setName(mImageView.getResources().getString(mAxisTitles[1]));
    yaxis.setOnFrame();

    double[][] bars = new double[2][];
    bars[0] = mSeriesList[0];
    bars[1] = mSeriesList[1];
    BarGraph barGraph = new BarGraph(plotSheet, barThickness, bars,
            new Color(mImageView.getResources().getColor(mColors[0])));
    barGraph.setFilling(true);
    barGraph.setName(mImageView.getResources().getString(mValueLabels[0]));
    //barGraph.setFillColor(Color.GREEN.darker());
    barGraph.setFillColor(new Color(mImageView.getResources().getColor(mColors[0])));
    double[][] bars2 = new double[2][];
    bars2[0] = mSeriesList[0];
    bars2[1] = mSeriesList[2];
    BarGraph barGraphMature = new BarGraph(plotSheet, barThickness, bars2,
            new Color(mImageView.getResources().getColor(mColors[1])));
    barGraphMature.setFilling(true);
    barGraphMature.setFillColor(new Color(mImageView.getResources().getColor(mColors[1])));
    barGraphMature.setName(mImageView.getResources().getString(mValueLabels[1]));

    double[][] cumulative = Utils.createCumulative(bars, mZeroIndex);
    PlotSheet hiddenPlotSheet = new PlotSheet(-0.5, end + 0.5, 0,
            cumulative[1][cumulative[1].length - 1] * 1.1); //for second y-axis

    Lines lines = new Lines(hiddenPlotSheet, cumulative, Color.black);
    lines.setSize(3f);
    lines.setName(mImageView.getResources().getString(R.string.stats_cumulative));
    lines.setShadow(5f, 3f, 3f, Color.BLACK);

    hiddenPlotSheet.setFrameThickness(mFrameThickness);
    double rightYtics = ticsCalc(150, rect, cumulative[1][cumulative[1].length - 1] * 1.1);
    YAxis rightYaxis = new YAxis(hiddenPlotSheet, 0, rightYtics, rightYtics / 2.0);
    rightYaxis.setIntegerNumbering(true);
    rightYaxis.setName(mImageView.getResources().getString(mAxisTitles[2]));
    rightYaxis.setOnRightSideFrame();

    int red = Color.LIGHT_GRAY.getRed();
    int green = Color.LIGHT_GRAY.getGreen();
    int blue = Color.LIGHT_GRAY.getBlue();

    Color newGridColor = new Color(red, green, blue, 222);

    XGrid xGrid = new XGrid(plotSheet, 0, 150);
    YGrid yGrid = new YGrid(plotSheet, 0, 150);

    xGrid.setColor(newGridColor);
    yGrid.setColor(newGridColor);
    plotSheet.setFontSize(textSize);

    plotSheet.addDrawable(barGraph);
    plotSheet.addDrawable(barGraphMature);
    plotSheet.addDrawable(lines);
    plotSheet.addDrawable(xaxis);
    plotSheet.addDrawable(yaxis);
    plotSheet.addDrawable(rightYaxis);
    plotSheet.addDrawable(xGrid);
    plotSheet.addDrawable(yGrid);
    plotSheet.paint(g);
    Bitmap bitmap = bufferedFrameImage.getBitmap();
    bitmap.prepareToDraw();
    return bitmap;
}

From source file:com.wildplot.android.ankistats.AnswerButton.java

public Bitmap renderChart(int type) {
    calculateAnswerButtons(type);// w ww  .j a va2 s .  com
    int height = mImageView.getMeasuredHeight();
    int width = mImageView.getMeasuredWidth();

    if (height <= 0 || width <= 0) {
        return null;
    }

    BufferedImage bufferedFrameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedFrameImage.createGraphics();
    Rectangle rect = new Rectangle(width, height);
    g.setClip(rect);
    g.setColor(Color.BLACK);
    float textSize = AnkiStatsApplication.getInstance().getmStandardTextSize() * 0.75f;
    g.setFontSize(textSize);

    float FontHeigth = g.getFontMetrics().getHeight(true);
    mFrameThickness = Math.round(FontHeigth * 4.0f);
    //System.out.println("frame thickness: " + mFrameThickness);

    PlotSheet plotSheet = new PlotSheet(0, 15, 0, mMaxCards * 1.03);
    plotSheet.setFrameThickness(mFrameThickness);

    //no title because of tab title
    //plotSheet.setTitle(mImageView.getResources().getString(mTitle));

    double xTics = ticsCalcX(targetPixelDistanceBetweenTics, rect);
    double yTics = ticsCalcY(targetPixelDistanceBetweenTics, rect);

    XAxis xaxis = new XAxis(plotSheet, 0, xTics, xTics / 2.0);
    YAxis yaxis = new YAxis(plotSheet, 0, yTics, yTics / 2.0);
    double[] timePositions = { 1, 2, 3, 6, 7, 8, 9, 11, 12, 13, 14 };
    xaxis.setExplicitTics(timePositions, mImageView.getResources().getStringArray(R.array.stats_eases_ticks));
    xaxis.setOnFrame();
    xaxis.setName(mImageView.getResources().getString(mAxisTitles[0]));
    xaxis.setIntegerNumbering(true);
    yaxis.setIntegerNumbering(true);
    yaxis.setName(mImageView.getResources().getString(mAxisTitles[1]));
    yaxis.setOnFrame();

    BarGraph[] barGraphs = new BarGraph[mSeriesList.length - 1];
    for (int i = 1; i < mSeriesList.length; i++) {
        double[][] bars = new double[2][];
        bars[0] = mSeriesList[0];
        bars[1] = mSeriesList[i];

        barGraphs[i - 1] = new BarGraph(plotSheet, mBarThickness, bars,
                new Color(mImageView.getResources().getColor(mColors[i - 1])));
        barGraphs[i - 1].setFilling(true);
        barGraphs[i - 1].setName(mImageView.getResources().getString(mValueLabels[i - 1]));
        //barGraph.setFillColor(Color.GREEN.darker());
        barGraphs[i - 1].setFillColor(new Color(mImageView.getResources().getColor(mColors[i - 1])));
    }

    PlotSheet hiddenPlotSheet = new PlotSheet(0, 15, 0, 101); //for second y-axis
    hiddenPlotSheet.setFrameThickness(mFrameThickness);

    Lines[] lineses = new Lines[mCumulative.length - 1];
    for (int i = 1; i < mCumulative.length; i++) {
        double[][] cumulatives = new double[][] { mCumulative[0], mCumulative[i] };
        lineses[i - 1] = new Lines(hiddenPlotSheet, cumulatives,
                new Color(mImageView.getResources().getColor(mColors[i - 1])));
        lineses[i - 1].setSize(3f);
        lineses[i - 1].setShadow(5f, 3f, 3f, Color.BLACK);
        //No names to prevent double entries in legend:
        //lineses[i-1].setName(mImageView.getResources().getString(R.string.stats_cumulative));
    }

    double rightYtics = ticsCalc(targetPixelDistanceBetweenTics, rect, 101);
    YAxis rightYaxis = new YAxis(hiddenPlotSheet, 0, rightYtics, rightYtics / 2.0);
    rightYaxis.setIntegerNumbering(true);
    rightYaxis.setName(mImageView.getResources().getString(mAxisTitles[2]));
    rightYaxis.setOnRightSideFrame();

    int red = Color.LIGHT_GRAY.getRed();
    int green = Color.LIGHT_GRAY.getGreen();
    int blue = Color.LIGHT_GRAY.getBlue();

    Color newGridColor = new Color(red, green, blue, 222);

    XGrid xGrid = new XGrid(plotSheet, 0, targetPixelDistanceBetweenTics);
    YGrid yGrid = new YGrid(plotSheet, 0, targetPixelDistanceBetweenTics);

    xGrid.setColor(newGridColor);
    yGrid.setColor(newGridColor);
    yGrid.setExplicitTics(timePositions);
    plotSheet.setFontSize(textSize);

    for (BarGraph barGraph : barGraphs) {
        plotSheet.addDrawable(barGraph);
    }

    for (Lines lines : lineses) {
        plotSheet.addDrawable(lines);
    }
    plotSheet.addDrawable(xaxis);
    plotSheet.addDrawable(yaxis);
    plotSheet.addDrawable(rightYaxis);
    plotSheet.addDrawable(xGrid);
    plotSheet.addDrawable(yGrid);
    plotSheet.paint(g);
    Bitmap bitmap = bufferedFrameImage.getBitmap();
    bitmap.prepareToDraw();
    return bitmap;
}

From source file:com.wildplot.android.ankistats.HourlyBreakdown.java

public Bitmap renderChart(int type) {
    calculateBreakdown(type);/*w w w  .ja  v a 2  s  .c  om*/
    int height = mImageView.getMeasuredHeight();
    int width = mImageView.getMeasuredWidth();

    if (height <= 0 || width <= 0) {
        return null;
    }

    BufferedImage bufferedFrameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedFrameImage.createGraphics();
    Rectangle rect = new Rectangle(width, height);
    g.setClip(rect);
    g.setColor(Color.BLACK);
    float textSize = AnkiStatsApplication.getInstance().getmStandardTextSize() * 0.75f;
    g.setFontSize(textSize);

    float FontHeigth = g.getFontMetrics().getHeight(true);
    mFrameThickness = Math.round(FontHeigth * 4.0f);
    //System.out.println("frame thickness: " + mFrameThickness);

    PlotSheet plotSheet = new PlotSheet(mSeriesList[0][0] - 0.5,
            mSeriesList[0][mSeriesList[0].length - 1] + 0.5, 0, mPeak * 1.03);
    plotSheet.setFrameThickness(mFrameThickness);

    //no title because of tab title
    //plotSheet.setTitle(mImageView.getResources().getString(mTitle));

    double xTics = ticsCalcX(targetPixelDistanceBetweenTics, rect);
    double yTics = ticsCalcY(targetPixelDistanceBetweenTics, rect);

    XAxis xaxis = new XAxis(plotSheet, 0, xTics, xTics / 2.0);
    YAxis yaxis = new YAxis(plotSheet, 0, yTics, yTics / 2.0);
    double[] timePositions = { 0, 6, 12, 18, 23 };
    xaxis.setExplicitTics(timePositions,
            mImageView.getResources().getStringArray(R.array.stats_day_time_strings));
    xaxis.setOnFrame();
    xaxis.setName(mImageView.getResources().getString(mAxisTitles[0]));
    xaxis.setIntegerNumbering(true);
    yaxis.setIntegerNumbering(true);
    yaxis.setName(mImageView.getResources().getString(mAxisTitles[1]));
    yaxis.setOnFrame();

    //double maxCumulative = mCumulative[1][mCumulative[1].length-1];
    PlotSheet hiddenPlotSheet = new PlotSheet(mSeriesList[0][0] - 0.5,
            mSeriesList[0][mSeriesList[0].length - 1] + 0.5, 0, mMcount * 1.03); //for second y-axis
    hiddenPlotSheet.setFrameThickness(mFrameThickness);
    BarGraph[] barGraphs = new BarGraph[2];
    for (int i = 1; i < 3; i++) {
        double[][] bars = new double[2][];
        bars[0] = mSeriesList[0];
        bars[1] = mSeriesList[i];

        PlotSheet usedPlotSheet = (i == 2) ? hiddenPlotSheet : plotSheet;
        double barThickness = (i == 1) ? mBarThickness : 0.2;
        barGraphs[i - 1] = new BarGraph(usedPlotSheet, barThickness, bars,
                new Color(mImageView.getResources().getColor(mColors[i - 1])));
        barGraphs[i - 1].setFilling(true);
        barGraphs[i - 1].setName(mImageView.getResources().getString(mValueLabels[i - 1]));
        //barGraph.setFillColor(Color.GREEN.darker());
        barGraphs[i - 1].setFillColor(new Color(mImageView.getResources().getColor(mColors[i - 1])));
    }

    double rightYtics = ticsCalc(targetPixelDistanceBetweenTics, rect, mMcount);
    YAxis rightYaxis = new YAxis(hiddenPlotSheet, 0, rightYtics, rightYtics / 2.0);
    rightYaxis.setIntegerNumbering(true);
    rightYaxis.setName(mImageView.getResources().getString(mAxisTitles[2]));
    rightYaxis.setOnRightSideFrame();

    int red = Color.LIGHT_GRAY.getRed();
    int green = Color.LIGHT_GRAY.getGreen();
    int blue = Color.LIGHT_GRAY.getBlue();

    Color newGridColor = new Color(red, green, blue, 222);

    XGrid xGrid = new XGrid(plotSheet, 0, targetPixelDistanceBetweenTics);
    YGrid yGrid = new YGrid(plotSheet, 0, targetPixelDistanceBetweenTics);

    xGrid.setColor(newGridColor);
    yGrid.setColor(newGridColor);
    yGrid.setExplicitTics(timePositions);
    plotSheet.setFontSize(textSize);

    for (BarGraph barGraph : barGraphs) {
        plotSheet.addDrawable(barGraph);
    }

    plotSheet.addDrawable(xaxis);
    plotSheet.addDrawable(yaxis);
    plotSheet.addDrawable(rightYaxis);
    plotSheet.addDrawable(xGrid);
    plotSheet.addDrawable(yGrid);
    plotSheet.paint(g);
    Bitmap bitmap = bufferedFrameImage.getBitmap();
    bitmap.prepareToDraw();
    return bitmap;
}

From source file:com.wildplot.android.ankistats.ReviewCount.java

public Bitmap renderChart(int type, boolean reps) {
    calculateDone(type, reps);/*w  w  w  .  jav a 2s .  c  om*/

    int end = 0;
    switch (mType) {
    case Utils.TYPE_MONTH:
        end = -31;
        break;
    case Utils.TYPE_YEAR:
        end = -52;
        break;
    default:
    case Utils.TYPE_LIFE:
        end = (int) mFirstElement;
        break;

    }
    Log.d(AnkiStatsApplication.TAG, "MType of PreviewCount: " + mType);

    int height = mImageView.getMeasuredHeight();
    int width = mImageView.getMeasuredWidth();

    if (height <= 0 || width <= 0) {
        return null;
    }

    BufferedImage bufferedFrameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufferedFrameImage.createGraphics();
    Rectangle rect = new Rectangle(width, height);
    g.setClip(rect);
    g.setColor(Color.BLACK);
    float textSize = AnkiStatsApplication.getInstance().getmStandardTextSize() * 0.75f;
    g.setFontSize(textSize);

    float FontHeigth = g.getFontMetrics().getHeight(true);
    mFrameThickness = Math.round(FontHeigth * 4.0f);
    //System.out.println("frame thickness: " + mFrameThickness);

    PlotSheet plotSheet = new PlotSheet(end - 0.5, 0 + 0.5, 0, mMaxCards * 1.1);
    plotSheet.setFrameThickness(mFrameThickness);

    //no title because of tab title
    //plotSheet.setTitle(mImageView.getResources().getString(mTitle));

    double xTics = ticsCalcX(targetPixelDistanceBetweenTics, rect, end, 0);
    double yTics = ticsCalcY(targetPixelDistanceBetweenTics, rect, 0, mMaxCards);

    XAxis xaxis = new XAxis(plotSheet, 0, xTics, xTics / 2.0);
    YAxis yaxis = new YAxis(plotSheet, 0, yTics, yTics / 2.0);
    xaxis.setOnFrame();
    xaxis.setName(mImageView.getResources().getStringArray(R.array.due_x_axis_title)[mAxisTitles[0]]);
    xaxis.setIntegerNumbering(true);
    yaxis.setIntegerNumbering(true);
    yaxis.setName(mImageView.getResources().getString(mAxisTitles[1]));
    yaxis.setOnFrame();

    double maxCumulative = 0;
    BarGraph[] barGraphs = new BarGraph[mSeriesList.length - 1];
    double[][][] cumulatives = new double[mSeriesList.length - 1][][];
    for (int i = 1; i < mSeriesList.length; i++) {
        double[][] bars = new double[2][];
        bars[0] = mSeriesList[0];
        bars[1] = mSeriesList[i];

        barGraphs[i - 1] = new BarGraph(plotSheet, barThickness, bars,
                new Color(mImageView.getResources().getColor(mColors[i - 1])));
        barGraphs[i - 1].setFilling(true);
        barGraphs[i - 1].setName(mImageView.getResources().getString(mValueLabels[i - 1]));
        //barGraph.setFillColor(Color.GREEN.darker());
        barGraphs[i - 1].setFillColor(new Color(mImageView.getResources().getColor(mColors[i - 1])));

        cumulatives[i - 1] = Utils.createCumulative(bars);
        if (i > 1) {
            for (int j = 0; j < cumulatives[i - 2][1].length; j++) {
                cumulatives[i - 2][1][j] -= cumulatives[i - 1][1][j];
            }

            if (maxCumulative < cumulatives[i - 2][1][cumulatives[i - 2][1].length - 1]) {
                maxCumulative = cumulatives[i - 2][1][cumulatives[i - 2][1].length - 1];
            }
        }
        if (i == mSeriesList.length - 1) {
            if (maxCumulative < cumulatives[i - 1][1][cumulatives[i - 1][1].length - 1]) {
                maxCumulative = cumulatives[i - 1][1][cumulatives[i - 1][1].length - 1];
            }
        }

    }

    PlotSheet hiddenPlotSheet = new PlotSheet(end - 0.5, 0 + 0.5, 0, maxCumulative * 1.1); //for second y-axis
    hiddenPlotSheet.setFrameThickness(mFrameThickness);

    Lines[] lineses = new Lines[mSeriesList.length - 1];
    for (int i = 1; i < mSeriesList.length; i++) {
        lineses[i - 1] = new Lines(hiddenPlotSheet, cumulatives[i - 1],
                new Color(mImageView.getResources().getColor(mColors[i - 1])));
        lineses[i - 1].setSize(3f);
        lineses[i - 1].setShadow(5f, 3f, 3f, Color.BLACK);
        //No names to prevent double entries in legend:
        //lineses[i-1].setName(mImageView.getResources().getString(R.string.stats_cumulative));
    }

    double rightYtics = ticsCalc(targetPixelDistanceBetweenTics, rect, maxCumulative * 1.1);
    YAxis rightYaxis = new YAxis(hiddenPlotSheet, 0, rightYtics, rightYtics / 2.0);
    rightYaxis.setIntegerNumbering(true);
    rightYaxis.setName(mImageView.getResources().getString(mAxisTitles[2]));
    rightYaxis.setOnRightSideFrame();

    int red = Color.LIGHT_GRAY.getRed();
    int green = Color.LIGHT_GRAY.getGreen();
    int blue = Color.LIGHT_GRAY.getBlue();

    Color newGridColor = new Color(red, green, blue, 222);

    XGrid xGrid = new XGrid(plotSheet, 0, targetPixelDistanceBetweenTics);
    YGrid yGrid = new YGrid(plotSheet, 0, targetPixelDistanceBetweenTics);

    xGrid.setColor(newGridColor);
    yGrid.setColor(newGridColor);
    plotSheet.setFontSize(textSize);

    for (BarGraph barGraph : barGraphs) {
        plotSheet.addDrawable(barGraph);
    }
    for (Lines lines : lineses) {
        plotSheet.addDrawable(lines);
    }
    plotSheet.addDrawable(xaxis);
    plotSheet.addDrawable(yaxis);
    plotSheet.addDrawable(rightYaxis);
    plotSheet.addDrawable(xGrid);
    plotSheet.addDrawable(yGrid);
    plotSheet.paint(g);
    Bitmap bitmap = bufferedFrameImage.getBitmap();
    bitmap.prepareToDraw();
    return bitmap;
}

From source file:com.squareup.picasso3.Dispatcher.java

private void deliver(BitmapHunter hunter) {
    if (hunter.isCancelled()) {
        return;// ww w . ja  v a 2  s .c  om
    }
    RequestHandler.Result result = hunter.getResult();
    if (result != null && result.hasBitmap()) {
        Bitmap bitmap = result.getBitmap();
        bitmap.prepareToDraw();
    }

    mainThreadHandler.sendMessage(mainThreadHandler.obtainMessage(HUNTER_COMPLETE, hunter));
    logDelivery(hunter);
}