com.blankj.utilcode.util.ScreenUtils Java Examples

The following examples show how to use com.blankj.utilcode.util.ScreenUtils. 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: CoverLoader.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
private Bitmap loadCoverByType(AudioBean music, Type type) {
    Bitmap bitmap;
    if (music.getType() == AudioBean.Type.LOCAL) {
        bitmap = loadCoverFromMediaStore(music.getAlbumId());
    } else {
        bitmap = loadCoverFromFile(music.getCoverPath());
    }
    switch (type) {
        case BLUR:
            return ImageUtils.blur(bitmap);
        case ROUND:
            bitmap = ImageUtils.resizeImage(bitmap, ScreenUtils.getScreenWidth() / 2, ScreenUtils.getScreenWidth() / 2);
            return ImageUtils.createCircleImage(bitmap);
        default:
            return bitmap;
    }
}
 
Example #2
Source File: LongImageUtils.java    From SuperNote with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 截取scrollview的屏幕
 **/
public static Bitmap getScrollViewBitmap(ScrollView scrollView) {
    int h = 0;
    Bitmap bitmap;
    for (int i = 0; i < scrollView.getChildCount(); i++) {
        h += scrollView.getChildAt(i).getHeight();
    }
    // 创建对应大小的bitmap

    bitmap = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), h,
            Bitmap.Config.ARGB_4444);
    final Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.parseColor("#f2f7fa"));
    scrollView.draw(canvas);
    return bitmap;
}
 
Example #3
Source File: AppService.java    From V2EX with GNU General Public License v3.0 6 votes vote down vote up
public static void checkNotifycation(String errorLog,ResponseListener<String> responseListener){

        Map<String, String> form = new HashMap<String,String>(){{
            put("version", AppUtils.getAppVersionName() + AppUtils.getAppVersionCode());
            put("deviceModel", DeviceUtils.getModel());
            put("sdkVersion", String.valueOf(DeviceUtils.getSDKVersionCode()));
            put("screen",  ScreenUtils.getScreenDensity() +
                    " " + ScreenUtils.getScreenHeight() +
                    "x" + ScreenUtils.getScreenWidth());
            put("errorLog", errorLog);
        }};
        RetrofitManager.create(AppApi.class)
                .checkNotifycation(form)
                .compose(RxUtil.io2main())
                .subscribe(new RxObserver<JsonObject>() {
                    @Override
                    public void _onNext(JsonObject jsonObject) {

                    }
                });
    }
 
Example #4
Source File: EverywherePopup.java    From EasyPopup with Apache License 2.0 5 votes vote down vote up
/**
     * 自适应触摸点 弹出
     * @param parent
     * @param touchX
     * @param touchY
     * @return
     */
    public EverywherePopup showEverywhere(View parent,int touchX, int touchY) {
//        if (isRealWHAlready()) {
            int screenHeight = ScreenUtils.getScreenHeight();
            int screenWidth = ScreenUtils.getScreenWidth();
            int offsetX=touchX;
            int offsetY=touchY;
            if (touchX<getWidth() && screenHeight-touchY<getHeight()){
                //左下弹出动画
                getPopupWindow().setAnimationStyle(R.style.LeftBottomPopAnim);
                offsetY=touchY-getHeight();
            }else if (touchX+getWidth()>screenWidth && touchY+getHeight()>screenHeight){
                //右下弹出动画
                getPopupWindow().setAnimationStyle(R.style.RightBottomPopAnim);
                offsetX=(touchX-getWidth());
                offsetY=touchY-getHeight();
            }else if (touchX+getWidth()>screenWidth){
                getPopupWindow().setAnimationStyle(R.style.RightTopPopAnim);
                offsetX=(touchX-getWidth());
            }else {
                getPopupWindow().setAnimationStyle(R.style.LeftTopPopAnim);
            }

            showAtLocation(parent, Gravity.NO_GRAVITY,offsetX,offsetY);
//        }
        return this;
    }
 
