Reset Wallpaper Once Settings Have Been Changed

  ... the Live-Wallpaper Extension for AndEngine.

Re: Reset Wallpaper Once Settings Have Been Changed

Postby mjhavens » Thu Dec 01, 2011 12:13 am

jgibbs wrote: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.032 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.032 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.035 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



Thank you so much jgibbs this has helped tremendously
mjhavens
 
Posts: 44
Joined: Mon Nov 28, 2011 2:59 am

Re: Reset Wallpaper Once Settings Have Been Changed

Postby ttttkk » Mon Jul 29, 2013 9:17 am

Hi, i'm new to andengine, does that mean i have to clear out the content of "public void onCreateScene(OnCreateSceneCallback createSceneCallback) throws Exception { " ?

jgibbs wrote: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.037 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.038 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.038 seconds, using GeSHi 1.0.8.4
ttttkk
 
Posts: 54
Joined: Thu Dec 22, 2011 4:27 am

Previous

Return to Live-Wallpaper

Who is online

Users browsing this forum: No registered users and 4 guests