4

Some appwidgets are using the makeScaleUpAnimation (introduced in JellyBean 4.1) when starting an activity from the widget. How is this possible when you can't reach the view from your widget provider?

Is there any way to get the whole appwidgets view or something? I can't find a solution..

ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(view, 0, 0,
        view.getWidth(), view.getHeight());
  // Request the activity be started, using the custom animation options.
  startActivity(new Intent(MainActivity.this, AnimationActivity.class),
        opts.toBundle());

I'm opening the sms inbox from my widget

Intent inboxIntent = new Intent(Intent.ACTION_MAIN);
                inboxIntent.setType("vnd.android-dir/mms-sms");
                int flags = Intent.FLAG_ACTIVITY_NEW_TASK |

                        Intent.FLAG_ACTIVITY_SINGLE_TOP |          

                        Intent.FLAG_ACTIVITY_CLEAR_TOP;
                inboxIntent.setFlags(flags);

                context.startActivity(inboxIntent);
Thoast83
  • 529
  • 5
  • 15

1 Answers1

4

Your activity should call getIntent().getSourceBounds() to fetch this information.

j__m
  • 9,392
  • 1
  • 32
  • 56
  • Wasn't starting the activity from an activity, but your're right, that was the key. This is my final code. Feels wrong to create a empty view, but it works. `View view = new View(context); view.setLayoutParams(new LayoutParams(0,0)); ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(view, intent.getSourceBounds().left, intent.getSourceBounds().top, intent.getSourceBounds().width(), intent.getSourceBounds().height()); context.startActivity(threadIntent, opts.toBundle());` – Thoast83 Dec 26 '13 at 11:51
  • 1
    It's a strange function. If you look at the source code, the passed-in `View` is only used to get your package name (from the view's context) and to translate the bounds from client coordinates to screen coordinates. Seems they would have been better off making that parameter a `Context` and simply requiring screen coordinates to start with. Since the `View` you're passing in doesn't have a position on screen (having never been attached to the window) your coordinates end up being treated like screen coordinates anyway (which is good, because that's what you get from `getSourceBounds()`). – j__m Dec 26 '13 at 13:59
  • 1
    Basically your solution is even more of a hack than you realized, but it works, and there's no alternate version of the method. – j__m Dec 26 '13 at 14:02