DO NOT MERGE. Port live wallpaper changes from Froyo to Eclair for Droid support.

Fix the 'many' visualization so it doesn't jump after turning the screen on.

Update to new RS texture API.

Update to new RS element API.

Add uses-feature for live wallpapers.
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 11858b7..30607f5 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -21,6 +21,8 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.android.musicvis">
 
+    <uses-feature android:name="android.software.live_wallpaper" />
+
     <application
         android:label="@string/wallpapers"
         android:icon="@drawable/ic_launcher_wallpaper">
diff --git a/res/raw/many.rs b/res/raw/many.rs
index db59fba..bfde7ca 100644
--- a/res/raw/many.rs
+++ b/res/raw/many.rs
@@ -243,8 +243,12 @@
     int now = uptimeMillis();
     int delta = now - lastuptime;
     lastuptime = now;
-    if (delta > 5000) {
-        delta = 100;
+    if (delta > 80) {
+        // Limit the delta to avoid jumps when coming back from sleep.
+        // A value of 80 will make the rotation keep the same speed
+        // until the frame rate drops to 12.5 fps, at which point it
+        // will start slowing down.
+        delta = 80;
     }
     autorotation += .3 * delta / 35;
     while (autorotation > 360.f) autorotation -= 360.f;
diff --git a/src/com/android/musicvis/GenericWaveRS.java b/src/com/android/musicvis/GenericWaveRS.java
index 78ffe3c..b97acfe 100644
--- a/src/com/android/musicvis/GenericWaveRS.java
+++ b/src/com/android/musicvis/GenericWaveRS.java
@@ -17,7 +17,6 @@
 package com.android.musicvis;
 
 import static android.renderscript.Element.RGB_565;
-import static android.renderscript.ProgramFragment.EnvMode.REPLACE;
 import static android.renderscript.Sampler.Value.LINEAR;
 import static android.renderscript.Sampler.Value.WRAP;
 
@@ -146,11 +145,8 @@
 
         // Create the Element for the points
         Builder elementBuilder = new Builder(mRS);
-        // By specifying a prefix, even an empty one, the members will be accessible
-        // in the renderscript. If we just called addFloatXYZ(), the members would be
-        // unnamed in the renderscript struct definition.
-        elementBuilder.addFloatXY("");
-        elementBuilder.addFloatST("");
+        elementBuilder.add(Element.ATTRIB_POSITION_2(mRS), "position");
+        elementBuilder.add(Element.ATTRIB_TEXTURE_2(mRS), "texture");
         final Element vertexElement = elementBuilder.create();
         final int vertexSlot = meshBuilder.addVertexType(vertexElement, mPointData.length / 4);
         // Specify the type and number of indices we need. We'll allocate them later.
@@ -193,7 +189,7 @@
         mTexture = Allocation.createFromBitmapResourceBoxed(mRS, mResources, mTexId, RGB_565(mRS), false);
         mTexture.setName("Tlinetexture");
         mTexture.uploadToTexture(0);
-        
+
         /*
          * create a program fragment to use the texture
          */
@@ -204,9 +200,9 @@
         samplerBuilder.setWrapT(WRAP);
         mSampler = samplerBuilder.create();
 
-        ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
-        builder.setTexEnable(true, 0);
-        builder.setTexEnvMode(REPLACE, 0);
+        ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
+        builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
+                           ProgramFragment.Builder.Format.RGBA, 0);
         mPfBackground = builder.create();
         mPfBackground.setName("PFBackground");
         mPfBackground.bindSampler(mSampler, 0);
diff --git a/src/com/android/musicvis/vis4/Visualization4RS.java b/src/com/android/musicvis/vis4/Visualization4RS.java
index 78a7e2e..1f22075 100644
--- a/src/com/android/musicvis/vis4/Visualization4RS.java
+++ b/src/com/android/musicvis/vis4/Visualization4RS.java
@@ -16,7 +16,6 @@
 
 package com.android.musicvis.vis4;
 
-import static android.renderscript.ProgramFragment.EnvMode.REPLACE;
 import static android.renderscript.ProgramStore.DepthFunc.ALWAYS;
 import static android.renderscript.Sampler.Value.LINEAR;
 import static android.renderscript.Sampler.Value.WRAP;
@@ -54,7 +53,7 @@
     // tweak this to get quicker/slower response
     private int mNeedleMass = 10;
     private int mSpringForceAtOrigin = 200;
