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);
}
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;
}
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());
}
}
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;
}
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");
}
Aggregations