From c5fd9ce7ece04548819a0e9fe7ef13a67633b3e8 Mon Sep 17 00:00:00 2001 From: watson1982 <112817572+watson1982@users.noreply.github.com> Date: Mon, 21 Aug 2023 20:42:29 +0800 Subject: [PATCH] ScreenUtils.java --- .../github/tvbox/osc/util/ScreenUtils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/main/java/com/github/tvbox/osc/util/ScreenUtils.java b/app/src/main/java/com/github/tvbox/osc/util/ScreenUtils.java index b8be2dca..ad9b2427 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/ScreenUtils.java +++ b/app/src/main/java/com/github/tvbox/osc/util/ScreenUtils.java @@ -1,6 +1,12 @@ package com.github.tvbox.osc.util; +import static android.content.Context.UI_MODE_SERVICE; + import android.app.Activity; +import android.app.UiModeManager; +import android.content.Context; +import android.content.res.Configuration; +import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.view.WindowManager; @@ -16,4 +22,19 @@ public class ScreenUtils { return screenInches; } + private static boolean checkScreenLayoutIsTv(Context context) { + return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) > Configuration.SCREENLAYOUT_SIZE_LARGE; + } + + private static boolean checkIsPhone(Context context) { + TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + return telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; + } + + public static boolean isTv(Context context) { + UiModeManager uiModeManager = (UiModeManager) context.getSystemService(UI_MODE_SERVICE); + return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION || (checkScreenLayoutIsTv(context) && !checkIsPhone(context)); + } + + }