Clean up the SDK and make it compiled and installed in the SDK system image.

Change-Id: I6e5f01a1cc45beada70608307f4ac38a4dcdd0b9
This commit is contained in:
Xavier Ducrohet
2009-12-14 22:34:06 -08:00
parent 1162372c9e
commit b84cf9e1e3
13 changed files with 13 additions and 565 deletions

View File

@@ -87,6 +87,7 @@ development/samples/ContactManager platforms/${PLATFORM_NAME}/samples/ContactMan
development/samples/MultiResolution platforms/${PLATFORM_NAME}/samples/MultiResolution
development/samples/Wiktionary platforms/${PLATFORM_NAME}/samples/Wiktionary
development/samples/WiktionarySimple platforms/${PLATFORM_NAME}/samples/WiktionarySimple
development/samples/CubeLiveWallpaper platforms/${PLATFORM_NAME}/samples/CubeLiveWallpaper
# dx
bin/dx platforms/${PLATFORM_NAME}/tools/dx

View File

@@ -17,11 +17,12 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# LOCAL_MODULE_TAGS := user
LOCAL_MODULE_TAGS := samples
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := CubeLiveWallpapers
LOCAL_CERTIFICATE := shared
LOCAL_SDK_VERSION := current
include $(BUILD_PACKAGE)

View File

@@ -19,7 +19,7 @@
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.livecubes">
package="com.example.android.livecubes">
<application
android:label="@string/wallpapers"
@@ -46,21 +46,10 @@
</service>
<activity
android:label="@string/cube2_settings"
android:name="com.android.livecubes.cube2.CubeWallpaper2Settings"
android:name=".cube2.CubeWallpaper2Settings"
android:theme="@android:style/Theme.Light.WallpaperSettings"
android:exported="true">
</activity>
<service
android:label="@string/wallpaper_cube3"
android:name=".cube3.CubeWallpaper3"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper" android:resource="@xml/cube3" />
</service>
</application>
</manifest>

View File

@@ -1,50 +0,0 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma version(1)
#pragma stateVertex(PVBackground)
#define RSID_POINTS 0
void dumpState() {
// debugF("@@@@@ yrot: ", State->yRotation);
}
int main(int launchID) {
int i;
// Change the model matrix to account for the large model
// and to do the necessary rotations.
float mat1[16];
float rads = ((float)startTimeMillis()) / 1000;
float xrot = degf(-rads);
float yrot = State->yRotation;
float scale = 1.0/900.0;
matrixLoadScale(mat1, scale, scale, scale);
matrixRotate(mat1, yrot, 0.f, 1.f, 0.f);
matrixRotate(mat1, xrot, 1.f, 0.f, 0.f);
vpLoadModelMatrix(mat1);
// Draw the cube. The default color will be used,
// but we can also set the color here with the color()
// function, or specify the color(s) as part of
// the vertex data.
uploadToBufferObject(NAMED_PointBuffer);
drawSimpleMesh(NAMED_CubeMesh);
return 1;
}

View File

@@ -20,5 +20,5 @@
<!-- The attributes in this XML file provide configuration information -->
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.android.livecubes.cube2.CubeWallpaper2Settings"
android:settingsActivity="com.example.android.livecubes.cube2.CubeWallpaper2Settings"
/>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright (c) 2009, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<!-- The attributes in this XML file provide configuration information -->
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
/>

View File

