Java Code Examples for com.jess.arms.utils.Preconditions#checkNotNull()

The following examples show how to use com.jess.arms.utils.Preconditions#checkNotNull() . These examples are extracted from open source projects. 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 Project: MVPArms   File: RepositoryManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据传入的 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 Project: Aurora   File: BaseApplication.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将 {@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 3
Source Project: Aurora   File: AppDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将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 4
Source Project: Aurora   File: RepositoryManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 根据传入的 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 5
@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 6
Source Project: Aurora   File: BasePresenter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 如果当前页面同时需要 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 7
Source Project: MVPArms   File: BaseApplication.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将 {@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 8
Source Project: MVPArms   File: AppDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将 {@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 9
@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 10
@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 11
Source Project: Aurora   File: FragmentLifecycle.java    License: Apache License 2.0 4 votes vote down vote up
@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 12
Source Project: Aurora   File: BasePresenter.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 如果当前页面不需要操作数据,只需要 View 层,则使用此构造函数
 *
 * @param rootView
 */
public BasePresenter(V rootView) {
    Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName());
    this.mRootView = rootView;
    onStart();
}
 
Example 13
Source Project: MVPArms   File: FragmentLifecycle.java    License: Apache License 2.0 4 votes vote down vote up
@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 14
Source Project: MVPArms   File: ActivityLifecycle.java    License: Apache License 2.0 4 votes vote down vote up
@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 15
Source Project: MVPArms   File: GlobalConfigModule.java    License: Apache License 2.0 4 votes vote down vote up
public Builder baseurl(BaseUrl baseUrl) {
    this.baseUrl = Preconditions.checkNotNull(baseUrl, BaseUrl.class.getCanonicalName() + "can not be null.");
    return this;
}
 
Example 16
@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 17
Source Project: MVPArms   File: BasePresenter.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 如果当前页面不需要操作数据,只需要 View 层,则使用此构造函数
 *
 * @param rootView
 */
public BasePresenter(V rootView) {
    Preconditions.checkNotNull(rootView, "%s cannot be null", IView.class.getName());
    this.mRootView = rootView;
    onStart();
}
 
Example 18
Source Project: MVPArms   File: ImageLoader.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 可在运行时随意切换 {@link BaseImageLoaderStrategy}
 *
 * @param strategy
 */
public void setLoadImgStrategy(BaseImageLoaderStrategy strategy) {
    Preconditions.checkNotNull(strategy, "strategy == null");
    this.mStrategy = strategy;
}
 
Example 19
Source Project: MVPArms   File: ImageLoader.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 停止加载或清理缓存
 *
 * @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 20
Source Project: MVPArms   File: ImageLoader.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 加载图片
 *
 * @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);
}