android.app.WallpaperManager#getDrawable ( )源码实例Demo

下面列出了android.app.WallpaperManager#getDrawable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
    }
}
 
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.
    }
}
 
源代码3 项目: BigApp_Discuz_Android   文件: SystemBitmap.java
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);
    }
 
源代码4 项目: BigApp_Discuz_Android   文件: SystemBitmap.java
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;
}
 
源代码5 项目: SuntimesWidget   文件: WidgetThemeListActivity.java
/**
 * 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);
            }
        }
    }
}
 
源代码6 项目: MusicPlayer   文件: Tool.java
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);
}
 
源代码7 项目: BigApp_Discuz_Android   文件: SystemBitmap.java
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);
    }
 
源代码8 项目: BigApp_Discuz_Android   文件: SystemBitmap.java
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;

    }
 
源代码9 项目: BigApp_Discuz_Android   文件: SystemBitmap.java
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;
}
 
源代码10 项目: Noyze   文件: Utils.java
/**
 * @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;
}
 
源代码11 项目: SuntimesWidget   文件: WidgetThemeConfigActivity.java
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);
        }
    }
}
 
源代码12 项目: Noyze   文件: Utils.java
/**
 * @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;
}
 
源代码13 项目: DelegateAdapter   文件: MainActivity.java
private void refreshWallpaper () {
    final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
    mCoverIv.setImageDrawable(wallpaperDrawable);
}