@@ -1,242 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.livecubes.cube3;
import com.android.livecubes.R;
import com.android.livecubes.RenderScriptScene;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.Primitive;
import android.renderscript.ProgramRaster;
import android.renderscript.ProgramVertex;
import android.renderscript.ScriptC;
import android.renderscript.SimpleMesh;
import android.renderscript.Type;
import android.renderscript.Element.Builder;
import java.util.TimeZone;
/*
* This example draws a shape whose definition is read from resources (though
* it's not user selectable like in example #2), but does the drawing using
* RenderScript.
*/
class Cube3RS extends RenderScriptScene {
static class ThreeDPoint {
public float x;
public float y;
public float z;
}
static class ThreeDLine {
int startPoint;
int endPoint;
}
static class WorldState {
public float yRotation;
public float mCenterX;
public float mCenterY;
}
ThreeDPoint [] mOriginalPoints;
ThreeDLine [] mLines;
WorldState mWorldState = new WorldState();
private Type mStateType;
private Allocation mState;
private SimpleMesh mCubeMesh;
private Allocation mPointAlloc;
private float [] mPointData;
private Allocation mLineIdxAlloc;
private short [] mIndexData;
private ProgramVertex mPVBackground;
private ProgramVertex.MatrixAllocation mPVAlloc;
private int mWidth;
private int mHeight;
private static final int RSID_STATE = 0;
private static final int RSID_POINTS = 1;
private static final int RSID_LINES = 2;
private static final int RSID_PROGRAMVERTEX = 3;
Cube3RS(int width, int height) {
super(width, height);
mWidth = width;
mHeight = height;
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
mWidth = width;
mHeight = height;
}
@Override
protected ScriptC createScript() {
// Read the model in to our point/line objects
readModel();
// Create a renderscript type from a java class. The specified name doesn't
// really matter; the name by which we refer to the object in RenderScript
// will be specified later.
mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
// Create an allocation from the type we just created.
mState = Allocation.createTyped(mRS, mStateType);
// set our java object as the data for the renderscript allocation
mWorldState.yRotation = (-0.5f) * 2 * 180 / (float) Math.PI;
mState.data(mWorldState);
/*
* Now put our model in to a form that renderscript can work with:
* - create a buffer of floats that are the coordinates for the points that define the cube
* - create a buffer of integers that are the indices of the points that form lines
* - combine the two in to a mesh
*/
// First set up the coordinate system and such
ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
mPVBackground = pvb.create();
mPVBackground.setName("PVBackground");
mPVAlloc = new ProgramVertex.MatrixAllocation(mRS);
mPVBackground.bindAllocation(mPVAlloc);
mPVAlloc.setupProjectionNormalized(mWidth, mHeight);
// 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.addFloatXYZ("");
final Element vertexElement = elementBuilder.create();
final int vertexSlot = meshBuilder.addVertexType(vertexElement, mOriginalPoints.length);
// Specify the type and number of indices we need. We'll allocate them later.
meshBuilder.setIndexType(Element.INDEX_16(mRS), mLines.length * 2);
// This will be a line mesh
meshBuilder.setPrimitive(Primitive.LINE);
// Create the Allocation for the vertices
mCubeMesh = meshBuilder.create();
mCubeMesh.setName("CubeMesh");
mPointAlloc = mCubeMesh.createVertexAllocation(vertexSlot);
mPointAlloc.setName("PointBuffer");
// Create the Allocation for the indices
mLineIdxAlloc = mCubeMesh.createIndexAllocation();
// Bind the allocations to the mesh
mCubeMesh.bindVertexAllocation(mPointAlloc, 0);
mCubeMesh.bindIndexAllocation(mLineIdxAlloc);
/*
* put the vertex and index data in their respective buffers
*/
// one float each for x, y and z, and the 4th float will hold rgba
mPointData = new float[mOriginalPoints.length * 3];
for(int i = 0; i < mOriginalPoints.length; i ++) {
mPointData[i*3] = mOriginalPoints[i].x;
mPointData[i*3+1] = mOriginalPoints[i].y;
mPointData[i*3+2] = mOriginalPoints[i].z;
}
mIndexData = new short[mLines.length * 2];
for(int i = 0; i < mLines.length; i++) {
mIndexData[i * 2] = (short)(mLines[i].startPoint);
mIndexData[i * 2 + 1] = (short)(mLines[i].endPoint);
}
/*
* upload the vertex and index data
*/
mPointAlloc.data(mPointData);
mPointAlloc.uploadToBufferObject();
mLineIdxAlloc.data(mIndexData);
mLineIdxAlloc.uploadToBufferObject();
// Time to create the script
ScriptC.Builder sb = new ScriptC.Builder(mRS);
// Specify the name by which to refer to the WorldState object in the
// renderscript.
sb.setType(mStateType, "State", RSID_STATE);
sb.setType(mCubeMesh.getVertexType(0), "Points", RSID_POINTS);
// this crashes when uncommented
//sb.setType(mCubeMesh.getIndexType(), "Lines", RSID_LINES);
// Set the render script that will make use of the objects we defined above
sb.setScript(mResources, R.raw.cube);
sb.setRoot(true);
ScriptC script = sb.create();
script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
script.setTimeZone(TimeZone.getDefault().getID());
script.bindAllocation(mState, RSID_STATE);
script.bindAllocation(mPointAlloc, RSID_POINTS);
script.bindAllocation(mLineIdxAlloc, RSID_LINES);
script.bindAllocation(mPVAlloc.mAlloc, RSID_PROGRAMVERTEX);
return script;
}
@Override
public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
// update our state, then push it to the renderscript
mWorldState.yRotation = (xOffset - 0.5f) * 2 * 180 / (float) Math.PI;
mState.data(mWorldState);
}
/*
* Read the model definition from the resource.
*/
private void readModel() {
String [] p = mResources.getStringArray(R.array.cubepoints);
int numpoints = p.length;
mOriginalPoints = new ThreeDPoint[numpoints];
for (int i = 0; i < numpoints; i++) {
mOriginalPoints[i] = new ThreeDPoint();
String [] coord = p[i].split(" ");
mOriginalPoints[i].x = Float.valueOf(coord[0]);
mOriginalPoints[i].y = Float.valueOf(coord[1]);
mOriginalPoints[i].z = Float.valueOf(coord[2]);
}
String [] l = mResources.getStringArray(R.array.cubelines);
int numlines = l.length;
mLines = new ThreeDLine[numlines];
for (int i = 0; i < numlines; i++) {
mLines[i] = new ThreeDLine();
String [] idx = l[i].split(" ");
mLines[i].startPoint = Integer.valueOf(idx[0]);
mLines[i].endPoint = Integer.valueOf(idx[1]);
}
}
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.livecubes.cube3;
import com.android.livecubes.RenderScriptWallpaper;
public class CubeWallpaper3 extends RenderScriptWallpaper<Cube3RS> {
@Override
protected Cube3RS createScene(int width, int height) {
return new Cube3RS(width, height);
}
}

