0
votes

When i try and take a screenshot of my activity that uses Androidplot i get a 'Could'nt capture capture screenshot - storage may be in use' message. I am able to take a screenshot perfectly if the Androidplot graph is not placed on the activity.

private void renderAndroidPlot()
{
    // on ICS+ devices :-)
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
            WindowManager.LayoutParams.FLAG_SECURE);

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

    // Create a couple arrays of y-values to plot:
    Number[] series1Numbers =   getGraphData();

    // Turn the above arrays into XYSeries':
    XYSeries series1 = new SimpleXYSeries(
            Arrays.asList(series1Numbers),          // SimpleXYSeries takes a List so turn our array into a List
            SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, // Y_VALS_ONLY means use the element index as the x value
            "Series1");                             // Set the display title of the series


    // add a new series' to the xyplot:
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.setBorderStyle(Plot.BorderStyle.NONE, null, null);

    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.parseColor("#99E6B1"), Shader.TileMode.MIRROR));
    LineAndPointFormatter formatter  = new LineAndPointFormatter(Color.rgb(0, 0,0), null, null,null);
    formatter.setFillPaint(lineFill);

    plot.setPlotMargins(0, 0, 0, 0);
    plot.setPlotPadding(0, 0, 0, 0);

    plot.getGraphWidget().setMarginTop(30);
    plot.getGraphWidget().setMarginRight(50);
    plot.getGraphWidget().setMarginLeft(50);
    plot.getGraphWidget().setMarginBottom(50);



    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);


    // reduce the number of range labels
    plot.setTicksPerRangeLabel(3);
    plot.getGraphWidget().setDomainLabelOrientation(0);

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

    plot.setDomainStep(XYStepMode.SUBDIVIDE, 6);

    plot.addSeries(series1, formatter); //new LineAndPointFormatter(Color.parseColor("#2E64FE"), null, null, null));



}
2
can u show some snap on code snippet? - keshav
have just updated my main query with the code - thank you. - user3792936

2 Answers

1
votes

That's due to an unfortunate mistake in the sample code that included this line:

getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
    WindowManager.LayoutParams.FLAG_SECURE);

Remove that from your code and screen captures should work.

0
votes
// on ICS+ devices :-)
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
        WindowManager.LayoutParams.FLAG_SECURE);

This funny little block is made so the user is unable to to take screenshots. Remove it, and you will be able to take screenshots.