EDIT : Added Y offset correction - thanks @Jason Goff!
Good, so it turns out that the minimum width of the initial screen on s3 is not 720, but actually 1280! You can find out the desired minimum width and height of the wallpaper by calling
wallpaperManager.getDesiredMinimumWidth();//returned 1280 on s3 wallpaperManager.getDesiredMinimumHeight();//also returned 1280 on s3
So, in order to apply the wallpaper to the center of the screen, I had to create an empty 1280x1280 raster map on the fly, and then lay my wallpaper in the center of the empty raster image, I created a static BitmapHelper class with methods for setting bitmaps, here are the methods for creating bitmaps and image overlay Wallpaper:
public class BitmapHelper { public static Bitmap overlayIntoCentre(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null);
and all my code uses my BitmapHelper:
private void applyWallpaperFromFile(final File file) { Bitmap wallpaperImage = BitmapFactory.decodeFile(file.getPath()); try { if((wallpaperManager.getDesiredMinimumWidth()>0)&&(wallpaperManager.getDesiredMinimumHeight()>0)) { Bitmap blank = BitmapHelper.createNewBitmap(wallpaperManager.getDesiredMinimumWidth(), wallpaperManager.getDesiredMinimumHeight()); Bitmap overlay = BitmapHelper.overlayIntoCentre(blank, wallpaperImage); wallpaperManager.setBitmap(overlay); } else { wallpaperManager.setBitmap(wallpaperImage); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(WallpaperActivity.this,"Wallpaper set to:"+file.getName(), Toast.LENGTH_SHORT).show(); } }); }
AndroidNoob
source share