Example usage for android.app WallpaperManager getDesiredMinimumWidth

List of usage examples for android.app WallpaperManager getDesiredMinimumWidth

Introduction

In this page you can find the example usage for android.app WallpaperManager getDesiredMinimumWidth.

Prototype

public int getDesiredMinimumWidth() 

Source Link

Document

Returns the desired minimum width for the wallpaper.

Usage

From source file:com.leo.runningman.ui.ImageDetailActivity.java

private void setWapaper(Bitmap bitmap) {
    try {//from w ww.j a  va 2 s .c o m
        WallpaperManager wpm = WallpaperManager.getInstance(this);
        float minH = wpm.getDesiredMinimumHeight();
        float minW = wpm.getDesiredMinimumWidth();
        Bitmap targetBitmap = getResizedBitmap(bitmap, (int) minH, (int) minW);
        wpm.setBitmap(targetBitmap);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.leo.runningman.ui.ImageDetailFragment.java

private void setWapaper(final Bitmap bitmap) {
    final Context mContext = this.getActivity();
    new Handler().post(new Runnable() {

        @Override/*from  www .j av  a2 s  . c o m*/
        public void run() {
            try {
                WallpaperManager wpm = WallpaperManager.getInstance(mContext);
                float minH = wpm.getDesiredMinimumHeight();
                float minW = wpm.getDesiredMinimumWidth();
                Bitmap targetBitmap = getResizedBitmap(bitmap, (int) minH, (int) minW);
                wpm.setBitmap(targetBitmap);
                Toast.makeText(mContext, getActivity().getResources().getString(R.string.set_wallpaper_success),
                        200).show();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(mContext, getActivity().getResources().getString(R.string.set_wallpaper_failure),
                        200).show();
            }

        }
    });
}

From source file:nf.frex.android.FrexActivity.java

private void setWallpaper() {
    final WallpaperManager wallpaperManager = WallpaperManager.getInstance(FrexActivity.this);
    final int desiredWidth = wallpaperManager.getDesiredMinimumWidth();
    final int desiredHeight = wallpaperManager.getDesiredMinimumHeight();

    final Image image = view.getImage();
    final int imageWidth = image.getWidth();
    final int imageHeight = image.getHeight();

    final boolean useDesiredSize = desiredWidth > imageWidth || desiredHeight > imageHeight;

    DialogInterface.OnClickListener noListener = new DialogInterface.OnClickListener() {
        @Override/*  ww  w.j a  va  2 s. co  m*/
        public void onClick(DialogInterface dialog, int which) {
            // ok
        }
    };

    if (useDesiredSize) {
        showYesNoDialog(this, R.string.set_wallpaper,
                getString(R.string.wallpaper_compute_msg, desiredWidth, desiredHeight),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        final Image wallpaperImage;
                        try {
                            wallpaperImage = new Image(desiredWidth, desiredHeight);
                        } catch (OutOfMemoryError e) {
                            alert(getString(R.string.out_of_memory));
                            return;
                        }

                        final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this);

                        Generator.ProgressListener progressListener = new Generator.ProgressListener() {
                            int numLines;

                            @Override
                            public void onStarted(int numTasks) {
                            }

                            @Override
                            public void onSomeLinesComputed(int taskId, int line1, int line2) {
                                numLines += 1 + line2 - line1;
                                progressDialog.setProgress(numLines);
                            }

                            @Override
                            public void onStopped(boolean cancelled) {
                                progressDialog.dismiss();
                                if (!cancelled) {
                                    setWallpaper(wallpaperManager, wallpaperImage);
                                }
                            }
                        };
                        final Generator wallpaperGenerator = new Generator(view.getGeneratorConfig(),
                                SettingsActivity.NUM_CORES, progressListener);

                        DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                if (progressDialog.isShowing()) {
                                    progressDialog.dismiss();
                                }
                                wallpaperGenerator.cancel();
                            }
                        };
                        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        progressDialog.setCancelable(true);
                        progressDialog.setMax(desiredHeight);
                        progressDialog.setOnCancelListener(cancelListener);
                        progressDialog.show();

                        Arrays.fill(wallpaperImage.getValues(), FractalView.MISSING_VALUE);
                        wallpaperGenerator.start(wallpaperImage, false);
                    }
                }, noListener, null);
    } else {
        showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_replace_msg),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        setWallpaper(wallpaperManager, image);
                    }
                }, noListener, null);
    }
}