use of android.os.AsyncTask in project android_packages_apps_Dialer by LineageOS.
the class ClearFrequentsDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity().getApplicationContext();
final ContentResolver resolver = getActivity().getContentResolver();
final OnClickListener okListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!PermissionsUtil.hasContactsReadPermissions(context)) {
return;
}
final ProgressDialog progressDialog = ProgressDialog.show(getContext(), getString(R.string.clearFrequentsProgress_title), null, true, true);
final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
resolver.delete(ContactsContract.DataUsageFeedback.DELETE_USAGE_URI, null, null);
return null;
}
@Override
protected void onPostExecute(Void result) {
progressDialog.dismiss();
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
};
return new AlertDialog.Builder(getActivity()).setTitle(R.string.clearFrequentsConfirmation_title).setMessage(R.string.clearFrequentsConfirmation).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, okListener).setCancelable(true).create();
}
use of android.os.AsyncTask in project xDrip by NightscoutFoundation.
the class ShareRest method getSessionId.
private String getSessionId() {
AsyncTask<String, Void, String> task = new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... params) {
try {
Boolean isActive = null;
if (params[0] != null)
isActive = dexcomShareApi.checkSessionActive(params[0]).execute().body();
if (isActive == null || !isActive) {
return updateAuthenticationParams();
} else
return params[0];
} catch (IOException e) {
return null;
} catch (RuntimeException e) {
UserError.Log.wtf(TAG, "Painful exception processing response in updateAuthenticationParams " + e);
return null;
}
}
private String updateAuthenticationParams() throws IOException {
sessionId = dexcomShareApi.getSessionId(new ShareAuthenticationBody(password, username).toMap()).execute().body();
dexcomShareApi.authenticatePublisherAccount(sessionId, serialNumber, new ShareAuthenticationBody(password, username).toMap()).execute().body();
dexcomShareApi.StartRemoteMonitoringSession(sessionId, serialNumber).execute();
String assignment = dexcomShareApi.checkMonitorAssignment(sessionId, serialNumber).execute().body();
if ((assignment != null) && (!assignment.equals("AssignedToYou"))) {
dexcomShareApi.updateMonitorAssignment(sessionId, serialNumber).execute();
}
return sessionId;
}
};
if (sessionId == null || sessionId.equals(""))
try {
sessionId = task.executeOnExecutor(xdrip.executor, sessionId).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return sessionId;
}
use of android.os.AsyncTask in project Signal-Android by signalapp.
the class ConversationActivity method onRecorderCanceled.
@Override
public void onRecorderCanceled() {
Vibrator vibrator = ServiceUtil.getVibrator(this);
vibrator.vibrate(50);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {
@Override
public void onSuccess(final Pair<Uri, Long> result) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void onFailure(ExecutionException e) {
}
});
}
use of android.os.AsyncTask in project Signal-Android by signalapp.
the class ConversationActivity method handleUnblock.
private void handleUnblock() {
// noinspection CodeBlock2Expr
new AlertDialog.Builder(this).setTitle(R.string.ConversationActivity_unblock_this_contact_question).setMessage(R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact).setNegativeButton(android.R.string.cancel, null).setPositiveButton(R.string.ConversationActivity_unblock, (dialog, which) -> {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setBlocked(recipient, false);
ApplicationContext.getInstance(ConversationActivity.this).getJobManager().add(new MultiDeviceBlockedUpdateJob(ConversationActivity.this));
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}).show();
}
use of android.os.AsyncTask in project Signal-Android by signalapp.
the class ConversationItem method setExpiration.
@SuppressLint("StaticFieldLeak")
private void setExpiration(final MessageRecord messageRecord) {
if (messageRecord.getExpiresIn() > 0) {
this.expirationTimer.setVisibility(View.VISIBLE);
this.expirationTimer.setPercentage(0);
if (messageRecord.getExpireStarted() > 0) {
this.expirationTimer.setExpirationTime(messageRecord.getExpireStarted(), messageRecord.getExpiresIn());
this.expirationTimer.startAnimation();
} else if (!messageRecord.isOutgoing() && !messageRecord.isMediaPending()) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
long id = messageRecord.getId();
boolean mms = messageRecord.isMms();
if (mms)
DatabaseFactory.getMmsDatabase(context).markExpireStarted(id);
else
DatabaseFactory.getSmsDatabase(context).markExpireStarted(id);
expirationManager.scheduleDeletion(id, mms, messageRecord.getExpiresIn());
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
} else {
this.expirationTimer.setVisibility(View.GONE);
}
}
Aggregations