Java Code Examples for com.jess.arms.utils.ArmsUtils

The following examples show how to use com.jess.arms.utils.ArmsUtils. 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   Source File: GlideConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
    final AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(() -> {
        // Careful: the external cache directory doesn't enforce permissions
        return DiskLruCacheWrapper.create(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}
 
Example 2
@Override
public void handleResponseError(Context context, Throwable t) {
    Timber.tag("Catch-Error").w(t.getMessage());
    //这里不光只能打印错误, 还可以根据不同的错误做出不同的逻辑处理
    //这里只是对几个常用错误进行简单的处理, 展示这个类的用法, 在实际开发中请您自行对更多错误进行更严谨的处理
    String msg = "未知错误";
    if (t instanceof UnknownHostException) {
        msg = "网络不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "请求网络超时";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "数据解析错误";
    }
    ArmsUtils.snackbarText(msg);
}
 
Example 3
Source Project: Hands-Chopping   Source File: ResponseErrorListenerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handleResponseError(Context context, Throwable t) {
    Timber.tag("Catch-Error").w(t.getMessage());
    //这里不光只能打印错误, 还可以根据不同的错误做出不同的逻辑处理
    //这里只是对几个常用错误进行简单的处理, 展示这个类的用法, 在实际开发中请您自行对更多错误进行更严谨的处理
    String msg = "未知错误";
    if (t instanceof UnknownHostException) {
        msg = "网络不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "请求网络超时";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "数据解析错误";
    }
    ArmsUtils.snackbarText(msg);
}
 
Example 4
Source Project: Hands-Chopping   Source File: GlobalConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码, 所以不需要再执行
    if (BuildConfig.IS_BUILD_MODULE) {
        lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
            @Override
            public void onFragmentDestroyed(FragmentManager fm, android.support.v4.app.Fragment f) {
                ((RefWatcher) ArmsUtils
                        .obtainAppComponentFromContext(f.getActivity())
                        .extras()
                        .get(RefWatcher.class.getName()))
                        .watch(f);
            }
        });
    }
}
 
Example 5
Source Project: Hands-Chopping   Source File: GlobalConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码, 所以不需要再执行
    if (BuildConfig.IS_BUILD_MODULE) {
        lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
            @Override
            public void onFragmentDestroyed(FragmentManager fm, android.support.v4.app.Fragment f) {
                ((RefWatcher) ArmsUtils
                        .obtainAppComponentFromContext(f.getActivity())
                        .extras()
                        .get(RefWatcher.class.getName()))
                        .watch(f);
            }
        });
    }
}
 
Example 6
Source Project: Hands-Chopping   Source File: GlobalConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码, 所以不需要再执行
    if (BuildConfig.IS_BUILD_MODULE) {
        lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
            @Override
            public void onFragmentDestroyed(FragmentManager fm, android.support.v4.app.Fragment f) {
                ((RefWatcher) ArmsUtils
                        .obtainAppComponentFromContext(f.getActivity())
                        .extras()
                        .get(RefWatcher.class.getName()))
                        .watch(f);
            }
        });
    }
}
 
Example 7
Source Project: Aurora   Source File: FollowButton.java    License: Apache License 2.0 6 votes vote down vote up
private void refreshView() {
    Cache cache = ArmsUtils.obtainAppComponentFromContext(FollowButton.this.getContext()).extras();
    List<MyAttentionEntity> entities = CommonUtils.getFollowedInfo(mContext);
    if (entities != null && BmobUser.getCurrentUser() != null) {
        boolean isFollowed = false;
        for (MyAttentionEntity entity : entities) {
            if (entity.getId() == this.attention.getId()) {
                isFollowed = true;
            }
        }
        if (isFollowed) {
            setState(FOLLOWED);
        } else {
            setState(UNFOLLOWED);
        }
    }
}
 
Example 8
Source Project: LQRBiliBlili   Source File: SummaryFragment.java    License: MIT License 6 votes vote down vote up
private void initOtherInfo(Summary.DataBean data) {
    List<Summary.DataBean.RelatesBean> relates = data.getRelates();
    if (relates != null) {
        mRvRelates.setLayoutManager(new LinearLayoutManager(_mActivity));
        mRvRelates.setAdapter(new BaseQuickAdapter<Summary.DataBean.RelatesBean, BaseViewHolder>(R.layout.item_relate_video_detail, relates) {
            @Override
            protected void convert(BaseViewHolder helper, Summary.DataBean.RelatesBean item) {
                ArmsUtils.obtainAppComponentFromContext(_mActivity).imageLoader().loadImage(_mActivity, ImageConfigImpl.builder().url(item.getPic()).imageView(helper.getView(R.id.iv_pic)).build());
                helper.setText(R.id.tv_title, item.getTitle())
                        .setText(R.id.tv_owner_name, item.getOwner() == null ? "" : item.getOwner().getName())
                        .setText(R.id.tv_view, item.getStat() == null ? "0" : TextHandleUtil.handleCount2TenThousand(item.getStat().getView()))
                        .setText(R.id.tv_danmaku, item.getStat() == null ? "0" : TextHandleUtil.handleCount2TenThousand(item.getStat().getDanmaku()));
            }
        });
    }
}
 
