android.view.WindowInsets Java Examples

The following examples show how to use android.view.WindowInsets. 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: CutoutUtil.java    From DKVideoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 是否为允许全屏界面显示内容到刘海区域的刘海屏机型(与AndroidManifest中配置对应)
 */
public static boolean allowDisplayToCutout(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        // 9.0系统全屏界面默认会保留黑边,不允许显示内容到刘海区域
        Window window = activity.getWindow();
        WindowInsets windowInsets = window.getDecorView().getRootWindowInsets();
        if (windowInsets == null) {
            return false;
        }
        DisplayCutout displayCutout = windowInsets.getDisplayCutout();
        if (displayCutout == null) {
            return false;
        }
        List<Rect> boundingRects = displayCutout.getBoundingRects();
        return boundingRects.size() > 0;
    } else {
        return hasCutoutHuawei(activity)
                || hasCutoutOPPO(activity)
                || hasCutoutVIVO(activity)
                || hasCutoutXIAOMI(activity);
    }
}
 
Example #2
Source File: DrawerLayoutContainer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
        WindowInsets insets = (WindowInsets) lastInsets;

        if (!SharedConfig.smoothKeyboard) {
            int bottomInset = insets.getSystemWindowInsetBottom();
            if (bottomInset > 0) {
                backgroundPaint.setColor(behindKeyboardColor);
                canvas.drawRect(0, getMeasuredHeight() - bottomInset, getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
            }
        }

        if (hasCutout) {
            backgroundPaint.setColor(0xff000000);
            int left = insets.getSystemWindowInsetLeft();
            if (left != 0) {
                canvas.drawRect(0, 0, left, getMeasuredHeight(), backgroundPaint);
            }
            int right = insets.getSystemWindowInsetRight();
            if (right != 0) {
                canvas.drawRect(right, 0, getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
            }
        }
    }
}
 
Example #3
Source File: AppUtils.java    From AndroidNavigation with MIT License 6 votes vote down vote up
public static void setStatusBarTranslucent(Window window, boolean translucent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setRenderContentInShortEdgeCutoutAreas(window, translucent);

        View decorView = window.getDecorView();
        if (translucent) {
            decorView.setOnApplyWindowInsetsListener((v, insets) -> {
                WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                return defaultInsets.replaceSystemWindowInsets(
                        defaultInsets.getSystemWindowInsetLeft(),
                        0,
                        defaultInsets.getSystemWindowInsetRight(),
                        defaultInsets.getSystemWindowInsetBottom());
            });
        } else {
            decorView.setOnApplyWindowInsetsListener(null);
        }

        ViewCompat.requestApplyInsets(decorView);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (translucent) {
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        ViewCompat.requestApplyInsets(window.getDecorView());
    }
}
 
Example #4
Source File: ContainerViewManager.java    From Paginize with MIT License 6 votes vote down vote up
@TargetApi(20)
public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
  if (insets != null) {
    if (mApplyInsetsToShadow && mShadowView != null) {
      MarginLayoutParams lp = (MarginLayoutParams)mShadowView.getLayoutParams();
      if (lp.topMargin != insets.getSystemWindowInsetTop()) {
        lp.topMargin = insets.getSystemWindowInsetTop();
      }
    }

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; ++i) {
      getChildAt(i).dispatchApplyWindowInsets(insets);
    }
  }
  return insets;
}
 
Example #5
Source File: FloatingViewManager.java    From FloatingView with Apache License 2.0 6 votes vote down vote up
/**
 * Find the safe area of DisplayCutout.
 *
 * @param activity {@link Activity} (Portrait and `windowLayoutInDisplayCutoutMode` != never)
 * @return Safe cutout insets.
 */
public static Rect findCutoutSafeArea(@NonNull Activity activity) {
    final Rect safeInsetRect = new Rect();
    // TODO:Rewrite with android-x
    // TODO:Consider alternatives
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
        return safeInsetRect;
    }

    // Fix: getDisplayCutout() on a null object reference (issue #110)
    final WindowInsets windowInsets = activity.getWindow().getDecorView().getRootWindowInsets();
    if (windowInsets == null) {
        return safeInsetRect;
    }

    // set safeInsetRect
    final DisplayCutout displayCutout = windowInsets.getDisplayCutout();
    if (displayCutout != null) {
        safeInsetRect.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetTop(), displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetBottom());
    }

    return safeInsetRect;
}
 
Example #6
Source File: FloatingViewManager.java    From dingo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Find the safe area of DisplayCutout.
 *
 * @param activity {@link Activity} (Portrait and `windowLayoutInDisplayCutoutMode` != never)
 * @return Safe cutout insets.
 */
