Hi All,
I am getting error in live wall paper plz help me
my code is
wallpaper engine
public class MywallpaperEngine extends Engine {
// private final DottedCircles circles = new DottedCircles();
private final MovingBackGround circles1 = new MovingBackGround(
getApplication());
private final Runnable mRunnable = new Runnable() {
public void run() {
drawFrame();
}
};
private boolean mVisible = false;
private long tapTime;
private float tapX;
private float tapY;
public void onCreate(SurfaceHolder holder) {
super.onCreate(holder);
setTouchEventsEnabled(true);
}
public void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mRunnable);
}
public void onVisibilityChanged(boolean visible) {
mVisible = visible;
drawFrame();
}
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
circles1.init(width, height);
drawFrame();
}
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
mVisible = false;
try
{
Thread updater = null;
updater.join();
}
catch (InterruptedException e)
{
}
super.onSurfaceDestroyed(holder);
drawFrame();
}
/*
* public void onOffsetsChanged(float xOffset, float yOffset, float
* xStep, float yStep, int xPixels, int yPixels) { if (xPixels !=
* circles.getOffset()) { circles.setOffset(xPixels); if (mVisible) {
* drawFrame(); } } }
*/
public void onTouchEvent(MotionEvent event) {
/*if (event.getAction() == MotionEvent.ACTION_DOWN) {
tapTime = event.getEventTime();
tapX = event.getX();
tapY = event.getY();
} else if (event.getAction() == MotionEvent.ACTION_UP
&& event.getEventTime() - tapTime < 250
&& Math.abs(event.getX() - tapX) < 4
&& Math.abs(event.getY() - tapY) < 4) {
// circles.add(tapX, tapY);
}*/
}
/*private void animate() {
mHandler.removeCallbacks(mRunnable);
if (mVisible) {
drawFrame();
mHandler.postDelayed(mRunnable,10);
}
}*/
private void drawFrame() {
SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if (canvas != null) {
Log.d("call", "" + canvas);
circles1.draw(canvas);
}
}
catch(NullPointerException exception)
{
Log.d("null pointer","null pointer");
}
finally {
if (canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
mHandler.removeCallbacks(mRunnable);
if (mVisible) {
//drawFrame();
mHandler.postDelayed(mRunnable,10);
}
}
}
}
movingbackgroundclass
public MovingBackGround(Context context) {
super(context);
bg=new BackgroundSelector();
setWillNotDraw(false);
}
private Context getApplication() {
// TODO Auto-generated method stub
return null;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(bg.click==0)
{
backGround = BitmapFactory.decodeResource(getResources(),
R.drawable.b1);
}
else if(bg.click==1)
{
backGround = BitmapFactory.decodeResource(getResources(),
R.drawable.b1);
}
else if(bg.click==2)
{
backGround = BitmapFactory.decodeResource(getResources(),
R.drawable.b2);
}
doDrawRunning(canvas);
invalidate();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
/**
* Draws current state of the game Canvas.
*/
private int mBGFarMoveX = 0;
private int mBGNearMoveX = 0;
private int width;
private int height;
private void doDrawRunning(Canvas canvas) {
int newFarX = backGround.getWidth() - (-mBGFarMoveX);
BitmapFactory.Options options = new BitmapFactory.Options();
Log.d("option", ""+options);
options.inPurgeable = true;
Resources res = getResources();
Log.d("rrrrrrrrr", ""+bmp);
bmp = BitmapFactory.decodeResource(res,bmp1[bgNumber], options);
DisplayMetrics metrics1 = new DisplayMetrics();
MovingBackGround context = this;
metrics1 = context.getResources().getDisplayMetrics();
float xScale = (float) canvas.getWidth() / bmp.getWidth();
float yScale = (float) canvas.getHeight() / bmp.getHeight();
float scale = Math.max(xScale, yScale); //selects the larger size to grow the images by
//scale = (float) (scale*1.1); //this allows for ensuring the image covers the whole screen.
float scaledWidth = scale * bmp.getWidth();
float scaledHeight = scale * bmp.getHeight();
bmp = Bitmap.createScaledBitmap(bmp, (int)scaledWidth, (int)scaledHeight, true);
float xScale1 = (float) canvas.getWidth() / backGround.getWidth();
float yScale1 = (float) canvas.getHeight() / backGround.getHeight();
float scale1= Math.max(xScale, yScale); //selects the larger size to grow the images by
//scale = (float) (scale*1.1); //this allows for ensuring the image covers the whole screen.
float scaledWidth1 = scale * backGround.getWidth();
float scaledHeight1= scale * backGround.getHeight();
backGround = Bitmap.createScaledBitmap(backGround, (int)scaledWidth1, (int)scaledHeight1, true);
canvas.drawBitmap(backGround, 0, 0, null);
canvas.drawBitmap(bmp, 0,0,null);
if (runUp = true){
bgNumber += 1;
Log.d("bnum", ""+bgNumber);
if (bgNumber == bmp1.length){
bgNumber=0;
runUp = false;
}
}
else if(runUp = false){
bgNumber -= 1;
if (bgNumber == 0){
bgNumber+=1;
runUp = true;
}
}
bmp.recycle();
}
public void init(int width, int height) {
this.width = width;
this.height = height;
}
// TODO Auto-generated method stub
}
backgroundselector class
public class BackgroundSelector extends Activity
{
ImageView b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,img;
static int click=0;
//static Bitmap bgImage1;
// private Resources mResources;
MovingBackGround mv;
@Override
public void onCreate(Bundle instanceState)
{
super.onCreate(instanceState);
/*context = this;
if(instanceState != null)
{
// restore any saved instance state if it exists
}
//setContentView(R.layout.my);
*/ setContentView(R.layout.my2);
//bgImage1 = BitmapFactory.decodeResource(mResources, R.drawable.b1);
b1=(ImageView)findViewById(R.id.s1);
b2=(ImageView)findViewById(R.id.s2);
b3=(ImageView)findViewById(R.id.s3);
b4=(ImageView)findViewById(R.id.s4);
b5=(ImageView)findViewById(R.id.s5);
b6=(ImageView)findViewById(R.id.s6);
b7=(ImageView)findViewById(R.id.s7);
b8=(ImageView)findViewById(R.id.s8);
b9=(ImageView)findViewById(R.id.s9);
b10=(ImageView)findViewById(R.id.s10);
img=(ImageView)findViewById(R.id.imageView1);
img.setBackgroundResource(R.drawable.s1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
click=1;
Log.d("click1", ""+click);
mv=new MovingBackGround(getApplication());
img.setBackgroundResource(R.drawable.s1);
finish();
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
click=2;
Log.d("click1", ""+click);
img.setBackgroundResource(R.drawable.b2);
mv=new MovingBackGround(getApplication());
finish();
}
});
}
}
when i click on setwallpaperbutton & goto home screen get belown error
07-23 17:29:40.020: E/SpannableStringBuilder(15702): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
07-23 17:29:40.020: E/SpannableStringBuilder(15702): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
07-23 17:29:41.045: V/WallpaperService(15702): Display Width=800 Height=1280
07-23 17:29:43.005: E/SurfaceTextureClient(15702): queueBuffer: error queuing buffer to SurfaceTexture, -19
07-23 17:29:43.005: E/SurfaceTextureClient(15702): queueBuffer (handle=0x5d436f20) failed (No such device)
07-23 17:29:43.025: E/AndroidRuntime(15702): FATAL EXCEPTION: main
07-23 17:29:43.025: E/AndroidRuntime(15702): java.lang.IllegalArgumentException
07-23 17:29:43.025: E/AndroidRuntime(15702): at android.view.Surface.unlockCanvasAndPost(Native Method)
07-23 17:29:43.025: E/AndroidRuntime(15702): at com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)
07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine.drawFrame(Rain.java:145)
07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine.animate(Rain.java:124)
07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine.access$0(Rain.java:121)
07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine$1.run(Rain.java:35)
07-23 17:29:43.025: E/AndroidRuntime(15702): at android.os.Handler.handleCallback(Handler.java:615)
07-23 17:29:43.025: E/AndroidRuntime(15702): at android.os.Handler.dispatchMessage(Handler.java:92)
07-23 17:29:43.025: E/AndroidRuntime(15702): at android.os.Looper.loop(Looper.java:137)
07-23 17:29:43.025: E/AndroidRuntime(15702): at android.app.ActivityThread.main(ActivityThread.java:4921)
07-23 17:29:43.025: E/AndroidRuntime(15702): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 17:29:43.025: E/AndroidRuntime(15702): at java.lang.reflect.Method.invoke(Method.java:511)
07-23 17:29:43.025: E/AndroidRuntime(15702): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-23 17:29:43.025: E/AndroidRuntime(15702): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-23 17:29:43.025: E/AndroidRuntime(15702): at dalvik.system.NativeStart.main(Native Method)