java类android.support.annotation.MainThread的实例源码

ParticleDevice.java 文件源码 项目:xlight_android_native 阅读 38 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
Router.java 文件源码 项目:RIBs 阅读 41 收藏 0 点赞 0 评论 0
/**
 * 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();
}
HNViewTypeManager.java 文件源码 项目:HtmlNative 阅读 42 收藏 0 点赞 0 评论 0
@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);
                }
            }
        }
    }
}
CountriesViewModel.java 文件源码 项目:NewAndroidArchitecture 阅读 42 收藏 0 点赞 0 评论 0
@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;
}
CodeScanner.java 文件源码 项目:code-scanner 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
AWindow.java 文件源码 项目:vlc-example-streamplayer 阅读 44 收藏 0 点赞 0 评论 0
@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);
    }
}
Router.java 文件源码 项目:RIBs 阅读 42 收藏 0 点赞 0 评论 0
/**
 * 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);
}
MergeResource.java 文件源码 项目:Fairy 阅读 40 收藏 0 点赞 0 评论 0
@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));
                }
            });
        });
    });
}
GrepFilter.java 文件源码 项目:Fairy 阅读 50 收藏 0 点赞 0 评论 0
@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;

    });
}
Dialog.java 文件源码 项目:vlc-example-streamplayer 阅读 49 收藏 0 点赞 0 评论 0
/**
 * 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;
    }
}
MiniDownloader.java 文件源码 项目:MiniDownloader 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 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!");
    }
}
PresenterManager.java 文件源码 项目:GitHub 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 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);
}
NetworkBoundResource.java 文件源码 项目:SampleAppArch 阅读 41 收藏 0 点赞 0 评论 0
@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)));
    }
  });
}
SingleLiveEvent.java 文件源码 项目:Android-Code-Demos 阅读 43 收藏 0 点赞 0 评论 0
@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);
            }
        }
    });
}
FitnessHabitsApplication.java 文件源码 项目:FitnessHabits 阅读 38 收藏 0 点赞 0 评论 0
@MainThread
public ParamRepository getParamRepository() {
    if (paramRepository == null) {
        paramRepository = new ParamRepository(getDatabase().paramRecordDao());
    }
    return paramRepository;
}
FoodDataRepository.java 文件源码 项目:FitnessHabits 阅读 43 收藏 0 点赞 0 评论 0
@SuppressLint("StaticFieldLeak")
@MainThread
public void saveFoodEntry(FoodEntry entry) {
    new AsyncTask<Void,Void,Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            foodDataDao.insertOrReplaceFoodEntry(entry);
            return null;
        }
    }.execute();
}
LoadController.java 文件源码 项目:LoadMoreHelper 阅读 55 收藏 0 点赞 0 评论 0
/**
 * Call when 1st page data loaded
 */
@MainThread
private void onPullDataEnd() {
    isPullingData = false;
    if (isDestoryed) {
        return;
    }
    if (paramBuilder.pullView != null) {
        paramBuilder.pullView.doPullEnd();
    }
}
DrinkRepository.java 文件源码 项目:FitnessHabits 阅读 41 收藏 0 点赞 0 评论 0
/**
 * Add value to a id for a certain date
 */
@SuppressLint("StaticFieldLeak")
@MainThread
public void replaceAmountCurrentDay(int categoryId, int amount) {
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            drinkDataDAO.replaceDrink(categoryId,amount);
            return null;
        }
    }.execute();
}
CommentDataRepository.java 文件源码 项目:FitnessHabits 阅读 36 收藏 0 点赞 0 评论 0
@SuppressLint("StaticFieldLeak")
@MainThread
public void saveAlcoolComment(CommentData comment) {
    new AsyncTask<Void,Void,Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            comment.setCategory(0);
            commentDataDao.insertOrUpdateComment(comment);
            return null;
        }
    }.execute();
}
MediaBrowser.java 文件源码 项目:vlc-example-streamplayer 阅读 48 收藏 0 点赞 0 评论 0
/**
 * Browse to the specified local path starting with '/'.
 *
 * @param path
 * @param flags see {@link Flag}
 */
