0

I've read this one : How to programmatically take a screenshot in Android? that helps a lot.

In my case I have some animation (transition) on some graphics, the graphics are displayed in few seconds. If I follow the previous thread I get a screenshot before the animations so the graphics are empty.

Is there a solution to take the screenshot after the animations? Or is there a solution to call the "activity" with a parameter that set animation delay = 0?

Community
  • 1
  • 1
Fredblabla
  • 1,029
  • 1
  • 6
  • 5

3 Answers3

0

I'm not aware about the way you're animating your screen.

If you have access to any listener that may have onAnimationComplete method you can run your screenshot code from there.

Alternatively, You can run your code with the help of a handler.

new Handler ().postDelayed (new Runnable (){
    void run (){
         // screenshot code
    }
},2500);

2500 is the time in milliseconds.

Prashant Solanki
  • 660
  • 5
  • 10
0

Actually I am using a component to display a progressbar where I have something like (to animate the view):

        ObjectAnimator animation = ObjectAnimator.ofInt(view, "progress", start, value);
        animation.setDuration(duration); //in milliseconds
        animation.setInterpolator(new AccelerateInterpolator());
        animation.start();
Fredblabla
  • 1,029
  • 1
  • 6
  • 5
0

I found the solution and it is very simple I was doing something like

View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
Bitmap bitmap = rootView.getDrawingCache();

I just need to call again the animation with a duration at 0 juste before setDrawingCache :

...
View rootView = findViewById(android.R.id.content).getRootView();
ObjectAnimator animation = ObjectAnimator.ofInt(view, "progress", start, value);
animation.setDuration(0); //in milliseconds
animation.setInterpolator(new AccelerateInterpolator());
animation.start();
rootView.setDrawingCacheEnabled(true);
Bitmap bitmap = rootView.getDrawingCache();
...
Fredblabla
  • 1,029
  • 1
  • 6
  • 5