How to import the new API demos into Android-Studio (and Eclipse)?

4.2k views Asked by At

Background

Recently Android-Studio has reached RC version, and I thought of giving it (another) try.

This, and the fact that Lollipop was announced, along with nice cool features on Android-Studio.

The problem

I wanted to try out the samples of the new Lollipop version, but as opposed to Eclipse which has the ability to create a project of the API-Demos (which sadly has become "legacy" and has annoyingly more steps to import), I couldn't find how to do it on Android-Studio.

What I've tried

The only thing I've found is single projects, here.

Sadly, not only it's annoying to import them one after another (yet maybe it's better than a huge project), but I've also failed to do it. This is the instructions:

  1. Unpack the downloaded project package.
  2. In Android Studio, chose File > Import Project and select the root folder of the unpacked project. Android Studio may ask you to choose the type of project you are importing. If this is the case, make sure to choose Import project from external model and select the Gradle option.

So, I've taken one sample from here , which is supposed to show how to use the new transition mechanism on Lollipop.

I've opened Android Studio, and I can't find any "File" menu:

enter image description here

I've tried using the "open an existing android studio project" , but this caused this error: enter image description here

I've also tried other solutions, such as creating a new Android app and import the other project, and also use "import non android studio project". I've even tried importing it to Eclipse (and succeeded), but then it crashed on this exception:

11-23 18:07:20.950: E/AndroidRuntime(2141): Process: com.example.android.activityscenetransitionbasic, PID: 2141
11-23 18:07:20.950: E/AndroidRuntime(2141): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.activityscenetransitionbasic/com.example.android.activityscenetransitionbasic.MainActivity}: java.lang.RuntimeException: Unknown scene name: moveImage
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.access$800(ActivityThread.java:144)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.os.Handler.dispatchMessage(Handler.java:102)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.os.Looper.loop(Looper.java:135)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.main(ActivityThread.java:5221)
11-23 18:07:20.950: E/AndroidRuntime(2141): at java.lang.reflect.Method.invoke(Native Method)
11-23 18:07:20.950: E/AndroidRuntime(2141): at java.lang.reflect.Method.invoke(Method.java:372)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
11-23 18:07:20.950: E/AndroidRuntime(2141): Caused by: java.lang.RuntimeException: Unknown scene name: moveImage
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:177)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:181)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.transition.TransitionInflater.inflateTransition(TransitionInflater.java:77)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.policy.impl.PhoneWindow.getTransition(PhoneWindow.java:3696)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3657)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:367)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.Activity.setContentView(Activity.java:2144)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.example.android.activityscenetransitionbasic.MainActivity.onCreate(MainActivity.java:47)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.Activity.performCreate(Activity.java:5933)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)

The question

How do I really import sample apps into Android-Studio?

Is the new website the new, official way to do it?

Also, how do I do it correctly for Eclipse? It seems to be missing SMS handling classes/functions on the files "MmsMessagingDemo.java" and "MmsWapPushReceiver.java". Only if I make them as comments, it compiles fine.

2

There are 2 answers

3
Amt87 On

Check out this link it contains a solution for moveImage error:

It says

  moveImage should be replaced by changeBounds and changeImageTransform

Like this:

  <?xml version="1.0" encoding="utf-8"?>

<!-- changeBounds is used for the TextViews which are shared -->
<changeBounds>
    <!--
        Set this transitions target IDs to be those which point to the TextViews in both the
        starting and result Activities
    -->
    <targets>
        <target android:targetId="@id/textview_name" />
        <target android:targetId="@id/textview_title" />
    </targets>
</changeBounds>

<!-- moveImage is used for the ImageViews which are shared -->
<changeImageTransform>
    <!--
        Set this transitions target IDs to be those which point to the ImageViews in both the
        starting and result Activities
    -->
    <targets>
        <target android:targetId="@id/imageview_header" />
        <target android:targetId="@id/imageview_item" />
    </targets>
</changeImageTransform>

Go to:

  res>>>transition>>> edit your transition xml file and change <moveImage> to <changeImageTransform>

And make sure to check the ids in "target" tag; you must have them in your layout.

5
thekadrik On

This is what you should put instead of moveImage:

<changeBounds>
    <targets>
        <target android:targetId="@id/imageView_image" />
        <target android:targetId="@id/imageView_image" />
    </targets>
</changeBounds>

<changeImageTransform>
  <targets>
        <target android:targetId="@id/imageView_image" />
        <target android:targetId="@id/imageView_image" />
    </targets>
</changeImageTransform>