本文整理汇总了Java中android.app.WallpaperManager类的典型用法代码示例。如果您正苦于以下问题:Java WallpaperManager类的具体用法?Java WallpaperManager怎么用?Java WallpaperManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WallpaperManager类属于android.app包,在下文中一共展示了WallpaperManager类的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: onLayout
import android.app.WallpaperManager; //导入依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
int childLeft = lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);//对子对象进行布局。
if (lp.dropped) {
lp.dropped = false;
final int[] cellXY = mTmpCellXY;
getLocationOnScreen(cellXY);
mWallpaperManager.sendWallpaperCommand(getWindowToken(),
WallpaperManager.COMMAND_DROP,
cellXY[0] + childLeft + lp.width / 2,
cellXY[1] + childTop + lp.height / 2, 0, null);
}
}
}
}
示例3: onLayout
import android.app.WallpaperManager; //导入依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
if (child instanceof LauncherAppWidgetHostView) {
LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) child;
// Scale and center the widget to fit within its cells.
DeviceProfile profile = mLauncher.getDeviceProfile();
float scaleX = profile.appWidgetScale.x;
float scaleY = profile.appWidgetScale.y;
lahv.setScaleToFit(Math.min(scaleX, scaleY));
lahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f,
-(lp.height - (lp.height * scaleY)) / 2.0f);
}
int childLeft = lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
if (lp.dropped) {
lp.dropped = false;
final int[] cellXY = mTmpCellXY;
getLocationOnScreen(cellXY);
mWallpaperManager.sendWallpaperCommand(getWindowToken(),
WallpaperManager.COMMAND_DROP,
cellXY[0] + childLeft + lp.width / 2,
cellXY[1] + childTop + lp.height / 2, 0, null);
}
}
}
}
示例4: Workspace
import android.app.WallpaperManager; //导入依赖的package包/类
/**
* Used to inflate the Workspace from XML.
*
* @param context The application's context.
* @param attrs The attributes set containing the Workspace's customization values.
* @param defStyle Unused.
*/
public Workspace(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLauncher = Launcher.getLauncher(context);
mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
final Resources res = getResources();
DeviceProfile grid = mLauncher.getDeviceProfile();
mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens();
mWallpaperManager = WallpaperManager.getInstance(context);
mWallpaperOffset = new WallpaperOffsetInterpolator(this);
mOverviewModeShrinkFactor =
res.getInteger(R.integer.config_workspaceOverviewShrinkPercentage) / 100f;
setOnHierarchyChangeListener(this);
setHapticFeedbackEnabled(false);
initWorkspace();
// Disable multitouch across the workspace/all apps/customize tray
setMotionEventSplittingEnabled(true);
}
示例5: onCreate
import android.app.WallpaperManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Preference applyWallpaper = findPreference("applyWallpaper");
applyWallpaper.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(
WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(getActivity(), Wallpaper.class));
startActivity(intent);
return true;
}
});
}
示例6: screenshotWithWallpaper
import android.app.WallpaperManager; //导入依赖的package包/类
public static Bitmap screenshotWithWallpaper(Context context, View view, Rect clipRect) {
Bitmap bitmap = Bitmap.createBitmap(clipRect.width(), clipRect.height(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
// Translate for clipRect.
canvas.translate(-clipRect.left, -clipRect.top);
Drawable wallpaper = WallpaperManager.getInstance(context).getFastDrawable();
// Center wallpaper on screen, as in launcher.
DisplayMetrics displayMetrics = view.getResources().getDisplayMetrics();
wallpaper.setBounds(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
// Translate the canvas to draw wallpaper on the correct location.
int[] location = new int[2];
view.getLocationOnScreen(location);
canvas.save();
canvas.translate(-location[0], -location[1]);
wallpaper.draw(canvas);
canvas.restore();
view.draw(canvas);
return bitmap;
}
示例7: setWallpaper
import android.app.WallpaperManager; //导入依赖的package包/类
private void setWallpaper() {
Observable.just(null)
.compose(bindToLifecycle())
.compose(ensurePermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE))
.filter(granted -> {
if (granted) {
return true;
} else {
Toasty.info(this, getString(R.string.permission_required),
Toast.LENGTH_LONG).show();
return false;
}
})
.flatMap(granted -> download(picture.downloadUrl))
.map(file -> FileProvider.getUriForFile(this, AUTHORITIES, file))
.doOnNext(uri -> {
final WallpaperManager wm = WallpaperManager.getInstance(this);
startActivity(wm.getCropAndSetWallpaperIntent(uri));
})
.subscribe();
}
示例8: setLiveWallpaper
import android.app.WallpaperManager; //导入依赖的package包/类
/**
* 跳转到系统设置壁纸界面
*
* @param context
* @param paramActivity
*/
public static void setLiveWallpaper(Context context, Activity paramActivity, int requestCode) {
try {
Intent localIntent = new Intent();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {//ICE_CREAM_SANDWICH_MR1 15
localIntent.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);//android.service.wallpaper.CHANGE_LIVE_WALLPAPER
//android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT
localIntent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT
, new ComponentName(context.getApplicationContext().getPackageName()
, LiveWallpaperService.class.getCanonicalName()));
} else {
localIntent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);//android.service.wallpaper.LIVE_WALLPAPER_CHOOSER
}
paramActivity.startActivityForResult(localIntent, requestCode);
} catch (Exception localException) {
localException.printStackTrace();
}
}
示例9: 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();
}
}
示例10: loadWallpaper
import android.app.WallpaperManager; //导入依赖的package包/类
protected void loadWallpaper() {
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected void onPostExecute(Bitmap bitmap) {
mWallPaperView.showWallPaper(bitmap);
SetLockWallPaper(bitmap);
}
@Override
protected Bitmap doInBackground(Void... params) {
WallpaperManager wallpaperManager = WallpaperManager
.getInstance(mContext);
// 获取当前壁纸
return ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
}
}.execute();
}
示例11: setDefaultOnLock
import android.app.WallpaperManager; //导入依赖的package包/类
private boolean setDefaultOnLock(WallpaperPickerActivity a) {
boolean succeeded = true;
try {
Bitmap defaultWallpaper = ((BitmapDrawable) WallpaperManager.getInstance(
a.getApplicationContext()).getBuiltInDrawable()).getBitmap();
ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(2048);
if (defaultWallpaper.compress(Bitmap.CompressFormat.PNG, 100, tmpOut)) {
byte[] outByteArray = tmpOut.toByteArray();
WallpaperManagerCompat.getInstance(a.getApplicationContext())
.setStream(new ByteArrayInputStream(outByteArray), null,
true, WallpaperManagerCompat.FLAG_SET_LOCK);
}
} catch (IOException e) {
Log.w(TAG, "Setting wallpaper to default threw exception", e);
succeeded = false;
}
return succeeded;
}
示例12: onLayout
import android.app.WallpaperManager; //导入依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
int childLeft = lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
if (lp.dropped) {
lp.dropped = false;
final int[] cellXY = mTmpCellXY;
getLocationOnScreen(cellXY);
mWallpaperManager.sendWallpaperCommand(getWindowToken(),
WallpaperManager.COMMAND_DROP,
cellXY[0] + childLeft + lp.width / 2,
cellXY[1] + childTop + lp.height / 2, 0, null);
}
}
}
}
示例13: 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();
}
}
示例14: onClick
import android.app.WallpaperManager; //导入依赖的package包/类
@Override
public void onClick(WallpaperPickerActivity a) {
CropView c = a.getCropView();
Drawable defaultWallpaper = WallpaperManager.getInstance(a.getContext())
.getBuiltInDrawable(c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
if (defaultWallpaper == null) {
Log.w(TAG, "Null default wallpaper encountered.");
c.setTileSource(null, null);
return;
}
LoadRequest req = new LoadRequest();
req.moveToLeft = false;
req.touchEnabled = false;
req.scaleAndOffsetProvider = new CropViewScaleAndOffsetProvider();
req.result = new DrawableTileSource(a.getContext(),
defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE);
a.onLoadRequestComplete(req, true);
}
示例15: onClick
import android.app.WallpaperManager; //导入依赖的package包/类
@Override
public void onClick(WallpaperPickerActivity a) {
CropView c = a.getCropView();
Drawable defaultWallpaper = WallpaperManager.getInstance(a.getContext())
.getBuiltInDrawable(c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
if (defaultWallpaper == null) {
Log.w(TAG, "Null default wallpaper encountered.");
c.setTileSource(null, null);
return;
}
LoadRequest req = new LoadRequest();
req.moveToLeft = false;
req.touchEnabled = false;
req.scaleProvider = new CropViewScaleProvider() {
@Override
public float getScale(TileSource src) {
return 1f;
}
};
req.result = new DrawableTileSource(a.getContext(),
defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE);
a.onLoadRequestComplete(req, true);
}