12

According to the guidelines: https://developer.android.com/design/wear/patterns.html#Continuing

"In cases where the phone must be used, a generic animation should be played once the action button has been tapped and the corresponding Android app will open on the phone."

The animation can be seen in the Google Keep app. Here is a sample recording: https://dl.dropboxusercontent.com/u/25670071/IMG_0274.MOV

Is there a standard implementation of this animation somewhere?

Christer Nordvik
  • 2,518
  • 3
  • 35
  • 52

1 Answers1

31

The steps needed to implement this functionality depends on whether the notification is submitted from phone or from wearable device.

Notification from phone:

If your notification came from phone - the "Open on phone" action page is added automatically when your notification has setContentIntent(PendingIntent intent) set.

From your wearable app:

If you need to play this animation in a notification that is submitted from wearable device directly (or from any other place from your wearable application) you will need to launch this animation by yourself.

There is a nice ConfirmationActivity that supports few predefined animation types:

  • ConfirmationActivity.SUCCESS_ANIMATION
  • ConfirmationActivity.OPEN_ON_PHONE_ANIMATION
  • ConfirmationActivity.FAILURE_ANIMATION

The animation you should be interested it is ConfirmationActivity.OPEN_ON_PHONE_ANIMATION. You need to pass the type of animation in the ConfirmationActivity.EXTRA_ANIMATION_TYPE extra.

Intent intent = new Intent(context, ConfirmationActivity.class);
intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);
startActivity(intent);

IMPORTANT: To launch the ConfirmationActivity you need to add it to your Manifest file:

<activity android:name="android.support.wearable.activity.ConfirmationActivity" />

Theme:

Next step is to tweak the style of this ConfirmationActivity. For example if you want to disable the default sliding animation or to make the window transparent you will need to set a custom theme to it in your manifest:

<activity android:name="android.support.wearable.activity.ConfirmationActivity"
    android:theme="@style/TransparentTheme"/>

and define the TransparentTheme in themes.xml:

<style name="TransparentTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@null</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
</style>
Maciej Ciemięga
  • 10,125
  • 1
  • 41
  • 48
  • It would also be great to know where in the SDK to get the stock "Open on phone" drawable. – Warlax Oct 06 '14 at 19:08
  • @Warlax Animation is located as drawable: `R.drawable.go_to_phone_animation`. You can use it to build your custom interface, but only if you have good reason not to use standard `ConfirmationActivity` :) – Maciej Ciemięga Oct 06 '14 at 20:27
  • Oh I wasn't clear about my question. I meant a drawable that I can use to pass into the Action so it looks like the stock "open on phone" action. – Warlax Oct 06 '14 at 20:41
  • 2
    Go to the `R.drawable.go_to_phone_animation` animation drawable and check drawables for separate frames. First frame is stored in `R.drawable.go_to_phone_00156`, probably you can use that as an image for action. – Maciej Ciemięga Oct 06 '14 at 20:52
  • Hi, I can't seem to disable the slide in from the left @null should resolve it but for some reason does not work for me. I also tried windowEnterAnimation and set to null but does not work :(. Everything else works like transparent background. Not sure what I am doing wrong.... – Springy Nov 25 '14 at 22:00
  • I can't edit the above but solved it. For some reason defining it in xml does not work, but I used the ActivityOptions to do it. Code I used is: **context.startActivity(intentAnimation, ActivityOptions.makeCustomAnimation(context,0,0).toBundle());** – Springy Nov 26 '14 at 22:07
  • 1
    An easier way to disable the default sliding animation for the ConfirmationActivity is to add the Intent.FLAG_ACTIVITY_NO_ANIMATION flag on the intent that starts it. – Tony Wickham Apr 14 '15 at 03:03
  • Another way to disable the sliding animation is after you call `startActivity(intent)` you do this: `overridePendingTransition(0,0);` This overrides the transition and gives it no animation. – Kevin van Mierlo Nov 30 '15 at 10:42