Search in sources :

Example 16 with AnyThread

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());
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) NetworkErrorException(android.accounts.NetworkErrorException) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) NoCurrentAccountSelectedException(com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException) NetworkErrorException(android.accounts.NetworkErrorException) ImportStatus(it.niedermann.owncloud.notes.shared.model.ImportStatus) MutableLiveData(androidx.lifecycle.MutableLiveData) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) AnyThread(androidx.annotation.AnyThread)

Example 17 with AnyThread

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;
}
Also used : ExifInterface(androidx.exifinterface.media.ExifInterface) Cursor(android.database.Cursor) Point(android.graphics.Point) Paint(android.graphics.Paint) AnyThread(androidx.annotation.AnyThread)

Example 18 with AnyThread

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;
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) UUID(java.util.UUID) Job(org.thoughtcrime.securesms.jobmanager.Job) NonNull(androidx.annotation.NonNull) AnyThread(androidx.annotation.AnyThread)

Example 19 with AnyThread

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();
    });
}
Also used : MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AnyThread(androidx.annotation.AnyThread)

Example 20 with AnyThread

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();
        }
    });
}
Also used : MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AnyThread(androidx.annotation.AnyThread)

Aggregations

AnyThread (androidx.annotation.AnyThread)27 IOException (java.io.IOException)5 Cursor (android.database.Cursor)4 NonNull (androidx.annotation.NonNull)4 UUID (java.util.UUID)4 MegaphoneRecord (org.thoughtcrime.securesms.database.model.MegaphoneRecord)4 SuppressLint (android.annotation.SuppressLint)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 ExifInterface (androidx.exifinterface.media.ExifInterface)2 ByteString (com.google.protobuf.ByteString)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2