本文整理汇总了Java中android.app.WallpaperManager.getDesiredMinimumHeight方法的典型用法代码示例。如果您正苦于以下问题:Java WallpaperManager.getDesiredMinimumHeight方法的具体用法?Java WallpaperManager.getDesiredMinimumHeight怎么用?Java WallpaperManager.getDesiredMinimumHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.WallpaperManager
的用法示例。
在下文中一共展示了WallpaperManager.getDesiredMinimumHeight方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: suggestWallpaperDimension
import android.app.WallpaperManager; //导入方法依赖的package包/类
public static void suggestWallpaperDimension(Resources res,
final SharedPreferences sharedPrefs,
WindowManager windowManager,
final WallpaperManager wallpaperManager, boolean fallBackToDefaults) {
final Point defaultWallpaperSize = WallpaperUtils.getDefaultWallpaperSize(res, windowManager);
// If we have saved a wallpaper width/height, use that instead
int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, -1);
int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, -1);
if (savedWidth == -1 || savedHeight == -1) {
if (!fallBackToDefaults) {
return;
} else {
savedWidth = defaultWallpaperSize.x;
savedHeight = defaultWallpaperSize.y;
}
}
if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
}
}
示例2: suggestWallpaperDimension
import android.app.WallpaperManager; //导入方法依赖的package包/类
static public void suggestWallpaperDimension(Resources res,
final SharedPreferences sharedPrefs,
WindowManager windowManager,
final WallpaperManager wallpaperManager, boolean fallBackToDefaults) {
final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager);
// If we have saved a wallpaper width/height, use that instead
int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, -1);
int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, -1);
if (savedWidth == -1 || savedHeight == -1) {
if (!fallBackToDefaults) {
return;
} else {
savedWidth = defaultWallpaperSize.x;
savedHeight = defaultWallpaperSize.y;
}
}
if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
}
}
示例3: 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();
}
示例4: setCustomLockscreenImage
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void setCustomLockscreenImage() {
Intent intent = new Intent(getActivity(), PickImageActivity.class);
intent.putExtra(PickImageActivity.EXTRA_CROP, true);
intent.putExtra(PickImageActivity.EXTRA_SCALE, true);
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point displaySize = new Point();
display.getRealSize(displaySize);
// Lock screen for tablets visible section are different in landscape/portrait,
// image need to be cropped correctly, like wallpaper setup for scrolling in background in home screen
// other wise it does not scale correctly
if (Utils.isTabletUI(getActivity())) {
WallpaperManager wpManager = WallpaperManager.getInstance(getActivity());
int wpWidth = wpManager.getDesiredMinimumWidth();
int wpHeight = wpManager.getDesiredMinimumHeight();
float spotlightX = (float) displaySize.x / wpWidth;
float spotlightY = (float) displaySize.y / wpHeight;
intent.putExtra(PickImageActivity.EXTRA_ASPECT_X, wpWidth);
intent.putExtra(PickImageActivity.EXTRA_ASPECT_Y, wpHeight);
intent.putExtra(PickImageActivity.EXTRA_OUTPUT_X, wpWidth);
intent.putExtra(PickImageActivity.EXTRA_OUTPUT_Y, wpHeight);
intent.putExtra(PickImageActivity.EXTRA_SPOTLIGHT_X, spotlightX);
intent.putExtra(PickImageActivity.EXTRA_SPOTLIGHT_Y, spotlightY);
} else {
boolean isPortrait = getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT;
intent.putExtra(PickImageActivity.EXTRA_ASPECT_X, isPortrait ? displaySize.x : displaySize.y);
intent.putExtra(PickImageActivity.EXTRA_ASPECT_Y, isPortrait ? displaySize.y : displaySize.x);
}
getActivity().startActivityFromFragment(this, intent, REQ_LOCKSCREEN_BACKGROUND);
}
示例5: loadSourceBitmap
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void loadSourceBitmap(final OnLoadSourceListener l) {
InputStream stream = getPhotoStream();
if (stream == null) {
return;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(stream, new Rect(0, 0, 0, 0), options);
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
WallpaperManager manager = WallpaperManager.getInstance(this);
int width;
int height;
if (1.0 * options.outWidth / options.outHeight
> 1.0 * manager.getDesiredMinimumWidth() / manager.getDesiredMinimumHeight()) {
width = (int) (1.0 * options.outWidth / options.outHeight * manager.getDesiredMinimumHeight());
height = manager.getDesiredMinimumHeight();
} else {
width = manager.getDesiredMinimumWidth();
height = (int) (1.0 * options.outHeight / options.outWidth * manager.getDesiredMinimumWidth());
}
ImageHelper.loadBitmap(
this,
new SimpleTarget<Bitmap>(width, height) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
if (l != null) {
l.onLoadSourceBitmap(resource);
}
}
},
getIntent().getData());
}
示例6: suggestWallpaperDimension
import android.app.WallpaperManager; //导入方法依赖的package包/类
static public void suggestWallpaperDimension(Resources res,
final SharedPreferences sharedPrefs,
WindowManager windowManager,
final WallpaperManager wallpaperManager) {
final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager);
// If we have saved a wallpaper width/height, use that instead
int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, defaultWallpaperSize.x);
int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y);
if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
}
}
示例7: onTryUpdate
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
protected void onTryUpdate(int reason) throws RetryException {
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint("http://h.bilibili.com")
.setExecutors(mExecutor, mMainExecutor)
.setClient(new ApacheClient(mClient))
.build();
BiliWallpaperService service = adapter.create(BiliWallpaperService.class);
List<Wallpaper> wallpapers = getWallpapers(service);
if (wallpapers == null) {
throw new RetryException();
}
if (wallpapers.isEmpty()) {
Log.w(TAG, "No wallpapers returned from API.");
scheduleUpdate(System.currentTimeMillis() + UPDATE_TIME_MILLIS);
return;
}
wallpapers.remove(0); // first item is banner place holder
final Wallpaper wallpaper = selectWallpaper(wallpapers);
final Wallpaper selectedPaper = getDetail(service, wallpaper);
if (selectedPaper == null) {
Log.w(TAG, "No details returned for selected paper from API. id=" + wallpaper.il_id);
throw new RetryException();
}
WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
int minimumHeight = manager.getDesiredMinimumHeight();
final Resolution pic = selectResolution(selectedPaper, minimumHeight);
publishArtwork(new Artwork.Builder()
.imageUri((Uri.parse(pic.il_file.replaceFirst("_m\\.", "_l\\."))))
.title(pic.title)
.token(String.valueOf(wallpaper.il_id))
.byline(wallpaper.author_name + ", "
+ DateFormat.format("yyyy-MM-dd", wallpaper.posttime * 1000)
+ "\n" + wallpaper.type)
.viewIntent(new Intent(Intent.ACTION_VIEW,
Uri.parse(wallpaper.author_url)))
.build());
scheduleUpdate(System.currentTimeMillis() + UPDATE_TIME_MILLIS);
}
示例8: setPlasmaWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
protected void setPlasmaWallpaper(ArrayList<String> colors) {
WallpaperManager wpManager = WallpaperManager.getInstance(this.getApplicationContext());
// Use half screen size for speed.
int height = wpManager.getDesiredMinimumHeight()/4;
int width = height;
// Create wallpaper bitmap.
Bitmap wallpaperBitmap = Bitmap.createBitmap(width, 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 to construct palette.
Paint paint = new Paint();
Bitmap gradientBitmap = Bitmap.createBitmap(256, 1, Bitmap.Config.ARGB_8888);
Shader gradientShader = new LinearGradient(0, 0, 255, 0, colorsInt, null, Shader.TileMode.MIRROR);
Canvas c = new Canvas(gradientBitmap);
paint.setShader(gradientShader);
// Draw gradient on bitmap.
c.drawRect(0, 0, 256, 1, paint);
int[] palette = new int[256];
//
for(int x = 0; x < 256; x++) {
palette[x] = gradientBitmap.getPixel(x, 0);
}
// Cleanup.
gradientBitmap.recycle();
// Generate plasma.
int[][] plasma = new int[width][height];
Random random = new Random();
// TODO: add n (and maybe spread) as parameter in Settings.
double n = 1.3; // Number of periods per wallpaper width.
double period = width / (n * 2 * 3.14);
double spread = period * 0.3;
double period1 = period - spread + spread*random.nextFloat();
double period2 = period - spread + spread*random.nextFloat();
double period3 = period - spread + spread*random.nextFloat();
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++) {
// Adding sines to get plasma value.
int value = (int)
(
128.0 + (128.0 * Math.sin(x / period1))
+ 128.0 + (128.0 * Math.sin(y / period2))
+ 128.0 + (128.0 * Math.sin((x + y) / period1))
+ 128.0 + (128.0 * Math.sin(Math.sqrt((double) (x * x + y * y)) / period3))
) / 4;
plasma[x][y] = value;
}
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++) {
int color = palette[plasma[x][y] % 256];
wallpaperBitmap.setPixel(x, y, color);
}
// TODO: Add noise as option in Settings.
//addNoise(wallpaperBitmap);
wallpaperBitmap = Bitmap.createScaledBitmap(wallpaperBitmap, wpManager.getDesiredMinimumHeight(), wpManager.getDesiredMinimumHeight(), true);
setBitmapAsWallpaper(wpManager, wallpaperBitmap);
// Cleanup.
wallpaperBitmap.recycle();
}
示例9: setStripesWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
protected void setStripesWallpaper(ArrayList<String> colors) {
WallpaperManager wpManager = WallpaperManager.getInstance(this.getApplicationContext());
// Use full screen size so wallpaper is movable.
int smallHeight = wpManager.getDesiredMinimumHeight();
int smallWidth = smallHeight;
// Big height to account for rotation.
int bigHeight = 2*smallHeight;
int bigWidth = bigHeight;
// Medium height for color distribution.
int middleHeight = (int) ((2*smallHeight)/Math.sqrt(2));
// Offset for cropping.
int offset = (bigHeight - middleHeight) / 2;
// Create square bitmap for wallpaper.
Bitmap bigBitmap = Bitmap.createBitmap(bigWidth, bigHeight, Bitmap.Config.ARGB_8888);
// Prepare colors.
int[] colorsInt = new int[colors.size()];
for (int i = 0; i < colors.size(); i++) {
colorsInt[i] = Color.parseColor(colors.get(i));
}
Canvas c = new Canvas(bigBitmap);
// Rotate canvas before drawing.
c.save();
c.rotate(-45, c.getWidth() / 2, c.getHeight() / 2);
Paint paint = new Paint();
float initStripeHeight = middleHeight / colors.size();
float initShadowHeight = (float) (middleHeight * 0.012);
int stripeSpread = (int) (initStripeHeight * 0.25); // Vary stripe height a bit.
float shadowSpread = initShadowHeight * 0.5f; // Vary shadow thickness too.
for (int i = colors.size() - 1; i >= 0; i--) { // Going upwards.
int stripeHeight;
float shadowThickness;
if (i == colors.size() - 1) { // Fill whole canvas with last color.
stripeHeight = bigHeight;
shadowThickness = 0;
} else {
stripeHeight = Math.round((i + 1) * initStripeHeight);
int dh = (int) (stripeSpread * Math.random() - stripeSpread / 2);
stripeHeight = offset + stripeHeight + dh;
if (stripeHeight < 0) stripeHeight = 0;
if (stripeHeight > bigHeight) stripeHeight = bigHeight;
float ds = (float) (shadowSpread * Math.random() - shadowSpread / 2);
shadowThickness = Math.max(1, initShadowHeight + ds);
}
paint.setColor(colorsInt[i]);
paint.setStyle(Paint.Style.FILL);
paint.setShadowLayer(shadowThickness, 0.0f, 0.0f, 0xFF000000);
c.drawRect(0, 0, bigWidth, stripeHeight, paint);
}
// Rotate canvas back.
c.restore();
// Crop to screen size.
int x = (c.getWidth() - smallWidth)/2;
int y = (c.getHeight() - smallHeight)/2;
Bitmap wallpaperBitmap = Bitmap.createBitmap(bigBitmap, x, y, smallWidth, smallHeight);
// Add noise.
//addNoise(wallpaperBitmap);
setBitmapAsWallpaper(wpManager, wallpaperBitmap);
// Cleanup.
bigBitmap.recycle();
wallpaperBitmap.recycle();
}