Java Code Examples for com.blankj.utilcode.util.ConvertUtils#dp2px()

The following examples show how to use com.blankj.utilcode.util.ConvertUtils#dp2px() . 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: 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 2
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 3
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 4
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 5
Source File: UIUtils.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public static int dp2px(float dpValue) {
    return ConvertUtils.dp2px(dpValue);
}
 
Example 6
Source File: RoundImageView.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mRadiusPx = ConvertUtils.dp2px(5);
}
 
Example 7
Source File: AnimeDetailActivity.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@Override
public void initView() {
    int statusBarHeight = ConvertUtils.dp2px(20);
    toolBar.setPadding(0, statusBarHeight, 0, 0);
    ViewGroup.LayoutParams toolbarParams = toolBar.getLayoutParams();
    toolbarParams.height += statusBarHeight;
    toolbarHeight = toolbarParams.height;

    scrollableLayout.addHeadView(toolBar);
    toolBar.setBackgroundColor(CommonUtils.getResColor(0, R.color.theme_color));
    toolBar.setTitleTextColor(CommonUtils.getResColor(0, R.color.immutable_text_white));

    episodeLinearList = new ArrayList<>();
    episodeGridList = new ArrayList<>();
    recommendList = new ArrayList<>();
    moreList = new ArrayList<>();
    tagList = new ArrayList<>();

    episodeLinearAdapter = new BaseRvAdapter<AnimeDetailBean.BangumiBean.EpisodesBean>(episodeLinearList) {
        @NonNull
        @Override
        public AdapterItem<AnimeDetailBean.BangumiBean.EpisodesBean> onCreateItem(int viewType) {
            return new AnimeEpisodeItem(false);
        }
    };

    episodeGridAdapter = new BaseRvAdapter<AnimeDetailBean.BangumiBean.EpisodesBean>(episodeGridList) {
        @NonNull
        @Override
        public AdapterItem<AnimeDetailBean.BangumiBean.EpisodesBean> onCreateItem(int viewType) {
            return new AnimeEpisodeItem(true);
        }
    };

    recommendAdapter = new BaseRvAdapter<AnimeBean>(recommendList) {
        @NonNull
        @Override
        public AdapterItem<AnimeBean> onCreateItem(int viewType) {
            return new AnimeRecommendItem();
        }
    };

    moreAdapter = new BaseRvAdapter<AnimeBean>(moreList) {
        @NonNull
        @Override
        public AdapterItem<AnimeBean> onCreateItem(int viewType) {
            return new AnimeMoreItem();
        }
    };

    tagAdapter = new BaseRvAdapter<AnimeDetailBean.BangumiBean.TagsBean>(tagList) {
        @NonNull
        @Override
        public AdapterItem<AnimeDetailBean.BangumiBean.TagsBean> onCreateItem(int viewType) {
            return new AnimeTagItem();
        }
    };

    episodeLinearRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    episodeLinearRv.setNestedScrollingEnabled(false);
    episodeLinearRv.addItemDecoration(new ItemDecorationSpaces(10));
    episodeLinearRv.setAdapter(episodeLinearAdapter);

    episodeGridRv.setLayoutManager(new GridLayoutManager(this, 2));
    episodeGridRv.addItemDecoration(new ItemDecorationSpaces(0, 10, 10, 10, 2));
    episodeGridRv.setAdapter(episodeGridAdapter);

    recommendRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    recommendRv.setNestedScrollingEnabled(false);
    recommendRv.addItemDecoration(new ItemDecorationSpaces(10));
    recommendRv.setAdapter(recommendAdapter);

    moreRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    moreRv.setNestedScrollingEnabled(false);
    moreRv.setAdapter(moreAdapter);

    tagRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    tagRv.setAdapter(tagAdapter);

    animeId = getIntent().getStringExtra("anime_id");
    presenter.getAnimeDetail(animeId);

    scrollableLayout.setHeadCount(2);
}
 
Example 8
Source File: SubtitleManager.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
public void setTextSizeProgress(int textSizeProgress) {
    this.textSize = (int) (((float) textSizeProgress / 100) * ConvertUtils.dp2px(36));
}
 
Example 9
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 10
Source File: CourtesyCardView.java    From AndroidSamples with Apache License 2.0 4 votes vote down vote up
public void setRadius(int radius) {
    this.radius = ConvertUtils.dp2px(radius);
    // 刷新视图
    invalidate();
}
 
Example 11
Source File: CourtesyCardView.java    From AndroidSamples with Apache License 2.0 4 votes vote down vote up
public void setGap(int gap) {
    this.gap = ConvertUtils.dp2px(gap);
    invalidate();
}