Example #5
Source File: DebugConfig.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public static int getViewHeight(View view, int height) {
    if (ScreenUtils.isPortrait()) {
        return getSp().getInt(view.getClass().getSimpleName() + ".heightP", height);
    } else {
        return getSp().getInt(view.getClass().getSimpleName() + ".heightL", height);
    }
}
 
Example #6
Source File: DebugConfig.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public static void saveViewHeight(View view, int height) {
    if (ScreenUtils.isPortrait()) {
        getSp().put(view.getClass().getSimpleName() + ".heightP", height);
    } else {
        getSp().put(view.getClass().getSimpleName() + ".heightL", height);
    }
}
 
Example #7
Source File: DebugConfig.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public static int getViewX(View view) {
    if (ScreenUtils.isPortrait()) {
        return getSp().getInt(view.getClass().getSimpleName() + ".xP");
    } else {
        return getSp().getInt(view.getClass().getSimpleName() + ".xL");
    }
}
 
Example #8
Source File: DebugConfig.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public static void saveViewX(View view, int x) {
    if (ScreenUtils.isPortrait()) {
        getSp().put(view.getClass().getSimpleName() + ".xP", x);
    } else {
        getSp().put(view.getClass().getSimpleName() + ".xL", x);
    }
}
 
Example #9
Source File: DebugConfig.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public static int getViewY(View view, int defaultVal) {
    if (ScreenUtils.isPortrait()) {
        return getSp().getInt(view.getClass().getSimpleName() + ".yP", defaultVal);
    } else {
        return getSp().getInt(view.getClass().getSimpleName() + ".yL", defaultVal);
    }
}
 
Example #10
Source File: DebugConfig.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public static void saveViewY(View view, int y) {
    if (ScreenUtils.isPortrait()) {
        getSp().put(view.getClass().getSimpleName() + ".yP", y);
    } else {
        getSp().put(view.getClass().getSimpleName() + ".yL", y);
    }
}
 
Example #11
Source File: PointActivity.java    From Pixel-Activity-Keep-Alive with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();
	Log.INSTANCE.e(TAG, " isScreenLock:" + ScreenUtils.isScreenLock());
	//windowAnimationStyle
	if (!isFirst) {
		finish();
	}
	isFirst = false;
	PixelActivityManager.isStarting = false;
}
 
Example #12
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 #13
Source File: EditNotePresenter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public int getRequestImeHeight(BitmapFactory.Options option) {
        float width = option.outWidth;
        float height = option.outHeight;
//        屏幕宽
        float screenWidth = ScreenUtils.getScreenWidth();
        //计算宽、高缩放率
        float scanleWidth = (getRequestImeWidth()) / width;
        return (int) (height * scanleWidth);
    }
 
Example #14
Source File: CoverLoader.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 获取默认的bitmap视图
 * @param type          类型
 * @return              bitmap对象
 */
private Bitmap getDefaultCover(Type type) {
    switch (type) {
        case BLUR:
            return BitmapFactory.decodeResource(Utils.getApp().getResources(), R.drawable.default_cover);
        case ROUND:
            Bitmap bitmap = BitmapFactory.decodeResource(Utils.getApp().getResources(), R.drawable.default_cover);
            bitmap = ImageUtils.resizeImage(bitmap, ScreenUtils.getScreenWidth() / 2, ScreenUtils.getScreenWidth() / 2);
            return bitmap;
        default:
            return BitmapFactory.decodeResource(Utils.getApp().getResources(), R.drawable.default_cover);
    }
}
 
Example #15
Source File: DetailVideoActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 设置视频宽高比是16:9
 */
private void initVideoPlayerSize() {
    int screenWidth = ScreenUtils.getScreenWidth();
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.height = (int) (9 * screenWidth / 16.0f);
    videoPlayer.setLayoutParams(params);
}
 
Example #16
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 #17
Source File: AbsDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 限制边界 调用的时候必须保证是在控件能获取到宽高德前提下
 */
