Permalink
Browse files

Updated the demos to store the IDs of the resources rather than putti…

…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...
1 parent 2df0442 commit 409ca0d538a824543aed77e4937ed94f8b940f84 kevinmcdonagh committed Feb 28, 2010
Showing with 53 additions and 94 deletions.
  1. BIN Livewallpaper/switch_animation/res/drawable/front_day001.png
  2. BIN Livewallpaper/switch_animation/res/drawable/front_day002.png
  3. BIN Livewallpaper/switch_animation/res/drawable/front_day003.png
  4. BIN Livewallpaper/switch_animation/res/drawable/front_day004.png
  5. BIN Livewallpaper/switch_animation/res/drawable/left_day001.png
  6. BIN Livewallpaper/switch_animation/res/drawable/left_day002.png
  7. BIN Livewallpaper/switch_animation/res/drawable/left_day003.png
  8. BIN Livewallpaper/switch_animation/res/drawable/left_day004.png
  9. BIN Livewallpaper/switch_animation/res/drawable/right_day001.png
  10. BIN Livewallpaper/switch_animation/res/drawable/right_day002.png
  11. BIN Livewallpaper/switch_animation/res/drawable/right_day003.png
  12. BIN Livewallpaper/switch_animation/res/drawable/right_day004.png
  13. +3 −1 Livewallpaper/switch_animation/res/xml/wallpaper.xml
  14. +12 −24 Livewallpaper/switch_animation/src/com/novoda/wallpaper/AnimSwitchWallPaper.java
  15. BIN Livewallpaper/switch_leftright/res/drawable/day_front.png
  16. BIN Livewallpaper/switch_leftright/res/drawable/day_left.png
  17. BIN Livewallpaper/switch_leftright/res/drawable/day_right.png
  18. BIN Livewallpaper/switch_leftright/res/drawable/night_front.png
  19. BIN Livewallpaper/switch_leftright/res/drawable/night_left.png
  20. BIN Livewallpaper/switch_leftright/res/drawable/night_right.png
  21. +3 −1 Livewallpaper/switch_leftright/res/xml/wallpaper.xml
  22. +35 −68 Livewallpaper/switch_leftright/src/com/novoda/wallpaper/ImageSwitchWallPaper.java
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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"/>
@@ -36,20 +36,15 @@ public Engine onCreateEngine() {
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");
}
}
@@ -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();
}
@@ -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
@@ -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;
}
@@ -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() {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
Deleted file not rendered
Deleted file not rendered
@@ -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"/>
@@ -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;
@@ -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
@@ -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
@@ -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){
@@ -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);
}
}
}
@@ -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.