Example 9
Source Project: LQRBiliBlili   Source File: VideoDetailActivity.java    License: MIT License 6 votes vote down vote up
private void showVideoStartTip() {
    mRlVideoTip.setVisibility(View.VISIBLE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Animator circularReveal = ViewAnimationUtils.createCircularReveal(mRlVideoTip,
                mIvCover.getWidth() - ArmsUtils.dip2px(VideoDetailActivity.this, mAnchorX),
                mIvCover.getHeight() - ArmsUtils.dip2px(VideoDetailActivity.this, mAnchorY),
                0,
                ((float) Math.hypot(mIvCover.getWidth(), mIvCover.getHeight())));
        circularReveal.setDuration(800);
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mIvCover.setVisibility(View.GONE);
                mPresenter.loadPlayUrl(aid);
            }
        });
        circularReveal.start();
    } else {
        mPresenter.loadPlayUrl(aid);
    }
    // 锁定AppBarLayout
    AppBarLayout.LayoutParams layoutParams = (AppBarLayout.LayoutParams) mAppbar.getChildAt(0).getLayoutParams();
    layoutParams.setScrollFlags(0);
    mAppbar.getChildAt(0).setLayoutParams(layoutParams);
}
 
Example 10
Source Project: LQRBiliBlili   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void onBackPressedSupport() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
        closeDrawer();
    } else {
        ISupportFragment topFragment = getTopFragment();
        if (!(topFragment instanceof NavHomeFragment)) {
            mNav.setCheckedItem(R.id.nav_home);
        }
        if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
            pop();
        } else {
            // 放置后台
            // moveTaskToBack(false);

            // 2秒内两次点击返回键退出应用
            long nowTime = System.currentTimeMillis();
            if (nowTime - mPreTime > 2000) {
                ArmsUtils.makeText(this, ArmsUtils.getString(this, R.string.double_click_to_exit));
                mPreTime = nowTime;
            } else {
                ArmsUtils.exitApp();
            }
        }
    }
}
 
Example 11
Source Project: MVPArms   Source File: ResponseErrorListenerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handleResponseError(Context context, Throwable t) {
    Timber.tag("Catch-Error").w(t);
    //这里不光只能打印错误, 还可以根据不同的错误做出不同的逻辑处理
    //这里只是对几个常用错误进行简单的处理, 展示这个类的用法, 在实际开发中请您自行对更多错误进行更严谨的处理
    String msg = "未知错误";
    if (t instanceof UnknownHostException) {
        msg = "网络不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "请求网络超时";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "数据解析错误";
    }
    ArmsUtils.snackbarText(msg);
}
 
Example 12
Source Project: lifecycle-component   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    //获取第一次按键时间
    long mNowTime = System.currentTimeMillis();
    //比较两次按键时间差
    if ((mNowTime - mPressedTime) > 2000) {
        ArmsUtils.makeText(getApplicationContext(),
                "再按一次退出" + ArmsUtils.getString(getApplicationContext(), R.string.public_app_name));
        mPressedTime = mNowTime;
    } else {
        super.onBackPressed();
    }
}
 
Example 13
Source Project: lifecycle-component   Source File: AppLifecyclesImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull Application application) {
    if (LeakCanary.isInAnalyzerProcess(application)) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        return;
    }
    //leakCanary内存泄露检查
    ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
}
 
Example 14
Source Project: lifecycle-component   Source File: GlobalConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example 15
@Override
public void onActivityStarted(Activity activity) {
    Timber.i(activity + " - onActivityStarted");
    if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) {
        //由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行
        //而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行
        activity.getIntent().putExtra("isInitToolbar", true);
        //这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里
        if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar") != null) {
            if (activity instanceof AppCompatActivity) {
                ((AppCompatActivity) activity).setSupportActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
                ((AppCompatActivity) activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    activity.setActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
                    activity.getActionBar().setDisplayShowTitleEnabled(false);
                }
            }
        }
        if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title") != null) {
            ((TextView) ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title")).setText(activity.getTitle());
        }
        if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back") != null) {
            ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back").setOnClickListener(v -> {
                activity.onBackPressed();
            });
        }
    }
}
 
Example 16
Source Project: TikTok   Source File: GlobalConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example 17
@Override
public void onActivityStarted(Activity activity) {
    Timber.w(activity + " - onActivityStarted");
    if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) {
        //由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行
        //而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行
        activity.getIntent().putExtra("isInitToolbar", true);
        //这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里
        if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar") != null) {
            if (activity instanceof AppCompatActivity) {
                ((AppCompatActivity) activity).setSupportActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
                ((AppCompatActivity) activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    activity.setActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
                    activity.getActionBar().setDisplayShowTitleEnabled(false);
                }
            }
        }
        if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title") != null) {
            ((TextView) ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title")).setText(activity.getTitle());
        }
        if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back") != null) {
            ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back").setOnClickListener(v -> {
                activity.onBackPressed();
            });
        }
    }
}
 
