Java Code Examples for com.blankj.utilcode.util.ScreenUtils#isPortrait()

The following examples show how to use com.blankj.utilcode.util.ScreenUtils#isPortrait() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
Source File: LastDokitViewPosInfo.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public void setPortrait() {
    this.isPortrait = ScreenUtils.isPortrait();
}