本文整理汇总了Java中android.support.annotation.MainThread类的典型用法代码示例。如果您正苦于以下问题:Java MainThread类的具体用法?Java MainThread怎么用?Java MainThread使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MainThread类属于android.support.annotation包,在下文中一共展示了MainThread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribeToSystemEvents
import android.support.annotation.MainThread; //导入依赖的package包/类
/**
* Subscribes to system events of current device. Events emitted to EventBus listener.
*
* @throws ParticleCloudException Failure to subscribe to system events.
* @see <a href="https://github.com/greenrobot/EventBus">EventBus</a>
*/
@MainThread
public void subscribeToSystemEvents() throws ParticleCloudException {
try {
EventBus eventBus = EventBus.getDefault();
subscriptions.add(subscribeToSystemEvent("spark/status", (eventName, particleEvent) ->
sendUpdateStatusChange(eventBus, particleEvent.dataPayload)));
subscriptions.add(subscribeToSystemEvent("spark/flash/status", (eventName, particleEvent) ->
sendUpdateFlashChange(eventBus, particleEvent.dataPayload)));
subscriptions.add(subscribeToSystemEvent("spark/device/app-hash", (eventName, particleEvent) ->
sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
ParticleDeviceState.APP_HASH_UPDATED), eventBus)));
subscriptions.add(subscribeToSystemEvent("spark/status/safe-mode", (eventName, particleEvent) ->
sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
ParticleDeviceState.SAFE_MODE_UPDATER), eventBus)));
subscriptions.add(subscribeToSystemEvent("spark/safe-mode-updater/updating", (eventName, particleEvent) ->
sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
ParticleDeviceState.ENTERED_SAFE_MODE), eventBus)));
} catch (IOException e) {
log.d("Failed to auto-subscribe to system events");
throw new ParticleCloudException(e);
}
}
示例2: detachChild
import android.support.annotation.MainThread; //导入依赖的package包/类
/**
* Detaches the {@param childFactory} from the current {@link Interactor}. NOTE: No consumers of
* this API should ever keep a reference to the detached child router, leak canary will enforce
* that it gets garbage collected.
*
* <p>If you need to keep references to previous routers, use {@link RouterNavigator}.
*
* @param childRouter the {@link Router} to be detached.
*/
@MainThread
protected void detachChild(Router childRouter) {
children.remove(childRouter);
Interactor interactor = childRouter.getInteractor();
ribRefWatcher.watchDeletedObject(interactor);
ribRefWatcher.logBreadcrumb(
"DETACHED", childRouter.getClass().getSimpleName(), this.getClass().getSimpleName());
if (savedInstanceState != null) {
Bundle childrenBundles =
checkNotNull(savedInstanceState.getBundleExtra(KEY_CHILD_ROUTERS));
childrenBundles.putBundleExtra(childRouter.tag, null);
}
childRouter.dispatchDetach();
}
示例3: registerViewType
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
static synchronized void registerViewType(HNViewType viewType) {
if (viewType.getViewClass() != null && viewType.getHTMLType() != null) {
ViewTypeRelations.registerExtraView(viewType.getViewClass().getName(), viewType
.getHTMLType());
StyleHandlerFactory.registerExtraStyleHandler(viewType.getViewClass(), viewType);
HNRenderer.registerViewFactory(viewType.getViewClass().getName(), viewType);
Set<String> inheritStyleNames = viewType.onInheritStyleNames();
if (inheritStyleNames != null && !inheritStyleNames.isEmpty()) {
for (String style : inheritStyleNames) {
if (!InheritStylesRegistry.isPreserved(style)) {
InheritStylesRegistry.register(style);
}
}
}
}
}
示例4: getMoviesList
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
@NonNull
LiveData<Response<List<Country>>> getMoviesList() {
if (countriesLiveData == null) {
countriesLiveData = new MutableLiveData<>();
countriesRepository.getCountries()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(disposable -> loadingLiveData.setValue(true))
.doAfterTerminate(() -> loadingLiveData.setValue(false))
.subscribe(
countries1 -> countriesLiveData.setValue(Response.success(countries1)),
throwable -> countriesLiveData.setValue(Response.error(throwable))
);
}
return countriesLiveData;
}
示例5: setCamera
import android.support.annotation.MainThread; //导入依赖的package包/类
/**
* Camera to use
*
* @param cameraId Camera id (between {@code 0} and
* {@link Camera#getNumberOfCameras()} - {@code 1})
*/
@MainThread
public void setCamera(int cameraId) {
mInitializeLock.lock();
try {
if (mCameraId != cameraId) {
mCameraId = cameraId;
if (mInitialized) {
boolean previewActive = mPreviewActive;
releaseResources();
if (previewActive) {
initialize();
}
}
}
} finally {
mInitializeLock.unlock();
}
}
示例6: onSurfaceCreated
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
private void onSurfaceCreated() {
if (mSurfacesState.get() != SURFACE_STATE_ATTACHED)
throw new IllegalArgumentException("invalid state");
final SurfaceHelper videoHelper = mSurfaceHelpers[ID_VIDEO];
final SurfaceHelper subtitlesHelper = mSurfaceHelpers[ID_SUBTITLES];
if (videoHelper == null)
throw new NullPointerException("videoHelper shouldn't be null here");
if (videoHelper.isReady() && (subtitlesHelper == null || subtitlesHelper.isReady())) {
mSurfacesState.set(SURFACE_STATE_READY);
for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
cb.onSurfacesCreated(this);
if (mSurfaceCallback != null)
mSurfaceCallback.onSurfacesCreated(this);
}
}
示例7: attachChild
import android.support.annotation.MainThread; //导入依赖的package包/类
/**
* Attaches a child router to this router.
*
* @param childRouter the {@link Router} to be attached.
* @param tag an identifier to namespace saved instance state {@link Bundle} objects.
*/
@MainThread
protected void attachChild(Router<?, ?> childRouter, String tag) {
for (Router child : children) {
if (tag.equals(child.tag)) {
Rib.getConfiguration()
.handleNonFatalWarning(
String.format(
Locale.getDefault(), "There is already a child router with tag: %s", tag),
null);
}
}
children.add(childRouter);
ribRefWatcher.logBreadcrumb(
"ATTACHED", childRouter.getClass().getSimpleName(), this.getClass().getSimpleName());
Bundle childBundle = null;
if (this.savedInstanceState != null) {
Bundle previousChildren =
checkNotNull(this.savedInstanceState.getBundleExtra(KEY_CHILD_ROUTERS));
childBundle = previousChildren.getBundleExtra(tag);
}
childRouter.dispatchAttach(childBundle, tag);
}
示例8: initData
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
public void initData() {
executors.getDiskIO().execute(() -> {
LiveData<LocalType> dbSource = loadFromDb();
executors.getMainExecutor().execute(() -> {
result.addSource(dbSource, dbData -> {
result.removeSource(dbSource);
if (dbData != null) {
ZLog.d("db------" + dbData.toString());
setValue(dbData);
appendResult(castLocalToNet(dbData));
}
});
});
});
}
示例9: grepData
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
static LiveData<LogcatContent> grepData(LiveData<LogcatContent> rawData, String grep) {
return Transformations.map(rawData, logcatData -> {
String content = logcatData.getContent();
if (GREP_SIGNAL.equals(content)) {
return logcatData;
}
if (content != null) {
logcatData.setContent(parseHtml2(content,grep));
}
return logcatData;
});
}
示例10: postLogin
import android.support.annotation.MainThread; //导入依赖的package包/类
/**
* Post an answer
*
* @param username valid username (can't be empty)
* @param password valid password (can be empty)
* @param store if true, store the credentials
*/
@MainThread
public void postLogin(String username, String password, boolean store) {
if (mId != 0) {
nativePostLogin(mId, username, password, store);
mId = 0;
}
}
示例11: checkTask
import android.support.annotation.MainThread; //导入依赖的package包/类
/**
* Check task whether valid.
*
* @param task
* @return
*/
@MainThread
private void checkTask(@NonNull Task task) {
if (task == null
|| task.getUrlStr() == null
|| task.getFilePath() == null
|| task.getListener() == null
|| task.getErrorListener() == null) {
throw new IllegalArgumentException("task ,urlStr, filePath, listener, errorListener must not be null!");
}
}
示例12: getActivityScope
import android.support.annotation.MainThread; //导入依赖的package包/类
/**
* Get the {@link ActivityScopedCache} for the given Activity or <code>null</code> if no {@link
* ActivityScopedCache} exists for the given Activity
*
* @param activity The activity
* @return The {@link ActivityScopedCache} or null
* @see #getOrCreateActivityScopedCache(Activity)
*/
@Nullable @MainThread static ActivityScopedCache getActivityScope(@NonNull Activity activity) {
if (activity == null) {
throw new NullPointerException("Activity is null");
}
String activityId = activityIdMap.get(activity);
if (activityId == null) {
return null;
}
return activityScopedCacheMap.get(activityId);
}
示例13: NetworkBoundResource
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
public NetworkBoundResource(AppExecutors appExecutors) {
this.appExecutors = appExecutors;
result.setValue(Resource.loading(null));
LiveData<ResultType> dbSource = loadFromDb();
result.addSource(dbSource, data -> {
result.removeSource(dbSource);
if (shouldFetch(data)) {
fetchFromNetwork(dbSource);
} else {
result.addSource(dbSource, newData -> setValue(Resource.success(newData)));
}
});
}
示例14: observe
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
public void observe(LifecycleOwner owner, final Observer<T> observer) {
if (hasActiveObservers()) {
Log.w(TAG, "Multiple observers registered but only one will be notified of changes.");
}
super.observe(owner, new Observer<T>() {
@Override
public void onChanged(@Nullable T t) {
if (mPending.compareAndSet(true, false)) {
observer.onChanged(t);
}
}
});
}
示例15: getParamRepository
import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
public ParamRepository getParamRepository() {
if (paramRepository == null) {
paramRepository = new ParamRepository(getDatabase().paramRecordDao());
}
return paramRepository;
}