strange behaviors...

Problems with Canvas, OpenGL, etc...

strange behaviors...

Postby tenji73 » Sun Dec 12, 2010 9:36 pm

hi,
i am new to java & trying to create a live wallpaper that contains some timer elements, but i get some strange behaviors all the time:

1. is it possible to clear last canvas after refreshing it with new time? my code adds the new data on top of the old. is it okay to add black background (canvas.drawColor(0xFF000000); ) to cover it? is this going to cause some memory issues?

2. the app works fine in the wallpaper preview, but crushes after clicking "set wallpaper", restarts than & works fine again ..

i hope somebody has an idea...
THANKS!!
tom

my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class myClock extends  WallpaperService {
  2.         @Override
  3.         public Engine onCreateEngine() {
  4.                 return new wp();
  5.         }
  6.        
  7.         class wp extends Engine{
  8.                 public Paint seconds;
  9.                 public Canvas canvas;
  10.                 private Handler mHandler = new Handler();
  11.                
  12.                 @Override
  13.                 public void onSurfaceCreated(SurfaceHolder arg0)
  14.                 {
  15.                         mHandler.postDelayed(mUpdateTimeTask, 10);
  16.                 }
  17.                
  18.                 private Runnable mUpdateTimeTask = new Runnable()
  19.                 {
  20.                         @Override
  21.                         public void run()
  22.                         {
  23.                                 canvas = getSurfaceHolder().lockCanvas();
  24.                                 seconds = new Paint();
  25.                                 seconds.setColor(0xFF666666);
  26.                                 seconds.setTextSize(50);
  27.                                 Date date = new Date();
  28.                                 canvas.drawText(Double.toString(date.getSeconds()), 10 , 100, seconds);
  29.                                 mHandler.postDelayed(this, 1000);
  30.                                 getSurfaceHolder().unlockCanvasAndPost(canvas);
  31.                         }
  32.                 };
  33.         }
  34. }
  35.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
tenji73
Freshman
Freshman
 
Posts: 4
Joined: Sun Dec 12, 2010 8:48 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests