Search in sources :

Example 1 with UiThread

use of androidx.annotation.UiThread in project butterknife by JakeWharton.

the class ButterKnife method bind.

/**
 * BindView annotated fields and methods in the specified {@code target} using the {@code source}
 * {@link View} as the view root.
 *
 * @param target Target class for view binding.
 * @param source View root on which IDs will be looked up.
 */
@NonNull
@UiThread
public static Unbinder bind(@NonNull Object target, @NonNull View source) {
    List<Unbinder> unbinders = new ArrayList<>();
    Class<?> targetClass = target.getClass();
    if ((targetClass.getModifiers() & PRIVATE) != 0) {
        throw new IllegalArgumentException(targetClass.getName() + " must not be private.");
    }
    while (true) {
        String clsName = targetClass.getName();
        if (clsName.startsWith("android.") || clsName.startsWith("java.") || clsName.startsWith("androidx.")) {
            break;
        }
        for (Field field : targetClass.getDeclaredFields()) {
            int unbinderStartingSize = unbinders.size();
            Unbinder unbinder;
            unbinder = parseBindView(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindViews(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindAnim(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindArray(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindBitmap(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindBool(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindColor(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindDimen(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindDrawable(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindFloat(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindFont(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindInt(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseBindString(target, field, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            if (unbinders.size() - unbinderStartingSize > 1) {
                throw new IllegalStateException("More than one bind annotation on " + targetClass.getName() + "." + field.getName());
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Unbinder unbinder;
            unbinder = parseOnCheckedChanged(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnClick(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnEditorAction(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnFocusChange(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnItemClick(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnItemLongClick(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnLongClick(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnPageChange(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnTextChanged(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
            unbinder = parseOnTouch(target, method, source);
            if (unbinder != null)
                unbinders.add(unbinder);
        }
        targetClass = targetClass.getSuperclass();
    }
    if (unbinders.isEmpty()) {
        if (debug)
            Log.d(TAG, "MISS: Reached framework class. Abandoning search.");
        return Unbinder.EMPTY;
    }
    if (debug)
        Log.d(TAG, "HIT: Reflectively found " + unbinders.size() + " bindings.");
    return new CompositeUnbinder(unbinders);
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) UiThread(androidx.annotation.UiThread) NonNull(androidx.annotation.NonNull)

Example 2 with UiThread

use of androidx.annotation.UiThread in project k-9 by k9mail.

the class MessageLoaderHelper method onLoadMessageFromDatabaseFinished.

@UiThread
private void onLoadMessageFromDatabaseFinished() {
    if (callback == null) {
        throw new IllegalStateException("unexpected call when callback is already detached");
    }
    callback.onMessageDataLoadFinished(localMessage);
    boolean downloadedCompletely = localMessage.isSet(Flag.X_DOWNLOADED_FULL);
    boolean downloadedPartially = localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL);
    boolean messageIncomplete = !downloadedCompletely && !downloadedPartially;
    if (messageIncomplete) {
        startDownloadingMessageBody(false);
        return;
    }
    if (onlyLoadMetadata) {
        MessageViewInfo messageViewInfo = MessageViewInfo.createForMetadataOnly(localMessage, !downloadedCompletely);
        onDecodeMessageFinished(messageViewInfo);
        return;
    }
    String openPgpProvider = account.getOpenPgpProvider();
    if (openPgpProvider != null) {
        startOrResumeCryptoOperation(openPgpProvider);
        return;
    }
    startOrResumeDecodeMessage();
}
Also used : MessageViewInfo(com.fsck.k9.mailstore.MessageViewInfo) UiThread(androidx.annotation.UiThread)

Example 3 with UiThread

use of androidx.annotation.UiThread in project materialistic by hidroh.

the class SyncDelegate method scheduleSync.

@UiThread
static void scheduleSync(Context context, Job job) {
    if (!Preferences.Offline.isEnabled(context)) {
        return;
    }
    if (!TextUtils.isEmpty(job.id)) {
        JobInfo.Builder builder = new JobInfo.Builder(Long.valueOf(job.id).intValue(), new ComponentName(context.getPackageName(), ItemSyncJobService.class.getName())).setRequiredNetworkType(Preferences.Offline.isWifiOnly(context) ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY).setExtras(job.toPersistableBundle());
        if (Preferences.Offline.currentConnectionEnabled(context)) {
            builder.setOverrideDeadline(0);
        }
        ((JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(builder.build());
    } else {
        Bundle extras = new Bundle(job.toBundle());
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        Account syncAccount;
        AccountManager accountManager = AccountManager.get(context);
        Account[] accounts = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID);
        if (accounts.length == 0) {
            syncAccount = new Account(SYNC_ACCOUNT_NAME, BuildConfig.APPLICATION_ID);
            accountManager.addAccountExplicitly(syncAccount, null, null);
        } else {
            syncAccount = accounts[0];
        }
        ContentResolver.requestSync(syncAccount, SyncContentProvider.PROVIDER_AUTHORITY, extras);
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) Account(android.accounts.Account) JobInfo(android.app.job.JobInfo) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) ComponentName(android.content.ComponentName) AccountManager(android.accounts.AccountManager) UiThread(androidx.annotation.UiThread)

Example 4 with UiThread

use of androidx.annotation.UiThread in project AntennaPod by AntennaPod.

the class OnlineFeedViewActivity method showErrorDialog.

@UiThread
private void showErrorDialog(String errorMsg, String details) {
    if (!isFinishing() && !isPaused) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.error_label);
        if (errorMsg != null) {
            String total = errorMsg + "\n\n" + details;
            SpannableString errorMessage = new SpannableString(total);
            errorMessage.setSpan(new ForegroundColorSpan(0x88888888), errorMsg.length(), total.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setMessage(errorMessage);
        } else {
            builder.setMessage(R.string.download_error_error_unknown);
        }
        builder.setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.cancel());
        builder.setOnDismissListener(dialog -> {
            setResult(RESULT_ERROR);
            finish();
        });
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
        dialog = builder.show();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableString(android.text.SpannableString) UiThread(androidx.annotation.UiThread)

Example 5 with UiThread

use of androidx.annotation.UiThread in project Signal-Android by WhisperSystems.

the class ThumbnailView method setImageResource.

@UiThread
public ListenableFuture<Boolean> setImageResource(@NonNull GlideRequests glideRequests, @NonNull Slide slide, boolean showControls, boolean isPreview, int naturalWidth, int naturalHeight) {
    if (showControls) {
        getTransferControls().setSlide(slide);
        getTransferControls().setDownloadClickListener(new DownloadClickDispatcher());
    } else if (transferControls.isPresent()) {
        getTransferControls().setVisibility(View.GONE);
    }
    if (slide.getUri() != null && slide.hasPlayOverlay() && (slide.getTransferState() == AttachmentDatabase.TRANSFER_PROGRESS_DONE || isPreview)) {
        this.playOverlay.setVisibility(View.VISIBLE);
    } else {
        this.playOverlay.setVisibility(View.GONE);
    }
    if (Util.equals(slide, this.slide)) {
        Log.i(TAG, "Not re-loading slide " + slide.asAttachment().getUri());
        return new SettableFuture<>(false);
    }
    if (this.slide != null && this.slide.getFastPreflightId() != null && (!slide.hasVideo() || Util.equals(this.slide.getUri(), slide.getUri())) && Util.equals(this.slide.getFastPreflightId(), slide.getFastPreflightId())) {
        Log.i(TAG, "Not re-loading slide for fast preflight: " + slide.getFastPreflightId());
        this.slide = slide;
        return new SettableFuture<>(false);
    }
    Log.i(TAG, "loading part with id " + slide.asAttachment().getUri() + ", progress " + slide.getTransferState() + ", fast preflight id: " + slide.asAttachment().getFastPreflightId());
    BlurHash previousBlurhash = this.slide != null ? this.slide.getPlaceholderBlur() : null;
    this.slide = slide;
    this.captionIcon.setVisibility(slide.getCaption().isPresent() ? VISIBLE : GONE);
    dimens[WIDTH] = naturalWidth;
    dimens[HEIGHT] = naturalHeight;
    invalidate();
    SettableFuture<Boolean> result = new SettableFuture<>();
    boolean resultHandled = false;
    if (slide.hasPlaceholder() && (previousBlurhash == null || !Objects.equals(slide.getPlaceholderBlur(), previousBlurhash))) {
        buildPlaceholderGlideRequest(glideRequests, slide).into(new GlideBitmapListeningTarget(blurhash, result));
        resultHandled = true;
    } else if (!slide.hasPlaceholder()) {
        glideRequests.clear(blurhash);
        blurhash.setImageDrawable(null);
    }
    if (slide.getUri() != null) {
        if (!MediaUtil.isJpegType(slide.getContentType()) && !MediaUtil.isVideoType(slide.getContentType())) {
            SettableFuture<Boolean> thumbnailFuture = new SettableFuture<>();
            thumbnailFuture.deferTo(result);
            thumbnailFuture.addListener(new BlurhashClearListener(glideRequests, blurhash));
        }
        buildThumbnailGlideRequest(glideRequests, slide).into(new GlideDrawableListeningTarget(image, result));
        resultHandled = true;
    } else {
        glideRequests.clear(image);
        image.setImageDrawable(null);
    }
    if (!resultHandled) {
        result.set(false);
    }
    return result;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) BlurHash(org.thoughtcrime.securesms.blurhash.BlurHash) UiThread(androidx.annotation.UiThread)

Aggregations

UiThread (androidx.annotation.UiThread)22 ArrayList (java.util.ArrayList)5 Feature (com.mapbox.geojson.Feature)4 SuppressLint (android.annotation.SuppressLint)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 BlurHash (org.thoughtcrime.securesms.blurhash.BlurHash)2 Slide (org.thoughtcrime.securesms.mms.Slide)2 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 Notification (android.app.Notification)1 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 JobInfo (android.app.job.JobInfo)1 JobScheduler (android.app.job.JobScheduler)1 ComponentName (android.content.ComponentName)1 Drawable (android.graphics.drawable.Drawable)1