com.android.gallery3d.common.BitmapUtils Java Examples

The following examples show how to use com.android.gallery3d.common.BitmapUtils. 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: WallpaperPickerActivity.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
private ResourceWallpaperInfo getPreKKDefaultWallpaperInfo() {
    Resources sysRes = Resources.getSystem();
    int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android");

    File defaultThumbFile = getDefaultThumbFile();
    Bitmap thumb = null;
    boolean defaultWallpaperExists = false;
    if (defaultThumbFile.exists()) {
        thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath());
        defaultWallpaperExists = true;
    } else {
        Resources res = getResources();
        Point defaultThumbSize = getDefaultThumbnailSize(res);
        int rotation = BitmapUtils.getRotationFromExif(res, resId);
        thumb = createThumbnail(
                defaultThumbSize, getContext(), null, null, sysRes, resId, rotation, false);
        if (thumb != null) {
            defaultWallpaperExists = saveDefaultWallpaperThumb(thumb);
        }
    }
    if (defaultWallpaperExists) {
        return new ResourceWallpaperInfo(sysRes, resId, new BitmapDrawable(thumb));
    }
    return null;
}
 
Example #2
Source File: WallpaperCropActivity.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
protected void setWallpaper(Uri uri, final boolean finishActivityWhenDone) {
    int rotation = BitmapUtils.getRotationFromExif(getContext(), uri);
    BitmapCropTask cropTask = new BitmapCropTask(
            getContext(), uri, null, rotation, 0, 0, true, false, null);
    final Point bounds = cropTask.getImageBounds();
    Runnable onEndCrop = new Runnable() {
        public void run() {
            updateWallpaperDimensions(bounds.x, bounds.y);
            if (finishActivityWhenDone) {
                setResult(Activity.RESULT_OK);
                finish();
            }
        }
    };
    cropTask.setOnEndRunnable(onEndCrop);
    cropTask.setNoCrop(true);
    cropTask.execute();
}
 
Example #3
Source File: WallpaperCropActivity.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
protected void cropImageAndSetWallpaper(
        Resources res, int resId, final boolean finishActivityWhenDone) {
    // crop this image and scale it down to the default wallpaper size for
    // this device
    int rotation = BitmapUtils.getRotationFromExif(res, resId);
    Point inSize = mCropView.getSourceDimensions();
    Point outSize = WallpaperUtils.getDefaultWallpaperSize(getResources(),
            getWindowManager());
    RectF crop = Utils.getMaxCropRect(
            inSize.x, inSize.y, outSize.x, outSize.y, false);
    Runnable onEndCrop = new Runnable() {
        public void run() {
            // Passing 0, 0 will cause launcher to revert to using the
            // default wallpaper size
            updateWallpaperDimensions(0, 0);
            if (finishActivityWhenDone) {
                setResult(Activity.RESULT_OK);
                finish();
            }
        }
    };
    BitmapCropTask cropTask = new BitmapCropTask(getContext(), res, resId,
            crop, rotation, outSize.x, outSize.y, true, false, onEndCrop);
    cropTask.execute();
}
 
Example #4
Source File: BitmapRegionTileSource.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Note that the returned bitmap may have a long edge that's longer
 * than the targetSize, but it will always be less than 2x the targetSize
 */
private Bitmap decodePreview(BitmapSource source, int targetSize) {
    Bitmap result = source.getPreviewBitmap();
    if (result == null) {
        return null;
    }

    // We need to resize down if the decoder does not support inSampleSize
    // or didn't support the specified inSampleSize (some decoders only do powers of 2)
    float scale = (float) targetSize / (float) (Math.max(result.getWidth(), result.getHeight()));

    if (scale <= 0.5) {
        result = BitmapUtils.resizeBitmapByScale(result, scale, true);
    }
    return ensureGLCompatibleBitmap(result);
}
 
Example #5
Source File: BitmapRegionTileSource.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
/**
 * Note that the returned bitmap may have a long edge that's longer
 * than the targetSize, but it will always be less than 2x the targetSize
 */
private Bitmap decodePreview(BitmapSource source, int targetSize) {
    Bitmap result = source.getPreviewBitmap();
    if (result == null) {
        return null;
    }

    // We need to resize down if the decoder does not support inSampleSize
    // or didn't support the specified inSampleSize (some decoders only do powers of 2)
    float scale = (float) targetSize / (float) (Math.max(result.getWidth(), result.getHeight()));

    if (scale <= 0.5) {
        result = BitmapUtils.resizeBitmapByScale(result, scale, true);
    }
    return ensureGLCompatibleBitmap(result);
}
 
