Why my live wallpaper dont update?

All your problems with Audio, Video and Images.

Why my live wallpaper dont update?

Postby fkopew » Fri Aug 24, 2012 8:28 am

Why my live wallpaper dont update?
Code: Select all
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Handler;

import android.service.wallpaper.WallpaperService;
import android.view.MotionEvent;
import android.view.SurfaceHolder;

public class MyWallpaperService extends WallpaperService {
static int nomer=1;
Bitmap bmp;
  @Override
  public Engine onCreateEngine() {
    return new MyWallpaperEngine();
  }

  private class MyWallpaperEngine extends Engine {
    private final Handler handler = new Handler();
    private final Runnable drawRunner = new Runnable() {
     
      public void run() {
       
         drawFrame();
      }

    };

    private Paint paint = new Paint();

    private boolean visible = true;

    public MyWallpaperEngine() {

      paint.setAntiAlias(true);
      paint.setColor(Color.WHITE);
      paint.setStyle(Paint.Style.STROKE);
      paint.setStrokeJoin(Paint.Join.ROUND);
      paint.setStrokeWidth(10f);
      handler.post(drawRunner);
    }

    @Override
    public void onVisibilityChanged(boolean visible) {
      this.visible = visible;
      if (visible) {
        handler.post(drawRunner);
      } else {
        handler.removeCallbacks(drawRunner);
      }
    }

   


  @Override
  public void onSurfaceDestroyed(SurfaceHolder holder) {
    super.onSurfaceDestroyed(holder);
    this.visible = false;
    handler.removeCallbacks(drawRunner);
  }
 
  public void onSurfaceCreated(SurfaceHolder holder) {
     super.onSurfaceCreated(holder);
     // TODO Surface has been created, begin the update loop that will
     // update the Live Wallpaper.
   
     drawFrame();
   
     handler.post(drawRunner);
     }
  public void drawFrame()
  {
     SurfaceHolder holder = getSurfaceHolder();
    
      Canvas c = null;
      try {
         c = holder.lockCanvas();
         if (c != null) {
            draw(c);
         }
      } finally {
         if (c != null)
            holder.unlockCanvasAndPost(c);
      }
  }
  public void draw(Canvas c)
  {
     if (nomer ==40)
     {
        nomer=1;
     }
     switch(nomer){
    
     case 1:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a1);
     break;
     case 2:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a2);
     break;
     case 3:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a3);
     break;
     case 4:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a4);
     break;
     case 5:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a5);
     break;
     case 6:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a6);
     break;
     case 7:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a7);
     break;
     case 8:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a8);
     break;
     case 9:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a9);
     break;
     case 10:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a10);
     break;
     case 11:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a11);
     break;
     case 12:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a12);
     break;
     case 13:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a13);
     break;
     case 14:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a14);
     break;
     case 15:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a15);
     break;
     case 16:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a16);
     break;
     case 17:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a17);
     break;
     case 18:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a18);
     break;
     case 19:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a19);
     break;
     case 20:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a20);
     break;
     case 21:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a21);
     break;
     case 22:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a22);
     break;
     case 23:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a23);
     break;
     case 24:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a24);
     break;
     case 25:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a25);
     break;
     case 26:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a26);
     break;
     case 27:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a27);
     break;
     case 28:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a28);
     break;
     case 29:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a29);
     break;
     case 30:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a30);
     break;
     case 31:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a31);
     break;
     case 32:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a32);
     break;
     case 33:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a33);
     break;
     case 34:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a34);
     break;
     case 35:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a35);
     break;
     case 36:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a36);
     break;
     case 37:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a37);
     break;
     case 38:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a38);
     break;
     case 39:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a39);
     break;
     case 40:  bmp = BitmapFactory.decodeResource(getResources(),R.drawable.a40);
     break;
     }
     nomer+=1;
    
     c.drawBitmap(bmp, 10,10, null);
      
  }
  @Override
  public void onSurfaceChanged(SurfaceHolder holder, int format,
      int width, int height) {

    super.onSurfaceChanged(holder, format, width, height);
    handler.post(drawRunner);
  }

  @Override
  public void onTouchEvent(MotionEvent event) {
     handler.post(drawRunner);
  }


}}

And it is loading forever.
fkopew
Freshman
Freshman
 
Posts: 3
Joined: Mon Aug 13, 2012 10:17 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 27 guests