当前位置: 首页>>代码示例>>Java>>正文


Java MainThread类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:29,代码来源:ParticleDevice.java

示例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();
}
 
开发者ID:uber,项目名称:RIBs,代码行数:26,代码来源:Router.java

示例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);
                }
            }
        }
    }
}
 
开发者ID:hsllany,项目名称:HtmlNative,代码行数:20,代码来源:HNViewTypeManager.java

示例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;
}
 
开发者ID:graviton57,项目名称:NewAndroidArchitecture,代码行数:18,代码来源:CountriesViewModel.java

示例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();
    }
}
 
开发者ID:yuriy-budiyev,项目名称:code-scanner,代码行数:25,代码来源:CodeScanner.java

示例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);
    }
}
 
开发者ID:pedroSG94,项目名称:vlc-example-streamplayer,代码行数:19,代码来源:AWindow.java

示例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);
}
 
开发者ID:uber,项目名称:RIBs,代码行数:31,代码来源:Router.java

示例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));
                }
            });
        });
    });
}
 
开发者ID:Zane96,项目名称:Fairy,代码行数:17,代码来源:MergeResource.java

示例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;

    });
}
 
开发者ID:Zane96,项目名称:Fairy,代码行数:18,代码来源:GrepFilter.java

示例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;
    }
}
 
开发者ID:pedroSG94,项目名称:vlc-example-streamplayer,代码行数:15,代码来源:Dialog.java

示例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!");
    }
}
 
开发者ID:xyhuangjinfu,项目名称:MiniDownloader,代码行数:17,代码来源:MiniDownloader.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:PresenterManager.java

示例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)));
    }
  });
}
 
开发者ID:charlesng,项目名称:SampleAppArch,代码行数:15,代码来源:NetworkBoundResource.java

示例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);
            }
        }
    });
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:16,代码来源:SingleLiveEvent.java

示例15: getParamRepository

import android.support.annotation.MainThread; //导入依赖的package包/类
@MainThread
public ParamRepository getParamRepository() {
    if (paramRepository == null) {
        paramRepository = new ParamRepository(getDatabase().paramRecordDao());
    }
    return paramRepository;
}
 
开发者ID:strudelauxpommes,项目名称:FitnessHabits,代码行数:8,代码来源:FitnessHabitsApplication.java


注:本文中的android.support.annotation.MainThread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。