-    
+
     static class WorldState {
         public float mAngle;
         public int   mPeak;
@@ -67,7 +66,7 @@
     private ProgramFragment mPfBackground;
     private Sampler mSampler;
     private Allocation[] mTextures;
-    
+
     private ProgramVertex mPVBackground;
     private ProgramVertex.MatrixAllocation mPVAlloc;
 
@@ -131,7 +130,7 @@
         for (int i = 0; i < count; i++) {
             mTextures[i].uploadToTexture(0);
         }
-        
+
         Sampler.Builder samplerBuilder = new Sampler.Builder(mRS);
         samplerBuilder.setMin(LINEAR);
         samplerBuilder.setMag(LINEAR);
@@ -140,9 +139,9 @@
         mSampler = samplerBuilder.create();
 
         {
-            ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
-            builder.setTexEnable(true, 0);
-            builder.setTexEnvMode(REPLACE, 0);
+            ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
+            builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
+                               ProgramFragment.Builder.Format.RGBA, 0);
             mPfBackground = builder.create();
             mPfBackground.setName("PFBackground");
             mPfBackground.bindSampler(mSampler, 0);
@@ -198,7 +197,7 @@
         mHandler.postDelayed(mDrawCube, 20);
 
         int len = MediaPlayer.snoop(mVizData, 0);
-        
+
         // Simulate running the signal through a rectifier by
         // taking the average of the absolute sample values.
         int volt = 0;
@@ -224,8 +223,8 @@
         // The friction force is a function of the speed of the needle, but so is
         // the current induced by the movement of the needle, so we can combine
         // them.
-        
-        
+
+
         // Add up the various forces, with some multipliers to make the movement
         // of the needle more realistic
         // 'volt' is for the applied voltage, which causes a current to flow through the coil
diff --git a/src/com/android/musicvis/vis5/Visualization5RS.java b/src/com/android/musicvis/vis5/Visualization5RS.java
index b5ef2a3..e92ef2c 100644
--- a/src/com/android/musicvis/vis5/Visualization5RS.java
+++ b/src/com/android/musicvis/vis5/Visualization5RS.java
@@ -16,8 +16,6 @@
 
 package com.android.musicvis.vis5;
 
-import static android.renderscript.ProgramFragment.EnvMode.REPLACE;
-
 import com.android.musicvis.R;
 import com.android.musicvis.RenderScriptScene;
 
@@ -57,7 +55,7 @@
     // tweak this to get quicker/slower response
     private int mNeedleMass = 10;
     private int mSpringForceAtOrigin = 200;
-    
+
     static class WorldState {
         public float mAngle;
         public int   mPeak;
@@ -76,7 +74,7 @@
     private Sampler mSamplerMip;
     private Sampler mSamplerNoMip;
     private Allocation[] mTextures;
-    
+
     private ProgramVertex mPVBackground;
     private ProgramVertex.MatrixAllocation mPVAlloc;
 
@@ -90,7 +88,7 @@
     private Allocation mLineIdxAlloc;
     // 2 indices per line
     private short [] mIndexData = new short[256*2];
-    
+
     private short [] mVizData = new short[1024];
 
     private static final int RSID_STATE = 0;
@@ -99,7 +97,7 @@
     private static final int RSID_PROGRAMVERTEX = 3;
 
     private float mTouchY;
-    
+
     Visualization5RS(int width, int height) {
         super(width, height);
         mWidth = width;
@@ -146,7 +144,7 @@
                 mState.data(mWorldState);
         }
     }
-    
+
     @Override
     public void setOffset(float xOffset, float yOffset,
             float xStep, float yStep, int xPixels, int yPixels) {
@@ -215,18 +213,18 @@
         }
 
         {
-            ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
-            builder.setTexEnable(true, 0);
-            builder.setTexEnvMode(REPLACE, 0);
+            ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
+            builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
+                               ProgramFragment.Builder.Format.RGBA, 0);
             mPfBackgroundNoMip = builder.create();
             mPfBackgroundNoMip.setName("PFBackgroundNoMip");
             mPfBackgroundNoMip.bindSampler(mSamplerNoMip, 0);
         }
-        
+
         {
-            ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
-            builder.setTexEnable(true, 0);
-            builder.setTexEnvMode(REPLACE, 0);
+            ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS);
+            builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
+                               ProgramFragment.Builder.Format.RGBA, 0);
             mPfBackgroundMip = builder.create();
             mPfBackgroundMip.setName("PFBackgroundMip");
             mPfBackgroundMip.bindSampler(mSamplerMip, 0);
@@ -242,17 +240,14 @@
             mPfsBackground = builder.create();
             mPfsBackground.setName("PFSBackground");
         }
-        
+
         // Start creating the mesh
         final SimpleMesh.Builder meshBuilder = new SimpleMesh.Builder(mRS);
 
         // Create the Element for the points
         Builder elementBuilder = new Builder(mRS);
-        // By specifying a prefix, even an empty one, the members will be accessible
-        // in the renderscript. If we just called addFloatXYZ(), the members would be
-        // unnamed in the renderscript struct definition.
-        elementBuilder.addFloatXY("");
-        elementBuilder.addFloatST("");
+        elementBuilder.add(Element.ATTRIB_POSITION_2(mRS), "position");
+        elementBuilder.add(Element.ATTRIB_TEXTURE_2(mRS), "texture");
         final Element vertexElement = elementBuilder.create();
         final int vertexSlot = meshBuilder.addVertexType(vertexElement, mPointData.length / 4);
         // Specify the type and number of indices we need. We'll allocate them later.
@@ -330,7 +325,7 @@
         mHandler.postDelayed(mDrawCube, 20);
 
         int len = MediaPlayer.snoop(mVizData, 0);
-        
+
         // Simulate running the signal through a rectifier by
         // taking the average of the absolute sample values.
         int volt = 0;
@@ -356,8 +351,8 @@
         // The friction force is a function of the speed of the needle, but so is
         // the current induced by the movement of the needle, so we can combine
         // them.
-        
-        
+
+
         // Add up the various forces, with some multipliers to make the movement
         // of the needle more realistic
         // 'volt' is for the applied voltage, which causes a current to flow through the coil
@@ -383,9 +378,9 @@
         }
 
         mWorldState.mAngle = 131f - (mNeedlePos / 410f); // ~80 degree range
-        
+
         // downsample 1024 samples in to 256
-        
+
         if (len == 0) {
             if (mWorldState.mIdle == 0) {
                 mWorldState.mIdle = 1;
@@ -406,7 +401,7 @@
             mPointAlloc.data(mPointData);
             mWorldState.mWaveCounter++;
         }
-        
+
         mState.data(mWorldState);
     }