com.jess.arms.utils.Preconditions Java Examples
The following examples show how to use
com.jess.arms.utils.Preconditions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryManager.java From MVPArms with Apache License 2.0 | 6 votes |
/** * 根据传入的 Class 获取对应的 RxCache service * * @param cacheClass Cache class * @param <T> Cache class * @return Cache */ @NonNull @Override public synchronized <T> T obtainCacheService(@NonNull Class<T> cacheClass) { Preconditions.checkNotNull(cacheClass, "cacheClass == null"); if (mCacheServiceCache == null) { mCacheServiceCache = mCacheFactory.build(CacheType.CACHE_SERVICE_CACHE); } Preconditions.checkNotNull(mCacheServiceCache, "Cannot return null from a Cache.Factory#build(int) method"); T cacheService = (T) mCacheServiceCache.get(cacheClass.getCanonicalName()); if (cacheService == null) { cacheService = mRxCache.get().using(cacheClass); mCacheServiceCache.put(cacheClass.getCanonicalName(), cacheService); } return cacheService; }
Example #2
Source File: RepositoryManager.java From MVPArms with Apache License 2.0 | 6 votes |
/** * 根据传入的 Class 获取对应的 Retrofit service * * @param serviceClass ApiService class * @param <T> ApiService class * @return ApiService */ @NonNull @Override public synchronized <T> T obtainRetrofitService(@NonNull Class<T> serviceClass) { if (mRetrofitServiceCache == null) { mRetrofitServiceCache = mCacheFactory.build(CacheType.RETROFIT_SERVICE_CACHE); } Preconditions.checkNotNull(mRetrofitServiceCache, "Cannot return null from a Cache.Factory#build(int) method"); T retrofitService = (T) mRetrofitServiceCache.get(serviceClass.getCanonicalName()); if (retrofitService == null) { if (mObtainServiceDelegate != null) { retrofitService = mObtainServiceDelegate.createRetrofitService( mRetrofit.get(), serviceClass); } if (retrofitService == null) { retrofitService = (T) Proxy.newProxyInstance( serviceClass.getClassLoader(), new Class[]{serviceClass}, new RetrofitServiceProxyHandler(mRetrofit.get(), serviceClass)); } mRetrofitServiceCache.put(serviceClass.getCanonicalName(), retrofitService); } return retrofitService; }
Example #3
Source File: GlideImageLoaderStrategy.java From MVPArms with Apache License 2.0 | 5 votes |
@Override public void clear(@Nullable final Context ctx, @Nullable ImageConfigImpl config) { Preconditions.checkNotNull(ctx, "Context is required"); Preconditions.checkNotNull(config, "ImageConfigImpl is required"); if (config.getImageView() != null) { GlideArms.get(ctx).getRequestManagerRetriever().get(ctx).clear(config.getImageView()); } if (config.getImageViews() != null && config.getImageViews().length > 0) {//取消在执行的任务并且释放资源 for (ImageView imageView : config.getImageViews()) { GlideArms.get(ctx).getRequestManagerRetriever().get(ctx).clear(imageView); } } if (config.isClearDiskCache()) {//清除本地缓存 Completable.fromAction(new Action() { @Override public void run() throws Exception { Glide.get(ctx).clearDiskCache(); } }).subscribeOn(Schedulers.io()).subscribe(); } if (config.isClearMemory()) {//清除内存缓存 Completable.fromAction(new Action() { @Override public void run() throws Exception { Glide.get(ctx).clearMemory(); } }).subscribeOn(AndroidSchedulers.mainThread()).subscribe(); } }
Example #4
Source File: BaseApplication.java From Aurora with Apache License 2.0 | 5 votes |
/** * 将 {@link AppComponent} 返回出去,供其它地方使用,{@link AppComponent} 中声明的方法所返回的实例 * 在 {@link #getAppComponent()}拿到对象后都可以直接使用 * * @return */ @NonNull @Override public AppComponent getAppComponent() { Preconditions.checkNotNull(mAppDelegate, "%s cannot be null", AppDelegate.class.getName()); Preconditions.checkState(mAppDelegate instanceof App, "%s must be implements %s", AppDelegate.class.getName(), App.class.getName()); return ((App) mAppDelegate).getAppComponent(); }
Example #5
Source File: AppDelegate.java From Aurora with Apache License 2.0 | 5 votes |
/** * 将AppComponent返回出去,供其它地方使用, AppComponent接口中声明的方法返回的实例,在getAppComponent()拿到对象后都可以直接使用 * * @return */ @NonNull @Override public AppComponent getAppComponent() { Preconditions.checkNotNull(mAppComponent, "%s cannot be null,first call %s#onCreate(Application) in %s#onCreate()", AppComponent.class.getName(), getClass().getName(), Application.class.getName()); return mAppComponent; }
Example #6
Source File: RepositoryManager.java From Aurora with Apache License 2.0 | 5 votes |
/** * 根据传入的 Class 获取对应的 Retrofit service * * @param service * @param <T> * @return */ @Override public synchronized <T> T obtainRetrofitService(Class<T> service) { if (mRetrofitServiceCache == null) mRetrofitServiceCache = mCachefactory.build(CacheType.RETROFIT_SERVICE_CACHE); Preconditions.checkNotNull(mRetrofitServiceCache, "Cannot return null from a Cache.Factory#build(int) method"); T retrofitService = (T) mRetrofitServiceCache.get(service.getCanonicalName()); if (retrofitService == null) { retrofitService = mRetrofit.get().create(service); mRetrofitServiceCache.put(service.getCanonicalName(), retrofitService); } return retrofitService; }
Example #7
Source File: RepositoryManager.java From Aurora with Apache License 2.0 | 5 votes |
/** * 根据传入的 Class 获取对应的 RxCache service * * @param cache * @param <T> * @return */ @Override public synchronized <T> T obtainCacheService(Class<T> cache) { if (mCacheServiceCache == null) mCacheServiceCache = mCachefactory.build(CacheType.CACHE_SERVICE_CACHE); Preconditions.checkNotNull(mCacheServiceCache, "Cannot return null from a Cache.Factory#build(int) method"); T cacheService = (T) mCacheServiceCache.get(cache.getCanonicalName()); if (cacheService == null) { cacheService = mRxCache.get().using(cache); mCacheServiceCache.put(cache.getCanonicalName(), cacheService); } return cacheService; }
Example #8
Source File: BasePresenter.java From Aurora with Apache License 2.0 | 5 votes |
/** * 如果当前页面同时需要 Model 层和 View 层,则使用此构造函数(默认) * * @param model * @param rootView */ public BasePresenter(M model, V rootView) { Preconditions.checkNotNull(model, "%s cannot be null", IModel.class.getName()); Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName()); this.mModel = model; this.mRootView = rootView; onStart(); }
Example #9
Source File: BasePresenter.java From MVPArms with Apache License 2.0 | 5 votes |
/** * 如果当前页面同时需要 Model 层和 View 层,则使用此构造函数(默认) * * @param model * @param rootView */ public BasePresenter(M model, V rootView) { Preconditions.checkNotNull(model, "%s cannot be null", IModel.class.getName()); Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName()); this.mModel = model; this.mRootView = rootView; onStart(); }
Example #10
Source File: BaseApplication.java From MVPArms with Apache License 2.0 | 5 votes |
/** * 将 {@link AppComponent} 返回出去, 供其它地方使用, {@link AppComponent} 接口中声明的方法所返回的实例, 在 {@link #getAppComponent()} 拿到对象后都可以直接使用 * * @return AppComponent * @see ArmsUtils#obtainAppComponentFromContext(Context) 可直接获取 {@link AppComponent} */ @NonNull @Override public AppComponent getAppComponent() { Preconditions.checkNotNull(mAppDelegate, "%s cannot be null", AppDelegate.class.getName()); Preconditions.checkState(mAppDelegate instanceof App, "%s must be implements %s", mAppDelegate.getClass().getName(), App.class.getName()); return ((App) mAppDelegate).getAppComponent(); }
Example #11
Source File: AppDelegate.java From MVPArms with Apache License 2.0 | 5 votes |
/** * 将 {@link AppComponent} 返回出去, 供其它地方使用, {@link AppComponent} 接口中声明的方法返回的实例, 在 {@link #getAppComponent()} 拿到对象后都可以直接使用 * * @return AppComponent * @see ArmsUtils#obtainAppComponentFromContext(Context) 可直接获取 {@link AppComponent} */ @NonNull @Override public AppComponent getAppComponent() { Preconditions.checkNotNull(mAppComponent, "%s == null, first call %s#onCreate(Application) in %s#onCreate()", AppComponent.class.getName(), getClass().getName(), mApplication == null ? Application.class.getName() : mApplication.getClass().getName()); return mAppComponent; }
Example #12
Source File: FragmentLifecycle.java From MVPArms with Apache License 2.0 | 4 votes |
@NonNull private Cache<String, Object> getCacheFromFragment(IFragment fragment) { Cache<String, Object> cache = fragment.provideCache(); Preconditions.checkNotNull(cache, "%s cannot be null on Fragment", Cache.class.getName()); return cache; }
Example #13
Source File: GlideImageLoaderStrategy.java From MVPArms with Apache License 2.0 | 4 votes |
@Override public void loadImage(@Nullable Context ctx, @Nullable ImageConfigImpl config) { Preconditions.checkNotNull(ctx, "Context is required"); Preconditions.checkNotNull(config, "ImageConfigImpl is required"); Preconditions.checkNotNull(config.getImageView(), "ImageView is required"); GlideRequests requests; requests = GlideArms.with(ctx);//如果context是activity则自动使用Activity的生命周期 GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()); switch (config.getCacheStrategy()) { //缓存策略 case CacheStrategy.NONE: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case CacheStrategy.RESOURCE: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case CacheStrategy.DATA: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case CacheStrategy.AUTOMATIC: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; default: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; } if (config.isCrossFade()) { glideRequest.transition(DrawableTransitionOptions.withCrossFade()); } if (config.isCenterCrop()) { glideRequest.centerCrop(); } if (config.isCircle()) { glideRequest.circleCrop(); } if (config.isImageRadius()) { glideRequest.transform(new RoundedCorners(config.getImageRadius())); } if (config.isBlurImage()) { glideRequest.transform(new BlurTransformation(config.getBlurValue())); } if (config.getTransformation() != null) {//glide用它来改变图形的形状 glideRequest.transform(config.getTransformation()); } if (config.getPlaceholder() != 0)//设置占位符 { glideRequest.placeholder(config.getPlaceholder()); } if (config.getErrorPic() != 0)//设置错误的图片 { glideRequest.error(config.getErrorPic()); } if (config.getFallback() != 0)//设置请求 url 为空图片 { glideRequest.fallback(config.getFallback()); } glideRequest .into(config.getImageView()); }
Example #14
Source File: BasePresenter.java From MVPArms with Apache License 2.0 | 4 votes |
/** * 如果当前页面不需要操作数据,只需要 View 层,则使用此构造函数 * * @param rootView */ public BasePresenter(V rootView) { Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName()); this.mRootView = rootView; onStart(); }
Example #15
Source File: GlobalConfigModule.java From MVPArms with Apache License 2.0 | 4 votes |
public Builder baseurl(BaseUrl baseUrl) { this.baseUrl = Preconditions.checkNotNull(baseUrl, BaseUrl.class.getCanonicalName() + "can not be null."); return this; }
Example #16
Source File: ActivityLifecycle.java From MVPArms with Apache License 2.0 | 4 votes |
@NonNull private Cache<String, Object> getCacheFromActivity(IActivity activity) { Cache<String, Object> cache = activity.provideCache(); Preconditions.checkNotNull(cache, "%s cannot be null on Activity", Cache.class.getName()); return cache; }
Example #17
Source File: CommonGlideImageLoaderStrategy.java From lifecycle-component with Apache License 2.0 | 4 votes |
@Override public void loadImage(Context ctx, CommonImageConfigImpl config) { Preconditions.checkNotNull(ctx, "Context is required"); Preconditions.checkNotNull(config, "ImageConfigImpl is required"); if (TextUtils.isEmpty(config.getUrl())) throw new NullPointerException("Url is required"); Preconditions.checkNotNull(config.getImageView(), "ImageView is required"); GlideRequests requests; requests = GlideArms.with(ctx);//如果context是activity则自动使用Activity的生命周期 GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()); // switch (config.getCacheStrategy()) {//缓存策略 case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; default: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; } if (config.isCrossFade()) { glideRequest.transition(DrawableTransitionOptions.withCrossFade()); } if (config.isImageRadius()) { glideRequest.transform(new RoundedCorners(config.getImageRadius())); } if (config.isBlurImage()) { glideRequest.transform(new BlurTransformation(config.getBlurValue())); } if (config.getTransformation() != null) {//glide用它来改变图形的形状 glideRequest.transform(config.getTransformation()); } if (config.getPlaceHolderDrawble() != null) { glideRequest.placeholder(config.getPlaceHolderDrawble()); } if (config.getPlaceholder() != 0)//设置占位符 glideRequest.placeholder(config.getPlaceholder()); if (config.getErrorPic() != 0)//设置错误的图片 glideRequest.error(config.getErrorPic()); if (config.getFallback() != 0)//设置请求 url 为空图片 glideRequest.fallback(config.getFallback()); if (config.getResizeX() != 0 && config.getResizeY() != 0) { glideRequest.override(config.getResizeX(), config.getResizeY()); } if (config.isCropCenter()) { glideRequest.centerCrop(); } if (config.isCropCircle()) { glideRequest.circleCrop(); } if (config.decodeFormate() != null) { glideRequest.format(config.decodeFormate()); } if (config.isFitCenter()) { glideRequest.fitCenter(); } glideRequest .into(config.getImageView()); }
Example #18
Source File: BasePresenter.java From Aurora with Apache License 2.0 | 4 votes |
/** * 如果当前页面不需要操作数据,只需要 View 层,则使用此构造函数 * * @param rootView */ public BasePresenter(V rootView) { Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName()); this.mRootView = rootView; onStart(); }
Example #19
Source File: ActivityLifecycle.java From Aurora with Apache License 2.0 | 4 votes |
@NonNull private Cache<String, Object> getCacheFromActivity(IActivity activity) { Cache<String, Object> cache = activity.provideCache(); Preconditions.checkNotNull(cache, "%s cannot be null on Activity", Cache.class.getName()); return cache; }
Example #20
Source File: FragmentLifecycle.java From Aurora with Apache License 2.0 | 4 votes |
@NonNull private Cache<String, Object> getCacheFromFragment(IFragment fragment) { Cache<String, Object> cache = fragment.provideCache(); Preconditions.checkNotNull(cache, "%s cannot be null on Fragment", Cache.class.getName()); return cache; }
Example #21
Source File: CommonGlideImageLoaderStrategy.java From Hands-Chopping with Apache License 2.0 | 4 votes |
@Override public void loadImage(Context ctx, CommonImageConfigImpl config) { Preconditions.checkNotNull(ctx, "Context is required"); Preconditions.checkNotNull(config, "ImageConfigImpl is required"); if (TextUtils.isEmpty(config.getUrl())) throw new NullPointerException("Url is required"); Preconditions.checkNotNull(config.getImageView(), "ImageView is required"); GlideRequests requests; requests = GlideArms.with(ctx);//如果context是activity则自动使用Activity的生命周期 GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()); // switch (config.getCacheStrategy()) {//缓存策略 case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; default: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; } if (config.isCrossFade()) { glideRequest.transition(DrawableTransitionOptions.withCrossFade()); } if (config.isImageRadius()) { glideRequest.transform(new RoundedCorners(config.getImageRadius())); } if (config.isBlurImage()) { glideRequest.transform(new BlurTransformation(config.getBlurValue())); } if (config.getTransformation() != null) {//glide用它来改变图形的形状 glideRequest.transform(config.getTransformation()); } if (config.getPlaceHolderDrawble() != null) { glideRequest.placeholder(config.getPlaceHolderDrawble()); } if (config.getPlaceholder() != 0)//设置占位符 glideRequest.placeholder(config.getPlaceholder()); if (config.getErrorPic() != 0)//设置错误的图片 glideRequest.error(config.getErrorPic()); if (config.getFallback() != 0)//设置请求 url 为空图片 glideRequest.fallback(config.getFallback()); if (config.getResizeX() != 0 && config.getResizeY() != 0) { glideRequest.override(config.getResizeX(), config.getResizeY()); } if (config.isCropCenter()) { glideRequest.centerCrop(); } if (config.isCropCircle()) { glideRequest.circleCrop(); } if (config.decodeFormate() != null) { glideRequest.format(config.decodeFormate()); } if (config.isFitCenter()) { glideRequest.fitCenter(); } glideRequest .into(config.getImageView()); }
Example #22
Source File: IntelligentCache.java From MVPArms with Apache License 2.0 | 2 votes |
/** * 使用此方法返回的值作为 key, 可以将数据永久存储至内存中 * * @param key {@code key} * @return Keep= + {@code key} */ @NonNull public static String getKeyOfKeep(@NonNull String key) { Preconditions.checkNotNull(key, "key == null"); return IntelligentCache.KEY_KEEP + key; }
Example #23
Source File: ImageLoader.java From MVPArms with Apache License 2.0 | 2 votes |
/** * 加载图片 * * @param context * @param config * @param <T> */ public <T extends ImageConfig> void loadImage(Context context, T config) { Preconditions.checkNotNull(mStrategy, "Please implement BaseImageLoaderStrategy and call GlobalConfigModule.Builder#imageLoaderStrategy(BaseImageLoaderStrategy) in the applyOptions method of ConfigModule"); //noinspection unchecked this.mStrategy.loadImage(context, config); }
Example #24
Source File: ImageLoader.java From MVPArms with Apache License 2.0 | 2 votes |
/** * 停止加载或清理缓存 * * @param context * @param config * @param <T> */ public <T extends ImageConfig> void clear(Context context, T config) { Preconditions.checkNotNull(mStrategy, "Please implement BaseImageLoaderStrategy and call GlobalConfigModule.Builder#imageLoaderStrategy(BaseImageLoaderStrategy) in the applyOptions method of ConfigModule"); //noinspection unchecked this.mStrategy.clear(context, config); }
Example #25
Source File: ImageLoader.java From MVPArms with Apache License 2.0 | 2 votes |
/** * 可在运行时随意切换 {@link BaseImageLoaderStrategy} * * @param strategy */ public void setLoadImgStrategy(BaseImageLoaderStrategy strategy) { Preconditions.checkNotNull(strategy, "strategy == null"); this.mStrategy = strategy; }