Java 类android.app.WallpaperManager 实例源码

项目:SimpleUILauncher    文件:ShortcutAndWidgetContainer.java   
@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);
            }
        }
    }
}
项目:LoneColor-Android    文件:ColorWallpaper.java   
/**
 * 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);
    }
}
项目:LaunchEnr    文件:ShortcutAndWidgetContainer.java   
@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);
            }
        }
    }
}
项目:LaunchEnr    文件:Workspace.java   
/**
 * 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);
}
项目:HexColorTime    文件:Preferences.java   
@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;
        }
    });
}
项目:GeekZone    文件:ScreenshotUtils.java   
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;
    }
项目:Moment    文件:PictureActivity.java   
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();
}
项目:LiveWallpaper    文件:WallpaperUtil.java   
/**
 * 跳转到系统设置壁纸界面
 *
 * @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();
    }
}
项目:chameleon-live-wallpaper    文件:MainActivity.java   
/**
 * 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();
    }
}
项目:TextEmoji    文件:WallpaperPresenter.java   
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();
}
项目:FlickLauncher    文件:DefaultWallpaperInfo.java   
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;
}
项目:FlickLauncher    文件:ShortcutAndWidgetContainer.java   
@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);
            }
        }
    }
}
项目:FlickLauncher    文件:Workspace.java   
/**
 * 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);
}
项目:Camera-Roll-Android-App    文件:SetWallpaperActivity.java   
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();
    }
}
项目:SimpleUILauncher    文件:WallpaperPickerActivity.java   
@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);
}
项目:SimpleUILauncher    文件:Workspace.java   
/**
 * 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);
}
项目:SimplOS    文件:WallpaperPickerActivity.java   
@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);
}
项目:SimplOS    文件:ShortcutAndWidgetContainer.java   
@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);
            }
        }
    }
}
项目:SimplOS    文件:WallpaperUtils.java   
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);
    }
}
项目:BigApp_Discuz_Android    文件:SystemBitmap.java   
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);
    }
项目:BigApp_Discuz_Android    文件:SystemBitmap.java   
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;
}
项目:Fire-Bird-Dashboard-for-Zooper    文件:DetailActivity.java   
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();
    }
}
项目:ZZShow    文件:PhotoDetailPresenterImpl.java   
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());
        }
    }
}
项目:Trebuchet    文件:WallpaperPickerActivity.java   
@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);
}
项目:Trebuchet    文件:ShortcutAndWidgetContainer.java   
@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);
            }
        }
    }
}
项目:Trebuchet    文件:WallpaperUtils.java   
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);
    }
}
项目:quotograph    文件:LWQActivateActivity.java   
@OnClick(R.id.button_lwq_activate)
void activate() {
    try {
        startActivity(new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
                .putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                        new ComponentName(LWQActivateActivity.this, LWQWallpaperService.class))
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        Toast.makeText(LWQActivateActivity.this,
                getString(R.string.toast_tap_set_wallpaper), Toast.LENGTH_LONG).show();
    } catch (ActivityNotFoundException e) {
        try {
            startActivity(new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER)
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
            Toast.makeText(LWQActivateActivity.this,
                    getString(R.string.toast_tap_set_wallpaper), Toast.LENGTH_LONG).show();
        } catch (ActivityNotFoundException e2) {
            Toast.makeText(LWQActivateActivity.this, R.string.error_wallpaper_chooser,
                    Toast.LENGTH_LONG).show();
        }
    }
    // Log tutorial as completed
    AnalyticsUtils.trackTutorial(false);
}
项目:TurboLauncher    文件:WallpaperPickerActivity.java   
@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);
}
项目:TurboLauncher    文件:WallpaperCropActivity.java   
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));
}
项目:TurboLauncher    文件:ShortcutAndWidgetContainer.java   
@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);
            }
        }
    }
}
项目:FLauncher    文件:WallpaperPickerActivity.java   
@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);
}
项目:FLauncher    文件:ShortcutAndWidgetContainer.java   
@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);
            }
        }
    }
}
项目:AndroidLiveWallpaperHelloWorld    文件:MuzeiWallpaperService.java   
@Override
public Bundle onCommand(String action, int x, int y, int z, Bundle extras,
        boolean resultRequested) {
    // mValidDoubleTap previously set in the gesture listener
    if (WallpaperManager.COMMAND_TAP.equals(action) && mValidDoubleTap) {
        // Temporarily toggle focused/blurred
        queueEvent(new Runnable() {
            @Override
            public void run() {
                // this triggers reloading of the next image
                mRenderController.reloadCurrentArtwork(true);
            }
        });
        // Reset the flag
        mValidDoubleTap = false;
    }
    return super.onCommand(action, x, y, z, extras, resultRequested);
}
项目:AndroidLiveWallpaperHelloWorld    文件:MuzeiActivity.java   
private void setupIntroModeUi() {
    findViewById(R.id.activate_muzei_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                startActivity(new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
                        .putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                                new ComponentName(MuzeiActivity.this,
                                        MuzeiWallpaperService.class))
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
            } catch (ActivityNotFoundException e) {
                try {
                    startActivity(new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER)
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (ActivityNotFoundException e2) {
                    Toast.makeText(MuzeiActivity.this, R.string.error_wallpaper_chooser,
                            Toast.LENGTH_LONG).show();
                }
            }
        }
    });
}
项目:WallpaperPicker    文件:WallpaperPickerActivity.java   
@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);
}
项目:WallpaperPicker    文件:WallpaperCropActivity.java   
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), true);
}
项目:WallpaperPicker    文件:WallpaperCropActivity.java   
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);
    }
}
项目:abelana    文件:PicturesFragment.java   
@Override
protected String doInBackground(final Void... params) {
    try {
        mPhotoPosition = mPhotoAdapter.getPosition();
        String url = mPhotoAdapter.getPhotoList().get(mPhotoPosition)
                .url;
        url = url.replace(".webp", "_o" + ".webp");
        WallpaperManager wpm = WallpaperManager
                .getInstance(getActivity().getApplicationContext());
        InputStream ins = new URL(url).openStream();
        wpm.setStream(ins);
        return null;
    } catch (IOException e) {
        return getString(R.string.wallpaper_error);
    }
}
项目:wpgen    文件:ColorsActivity.java   
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();
}
项目:NasaPic    文件:SpacePicInteractor.java   
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();
    }
}