Search in sources :

Example 6 with BitmapRegionTileSource

use of com.android.photos.BitmapRegionTileSource in project android_frameworks_base by AOSPA.

the class WallpaperCropActivity method setCropViewTileSource.

public void setCropViewTileSource(final BitmapRegionTileSource.BitmapSource bitmapSource, final boolean touchEnabled, final boolean moveToLeft, final Runnable postExecute) {
    final Context context = WallpaperCropActivity.this;
    final View progressView = findViewById(R.id.loading);
    final AsyncTask<Void, Void, Void> loadBitmapTask = new AsyncTask<Void, Void, Void>() {

        protected Void doInBackground(Void... args) {
            if (!isCancelled()) {
                try {
                    bitmapSource.loadInBackground();
                } catch (SecurityException securityException) {
                    if (isDestroyed()) {
                        // 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(Void arg) {
            if (!isCancelled()) {
                progressView.setVisibility(View.INVISIBLE);
                if (bitmapSource.getLoadingState() == BitmapSource.State.LOADED) {
                    mCropView.setTileSource(new BitmapRegionTileSource(context, bitmapSource), null);
                    mCropView.setTouchEnabled(touchEnabled);
                    if (moveToLeft) {
                        mCropView.moveToLeft();
                    }
                }
            }
            if (postExecute != null) {
                postExecute.run();
            }
        }
    };
    // We don't want to show the spinner every time we load an image, because that would be
    // annoying; instead, only start showing the spinner if loading the image has taken
    // longer than 1 sec (ie 1000 ms)
    progressView.postDelayed(new Runnable() {

        public void run() {
            if (loadBitmapTask.getStatus() != AsyncTask.Status.FINISHED) {
                progressView.setVisibility(View.VISIBLE);
            }
        }
    }, 1000);
    loadBitmapTask.execute();
}
Also used : Context(android.content.Context) AsyncTask(android.os.AsyncTask) View(android.view.View) BitmapRegionTileSource(com.android.photos.BitmapRegionTileSource)

Aggregations

View (android.view.View)6 BitmapRegionTileSource (com.android.photos.BitmapRegionTileSource)6 Context (android.content.Context)5 AsyncTask (android.os.AsyncTask)5 ActionBar (android.app.ActionBar)1 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Uri (android.net.Uri)1