com.blankj.utilcode.util.ConvertUtils Java Examples

The following examples show how to use com.blankj.utilcode.util.ConvertUtils. 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: AnimeListActivity.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
@Override
public void initView() {

    recyclerView.addItemDecoration(new ItemDecorationSpaces(ConvertUtils.dp2px(5)));
    recyclerView.setLayoutManager(new GridLayoutManager(this, 3));

    int openType = getIntent().getIntExtra("open_type", ANIME_TAG);
    switch (openType){
        case PERSONAL_FAVORITE:
            setTitle("我的关注");
            presenter.getFavorite();
            break;
        case PERSONAL_HISTORY:
            setTitle("云端播放历史");
            presenter.getPlayHistory();
            break;
        case ANIME_TAG:
            String tagName = getIntent().getStringExtra("tag_name");
            int tagId = getIntent().getIntExtra("tag_id", 0);
            setTitle(tagName);
            presenter.getByTag(tagId);
            break;
    }
}
 
Example #2
Source File: LongShowPopupActivity.java    From AndroidSamples with Apache License 2.0 6 votes vote down vote up
@Override
public void onLongPress(MotionEvent e) {
    Log.e(TAG, "onShowPress: " + "长按");
    // 获取点击位置相对于屏幕的坐标
    int x = (int) e.getRawX();
    int y = (int) e.getRawY();
    x -= ConvertUtils.dp2px(55);
    if (mPopWindow != null) {
        if (mPopWindow.isShowing()) {
            mPopWindow.dismiss();
            showPopupWindow(x, y);
        } else {
            showPopupWindow(x, y);
        }
    } else {
        showPopupWindow(x, y);
    }

}
 
Example #3
Source File: IjkPlayerView.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
/**
 * 顶栏和底栏以及截图键显示与隐藏
 */
private void hideShowBar(boolean isShow) {
    if (isShow) {
        AnimHelper.viewTranslationY(bottomBarView, 0);
        bottomBarView.setVisibility(View.VISIBLE);
        topBarView.setTopBarVisibility(true);
        mIsShowBar = true;
    } else {
        AnimHelper.viewTranslationY(bottomBarView, bottomBarView.getHeight());
        topBarView.setTopBarVisibility(false);
        mIsShowBar = false;
        if (mOutsideListener != null)
            mOutsideListener.onAction(Constants.INTENT_RESET_FULL_SCREEN, 0);
    }
    //截图键与控制栏的显示与隐藏是绑定的
    if (isShow) {
        AnimHelper.viewTranslationX(mIvScreenShot, 0, 300);
    } else {
        AnimHelper.viewTranslationX(mIvScreenShot, ConvertUtils.dp2px(60), 300);
    }
}
 
Example #4
Source File: AnimeRecommendItem.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
@Override
public void onUpdateViews(AnimeBean model, int position) {
    RequestOptions options = new RequestOptions()
            .centerCrop()
            .transform(new CornersCenterCrop(ConvertUtils.dp2px(5)));

    Glide.with(imageIv.getContext())
            .load(model.getImageUrl())
            .apply(options)
            .transition((DrawableTransitionOptions.withCrossFade()))
            .into(imageIv);

    titleTv.setText(model.getAnimeTitle());

    typeTv.setText(model.isIsOnAir() ? "连载中" : "已完结");

    ratingTv.setText(model.getRating()+"");

    mView.setOnClickListener(v ->
            AnimeDetailActivity.launchAnimeDetail(
                    (Activity)mView.getContext(),
                    model.getAnimeId()+"")
    );
}
 
Example #5
Source File: ExoPlayerView.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
/**
 * 顶栏和底栏以及截图键显示与隐藏
 */
private void hideShowBar(boolean isShow) {
    if (isShow) {
        AnimHelper.viewTranslationY(bottomBarView, 0);
        bottomBarView.setVisibility(View.VISIBLE);
        topBarView.setTopBarVisibility(true);
        mIsShowBar = true;
    } else {
        AnimHelper.viewTranslationY(bottomBarView, bottomBarView.getHeight());
        topBarView.setTopBarVisibility(false);
        mIsShowBar = false;
        if (mOutsideListener != null)
            mOutsideListener.onAction(Constants.INTENT_RESET_FULL_SCREEN, 0);
    }
    //截图键与控制栏的显示与隐藏是绑定的
    if (isShow) {
        AnimHelper.viewTranslationX(mIvScreenShot, 0, 300);
    } else {
        AnimHelper.viewTranslationX(mIvScreenShot, ConvertUtils.dp2px(60), 300);
    }
}
 
Example #6
Source File: WebImageSpan.java    From V2EX with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Drawable getDrawable() {
    if (isShow){
        return super.getDrawable();
    }
    Glide.with(mTextView.getContext()).load(mUri).into(new SimpleTarget<Drawable>() {
        @Override
        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {

            Resources resources = mTextView.getContext().getResources();
            int targetWidth = (int) (resources.getDisplayMetrics().widthPixels * 0.8);
            Bitmap zoom = zoom(ConvertUtils.drawable2Bitmap(resource), targetWidth);
            BitmapDrawable b = new BitmapDrawable(resources, zoom);
            b.setBounds(0, 0, b.getIntrinsicWidth(), b.getIntrinsicHeight());
            Field mDrawable;
            Field mDrawableRef;
            try { mDrawable = ImageSpan.class.getDeclaredField("mDrawable");
                mDrawable.setAccessible(true);
                mDrawable.set(WebImageSpan.this, b);
                mDrawableRef = DynamicDrawableSpan.class.getDeclaredField("mDrawableRef");
                mDrawableRef.setAccessible(true); mDrawableRef.set(WebImageSpan.this, null);
                isShow = true;
                mTextView.setText(mTextView.getText());
            } catch (IllegalAccessException | NoSuchFieldException e) {
                e.printStackTrace();
            }

        }

    });
    return null;
}
 
Example #7
Source File: WebViewActivity.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private void initView() {
    //初始化进度条
    progressView = new ProgressView(this);
    progressView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ConvertUtils.dp2px(4)));
    progressView.setColor(Color.BLUE);
    progressView.setProgress(10);
    //把进度条加到WebView中
    mWebView.addView(progressView);
}
 
Example #8
Source File: IjkPlayerView.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * 锁屏键的显示与隐藏
 */
private void hideShowLockScreen(boolean isShow) {
    if (isShow) {
        AnimHelper.viewTranslationX(mIvPlayerLock, 0, 300);
    } else {
        AnimHelper.viewTranslationX(mIvPlayerLock, -ConvertUtils.dp2px(60), 300);
    }
}
 
Example #9
Source File: DialogScreenShot.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void show() {
    super.show();

    if (getWindow() == null)
        return;

    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.gravity = Gravity.CENTER;
    layoutParams.width = ConvertUtils.dp2px(450);
    layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;

    getWindow().getDecorView().setPadding(0, 0, 0, 0);
    getWindow().setAttributes(layoutParams);
}
 
Example #10
Source File: ExoPlayerView.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * 锁屏键的显示与隐藏
 */
private void hideShowLockScreen(boolean isShow) {
    if (isShow) {
        AnimHelper.viewTranslationX(mIvPlayerLock, 0, 300);
    } else {
        AnimHelper.viewTranslationX(mIvPlayerLock, -ConvertUtils.dp2px(60), 300);
    }
}
 
Example #11
Source File: VLayoutFragment.java    From AndroidSamples with Apache License 2.0 5 votes vote down vote up
private void initBanner() {
    adapters.add(new SubAdapter(mContext, new LinearLayoutHelper(), 1,
            new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ConvertUtils.dp2px(200))) {
        @Override
        public int getItemViewType(int position) {
            return 1;
        }
    });
}
 
Example #12
Source File: GlideUtil.java    From Android-IM with Apache License 2.0 5 votes vote down vote up
/**
 * 加载圆角封面,默认4dp
 */
