summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--carousel/java/com/android/ex/carousel/CarouselRS.java73
-rw-r--r--carousel/java/com/android/ex/carousel/CarouselView.java52
-rw-r--r--carousel/java/com/android/ex/carousel/carousel.rs113
-rw-r--r--carousel/test/res/values/strings.xml1
-rw-r--r--carousel/test/src/com/android/carouseltest/CarouselTestActivity.java33
-rw-r--r--carousel/test/src/com/android/carouseltest/MusicDemoActivity.java2
6 files changed, 237 insertions, 37 deletions
diff --git a/carousel/java/com/android/ex/carousel/CarouselRS.java b/carousel/java/com/android/ex/carousel/CarouselRS.java
index f9fbadf..4e2c11e 100644
--- a/carousel/java/com/android/ex/carousel/CarouselRS.java
+++ b/carousel/java/com/android/ex/carousel/CarouselRS.java
@@ -62,15 +62,23 @@ public class CarouselRS {
private Resources mRes;
private ScriptC_carousel mScript;
private ScriptField_Card mCards;
- private Sampler mSampler;
+ private ScriptField_FragmentShaderConstants_s mFSConst;
private ProgramStore mProgramStore;
- private ProgramFragment mFragmentProgram;
+ private ProgramFragment mSingleTextureFragmentProgram;
+ private ProgramFragment mMultiTextureFragmentProgram;
private ProgramVertex mVertexProgram;
private ProgramRaster mRasterProgram;
private CarouselCallback mCallback;
private float[] mEyePoint = new float[3];
private float[] mAtPoint = new float[3];
private float[] mUp = new float[3];
+ private static final String mShaderString = new String(
+ "varying vec4 varTex0;" +
+ "void main() {" +
+ "vec2 t0 = varTex0.xy;" +
+ "vec4 col = texture2D(UNI_Tex0, t0);" +
+ "vec4 col2 = texture2D(UNI_Tex1, t0);" +
+ "gl_FragColor = mix(col, col2, UNI_fadeAmount);}");
public static interface CarouselCallback {
/**
@@ -277,24 +285,41 @@ public class CarouselRS {
}
private void initFragmentProgram() {
- Sampler.Builder sampleBuilder = new Sampler.Builder(mRS);
- sampleBuilder.setMin(Value.LINEAR);
- sampleBuilder.setMag(LINEAR);
- sampleBuilder.setWrapS(CLAMP);
- sampleBuilder.setWrapT(CLAMP);
- mSampler = sampleBuilder.create();
- ProgramFragment.Builder fragmentBuilder = new ProgramFragment.Builder(mRS);
- fragmentBuilder.setTexture(ProgramFragment.Builder.EnvMode.DECAL,
- ProgramFragment.Builder.Format.RGBA, 0);
- mFragmentProgram = fragmentBuilder.create();
- mFragmentProgram.bindSampler(mSampler, 0);
- mScript.set_fragmentProgram(mFragmentProgram);
+ boolean old = false;
+ if (old) {
+ ProgramFragment.Builder fragmentBuilder = new ProgramFragment.Builder(mRS);
+ fragmentBuilder.setTexture(ProgramFragment.Builder.EnvMode.DECAL,
+ ProgramFragment.Builder.Format.RGBA, 0);
+ mSingleTextureFragmentProgram = fragmentBuilder.create();
+ mSingleTextureFragmentProgram.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0);
+ } else {
+ mScript.set_linearClamp(Sampler.CLAMP_LINEAR(mRS));
+ //mScript.set_linearWrap(Sampler.CLAMP_NEAREST(mRS));
+ //mScript.set_mipLinearWrap(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS));
+
+ mFSConst = new ScriptField_FragmentShaderConstants_s(mRS, 1);
+ mScript.bind_shaderConstants(mFSConst);
+
+ ProgramFragment.ShaderBuilder pfbCustom = new ProgramFragment.ShaderBuilder(mRS);
+ // Specify the resource that contains the shader string
+ pfbCustom.setShader(mShaderString);
+ // Tell the builder how many textures we have
+ pfbCustom.setTextureCount(2);
+ // Define the constant input layout
+ pfbCustom.addConstant(mFSConst.getAllocation().getType());
+ mMultiTextureFragmentProgram = pfbCustom.create();
+ // Bind the source of constant data
+ mMultiTextureFragmentProgram.bindConstants(mFSConst.getAllocation(), 0);
+ mMultiTextureFragmentProgram.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0);
+ mMultiTextureFragmentProgram.bindSampler(Sampler.CLAMP_LINEAR(mRS), 1);
+ }
+ mScript.set_fragmentProgram(mMultiTextureFragmentProgram);
}
private void initProgramStore() {
ProgramStore.Builder programStoreBuilder = new ProgramStore.Builder(mRS, null, null);
programStoreBuilder.setDepthFunc(ProgramStore.DepthFunc.LESS);
- programStoreBuilder.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
+ programStoreBuilder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE,
ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
programStoreBuilder.setDitherEnable(true);
programStoreBuilder.setDepthMask(true);
@@ -480,6 +505,16 @@ public class CarouselRS {
mScript.set_detailLineTexture(texture);
}
+ public void setDetailLoadingTexture(Bitmap bitmap) {
+ Allocation texture = null;
+ if (bitmap != null) {
+ texture = Allocation.createFromBitmap(mRS, bitmap,
+ elementForBitmap(bitmap, Bitmap.Config.ARGB_4444), MIPMAP);
+ texture.uploadToTexture(0);
+ }
+ mScript.set_detailLoadingTexture(texture);
+ }
+
public void pauseRendering() {
// Used to update multiple states at once w/o redrawing for each.
mRS.contextBindRootScript(null);
@@ -513,6 +548,14 @@ public class CarouselRS {
mScript.invoke_requestFirstCardPosition();
}
+ public void setRezInCardCount(float alpha) {
+ mScript.set_rezInCardCount(alpha);
+ }
+
+ public void setFadeInDuration(long t) {
+ mScript.set_fadeInDuration((int)t); // TODO: Remove cast when RS supports exporting longs
+ }
+
private Element elementForBitmap(Bitmap bitmap, Bitmap.Config defaultConfig) {
Bitmap.Config config = bitmap.getConfig();
if (config == null) {
diff --git a/carousel/java/com/android/ex/carousel/CarouselView.java b/carousel/java/com/android/ex/carousel/CarouselView.java
index 5afab7b..2680162 100644
--- a/carousel/java/com/android/ex/carousel/CarouselView.java
+++ b/carousel/java/com/android/ex/carousel/CarouselView.java
@@ -82,6 +82,10 @@ public abstract class CarouselView extends RSSurfaceView {
private float mUp[] = { 0.0f, 1.0f, 0.0f };
private Float4 mBackgroundColor = new Float4(0.0f, 0.0f, 0.0f, 1.0f);
private CarouselCallback mCarouselCallback;
+ private float mRezInCardCount = 0.0f;
+ private long mFadeInDuration = 250L;
+ private Bitmap mDetailLoadingBitmap = Bitmap.createBitmap(
+ new int[] {0}, 0, 1, 1, 1, Bitmap.Config.ARGB_4444);
public static class Info {
public Info(int _resId) { resId = _resId; }
@@ -140,6 +144,9 @@ public abstract class CarouselView extends RSSurfaceView {
setFrictionCoefficient(mFrictionCoefficient);
setDragFactor(mDragFactor);
setLookAt(mEye, mAt, mUp);
+ setRezInCardCount(mRezInCardCount);
+ setFadeInDuration(mFadeInDuration);
+ setDetailLoadingBitmap(mDetailLoadingBitmap);
}
/**
@@ -334,6 +341,7 @@ public abstract class CarouselView extends RSSurfaceView {
mRenderScript.setBackgroundColor(mBackgroundColor);
}
}
+
/**
* Can be used to optionally set the background to a bitmap. When set to something other than
* null, this overrides {@link CarouselView#setBackgroundColor(Float4)}.
@@ -348,6 +356,19 @@ public abstract class CarouselView extends RSSurfaceView {
}
/**
+ * Can be used to optionally set a "loading" detail bitmap. Typically, this is just a black
+ * texture with alpha = 0 to allow details to slowly fade in.
+ *
+ * @param bitmap
+ */
+ public void setDetailLoadingBitmap(Bitmap bitmap) {
+ mDetailLoadingBitmap = bitmap;
+ if (mRenderScript != null) {
+ mRenderScript.setDetailLoadingTexture(bitmap);
+ }
+ }
+
+ /**
* This texture is used to draw a line from the card alongside the texture detail. The line
* will be as wide as the texture. It can be used to give the line glow effects as well as
* allowing other blending effects. It is typically one dimensional, e.g. 3x1.
@@ -465,6 +486,37 @@ public abstract class CarouselView extends RSSurfaceView {
}
}
+ /**
+ * This sets the number of cards in the distance that will be shown "rezzing in".
+ * These alpha values will be faded in from the background to the foreground over
+ * 'n' cards. A floating point value is used to allow subtly changing the rezzing in
+ * position.
+ *
+ * @param n the number of cards to rez in.
+ */
+ public void setRezInCardCount(float n) {
+ mRezInCardCount = n;
+ if (mRenderScript != null) {
+ mRenderScript.setRezInCardCount(n);
+ }
+ }
+
+ /**
+ * This sets the duration (in ms) that a card takes to fade in when loaded via a call
+ * to {@link CarouselView#setTextureForItem(int, Bitmap)}. The timer starts the
+ * moment {@link CarouselView#setTextureForItem(int, Bitmap)} is called and continues
+ * until all of the cards have faded in. Note: using large values will extend the
+ * animation until all cards have faded in.
+ *
+ * @param t
+ */
+ public void setFadeInDuration(long t) {
+ mFadeInDuration = t;
+ if (mRenderScript != null) {
+ mRenderScript.setFadeInDuration(t);
+ }
+ }
+
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
diff --git a/carousel/java/com/android/ex/carousel/carousel.rs b/carousel/java/com/android/ex/carousel/carousel.rs
index 94433e4..11deb08 100644
--- a/carousel/java/com/android/ex/carousel/carousel.rs
+++ b/carousel/java/com/android/ex/carousel/carousel.rs
@@ -30,6 +30,9 @@ typedef struct __attribute__((aligned(4))) Card {
int detailTextureState; // whether or not the detail for the card is loaded.
int geometryState; // whether or not geometry is loaded
int visible; // not bool because of packing bug?
+ // TODO: Change when int64_t is supported. This will break after ~40 days of uptime.
+ unsigned int textureTimeStamp; // time when this texture was last updated, in seconds
+ unsigned int detailTextureTimeStamp; // time when this texture was last updated, in seconds
} Card_t;
typedef struct Ray_s {
@@ -47,6 +50,10 @@ typedef struct PerspectiveCamera_s {
float far;
} PerspectiveCamera;
+typedef struct FragmentShaderConstants_s {
+ float fadeAmount;
+} FragmentShaderConstants;
+
// Request states. Used for loading 3D object properties from the Java client.
// Typical properties: texture, geometry and matrices.
enum {
@@ -93,6 +100,8 @@ float cardRotation; // rotation of card in XY plane relative to Z=1
float swaySensitivity; // how much to rotate cards in relation to the rotation velocity
float frictionCoeff; // how much to slow down the carousel over time
float dragFactor; // a scale factor for how sensitive the carousel is to user dragging
+int fadeInDuration; // amount of time (in ms) for smoothly switching out textures
+float rezInCardCount; // this controls how rapidly distant card textures will be rez-ed in
rs_program_store programStore;
rs_program_fragment fragmentProgram;
rs_program_vertex vertexProgram;
@@ -101,17 +110,22 @@ rs_allocation defaultTexture; // shown when no other texture is assigned
rs_allocation loadingTexture; // progress texture (shown when app is fetching the texture)
rs_allocation backgroundTexture; // drawn behind everything, if set
rs_allocation detailLineTexture; // used to draw detail line (as a quad, of course)
+rs_allocation detailLoadingTexture; // used when detail texture is loading
rs_mesh defaultGeometry; // shown when no geometry is loaded
rs_mesh loadingGeometry; // shown when geometry is loading
rs_matrix4x4 projectionMatrix;
rs_matrix4x4 modelviewMatrix;
+FragmentShaderConstants* shaderConstants;
+rs_sampler linearClamp;
#pragma rs export_var(radius, cards, slotCount, visibleSlotCount, cardRotation, backgroundColor)
#pragma rs export_var(swaySensitivity, frictionCoeff, dragFactor)
#pragma rs export_var(visibleDetailCount, drawDetailBelowCard, drawRuler)
#pragma rs export_var(programStore, fragmentProgram, vertexProgram, rasterProgram)
-#pragma rs export_var(detailLineTexture, backgroundTexture)
+#pragma rs export_var(detailLineTexture, detailLoadingTexture, backgroundTexture)
+#pragma rs export_var(linearClamp, shaderConstants)
#pragma rs export_var(startAngle, defaultTexture, loadingTexture, defaultGeometry, loadingGeometry)
+#pragma rs export_var(fadeInDuration, rezInCardCount)
#pragma rs export_func(createCards, lookAt, doStart, doStop, doMotion, doSelection)
#pragma rs export_func(setTexture, setGeometry, setDetailTexture, debugCamera, debugPicking)
#pragma rs export_func(requestFirstCardPosition)
@@ -173,6 +187,8 @@ void init() {
backgroundColor = (float4) { 0.0f, 0.0f, 0.0f, 1.0f };
cardAllocationValid = false;
cardCount = 0;
+ fadeInDuration = 250;
+ rezInCardCount = 0.0f; // alpha will ramp to 1.0f over this many cards (0.0f means disabled)
}
static void updateAllocationVars()
@@ -191,6 +207,14 @@ void createCards(int n)
updateAllocationVars();
}
+// Computes an alpha value for a card using elapsed time and constant fadeInDuration
+float getAnimatedAlpha(int64_t startTime, int64_t currentTime)
+{
+ double timeElapsed = (double) (currentTime - startTime); // in ms
+ double alpha = (double) timeElapsed / fadeInDuration;
+ return min(1.0f, (float) alpha);
+}
+
// Return angle for position p. Typically p will be an integer position, but can be fractional.
static float cardPosition(float p)
{
@@ -273,6 +297,7 @@ void setTexture(int n, rs_allocation texture)
if (n < 0 || n >= cardCount) return;
rsSetObject(&cards[n].texture, texture);
cards[n].textureState = (texture.p != 0) ? STATE_LOADED : STATE_INVALID;
+ cards[n].textureTimeStamp = rsUptimeMillis();
}
void setDetailTexture(int n, float offx, float offy, rs_allocation texture)
@@ -282,6 +307,7 @@ void setDetailTexture(int n, float offx, float offy, rs_allocation texture)
cards[n].detailTextureOffset.x = offx;
cards[n].detailTextureOffset.y = offy;
cards[n].detailTextureState = (texture.p != 0) ? STATE_LOADED : STATE_INVALID;
+ cards[n].detailTextureTimeStamp = rsUptimeMillis();
}
void setGeometry(int n, rs_mesh geometry)
@@ -349,17 +375,46 @@ static void getMatrixForCard(rs_matrix4x4* matrix, int i, bool enableSway)
// TODO: apply custom matrix for cards[i].geometry
}
-static void drawCards()
+/*
+ * Draws cards around the Carousel.
+ * Returns true if we're still animating any property of the cards (e.g. fades).
+ */
+static bool drawCards(int64_t currentTime)
{
- for (int i = 0; i < cardCount; i++) {
+ const float wedgeAngle = 2.0f * M_PI / slotCount;
+ const float endAngle = startAngle + visibleSlotCount * wedgeAngle;
+ bool stillAnimating = false;
+ for (int i = cardCount-1; i >= 0; i--) {
if (cards[i].visible) {
- // Bind texture
+ // If this card was recently loaded, this will be < 1.0f until the animation completes
+ float animatedAlpha = getAnimatedAlpha(cards[i].textureTimeStamp, currentTime);
+ if (animatedAlpha < 1.0f) {
+ stillAnimating = true;
+ }
+
+ // Compute fade out for cards in the distance
+ float positionAlpha;
+ if (rezInCardCount > 0.0f) {
+ positionAlpha = (endAngle - cardPosition(i)) / wedgeAngle;
+ positionAlpha = min(1.0f, positionAlpha / rezInCardCount);
+ } else {
+ positionAlpha = 1.0f;
+ }
+
+ // Set alpha for blending between the textures
+ shaderConstants->fadeAmount = min(1.0f, animatedAlpha * positionAlpha);
+ rsAllocationMarkDirty(rsGetAllocation(shaderConstants));
+
+ // Bind place-holder texture
+ rsgBindSampler(fragmentProgram, 0, linearClamp);
+ rsgBindTexture(fragmentProgram, 0, loadingTexture);
+
+ // Bind artwork texture, if loaded
+ rsgBindSampler(fragmentProgram, 1, linearClamp);
if (cards[i].textureState == STATE_LOADED) {
- rsgBindTexture(fragmentProgram, 0, cards[i].texture);
- } else if (cards[i].textureState == STATE_LOADING) {
- rsgBindTexture(fragmentProgram, 0, loadingTexture);
+ rsgBindTexture(fragmentProgram, 1, cards[i].texture);
} else {
- rsgBindTexture(fragmentProgram, 0, defaultTexture);
+ rsgBindTexture(fragmentProgram, 1, loadingTexture);
}
// Draw geometry
@@ -382,17 +437,21 @@ static void drawCards()
}
}
}
+ return stillAnimating;
}
/*
* Draws a screen-aligned card with the exact dimensions from the detail texture.
* This is used to display information about the object being displayed above the geomertry.
+ * Returns true if we're still animating any property of the cards (e.g. fades).
*/
-static void drawDetails()
+static bool drawDetails(int64_t currentTime)
{
const float width = rsgGetWidth();
const float height = rsgGetHeight();
+ bool stillAnimating = false;
+
// We'll be drawing in screen space, sampled on pixel centers
rs_matrix4x4 projection, model;
rsMatrixLoadOrtho(&projection, 0.0f, width, 0.0f, height, 0.0f, 1.0f);
@@ -404,6 +463,11 @@ static void drawDetails()
const float yPadding = 5.0f; // draw line this far (in pixels) away from top and geometry
int drawn = 0; // number of details drawn
+
+ // This can be done once...
+ rsgBindSampler(fragmentProgram, 0, linearClamp);
+ rsgBindTexture(fragmentProgram, 0, detailLoadingTexture);
+
for (int i = 0; i < cardCount && drawn < visibleDetailCount; i++) {
if (cards[i].visible) {
if (cards[i].detailTextureState == STATE_LOADED && cards[i].detailTexture.p != 0) {
@@ -415,8 +479,6 @@ static void drawDetails()
rs_matrix4x4 matrix;
rsMatrixLoadMultiply(&matrix, &projectionMatrix, &model);
- rsDebug("******", 0); // Strategic printf!!! TODO: Remove when LLMV fixed
-
float4 screenCoord = rsMatrixMultiply(&matrix,
cardVertices[drawDetailBelowCard ? 0 : 3]);
if (screenCoord.w == 0.0f) {
@@ -425,6 +487,17 @@ static void drawDetails()
continue;
}
+ // Compute alpha for gradually fading in details. Applied to both line and
+ // detail texture. TODO: use a separate background texture for line.
+ float animatedAlpha = getAnimatedAlpha(cards[i].detailTextureTimeStamp, currentTime);
+ if (animatedAlpha < 1.0f) {
+ stillAnimating = true;
+ }
+
+ // Set alpha for blending between the textures
+ shaderConstants->fadeAmount = min(1.0f, animatedAlpha);
+ rsAllocationMarkDirty(rsGetAllocation(shaderConstants));
+
// Convert projection from normalized coordinates to pixel coordinates.
// This is probably cheaper than pre-multiplying the above with another matrix.
screenCoord *= 1.0f / screenCoord.w;
@@ -439,10 +512,11 @@ static void drawDetails()
// Draw line from upper left card corner to the top of the screen
if (drawRuler) {
- rsgBindTexture(fragmentProgram, 0, detailLineTexture);
const float halfWidth = lineWidth * 0.5f;
const float rulerTop = drawDetailBelowCard ? screenCoord.y : height;
const float rulerBottom = drawDetailBelowCard ? 0 : screenCoord.y;
+ rsgBindSampler(fragmentProgram, 1, linearClamp);
+ rsgBindTexture(fragmentProgram, 1, detailLineTexture);
rsgDrawQuad(
screenCoord.x - halfWidth, rulerBottom + yPadding, 0,
screenCoord.x + halfWidth, rulerBottom + yPadding, 0,
@@ -451,12 +525,13 @@ static void drawDetails()
}
// Draw the detail texture next to it using the offsets provided.
- rsgBindTexture(fragmentProgram, 0, cards[i].detailTexture);
const float textureWidth = rsAllocationGetDimX(cards[i].detailTexture);
const float textureHeight = rsAllocationGetDimY(cards[i].detailTexture);
const float offx = cards[i].detailTextureOffset.x;
const float offy = -cards[i].detailTextureOffset.y;
const float textureTop = drawDetailBelowCard ? screenCoord.y : height;
+ rsgBindSampler(fragmentProgram, 1, linearClamp);
+ rsgBindTexture(fragmentProgram, 1, cards[i].detailTexture);
rsgDrawQuad(
screenCoord.x + offx, textureTop + offy - textureHeight, 0,
screenCoord.x + offx + textureWidth, textureTop + offy - textureHeight, 0,
@@ -467,6 +542,7 @@ static void drawDetails()
}
}
}
+ return stillAnimating;
}
static void drawBackground()
@@ -479,6 +555,7 @@ static void drawBackground()
rsMatrixLoadIdentity(&model);
rsgProgramVertexLoadModelMatrix(&model);
rsgBindTexture(fragmentProgram, 0, backgroundTexture);
+ rsgBindTexture(fragmentProgram, 1, backgroundTexture); // TODO: background blending
float z = -0.9999f;
rsgDrawQuad(
cardVertices[0].x, cardVertices[0].y, z,
@@ -862,7 +939,7 @@ static int cullCards()
// Request texture/geometry for items that have come into view
// or doesn't have a texture yet.
-static void updateCardResources()
+static void updateCardResources(int64_t currentTime)
{
for (int i = 0; i < cardCount; i++) {
int data[1];
@@ -904,6 +981,7 @@ static void updateCardResources()
bool enqueued = rsSendToClient(CMD_INVALIDATE_TEXTURE, data, sizeof(data));
if (enqueued) {
cards[i].textureState = STATE_INVALID;
+ cards[i].textureTimeStamp = currentTime;
} else {
if (debugTextureLoading) rsDebug("Couldn't send CMD_INVALIDATE_TEXTURE", 0);
}
@@ -914,6 +992,7 @@ static void updateCardResources()
bool enqueued = rsSendToClient(CMD_INVALIDATE_DETAIL_TEXTURE, data, sizeof(data));
if (enqueued) {
cards[i].detailTextureState = STATE_INVALID;
+ cards[i].detailTextureTimeStamp = currentTime;
} else {
if (debugTextureLoading) rsDebug("Can't send CMD_INVALIDATE_DETAIL_TEXTURE", 0);
}
@@ -986,10 +1065,10 @@ int root() {
cullCards();
- updateCardResources();
+ updateCardResources(currentTime);
- drawCards();
- drawDetails();
+ stillAnimating |= drawCards(currentTime);
+ drawDetails(currentTime);
if (debugPicking) {
renderWithRays();
diff --git a/carousel/test/res/values/strings.xml b/carousel/test/res/values/strings.xml
index a64a04c..a089aac 100644
--- a/carousel/test/res/values/strings.xml
+++ b/carousel/test/res/values/strings.xml
@@ -21,6 +21,7 @@
<!-- General --><skip />
<string name="music_demo_activity_label">MusicCarousel2</string>
<string name="carousel_test_activity_label">CarouselTest2</string>
+ <string name="carousel_test_activity_description">An application to show the use of Carousel</string>
<string name="task_switcher_activity_label">TaskSwitcher2</string>
<string name="recent_tasks_title">Recent Applications</string>
diff --git a/carousel/test/src/com/android/carouseltest/CarouselTestActivity.java b/carousel/test/src/com/android/carouseltest/CarouselTestActivity.java
index 12b729b..0c890c2 100644
--- a/carousel/test/src/com/android/carouseltest/CarouselTestActivity.java
+++ b/carousel/test/src/com/android/carouseltest/CarouselTestActivity.java
@@ -31,16 +31,18 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
+import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
+import android.view.WindowManager;
public class CarouselTestActivity extends Activity {
private static final String TAG = "CarouselTestActivity";
private static final int CARD_SLOTS = 56;
private static final int TOTAL_CARDS = 1000;
- private static final int TEXTURE_HEIGHT = 512;
- private static final int TEXTURE_WIDTH = 512;
+ private static final int TEXTURE_HEIGHT = 256;
+ private static final int TEXTURE_WIDTH = 256;
private static final int SLOTS_VISIBLE = 7;
protected static final boolean DBG = false;
@@ -77,10 +79,12 @@ public class CarouselTestActivity extends Activity {
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawARGB(0, 0, 0, 0);
+ mPaint.setColor(0x40808080);
+ canvas.drawRect(2, 2, TEXTURE_WIDTH-2, TEXTURE_HEIGHT-2, mPaint);
mPaint.setTextSize(100.0f);
mPaint.setAntiAlias(true);
mPaint.setColor(0xffffffff);
- canvas.drawText(""+n, 0, TEXTURE_HEIGHT-10, mPaint);
+ canvas.drawText("" + n, 2, TEXTURE_HEIGHT-10, mPaint);
canvas.drawBitmap(mGlossyOverlay, null,
new Rect(PIXEL_BORDER, PIXEL_BORDER,
TEXTURE_WIDTH - PIXEL_BORDER, TEXTURE_HEIGHT - PIXEL_BORDER), mPaint);
@@ -92,7 +96,7 @@ public class CarouselTestActivity extends Activity {
Bitmap bitmap = Bitmap.createBitmap(DETAIL_TEXTURE_WIDTH, DETAIL_TEXTURE_HEIGHT,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
- canvas.drawARGB(200, 200, 200, 255);
+ canvas.drawARGB(32, 10, 10, 10);
mPaint.setTextSize(15.0f);
mPaint.setAntiAlias(true);
canvas.drawText("Detail text for card " + n, 0, DETAIL_TEXTURE_HEIGHT/2, mPaint);
@@ -101,10 +105,16 @@ public class CarouselTestActivity extends Activity {
};
@Override
+ public CharSequence onCreateDescription() {
+ return getText(R.string.carousel_test_activity_description);
+ }
+
+ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mView = new MyCarouselView(this);
+ mView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
mPaint.setColor(0xffffffff);
final Resources res = getResources();
@@ -117,9 +127,22 @@ public class CarouselTestActivity extends Activity {
mBorder = BitmapFactory.decodeResource(res, R.drawable.border);
mView.setDefaultBitmap(mBorder);
mView.setLoadingBitmap(mBorder);
- mView.setBackgroundColor(0.25f, 0.25f, 0.5f, 1.0f);
+ mView.setBackgroundColor(0.25f, 0.25f, 0.5f, 0.5f);
+ mView.setRezInCardCount(3.0f);
+ mView.setFadeInDuration(250);
mGlossyOverlay = BitmapFactory.decodeResource(res, R.drawable.glossy_overlay);
+
+ /*
+ mView.setBackgroundColor(0x80ffffff);
+ int flags = WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
+ WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
+ mView.getWidth(), mView.getHeight(),
+ WindowManager.LayoutParams.TYPE_APPLICATION,
+ flags, PixelFormat.TRANSLUCENT);
+ getWindow().setAttributes(lp);
+ */
+
setContentView(mView);
}
diff --git a/carousel/test/src/com/android/carouseltest/MusicDemoActivity.java b/carousel/test/src/com/android/carouseltest/MusicDemoActivity.java
index 661cd9b..915fd55 100644
--- a/carousel/test/src/com/android/carouseltest/MusicDemoActivity.java
+++ b/carousel/test/src/com/android/carouseltest/MusicDemoActivity.java
@@ -94,6 +94,8 @@ public class MusicDemoActivity extends Activity {
mView.setLoadingBitmap(BitmapFactory.decodeResource(res, R.drawable.blank_album));
mView.setBackgroundBitmap(BitmapFactory.decodeResource(res, R.drawable.background));
mView.setDefaultGeometry(mView.loadGeometry(CD_GEOMETRY));
+ mView.setFadeInDuration(250);
+ mView.setRezInCardCount(3.0f);
}
@Override