Java Code Examples for org.telegram.messenger.AndroidUtilities#getViewInset()

The following examples show how to use org.telegram.messenger.AndroidUtilities#getViewInset() . 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: ActionBarLayout.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b)
{
    super.onLayout(changed, l, t, r, b);

    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
    isKeyboardVisible = usableViewHeight - (rect.bottom - rect.top) > 0;
    if (waitingForKeyboardCloseRunnable != null && !containerView.isKeyboardVisible && !containerViewBack.isKeyboardVisible)
    {
        AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
        waitingForKeyboardCloseRunnable.run();
        waitingForKeyboardCloseRunnable = null;
    }
}
 
Example 2
Source File: PasscodeView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    View rootView = getRootView();
    int usableViewHeight = rootView.getHeight() - AndroidUtilities.statusBarHeight - AndroidUtilities.getViewInset(rootView);
    getWindowVisibleDisplayFrame(rect);
    keyboardHeight = usableViewHeight - (rect.bottom - rect.top);

    if (SharedConfig.passcodeType == 1 && (AndroidUtilities.isTablet() || getContext().getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)) {
        int t = 0;
        if (passwordFrameLayout.getTag() != null) {
            t = (Integer) passwordFrameLayout.getTag();
        }
        LayoutParams layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
        layoutParams.topMargin = t + layoutParams.height - keyboardHeight / 2 - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
        passwordFrameLayout.setLayoutParams(layoutParams);
    }

    super.onLayout(changed, left, top, right, bottom);
}
 
Example 3
Source File: ActionBarLayout.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b)
{
    super.onLayout(changed, l, t, r, b);

    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
    isKeyboardVisible = usableViewHeight - (rect.bottom - rect.top) > 0;
    if (waitingForKeyboardCloseRunnable != null && !containerView.isKeyboardVisible && !containerViewBack.isKeyboardVisible)
    {
        AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
        waitingForKeyboardCloseRunnable.run();
        waitingForKeyboardCloseRunnable = null;
    }
}
 
Example 4
Source File: PasscodeView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    View rootView = getRootView();
    int usableViewHeight = rootView.getHeight() - AndroidUtilities.statusBarHeight - AndroidUtilities.getViewInset(rootView);
    getWindowVisibleDisplayFrame(rect);
    keyboardHeight = usableViewHeight - (rect.bottom - rect.top);

    if (SharedConfig.passcodeType == 1 && (AndroidUtilities.isTablet() || getContext().getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)) {
        int t = 0;
        if (passwordFrameLayout.getTag() != null) {
            t = (Integer) passwordFrameLayout.getTag();
        }
        LayoutParams layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
        layoutParams.topMargin = t + layoutParams.height - keyboardHeight / 2 - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
        passwordFrameLayout.setLayoutParams(layoutParams);
    }

    super.onLayout(changed, left, top, right, bottom);
}
 
Example 5
Source File: PasscodeView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    View rootView = getRootView();
    int usableViewHeight = rootView.getHeight() - AndroidUtilities.statusBarHeight - AndroidUtilities.getViewInset(rootView);
    getWindowVisibleDisplayFrame(rect);
    keyboardHeight = usableViewHeight - (rect.bottom - rect.top);

    if (SharedConfig.passcodeType == 1 && (AndroidUtilities.isTablet() || getContext().getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)) {
        int t = 0;
        if (passwordFrameLayout.getTag() != null) {
            t = (Integer) passwordFrameLayout.getTag();
        }
        LayoutParams layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
        layoutParams.topMargin = t + layoutParams.height - keyboardHeight / 2 - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
        passwordFrameLayout.setLayoutParams(layoutParams);
    }

    super.onLayout(changed, left, top, right, bottom);
}
 
Example 6
Source File: PasscodeView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    View rootView = getRootView();
    int usableViewHeight = rootView.getHeight() - AndroidUtilities.statusBarHeight - AndroidUtilities.getViewInset(rootView);
    getWindowVisibleDisplayFrame(rect);
    keyboardHeight = usableViewHeight - (rect.bottom - rect.top);

    if (SharedConfig.passcodeType == 1 && (AndroidUtilities.isTablet() || getContext().getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)) {
        int t = 0;
        if (passwordFrameLayout.getTag() != null) {
            t = (Integer) passwordFrameLayout.getTag();
        }
        LayoutParams layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
        layoutParams.topMargin = t + layoutParams.height - keyboardHeight / 2 - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
        passwordFrameLayout.setLayoutParams(layoutParams);
    }

    super.onLayout(changed, left, top, right, bottom);
}
 
Example 7
Source File: SizeNotifierFrameLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public int measureKeyboardHeight() {
    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    if (rect.bottom == 0 && rect.top == 0) {
        return 0;
    }
    int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
    return keyboardHeight = Math.max(0, usableViewHeight - (rect.bottom - rect.top));
}
 
