91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 6KB
    文件類型: .java
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-09
  • 語(yǔ)言: Java
  • 標(biāo)簽: 劉海屏??適配??

資源簡(jiǎn)介

小米華為OPPO/VIVO手機(jī)劉海屏適配
判斷是否有劉海屏,根據(jù)不同的上述4類機(jī)型,進(jìn)行適配。
代碼依據(jù)于各家的開(kāi)發(fā)適配文檔,未來(lái)可能有更新。

資源截圖

代碼片段和文件信息



import?android.content.Context;
import?android.util.Log;
import?android.view.Window;
import?android.view.WindowManager;

import?java.lang.reflect.Constructor;
import?java.lang.reflect.Method;

public?class?Utils?{

????/**
?????*?是否劉海
?????*
?????*?@param?context
?????*?@return
?????*/
????public?static?boolean?hasNotchInScreen(Context?context)?{
????????boolean?ret?=?false;
????????try?{
????????????ClassLoader?cl?=?context.getClassLoader();
????????????Class?HwNotchSizeUtil?=?cl.loadClass(“com.huawei.android.util.HwNotchSizeUtil“);
????????????Method?get?=?HwNotchSizeUtil.getMethod(“hasNotchInScreen“);
????????????ret?=?(boolean)?get.invoke(HwNotchSizeUtil);
????????}?catch?(ClassNotFoundException?e)?{
????????????Log.e(“test“?“hasNotchInScreen?ClassNotFoundException“);
????????}?catch?(NoSuchMethodException?e)?{
????????????Log.e(“test“?“hasNotchInScreen?NoSuchMethodException“);
????????}?catch?(Exception?e)?{
????????????Log.e(“test“?“hasNotchInScreen?Exception“);
????????}
????????return?ret;
????}

????/**
?????*?獲取劉海尺寸:width、heightint[0]值為劉海寬度?int[1]值為劉海高度。
?????*
?????*?@param?context
?????*?@return
?????*/
????public?static?int[]?getNotchSize(Context?context)?{
????????int[]?ret?=?new?int[]{0?0};
????????try?{
????????????ClassLoader?cl?=?context.getClassLoader();
????????????Class?HwNotchSizeUtil?=?cl.loadClass(“com.huawei.android.util.HwNotchSizeUtil“);
????????????Method?get?=?HwNotchSizeUtil.getMethod(“getNotchSize“);
????????????ret?=?(int[])?get.invoke(HwNotchSizeUtil);
????????}?catch?(ClassNotFoundException?e)?{
????????????Log.e(“test“?“getNotchSize?ClassNotFoundException“);
????????}?catch?(NoSuchMethodException?e)?{
????????????Log.e(“test“?“getNotchSize?NoSuchMethodException“);
????????}?catch?(Exception?e)?{
????????????Log.e(“test“?“getNotchSize?Exception“);
????????}
????????return?ret;
????}

????/**
?????*?設(shè)置使用劉海區(qū)域
?????*
?????*?@param?window
?????*/
????public?static?void?setFullScreenWindowLayoutInDisplayCutout(Window?window)?{
????????if?(window?==?null)?{
????????????return;
????????}

????????try?{
????????????WindowManager.LayoutParams?layoutParams?=?window.getAttributes();
????????????Class?layoutParamsExCls?=?Class.forName(“com.huawei.android.view.LayoutParamsEx“);
????????????Constructor?con?=?layoutParamsExCls.getConstructor(WindowManager.LayoutParams.class);
????????????object?layoutParamsExObj?=?con.newInstance(layoutParams);
????????????Method?method?=?layoutParamsExCls.getMethod(“addHwFlags“?int.class);
????????????method.invoke(layoutParamsExObj?FLAG_NOTCH_SUPPORT);
????????}?catch?(Exception?e)?{
????????????Log.e(“test“?“other?Exception“);
????????}

評(píng)論

共有 條評(píng)論