private void resetBorderline(FrameLayout.LayoutParams normalFrameLayoutParams) {
    //如果是系统模式或者手动关闭动态限制边界
    if (!restrictBorderline() || !isNormalMode()) {
        return;
    }
    //LogHelper.i(TAG, "topMargin==>" + normalFrameLayoutParams.topMargin + "  leftMargin====>" + normalFrameLayoutParams.leftMargin);
    if (normalFrameLayoutParams.topMargin <= 0) {
        normalFrameLayoutParams.topMargin = 0;
    }

    if (ScreenUtils.isPortrait()) {
        if (normalFrameLayoutParams.topMargin >= getScreenLongSideLength() - mDokitViewHeight) {
            normalFrameLayoutParams.topMargin = getScreenLongSideLength() - mDokitViewHeight;
        }
    } else {
        if (normalFrameLayoutParams.topMargin >= getScreenShortSideLength() - mDokitViewHeight) {
            normalFrameLayoutParams.topMargin = getScreenShortSideLength() - mDokitViewHeight;
        }
    }


    if (normalFrameLayoutParams.leftMargin <= 0) {
        normalFrameLayoutParams.leftMargin = 0;
    }

    if (ScreenUtils.isPortrait()) {
        if (normalFrameLayoutParams.leftMargin >= getScreenShortSideLength() - mDokitViewWidth) {
            normalFrameLayoutParams.leftMargin = getScreenShortSideLength() - mDokitViewWidth;
        }
    } else {
        if (normalFrameLayoutParams.leftMargin >= getScreenLongSideLength() - mDokitViewWidth) {
            normalFrameLayoutParams.leftMargin = getScreenLongSideLength() - mDokitViewWidth;
        }
    }

}
 
Example #18
Source File: AbsDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 获取屏幕短边的长度 不包含statusBar
 *
 * @return
 */
public int getScreenShortSideLength() {
    if (ScreenUtils.isPortrait()) {
        return ScreenUtils.getAppScreenWidth();
    } else {
        return ScreenUtils.getAppScreenHeight();
    }
}
 
Example #19
Source File: AbsDokitView.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 获取屏幕长边的长度 不包含statusBar
 *
 * @return
 */
public int getScreenLongSideLength() {
    if (ScreenUtils.isPortrait()) {
        //ScreenUtils.getScreenHeight(); 包含statusBar
        //ScreenUtils.getAppScreenHeight(); 不包含statusBar
        return ScreenUtils.getAppScreenHeight();
    } else {
        return ScreenUtils.getAppScreenWidth();
    }
}
 
Example #20
Source File: DeviceInfoItem.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
private static String getScreenInfo() {
    return "width=" + ScreenUtils.getScreenWidth() +
            ", height=" + ScreenUtils.getScreenHeight() +
            ", density=" + ScreenUtils.getScreenDensity();
}
 
Example #21
Source File: PreventKeyboardBlockUtil.java    From PreventKeyboardBlockUtil with Apache License 2.0 4 votes vote down vote up
public void register() {

        isRegister = true;

        keyboardHeightProvider.setKeyboardHeightObserver(new KeyboardHeightObserver() {
            @Override
            public void onKeyboardHeightChanged(int height, int orientation) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    return;
                }
                if(!isRegister){
                    return;
                }

                if (keyBoardHeight == height) {
                    return;
                } else {
                    keyBoardHeight = height;
                }

                if (keyBoardHeight <= 0) {//键盘收起
                    if (isMove) {

                        sendHandlerMsg(0);

                        isMove = true;
                    }
                } else {//键盘打开

                    int keyBorardTopY = ScreenUtils.getAppScreenHeight() - keyBoardHeight;
                    if (keyBorardTopY > (btnViewY + mBtnView.getHeight())) {
                        return;
                    }
                    int margin = keyBorardTopY - (btnViewY + mBtnView.getHeight());
                    Log.i("tag", "margin:" + margin);
                    sendHandlerMsg(margin);

                    isMove = true;
                }

            }
        });

        mBtnView.post(new Runnable() {
            @Override
            public void run() {
                btnViewY = getViewLocationYInScreen(mBtnView);
                keyboardHeightProvider.start();
            }
        });

    }
 