public static void loadCornerPicture(Context context, String imgUrl, ImageView imageView) {
    Glide.with(context)
            .load(imgUrl)
            .apply(new RequestOptions().error(R.drawable.icon_user))
            .apply(RequestOptions.bitmapTransform(new MultiTransformation<Bitmap>(new CenterCrop(),
                    new RoundedCornersTransformation(ConvertUtils.dp2px(4), 0))))
            .into(imageView);
}
 
Example #13
Source File: GlideUtil.java    From Android-IM with Apache License 2.0 5 votes vote down vote up
public static void loadCornerPicture(Context context, String imgUrl, ImageView imageView, int resourceId) {
    Glide.with(context)
            .load(imgUrl)
            .apply(new RequestOptions().error(resourceId))
            .apply(RequestOptions.bitmapTransform(new MultiTransformation<Bitmap>(new CenterCrop(),
                    new RoundedCornersTransformation(ConvertUtils.dp2px(4), 0))))
            .into(imageView);
}
 
Example #14
Source File: GlideUtil.java    From Android-IM with Apache License 2.0 5 votes vote down vote up
public static void loadCornerPicture(Context context, String imgUrl, int cornerRadius, int errorResourceId, ImageView imageView) {
    Glide.with(context)
            .load(imgUrl)
            .apply(new RequestOptions().error(errorResourceId))
            .apply(RequestOptions.bitmapTransform(new MultiTransformation<Bitmap>(new CenterCrop(),
                    new RoundedCornersTransformation(ConvertUtils.dp2px(cornerRadius), 0))))
            .into(imageView);
}
 
Example #15
Source File: GlideUtil.java    From Android-IM with Apache License 2.0 5 votes vote down vote up
/**
 * 加载自定义封面带圆角
 *
 * @param context      上下文
 * @param imgUrl       图片链接
 * @param cornerRadius 圆角弧度
 * @param imageView    view
 */
public static void loadCornerPicture(Context context, String imgUrl, int cornerRadius, ImageView imageView) {
    Glide.with(context)
            .load(imgUrl)
            .apply(new RequestOptions().error(R.drawable.icon_user))
            .apply(RequestOptions.bitmapTransform(new MultiTransformation<Bitmap>(new CenterCrop(),
                    new RoundedCornersTransformation(ConvertUtils.dp2px(cornerRadius), 0))))
            .into(imageView);
}
 
Example #16
Source File: ClearCacheDebug.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
private ThreadUtils.SimpleTask<Long> createClearCacheTask() {
    return new ThreadUtils.SimpleTask<Long>() {
        @Override
        public Long doInBackground() throws Throwable {
            try {
                long len = 0;
                File appDataDir = new File(PathUtils.getInternalAppDataPath());
                if (appDataDir.exists()) {
                    String[] names = appDataDir.list();
                    for (String name : names) {
                        if (!name.equals("lib")) {
                            File file = new File(appDataDir, name);
                            len += FileUtils.getLength(file);
                            FileUtils.delete(file);
                            LogUtils.i("「" + file + "」 was deleted.");
                        }
                    }
                }
                String externalAppCachePath = PathUtils.getExternalAppCachePath();
                len += FileUtils.getLength(externalAppCachePath);
                FileUtils.delete(externalAppCachePath);
                LogUtils.i("「" + externalAppCachePath + "」 was deleted.");
                return len;
            } catch (Exception e) {
                ToastUtils.showLong(e.toString());
                return -1L;
            }
        }

        @Override
        public void onSuccess(Long result) {
            if (result != -1) {
                ToastUtils.showLong("Clear Cache: " + ConvertUtils.byte2FitMemorySize(result));
            }
        }
    };
}
 
Example #17
Source File: BottomZoomActivity.java    From AndroidSamples with Apache License 2.0 5 votes vote down vote up
private void setButtonSize(int x, int y) {

        ViewWrapper viewWrapper = new ViewWrapper(animator1Btn);

        // 动画集合,同时执行下面的动画效果
        AnimatorSet set = new AnimatorSet();
        set.playTogether(
                ObjectAnimator.ofInt(viewWrapper, "width",
                        ConvertUtils.dp2px(x)),
                ObjectAnimator.ofInt(viewWrapper, "height",
                        ConvertUtils.dp2px(y))
        );

        set.setDuration(5000).start();
    }
 
