當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。