Example #22
Source File: AbsDokitView.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
/**
 * 用于普通模式下的横竖屏切换
 */
private void portraitOrLandscape(FrameLayout.LayoutParams params) {
    Point point = DokitViewManager.getInstance().getDokitViewPos(mTag);
    if (point != null) {
        //横竖屏切换兼容
        if (ScreenUtils.isPortrait()) {
            if (mLastDokitViewPosInfo.isPortrait()) {
                params.leftMargin = point.x;
                params.topMargin = point.y;
            } else {
                params.leftMargin = (int) (point.x * mLastDokitViewPosInfo.getLeftMarginPercent());
                params.topMargin = (int) (point.y * mLastDokitViewPosInfo.getTopMarginPercent());
            }
        } else {
            if (mLastDokitViewPosInfo.isPortrait()) {
                params.leftMargin = (int) (point.x * mLastDokitViewPosInfo.getLeftMarginPercent());
                params.topMargin = (int) (point.y * mLastDokitViewPosInfo.getTopMarginPercent());
            } else {
                params.leftMargin = point.x;
                params.topMargin = point.y;
            }
        }
    } else {
        //横竖屏切换兼容
        if (ScreenUtils.isPortrait()) {
            if (mLastDokitViewPosInfo.isPortrait()) {
                params.leftMargin = mDokitViewLayoutParams.x;
                params.topMargin = mDokitViewLayoutParams.y;
            } else {
                params.leftMargin = (int) (mDokitViewLayoutParams.x * mLastDokitViewPosInfo.getLeftMarginPercent());
                params.topMargin = (int) (mDokitViewLayoutParams.y * mLastDokitViewPosInfo.getTopMarginPercent());
            }
        } else {
            if (mLastDokitViewPosInfo.isPortrait()) {
                params.leftMargin = (int) (mDokitViewLayoutParams.x * mLastDokitViewPosInfo.getLeftMarginPercent());
                params.topMargin = (int) (mDokitViewLayoutParams.y * mLastDokitViewPosInfo.getTopMarginPercent());
            } else {
                params.leftMargin = mDokitViewLayoutParams.x;
                params.topMargin = mDokitViewLayoutParams.y;
            }
        }
    }
    mLastDokitViewPosInfo.setPortrait();
    mLastDokitViewPosInfo.setLeftMargin(params.leftMargin);
    mLastDokitViewPosInfo.setTopMargin(params.topMargin);
}
 
Example #23
Source File: DebugConfig.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public static float getDebugIconY() {
    return getSp().getFloat(DEBUG_ICON_Y, ScreenUtils.getAppScreenHeight() / 3);
}
 
Example #24
Source File: WindowHelper.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public static int getAppWindowHeight() {
    return ScreenUtils.getAppScreenHeight();
}
 
Example #25
Source File: UIUtils.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public static int getDensityDpi() {
    return ScreenUtils.getScreenDensityDpi();
}
 
Example #26
Source File: LastDokitViewPosInfo.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public void setPortrait() {
    this.isPortrait = ScreenUtils.isPortrait();
}
 
Example #27
Source File: LastDokitViewPosInfo.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public void setLeftMargin(int leftMargin) {
    this.leftMarginPercent = (float) leftMargin / (float) ScreenUtils.getAppScreenWidth();
}
 
Example #28
Source File: LastDokitViewPosInfo.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public void setTopMargin(int topMargin) {
    this.topMarginPercent = (float) topMargin / (float) ScreenUtils.getAppScreenHeight();
}
 
Example #29
Source File: EditNotePresenter.java    From SuperNote with GNU General Public License v3.0 4 votes vote down vote up
private int getRequestImeWidth() {
    return (int) (ScreenUtils.getScreenWidth() - EditNoteConstans.imageMargin);
}
 
Example #30
Source File: UIUtils.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public static float getDensity() {
    return ScreenUtils.getScreenDensity();
}