com.android.gallery3d.common.Utils Java Examples

The following examples show how to use com.android.gallery3d.common.Utils. 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: BitmapRegionTileSource.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public SimpleBitmapRegionDecoder loadBitmapRegionDecoder() {
    try {
        InputStream is = regenerateInputStream();
        SimpleBitmapRegionDecoder regionDecoder =
                SimpleBitmapRegionDecoderWrapper.newInstance(is, false);
        Utils.closeSilently(is);
        if (regionDecoder == null) {
            is = regenerateInputStream();
            regionDecoder = DumbBitmapRegionDecoder.newInstance(is);
            Utils.closeSilently(is);
        }
        return regionDecoder;
    } catch (FileNotFoundException e) {
        Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e);
        return null;
    }
}
 
Example #2
Source File: BitmapRegionTileSource.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
@Override
public SimpleBitmapRegionDecoder loadBitmapRegionDecoder() {
    try {
        InputStream is = regenerateInputStream();
        SimpleBitmapRegionDecoder regionDecoder =
                SimpleBitmapRegionDecoderWrapper.newInstance(is, false);
        Utils.closeSilently(is);
        if (regionDecoder == null) {
            is = regenerateInputStream();
            regionDecoder = DumbBitmapRegionDecoder.newInstance(is);
            Utils.closeSilently(is);
        }
        return regionDecoder;
    } catch (FileNotFoundException e) {
        Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e);
        return null;
    }
}
 
Example #3
Source File: WallpaperPickerActivity.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(final WallpaperPickerActivity a) {
    a.setWallpaperButtonEnabled(false);
    final BitmapRegionTileSource.ResourceBitmapSource bitmapSource =
            new BitmapRegionTileSource.ResourceBitmapSource(mResources, mResId);
    a.setCropViewTileSource(bitmapSource, false, false, new CropViewScaleProvider() {

        @Override
        public float getScale(TileSource src) {
            Point wallpaperSize = WallpaperUtils.getDefaultWallpaperSize(
                    a.getResources(), a.getWindowManager());
            RectF crop = Utils.getMaxCropRect(
                    src.getImageWidth(), src.getImageHeight(),
                    wallpaperSize.x, wallpaperSize.y, false);
            return wallpaperSize.x / crop.width();
        }
    }, new Runnable() {

        @Override
        public void run() {
            if (bitmapSource.getLoadingState() == BitmapSource.State.LOADED) {
                a.setWallpaperButtonEnabled(true);
            }
        }
    });
}
 
Example #4
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 #5
Source File: BitmapRegionTileSource.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
@Override
public SimpleBitmapRegionDecoder loadBitmapRegionDecoder() {
    try {
        InputStream is = regenerateInputStream();
        SimpleBitmapRegionDecoder regionDecoder =
                SimpleBitmapRegionDecoderWrapper.newInstance(is, false);
        Utils.closeSilently(is);
        if (regionDecoder == null) {
            is = regenerateInputStream();
            regionDecoder = DumbBitmapRegionDecoder.newInstance(is);
            Utils.closeSilently(is);
        }
        return regionDecoder;
    } catch (FileNotFoundException e) {
        Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e);
        return null;
    }
}
 
Example #6
Source File: BasicTexture.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the content size of this texture. In OpenGL, the actual texture
 * size must be of power of 2, the size of the content may be smaller.
 */
public void setSize(int width, int height) {
    mWidth = width;
    mHeight = height;
    mTextureWidth = width > 0 ? Utils.nextPowerOf2(width) : 0;
    mTextureHeight = height > 0 ? Utils.nextPowerOf2(height) : 0;
    if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) {
        Log.w(TAG, String.format("texture is too large: %d x %d",
                mTextureWidth, mTextureHeight), new Exception());
    }
}
 
Example #7
Source File: TiledImageRenderer.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
protected Bitmap onGetBitmap() {
    Utils.assertTrue(mTileState == STATE_DECODED);

    // We need to override the width and height, so that we won't
    // draw beyond the boundaries.
    int rightEdge = ((mImageWidth - mX) >> mTileLevel);
    int bottomEdge = ((mImageHeight - mY) >> mTileLevel);
    setSize(Math.min(mTileSize, rightEdge), Math.min(mTileSize, bottomEdge));

    Bitmap bitmap = mDecodedTile;
    mDecodedTile = null;
    mTileState = STATE_ACTIVATED;
    return bitmap;
}
 
Example #8
Source File: TiledImageRenderer.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
private void calculateLevelCount() {
    if (mPreview != null) {
        mLevelCount = Math.max(0, Utils.ceilLog2(
            mImageWidth / (float) mPreview.getWidth()));
    } else {
        int levels = 1;
        int maxDim = Math.max(mImageWidth, mImageHeight);
        int t = mTileSize;
        while (t < maxDim) {
            t <<= 1;
            levels++;
        }
        mLevelCount = levels;
    }
}
 
Example #9
Source File: BitmapRegionTileSource.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public boolean readExif(ExifInterface ei) {
    try {
        InputStream is = regenerateInputStream();
        ei.readExif(is);
        Utils.closeSilently(is);
        return true;
    } catch (IOException e) {
        Log.e("BitmapRegionTileSource", "Error reading resource", e);
        return false;
    }
}
 