Example #18
Source File: RpcMockInterceptor.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 将request body 转化成json字符串
 *
 * @return
 */
private String transformRequestBody(HttpEntity requestBody) {
    //form :"application/x-www-form-urlencoded"
    //json :"application/json;"
    String json = "";
    if (requestBody == null || requestBody.getContentType() == null) {
        return json;
    }

    try {
        String strBody = ConvertUtils.inputStream2String(requestBody.getContent(), "utf-8");
        if (TextUtils.isEmpty(strBody)) {
            return "";
        }

        if (requestBody.getContentType().toString().toLowerCase().contains(MEDIA_TYPE_FORM)) {
            String form = ConvertUtils.inputStream2String(requestBody.getContent(), "utf-8");
            //类似 ccc=ccc&ddd=ddd
            json = DokitUtil.param2Json(form);
        } else if (requestBody.getContentType().toString().toLowerCase().contains(MEDIA_TYPE_JSON)) {
            //类似 {"ccc":"ccc","ddd":"ddd"}
            json = ConvertUtils.inputStream2String(requestBody.getContent(), "utf-8");
        } else {
            json = NOT_STRING_CONTENT_FLAG;
        }
        //测试是否是json字符串
        new JSONObject(json);
    } catch (Exception e) {
        //e.printStackTrace();
        json = NOT_STRING_CONTENT_FLAG;
        LogHelper.e(TAG, "===body json====>" + json);
    }

    return json;
}
 
Example #19
Source File: DokitFrescoPostprocessor.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
    try {
        if (PerformanceSpInfoConfig.isLargeImgOpen()) {
            double imgSize = ConvertUtils.byte2MemorySize(sourceBitmap.getByteCount(), MemoryConstants.MB);
            LargePictureManager.getInstance().saveImageInfo(mUri.toString(), imgSize, sourceBitmap.getWidth(), sourceBitmap.getHeight(), "Fresco");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (mOriginalPostprocessor != null) {
        return mOriginalPostprocessor.process(sourceBitmap, bitmapFactory);
    }

    final Bitmap.Config sourceBitmapConfig = sourceBitmap.getConfig();
    CloseableReference<Bitmap> destBitmapRef =
            bitmapFactory.createBitmapInternal(
                    sourceBitmap.getWidth(),
                    sourceBitmap.getHeight(),
                    sourceBitmapConfig != null ? sourceBitmapConfig : FALLBACK_BITMAP_CONFIGURATION);
    try {
        process(destBitmapRef.get(), sourceBitmap);
        return CloseableReference.cloneOrNull(destBitmapRef);
    } finally {
        CloseableReference.closeSafely(destBitmapRef);
    }

}
 
Example #20
Source File: MockResponseHandler.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * response读取完成
 *
 * @param outputStream
 */
@Override
public void onEOF(ByteArrayOutputStream outputStream) {
    if (host.equals(NetworkManager.MOCK_HOST)) {
        mockApi.setResponseFrom(MockTemplateApiBean.RESPONSE_FROM_MOCK);
    } else {
        mockApi.setResponseFrom(MockTemplateApiBean.RESPONSE_FROM_REAL);
    }
    String strResponseBody = ConvertUtils.outputStream2String(outputStream, "utf-8");
    mockApi.setStrResponse(strResponseBody);
    //更新本地数据库
    DokitDbManager.getInstance().updateTemplateApi(mockApi);
    //LogHelper.i(TAG, "result===>" + ConvertUtils.outputStream2String(outputStream, "utf-8"));
}
 
Example #21
Source File: AlignRulerLineDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public void onPositionChanged(int x, int y) {
    /**
     * 限制边界
     */
    if (!isNormalMode()) {
        int iconSize = ConvertUtils.dp2px(30);
        if (y <= iconSize) {
            y = iconSize;
        }

        if (ScreenUtils.isPortrait()) {
            if (y >= getScreenLongSideLength() - iconSize) {
                y = getScreenLongSideLength() - iconSize;
            }
        } else {
            if (y >= getScreenShortSideLength() - iconSize) {
                y = getScreenShortSideLength() - iconSize;
            }
        }


        if (x <= iconSize) {
            x = iconSize;
        }
        if (ScreenUtils.isPortrait()) {
            if (x >= getScreenShortSideLength() - iconSize) {
                x = getScreenShortSideLength() - iconSize;
            }
        } else {
            if (x >= getScreenLongSideLength() - iconSize) {
                x = getScreenLongSideLength() - iconSize;
            }
        }
    }


    mAlignInfoView.showInfo(x, y);
}
 
Example #22
Source File: CountDownDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public void initDokitViewLayoutParams(DokitViewLayoutParams params) {
    params.height = DokitViewLayoutParams.WRAP_CONTENT;
    params.width = DokitViewLayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = ConvertUtils.dp2px(280);
    params.y = ConvertUtils.dp2px(25);
}
 
Example #23
Source File: DokitGlideTransform.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Resource<Bitmap> transform(@NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) {
    try {
        if (mWrap != null) {
            resource = mWrap.transform(context, resource, outWidth, outHeight);
        }

        if (PerformanceSpInfoConfig.isLargeImgOpen()) {
            String url = "";
            if (mRequestBuilder instanceof RequestBuilder) {
                if (ReflectUtils.reflect(mRequestBuilder).field("model").get() instanceof String) {
                    url = ReflectUtils.reflect(mRequestBuilder).field("model").get();
                } else if (ReflectUtils.reflect(mRequestBuilder).field("model").get() instanceof Integer) {
                    url = "" + ReflectUtils.reflect(mRequestBuilder).field("model").get();
                }
            }
            Bitmap bitmap = resource.get();
            double imgSize = ConvertUtils.byte2MemorySize(bitmap.getByteCount(), MemoryConstants.MB);
            LargePictureManager.getInstance().saveImageInfo(url, imgSize, bitmap.getWidth(), bitmap.getHeight(), "Glide");
        }
    } catch (Exception e) {
        if (mWrap != null) {
            resource = mWrap.transform(context, resource, outWidth, outHeight);
        }
    }

    return resource;
}
 
Example #24
Source File: DokitImageLoadingListener.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
    try {
        if (PerformanceSpInfoConfig.isLargeImgOpen()) {
            double imgSize = ConvertUtils.byte2MemorySize(loadedImage.getByteCount(), MemoryConstants.MB);
            LargePictureManager.getInstance().saveImageInfo(imageUri, imgSize, loadedImage.getWidth(), loadedImage.getHeight(), "ImageLoader");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (mOriginalImageLoadingListener != null) {
        mOriginalImageLoadingListener.onLoadingComplete(imageUri, view, loadedImage);
    }
}
 
Example #25
Source File: JMWebViewClient.java    From QPM with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {

    try {
        if (!TextUtils.isEmpty(url) && url.contains(JM_LOCAL_COLLECTOR_JS_PATH)) {
            InputStream inputStream = ConvertUtils.string2InputStream(ResourceUtils.readAssets2String("collector.js"), "utf-8");
            return new WebResourceResponse("application/javascript", "UTF-8", inputStream);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return super.shouldInterceptRequest(view, url);
}
 
Example #26
Source File: AnimeMoreItem.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void onUpdateViews(AnimeBean model, int position) {
    RequestOptions options = new RequestOptions()
            .centerCrop()
            .transform(new CornersCenterCrop(ConvertUtils.dp2px(5)));

    Glide.with(imageIv.getContext())
            .load(model.getImageUrl())
            .apply(options)
            .transition((DrawableTransitionOptions.withCrossFade()))
            .into(imageIv);

    titleTv.setText(model.getAnimeTitle());

    followTv.setVisibility(model.isIsFavorited() ? View.VISIBLE : View.GONE);

    airTv.setText(model.isIsOnAir() ? "连载中" : "已完结");

    typeTv.setVisibility(View.GONE);

    restrictedTv.setVisibility(model.isIsRestricted() ? View.VISIBLE : View.GONE);

    ratingTv.setText(model.getRating() + "分");

    mView.setOnClickListener(v ->
            AnimeDetailActivity.launchAnimeDetail(
            (Activity)mView.getContext(),
            model.getAnimeId()+"")
    );
}
 
Example #27
Source File: AnimeItem.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void onUpdateViews(AnimeBean model, int position) {

    if (AppConfig.getInstance().isLogin()) {
        followTagView.setVisibility(model.isIsFavorited()
                ? View.VISIBLE
                : View.GONE);
    }

    animeTitle.setText(model.getAnimeTitle());

    RequestOptions options = new RequestOptions()
            .centerCrop()
            .transform(new CornersCenterCrop(ConvertUtils.dp2px(3)));

    Glide.with(imageView.getContext())
            .load(model.getImageUrl())
            .apply(options)
            .transition((DrawableTransitionOptions.withCrossFade()))
            .into(imageView);

    mView.setOnClickListener(v ->
            AnimeDetailActivity.launchAnimeDetail(
                    (Activity) mView.getContext(),
                    model.getAnimeId() + "")
    );
}
 
Example #28
Source File: AnimeFragment.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void initView() {
    BangumiBean bangumiBean;
    Bundle args = getArguments();
    if (args == null) return;
    bangumiBean = (BangumiBean)getArguments().getSerializable("anime_data");
    if (bangumiBean ==null) return;

    List<AnimeBean> bangumiList = bangumiBean.getBangumiList();

    if (AppConfig.getInstance().isLogin()){
        Collections.sort(bangumiList, (o1, o2) -> {
            // 返回值为int类型,大于0表示正序,小于0表示逆序
            if (o1.isIsFavorited()) return -1;
            if (o2.isIsFavorited()) return 1;
            return 0;
        });
    }
    BaseRvAdapter<AnimeBean> adapter = new BaseRvAdapter<AnimeBean>(bangumiList) {
        @NonNull
        @Override
        public AdapterItem<AnimeBean> onCreateItem(int viewType) {
            return new AnimeItem();
        }
    };

    animeRv.setLayoutManager(new GridLayoutManager(getContext(), 3){});
    animeRv.addItemDecoration(new ItemDecorationSpaces(ConvertUtils.dp2px(5)));
    animeRv.setAdapter(adapter);
}
 
Example #29
Source File: CourtesyCardView.java    From AndroidSamples with Apache License 2.0 4 votes vote down vote up
private void init(Context context) {
    mContext = context;
    mPaint.setColor(mColor);
    gap = ConvertUtils.dp2px(10);
}
 
Example #30
Source File: LocalPlayHistoryActivity.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@Override
public void initPageView() {
    setTitle("本地播放历史");

    historyList = new ArrayList<>();

    adapter = new BaseRvAdapter<LocalPlayHistoryBean>(historyList) {
        @NonNull
        @Override
        public AdapterItem<LocalPlayHistoryBean> onCreateItem(int viewType) {
            return new LocalPlayHistoryItem(new LocalPlayHistoryItem.OnLocalHistoryItemClickListener() {
                @Override
                public boolean onLongClick(int position) {
                    //长按切换到选中删除模式
                    for (LocalPlayHistoryBean historyBean : historyList) {
                        historyBean.setDeleteMode(true);
                    }
                    setTitle("删除本地播放历史");
                    menuDeleteCheckedItem.setVisible(true);
                    menuDeleteCancelItem.setVisible(true);
                    menuDeleteAllItem.setVisible(false);
                    historyList.get(position).setChecked(true);
                    adapter.notifyDataSetChanged();
                    return true;
                }

                @Override
                public void onCheckedChanged(int position) {
                    boolean isChecked = historyList.get(position).isChecked();
                    historyList.get(position).setChecked(!isChecked);
                    adapter.notifyItemChanged(position);
                }
            });
        }
    };

    recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    recyclerView.addItemDecoration(
            new ItemDecorationDivider(
                    ConvertUtils.dp2px(1),
                    CommonUtils.getResColor(R.color.layout_bg_color),
                    1)
    );
    recyclerView.setAdapter(adapter);

    queryHistory();
}