Skip to content

Commit

Permalink
Updated the demos to store the IDs of the resources rather than putti…
Browse files Browse the repository at this point in the history
…ng all the Bitmaps into memory. Runs fast enough on the phone so seems like they don't need to be taking up memory.
  • Loading branch information
kevinmcdonagh committed Feb 28, 2010
1 parent 2df0442 commit 409ca0d
Show file tree
Hide file tree
Showing 22 changed files with 53 additions and 94 deletions.
Binary file modified Livewallpaper/switch_animation/res/drawable/front_day001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/front_day002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/front_day003.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/front_day004.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/left_day001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/left_day002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/left_day003.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/left_day004.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/right_day001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/right_day002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/right_day003.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_animation/res/drawable/right_day004.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Livewallpaper/switch_animation/res/xml/wallpaper.xml
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The attributes in this XML file provide configuration information -->

<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"/>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="@drawable/ic_launcher_wallpaper"
android:description="@string/title"/>
Expand Up @@ -36,20 +36,15 @@ class OutRunEngine extends Engine {

OutRunEngine() {
Resources res = getResources();
int id =0;

for (int i = 0; i< FRONT_RES; i++) {
id = res.getIdentifier("front_day00" + (i + 1), "drawable", "com.novoda.wallpaper");
mFrontPics[i] = BitmapFactory.decodeResource(res, id);
mFrontPicIds[i] = res.getIdentifier("front_day00" + (i + 1), "drawable", "com.novoda.wallpaper");
}
id=0;
for (int i = 0; i< LEFT_RES; i++) {
id = res.getIdentifier("left_day00" + (i + 1), "drawable", "com.novoda.wallpaper");
mLeftPics[i] = BitmapFactory.decodeResource(res, id);
mLeftPicIds[i] = res.getIdentifier("left_day00" + (i + 1), "drawable", "com.novoda.wallpaper");
}
id=0;
for (int i = 0; i< RIGHT_RES; i++) {
id = res.getIdentifier("right_day00" + (i + 1), "drawable", "com.novoda.wallpaper");
mRightPics[i] = BitmapFactory.decodeResource(res, id);
mRightPicIds[i] = res.getIdentifier("right_day00" + (i + 1), "drawable", "com.novoda.wallpaper");
}
}

Expand Down Expand Up @@ -78,13 +73,6 @@ public void onVisibilityChanged(boolean visible) {
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
float w = mFrontPics[0].getWidth();
float h = mFrontPics[0].getHeight();
float s = width / (float)w;
mMatrix.reset();
mMatrix.setScale(s, s);

mPosY = (height - (h * s)) / 2f;
drawFrame();
}

Expand Down Expand Up @@ -178,13 +166,13 @@ private void drawCar(Canvas c) {

if(takingACorner){
if(currentDirection == DRIVING_RIGHT){
drawAnim(c, mRightPics);
drawAnim(c, mRightPicIds);
}else{
drawAnim(c, mLeftPics);
drawAnim(c, mLeftPicIds);
}
}else{
if(!mDragEventInProgress){
drawAnim(c, mFrontPics);
drawAnim(c, mFrontPicIds);
}else{
/*
* Uncomment this to respond
Expand All @@ -200,8 +188,8 @@ private void drawCar(Canvas c) {
}
}

void drawAnim(Canvas c, Bitmap[] pics) {
c.drawBitmap(pics[picIdx], mMatrix, mPaint);
void drawAnim(Canvas c, int[] pics) {
c.drawBitmap(BitmapFactory.decodeResource(getResources(), pics[picIdx]), 0, 100, null);
++picIdx;
if (picIdx == FRONT_RES) picIdx = 0;
}
Expand All @@ -223,9 +211,9 @@ void drawAnim(Canvas c, Bitmap[] pics) {
private static final int FRONT_RES = 4;
private static final int LEFT_RES = 4;
private static final int RIGHT_RES = 4;
private final Bitmap[] mFrontPics = new Bitmap[FRONT_RES];
private final Bitmap[] mRightPics = new Bitmap[RIGHT_RES];
private final Bitmap[] mLeftPics = new Bitmap[LEFT_RES];
private final int[] mFrontPicIds = new int[FRONT_RES];
private final int[] mRightPicIds = new int[RIGHT_RES];
private final int[] mLeftPicIds = new int[LEFT_RES];

private final Runnable mDrawWallpaper = new Runnable() {
public void run() {
Expand Down
Binary file modified Livewallpaper/switch_leftright/res/drawable/day_front.png 100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_leftright/res/drawable/day_left.png 100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Livewallpaper/switch_leftright/res/drawable/day_right.png 100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion Livewallpaper/switch_leftright/res/xml/wallpaper.xml
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The attributes in this XML file provide configuration information -->

<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"/>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="@drawable/ic_launcher_wallpaper"
android:description="@string/title"/>
Expand Up @@ -3,6 +3,7 @@
import java.util.Timer;
import java.util.TimerTask;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
Expand Down Expand Up @@ -37,71 +38,11 @@ public Engine onCreateEngine() {

class OutRunEngine extends Engine {

private final Paint mPaint = new Paint();
private float mOffset;
private float mTouchX = -1;
private float mTouchY = -1;
private long mStartTime;
private float mCenterX;
private float mCenterY;

private boolean mDrivingForward = true;
private boolean mTurningLeft = false;
private boolean mTurningRight = false;
private boolean mDragEventAnimStarted = false;

private Bitmap carRightBitmap;
private Bitmap carLeftBitmap;
private Bitmap carFrontBitmap;
private Bitmap slidePic;
private boolean duringSlide = false;

private boolean mDragEventInProgress = false;
private float mDragEventStartX = 0;

private final Runnable mDrawWallpaper = new Runnable() {
public void run() {
drawFrame();
}
};
private boolean mVisible;
private float xLastOffset;
private boolean takingACorner = false;


OutRunEngine() {

mStartTime = SystemClock.elapsedRealtime();

java.io.InputStream is;
is = getResources().openRawResource(R.drawable.day_front);
BitmapFactory.Options opts = new BitmapFactory.Options();
Bitmap bm;

opts.inJustDecodeBounds = true;
bm = BitmapFactory.decodeStream(is, null, opts);
opts.inJustDecodeBounds = false; // this will request the bm
bm = BitmapFactory.decodeStream(is, null, opts);
carFrontBitmap = bm;

is = getResources().openRawResource(R.drawable.day_right);
opts = new BitmapFactory.Options();

opts.inJustDecodeBounds = true;
bm = BitmapFactory.decodeStream(is, null, opts);
opts.inJustDecodeBounds = false; // this will request the bm
bm = BitmapFactory.decodeStream(is, null, opts);
carRightBitmap = bm;

is = getResources().openRawResource(R.drawable.day_left);
opts = new BitmapFactory.Options();

opts.inJustDecodeBounds = true;
bm = BitmapFactory.decodeStream(is, null, opts);
opts.inJustDecodeBounds = false; // this will request the bm
bm = BitmapFactory.decodeStream(is, null, opts);
carLeftBitmap = bm;

OutRunEngine() {
Resources res = getResources();
carFrontBitmap = res.getIdentifier("day_front", "drawable", "com.novoda.wallpaper");
carRightBitmap = res.getIdentifier("day_right", "drawable", "com.novoda.wallpaper");
carLeftBitmap = res.getIdentifier("day_left", "drawable", "com.novoda.wallpaper");
}

@Override
Expand Down Expand Up @@ -187,7 +128,7 @@ public void run() {

if( (mDragEventStartX < 150) && draggedLotsLeft ){
Log.d(TAG, "Driving animation started < Left");
takingACorner =true;
takingACorner =true;
slidePic = carLeftBitmap;
new Timer().schedule(new TimerTask(){
@Override
Expand Down Expand Up @@ -250,7 +191,7 @@ void drawFrame() {
private void drawCar(Canvas c) {

if(takingACorner){
c.drawBitmap(slidePic, 20, 0, null);
c.drawBitmap(BitmapFactory.decodeResource(getResources(), slidePic), 20, 120, null);
}else{

if(mDragEventInProgress){
Expand All @@ -260,7 +201,7 @@ private void drawCar(Canvas c) {
// c.drawBitmap(carLeftBitmap, 20, 0, null);
// }
}else{
c.drawBitmap(carFrontBitmap, 20, 0, null);
c.drawBitmap(BitmapFactory.decodeResource(getResources(), carFrontBitmap), 20, 120, null);
}
}
}
Expand All @@ -271,5 +212,31 @@ void drawTouchPoint(Canvas c) {
}
}

private final Paint mPaint = new Paint();
private float mOffset;
private float mTouchX = -1;
private float mTouchY = -1;
private float mCenterX;
private float mCenterY;
private boolean mDrivingForward = true;
private boolean mTurningLeft = false;
private boolean mTurningRight = false;
private boolean mDragEventAnimStarted = false;
private int carRightBitmap;
private int carLeftBitmap;
private int carFrontBitmap;
private int slidePic;
private boolean duringSlide = false;
private boolean mDragEventInProgress = false;
private float mDragEventStartX = 0;
private final Runnable mDrawWallpaper = new Runnable() {
public void run() {
drawFrame();
}
};
private boolean mVisible;
private float xLastOffset;
private boolean takingACorner = false;

}
}

0 comments on commit 409ca0d

Please sign in to comment.