Java Code Examples for com.blankj.utilcode.util.ConvertUtils

The following examples show how to use com.blankj.utilcode.util.ConvertUtils. 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: DanDanPlayForAndroid   Source File: AnimeRecommendItem.java    License: 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 2
Source Project: DanDanPlayForAndroid   Source File: AnimeListActivity.java    License: 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 3
Source Project: DanDanPlayForAndroid   Source File: IjkPlayerView.java    License: 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 Project: DanDanPlayForAndroid   Source File: ExoPlayerView.java    License: 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 5
Source Project: AndroidSamples   Source File: LongShowPopupActivity.java    License: 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 6
Source Project: DoraemonKit   Source File: RpcMockInterceptor.java    License: 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 7
Source Project: DoraemonKit   Source File: MockResponseHandler.java    License: 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 8
Source Project: DoraemonKit   Source File: AlignRulerLineDokitView.java    License: 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 9
Source Project: DoraemonKit   Source File: CountDownDokitView.java    License: 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 10
Source Project: DoraemonKit   Source File: DokitGlideTransform.java    License: 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 11
Source Project: DoraemonKit   Source File: DokitFrescoPostprocessor.java    License: 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 12
Source Project: DoraemonKit   Source File: DokitImageLoadingListener.java    License: 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 13
Source Project: QPM   Source File: JMWebViewClient.java    License: 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 14
Source Project: DanDanPlayForAndroid   Source File: AnimeFragment.java    License: 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 15
Source Project: DanDanPlayForAndroid   Source File: AnimeMoreItem.java    License: 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 16
Source Project: DanDanPlayForAndroid   Source File: AnimeItem.java    License: 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 17
Source Project: DanDanPlayForAndroid   Source File: WebViewActivity.java    License: 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 18
Source Project: DanDanPlayForAndroid   Source File: IjkPlayerView.java    License: 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 19
Source Project: DanDanPlayForAndroid   Source File: DialogScreenShot.java    License: 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 20
Source Project: DanDanPlayForAndroid   Source File: ExoPlayerView.java    License: 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 21
Source Project: V2EX   Source File: WebImageSpan.java    License: 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 22
Source Project: Android-IM   Source File: GlideUtil.java    License: 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 23
Source Project: Android-IM   Source File: GlideUtil.java    License: 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 24
Source Project: Android-IM   Source File: GlideUtil.java    License: 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 25
Source Project: Android-IM   Source File: GlideUtil.java    License: 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 26
Source Project: AndroidUtilCode   Source File: ClearCacheDebug.java    License: 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 27
Source Project: AndroidSamples   Source File: BottomZoomActivity.java    License: 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 28
Source Project: AndroidSamples   Source File: VLayoutFragment.java    License: 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 29
Source Project: DoraemonKit   Source File: LargeImageListAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void bind(final LargeImageInfo largeImageInfo) {
    try {
        int resourceUrl = Integer.parseInt(largeImageInfo.getUrl());
        DokitPicasso.with(DoraemonKit.APPLICATION)
                .load(resourceUrl)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .resize(ConvertUtils.dp2px(100), ConvertUtils.dp2px(100))
                .centerCrop()
                .into(iv);
        tvLink.setText("resource id:" + resourceUrl);
    } catch (Exception e) {
        DokitPicasso.with(DoraemonKit.APPLICATION)
                .load(largeImageInfo.getUrl())
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .resize(ConvertUtils.dp2px(100), ConvertUtils.dp2px(100))
                .centerCrop()
                .into(iv);
        tvLink.setText(largeImageInfo.getUrl());
    }

    if (largeImageInfo.getMemorySize() == 0) {
        tvFrameWork.setText(String.format("framework:%s", "network"));
        tvMemorySize.setVisibility(View.GONE);
        tvSize.setVisibility(View.GONE);
    } else {
        tvFrameWork.setText(String.format("framework:%s", largeImageInfo.getFramework()));
        tvMemorySize.setVisibility(View.VISIBLE);
        tvSize.setVisibility(View.VISIBLE);
    }
    if (largeImageInfo.getFileSize() == 0) {
        tvFileSize.setVisibility(View.GONE);
    } else {
        tvFileSize.setVisibility(View.VISIBLE);
    }

    tvFileSize.setText(String.format("fileSize:%s", mDecimalFormat.format(largeImageInfo.getFileSize()) + "KB"));
    tvMemorySize.setText(String.format("memorySize:%s", mDecimalFormat.format(largeImageInfo.getMemorySize()) + "MB"));
    tvSize.setText(String.format("width:%s   height:%s", largeImageInfo.getWidth(), largeImageInfo.getHeight()));
    btnCopy.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ClipboardUtils.copyUri(Uri.parse(largeImageInfo.getUrl()));
            ToastUtils.showShort("image url  has copied");
        }

    });
}
 
Example 30
Source Project: DoraemonKit   Source File: UIUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static int dp2px(float dpValue) {
    return ConvertUtils.dp2px(dpValue);
}