View File

@@ -1,86 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.livecubes;
import android.content.res.Resources;
import android.renderscript.RenderScript;
import android.renderscript.ScriptC;
public abstract class RenderScriptScene {
protected int mWidth;
protected int mHeight;
protected boolean mPreview;
protected Resources mResources;
protected RenderScript mRS;
protected ScriptC mScript;
public RenderScriptScene(int width, int height) {
mWidth = width;
mHeight = height;
}
public void init(RenderScript rs, Resources res, boolean isPreview) {
mRS = rs;
mResources = res;
mPreview = isPreview;
mScript = createScript();
}
public boolean isPreview() {
return mPreview;
}
public int getWidth() {
return mWidth;
}
public int getHeight() {
return mHeight;
}
public Resources getResources() {
return mResources;
}
public RenderScript getRS() {
return mRS;
}
public ScriptC getScript() {
return mScript;
}
protected abstract ScriptC createScript();
public void stop() {
mRS.contextBindRootScript(null);
}
public void start() {
mRS.contextBindRootScript(mScript);
}
public void resize(int width, int height) {
mWidth = width;
mHeight = height;
}
@SuppressWarnings({"UnusedDeclaration"})
public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
}
}

View File

@@ -1,110 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.livecubes;
import android.service.wallpaper.WallpaperService;
import android.renderscript.RenderScript;
import android.view.SurfaceHolder;
import android.view.Surface;
public abstract class RenderScriptWallpaper<T extends RenderScriptScene> extends WallpaperService {
public Engine onCreateEngine() {
return new RenderScriptEngine();
}
protected abstract T createScene(int width, int height);
private class RenderScriptEngine extends Engine {
private RenderScript mRs;
private T mRenderer;
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
setTouchEventsEnabled(false);
surfaceHolder.setSizeFromLayout();
}
@Override
public void onDestroy() {
super.onDestroy();
destroyRenderer();
}
private void destroyRenderer() {
if (mRenderer != null) {
mRenderer.stop();
mRenderer = null;
}
if (mRs != null) {
mRs.destroy();
mRs = null;
}
}
@Override
public void onVisibilityChanged(boolean visible) {
super.onVisibilityChanged(visible);
if (mRenderer != null) {
if (visible) {
mRenderer.start();
} else {
mRenderer.stop();
}
}
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
if (mRs != null) {
mRs.contextSetSurface(width, height, holder.getSurface());
}
if (mRenderer == null) {
mRenderer = createScene(width, height);
mRenderer.init(mRs, getResources(), isPreview());
mRenderer.start();
} else {
mRenderer.resize(width, height);
}
}
@Override
public void onOffsetsChanged(float xOffset, float yOffset,
float xStep, float yStep, int xPixels, int yPixels) {
mRenderer.setOffset(xOffset, yOffset, xPixels, yPixels);
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
Surface surface = null;
while (surface == null) {
surface = holder.getSurface();
}
mRs = new RenderScript(false, false);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
destroyRenderer();
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.livecubes.cube1;
package com.example.android.livecubes.cube1;
import android.graphics.Canvas;
import android.graphics.Paint;

View File

@@ -14,9 +14,7 @@
* limitations under the License.
*/
package com.android.livecubes.cube2;
import com.android.livecubes.R;
package com.example.android.livecubes.cube2;
import android.content.SharedPreferences;
import android.graphics.Canvas;
@@ -25,7 +23,6 @@ import android.graphics.Rect;
import android.os.Handler;
import android.os.SystemClock;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;

View File

@@ -14,15 +14,15 @@
* the License.
*/
package com.android.livecubes.cube2;
package com.example.android.livecubes.cube2;
import com.android.livecubes.R;
import com.example.android.livecubes.R;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.service.wallpaper.WallpaperSettingsActivity;
import android.preference.PreferenceActivity;
public class CubeWallpaper2Settings extends WallpaperSettingsActivity
public class CubeWallpaper2Settings extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
@@ -49,6 +49,5 @@ public class CubeWallpaper2Settings extends WallpaperSettingsActivity
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
//(new BackupManager(this)).dataChanged();
}
}