use of android.os.AsyncTask 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();
}
use of android.os.AsyncTask in project RSAndroidApp by RailwayStations.
the class NearbyNotificationService method startLocationUpdates.
private void startLocationUpdates() {
LocationRequest locationRequest = new LocationRequest().setInterval(2 * FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS).setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS).setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
AsyncTask<PendingResult<LocationSettingsResult>, Void, Boolean> task = new AsyncTask<PendingResult<LocationSettingsResult>, Void, Boolean>() {
@Override
@SafeVarargs
protected final Boolean doInBackground(PendingResult<LocationSettingsResult>... pendingResults) {
com.google.android.gms.common.api.Status status = pendingResults[0].await().getStatus();
int statusCode = status.getStatusCode();
return statusCode == LocationSettingsStatusCodes.SUCCESS || statusCode == LocationSettingsStatusCodes.SUCCESS_CACHE;
}
@Override
protected final void onPostExecute(Boolean success) {
super.onPostExecute(success);
if (!success) {
Log.e(TAG, "Device settings unsuitable for location");
Toast.makeText(NearbyNotificationService.this, R.string.no_location_enabled, Toast.LENGTH_LONG).show();
stopSelf();
}
}
};
//noinspection unchecked
task.execute(result);
try {
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
} catch (SecurityException se) {
Log.e(TAG, "Still no permission for location services");
Toast.makeText(this, "Bitte einmal \"in der Nähe\" aufrufen", Toast.LENGTH_LONG).show();
stopSelf();
}
}
use of android.os.AsyncTask in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class Helpers method showSystemUIrestartDialog.
public static void showSystemUIrestartDialog(Activity a) {
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
builder.setTitle(R.string.systemui_restart_title);
builder.setMessage(R.string.systemui_restart_message);
builder.setPositiveButton(R.string.print_restart, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
ProgressDialog dialog = new ProgressDialog(a);
dialog.setMessage(a.getResources().getString(R.string.restarting_ui));
dialog.setCancelable(false);
dialog.setIndeterminate(true);
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Give the user a second to see the dialog
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Ignore
}
// Restart the UI
CMDProcessor.startSuCommand("pkill -f com.android.systemui");
a.finish();
return null;
}
};
task.execute();
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
use of android.os.AsyncTask in project AndroidChromium by JackyAndroid.
the class AccountsChangedReceiver method onReceive.
@Override
public void onReceive(Context context, final Intent intent) {
final Context appContext = context.getApplicationContext();
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
SigninHelper.updateAccountRenameData(appContext);
return null;
}
@Override
protected void onPostExecute(Void result) {
continueHandleAccountChangeIfNeeded(appContext, intent);
}
};
task.execute();
}
use of android.os.AsyncTask in project AndroidChromium by JackyAndroid.
the class SpaceDisplay method createStorageSizeTask.
private AsyncTask<Void, Void, Long> createStorageSizeTask() {
return new AsyncTask<Void, Void, Long>() {
@Override
protected Long doInBackground(Void... params) {
File downloadDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// Create the downloads directory, if necessary.
if (!downloadDirectory.exists()) {
try {
// mkdirs() can fail, so we still need to check if the directory exists
// later.
downloadDirectory.mkdirs();
} catch (SecurityException e) {
Log.e(TAG, "SecurityException when creating download directory.", e);
}
}
// Determine how much space is available on the storage device where downloads
// reside. If the downloads directory doesn't exist, it is likely that the user
// doesn't have an SD card installed.
long fileSystemBytes = 0;
if (downloadDirectory.exists()) {
StatFs statFs = new StatFs(downloadDirectory.getPath());
long totalBlocks = ApiCompatibilityUtils.getBlockCount(statFs);
long blockSize = ApiCompatibilityUtils.getBlockSize(statFs);
fileSystemBytes = totalBlocks * blockSize;
} else {
Log.e(TAG, "Download directory doesn't exist.");
}
return fileSystemBytes;
}
};
}
Aggregations