@MainThread
public void browse(String path, int flags) {
    final Media media = new Media(mLibVlc, path);
    browse(media, flags);
    media.release();
}
ViewPump.java 文件源码 项目:ViewPump 阅读 47 收藏 0 点赞 0 评论 0
@MainThread
public static ViewPump get() {
    if (INSTANCE == null) {
        INSTANCE = builder().build();
    }
    return INSTANCE;
}
TransferAction.java 文件源码 项目:tumbviewer 阅读 34 收藏 0 点赞 0 评论 0
@MainThread
void transferFinish() {
    if (progressRef != null) {
        DownloadService.DownloadProgress progress = progressRef.get();
        if (progress != null) {
            progress.onDownloadFinish();
        }
    }
}
AlcoolRepository.java 文件源码 项目:FitnessHabits 阅读 38 收藏 0 点赞 0 评论 0
@SuppressLint("StaticFieldLeak")
@MainThread
public void saveAlcoolDrinkEntry(DrinkEntry entry) {
    new AsyncTask<Void,Void,Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            drinkDataDAO.insetOrReplaceDrinkEntry(entry);
            return null;
        }
    }.execute();
}
AlcoolRepository.java 文件源码 项目:FitnessHabits 阅读 42 收藏 0 点赞 0 评论 0
/**
 * Create a new alcool category
 * @param category (category.type is not required, it will be set anyways)
 */
@SuppressLint("StaticFieldLeak")
@MainThread
public void saveAlcoolDrinkCategory(DrinkCategory category) {
    new AsyncTask<Void,Void,Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            category.setType(0);
            drinkDataDAO.insetOrReplaceDrinkCategory(category);
            return null;
        }
    }.execute();
}
PresenterManager.java 文件源码 项目:Watermark 阅读 42 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SleepRepository.java 文件源码 项目:FitnessHabits 阅读 39 收藏 0 点赞 0 评论 0
@SuppressLint("StaticFieldLeak")
@MainThread
public void saveSleepEntry(SleepEntry entry) {
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            sleepEntryDAO.insertNewEntry(entry);
            return null;
        }
    }.execute();
}
ParamManager.java 文件源码 项目:FitnessHabits 阅读 59 收藏 0 点赞 0 评论 0
@SuppressLint("StaticFieldLeak")
@MainThread
public void saveParamRecord(ParamRecord record) {

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            paramRecordDao.saveParamRecord(record);
            return null;
        }
    }.execute();


}
ConnectionUtils.java 文件源码 项目:NSMPlayer-Android 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 仅当监听到网络连接成功后触发一次,只触发唯一一次
 * @param listener 触发监听器
 */
@MainThread
public static void triggerOnceUponConnected(final OnConnectedListener listener) {
    register(new OnConnectionChangeListener() {
        @Override
        public void onConnectionChange(Intent connectivityIntent) {
            if (isNetworkConnected()) {
                unregister(this);
                listener.onConnected();
            }
        }
    });
}
RealmComputableLiveData.java 文件源码 项目:realm-helpers 阅读 49 收藏 0 点赞 0 评论 0
@MainThread
@Override
public void run() {
    boolean isActive = mLiveData.hasActiveObservers();
    if (mInvalid.compareAndSet(false, true)) {
        if (isActive) {
            realmQueryExecutor.execute(mRefreshRunnable);
        }
    }
}
MediaBrowser.java 文件源码 项目:vlc-example-streamplayer 阅读 54 收藏 0 点赞 0 评论 0
/**
 * Browse to the specified uri.
 *
 * @param uri
 * @param flags see {@link Flag}
 */
@MainThread
public void browse(Uri uri, int flags) {
    final Media media = new Media(mLibVlc, uri);
    browse(media, flags);
    media.release();
}


问题


面经


文章

微信
公众号

扫码关注公众号