Merge "Add dependency on the 22.0 plugin."
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java
index baeb154..093072b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java
@@ -17,6 +17,8 @@
 package com.android.ide.eclipse.adt.internal.build.builders;
 
 import com.android.SdkConstants;
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
 import com.android.ide.eclipse.adt.AdtConstants;
 import com.android.ide.eclipse.adt.AdtPlugin;
 import com.android.ide.eclipse.adt.AndroidPrintStream;
@@ -913,8 +915,9 @@
     }
 
     @Override
-    protected void abortOnBadSetup(IJavaProject javaProject, ProjectState projectState)
-            throws AbortBuildException, CoreException {
+    protected void abortOnBadSetup(
+            @NonNull IJavaProject javaProject,
+            @Nullable ProjectState projectState) throws AbortBuildException, CoreException {
         super.abortOnBadSetup(javaProject, projectState);
 
         IProject iProject = getProject();
diff --git a/files/ant/build.xml b/files/ant/build.xml
index b50363a..7931cd2 100644
--- a/files/ant/build.xml
+++ b/files/ant/build.xml
@@ -71,6 +71,7 @@
     <property name="java.target" value="1.5" />
     <property name="java.source" value="1.5" />
     <property name="java.compilerargs" value="" />
+    <property name="java.compiler.classpath" value="" />
 
     <!-- Renderscript options -->
     <property name="renderscript.debug.opt.level" value="O0" />
@@ -714,6 +715,7 @@
             <path id="project.javac.classpath">
                 <path refid="project.all.jars.path" />
                 <path refid="tested.project.classpath" />
+                <path path="${java.compiler.classpath}" />
             </path>
             <javac encoding="${java.encoding}"
                     source="${java.source}" target="${java.target}"
diff --git a/templates/other/Daydream/globals.xml.ftl b/templates/other/Daydream/globals.xml.ftl
new file mode 100644
index 0000000..04537f9
--- /dev/null
+++ b/templates/other/Daydream/globals.xml.ftl
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<globals>
+    <global id="srcOut" value="src/${slashedPackageName(packageName)}" />
+    <global id="class_name" value="${classToResource(className)}" />
+    <global id="info_name" value="${classToResource(className)}_info" />
+    <global id="settingsClassName"  value="${className}SettingsActivity" />
+    <global id="prefs_name" value="${classToResource(className)}_prefs" />
+</globals>
diff --git a/templates/other/Daydream/recipe.xml.ftl b/templates/other/Daydream/recipe.xml.ftl
new file mode 100644
index 0000000..8db9811
--- /dev/null
+++ b/templates/other/Daydream/recipe.xml.ftl
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<recipe>
+
+    <merge from="AndroidManifest.xml.ftl" />
+    <merge from="res/values/strings.xml.ftl" />
+
+    <copy from="res/layout-v17/dream.xml"
+          to="res/layout-v17/${class_name}.xml" />
+
+    <instantiate from="src/app_package/DreamService.java.ftl"
+                 to="${srcOut}/${className}.java" />
+
+<#if configurable>
+    <copy from="res/xml/dream_prefs.xml"
+          to="res/xml/${prefs_name}.xml" />
+
+    <instantiate from="src/app_package/SettingsActivity.java.ftl"
+                 to="${srcOut}/${settingsClassName}.java" />
+
+    <instantiate from="res/xml/xml_dream.xml.ftl"
+                 to="res/xml/${info_name}.xml" />
+</#if>
+
+    <open file="${srcOut}/${className}.java" />
+
+</recipe>
diff --git a/templates/other/Daydream/root/AndroidManifest.xml.ftl b/templates/other/Daydream/root/AndroidManifest.xml.ftl
new file mode 100644
index 0000000..c23bc6e
--- /dev/null
+++ b/templates/other/Daydream/root/AndroidManifest.xml.ftl
@@ -0,0 +1,28 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <application>
+
+<#if configurable>
+        <activity
+            android:name=".${settingsClassName}" />
+</#if>
+
+        <!-- This service is only used on devices with API v17+ -->
+        <service
+            android:name=".${className}"
+            android:exported="true" >
+            <intent-filter>
+                <action android:name="android.service.dreams.DreamService" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+<#if configurable>
+
+            <!-- Point to additional information for this dream -->
+            <meta-data
+                android:name="android.service.dream"
+                android:resource="@xml/${info_name}" />
+</#if>
+        </service>
+    </application>
+
+</manifest>
diff --git a/templates/other/Daydream/root/res/layout-v17/dream.xml b/templates/other/Daydream/root/res/layout-v17/dream.xml
new file mode 100644
index 0000000..25593f3
--- /dev/null
+++ b/templates/other/Daydream/root/res/layout-v17/dream.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <TextView
+        android:id="@+id/dream_text"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:fontFamily="sans-serif-light"
+        android:textSize="50sp" />
+
+</FrameLayout>
diff --git a/templates/other/Daydream/root/res/values/strings.xml.ftl b/templates/other/Daydream/root/res/values/strings.xml.ftl
new file mode 100644
index 0000000..b3d208f
--- /dev/null
+++ b/templates/other/Daydream/root/res/values/strings.xml.ftl
@@ -0,0 +1,7 @@
+<resources>
+    <string name="pref_dream_text_key">pref_dream_text</string>
+    <string name="pref_dream_text_default">zzzZZZzzz</string>
+<#if configurable>
+    <string name="pref_dream_text_title">Ticker text</string>
+</#if>
+</resources>
diff --git a/templates/other/Daydream/root/res/xml/dream_prefs.xml b/templates/other/Daydream/root/res/xml/dream_prefs.xml
new file mode 100644
index 0000000..997e5b2
--- /dev/null
+++ b/templates/other/Daydream/root/res/xml/dream_prefs.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <EditTextPreference
+        android:key="@string/pref_dream_text_key"
+        android:title="@string/pref_dream_text_title"
+        android:defaultValue="@string/pref_dream_text_default" />
+
+</PreferenceScreen>
diff --git a/templates/other/Daydream/root/res/xml/xml_dream.xml.ftl b/templates/other/Daydream/root/res/xml/xml_dream.xml.ftl
new file mode 100644
index 0000000..5367ae1
--- /dev/null
+++ b/templates/other/Daydream/root/res/xml/xml_dream.xml.ftl
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dream xmlns:android="http://schemas.android.com/apk/res/android"
+    android:settingsActivity="${packageName}/.${settingsClassName}" />
diff --git a/templates/other/Daydream/root/src/app_package/DreamService.java.ftl b/templates/other/Daydream/root/src/app_package/DreamService.java.ftl
new file mode 100644
index 0000000..30f080f
--- /dev/null
+++ b/templates/other/Daydream/root/src/app_package/DreamService.java.ftl
@@ -0,0 +1,140 @@
+package ${packageName};
+
+import java.util.Random;
+
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.TimeInterpolator;
+import android.annotation.TargetApi;
+import android.content.SharedPreferences;
+import android.graphics.Point;
+import android.os.Build;
+import android.preference.PreferenceManager;
+import android.service.dreams.DreamService;
+import android.view.ViewPropertyAnimator;
+import android.view.animation.LinearInterpolator;
+import android.widget.TextView;
+
+/**
+ * This class is a sample implementation of a DreamService. When activated, a
+ * TextView will repeatedly, move from the left to the right of screen, at a
+ * random y-value.
+<#if configurable>
+ * The generated {@link BlahDreamServiceSettingsActivity} allows
+ * the user to change the text which is displayed.
+</#if>
+ * <p />
+ * Daydreams are only available on devices running API v17+.
+ */
+@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+public class ${className} extends DreamService {
+
+    private static final TimeInterpolator sInterpolator = new LinearInterpolator();
+
+    private final AnimatorListener mAnimListener = new AnimatorListenerAdapter() {
+
+        @Override
+        public void onAnimationEnd(Animator animation) {
+            // Start animation again
+            startTextViewScrollAnimation();
+        }
+
+    };
+
+    private final Random mRandom = new Random();
+    private final Point mPointSize = new Point();
+
+    private TextView mDreamTextView;
+    private ViewPropertyAnimator mAnimator;
+
+    @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+
+        // Exit dream upon user touch?
+<#if isInteractive>
+        setInteractive(true);
+<#else>
+        setInteractive(false);
+</#if>
+
+        // Hide system UI?
+<#if isFullscreen>
+        setFullscreen(true);
+<#else>
+        setFullscreen(false);
+</#if>
+
+        // Keep screen at full brightness?
+<#if isScreenBright>
+        setScreenBright(true);
+<#else>
+        setScreenBright(false);
+</#if>
+
+        // Set the content view, just like you would with an Activity.
+        setContentView(R.layout.${class_name});
+
+        mDreamTextView = (TextView) findViewById(R.id.dream_text);
+        mDreamTextView.setText(getTextFromPreferences());
+    }
+
+    @Override
+    public void onDreamingStarted() {
+        super.onDreamingStarted();
+
+        // TODO: Begin animations or other behaviors here.
+
+        startTextViewScrollAnimation();
+    }
+
+    @Override
+    public void onDreamingStopped() {
+        super.onDreamingStopped();
+
+        // TODO: Stop anything that was started in onDreamingStarted()
+
+        mAnimator.cancel();
+    }
+
+    @Override
+    public void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+
+        // TODO: Dismantle resources
+        // (for example, detach from handlers and listeners).
+    }
+
+    private String getTextFromPreferences() {
+        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+        return prefs.getString(getString(R.string.pref_dream_text_key),
+                getString(R.string.pref_dream_text_default));
+    }
+
+    private void startTextViewScrollAnimation() {
+        // Refresh Size of Window
+        getWindowManager().getDefaultDisplay().getSize(mPointSize);
+
+        final int windowWidth = mPointSize.x;
+        final int windowHeight = mPointSize.y;
+
+        // Move TextView so it's moved all the way to the left
+        mDreamTextView.setTranslationX(-mDreamTextView.getWidth());
+
+        // Move TextView to random y value
+        final int yRange = windowHeight - mDreamTextView.getHeight();
+        mDreamTextView.setTranslationY(mRandom.nextInt(yRange));
+
+        // Create an Animator and keep a reference to it
+        mAnimator = mDreamTextView.animate().translationX(windowWidth)
+            .setDuration(3000)
+            .setStartDelay(500)
+            .setListener(mAnimListener)
+            .setInterpolator(sInterpolator);
+
+        // Start the animation
+        mAnimator.start();
+    }
+
+}
diff --git a/templates/other/Daydream/root/src/app_package/SettingsActivity.java.ftl b/templates/other/Daydream/root/src/app_package/SettingsActivity.java.ftl
new file mode 100644
index 0000000..62d5887
--- /dev/null
+++ b/templates/other/Daydream/root/src/app_package/SettingsActivity.java.ftl
@@ -0,0 +1,36 @@
+package ${packageName};
+
+import android.annotation.TargetApi;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
+
+/**
+ * A settings Activity for {@link ${className}}.
+ * <p />
+ * A DreamService can only be used on devices with API v17+, so it is safe
+ * for us to use a {@link PreferenceFragment} here.
+ */
+@TargetApi(Build.VERSION_CODES.HONEYCOMB)
+public class ${settingsClassName} extends PreferenceActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        getFragmentManager().beginTransaction()
+                .replace(android.R.id.content, new DreamPreferenceFragment()).commit();
+    }
+
+    public static class DreamPreferenceFragment extends PreferenceFragment {
+
+        @Override
+        public void onCreate(Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+            addPreferencesFromResource(R.xml.${prefs_name});
+        }
+
+    }
+
+}
diff --git a/templates/other/Daydream/template.xml b/templates/other/Daydream/template.xml
new file mode 100644
index 0000000..2014eee
--- /dev/null
+++ b/templates/other/Daydream/template.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<template
+    format="3"
+    revision="1"
+    name="New Daydream"
+    description="Creates a new Daydream service component, for use on devices running Android 4.2 and later."
+    minBuildApi="17">
+
+    <category value="Other" />
+
+    <parameter
+        id="className"
+        name="Class Name"
+        type="string"
+        constraints="class|unique|nonempty"
+        default="MyDaydreamService" />
+
+    <parameter
+        id="isInteractive"
+        name="Interactive?"
+        type="boolean"
+        default="false"
+        help="Whether or not the Daydream is interactive. Touching anywhere on a non-interactive Daydreams dismisses it." />
+
+    <parameter
+        id="isFullscreen"
+        name="Fullscreen?"
+        type="boolean"
+        default="true"
+        help="Whether or not the Daydream should be in fullscreen mode (in which case system UI will be hidden)." />
+
+    <parameter
+        id="isScreenBright"
+        name="Bright Screen?"
+        type="boolean"
+        default="true"
+        help="Whether or not the screen should be bright when this Daydream is running. The screen will be dim otherwise." />
+
+    <parameter
+        id="configurable"
+        name="Configuration Activity"
+        type="boolean"
+        default="false"
+        help="Whether or not to generate an associated settings Activity." />
+
+    <globals file="globals.xml.ftl" />
+    <execute file="recipe.xml.ftl" />
+
+</template>