本文整理匯總了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();
}
}