Search in sources :

Example 1 with BitmapRegionTileSource

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

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)

Example 2 with BitmapRegionTileSource

use of com.android.photos.BitmapRegionTileSource in project platform_frameworks_base by android.

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)

Example 3 with BitmapRegionTileSource

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

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)

Example 4 with BitmapRegionTileSource

use of com.android.photos.BitmapRegionTileSource in project Launcher3 by chislon.

the class WallpaperCropActivity method init.

protected void init() {
    setContentView(R.layout.wallpaper_cropper);
    mCropView = (CropView) findViewById(R.id.cropView);
    Intent cropIntent = getIntent();
    final Uri imageUri = cropIntent.getData();
    if (imageUri == null) {
        Log.e(LOGTAG, "No URI passed in intent, exiting WallpaperCropActivity");
        finish();
        return;
    }
    int rotation = getRotationFromExif(this, imageUri);
    mCropView.setTileSource(new BitmapRegionTileSource(this, imageUri, 1024, rotation), null);
    mCropView.setTouchEnabled(true);
    // Action bar
    // Show the custom action bar view
    final ActionBar actionBar = getActionBar();
    actionBar.setCustomView(R.layout.actionbar_set_wallpaper);
    actionBar.getCustomView().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean finishActivityWhenDone = true;
            cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone);
        }
    });
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri) View(android.view.View) Point(android.graphics.Point) Paint(android.graphics.Paint) BitmapRegionTileSource(com.android.photos.BitmapRegionTileSource) ActionBar(android.app.ActionBar)

Example 5 with BitmapRegionTileSource

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

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