|
|
|
|
@ -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)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|