com.jess.arms.utils.ArmsUtils Java Examples

The following examples show how to use com.jess.arms.utils.ArmsUtils. 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: GlobalConfiguration.java    From Hands-Chopping with 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 #2
Source File: ResponseErrorListenerImpl.java    From MVPArms with 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 #3
Source File: MainActivity.java    From LQRBiliBlili with 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 #4
Source File: VideoDetailActivity.java    From LQRBiliBlili with 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 #5
Source File: GlideConfiguration.java    From MVPArms with 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 #6
Source File: SummaryFragment.java    From LQRBiliBlili with 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 #7
Source File: FollowButton.java    From Aurora with 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 File: ResponseErrorListenerImpl.java    From lifecycle-component with 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 #9
Source File: GlobalConfiguration.java    From Hands-Chopping with 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 #10
Source File: GlobalConfiguration.java    From Hands-Chopping with 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 #11
Source File: ResponseErrorListenerImpl.java    From Hands-Chopping with 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 #12
Source File: BaseFragment.java    From Aurora with 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 #13
Source File: VideoDetailActivity.java    From LQRBiliBlili with MIT License 5 votes vote down vote up
private void initFab() {
    mFab.setOnClickListener(view -> {
        ObjectAnimator translationY = ObjectAnimator.ofFloat(mFab, "translationY", -ArmsUtils.dip2px(this, mAnchorY));
        translationY.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mFab.setVisibility(View.GONE);
                showVideoStartTip();
            }
        });
        translationY.start();
    });
}
 
Example #14
Source File: GlideConfiguration.java    From Aurora with 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);
    }
}
 
Example #15
Source File: MainHomeFragmentAdapter.java    From LQRBiliBlili with MIT License 5 votes vote down vote up
public MainHomeFragmentAdapter(FragmentManager fm, Context context) {
    super(fm);
    mContext = context;
    mTabTitles = ArmsUtils.getStringArray(mContext, R.array.tab_titles_main_home);
    mFragments.add(LiveFragment.newInstance());
    mFragments.add(RecommendFragment.newInstance());
    mFragments.add(TrackCartoonFragment.newInstance());
    mFragments.add(ColumnFragment.newInstance());
}
 
Example #16
Source File: MyTagAdapter.java    From LQRBiliBlili with MIT License 5 votes vote down vote up
@Override
public View getView(FlowLayout parent, int position, Summary.DataBean.TagBean tagBean) {
    TextView tv = new TextView(parent.getContext());
    int paddingTopAndBottom = 10;
    int paddingLeftAndRight = 25;
    tv.setPadding(paddingLeftAndRight, paddingTopAndBottom, paddingLeftAndRight, paddingTopAndBottom);
    tv.setText(tagBean.getTag_name());
    tv.setTextSize(12);
    tv.setTextColor(ArmsUtils.getColor(parent.getContext(), R.color.text_title));
    tv.setBackgroundResource(R.drawable.shape_tv_tag_video_detail);
    AutoUtils.auto(tv);
    return tv;
}
 
Example #17
Source File: RecommendMultiItemAdapter.java    From LQRBiliBlili with MIT License 5 votes vote down vote up
private void setItemPaddingAndImage(BaseViewHolder helper, RecommendMultiItem item, IndexData.DataBean itemBean) {
    int leftPadding = item.isOdd() ? ArmsUtils.dip2px(mContext, ConstantUtil.MAIN_HOME_ITEM_PADDING) : 0;
    int rightPadding = item.isOdd() ? 0 : ArmsUtils.dip2px(mContext, ConstantUtil.MAIN_HOME_ITEM_PADDING);
    helper.getView(R.id.fl_item).setPadding(leftPadding, 0, rightPadding, 0);
    mAppComponent.imageLoader().loadImage(mContext, ImageConfigImpl.builder()
            .imageView(helper.getView(R.id.iv_cover))
            .url(itemBean.getCover())
            .build());
}
 
Example #18
Source File: VideoDetailFragmentAdapter.java    From LQRBiliBlili with MIT License 5 votes vote down vote up
public VideoDetailFragmentAdapter(FragmentManager fm, Context context, VideoDetail videoDetail) {
    super(fm);
    mContext = context;
    String summaryStr = ArmsUtils.getString(mContext, R.string.v_detail_summary);
    String replyCountStr = mContext.getResources().getString(R.string.v_detail_evaluate, videoDetail.getSummary().getData().getStat() == null ? 0 : videoDetail.getSummary().getData().getStat().getReply());
    mTabTitles = new String[]{summaryStr, replyCountStr};
    mFragments.add(SummaryFragment.newInstance(videoDetail.getSummary()));
    mFragments.add(ReplyFragment.newInstance(videoDetail.getReply(), replyCountStr));
}
 
Example #19
Source File: AppLifecyclesImpl.java    From Hands-Chopping with 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 File: BaseLazyLoadFragment.java    From Aurora with 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 #21
Source File: GlobalHttpHandlerImpl.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
/**
 * 这里可以先客户端一步拿到每一次 Http 请求的结果, 可以先解析成 Json, 再做一些操作, 如检测到 token 过期后
 * 重新请求 token, 并重新执行请求
 *
 * @param httpResult 服务器返回的结果 (已被框架自动转换为字符串)
 * @param chain      {@link okhttp3.Interceptor.Chain}
 * @param response   {@link Response}
 * @return {@link Response}
 */
@NonNull
@Override
public Response onHttpResultResponse(@Nullable String httpResult, @NonNull Interceptor.Chain chain, @NonNull Response response) {
    if (!TextUtils.isEmpty(httpResult) && RequestInterceptor.isJson(response.body().contentType())) {
        try {
            List<User> list = ArmsUtils.obtainAppComponentFromContext(context).gson().fromJson(httpResult, new TypeToken<List<User>>() {
            }.getType());
            User user = list.get(0);
            Timber.w("Result ------> " + user.getLogin() + "    ||   Avatar_url------> " + user.getAvatarUrl());
        } catch (Exception e) {
            e.printStackTrace();
            return response;
        }
    }

    /* 这里如果发现 token 过期, 可以先请求最新的 token, 然后在拿新的 token 放入 Request 里去重新请求
    注意在这个回调之前已经调用过 proceed(), 所以这里必须自己去建立网络请求, 如使用 Okhttp 使用新的 Request 去请求
    create a new request and modify it accordingly using the new token
    Request newRequest = chain.request().newBuilder().header("token", newToken)
                         .build();

    retry the request

    response.body().close();
    如果使用 Okhttp 将新的请求, 请求成功后, 再将 Okhttp 返回的 Response return 出去即可
    如果不需要返回新的结果, 则直接把参数 response 返回出去即可*/
    return response;
}
 
Example #22
Source File: SearchHolder.java    From Hands-Chopping with 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 #23
Source File: BaseActivity.java    From MVPArms with 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(this).cacheFactory().build(CacheType.ACTIVITY_CACHE);
    }
    return mCache;
}
 
Example #24
Source File: FragmentDelegateImpl.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    if (iFragment.useEventBus())//如果要使用eventbus请将此方法返回true
    {
        EventBusManager.getInstance().register(mFragment);//注册到事件主线
    }
    iFragment.setupFragmentComponent(ArmsUtils.obtainAppComponentFromContext(mFragment.getActivity()));
}
 
Example #25
Source File: AppLifecyclesImpl.java    From Hands-Chopping with 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 #26
Source File: SaleHolder.java    From Hands-Chopping with 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 #27
Source File: GlobalConfiguration.java    From Hands-Chopping with 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 #28
Source File: AppLifecyclesImpl.java    From Hands-Chopping with 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 #29
Source File: GlideConfiguration.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
    //Glide 默认使用 HttpURLConnection 做网络请求,在这切换成 Okhttp 请求
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.okHttpClient()));

    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).registerComponents(context, glide, registry);
    }
}
 
Example #30
Source File: BaseActivity.java    From Aurora with 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;
}