Java Code Examples for android.view.Window#isFloating()

The following examples show how to use android.view.Window#isFloating() . 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: AwesomeFragment.java    From AndroidNavigation with MIT License 6 votes vote down vote up
@Override
@NonNull
public LayoutInflater onGetLayoutInflater(@Nullable Bundle savedInstanceState) {
    inflateStyle();

    if (!getShowsDialog()) {
        return super.onGetLayoutInflater(savedInstanceState);
    }

    setStyle(STYLE_NORMAL, R.style.Theme_Nav_FullScreenDialog);

    super.onGetLayoutInflater(savedInstanceState);
    LayoutInflater layoutInflater = requireActivity().getLayoutInflater();
    Window window = getWindow();
    boolean isFloating = window != null && window.isFloating();
    if (getShowsDialog() && !isFloating) {
        layoutInflater = new DialogLayoutInflater(requireContext(), layoutInflater,
                () -> {
                    if (isCancelable()) {
                        hideDialog();
                    }
                });
    }

    return layoutInflater;
}
 
Example 2
Source File: UI.java    From android-lockpattern with Apache License 2.0 5 votes vote down vote up
/**
 * Uses a fixed size for {@code dialogWindow} in large screens.
 * 
 * @param dialogWindow
 *            the window <i>of the dialog</i>.
 */
public static void adjustDialogSizeForLargeScreens(Window dialogWindow) {
    if (DEBUG)
        Log.d(CLASSNAME, "adjustDialogSizeForLargeScreens()");

    if (!dialogWindow.isFloating())
        return;

    final ScreenSize screenSize = ScreenSize.getCurrent(dialogWindow
            .getContext());
    switch (screenSize) {
    case LARGE:
    case XLARGE:
        break;
    default:
        return;
    }

    final DisplayMetrics metrics = dialogWindow.getContext().getResources()
            .getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;

    int width = metrics.widthPixels;// dialogWindow.getDecorView().getWidth();
    int height = metrics.heightPixels;// dialogWindow.getDecorView().getHeight();
    if (DEBUG)
        Log.d(CLASSNAME,
                String.format("width = %,d | height = %,d", width, height));

    width = (int) (width * (isPortrait ? screenSize.fixedWidthMinor
            : screenSize.fixedWidthMajor));
    height = (int) (height * (isPortrait ? screenSize.fixedHeightMajor
            : screenSize.fixedHeightMinor));

    if (DEBUG)
        Log.d(CLASSNAME, String.format(
                "NEW >>> width = %,d | height = %,d", width, height));
    dialogWindow.setLayout(width, height);
}
 
Example 3
Source File: UI.java    From android-lockpattern with Apache License 2.0 5 votes vote down vote up
/**
 * Uses a fixed size for {@code dialogWindow} in large screens.
 * 
 * @param dialogWindow
 *            the window <i>of the dialog</i>.
 */
public static void adjustDialogSizeForLargeScreens(Window dialogWindow) {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "adjustDialogSizeForLargeScreens()");

    if (!dialogWindow.isFloating())
        return;

    final ScreenSize screenSize = ScreenSize.getCurrent(dialogWindow
            .getContext());
    switch (screenSize) {
    case LARGE:
    case XLARGE:
        break;
    default:
        return;
    }

    final DisplayMetrics metrics = dialogWindow.getContext().getResources()
            .getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;

    int width = metrics.widthPixels;// dialogWindow.getDecorView().getWidth();
    int height = metrics.heightPixels;// dialogWindow.getDecorView().getHeight();
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME,
                String.format("width = %,d | height = %,d", width, height));

    width = (int) (width * (isPortrait ? screenSize.fixedWidthMinor
            : screenSize.fixedWidthMajor));
    height = (int) (height * (isPortrait ? screenSize.fixedHeightMajor
            : screenSize.fixedHeightMinor));

    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, String.format(
                "NEW >>> width = %,d | height = %,d", width, height));
    dialogWindow.setLayout(width, height);
}
 
Example 4
Source File: UI.java    From Pi-Locker with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses a fixed size for {@code dialogWindow} in large screens.
 * 
 * @param dialogWindow
 *            the window <i>of the dialog</i>.
 */
public static void adjustDialogSizeForLargeScreen(final Window dialogWindow) {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "adjustDialogSizeForLargeScreen()");
    if (dialogWindow.isFloating()
            && dialogWindow.getContext().getResources()
                    .getBoolean(R.bool.alp_is_large_screen)) {
        final DisplayMetrics metrics = dialogWindow.getContext()
                .getResources().getDisplayMetrics();
        final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;

        int width = metrics.widthPixels;// dialogWindow.getDecorView().getWidth();
        int height = metrics.heightPixels;// dialogWindow.getDecorView().getHeight();
        if (BuildConfig.DEBUG)
            Log.d(CLASSNAME, String.format("width = %,d | height = %,d",
                    width, height));
        width = (int) dialogWindow
                .getContext()
                .getResources()
                .getFraction(
                        isPortrait ? R.dimen.aosp_dialog_fixed_width_minor
                                : R.dimen.aosp_dialog_fixed_width_major,
                        width, width);
        height = (int) dialogWindow
                .getContext()
                .getResources()
                .getFraction(
                        isPortrait ? R.dimen.aosp_dialog_fixed_height_major
                                : R.dimen.aosp_dialog_fixed_height_minor,
                        height, height);
        if (BuildConfig.DEBUG)
            Log.d(CLASSNAME, String.format(
                    "NEW >>> width = %,d | height = %,d", width, height));
        dialogWindow.setLayout(width, height);
    }
}