Function Screenshot on android

Asked

Viewed 101 times

0

I’m putting the screenshot function in the calendar, however the photo is not going as it should.

Esta saindo assim

But using native android function comes out correct

inserir a descrição da imagem aqui

Follows excerpt from the code:

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 any idea what it might be?

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

Thus remaining:

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 done. inserir a descrição da imagem aqui

0

Problem solved! in part. Was using:

view.setBackgroundDrawable(generateCircleDrawable(color));

and changed to:

view.setSelectionDrawable(generateCircleDrawable(color));

But when it comes to two example colors:

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

Only appears to a color as seen in the post.

https://github.com/prolificinteractive/material-calendarview/issues/263

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

I’m still waiting for suggestions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.