Screenshot Function on android

0

I'm putting the screenshot function on the calendar, but the photo is not coming out as it should.

Butusingthenativeandroidfunctioncomesoutcorrect

Here's some code snippet:

View v1 = getActivity().findViewById(R.id.ScrollcalendarView);

            v1.setDrawingCacheEnabled(true);

            ScrollView z = (ScrollView) getActivity().findViewById(R.id.ScrollcalendarView);
            int totalHeight = z.getChildAt(0).getHeight();
            int totalWidth = z.getChildAt(0).getWidth();
            v1.layout(0, 0, totalWidth, totalHeight);

            Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
            v1.setDrawingCacheEnabled(false);

            File imageFile = new File(mPath);

            FileOutputStream outputStream = new FileOutputStream(imageFile);
            int quality = 100;
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
            outputStream.flush();
            outputStream.close();

            openScreenshot(imageFile);
        } catch (Throwable e) {
            // Several error may come out with file handling or OOM
            e.printStackTrace();
        }
    }

Does anyone have an idea what it can be?

    
asked by anonymous 03.04.2016 / 18:07

2 answers

1

Solved!

I changed the line:

new float[]{0, 0.5f, 0.5f, 0}, Shader.TileMode.REPEAT);

To:

new float[]{0.5f, 0.5f, 0.5f, 0.5f}, Shader.TileMode.REPEAT);

Looking like this:

private static Drawable generateSemiCircleDrawable(final int color1, final int color2) {

        ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
        drawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
            @Override
            public Shader resize(int width, int height) {
                return new LinearGradient(0, 0, width, height,
                        new int[]{color1, color1, color2, color2},
                        new float[]{0.5f, 0.5f, 0.5f, 0.5f}, Shader.TileMode.REPEAT);
            }
        });
        return drawable;
    }

And then it was like this.

    
06.04.2016 / 20:08
0

Problem solved! in part. Was using:

view.setBackgroundDrawable(generateCircleDrawable(color));

and I've changed to:

view.setSelectionDrawable(generateCircleDrawable(color));

But when it comes to two-color example:

view.setSelectionDrawable(generateSemiCircleDrawable(color1, color2));

Only appears to a color as seen in the post.

link

The strange thing is that only happens with the code in the App, using the native screenshot works fine.

I'm still waiting for suggestions

    
06.04.2016 / 12:20