public static Rect findCutoutSafeArea(@NonNull Activity activity) {
    final Rect safeInsetRect = new Rect();
    // TODO:Rewrite with android-x
    // TODO:Consider alternatives
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
        return safeInsetRect;
    }

    // Fix: getDisplayCutout() on a null object reference (issue #110)
    final WindowInsets windowInsets = activity.getWindow().getDecorView().getRootWindowInsets();
    if (windowInsets == null) {
        return safeInsetRect;
    }

    // set safeInsetRect
    final DisplayCutout displayCutout = windowInsets.getDisplayCutout();
    if (displayCutout != null) {
        safeInsetRect.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetTop(), displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetBottom());
    }

    return safeInsetRect;
}
 
Example #7
Source File: EarthWatchFaceService.java    From earth with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onApplyWindowInsets(WindowInsets insets) {
    if (insets.isRound()) {
        inset = -2;
        setWatchFaceStyle(new WatchFaceStyle.Builder(EarthWatchFaceService.this)
                .setHotwordIndicatorGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)
                .setPeekOpacityMode(WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT)
                .setShowSystemUiTime(true)
                .setShowUnreadCountIndicator(true)
                .setStatusBarGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP)
                .setViewProtectionMode(WatchFaceStyle.PROTECT_HOTWORD_INDICATOR
                        | WatchFaceStyle.PROTECT_STATUS_BAR)
                .build());
    } else {
        inset = getResources().getDimensionPixelOffset(R.dimen.padding_square);
        setWatchFaceStyle(new WatchFaceStyle.Builder(EarthWatchFaceService.this)
                .setHotwordIndicatorGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)
                .setPeekOpacityMode(WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT)
                .setShowSystemUiTime(true)
                .setShowUnreadCountIndicator(true)
                .setStatusBarGravity(Gravity.END | Gravity.TOP)
                .setViewProtectionMode(WatchFaceStyle.PROTECT_HOTWORD_INDICATOR
                        | WatchFaceStyle.PROTECT_STATUS_BAR)
                .build());
    }
}
 
Example #8
Source File: HeadingListView.java    From WearPreferenceActivity with Apache License 2.0 6 votes vote down vote up
@Override public WindowInsets onApplyWindowInsets(final WindowInsets insets) {
    if(insets.isRound()) {
        heading.setGravity(Gravity.CENTER_HORIZONTAL);

        // Adjust paddings for round devices
        if(!hasAdjustedPadding) {
            final int padding = heading.getPaddingTop();
            heading.setPadding(padding, 2 * padding, padding, padding);
            list.setPadding(padding, 0, padding, 0);
            hasAdjustedPadding = true;
        }
    } else {
        heading.setGravity(Gravity.START);
    }
    return super.onApplyWindowInsets(insets);
}
 
Example #9
Source File: MainActivity.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Resources res = getResources();
    final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
    pager.setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // Adjust page margins:
            //   A little extra horizontal spacing between pages looks a bit
            //   less crowded on a round display.
            final boolean round = insets.isRound();
            int rowMargin = res.getDimensionPixelOffset(R.dimen.page_row_margin);
            int colMargin = res.getDimensionPixelOffset(round ?
                    R.dimen.page_column_margin_round : R.dimen.page_column_margin);
            pager.setPageMargins(rowMargin, colMargin);
            return insets;
        }
    });
    pager.setAdapter(new SampleGridPagerAdapter(this, getFragmentManager()));
}
 
Example #10
Source File: SuperTools.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
public static void isNavigationBarExist(Activity activity) {
        if (activity == null) {
            return;
        }
        final int height = getNavigationHeight(activity);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            activity.getWindow().getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsets onApplyWindowInsets(View v, WindowInsets windowInsets) {
                    boolean isShowing = false;
                    int b = 0;
                    if (windowInsets != null) {
                        b = windowInsets.getSystemWindowInsetBottom();
                        isShowing = (b == height);
                    }

                    print("导航栏到底存不存存在----" + isShowing);
//                    if (onNavigationStateListener != null && b <= height) {
//                        onNavigationStateListener.onNavigationState(isShowing, b);
//                    }
                    return windowInsets;
                }
            });
        }
    }
 
Example #11
Source File: BaseActivity.java    From DKVideoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 把状态栏设成透明
 */
protected void setStatusBarTransparent() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        View decorView = getWindow().getDecorView();
        decorView.setOnApplyWindowInsetsListener((v, insets) -> {
            WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
            return defaultInsets.replaceSystemWindowInsets(
                    defaultInsets.getSystemWindowInsetLeft(),
                    0,
                    defaultInsets.getSystemWindowInsetRight(),
                    defaultInsets.getSystemWindowInsetBottom());
        });
        ViewCompat.requestApplyInsets(decorView);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent));
    }
}
 
Example #12
Source File: HostLayout.java    From Sofia with Apache License 2.0 6 votes vote down vote up
@Override
public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int paddingSize = insets.getSystemWindowInsetBottom();
        int barSize = mNavigationView.getDefaultBarSize();
        paddingSize = paddingSize == barSize ? 0 : paddingSize;
        mContentLayout.setPaddingRelative(0, 0, 0, paddingSize);
        RelativeLayout.LayoutParams layoutParams = (LayoutParams) mContentLayout.getLayoutParams();
        if (paddingSize > 0 && !mNavigationView.isLandscape()) {
            layoutParams.bottomMargin = -barSize;
        } else {
            layoutParams.bottomMargin = 0;
        }
        return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, 0));
    } else {
        return insets;
    }
}
 
Example #13
Source File: ShapeWear.java    From WearViewStub with Apache License 2.0 5 votes vote down vote up
/**
 * Initialized to determine screen shape
 * @param view
 */
private static void initShapeDetection(View view){
    if(!setOnApplyWindowInsetsListenerCalled) {
        setOnApplyWindowInsetsListenerCalled = true;
        view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override
                public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                if (insets.isRound()) {
                    shape = ScreenShape.ROUND;
                    if (screenWidthPX == 320 && screenHeightPX == 290) {
                        shape = ScreenShape.MOTO_ROUND;
                    }
                } else {
                    shape = ScreenShape.RECTANGLE;
                }
                if (onShapeChangeListeners != null && !onShapeChangeListeners.isEmpty()) {
                    synchronized (onShapeChangeListeners) {
                        for (OnShapeChangeListener listener : onShapeChangeListeners)
                            listener.shapeDetected(getShape());
                    }
                }
                return insets;
            }
        });
        view.requestApplyInsets();
    }
}
 
Example #14
Source File: DrawerLayoutContainer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private void dispatchChildInsets(View child, Object insets, int drawerGravity) {
    WindowInsets wi = (WindowInsets) insets;
    if (drawerGravity == Gravity.LEFT) {
        wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
    } else if (drawerGravity == Gravity.RIGHT) {
        wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
    }
    child.dispatchApplyWindowInsets(wi);
}
 
Example #15
Source File: AppDrawerController.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        setPadding(0, insets.getSystemWindowInsetTop(), 0, insets.getSystemWindowInsetBottom());
        return insets;
    }
    return insets;
}
 
Example #16
Source File: SearchBar.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        bottomInset = insets.getSystemWindowInsetBottom();
        setPadding(0, insets.getSystemWindowInsetTop(), 0, 0);
        return insets;
    }
    return insets;
}
 
Example #17
Source File: IntroActivity.java    From intra42 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    introCalendarFragment = IntroCalendarFragment.newInstance();
    addSlide(introCalendarFragment);
    addSlide(IntroTranslationFragment.newInstance());

    SliderPage sliderPage = new SliderPage();
    sliderPage.setTitle(getString(R.string.introduction_cluster_map_contribute_title));
    sliderPage.setDescription(getString(R.string.introduction_cluster_map_contribute_description));
    sliderPage.setImageDrawable(R.drawable.intro_cluster_map_3);
    sliderPage.setBgColor(Color.parseColor("#9C27B0"));
    addSlide(AppIntroFragment.newInstance(sliderPage));

    // OPTIONAL METHODS
    // Override bar/separator color.
    setBarColor(Color.parseColor("#00000000"));
    setSeparatorColor(Color.parseColor("#00000000"));

    // Hide Skip/Done button.
    showSkipButton(false);
    setProgressButtonEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        pager.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                return insets;
            }
        });
    }
}
 
Example #18
Source File: NavigationView.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        int inset = insets.getSystemWindowInsetBottom();
        if (inset != 0) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            layoutParams.height = inset;
            setLayoutParams(layoutParams);
            setVisibility(VISIBLE);
        }
    }
    return insets;
}
 
Example #19
Source File: NestedCoordinatorLayout.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@TargetApi(21)
@Override
public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
    super.dispatchApplyWindowInsets(insets);

    for (int i = 0; i < getChildCount(); i++) {
        // Do NOT allow children to consume these insets
        getChildAt(i).dispatchApplyWindowInsets(insets);
    }

    return insets;
}
 
Example #20
Source File: FitsSystemWindowRelativeLayout.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    Rect windowInsets = new Rect(
            insets.getSystemWindowInsetLeft(),
            insets.getSystemWindowInsetTop(),
            insets.getSystemWindowInsetRight(),
            insets.getSystemWindowInsetBottom()
    );

    fitSystemWindows(windowInsets);
    return insets;
}
 
Example #21
Source File: DrawerLayoutCompatApi21.java    From u2020 with Apache License 2.0 5 votes vote down vote up
public static void dispatchChildInsets(View child, Object insets, int gravity) {
  WindowInsets wi = (WindowInsets) insets;
  if (gravity == Gravity.LEFT) {
    wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
        wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
  } else if (gravity == Gravity.RIGHT) {
    wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
        wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
  }
  child.dispatchApplyWindowInsets(wi);
}
 
