Search in sources :

Example 11 with UiThread

use of androidx.annotation.UiThread in project mobile-center-sdk-android by Microsoft.

the class Distribute method setInstalling.

/**
 * Update download state to installing if state did not change.
 *
 * @param releaseDetails to check state change.
 */
@UiThread
synchronized void setInstalling(@NonNull ReleaseDetails releaseDetails) {
    if (releaseDetails != mReleaseDetails) {
        return;
    }
    if (releaseDetails.isMandatoryUpdate()) {
        cancelNotification();
        SharedPreferencesManager.putInt(PREFERENCE_KEY_DOWNLOAD_STATE, DOWNLOAD_STATE_INSTALLING);
    } else {
        completeWorkflow(releaseDetails);
    }
    String groupId = releaseDetails.getDistributionGroupId();
    String releaseHash = releaseDetails.getReleaseHash();
    int releaseId = releaseDetails.getId();
    AppCenterLog.debug(LOG_TAG, "Stored release details: group id=" + groupId + " release hash=" + releaseHash + " release id=" + releaseId);
    SharedPreferencesManager.putString(PREFERENCE_KEY_DOWNLOADED_DISTRIBUTION_GROUP_ID, groupId);
    SharedPreferencesManager.putString(PREFERENCE_KEY_DOWNLOADED_RELEASE_HASH, releaseHash);
    SharedPreferencesManager.putInt(PREFERENCE_KEY_DOWNLOADED_RELEASE_ID, releaseId);
}
Also used : SuppressLint(android.annotation.SuppressLint) UiThread(androidx.annotation.UiThread)

Example 12 with UiThread

use of androidx.annotation.UiThread in project mobile-center-sdk-android by Microsoft.

the class Distribute method notifyDownload.

/**
 * Post notification about a completed download if we are in background when download completes.
 * If this method is called on app process restart or if application is in foreground
 * when download completes, it will not notify and return that the install U.I. should be shown now.
 *
 * @param releaseDetails release details to check state.
 * @return false if install U.I should be shown now, true if a notification was posted or if the task was canceled.
 */
@UiThread
synchronized boolean notifyDownload(ReleaseDetails releaseDetails) {
    /* Check state. */
    if (releaseDetails != mReleaseDetails) {
        return true;
    }
    /*
         * If we already notified, that means this check was triggered by application being resumed,
         * thus in foreground at the moment the check download async task was started.
         *
         * We should not hold the install any longer now, even if the async task was long enough
         * for app to be in background again, we should show install U.I. now.
         */
    if (mForegroundActivity != null || getStoredDownloadState() == DOWNLOAD_STATE_NOTIFIED) {
        return false;
    }
    /* Post notification. */
    AppCenterLog.debug(LOG_TAG, "Post a notification as the download finished in background.");
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        /* Create or update notification channel (mandatory on Android 8 target). */
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, mContext.getString(R.string.appcenter_distribute_notification_category), NotificationManager.IMPORTANCE_DEFAULT);
        // noinspection ConstantConditions
        notificationManager.createNotificationChannel(channel);
        builder = new Notification.Builder(mContext, NOTIFICATION_CHANNEL_ID);
    } else {
        builder = getOldNotificationBuilder();
    }
    builder.setTicker(mContext.getString(R.string.appcenter_distribute_install_ready_title)).setContentTitle(mContext.getString(R.string.appcenter_distribute_install_ready_title)).setContentText(getInstallReadyMessage()).setSmallIcon(mContext.getApplicationInfo().icon);
    builder.setStyle(new Notification.BigTextStyle().bigText(getInstallReadyMessage()));
    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    // noinspection ConstantConditions
    notificationManager.notify(DistributeUtils.getNotificationId(), notification);
    SharedPreferencesManager.putInt(PREFERENCE_KEY_DOWNLOAD_STATE, DOWNLOAD_STATE_NOTIFIED);
    /* Reset check download flag to show install U.I. on resume if notification ignored. */
    mCheckedDownload = false;
    return true;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) Notification(android.app.Notification) UiThread(androidx.annotation.UiThread)

Example 13 with UiThread

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

the class ConversationItemThumbnail method setImageResource.

@UiThread
public void setImageResource(@NonNull GlideRequests glideRequests, @NonNull List<Slide> slides, boolean showControls, boolean isPreview) {
    if (slides.size() == 1) {
        Slide slide = slides.get(0);
        if (slide.isVideoGif()) {
            setThumbnailBounds(gifBounds);
        } else {
            setThumbnailBounds(normalBounds);
            if (minimumThumbnailWidth != -1) {
                thumbnail.setMinimumThumbnailWidth(minimumThumbnailWidth);
            }
        }
        thumbnail.setVisibility(VISIBLE);
        album.setVisibility(GONE);
        Attachment attachment = slides.get(0).asAttachment();
        thumbnail.setImageResource(glideRequests, slides.get(0), showControls, isPreview, attachment.getWidth(), attachment.getHeight());
        setTouchDelegate(thumbnail.getTouchDelegate());
    } else {
        thumbnail.setVisibility(GONE);
        album.setVisibility(VISIBLE);
        album.setSlides(glideRequests, slides, showControls);
        setTouchDelegate(album.getTouchDelegate());
    }
}
Also used : Slide(org.thoughtcrime.securesms.mms.Slide) Attachment(org.thoughtcrime.securesms.attachments.Attachment) UiThread(androidx.annotation.UiThread)

Example 14 with UiThread

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

the class Utils method getTintedDrawable.

// Implicit synchronization for use of shared resource VALUE.
@UiThread
public static Drawable getTintedDrawable(Context context, @DrawableRes int id, @AttrRes int tintAttrId) {
    boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true);
    if (!attributeFound) {
        throw new Resources.NotFoundException("Required tint color attribute with name " + context.getResources().getResourceEntryName(tintAttrId) + " and attribute ID " + tintAttrId + " was not found.");
    }
    Drawable drawable = ContextCompat.getDrawable(context, id);
    drawable = DrawableCompat.wrap(drawable.mutate());
    int color = ContextCompat.getColor(context, VALUE.resourceId);
    DrawableCompat.setTint(drawable, color);
    return drawable;
}
Also used : Drawable(android.graphics.drawable.Drawable) UiThread(androidx.annotation.UiThread)

Example 15 with UiThread

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

the class Utils method getFloat.

// Implicit synchronization for use of shared resource VALUE.
@UiThread
public static float getFloat(Context context, @DimenRes int id) {
    TypedValue value = VALUE;
    context.getResources().getValue(id, value, true);
    if (value.type == TypedValue.TYPE_FLOAT) {
        return value.getFloat();
    }
    throw new Resources.NotFoundException("Resource ID #0x" + Integer.toHexString(id) + " type #0x" + Integer.toHexString(value.type) + " is not valid");
}
Also used : TypedValue(android.util.TypedValue) 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