Java Code Examples for android.app.WallpaperManager#getDrawable()

The following examples show how to use android.app.WallpaperManager#getDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRemoteViewsPresenter.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static boolean isLightWallpaper(Context context) {
    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        return false;
    }

    try {
        WallpaperManager manager = WallpaperManager.getInstance(context);
        if (manager == null) {
            return false;
        }

        Drawable drawable = manager.getDrawable();
        if (!(drawable instanceof BitmapDrawable)) {
            return false;
        }

        return DisplayUtils.isLightColor(
                DisplayUtils.bitmapToColorInt(((BitmapDrawable) drawable).getBitmap())
        );
    } catch (Exception ignore) {
        return false;
    }
}
 
Example 2
Source File: AbstractWidgetConfigActivity.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void bindWallpaper(boolean checkPermissions) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkPermissions) {
        boolean hasPermission = checkPermissions((requestCode, permission, grantResult) -> {
            bindWallpaper(false);
            if (textColorValueNow.equals("auto")) {
                updateHostView();
            }
        });
        if (!hasPermission) {
            return;
        }
    }

    try {
        WallpaperManager manager = WallpaperManager.getInstance(this);
        if (manager != null) {
            Drawable drawable = manager.getDrawable();
            if (drawable != null) {
                wallpaper.setImageDrawable(drawable);
            }
        }
    } catch (Exception ignore) {
        // do nothing.
    }
}
 
Example 3
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
public static BitmapDrawable getBackground(Context context) {

        WallpaperManager wallpaperManager = WallpaperManager
                .getInstance(context);
        // 获取当前壁纸
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();
        // 将Drawable,转成Bitmap
        Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
        float step = 0;
        // 计算出屏幕的偏移量
        step = (bm.getWidth() - 480) / (7 - 1);
        // 截取相应屏幕的Bitmap
        DisplayMetrics dm = new DisplayMetrics();
        Bitmap pbm = Bitmap.createBitmap(bm, (int) (5 * step), 0,
                dm.widthPixels, dm.heightPixels);

        return new BitmapDrawable(pbm);
    }
 
Example 4
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
public static Drawable getWallpaperDrawableWithSizeDrawable(Context context,
                                                            int width, int height, int alpha) {

    WallpaperManager wallpaperManager = WallpaperManager
            .getInstance(context);
    // 获取当前壁纸
    Drawable wallpaperDrawable = wallpaperManager.getDrawable();
    // 将Drawable,转成Bitmap
    Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
    bm = BitmapUtils.getAdpterBitmap(bm, width, height);
    Drawable d = BitmapUtils.Bitmap2Drawable(bm);
    bm = BitmapUtils.setAlpha(bm, alpha);
    if (bm != null && bm.isRecycled()) {
        bm.recycle();
    }
    return d;
}
 
Example 5
Source File: WidgetThemeListActivity.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set activity background to match home screen wallpaper.
 */
protected void initWallpaper(boolean animate)
{
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    if (wallpaperManager != null)
    {
        ImageView background = (ImageView)findViewById(R.id.themegrid_background);
        Drawable wallpaper = wallpaperManager.getDrawable();
        if (background != null && wallpaper != null)
        {
            background.setImageDrawable(wallpaper);
            background.setVisibility(View.VISIBLE);

            if (Build.VERSION.SDK_INT >= 12)
            {
                if (animate) {
                    background.animate().alpha(1f).setDuration(WALLPAPER_DELAY);
                } else background.setAlpha(1f);

            } else if (Build.VERSION.SDK_INT >= 11) {
                background.setAlpha(1f);
            }
        }
    }
}
 
Example 6
Source File: Tool.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private Bitmap getActiveWallPaper()
{
    final WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
    final Drawable wallpaperDrawable = wallpaperManager.getDrawable();

    Bitmap bmp = ((BitmapDrawable)wallpaperDrawable).getBitmap();
    if(bmp.getWidth()>0) return bmp.copy(bmp.getConfig(),true);
    return Bitmap.createBitmap(150,150, Bitmap.Config.ARGB_8888);
}
 
Example 7
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static Bitmap getWallpaper(Context context) {

        WallpaperManager wallpaperManager = WallpaperManager
                .getInstance(context);
        // 获取当前壁纸
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();
        // 将Drawable,转成Bitmap
        Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();

        return bm;
        // return new BitmapDrawable(bm);
    }
 
Example 8
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static Drawable getWallpaperDrawable(Context context) {

        WallpaperManager wallpaperManager = WallpaperManager
                .getInstance(context);
        // 获取当前壁纸
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();
        // 将Drawable,转成Bitmap
        Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
        Drawable d = BitmapUtils.Bitmap2Drawable(bm);
        if (bm != null && bm.isRecycled()) {
            bm.recycle();
        }
        return d;

    }
 
Example 9
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static Bitmap getWallpaperDrawableWithSizeBitmap(Context context,
                                                        int width, int height, int alpha) {

    WallpaperManager wallpaperManager = WallpaperManager
            .getInstance(context);
    // 获取当前壁纸
    Drawable wallpaperDrawable = wallpaperManager.getDrawable();
    // 将Drawable,转成Bitmap
    Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
    bm = BitmapUtils.getAdpterBitmap(bm, width, height);
    bm = BitmapUtils.setAlpha(bm, alpha);

    return bm;
}
 
Example 10
Source File: Utils.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @return The {@link Bitmap} for the current wallpaper, or null if none exists.
 */
public static Bitmap getWallpaperBitmap(WallpaperManager wManager, Context mContext) {
    if (null == wManager || null == mContext) return null;
    final Bitmap wallpaper = getCurrentWallpaperLocked(wManager, mContext);
    if (null != wallpaper) return wallpaper;
    final Drawable wallpaperD = wManager.getDrawable();
    if (null != wallpaperD) {
        return drawableToBitmap(wallpaperD);
    }
    return null;
}
 
Example 11
Source File: WidgetThemeConfigActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
protected void initWallpaper()
{
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    if (wallpaperManager != null)
    {
        ImageView background = (ImageView)findViewById(R.id.preview_background);
        Drawable wallpaper = wallpaperManager.getDrawable();
        if (background != null && wallpaper != null)
        {
            background.setImageDrawable(wallpaper);
        }
    }
}
 
Example 12
Source File: Utils.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @return The {@link Bitmap} for the current wallpaper, or null if none exists.
 */
public static Bitmap getWallpaperBitmap(WallpaperManager wManager, Context mContext) {
    if (null == wManager || null == mContext) return null;
    final Bitmap wallpaper = getCurrentWallpaperLocked(wManager, mContext);
    if (null != wallpaper) return wallpaper;
    final Drawable wallpaperD = wManager.getDrawable();
    if (null != wallpaperD) {
        return drawableToBitmap(wallpaperD);
    }
    return null;
}
 
Example 13
Source File: MainActivity.java    From DelegateAdapter with Apache License 2.0 4 votes vote down vote up
private void refreshWallpaper () {
    final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
    mCoverIv.setImageDrawable(wallpaperDrawable);
}