use of androidx.annotation.AnyThread in project nextcloud-notes by stefan-niedermann.
the class NotesRepository method addAccount.
// Accounts
@AnyThread
public LiveData<ImportStatus> addAccount(@NonNull String url, @NonNull String username, @NonNull String accountName, @NonNull Capabilities capabilities, @Nullable String displayName, @NonNull IResponseCallback<Account> callback) {
final var account = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account(url, username, accountName, displayName, capabilities)));
if (account == null) {
callback.onError(new Exception("Could not read created account."));
} else {
if (isSyncPossible()) {
syncActive.put(account.getId(), true);
try {
Log.d(TAG, "… starting now");
final NotesImportTask importTask = new NotesImportTask(context, this, account, importExecutor, apiProvider);
return importTask.importNotes(new IResponseCallback<>() {
@Override
public void onSuccess(Void result) {
callback.onSuccess(account);
}
@Override
public void onError(@NonNull Throwable t) {
callback.onError(t);
}
});
} catch (NextcloudFilesAppAccountNotFoundException e) {
Log.e(TAG, "… Could not find " + SingleSignOnAccount.class.getSimpleName() + " for account name " + account.getAccountName());
callback.onError(e);
}
} else {
callback.onError(new NetworkErrorException());
}
}
return new MutableLiveData<>(new ImportStatus());
}
use of androidx.annotation.AnyThread in project RxTools by vondear.
the class RxScaleImageView method getExifOrientation.
/**
* Helper method for load tasks. Examines the EXIF info on the image file to determine the orientation.
* This will only work for external files, not assets, resources or other URIs.
*/
@AnyThread
private int getExifOrientation(Context context, String sourceUri) {
int exifOrientation = ORIENTATION_0;
if (sourceUri.startsWith(ContentResolver.SCHEME_CONTENT)) {
Cursor cursor = null;
try {
String[] columns = { MediaStore.Images.Media.ORIENTATION };
cursor = context.getContentResolver().query(Uri.parse(sourceUri), columns, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int orientation = cursor.getInt(0);
if (VALID_ORIENTATIONS.contains(orientation) && orientation != ORIENTATION_USE_EXIF) {
exifOrientation = orientation;
} else {
TLog.w(TAG, "Unsupported orientation: " + orientation);
}
}
}
} catch (Exception e) {
TLog.w(TAG, "Could not get orientation of image from media store");
} finally {
if (cursor != null) {
cursor.close();
}
}
} else if (sourceUri.startsWith(ImageSource.FILE_SCHEME) && !sourceUri.startsWith(ImageSource.ASSET_SCHEME)) {
try {
ExifInterface exifInterface = new ExifInterface(sourceUri.substring(ImageSource.FILE_SCHEME.length() - 1));
int orientationAttr = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
if (orientationAttr == ExifInterface.ORIENTATION_NORMAL || orientationAttr == ExifInterface.ORIENTATION_UNDEFINED) {
exifOrientation = ORIENTATION_0;
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_90) {
exifOrientation = ORIENTATION_90;
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_180) {
exifOrientation = ORIENTATION_180;
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_270) {
exifOrientation = ORIENTATION_270;
} else {
TLog.w(TAG, "Unsupported EXIF orientation: " + orientationAttr);
}
} catch (Exception e) {
TLog.w(TAG, "Could not get EXIF orientation of image");
}
}
return exifOrientation;
}
use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.
the class PaymentSendJob method enqueuePayment.
/**
* @param totalFee Total quoted totalFee to the user. This is expected to cover all defrags and the actual transaction.
*/
@AnyThread
@NonNull
public static UUID enqueuePayment(@Nullable RecipientId recipientId, @NonNull MobileCoinPublicAddress publicAddress, @NonNull String note, @NonNull Money amount, @NonNull Money totalFee) {
UUID uuid = UUID.randomUUID();
long timestamp = System.currentTimeMillis();
Job sendJob = new PaymentSendJob(new Parameters.Builder().setQueue(QUEUE).setMaxAttempts(1).build(), uuid, timestamp, recipientId, Objects.requireNonNull(publicAddress), note, amount, totalFee);
JobManager.Chain chain = ApplicationDependencies.getJobManager().startChain(sendJob).then(new PaymentTransactionCheckJob(uuid, QUEUE)).then(new MultiDeviceOutgoingPaymentSyncJob(uuid));
if (recipientId != null) {
chain.then(new PaymentNotificationSendJob(recipientId, uuid, recipientId.toQueueKey(true)));
}
chain.then(PaymentLedgerUpdateJob.updateLedgerToReflectPayment(uuid)).enqueue();
return uuid;
}
use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.
the class MegaphoneRepository method markSeen.
@AnyThread
public void markSeen(@NonNull Event event) {
long lastSeen = System.currentTimeMillis();
executor.execute(() -> {
MegaphoneRecord record = getRecord(event);
database.markSeen(event, record.getSeenCount() + 1, lastSeen);
enabled = false;
resetDatabaseCache();
});
}
use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.
the class MegaphoneRepository method markFinished.
@AnyThread
public void markFinished(@NonNull Event event, @Nullable Runnable onComplete) {
executor.execute(() -> {
MegaphoneRecord record = databaseCache.get(event);
if (record != null && record.isFinished()) {
return;
}
database.markFinished(event);
resetDatabaseCache();
if (onComplete != null) {
onComplete.run();
}
});
}
Aggregations