I am creating an Android Live Wallpaper with Libgdx , It is just a circle on the screen which gets a random color and position and it slowly moves up . The issue is I want the program only in portrait mode but when i turn my phone it goes into landscape mode.
I have already tried changing the manifest file orientation to protrait android:screenOrientation="Portrait", and placing this.setRequestOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); in Android Launcher Class but nothing is working
Android Launcher Class
public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new CoreLWP(), config);
}
}
Live Wallpaper class
public class LiveWallpaper extends AndroidLiveWallpaperService {
public CoreLWP wallpaper;
@Override
public void onCreateApplication () {
super.onCreateApplication();
final AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
this.wallpaper = new CoreLWP();
initialize(this.wallpaper, config);
}
}
Core Live Wallpaper class
public class CoreLWP extends ApplicationAdapter implements ApplicationListener, AndroidWallpaperListener {
private ShapeRenderer ball;
private float x,y;
private Random random;
private float r,g,b;
@Override
public void create () {
ball = new ShapeRenderer();
random = new Random();
//generating random position
x = random.nextInt(Gdx.graphics.getWidth());
y = random.nextInt(Gdx.graphics.getHeight());
//generating random rgb values
r = getFloatRandomNum(0, 1) ;
g = getFloatRandomNum(0, 1) ;
b = getFloatRandomNum(0, 1) ;
}
@Override
public void render () {
//setting the background
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//updating x and y position
x = x + 0.5f;
y = y + 0.6f;
ball.begin(ShapeRenderer.ShapeType.Filled);
ball.setColor(r,g,b,1);
ball.circle(x,y,100);
ball.end();
}
//returns a random float number between a range
private float getFloatRandomNum(float min, float max) {
float random = min + new Random().nextFloat() * (max - min);
return random;
}
@Override
public void dispose () {
ball.dispose();
}
@Override
public void offsetChange(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {}
@Override
public void previewStateChange(boolean isPreview) {}
@Override
public void iconDropped(int x, int y) {}
}
Is it possible to do so . To fix the orientation only to portrait for the live wallpaper