When I click my live wallpaper, it crashes. I can't see what is wrong.
Here is my code.
package com.puinyuu.umasaka;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.content.res.Resources;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.view.SurfaceHolder;
public class UmasakaWallpaper extends WallpaperService {
private final Handler mHandler = new Handler();
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public Engine onCreateEngine() {
return new UmasakaEngine();
}
class UmasakaEngine extends Engine {
private Resources res;
private Bitmap mUmasakaFrame0;
private Bitmap mUmasakaFrame1;
private Bitmap mUmasakaFrame2;
private Bitmap mUmasakaFrame3;
private Bitmap mUmasakaFrame4;
private Bitmap mUmasakaFrame5;
private Bitmap mUmasakaFrame6;
private Bitmap mUmasakaFrame7;
private int mFrameNum = 0;
private final Runnable mGetFrame = new Runnable() {
public void run() {
drawFrame();
}
};
private boolean mVisible;
UmasakaEngine() {
mUmasakaFrame0 = BitmapFactory.decodeResource(res,
R.drawable.umasaka0);
mUmasakaFrame1 = BitmapFactory.decodeResource(res,
R.drawable.umasaka1);
mUmasakaFrame2 = BitmapFactory.decodeResource(res,
R.drawable.umasaka2);
mUmasakaFrame3 = BitmapFactory.decodeResource(res,
R.drawable.umasaka3);
mUmasakaFrame4 = BitmapFactory.decodeResource(res,
R.drawable.umasaka4);
mUmasakaFrame5 = BitmapFactory.decodeResource(res,
R.drawable.umasaka5);
mUmasakaFrame6 = BitmapFactory.decodeResource(res,
R.drawable.umasaka6);
mUmasakaFrame7 = BitmapFactory.decodeResource(res,
R.drawable.umasaka7);
mUmasakaFrame0 = Bitmap.createBitmap(mUmasakaFrame0);
mUmasakaFrame1 = Bitmap.createBitmap(mUmasakaFrame1);
mUmasakaFrame2 = Bitmap.createBitmap(mUmasakaFrame2);
mUmasakaFrame3 = Bitmap.createBitmap(mUmasakaFrame3);
mUmasakaFrame4 = Bitmap.createBitmap(mUmasakaFrame4);
mUmasakaFrame5 = Bitmap.createBitmap(mUmasakaFrame5);
mUmasakaFrame6 = Bitmap.createBitmap(mUmasakaFrame6);
mUmasakaFrame7 = Bitmap.createBitmap(mUmasakaFrame7);
}
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
}
@Override
public void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mGetFrame);
}
@Override
public void onVisibilityChanged(boolean visible) {
mVisible = visible;
if (visible) {
drawFrame();
} else {
mHandler.removeCallbacks(mGetFrame);
}
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
drawFrame();
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
mVisible = false;
mHandler.removeCallbacks(mGetFrame);
}
void drawFrame() {
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
getFrame(c);
}
} finally {
if (c != null) holder.unlockCanvasAndPost(c);
}
// Reschedule the next redraw
mHandler.removeCallbacks(mGetFrame);
if (mVisible && mFrameNum == 0) {
mHandler.postDelayed(mGetFrame, 90);
}
if (mVisible && mFrameNum == 1) {
mHandler.postDelayed(mGetFrame, 60);
}
if (mVisible && mFrameNum == 2) {
mHandler.postDelayed(mGetFrame, 140);
}
if (mVisible && mFrameNum == 3) {
mHandler.postDelayed(mGetFrame, 60);
}
if (mVisible && mFrameNum == 4) {
mHandler.postDelayed(mGetFrame, 90);
}
if (mVisible && mFrameNum == 5) {
mHandler.postDelayed(mGetFrame, 60);
}
if (mVisible && mFrameNum == 6) {
mHandler.postDelayed(mGetFrame, 130);
}
if (mVisible && mFrameNum == 7) {
mHandler.postDelayed(mGetFrame, 60);
}
}
void getFrame(Canvas c) {
c.save();
if (mFrameNum == 0) {
c.drawBitmap(mUmasakaFrame0, 100, 100, null);
}
if (mFrameNum == 1) {
c.drawBitmap(mUmasakaFrame1, 100, 100, null);
}
if (mFrameNum == 2) {
c.drawBitmap(mUmasakaFrame2, 100, 100, null);
}
if (mFrameNum == 3) {
c.drawBitmap(mUmasakaFrame3, 100, 100, null);
}
if (mFrameNum == 4) {
c.drawBitmap(mUmasakaFrame4, 100, 100, null);
}
if (mFrameNum == 5) {
c.drawBitmap(mUmasakaFrame5, 100, 100, null);
}
if (mFrameNum == 6) {
c.drawBitmap(mUmasakaFrame6, 100, 100, null);
}
if (mFrameNum == 7) {
c.drawBitmap(mUmasakaFrame7, 100, 100, null);
}
mFrameNum = mFrameNum + 1;
c.restore();
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe from this group, send email to
android-developers+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.