android.app.WallpaperManager Java Examples

The following examples show how to use android.app.WallpaperManager. 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: PictureActivity.java    From Moment with GNU General Public License v3.0 7 votes vote down vote up
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();
}
 
Example #2
Source File: WallpaperCropActivity.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #3
Source File: AbstractRemoteViewsPresenter.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #4
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
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);
    }
 
Example #5
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: PhotoDetailPresenterImpl.java    From ZZShow with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: WallpaperPickerActivity.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: WallpaperEffectsFragment.java    From android-kernel-tweaker with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	super.onCreateView(inflater, container, savedInstanceState);
	View v = inflater.inflate(R.layout.wallpaper_effects, container,false);

	mWall = (ImageView) v.findViewById(R.id.wall);
	mBlur = (SeekBar) v.findViewById(R.id.sb_blur);
	mApply = (Button) v.findViewById(R.id.btn_apply);
	mWall.setDrawingCacheEnabled(true);
	mBlur.setMax(25);

	mBlur.setOnSeekBarChangeListener(this);
	mApply.setOnClickListener(this);
	
	wallpaperManager = WallpaperManager.getInstance(getActivity());
	final Drawable wallpaperDrawable = wallpaperManager.getDrawable();

	mWall.setImageDrawable(wallpaperDrawable);

	source = drawableToBitmap(wallpaperDrawable);

	return v;
}
 
Example #9
Source File: ShortcutAndWidgetContainer.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example #10
Source File: WallpaperUtils.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #11
Source File: ShortcutAndWidgetContainer.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example #12
Source File: WallpaperCropActivity.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
protected void updateWallpaperDimensions(int width, int height) {
    String spKey = getSharedPreferencesKey();
    SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
    SharedPreferences.Editor editor = sp.edit();
    if (width != 0 && height != 0) {
        editor.putInt(WALLPAPER_WIDTH_KEY, width);
        editor.putInt(WALLPAPER_HEIGHT_KEY, height);
    } else {
        editor.remove(WALLPAPER_WIDTH_KEY);
        editor.remove(WALLPAPER_HEIGHT_KEY);
    }
    editor.commit();

    suggestWallpaperDimension(getResources(),
            sp, getWindowManager(), WallpaperManager.getInstance(this));
}
 
Example #13
Source File: DetailActivity.java    From Dashboard with MIT License 6 votes vote down vote up
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 #14
Source File: PhotoViewerFragment.java    From glimmr with Apache License 2.0 6 votes vote down vote up
private void onWallpaperButtonClick() {
    Toast.makeText(mActivity, mActivity.getString(R.string.setting_wallpaper),
            Toast.LENGTH_SHORT).show();
    if (mBasePhoto != null) {
        String url = getLargestUrlAvailable(mBasePhoto);
        new DownloadPhotoTask(mActivity, new Events.IPhotoDownloadedListener() {
            @Override
            public void onPhotoDownloaded(Bitmap bitmap, Exception e) {
                if (e == null) {
                    WallpaperManager wallpaperManager = WallpaperManager.getInstance(mActivity);
                    try {
                        wallpaperManager.setBitmap(bitmap);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                } else {
                    Log.e(TAG, "Error setting wallpaper");
                    e.printStackTrace();
                }
            }
        }, url).execute();
    }
}
 
Example #15
Source File: DetailActivity.java    From Dashboard with MIT License 6 votes vote down vote up
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 #16
Source File: WallpaperPickerActivity.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(WallpaperPickerActivity a) {
    CropView c = a.getCropView();

    Drawable defaultWallpaper = WallpaperManager.getInstance(a).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;
    }

    c.setTileSource(
            new DrawableTileSource(a, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE), null);
    c.setScale(1f);
    c.setTouchEnabled(false);
    a.setSystemWallpaperVisiblity(false);
}
 
Example #17
Source File: SetWallpaperTask.java    From Theogony with MIT License 5 votes vote down vote up
@Override
protected Boolean doInBackground(Bitmap... params) {
    Bitmap bitmap = params[0];
    try {
        if (bitmap != null) {
            WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
            wallpaperManager.setBitmap(bitmap);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example #18
Source File: MainActivity.java    From drip-steps with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
	Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
	intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(MainActivity.this, DripWallpaperService.class));
	startActivity(intent);
	finish();
}
 
Example #19
Source File: Workspace.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);

    mOutlineHelper = HolographicOutlineHelper.obtain(context);

    mHideIconLabels = SettingsProvider.getBoolean(context,
            SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
            R.bool.preferences_interface_homescreen_hide_icon_labels_default);

    mLauncher = (Launcher) context;
    mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
    final Resources res = getResources();
    DeviceProfile grid = mLauncher.getDeviceProfile();
    mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens();
    mFadeInAdjacentScreens = false;
    mWallpaperManager = WallpaperManager.getInstance(context);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.Workspace, defStyle, 0);
    mSpringLoadedShrinkFactor =
            res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
    mOverviewModeShrinkFactor =
            res.getInteger(R.integer.config_workspaceOverviewShrinkPercentage) / 100f;
    mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
    a.recycle();

    setOnHierarchyChangeListener(this);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);
}
 