Example #10
Source File: BitmapRegionTileSource.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public SimpleBitmapRegionDecoder loadBitmapRegionDecoder() {
    InputStream is = regenerateInputStream();
    SimpleBitmapRegionDecoder regionDecoder =
            SimpleBitmapRegionDecoderWrapper.newInstance(is, false);
    Utils.closeSilently(is);
    if (regionDecoder == null) {
        is = regenerateInputStream();
        regionDecoder = DumbBitmapRegionDecoder.newInstance(is);
        Utils.closeSilently(is);
    }
    return regionDecoder;
}
 
Example #11
Source File: BitmapRegionTileSource.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public Bitmap loadPreviewBitmap(BitmapFactory.Options options) {
    try {
        InputStream is = regenerateInputStream();
        Bitmap b = BitmapFactory.decodeStream(is, null, options);
        Utils.closeSilently(is);
        return b;
    } catch (FileNotFoundException e) {
        Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e);
        return null;
    }
}
 
Example #12
Source File: WallpaperCropActivity.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
public Point getImageBounds() {
    InputStream is = regenerateInputStream();
    if (is != null) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, null, options);
        Utils.closeSilently(is);
        if (options.outWidth != 0 && options.outHeight != 0) {
            return new Point(options.outWidth, options.outHeight);
        }
    }
    return null;
}
 
Example #13
Source File: BasicTexture.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the content size of this texture. In OpenGL, the actual texture
 * size must be of power of 2, the size of the content may be smaller.
 */
public void setSize(int width, int height) {
    mWidth = width;
    mHeight = height;
    mTextureWidth = width > 0 ? Utils.nextPowerOf2(width) : 0;
    mTextureHeight = height > 0 ? Utils.nextPowerOf2(height) : 0;
    if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) {
        Log.w(TAG, String.format("texture is too large: %d x %d",
                mTextureWidth, mTextureHeight), new Exception());
    }
}
 
Example #14
Source File: TiledImageRenderer.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
protected Bitmap onGetBitmap() {
    Utils.assertTrue(mTileState == STATE_DECODED);

    // We need to override the width and height, so that we won't
    // draw beyond the boundaries.
    int rightEdge = ((mImageWidth - mX) >> mTileLevel);
    int bottomEdge = ((mImageHeight - mY) >> mTileLevel);
    setSize(Math.min(mTileSize, rightEdge), Math.min(mTileSize, bottomEdge));

    Bitmap bitmap = mDecodedTile;
    mDecodedTile = null;
    mTileState = STATE_ACTIVATED;
    return bitmap;
}
 
Example #15
Source File: TiledImageRenderer.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private void calculateLevelCount() {
    if (mPreview != null) {
        mLevelCount = Math.max(0, Utils.ceilLog2(
            mImageWidth / (float) mPreview.getWidth()));
    } else {
        int levels = 1;
        int maxDim = Math.max(mImageWidth, mImageHeight);
        int t = mTileSize;
        while (t < maxDim) {
            t <<= 1;
            levels++;
        }
        mLevelCount = levels;
    }
}
 
Example #16
Source File: BitmapRegionTileSource.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
public boolean readExif(ExifInterface ei) {
    try {
        InputStream is = regenerateInputStream();
        ei.readExif(is);
        Utils.closeSilently(is);
        return true;
    } catch (IOException e) {
        Log.e("BitmapRegionTileSource", "Error reading resource", e);
        return false;
    }
}
 
Example #17
Source File: BitmapRegionTileSource.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
public SimpleBitmapRegionDecoder loadBitmapRegionDecoder() {
    InputStream is = regenerateInputStream();
    SimpleBitmapRegionDecoder regionDecoder =
            SimpleBitmapRegionDecoderWrapper.newInstance(is, false);
    Utils.closeSilently(is);
    if (regionDecoder == null) {
        is = regenerateInputStream();
        regionDecoder = DumbBitmapRegionDecoder.newInstance(is);
        Utils.closeSilently(is);
    }
    return regionDecoder;
}
 
Example #18
Source File: BitmapRegionTileSource.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
public Bitmap loadPreviewBitmap(BitmapFactory.Options options) {
    try {
        InputStream is = regenerateInputStream();
        Bitmap b = BitmapFactory.decodeStream(is, null, options);
        Utils.closeSilently(is);
        return b;
    } catch (FileNotFoundException e) {
        Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e);
        return null;
    }
}
 
Example #19
Source File: WallpaperCropActivity.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public Point getImageBounds() {
    InputStream is = regenerateInputStream();
    if (is != null) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, null, options);
        Utils.closeSilently(is);
        if (options.outWidth != 0 && options.outHeight != 0) {
            return new Point(options.outWidth, options.outHeight);
        }
    }
    return null;
}
 
