I wrote a simple application that sets the wallpaper on the device. I can't achieve one effect. I wish the picture automatically centrated horizontally. This means that the center of the image was on the most central desktop of Luncher app.
The picture at the bottom shows how it looks now:
Effect that I want to achieve:
And the image itself:
I tried to use the code from this question, however, did not achieve the desired effect.
My code:
public class SystemWallpaperHelper {
private Context context;
private ImageLoader imageLoader;
private DisplayImageOptions imageLoaderOptions;
public SystemWallpaperHelper(Context context){
this.context = context;
setImageLoaderOptions();
}
private void setImageLoaderOptions() {
final int width = SharedHelper.getDeviceWidth(context) << 1 ; // best wallpaper width is twice screen width
imageLoaderOptions = new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.NONE)
.cacheInMemory(false)
.cacheOnDisk(false)
.postProcessor(new BitmapProcessor() {
@Override
public Bitmap process(Bitmap bmp) {
float scale = (float) width / bmp.getWidth() ;
int height = (int) (scale * bmp.getHeight());
return Bitmap.createScaledBitmap(bmp, width, height, false);
}
})
.build();
imageLoader = ImageLoader.getInstance();
}
public void setDeviceWallpaper(Wallpaper wallpaper){
imageLoader.loadImage(wallpaper.getSrcUrl(), imageLoaderOptions, new SimpleImageLoadingListener(){
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage)
{
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
try {
wallpaperManager.setBitmap(loadedImage);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}