Example #20
Source File: wallpaper.java    From cordova-plugin-wallpaper with Apache License 2.0 5 votes vote down vote up
public void setlockwp(String image, Boolean base64, Context context)
{
	try
	{
		AssetManager assetManager = context.getAssets();
		Bitmap bitmap;
		if(base64) //Base64 encoded
		{
			byte[] decoded = android.util.Base64.decode(image, android.util.Base64.DEFAULT);
			bitmap = BitmapFactory.decodeByteArray(decoded, 0, decoded.length);
		}
		else //normal path
		{
			InputStream instr = assetManager.open("www/" + image);
			bitmap = BitmapFactory.decodeStream(instr);
		}
		if (android.os.Build.VERSION.SDK_INT>=24) {
			WallpaperManager ujWallpaperManager = WallpaperManager.getInstance(context);
			ujWallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK);
			Log.d("console", "lockscreen wallpaper set");
		}
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example #21
Source File: PlayDetailActivity.java    From BeMusic with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: Workspace.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
protected void onWallpaperTap(MotionEvent ev) {
    final int[] position = mTempCell;
    getLocationOnScreen(position);

    int pointerIndex = ev.getActionIndex();
    position[0] += (int) ev.getX(pointerIndex);
    position[1] += (int) ev.getY(pointerIndex);

    mWallpaperManager.sendWallpaperCommand(getWindowToken(),
            ev.getAction() == MotionEvent.ACTION_UP
                    ? WallpaperManager.COMMAND_TAP : WallpaperManager.COMMAND_SECONDARY_TAP,
            position[0], position[1], 0, null);
}
 
Example #23
Source File: WallpaperUtil.java    From earth with GNU General Public License v3.0 5 votes vote down vote up
static void changeLiveWallPaper(Context context) {
    Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);

    intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
            new ComponentName(context, EarthWallpaperService.class));

    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException ignored) {
    }
}
 
Example #24
Source File: SystemBitmap.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static Bitmap getWallpaperDrawableWithSizeBitmap(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);
    bm = BitmapUtils.setAlpha(bm, alpha);

    return bm;
}
 
Example #25
Source File: LockScreenWallPaper.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@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 #26
Source File: Desktop.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    Definitions.WallpaperScroll scroll = Setup.appSettings().getDesktopWallpaperScroll();
    float xOffset = (position + offset) / (_pages.size() - 1);
    if (scroll.equals(Inverse)) {
        xOffset = 1f - xOffset;
    } else if (scroll.equals(Off)) {
        xOffset = 0.5f;
    }

    WallpaperManager wallpaperManager = WallpaperManager.getInstance(getContext());
    wallpaperManager.setWallpaperOffsets(getWindowToken(), xOffset, 0.0f);
    super.onPageScrolled(position, offset, offsetPixels);
}
 
Example #27
Source File: MyScrollView.java    From palmsuda with Apache License 2.0 5 votes vote down vote up
public MyScrollView(Context context, AttributeSet attrs, int defStyle) {

		super(context, attrs, defStyle);
		mWallpaperManager = WallpaperManager.getInstance(context);
		mScroller = new Scroller(context);
		mCurScreen = mDefaultScreen;
		mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
	}
 
Example #28
Source File: PhotoUtil.java    From GankLock with GNU General Public License v3.0 5 votes vote down vote up
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 #29
Source File: WallpaperManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public WallpaperManagerService(Context context) {
    if (DEBUG) Slog.v(TAG, "WallpaperService startup");
    mContext = context;
    mShuttingDown = false;
    mImageWallpaper = ComponentName.unflattenFromString(
            context.getResources().getString(R.string.image_wallpaper_component));
    mDefaultWallpaperComponent = WallpaperManager.getDefaultWallpaperComponent(context);
    mIWindowManager = IWindowManager.Stub.asInterface(
            ServiceManager.getService(Context.WINDOW_SERVICE));
    mIPackageManager = AppGlobals.getPackageManager();
    mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
    mMonitor = new MyPackageMonitor();
    mColorsChangedListeners = new SparseArray<>();
}
 
Example #30
Source File: SetWallpaperActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
private void setWallpaper(int which) {
    try {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        InputStream inputStream = getContentResolver().openInputStream(imageUri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            Rect croppedRect = getCroppedRect();
            switch (which) {
                case HOME_SCREEN:
                    wallpaperManager.setStream(inputStream, croppedRect, true, WallpaperManager.FLAG_SYSTEM);
                    break;
                case LOCK_SCREEN:
                    wallpaperManager.setStream(inputStream, croppedRect, true, WallpaperManager.FLAG_LOCK);
                    break;
                case BOTH:
                    wallpaperManager.setStream(inputStream, croppedRect, true);
                    break;
            }
        } 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();
    }
}