Reset Wallpaper Once Settings Have Been Changed

  ... the Live-Wallpaper Extension for AndEngine.

Reset Wallpaper Once Settings Have Been Changed

Postby BigWinston » Wed Jun 15, 2011 10:31 pm

Hey All,

Quick question I couldn't see answered on the forum...

How can I adapt my live wallpaper (made using y Mimminito's template) to force an update once the settings have been applied? Right now, I have my settings working, but I have to switch to some other wallpaper and back again to force my new settings values to be applied.

I've been looking into the 'onSharedPreferenceChanged' method, but can't seem to hit my breakpoint there.

Thanks!
BigWinston
 
Posts: 16
Joined: Sat Nov 13, 2010 7:24 pm

Re: Reset Wallpaper Once Settings Have Been Changed

Postby tencent » Fri Jun 17, 2011 7:10 am

I have been wondering this as well. The best I can come up with is when you pause and resume you could probably clear your scene and then recreate it but I haven't tested this yet to verify if it works. Also doing this would probably be pretty expensive.

Since I did not feel like testing this. I keep a static reference of my settings and just keep that reference in sync with the settings. This way my update handlers can just refer to the static settings and enable/disable features or modify parameters based on them. I can see how this would not work for every situation but I hope that helps.
tencent
 
Posts: 60
Joined: Sat May 21, 2011 1:29 am
Location: Florida

Re: Reset Wallpaper Once Settings Have Been Changed

Postby kurloo » Fri Jun 17, 2011 5:39 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class AlphaSettings extends PreferenceActivity implements
  2.                 SharedPreferences.OnSharedPreferenceChangeListener {
  3.         @Override
  4.         protected void onCreate(Bundle icicle) {
  5.                 super.onCreate(icicle);
  6.                 addPreferencesFromResource(R.xml.setting);
  7.                 getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
  8.                 Global.isRestart = false;
  9.         }
  10.  
  11.         @Override
  12.         protected void onResume() {
  13.                 super.onResume();
  14.         }
  15.  
  16.         @Override
  17.         protected void onDestroy() {
  18.                 getPreferenceManager().getSharedPreferences()
  19.                                 .unregisterOnSharedPreferenceChangeListener(this);
  20.                 super.onDestroy();
  21.         }
  22.  
  23.         @Override
  24.         protected void onStop() {
  25.  
  26.                 super.onStop();
  27.         }
  28.  
  29.         @Override
  30.         public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
  31.                         String key) {
  32.                 SharedPreferences prefs = PreferenceManager
  33.                                 .getDefaultSharedPreferences(this);
  34.                
  35.                 Global.isRestart = true;
  36.         }
  37. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


just add a listener to observe the event.
kurloo
 
Posts: 5
Joined: Wed May 11, 2011 5:57 pm

Re: Reset Wallpaper Once Settings Have Been Changed

Postby BigWinston » Fri Jun 17, 2011 7:14 pm

Thanks! I'll give it a try and post my result...
BigWinston
 
Posts: 16
Joined: Sat Nov 13, 2010 7:24 pm

Re: Reset Wallpaper Once Settings Have Been Changed

Postby BigWinston » Fri Jun 17, 2011 8:17 pm

OK, so I'm able to detect when the settings change, but its not updating the wallpaper in the preview screen, or on the main screen. I still have to select a different wallpaper and then switch back to my wallpaper.

Any ideas?
BigWinston
 
Posts: 16
Joined: Sat Nov 13, 2010 7:24 pm

Re: Reset Wallpaper Once Settings Have Been Changed

Postby kurloo » Sat Jun 18, 2011 5:57 am

you should have a look at the link http://developer.android.com/resources/samples/Home/index.html

you need to override the onResume method.when changing to the preview screen.it would be running.
you may change the engine's scene here which you had set in the onLoadScene method. such as using an another scene or reseting the current scene. and then the engine will call his start method to render.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.         protected void onResume() {
  3.                
  4.                 if (Global.isRestart) {
  5.                         //change the scene.
  6.                 }
  7.                 super.onResume();// call the engine's start method.    this.mEngine.start();
  8.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
kurloo
 
Posts: 5
Joined: Wed May 11, 2011 5:57 pm

Re: Reset Wallpaper Once Settings Have Been Changed

Postby greentrucksoftware » Thu Jun 30, 2011 7:18 pm

Hmm, I tried this and in the onResume call I have some code that removes some sprites and adds some new ones. Works fine, but if I tap the Set Wallpaper button before this update is finished I get an array out of bounds error similar to adding/removing sprites not on the update thread.

Anyone else seen this? Maybe I'm missing something.
greentrucksoftware
 
Posts: 6
Joined: Tue Jun 14, 2011 5:10 pm

Re: Reset Wallpaper Once Settings Have Been Changed

Postby kurloo » Fri Jul 01, 2011 7:36 pm

make sure that all the thread are not running.
the homescreen 's . or the preview's. that's two, but there is only one andengine instance.

if you want to change the resources staticly. you should do like the following:
1.other threads are not running
2.update(the main thread).
3.other threads could go on running.

you may take a look at bellow, 46035e28 is the preview's renderer engine, 46033ea0 is the home screen's:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. : service.oncreate
  2. : service.onloadResources
  3. : service.onLoadScene
  4. : service.onLoadComplete
  5. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...service.onCreateEngine
  6. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.setEGLConfigChooser
  7. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.setRenderer
  8. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.setRenderMode
  9. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.onCreateSurface
  10. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.onSurfaceCreated
  11. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.onSurfaceChanged
  12. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.oncVisChanged
  13. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.onResume
  14. : service.onresume
  15. : onTouchEvent
  16. : onTouchEvent
  17. : onTouchEvent
  18. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...service.onCreateEngine
  19. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.setEGLConfigChooser
  20. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.setRenderer
  21. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.setRenderMode
  22. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.onCreateSurface
  23. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.onSurfaceCreated
  24. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.onSurfaceChanged
  25. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.oncVisChanged
  26. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.onPause
  27. : service.pause
  28. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.oncVisChanged
  29. : com.kurloo.service.AlphaService$AlphaEngine@46033ea0...engine.onResume
  30. : service.onresume
  31. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.onSurfaceDestroyed
  32. : onLoadedToHardware (Texture is loaded to hardware,it would be blank.)
  33. : com.kurloo.service.AlphaService$AlphaEngine@46035e28...engine.onDestroy
  34.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


you need to change your resources on the main thread.
kurloo
 
Posts: 5
Joined: Wed May 11, 2011 5:57 pm

Re: Reset Wallpaper Once Settings Have Been Changed

Postby yeah00 » Sun Jul 10, 2011 2:55 am

The tutorials by mimito thread(Tutorials section...) has a link to another thread with some example code that works fine.
yeah00
 
Posts: 15
Joined: Thu May 26, 2011 10:27 am

Re: Reset Wallpaper Once Settings Have Been Changed

Postby jgibbs » Sun Nov 27, 2011 10:54 pm

I've just been trying to solve the same problem with a wallpaper I'm putting together. The solution in my case is as follows:

Add a global variable to the wallpaper servlce

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class LiveWallpaperService extends BaseLiveWallpaperService implements SharedPreferences.OnSharedPreferenceChangeListener {
  2.         private boolean mSettingsChanged = false;
  3.         ...
  4. }
  5.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


Make a function that builds the scene from scratch

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void BuildScene(Scene scene) {
  2.         // Destroy the current scene
  3.         scene.detachChildren();
  4.        
  5.         // Create the scene with currentsettings
  6.         ...
  7. }      
  8.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Catch preference changes and set global flag to indicate new settings need to come into play

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
  2.         nMySetting = Integer.parseInt(prefs.getString("num_setting", "3"));
  3.         mSettingsChanged = true;
  4. }
  5.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


Call BuildScene from load and resume functions as applicable

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2. public Scene onLoadScene() {
  3.         final Scene scene = new Scene();
  4.         BuildScene(scene);
  5.         return scene;
  6. }
  7.  
  8. @Override
  9. public void onResume() {
  10.         super.onResume();
  11.         if( mSettingsChanged )
  12.         {
  13.                 BuildScene( this.getEngine().getScene() );
  14.                 mSettingsChanged = false;
  15.         }
  16. }
  17.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
Check out my adventures into Android programming:

4x4 Adventures - Featured in the Top Free Play Store listings
Slippery Sid
jgibbs
 
Posts: 105
Joined: Fri Nov 25, 2011 9:32 am
Location: New Zealand

Next

Return to Live-Wallpaper

Who is online

Users browsing this forum: No registered users and 6 guests