gpt4 book ai didi

java - 帮助设置和 Android 动态壁纸

转载 作者:行者123 更新时间:2023-11-29 22:31:21 27 4
gpt4 key购买 nike

基本上我想要做的是当首选项从默认切换到任何加载一组新的视差背景时。现在的代码可能过于复杂并且可能完全关闭当我切换我的首选项时没有任何变化。您绝对可以看出我是新手,但非常感谢您的帮助,我很乐意在发布时在应用程序中注明您的姓名。另外,如果您需要更多代码,请询问。

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) {

}

}

最佳答案

您是否更新了设置类以链接到您的动态壁纸并使用相同的共享首选项名称?

例如;

public class Settings extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getPreferenceManager().setSharedPreferencesName(
livewallpaper.SHARED_PREFS_NAME);

如果您不这样做,您将不会获得任何设置更改。我假设您使用的是可以从 andengine 网站获得的动态壁纸模板。

关于java - 帮助设置和 Android 动态壁纸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3877677/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com