Example #6
Source File: BitmapRegionTileSource.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public boolean loadInBackground() {
    ExifInterface ei = new ExifInterface();
    if (readExif(ei)) {
        Integer ori = ei.getTagIntValue(ExifInterface.TAG_ORIENTATION);
        if (ori != null) {
            mRotation = ExifInterface.getRotationForOrientationValue(ori.shortValue());
        }
    }
    mDecoder = loadBitmapRegionDecoder();
    if (mDecoder == null) {
        mState = State.ERROR_LOADING;
        return false;
    } else {
        int width = mDecoder.getWidth();
        int height = mDecoder.getHeight();
        if (mPreviewSize != 0) {
            int previewSize = Math.min(mPreviewSize, MAX_PREVIEW_SIZE);
            BitmapFactory.Options opts = new BitmapFactory.Options();
            opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
            opts.inPreferQualityOverSpeed = true;

            float scale = (float) previewSize / Math.max(width, height);
            opts.inSampleSize = BitmapUtils.computeSampleSizeLarger(scale);
            opts.inJustDecodeBounds = false;
            mPreview = loadPreviewBitmap(opts);
        }
        mState = State.LOADED;
        return true;
    }
}
 
Example #7
Source File: BitmapRegionTileSource.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
public boolean loadInBackground() {
    ExifInterface ei = new ExifInterface();
    if (readExif(ei)) {
        Integer ori = ei.getTagIntValue(ExifInterface.TAG_ORIENTATION);
        if (ori != null) {
            mRotation = ExifInterface.getRotationForOrientationValue(ori.shortValue());
        }
    }
    mDecoder = loadBitmapRegionDecoder();
    if (mDecoder == null) {
        mState = State.ERROR_LOADING;
        return false;
    } else {
        int width = mDecoder.getWidth();
        int height = mDecoder.getHeight();
        if (mPreviewSize != 0) {
            int previewSize = Math.min(mPreviewSize, MAX_PREVIEW_SIZE);
            BitmapFactory.Options opts = new BitmapFactory.Options();
            opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
            opts.inPreferQualityOverSpeed = true;

            float scale = (float) previewSize / Math.max(width, height);
            opts.inSampleSize = BitmapUtils.computeSampleSizeLarger(scale);
            opts.inJustDecodeBounds = false;
            mPreview = loadPreviewBitmap(opts);
        }
        mState = State.LOADED;
        return true;
    }
}
 
Example #8
Source File: WallpaperPickerActivity.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
private void addTemporaryWallpaperTile(final Uri uri, boolean fromRestore) {
    mTempWallpaperTiles.add(uri);
    // Add a tile for the image picked from Gallery
    final FrameLayout pickedImageThumbnail = (FrameLayout) getLayoutInflater().
            inflate(R.layout.wallpaper_picker_item, mWallpapersView, false);
    pickedImageThumbnail.setVisibility(View.GONE);
    mWallpapersView.addView(pickedImageThumbnail, 0);

    // Load the thumbnail
    final ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image);
    final Point defaultSize = getDefaultThumbnailSize(this.getResources());
    final Context context = getContext();
    new AsyncTask<Void, Bitmap, Bitmap>() {
        protected Bitmap doInBackground(Void...args) {
            try {
                int rotation = BitmapUtils.getRotationFromExif(context, uri);
                return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, false);
            } catch (SecurityException securityException) {
                if (isActivityDestroyed()) {
                    // Temporarily granted permissions are revoked when the activity
                    // finishes, potentially resulting in a SecurityException here.
                    // Even though {@link #isDestroyed} might also return true in different
                    // situations where the configuration changes, we are fine with
                    // catching these cases here as well.
                    cancel(false);
                } else {
                    // otherwise it had a different cause and we throw it further
                    throw securityException;
                }
                return null;
            }
        }
        protected void onPostExecute(Bitmap thumb) {
            if (!isCancelled() && thumb != null) {
                image.setImageBitmap(thumb);
                Drawable thumbDrawable = image.getDrawable();
                thumbDrawable.setDither(true);
                pickedImageThumbnail.setVisibility(View.VISIBLE);
            } else {
                Log.e(TAG, "Error loading thumbnail for uri=" + uri);
            }
        }
    }.execute();

    UriWallpaperInfo info = new UriWallpaperInfo(uri);
    pickedImageThumbnail.setTag(info);
    info.setView(pickedImageThumbnail);
    addLongPressHandler(pickedImageThumbnail);
    updateTileIndices();
    pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener);
    if (!fromRestore) {
        mThumbnailOnClickListener.onClick(pickedImageThumbnail);
    }
}