Example #20
Source File: WallpaperPickerActivity.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Thunk static Bitmap createThumbnail(Point size, Context context, Uri uri, byte[] imageBytes,
        Resources res, int resId, int rotation, boolean leftAligned) {
    int width = size.x;
    int height = size.y;

    BitmapCropTask cropTask;
    if (uri != null) {
        cropTask = new BitmapCropTask(
                context, uri, null, rotation, width, height, false, true, null);
    } else if (imageBytes != null) {
        cropTask = new BitmapCropTask(
                imageBytes, null, rotation, width, height, false, true, null);
    }  else {
        cropTask = new BitmapCropTask(
                context, res, resId, null, rotation, width, height, false, true, null);
    }
    Point bounds = cropTask.getImageBounds();
    if (bounds == null || bounds.x == 0 || bounds.y == 0) {
        return null;
    }

    Matrix rotateMatrix = new Matrix();
    rotateMatrix.setRotate(rotation);
    float[] rotatedBounds = new float[] { bounds.x, bounds.y };
    rotateMatrix.mapPoints(rotatedBounds);
    rotatedBounds[0] = Math.abs(rotatedBounds[0]);
    rotatedBounds[1] = Math.abs(rotatedBounds[1]);

    RectF cropRect = Utils.getMaxCropRect(
            (int) rotatedBounds[0], (int) rotatedBounds[1], width, height, leftAligned);
    cropTask.setCropBounds(cropRect);

    if (cropTask.cropBitmap()) {
        return cropTask.getCroppedBitmap();
    } else {
        return null;
    }
}
 
Example #21
Source File: BasicTexture.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the content size of this texture. In OpenGL, the actual texture
 * size must be of power of 2, the size of the content may be smaller.
 */
public void setSize(int width, int height) {
    mWidth = width;
    mHeight = height;
    mTextureWidth = width > 0 ? Utils.nextPowerOf2(width) : 0;
    mTextureHeight = height > 0 ? Utils.nextPowerOf2(height) : 0;
    if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) {
        Log.w(TAG, String.format("texture is too large: %d x %d",
                mTextureWidth, mTextureHeight), new Exception());
    }
}
 
Example #22
Source File: TiledImageRenderer.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Bitmap onGetBitmap() {
    Utils.assertTrue(mTileState == STATE_DECODED);

    // We need to override the width and height, so that we won't
    // draw beyond the boundaries.
    int rightEdge = ((mImageWidth - mX) >> mTileLevel);
    int bottomEdge = ((mImageHeight - mY) >> mTileLevel);
    setSize(Math.min(mTileSize, rightEdge), Math.min(mTileSize, bottomEdge));

    Bitmap bitmap = mDecodedTile;
    mDecodedTile = null;
    mTileState = STATE_ACTIVATED;
    return bitmap;
}
 
Example #23
Source File: TiledImageRenderer.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
private void calculateLevelCount() {
    if (mPreview != null) {
        mLevelCount = Math.max(0, Utils.ceilLog2(
            mImageWidth / (float) mPreview.getWidth()));
    } else {
        int levels = 1;
        int maxDim = Math.max(mImageWidth, mImageHeight);
        int t = mTileSize;
        while (t < maxDim) {
            t <<= 1;
            levels++;
        }
        mLevelCount = levels;
    }
}
 
Example #24
Source File: BitmapRegionTileSource.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean readExif(ExifInterface ei) {
    try {
        InputStream is = regenerateInputStream();
        ei.readExif(is);
        Utils.closeSilently(is);
        return true;
    } catch (IOException e) {
        Log.e("BitmapRegionTileSource", "Error reading resource", e);
        return false;
    }
}
 
Example #25
Source File: BitmapRegionTileSource.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SimpleBitmapRegionDecoder loadBitmapRegionDecoder() {
    InputStream is = regenerateInputStream();
    SimpleBitmapRegionDecoder regionDecoder =
            SimpleBitmapRegionDecoderWrapper.newInstance(is, false);
    Utils.closeSilently(is);
    if (regionDecoder == null) {
        is = regenerateInputStream();
        regionDecoder = DumbBitmapRegionDecoder.newInstance(is);
        Utils.closeSilently(is);
    }
    return regionDecoder;
}
 
Example #26
Source File: BitmapRegionTileSource.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Bitmap loadPreviewBitmap(BitmapFactory.Options options) {
    try {
        InputStream is = regenerateInputStream();
        Bitmap b = BitmapFactory.decodeStream(is, null, options);
        Utils.closeSilently(is);
        return b;
    } catch (FileNotFoundException e) {
        Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e);
        return null;
    }
}
 
Example #27
Source File: GLPaint.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public void setLineWidth(float width) {
    Utils.assertTrue(width >= 0);
    mLineWidth = width;
}
 
Example #28
Source File: UploadedTexture.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
private void freeBitmap() {
    Utils.assertTrue(mBitmap != null);
    onFreeBitmap(mBitmap);
    mBitmap = null;
}
 
Example #29
Source File: BitmapTexture.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public BitmapTexture(Bitmap bitmap, boolean hasBorder) {
    super(hasBorder);
    Utils.assertTrue(bitmap != null && !bitmap.isRecycled());
    mContentBitmap = bitmap;
}