Example usage for android.app WallpaperManager getFastDrawable

List of usage examples for android.app WallpaperManager getFastDrawable

Introduction

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

Prototype

@RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
public Drawable getFastDrawable() 

Source Link

Document

Like #getDrawable() , but the returned Drawable has a number of limitations to reduce its overhead as much as possible.

Usage

From source file:uk.co.humbell.anoted.MainActivity.java

private void setupTheme() {

    /*// w w  w.  ja v a  2  s  . co  m
     * We can't use android's resources before we set the theme ({@link #setTheme})
     * The constraints below need to be the same as the constants defined in
     * "res/values/strings_activity_settings.xml"
    */
    final String PREF_KEY_THEME = "pref_theme";
    final String PREF_KEY_ENABLE_TRANSPARENCY = "pref_transparency";
    final String PREF_VALUE_THEME_LIGHT = "light";
    final String PREF_VALUE_THEME_DARK = "dark";

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String theme = prefs.getString(PREF_KEY_THEME, PREF_VALUE_THEME_LIGHT);
    Boolean wantsTransparency = prefs.getBoolean(PREF_KEY_ENABLE_TRANSPARENCY, false);

    if (theme.equals(PREF_VALUE_THEME_DARK) && wantsTransparency == false) {
        setTheme(R.style.AppTheme);
    }

    else if (theme.equals(PREF_VALUE_THEME_DARK) && wantsTransparency == true) {
        setTheme(R.style.AppTheme_Trans_Dark);
    }

    else if (theme.equals(PREF_VALUE_THEME_LIGHT) && wantsTransparency == false) {
        setTheme(R.style.AppTheme_Light);
    }

    else if (theme.equals(PREF_VALUE_THEME_LIGHT) && wantsTransparency == true) {
        setTheme(R.style.AppTheme_Trans_Light);
    }

    if (wantsTransparency) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        getWindow().setBackgroundDrawable(wallpaperManager.getFastDrawable());
    }
}

From source file:jahirfiquitiva.iconshowcase.activities.ShowcaseActivity.java

public static void setupToolbarHeader(Context context, ImageView toolbarHeader) {

    if (themeMode) {
        wallpaperDrawable = ContextCompat.getDrawable(context, R.drawable.heroimage);
        toolbarHeader.setImageDrawable(wallpaperDrawable);
        toolbarHeaderImage = Utils.drawableToBitmap(wallpaperDrawable);
    } else if (ENABLE_USER_WALLPAPER_IN_TOOLBAR && mPrefs.getWallpaperAsToolbarHeaderEnabled()) {
        WallpaperManager wm = WallpaperManager.getInstance(context);

        if (wm != null) {
            Drawable currentWallpaper = wm.getFastDrawable();
            if (currentWallpaper != null) {
                toolbarHeader.setAlpha(0.9f);
                toolbarHeader.setImageDrawable(currentWallpaper);
                wallpaperDrawable = currentWallpaper;
                toolbarHeaderImage = Utils.drawableToBitmap(currentWallpaper);
            }//from  w ww.  j av  a 2  s . co  m
        }
    } else {
        String[] wallpapers = context.getResources().getStringArray(R.array.wallpapers);

        if (wallpapers.length > 0) {
            int res;
            ArrayList<Integer> wallpapersArray = new ArrayList<>();

            for (String wallpaper : wallpapers) {
                res = context.getResources().getIdentifier(wallpaper, "drawable", context.getPackageName());
                if (res != 0) {
                    final int thumbRes = context.getResources().getIdentifier(wallpaper, "drawable",
                            context.getPackageName());
                    if (thumbRes != 0) {
                        wallpapersArray.add(thumbRes);
                    }
                }
            }

            Random random = new Random();

            if (wallpaper == -1) {
                wallpaper = random.nextInt(wallpapersArray.size());
            }

            wallpaperDrawable = ContextCompat.getDrawable(context, wallpapersArray.get(wallpaper));
            toolbarHeader.setImageDrawable(wallpaperDrawable);
            toolbarHeaderImage = Utils
                    .drawableToBitmap(ContextCompat.getDrawable(context, wallpapersArray.get(wallpaper)));
        }
    }

    toolbarHeader.setVisibility(View.VISIBLE);
}