use of androidx.annotation.MainThread in project Douya by DreaminginCodeZH.
the class ResourcesFlusher method flushThemedResourceCache.
@MainThread
@RequiresApi(Build.VERSION_CODES.M)
@SuppressLint("PrivateApi")
private static void flushThemedResourceCache(@NonNull Object themedResourceCache) {
if (!sThemedResourceCacheClassInitialized) {
try {
sThemedResourceCacheClass = Class.forName("android.content.res.ThemedResourceCache");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
sThemedResourceCacheClassInitialized = true;
}
if (sThemedResourceCacheClass == null) {
return;
}
if (!sThemedResourceCacheMThemedEntriesFieldInitialized) {
try {
sThemedResourceCacheMThemedEntriesField = sThemedResourceCacheClass.getDeclaredField("mThemedEntries");
sThemedResourceCacheMThemedEntriesField.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
sThemedResourceCacheMThemedEntriesFieldInitialized = true;
}
if (sThemedResourceCacheMThemedEntriesField != null) {
ArrayMap themedEntries = null;
try {
themedEntries = (ArrayMap) sThemedResourceCacheMThemedEntriesField.get(themedResourceCache);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (themedEntries != null) {
themedEntries.clear();
}
}
if (!sThemedResourceCacheMUnthemedEntriesFieldInitialized) {
try {
sThemedResourceCacheMUnthemedEntriesField = sThemedResourceCacheClass.getDeclaredField("mUnthemedEntries");
sThemedResourceCacheMUnthemedEntriesField.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
sThemedResourceCacheMUnthemedEntriesFieldInitialized = true;
}
if (sThemedResourceCacheMUnthemedEntriesField != null) {
LongSparseArray unthemedEntries = null;
try {
unthemedEntries = (LongSparseArray) sThemedResourceCacheMUnthemedEntriesField.get(themedResourceCache);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (unthemedEntries != null) {
unthemedEntries.clear();
}
}
if (!sThemedResourceCacheMNullThemedEntriesFieldInitialized) {
try {
sThemedResourceCacheMNullThemedEntriesField = sThemedResourceCacheClass.getDeclaredField("mNullThemedEntries");
sThemedResourceCacheMNullThemedEntriesField.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
sThemedResourceCacheMNullThemedEntriesFieldInitialized = true;
}
if (sThemedResourceCacheMNullThemedEntriesField != null) {
LongSparseArray nullThemedEntries = null;
try {
nullThemedEntries = (LongSparseArray) sThemedResourceCacheMNullThemedEntriesField.get(themedResourceCache);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (nullThemedEntries != null) {
nullThemedEntries.clear();
}
}
}
use of androidx.annotation.MainThread in project SeriesGuide by UweTrottmann.
the class TaskManager method performAddTask.
/**
* Schedule shows to be added to the database.
*
* @param isSilentMode Whether to display status toasts if a show could not be added.
* @param isMergingShows Whether to set the Hexagon show merged flag to true if all shows were
*/
@MainThread
public synchronized void performAddTask(final Context context, final List<SearchResult> shows, final boolean isSilentMode, final boolean isMergingShows) {
if (!isSilentMode) {
// notify user here already
if (shows.size() == 1) {
// say title of show
SearchResult show = shows.get(0);
Toast.makeText(context, context.getString(R.string.add_started, show.getTitle()), Toast.LENGTH_SHORT).show();
} else {
// generic adding multiple message
Toast.makeText(context, R.string.add_multiple, Toast.LENGTH_SHORT).show();
}
}
// noinspection ConstantConditions: null check in isAddTaskRunning
if (!isAddTaskRunning() || !addShowTask.addShows(shows, isSilentMode, isMergingShows)) {
addShowTask = new AddShowTask(context, shows, isSilentMode, isMergingShows);
addShowTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of androidx.annotation.MainThread in project android-beacon-library by AltBeacon.
the class CycledLeScanner method setScanPeriods.
/**
* Tells the cycler the scan rate and whether it is in operating in background mode.
* Background mode flag is used only with the Android 5.0 scanning implementations to switch
* between LOW_POWER_MODE vs. LOW_LATENCY_MODE
* @param backgroundFlag
*/
@MainThread
public void setScanPeriods(long scanPeriod, long betweenScanPeriod, boolean backgroundFlag) {
LogManager.d(TAG, "Set scan periods called with %s, %s Background mode must have changed.", scanPeriod, betweenScanPeriod);
if (mBackgroundFlag != backgroundFlag) {
mRestartNeeded = true;
}
mBackgroundFlag = backgroundFlag;
mScanPeriod = scanPeriod;
mBetweenScanPeriod = betweenScanPeriod;
if (mBackgroundFlag) {
LogManager.d(TAG, "We are in the background. Setting wakeup alarm");
setWakeUpAlarm();
} else {
LogManager.d(TAG, "We are not in the background. Cancelling wakeup alarm");
cancelWakeUpAlarm();
}
long now = SystemClock.elapsedRealtime();
if (mNextScanCycleStartTime > now) {
// We are waiting to start scanning. We may need to adjust the next start time
// only do an adjustment if we need to make it happen sooner. Otherwise, it will
// take effect on the next cycle.
long proposedNextScanStartTime = (mLastScanCycleEndTime + betweenScanPeriod);
if (proposedNextScanStartTime < mNextScanCycleStartTime) {
mNextScanCycleStartTime = proposedNextScanStartTime;
LogManager.i(TAG, "Adjusted nextScanStartTime to be %s", new Date(mNextScanCycleStartTime - SystemClock.elapsedRealtime() + System.currentTimeMillis()));
}
}
if (mScanCycleStopTime > now) {
// we are waiting to stop scanning. We may need to adjust the stop time
// only do an adjustment if we need to make it happen sooner. Otherwise, it will
// take effect on the next cycle.
long proposedScanStopTime = (mLastScanCycleStartTime + scanPeriod);
if (proposedScanStopTime < mScanCycleStopTime) {
mScanCycleStopTime = proposedScanStopTime;
LogManager.i(TAG, "Adjusted scanStopTime to be %s", mScanCycleStopTime);
}
}
}
use of androidx.annotation.MainThread in project Signal-Android by signalapp.
the class VoiceNotePlaybackPreparer method applyDescriptionsToQueue.
@MainThread
private void applyDescriptionsToQueue(@NonNull List<MediaItem> mediaItems) {
for (MediaItem mediaItem : mediaItems) {
MediaItem.PlaybackProperties playbackProperties = mediaItem.playbackProperties;
if (playbackProperties == null) {
continue;
}
int holderIndex = indexOfPlayerMediaItemByUri(playbackProperties.uri);
MediaItem next = VoiceNoteMediaItemFactory.buildNextVoiceNoteMediaItem(mediaItem);
int currentIndex = player.getCurrentWindowIndex();
if (holderIndex != -1) {
if (currentIndex != holderIndex) {
player.removeMediaItem(holderIndex);
player.addMediaItem(holderIndex, mediaItem);
}
if (currentIndex != holderIndex + 1) {
if (player.getMediaItemCount() > 1) {
player.removeMediaItem(holderIndex + 1);
}
player.addMediaItem(holderIndex + 1, next);
}
} else {
int insertLocation = indexAfter(mediaItem);
player.addMediaItem(insertLocation, next);
player.addMediaItem(insertLocation, mediaItem);
}
}
int itemsCount = player.getMediaItemCount();
if (itemsCount > 0) {
int lastIndex = itemsCount - 1;
MediaItem last = player.getMediaItemAt(lastIndex);
if (last.playbackProperties != null && Objects.equals(last.playbackProperties.uri, VoiceNoteMediaItemFactory.NEXT_URI)) {
player.removeMediaItem(lastIndex);
if (player.getMediaItemCount() > 1) {
MediaItem end = VoiceNoteMediaItemFactory.buildEndVoiceNoteMediaItem(last);
player.addMediaItem(lastIndex, end);
}
}
}
}
use of androidx.annotation.MainThread in project Signal-Android by signalapp.
the class VerificationCodeView method append.
@MainThread
public void append(int value) {
if (index >= codes.size())
return;
setInactive(containers);
setActive(containers.get(index));
TextView codeView = codes.get(index++);
Animation translateIn = new TranslateAnimation(0, 0, codeView.getHeight(), 0);
translateIn.setInterpolator(new OvershootInterpolator());
translateIn.setDuration(500);
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setDuration(200);
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(fadeIn);
animationSet.addAnimation(translateIn);
animationSet.reset();
animationSet.setStartTime(0);
codeView.setText(String.valueOf(value));
codeView.clearAnimation();
codeView.startAnimation(animationSet);
if (index == codes.size() && listener != null) {
listener.onCodeComplete(Stream.of(codes).map(TextView::getText).collect(Collectors.joining()));
}
}
Aggregations