Example 8
Source File: SizeNotifierFrameLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public int measureKeyboardHeight() {
    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    if (rect.bottom == 0 && rect.top == 0) {
        return 0;
    }
    int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
    return keyboardHeight = Math.max(0, usableViewHeight - (rect.bottom - rect.top));
}
 
Example 9
Source File: SizeNotifierFrameLayout.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public int getKeyboardHeight() {
    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
    return usableViewHeight - (rect.bottom - rect.top);
}
 
Example 10
Source File: SizeNotifierFrameLayout.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public int getKeyboardHeight() {
    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
    return usableViewHeight - (rect.bottom - rect.top);
}
 
Example 11
Source File: BottomSheet.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    int containerHeight = height;
    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    if (rect.bottom != 0 && rect.top != 0) {
        int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
        keyboardHeight = Math.max(0, usableViewHeight - (rect.bottom - rect.top));
        if (keyboardHeight < AndroidUtilities.dp(20)) {
            keyboardHeight = 0;
        }
        bottomInset -= keyboardHeight;
    } else {
        keyboardHeight = 0;
    }
    keyboardVisible = keyboardHeight > AndroidUtilities.dp(20);
    if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
        bottomInset = lastInsets.getSystemWindowInsetBottom();
        if (Build.VERSION.SDK_INT >= 29) {
            bottomInset += getAdditionalMandatoryOffsets();
        }
        if (keyboardVisible && rect.bottom != 0 && rect.top != 0) {
            bottomInset -= keyboardHeight;
        }
        if (!drawNavigationBar) {
            containerHeight -= bottomInset;
        }
    }
    setMeasuredDimension(width, containerHeight);
    if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
        int inset = lastInsets.getSystemWindowInsetBottom();
        if (Build.VERSION.SDK_INT >= 29) {
            inset += getAdditionalMandatoryOffsets();
        }
        height -= inset;
    }
    if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
        width -= lastInsets.getSystemWindowInsetRight() + lastInsets.getSystemWindowInsetLeft();
    }
    boolean isPortrait = width < height;

    if (containerView != null) {
        if (!fullWidth) {
            int widthSpec;
            if (AndroidUtilities.isTablet()) {
                widthSpec = MeasureSpec.makeMeasureSpec((int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f) + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY);
            } else {
                widthSpec = MeasureSpec.makeMeasureSpec(isPortrait ? width + backgroundPaddingLeft * 2 : (int) Math.max(width * 0.8f, Math.min(AndroidUtilities.dp(480), width)) + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY);
            }
            containerView.measure(widthSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
        } else {
            containerView.measure(MeasureSpec.makeMeasureSpec(width + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
        }
    }
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() == GONE || child == containerView) {
            continue;
        }
        if (!onCustomMeasure(child, width, height)) {
            measureChildWithMargins(child, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 0, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY), 0);
        }
    }
}
 
Example 12
Source File: BottomSheet.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    int containerHeight = height;
    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    if (rect.bottom != 0 && rect.top != 0) {
        int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
        keyboardHeight = Math.max(0, usableViewHeight - (rect.bottom - rect.top));
        if (keyboardHeight < AndroidUtilities.dp(20)) {
            keyboardHeight = 0;
        }
        bottomInset -= keyboardHeight;
    } else {
        keyboardHeight = 0;
    }
    keyboardVisible = keyboardHeight > AndroidUtilities.dp(20);
    if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
        bottomInset = lastInsets.getSystemWindowInsetBottom();
        if (Build.VERSION.SDK_INT >= 29) {
            bottomInset += getAdditionalMandatoryOffsets();
        }
        if (keyboardVisible && rect.bottom != 0 && rect.top != 0) {
            bottomInset -= keyboardHeight;
        }
        if (!drawNavigationBar) {
            containerHeight -= bottomInset;
        }
    }
    setMeasuredDimension(width, containerHeight);
    if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
        int inset = lastInsets.getSystemWindowInsetBottom();
        if (Build.VERSION.SDK_INT >= 29) {
            inset += getAdditionalMandatoryOffsets();
        }
        height -= inset;
    }
    if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
        width -= lastInsets.getSystemWindowInsetRight() + lastInsets.getSystemWindowInsetLeft();
    }
    boolean isPortrait = width < height;

    if (containerView != null) {
        if (!fullWidth) {
            int widthSpec;
            if (AndroidUtilities.isTablet()) {
                widthSpec = MeasureSpec.makeMeasureSpec((int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f) + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY);
            } else {
                widthSpec = MeasureSpec.makeMeasureSpec(isPortrait ? width + backgroundPaddingLeft * 2 : (int) Math.max(width * 0.8f, Math.min(AndroidUtilities.dp(480), width)) + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY);
            }
            containerView.measure(widthSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
        } else {
            containerView.measure(MeasureSpec.makeMeasureSpec(width + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
        }
    }
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() == GONE || child == containerView) {
            continue;
        }
        if (!onCustomMeasure(child, width, height)) {
            measureChildWithMargins(child, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 0, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY), 0);
        }
    }
}