Example #22
Source File: DrawerLayoutCompatApi21.java    From u2020 with Apache License 2.0 5 votes vote down vote up
public static void applyMarginInsets(ViewGroup.MarginLayoutParams lp, Object insets,
    int gravity) {
  WindowInsets wi = (WindowInsets) insets;
  if (gravity == Gravity.LEFT) {
    wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
        wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
  } else if (gravity == Gravity.RIGHT) {
    wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
        wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
  }
  lp.leftMargin = wi.getSystemWindowInsetLeft();
  lp.topMargin = wi.getSystemWindowInsetTop();
  lp.rightMargin = wi.getSystemWindowInsetRight();
  lp.bottomMargin = wi.getSystemWindowInsetBottom();
}
 
Example #23
Source File: NotchUtils.java    From MNImageBrowser with GNU General Public License v3.0 5 votes vote down vote up
private static DisplayCutout getDisplayCutout(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        if (view != null) {
            WindowInsets windowInsets = view.getRootWindowInsets();
            if (windowInsets != null) {
                return windowInsets.getDisplayCutout();
            }
        }
    }
    return null;
}
 
Example #24
Source File: MyTapFace.java    From wearable with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplyWindowInsets(WindowInsets insets) {
    super.onApplyWindowInsets(insets);

    // Load resources that have alternate values for round watches.
    Resources resources = MyTapFace.this.getResources();
    boolean isRound = insets.isRound();
    mXOffset = resources.getDimension(isRound
            ? R.dimen.digital_x_offset_round : R.dimen.digital_x_offset);
    float textSize = resources.getDimension(isRound
            ? R.dimen.digital_text_size_round : R.dimen.digital_text_size);

    mTextPaint.setTextSize(textSize);
}
 
Example #25
Source File: StatusBarView.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ViewGroup.LayoutParams lp = getLayoutParams();
        lp.height = insets.getSystemWindowInsetTop();
        setLayoutParams(lp);
    }
    return super.onApplyWindowInsets(insets);
}
 
Example #26
Source File: NotchUtil.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
@TargetApi(28)
private static void getOfficialSafeInsetRect(View view, Rect out) {
    if (view == null) {
        return;
    }
    WindowInsets rootWindowInsets = view.getRootWindowInsets();
    if (rootWindowInsets == null) {
        return;
    }
    DisplayCutout displayCutout = rootWindowInsets.getDisplayCutout();
    if (displayCutout != null) {
        out.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetTop(),
                displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetBottom());
    }
}
 
Example #27
Source File: NotchUtil.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
/**
 * @param view
 * @return false indicates the failure to get the result
 */
@TargetApi(28)
private static boolean attachHasOfficialNotch(View view) {
    WindowInsets windowInsets = view.getRootWindowInsets();
    if (windowInsets != null) {
        DisplayCutout displayCutout = windowInsets.getDisplayCutout();
        sHasNotch = displayCutout != null;
        return true;
    } else {
        // view not attached, do nothing
        return false;
    }
}
 
Example #28
Source File: InsetsFrameLayout.java    From Moment with GNU General Public License v3.0 5 votes vote down vote up
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
    int b = insets.getSystemWindowInsetBottom();
    int r = insets.getSystemWindowInsetRight();

    pictureInfoLayout.setPadding(
            pictureInfoLayout.getPaddingLeft(),
            pictureInfoLayout.getPaddingTop(),
            pictureInfoLayout.getPaddingRight() + r,
            pictureInfoLayout.getPaddingBottom() + b);

    setOnApplyWindowInsetsListener(null);

    return insets.consumeSystemWindowInsets();
}
 
Example #29
Source File: SunsetsWatchFace.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplyWindowInsets(WindowInsets insets) {
    super.onApplyWindowInsets(insets);
    mIsRound = insets.isRound();
    if(mIsRound) {
        mTimePaint.setTextSize(getResources().getDimension(R.dimen.font_size_time_round));
    }else{
        mTimePaint.setTextSize(getResources().getDimension(R.dimen.font_size_time_square));
    }
}
 
Example #30
Source File: ViewCompatLollipop.java    From letv with Apache License 2.0 5 votes vote down vote up
public static WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
    if (!(insets instanceof WindowInsetsCompatApi21)) {
        return insets;
    }
    WindowInsets unwrapped = ((WindowInsetsCompatApi21) insets).unwrap();
    WindowInsets result = v.onApplyWindowInsets(unwrapped);
    if (result != unwrapped) {
        return new WindowInsetsCompatApi21(result);
    }
    return insets;
}