Example 18
Source Project: MVPArms   Source File: BaseFragment.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public synchronized Cache<String, Object> provideCache() {
    if (mCache == null) {
        //noinspection unchecked
        mCache = ArmsUtils.obtainAppComponentFromContext(getActivity()).cacheFactory().build(CacheType.FRAGMENT_CACHE);
    }
    return mCache;
}
 
Example 19
Source Project: Hands-Chopping   Source File: AppLifecyclesImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Application application) {
    if (LeakCanary.isInAnalyzerProcess(application)) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        return;
    }
    //使用 RetrofitUrlManager 切换 BaseUrl
    //RetrofitUrlManager.getInstance().putDomain(STEAM_DOMAIN_NAME, STEAM_DOMAIN);
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码
    if (BuildConfig.IS_BUILD_MODULE) {
        //leakCanary内存泄露检查
        ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
    }
}
 
Example 20
Source Project: Hands-Chopping   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    //获取第一次按键时间
    long mNowTime = System.currentTimeMillis();
    //比较两次按键时间差
    if ((mNowTime - mPressedTime) > 2000) {
        ArmsUtils.makeText(getApplicationContext(),
                "再按一次退出" + ArmsUtils.getString(getApplicationContext(), R.string.public_app_name));
        mPressedTime = mNowTime;
    } else {
        super.onBackPressed();
    }
}
 
Example 21
Source Project: Hands-Chopping   Source File: AppLifecyclesImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull Application application) {
    if (LeakCanary.isInAnalyzerProcess(application)) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        return;
    }
    //leakCanary内存泄露检查
    ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
}
 
Example 22
Source Project: Hands-Chopping   Source File: GlobalConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example 23
Source Project: Hands-Chopping   Source File: SaleHolder.java    License: Apache License 2.0 5 votes vote down vote up
public SaleHolder(View itemView) {
    super(itemView);
    mAppComponent= ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader=mAppComponent.imageLoader();
    imageView=(ImageView)itemView.findViewById(R.id.img);
    titleTv=(TextView)itemView.findViewById(R.id.name);
    nowpriceTv=(TextView)itemView.findViewById(R.id.nowprice);
    oldpriceTv=(TextView)itemView.findViewById(R.id.oldprice);
    offTv=(TextView)itemView.findViewById(R.id.off);

}
 
Example 24
Source Project: Hands-Chopping   Source File: AppLifecyclesImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Application application) {
    if (LeakCanary.isInAnalyzerProcess(application)) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        return;
    }
    //使用 RetrofitUrlManager 切换 BaseUrl
    //RetrofitUrlManager.getInstance().putDomain(STEAM_DOMAIN_NAME, STEAM_DOMAIN);
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码
    if (BuildConfig.IS_BUILD_MODULE) {
        //leakCanary内存泄露检查
        ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
    }
}
 
Example 25
Source Project: Hands-Chopping   Source File: SearchHolder.java    License: Apache License 2.0 5 votes vote down vote up
public SearchHolder(View itemView) {
    super(itemView);
    mAppComponent= ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
    mImageLoader=mAppComponent.imageLoader();
    imageView=(ImageView)itemView.findViewById(R.id.img);
    titleTv=(TextView)itemView.findViewById(R.id.name);
    nowpriceTv=(TextView)itemView.findViewById(R.id.nowprice);
}
 
Example 26
Source Project: Hands-Chopping   Source File: AppLifecyclesImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Application application) {
    if (LeakCanary.isInAnalyzerProcess(application)) {
        // This process is dedicated to LeakCanary for heap analysis.
        // You should not init your app in this process.
        return;
    }
    //使用 RetrofitUrlManager 切换 BaseUrl
    //RetrofitUrlManager.getInstance().putDomain(STEAM_DOMAIN_NAME, STEAM_DOMAIN);
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码
    if (BuildConfig.IS_BUILD_MODULE) {
        //leakCanary内存泄露检查
        ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
    }
}
 
Example 27
Source Project: Aurora   Source File: BaseLazyLoadFragment.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public synchronized Cache<String, Object> provideCache() {
    if (mCache == null) {
        mCache = ArmsUtils.obtainAppComponentFromContext(getActivity()).cacheFactory().build(CacheType.FRAGMENT_CACHE);
    }
    return mCache;
}
 
Example 28
Source Project: Aurora   Source File: BaseActivity.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public synchronized Cache<String, Object> provideCache() {
    if (mCache == null) {
        mCache = ArmsUtils.obtainAppComponentFromContext(this).cacheFactory().build(CacheType.ACTIVITY_CACHE);
    }
    return mCache;
}
 
Example 29
Source Project: Aurora   Source File: BaseFragment.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public synchronized Cache<String, Object> provideCache() {
    if (mCache == null) {
        mCache = ArmsUtils.obtainAppComponentFromContext(getActivity()).cacheFactory().build(CacheType.FRAGMENT_CACHE);
    }
    return mCache;
}
 
Example 30
Source Project: Aurora   Source File: GlideConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}