Example usage for android.app WallpaperManager getDrawable

List of usage examples for android.app WallpaperManager getDrawable

Introduction

In this page you can find the example usage for android.app WallpaperManager getDrawable.

Prototype

public Drawable getDrawable() 

Source Link

Document

Retrieve the current system wallpaper; if no wallpaper is set, the system built-in static wallpaper is returned.

Usage

From source file:Main.java

public static Drawable getWallpaperDrawable(Context context) {
    WallpaperManager wallpaperManager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
    return wallpaperManager.getDrawable();
}

From source file:com.example.app_2.utils.Utils.java

public static void setWallpaper(android.view.ViewGroup vg, int reqWidth, int reqHeight, Bitmap wallpaper,
        ScalingLogic sl) {/*from   ww w .  ja v a 2s  . c  om*/

    if (wallpaper == null) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(App_2.getAppContext());
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();
        wallpaper = BitmapCalc.drawableToBitmap(wallpaperDrawable);
    }

    if (reqHeight == 0 || reqWidth == 0) {
        reqHeight = App_2.getMaxHeight();
        reqWidth = App_2.getMaxWidth();
    }

    Resources r = App_2.getAppContext().getResources();
    int orientation = r.getConfiguration().orientation;

    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE: // landscape
        Bitmap wallpaperLandscape = ScalingUtilities.createScaledBitmap(wallpaper, reqHeight, reqWidth, sl);
        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperLandscape));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            }

        }
        //wallpaperLandscape.recycle();
        break;
    case Configuration.ORIENTATION_PORTRAIT: // portrait
        Bitmap wallpaperPortrait = ScalingUtilities.createScaledBitmap(wallpaper, reqWidth, reqHeight, sl);

        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperPortrait));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            }
        }
        //wallpaperPortrait.recycle();
        break;
    default:
        //ll.setBackgroundDrawable(App_2.wallpaperDrawable);
        break;
    }
}