java - Help with Preferences and Android Live Wallpaper -


basically want when preference switched default whatever load new set of parallax backgrounds. code on complicated , maybe off when switch preferences nothing changes. can tell i'm novice but, appreciated , gladly credit in app when post it. if need more of code ask.

package quotesandothers.livewallpaper.quotesandothers;  import org.anddev.andengine.engine.camera.camera; import org.anddev.andengine.engine.options.engineoptions; import org.anddev.andengine.engine.options.engineoptions.screenorientation; import org.anddev.andengine.engine.options.resolutionpolicy.fillresolutionpolicy; import org.anddev.andengine.entity.scene.scene; import org.anddev.andengine.entity.scene.background.autoparallaxbackground; import org.anddev.andengine.entity.scene.background.parallaxbackground.parallaxentity; import org.anddev.andengine.entity.sprite.sprite; import org.anddev.andengine.extension.ui.livewallpaper.baselivewallpaperservice; import org.anddev.andengine.opengl.texture.texture; import org.anddev.andengine.opengl.texture.textureoptions; import org.anddev.andengine.opengl.texture.region.textureregion; import org.anddev.andengine.opengl.texture.region.textureregionfactory; import org.anddev.andengine.opengl.texture.region.tiledtextureregion;  import android.content.sharedpreferences;  public class livewallpaper extends baselivewallpaperservice implements     sharedpreferences.onsharedpreferencechangelistener { // =========================================================== // constants // ===========================================================     public static final string shared_prefs_name ="settings";  private string mtheme= "inspiration";  // camera constants private static final int camera_width = 480; private static final int camera_height = 854;   // =========================================================== // fields // ===========================================================  // shared preferences  private texture mtexture;    private texture mautoparallaxinspirationaltexture;  private textureregion mparallaxlayermid1;  private textureregion mparallaxlayertop;  private textureregion mparallaxlayertop2;  private textureregion mparallaxlayermid2;  private textureregion mparallaxlayerlow1;  private textureregion mparallaxlayerlow2; private textureregion mparallaxlayerinspired;   private texture mautoparallaxbackgroundtexture;    // =========================================================== // constructors // ===========================================================  // =========================================================== // getter & setter // ===========================================================  // =========================================================== // methods for/from superclass/interfaces // ===========================================================  @override public org.anddev.andengine.engine.engine onloadengine() {     camera mcamera = new camera(0, 0, camera_width, camera_height);     return new org.anddev.andengine.engine.engine(             new engineoptions(true, screenorientation.portrait,                     new fillresolutionpolicy(), mcamera)); }  @override public void onsharedpreferencechanged(sharedpreferences prefs, string key) {     mtheme = prefs.getstring("cube2_shape", "inspiration");     readtheme();  } private void readtheme(){      final scene scene = new scene(1);     final autoparallaxbackground autoparallaxbackground = new autoparallaxbackground(             0, 0, 0, 5);     autoparallaxbackground.addparallaxentity(new parallaxentity(2.7f,             new sprite(0, 0, this.mparallaxlayerinspired)));     scene.setbackground(autoparallaxbackground);  }    @override public void onloadresources() {     this.mtexture = new texture(2048, 2048, textureoptions.default);       this.mautoparallaxbackgroundtexture = new texture(2048, 2048,             textureoptions.default);     this.mparallaxlayermid1 = textureregionfactory.createfromasset(             this.mautoparallaxbackgroundtexture, this,      "gfx/middle1.png",0, 320);     this.mparallaxlayertop = textureregionfactory.createfromasset(             this.mautoparallaxbackgroundtexture, this, "gfx/top.png", 0, 0);     this.mparallaxlayertop2 = textureregionfactory.createfromasset(             this.mautoparallaxbackgroundtexture, this, "gfx/top2.png", 0, 173);     this.mparallaxlayermid2 = textureregionfactory.createfromasset(             this.mautoparallaxbackgroundtexture, this, "gfx/middle2.png",0, 450);     this.mparallaxlayerlow1 = textureregionfactory.createfromasset(             this.mautoparallaxbackgroundtexture, this, "gfx/lower1.png", 200,574);     this.mparallaxlayerlow2 = textureregionfactory.createfromasset(             this.mautoparallaxbackgroundtexture, this, "gfx/lower2.png", 0,740);     this.mengine.gettexturemanager().loadtextures(this.mtexture,             this.mautoparallaxbackgroundtexture);       this.mautoparallaxinspirationaltexture = new texture(2048, 2048,                 textureoptions.default);       this.mparallaxlayerinspired = textureregionfactory.createfromasset(                 this.mautoparallaxinspirationaltexture, this, "gfx/topinspired.png", 0, 0);      this.mengine.gettexturemanager().loadtextures(this.mtexture,                 this.mautoparallaxinspirationaltexture);     }  @override public scene onloadscene() {      final scene scene = new scene(1);     final autoparallaxbackground autoparallaxbackground = new autoparallaxbackground(             0, 0, 0, 5);     autoparallaxbackground.addparallaxentity(new parallaxentity(2.7f,             new sprite(0, 0, this.mparallaxlayertop)));     autoparallaxbackground.addparallaxentity(new parallaxentity(2.9f,             new sprite(0, 173, this.mparallaxlayertop2)));     autoparallaxbackground.addparallaxentity(new parallaxentity(2.4f,             new sprite(0, 320, this.mparallaxlayermid1)));     autoparallaxbackground.addparallaxentity(new parallaxentity(-1.4f,             new sprite(0, 450, this.mparallaxlayermid2)));     autoparallaxbackground.addparallaxentity(new parallaxentity(2.3f,             new sprite(200, 574, this.mparallaxlayerlow1)));     autoparallaxbackground.addparallaxentity(new parallaxentity(-4.1f,             new sprite(0, 740, this.mparallaxlayerlow2)));        scene.setbackground(autoparallaxbackground);         return scene;        }      private float setheight(int i) {     // todo auto-generated method stub     return 0; }  @override public void onloadcomplete() {  }  @override protected void ontap(final int px, final int py) {  }   } 

have updated settings class link livewallpaper , use same shared preference name?

for example;

public class settings extends preferenceactivity implements sharedpreferences.onsharedpreferencechangelistener { @override     protected void oncreate(bundle icicle) {         super.oncreate(icicle);         getpreferencemanager().setsharedpreferencesname(                 livewallpaper.shared_prefs_name); 

if don't won't of setting changes. i'm assuming using livewallpaper template can andengine site.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -