Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - Need help animating the System Wallpaper.

Need help animating the System Wallpaper.

Put your problem here if it does not fit any of the other categories.

Need help animating the System Wallpaper.

Postby lgmcben » Mon Nov 17, 2008 1:53 pm

This is my Service.

It's a simple service which use Handler to invoke "setWallpaper()" every 2 seconds.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.mseer.testservice;
  2.  
  3.  
  4.  
  5. import java.io.IOException;
  6.  
  7. import java.io.InputStream;
  8.  
  9.  
  10.  
  11. import android.app.Service;
  12.  
  13. import android.content.Context;
  14.  
  15. import android.content.Intent;
  16.  
  17. import android.graphics.Bitmap;
  18.  
  19. import android.graphics.BitmapFactory;
  20.  
  21. import android.os.Handler;
  22.  
  23. import android.os.IBinder;
  24.  
  25. import android.os.Message;
  26.  
  27. import android.util.Log;
  28.  
  29.  
  30.  
  31. public class MyService extends Service{
  32.  
  33.  
  34.  
  35.   public IBinder onBind(Intent intent) {       
  36.  
  37.         return null;
  38.  
  39.   }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.   protected static Service sv;
  46.  
  47.   protected static InputStream bg01, bg02, bg03, bg04, bg05, bg06;
  48.  
  49.  
  50.  
  51.   protected static int index=0;
  52.  
  53.  
  54.  
  55.   protected static final int SECONDPASSED = 0x1234;
  56.  
  57.  
  58.  
  59.   protected boolean running = false;
  60.  
  61.  
  62.  
  63.   Thread counterThread = null;
  64.  
  65.  
  66.  
  67.   static Handler myWallpaperHandler = new Handler(){
  68.  
  69.        public void handleMessage(Message msg) {
  70.  
  71.             switch (msg.what) {
  72.  
  73.                  case MyService.SECONDPASSED:
  74.  
  75.                                
  76.  
  77.                          updateWallpaper();
  78.  
  79.                                
  80.  
  81.                       break;
  82.  
  83.             }
  84.  
  85.             super.handleMessage(msg);
  86.  
  87.        }
  88.  
  89.   };
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.        
  98.  
  99.        
  100.  
  101.   protected static void updateWallpaper(){
  102.  
  103.          
  104.  
  105.           try {
  106.  
  107.                         if(index==0){
  108.  
  109.                                 sv.setWallpaper(bg01);
  110.  
  111.                         }else if(index==1){
  112.  
  113.                                 sv.setWallpaper(bg02);
  114.  
  115.                         }else if(index==2){
  116.  
  117.                                 sv.setWallpaper(bg03);
  118.  
  119.                         }else if(index==3){
  120.  
  121.                                 sv.setWallpaper(bg04);
  122.  
  123.                         }else if(index==4){
  124.  
  125.                                 sv.setWallpaper(bg05);
  126.  
  127.                         }else if(index==5){
  128.  
  129.                                 sv.setWallpaper(bg06);
  130.  
  131.                         }
  132.  
  133.                        
  134.  
  135.                 index++;
  136.  
  137.                 if(index>5){
  138.  
  139.                         index = 0;
  140.  
  141.                 }
  142.  
  143.                  
  144.  
  145.  
  146.  
  147.                 } catch (IOException e) {
  148.  
  149.                        
  150.  
  151.                         e.printStackTrace();
  152.  
  153.                 }
  154.  
  155.                
  156.  
  157.          
  158.  
  159.          
  160.  
  161.          
  162.  
  163.   }
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.   public void onCreate(){
  172.  
  173.           sv = this;
  174.  
  175.           super.onCreate();
  176.  
  177.           running = true;
  178.  
  179.           bg01 = sv.getResources().openRawResource(R.drawable.night01w);
  180.  
  181.           bg02 = sv.getResources().openRawResource(R.drawable.night02w);
  182.  
  183.           bg03 = sv.getResources().openRawResource(R.drawable.night03w);
  184.  
  185.           bg04 = sv.getResources().openRawResource(R.drawable.night04w);
  186.  
  187.           bg05 = sv.getResources().openRawResource(R.drawable.night05w);
  188.  
  189.           bg06 = sv.getResources().openRawResource(R.drawable.night06w);
  190.  
  191.          
  192.  
  193.           this.counterThread = new Thread(new secondCountDownRunner());
  194.  
  195.       this.counterThread.start();
  196.  
  197.            
  198.  
  199.   }
  200.  
  201.  
  202.  
  203.   public void onDestroy() {
  204.  
  205.     super.onDestroy();
  206.  
  207.     running = false;
  208.  
  209.     counterThread.interrupt();
  210.  
  211.   }
  212.  
  213.  
  214.  
  215.  
  216.  
  217. }
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225. class secondCountDownRunner implements Runnable{
  226.  
  227.     public void run() {
  228.  
  229.          while(!Thread.currentThread().isInterrupted()){
  230.  
  231.               Message m = new Message();
  232.  
  233.               m.what = MyService.SECONDPASSED;
  234.  
  235.               MyService.myWallpaperHandler.sendMessage(m);
  236.  
  237.               try {
  238.  
  239.                    Thread.sleep(2000);
  240.  
  241.               } catch (InterruptedException e) {
  242.  
  243.                    Thread.currentThread().interrupt();
  244.  
  245.               }
  246.  
  247.          }
  248.  
  249.     }
  250.  
  251. }
  252.  
  253.  
Parsed in 0.023 seconds, using GeSHi 1.0.8.4


My problem:

The wallpaper changes for 4-5 frames, then stopped...


Solutions I've tried:

1. I tried Logging like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. if(index==0){
  3.  
  4.                                 Log.e("BM WALLPAPER","Wallpaper set to WP1 | " + bg01);
  5.  
  6.                                 sv.setWallpaper(bg01);
  7.  
  8.                         }else if(index==1){
  9.  
  10.                                 Log.e("BM WALLPAPER","Wallpaper set to WP2 | "  + bg02);
  11.  
  12.                                 sv.setWallpaper(bg02);
  13.  
  14. // and so on...
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


And I can still see the Log message every 2 seconds (but the wallpaper dont change anymore)



2. I tried creating the InputStream every cycle. It works. But it greatly slow down the phone to an unacceptable level.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if(index==0){
  2.  
  3.                                   bg01 = sv.getResources().openRawResource(R.drawable.night01w);
  4.  
  5.                                 sv.setWallpaper(bg01);
  6.  
  7.                         }else if(index==1){
  8.  
  9.                                   bg02 = sv.getResources().openRawResource(R.drawable.night02w);
  10.  
  11.                                 sv.setWallpaper(bg02);
  12.  
  13. // and so on...
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


3. I've tried all of the above solutions but use setWallpaper(Bitmap); instead. The result is even slower...



My requests to experts in this forum:
1. I wonder why my wallpaper animated for only 4-5 frames, then stopped. (using the first code snippet posted above)

2. If anyone happen to know how to efficiently create an animated wallpaper, please let me know.


Thank you in advance. =)
lgmcben
Junior Developer
Junior Developer
 
Posts: 24
Joined: Mon Nov 17, 2008 5:06 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests