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

The following examples show how to use com.blankj.utilcode.util.SizeUtils#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: OnLineMusicFragment.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    final RecycleViewItemLine line = new RecycleViewItemLine(activity, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new OnLineMusicAdapter(activity);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            if(NetworkUtils.isConnected()){
                onLazyLoad();
            }else {
                ToastUtils.showRoundRectToast("没有网络");
            }
        }
    });
}
 
Example 2
Source File: StudyFragment.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initYCRefreshView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    final RecycleViewItemLine line = new RecycleViewItemLine(activity, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new StudyAdapter(activity);
    recyclerView.setAdapter(adapter);
    addHeader();
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
            if(swipeToRefresh.isRefreshing()){
                recyclerView.setRefreshing(false);
            }
        }
    });
}
 
Example 3
Source File: InnovationFragment.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initYCRefreshView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    final RecycleViewItemLine line = new RecycleViewItemLine(activity, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new InnovationAdapter(activity);
    recyclerView.setAdapter(adapter);
    addHeader();
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
            if(swipeToRefresh.isRefreshing()){
                recyclerView.setRefreshing(false);
            }
        }
    });

    //设置回收复用池大小,(如果一屏内相同类型的 View 个数比较多,需要设置一个合适的大小,防止来回滚动时重新创建 View)
    RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
    recyclerView.getRecyclerView().setRecycledViewPool(viewPool);
    viewPool.setMaxRecycledViews(0, 20);
}
 
Example 4
Source File: LocalOfficeActivity.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new LocalOfficeAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
            if (swipeToRefresh.isRefreshing()) {
                recyclerView.setRefreshing(false);
            }else {
                initData();
            }
        }
    });
}
 
Example 5
Source File: LocalVideoActivity.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new LocalVideoAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
            if (swipeToRefresh.isRefreshing()) {
                recyclerView.setRefreshing(false);
            }else {
                initData();
            }
        }
    });
}
 
Example 6
Source File: LocalZipFileActivity.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private void initRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new LocalOfficeAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
            if (swipeToRefresh.isRefreshing()) {
                recyclerView.setRefreshing(false);
            }else {
                initData();
            }
        }
    });
}
 
Example 7
Source File: DetailVideoActivity.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化指示器
 */
private void initIndicator() {
    tvTitleLeft.setText("课程简介");
    tvTitleRight.setText("课程目录课程目录");
    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    tvTitleLeft.measure(spec,spec);
    tvTitleRight.measure(spec,spec);
    int widthLeft = tvTitleLeft.getMeasuredWidth();
    int widthRight = tvTitleRight.getMeasuredWidth();
    AppLogUtils.e("width"+tvTitleLeft.getWidth() + "---"+tvTitleRight.getWidth()
            + "---"+tvTitleLeft.getMeasuredWidth());
    AppLogUtils.e("width"+"----------"+widthLeft+"-----"+widthRight);
    LinearLayout.LayoutParams paramsLeft = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, SizeUtils.dp2px(2));
    paramsLeft.width = widthLeft;
    viewLeft.setLayoutParams(paramsLeft);
    LinearLayout.LayoutParams paramsRight = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, SizeUtils.dp2px(2));
    paramsRight.width = widthRight;
    viewRight.setLayoutParams(paramsRight);
    setViewIndicator(true);
}
 
Example 8
Source File: DetailAudioFragment.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private void initToolBar() {
    int statusBarHeight = BarUtils.getStatusBarHeight();
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, SizeUtils.dp2px(50));
    params.topMargin = statusBarHeight;
    toolbar.setLayoutParams(params);
}
 
Example 9
Source File: DetailAudioFragment.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private void initYCRefreshView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    final RecycleViewItemLine line = new RecycleViewItemLine(activity, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new DetailAudioAdapter(activity);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshing(false);
    addHeader();
}
 
Example 10
Source File: DetailVideoActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private void initYCRefreshView() {
    linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);
    final RecycleViewItemLine line = new RecycleViewItemLine(this, LinearLayout.HORIZONTAL,
            SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
    recyclerView.addItemDecoration(line);
    adapter = new DetailVideoAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setRefreshing(false);
    recyclerView.scrollTo(0,0);
    recyclerView.scrollBy(0,0);
    addHeader();
}
 
Example 11
Source File: EditNotePresenter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getNoteEditNeedHeight() {
    // 屏幕高度减去 状态栏高度、toolbar高度、底部工具栏高度
    float height = ScreenUtils.getScreenHeight() - ThemeUtils.getStatusBarHeight()
            - SizeUtils.dp2px(56) - SizeUtils.dp2px(48);
    return (int) height;
}
 
Example 12
Source File: LockView.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
private void measureDimension(int widthMeasureSpec,int heightMeasureSpec){
//        测量的值
        int measureWidth=0;
        int measureHeight=0;
//        默认值
        int defaultSize=400;

        int widthSpecMode= MeasureSpec.getMode(widthMeasureSpec);
        int heightSpcMode= MeasureSpec.getMode(heightMeasureSpec);
        int widthSpecSize= MeasureSpec.getSize(widthMeasureSpec);
        int heightSpecSize= MeasureSpec.getSize(heightMeasureSpec);
        switch (widthSpecMode){
            case MeasureSpec.EXACTLY:
                measureWidth=widthSpecSize;
                break;
            case MeasureSpec.UNSPECIFIED:
                measureWidth=SizeUtils.dp2px(defaultSize);
                break;
            case MeasureSpec.AT_MOST:
                measureWidth= Math.min(widthSpecSize,defaultSize);
                break;
        }
        switch (heightSpcMode){
            case MeasureSpec.EXACTLY:
                measureHeight=heightSpecSize;
                break;
            case MeasureSpec.UNSPECIFIED:
                measureHeight=SizeUtils.dp2px(defaultSize);
                break;
            case MeasureSpec.AT_MOST:
//                为了让解锁界面为方形,让高的值和宽一样。
                measureHeight=measureWidth;
                break;
        }
        setMeasuredDimension(measureWidth,measureHeight);

    }
 
Example 13
Source File: FloatToast.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreateLayoutParams() {
    super.onCreateLayoutParams();

    mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mLayoutParams.windowAnimations = android.R.style.Animation_Toast;
    mLayoutParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    mLayoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    mLayoutParams.y = SizeUtils.dp2px(64);
}
 
Example 14
Source File: InnovationFragment.java    From YCAudioPlayer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("ResourceType")
private LinearLayout initFiveButtonView() {
    ArrayList<String> title = new ArrayList<>();
    title.add("视频");
    title.add("图片");
    title.add("压缩包");
    title.add("文档");
    title.add("其他");
    //四个按钮
    LinearLayout btnLinearLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams params = new
            LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    btnLinearLayout.setLayoutParams(params);
    btnLinearLayout.setPadding(0, SizeUtils.dp2px(15), 0, SizeUtils.dp2px(15));
    btnLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    //重点:根据服务器返回数据动态创建按钮。如果返回5条数据,就创建5个按钮
    for (int i = 0; i < 5; i++) {
        LinearLayout llBtn = new LinearLayout(activity);
        LinearLayout.LayoutParams llLayoutParams = new
                LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        llLayoutParams.width = 0;
        llLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        llLayoutParams.weight = 1;
        llLayoutParams.gravity = Gravity.CENTER;
        llBtn.setLayoutParams(llLayoutParams);
        llBtn.setOrientation(LinearLayout.VERTICAL);
        llBtn.setId(1000 + i);
        llBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppLogUtils.e("onClick"+v.getId());
                switch (v.getId()) {
                    case 1000:
                        ActivityUtils.startActivity(LocalVideoActivity.class);
                        break;
                    case 1001:
                        ActivityUtils.startActivity(LocalOfficeActivity.class);
                        break;
                    case 1002:
                        ActivityUtils.startActivity(LocalZipFileActivity.class);
                        break;
                    case 1003:
                        ActivityUtils.startActivity(DetailVideoActivity.class);
                        break;
                    case 1004:
                        ActivityUtils.startActivity(DetailVideoActivity.class);
                        break;
                    default:
                        break;
                }
            }
        });

        ImageView imageView = new ImageView(activity);
        LinearLayout.LayoutParams ivLayoutParams = new LinearLayout.LayoutParams(SizeUtils.dp2px(45), SizeUtils.dp2px(45));
        ivLayoutParams.gravity = Gravity.CENTER;
        imageView.setLayoutParams(ivLayoutParams);
        ImageUtil.loadImgByPicasso(activity, R.drawable.ic_home_first, imageView);

        TextView textView = new TextView(activity);
        LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        tvLayoutParams.topMargin = SizeUtils.dp2px(8);
        tvLayoutParams.gravity = Gravity.CENTER;
        textView.setLayoutParams(tvLayoutParams);
        textView.setTextSize(14);
        textView.setText(title.get(i));
        llBtn.addView(imageView);
        llBtn.addView(textView);
        btnLinearLayout.addView(llBtn);
    }
    return btnLinearLayout;
}
 
Example 15
Source File: EasyPopActivity.java    From EasyPopup with Apache License 2.0 4 votes vote down vote up
private void showQQPop(View view) {
    int offsetX = SizeUtils.dp2px(20) - view.getWidth() / 2;
    int offsetY = (mTitleBar.getHeight() - view.getHeight()) / 2;
    mQQPop.showAtAnchorView(view, YGravity.BELOW, XGravity.ALIGN_RIGHT, offsetX, offsetY);
}