本文整理汇总了Java中android.app.WallpaperManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java WallpaperManager.getInstance方法的具体用法?Java WallpaperManager.getInstance怎么用?Java WallpaperManager.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.WallpaperManager
的用法示例。
在下文中一共展示了WallpaperManager.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setColorWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
/**
* Create a color filled bitmap and changes the current system wallpaper to this bitmap.
*/
public static void setColorWallpaper(Context context, int color) throws IOException {
// Get the Wallpaper Manager
final WallpaperManager wpManager = WallpaperManager.getInstance(context);
// Create the pitch black bitmap
final Bitmap pitchBlackBitmap = createColorBitmap(color, MIN_SAFE_SIZE, MIN_SAFE_SIZE);
// Set the wallpaper
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// On Android N and above use the new API to set both the general system wallpaper and
// the lock-screen-specific wallpaper
wpManager.setBitmap(pitchBlackBitmap, null, true, WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK);
} else {
wpManager.setBitmap(pitchBlackBitmap);
}
}
示例2: setWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void setWallpaper() {
try {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
InputStream inputStream = getContentResolver().openInputStream(imageUri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Rect croppedRect = getCroppedRect();
wallpaperManager.setStream(inputStream, croppedRect, true);
} else {
wallpaperManager.setStream(inputStream);
}
SubsamplingScaleImageView imageView = findViewById(R.id.imageView);
imageView.recycle();
this.finish();
} catch (IOException | IllegalArgumentException e) {
e.printStackTrace();
Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
}
}
示例3: initSetWallpaperPrompt
import android.app.WallpaperManager; //导入方法依赖的package包/类
/**
* Prompt the user to set our app as live wallpaper if the user has not set it.
*/
private void initSetWallpaperPrompt() {
final WallpaperManager wm = WallpaperManager.getInstance(getApplicationContext());
if ((wm.getWallpaperInfo() != null && wm.getWallpaperInfo().getPackageName().equalsIgnoreCase(getPackageName()))) {
// We are good
} else {
// Ask user.
Snackbar.make(binding.coordinatorLayout, R.string.set_live_wallpaper_promt, Snackbar.LENGTH_INDEFINITE)
.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
launchSetWallpaperScreen();
}
}).show();
}
}
示例4: toSetWallPage
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void toSetWallPage(Uri data) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(mActivity);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
File wallpageFile = new File(data.getPath());
Uri contentUri = getImageContentUri(mActivity,wallpageFile.getAbsolutePath());
mActivity.startActivity(wallpaperManager.getCropAndSetWallpaperIntent(contentUri));
}else{
try {
wallpaperManager.setStream(mActivity.getContentResolver().openInputStream(data));
mView.showMsg(MyApplication.getInstance().getString(R.string.set_wallpaper_success));
} catch (IOException e) {
e.printStackTrace();
mView.showMsg(e.getMessage());
}
}
}
示例5: getBackground
import android.app.WallpaperManager; //导入方法依赖的package包/类
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);
}
示例6: getWallpaperDrawableWithSizeDrawable
import android.app.WallpaperManager; //导入方法依赖的package包/类
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;
}
示例7: handleCrop
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void handleCrop(int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
mImageView.setImageURI(Crop.getOutput(result));
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
try {
Bitmap mBitmap = getImageBitmap();
myWallpaperManager.setBitmap(mBitmap);
Toast.makeText(DetailActivity.this, "Wallpaper set",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(DetailActivity.this,
"Error setting wallpaper", Toast.LENGTH_SHORT)
.show();
}
} else if (resultCode == Crop.RESULT_ERROR) {
Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
}
}
示例8: setGradientWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
protected void setGradientWallpaper(ArrayList<String> colors) {
WallpaperManager wpManager = WallpaperManager.getInstance(this.getApplicationContext());
// Use full screen size so wallpaper is movable.
int height = wpManager.getDesiredMinimumHeight();
// Create square bitmap for wallpaper.
Bitmap wallpaperBitmap = Bitmap.createBitmap(height, height, Bitmap.Config.ARGB_8888);
// Prepare colors for gradient.
int[] colorsInt = new int[colors.size()];
for (int i = 0; i < colors.size(); i++) {
colorsInt[i] = Color.parseColor(colors.get(i));
}
// Create gradient shader.
Paint paint = new Paint();
Shader gradientShader = new LinearGradient(0, 0, height, height, colorsInt, null, Shader.TileMode.CLAMP);
Canvas c = new Canvas(wallpaperBitmap);
paint.setShader(gradientShader);
// Draw gradient on bitmap.
c.drawRect(0, 0, height, height, paint);
// Add noise.
//addNoise(wallpaperBitmap);
setBitmapAsWallpaper(wpManager, wallpaperBitmap);
// Cleanup.
wallpaperBitmap.recycle();
}
示例9: storeLastWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void storeLastWallpaper() throws IOException {
Context context = contextWeakReference.get();
WallpaperManager wallpaperMgr = WallpaperManager.getInstance(context);
File lastWallpaperFile = new File(context.getFilesDir(), LAST_WALLPAPER_FILE_NAME);
if (!lastWallpaperFile.createNewFile()) {
lastWallpaperFile.delete();
lastWallpaperFile.createNewFile();
}
if (wallpaperMgr.getDrawable() instanceof BitmapDrawable) {
FileOutputStream outputStream = context.openFileOutput(LAST_WALLPAPER_FILE_NAME,
Context.MODE_PRIVATE);
((BitmapDrawable)wallpaperMgr.getDrawable()).getBitmap().compress(
Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.close();
}
}
示例10: WallpaperOffsetInterpolator
import android.app.WallpaperManager; //导入方法依赖的package包/类
public WallpaperOffsetInterpolator(Workspace workspace) {
mChoreographer = Choreographer.getInstance();
mInterpolator = new DecelerateInterpolator(1.5f);
mWorkspace = workspace;
mWallpaperManager = WallpaperManager.getInstance(workspace.getContext());
mIsRtl = Utilities.isRtl(workspace.getResources());
}
示例11: setWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
public void setWallpaper(View v) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
wallpaperManager.setBitmap(Wallpaper);
Toast toast = Toast.makeText(this, "wallpaper set", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: onClick
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case 0:
boolean saveSuccess = false;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
if(ContextCompat.checkSelfPermission(getActivity(), permissions[0]) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(getActivity(),permissions,0);
}else {
saveSuccess = savePicture(pictureBitmap);
}
}else {
saveSuccess = savePicture(pictureBitmap);
}
if(saveSuccess){
Toast.makeText(getActivity(),"图片已存储在 /miaosou/picture 文件夹下",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getActivity(),"图片保存失败,请检查SD卡读写权限是否开启",Toast.LENGTH_SHORT).show();
}
break;
case 1:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getContext());
try {
wallpaperManager.setBitmap(pictureBitmap);
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
示例13: initBg
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void initBg() {
// 获取壁纸管理器
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable drawable = wallpaperManager.getDrawable();
// 获取当前壁纸
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
// 将Drawable,转成Bitmap
Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();
splashBg.setImageBitmap(bm);
}
示例14: onSetWallpaperForResource
import android.app.WallpaperManager; //导入方法依赖的package包/类
/**
* 使用资源文件设置壁纸
* 直接设置为壁纸,不会有任何界面和弹窗出现
*
* @param view
*/
public void onSetWallpaperForResource(View view) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {
wallpaperManager.setResource(R.raw.wallpaper);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//WallpaperManager.FLAG_LOCK WallpaperManager.FLAG_SYSTEM
// wallpaperManager.setResource(R.raw.wallpaper, WallpaperManager.FLAG_SYSTEM);
// }
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: clearWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
/**
* 清除壁纸
*
* @param view
*/
public void clearWallpaper(View view) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {
wallpaperManager.clear();
// clearWallpaper();
} catch (IOException e) {
e.printStackTrace();
}
}