Java Code Examples for android.app.WallpaperManager#getInstance()
The following examples show how to use
android.app.WallpaperManager#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailActivity.java From Dashboard with MIT License | 6 votes |
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(); } }
Example 2
Source File: AbstractWidgetConfigActivity.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
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. } }
Example 3
Source File: PhotoDetailPresenterImpl.java From ZZShow with Apache License 2.0 | 6 votes |
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()); } } }
Example 4
Source File: AbstractRemoteViewsPresenter.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
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; } }
Example 5
Source File: WallpaperSetter.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 6 votes |
public static void set(String url, int setTo, Context context, SetWallpaperListener setWallpaperListener) { Toast.makeText(context, R.string.save_image_first, Toast.LENGTH_SHORT).show(); WallpaperManager wallpaperManager = WallpaperManager.getInstance(context); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Glide.with(context).asBitmap().load(url).into(new CustomTarget<Bitmap>() { @Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { new SetAsWallpaperAsyncTask(resource, setTo, wallpaperManager, windowManager, setWallpaperListener).execute(); } @Override public void onLoadCleared(@Nullable Drawable placeholder) { } }); }
Example 6
Source File: WidgetThemeListActivity.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
/** * 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); } } } }
Example 7
Source File: MainActivity.java From LiveWallpaper with Apache License 2.0 | 5 votes |
/** * 使用资源文件设置壁纸 * 直接设置为壁纸,不会有任何界面和弹窗出现 * * @param view */ public void onSetWallpaperForResource(View view) { // WallpaperManager manager =(WallpaperManager)getSystemService(WALLPAPER_SERVICE); 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(); } }
Example 8
Source File: LockScreenWallPaper.java From xDrip with GNU General Public License v3.0 | 5 votes |
@SuppressLint("WrongConstant") public static void setBitmap(final Bitmap bitmap) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { final WallpaperManager wallpaperManager = WallpaperManager.getInstance(xdrip.getAppContext()); final Bitmap wallpaper = BitmapUtil.getTiled(bitmap, getScreenWidth(), getScreenHeight(), isLockScreenBitmapTiled(), Pref.getString(NumberWallPreview.ViewModel.PREF_numberwall_background, null)); wallpaperManager.setBitmap(wallpaper, null, false, FLAG_LOCK); wallpaper.recycle(); } catch (Exception e) { UserError.Log.e(TAG, "Failed to set wallpaper: " + e); } } }
Example 9
Source File: DesktopSet.java From MainScreenShow with GNU General Public License v2.0 | 5 votes |
private boolean isStart() { String packageName = ""; WallpaperManager manager = WallpaperManager.getInstance(this); try { packageName = manager.getWallpaperInfo().getPackageName(); if (packageName.equals(getPackageName())) return true; } catch (Exception e) { } return false; }
Example 10
Source File: PhotoUtil.java From GankLock with GNU General Public License v3.0 | 5 votes |
public static void setWallPaper(Context context,File file){ WallpaperManager manager = WallpaperManager.getInstance(context); try { manager.setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath())); } catch (IOException e) { e.printStackTrace(); } }
Example 11
Source File: SetupService.java From astrobee_android with Apache License 2.0 | 5 votes |
protected void onHandleIntent(final Intent intent) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.astrobee_logo_modified_background); WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext()); Rect cropHints = new Rect(630, 0, 2250, 1620); try { manager.setBitmap(bitmap, cropHints, false); } catch (IOException e) { e.printStackTrace(); } }
Example 12
Source File: MainActivity.java From LiveWallpaper with Apache License 2.0 | 5 votes |
/** * 清除壁纸 * * @param view */ public void clearWallpaper(View view) { WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); try { wallpaperManager.clear(); // 已过时的Api // clearWallpaper(); } catch (IOException e) { e.printStackTrace(); } }
Example 13
Source File: PlayDetailActivity.java From BeMusic with Apache License 2.0 | 5 votes |
private void setWallpaper () { WallpaperManager manager = WallpaperManager.getInstance(this); boolean canSetWallpaper = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { canSetWallpaper &= manager.isWallpaperSupported(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { canSetWallpaper &= manager.isSetWallpaperAllowed(); } if (canSetWallpaper) { Song song = PlayManager.getInstance(this).getCurrentSong(); if (song != null) { Album album = song.getAlbumObj(); if (album == null) { return; } File source = new File(album.getAlbumArt()); if (source.exists()) { Bitmap bmp = BitmapFactory.decodeFile(source.getAbsolutePath()); try { manager.setBitmap(bmp); } catch (IOException e) { e.printStackTrace(); } finally { bmp.recycle(); } } } } }
Example 14
Source File: ColorExtractionService.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.N) private Palette getStatusBarPalette() { WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); int statusBarHeight = getResources() .getDimensionPixelSize(R.dimen.status_bar_height); if (AndroidVersion.isAtLeastNougat) { try (ParcelFileDescriptor fd = wallpaperManager .getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) { BitmapRegionDecoder decoder = BitmapRegionDecoder .newInstance(fd.getFileDescriptor(), false); Rect decodeRegion = new Rect(0, 0, decoder.getWidth(), statusBarHeight); Bitmap bitmap = decoder.decodeRegion(decodeRegion, null); decoder.recycle(); if (bitmap != null) { return Palette.from(bitmap).clearFilters().generate(); } } catch (IOException | NullPointerException e) { e.printStackTrace(); } } Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap(); return Palette.from(wallpaper) .setRegion(0, 0, wallpaper.getWidth(), statusBarHeight) .clearFilters() .generate(); }
Example 15
Source File: ColorExtractionService.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.N) private Palette getHotseatPalette() { WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); if (AndroidVersion.isAtLeastNougat) { try (ParcelFileDescriptor fd = wallpaperManager .getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) { BitmapRegionDecoder decoder = BitmapRegionDecoder .newInstance(fd.getFileDescriptor(), false); int height = decoder.getHeight(); Rect decodeRegion = new Rect(0, (int) (height * (1f - HOTSEAT_FRACTION)), decoder.getWidth(), height); Bitmap bitmap = decoder.decodeRegion(decodeRegion, null); decoder.recycle(); if (bitmap != null) { return Palette.from(bitmap).clearFilters().generate(); } } catch (IOException | NullPointerException e) { e.printStackTrace(); } } Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap(); return Palette.from(wallpaper) .setRegion(0, (int) (wallpaper.getHeight() * (1f - HOTSEAT_FRACTION)), wallpaper.getWidth(), wallpaper.getHeight()) .clearFilters() .generate(); }
Example 16
Source File: Workspace.java From TurboLauncher with Apache License 2.0 | 4 votes |
/** * 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); mContentIsRefreshable = false; mOutlineHelper = HolographicOutlineHelper.obtain(context); mDragEnforcer = new DropTarget.DragEnforcer(context); // With workspace, data is available straight from the get-go setDataIsReady(); mShowSearchBar = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH, R.bool.preferences_interface_homescreen_search_default); mShowOutlines = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_SCROLLING_PAGE_OUTLINES, R.bool.preferences_interface_homescreen_scrolling_page_outlines_default); mHideIconLabels = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS, R.bool.preferences_interface_homescreen_hide_icon_labels_default); mWorkspaceFadeInAdjacentScreens = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_SCROLLING_FADE_ADJACENT, R.bool.preferences_interface_homescreen_scrolling_fade_adjacent_default); TransitionEffect.setFromString(this, SettingsProvider.getString(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_SCROLLING_TRANSITION_EFFECT, R.string.preferences_interface_homescreen_scrolling_transition_effect)); mLauncher = (Launcher) context; final Resources res = getResources(); mFadeInAdjacentScreens = false; mWallpaperManager = WallpaperManager.getInstance(context); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0); mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; mOverviewModeShrinkFactor = grid.getOverviewModeScale(); mCameraDistance = res.getInteger(R.integer.config_cameraDistance); mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1); mDefaultScreenId = SettingsProvider.getLongCustomDefault(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_DEFAULT_SCREEN_ID, -1); a.recycle(); setOnHierarchyChangeListener(this); setHapticFeedbackEnabled(false); initWorkspace(); // Disable multitouch across the workspace/all apps/customize tray setMotionEventSplittingEnabled(true); setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); }
Example 17
Source File: ShortcutAndWidgetContainer.java From Trebuchet with GNU General Public License v3.0 | 4 votes |
public ShortcutAndWidgetContainer(Context context) { super(context); mLauncher = (Launcher) context; mWallpaperManager = WallpaperManager.getInstance(context); }
Example 18
Source File: BiliWallpaperSource.java From muzei-bilibili with Apache License 2.0 | 4 votes |
@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); }
Example 19
Source File: ShortcutAndWidgetContainer.java From TurboLauncher with Apache License 2.0 | 4 votes |
public ShortcutAndWidgetContainer(Context context) { super(context); mWallpaperManager = WallpaperManager.getInstance(context); }
Example 20
Source File: WallpaperFactory.java From NotificationPeekPort with Apache License 2.0 | 4 votes |
public WallpaperFactory(Context context) { this.mContext = context; mWallpaperManager = WallpaperManager.getInstance(context); }