|
|
|
|
@ -4,7 +4,6 @@ import android.content.Context; |
|
|
|
|
import android.content.res.Configuration; |
|
|
|
|
import android.content.res.TypedArray; |
|
|
|
|
import android.graphics.Paint; |
|
|
|
|
import android.graphics.Rect; |
|
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
|
import android.os.Build; |
|
|
|
|
import android.util.DisplayMetrics; |
|
|
|
|
@ -34,20 +33,20 @@ public class ResUtil { |
|
|
|
|
return context.getResources().getDisplayMetrics(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static WindowManager getWindowManager(Context context) { |
|
|
|
|
return (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static int getScreenWidth() { |
|
|
|
|
return getScreenWidth(App.get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static int getScreenWidth(Context context) { |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
|
|
|
|
Rect rect = getWindowManager(context).getCurrentWindowMetrics().getBounds(); |
|
|
|
|
return isLand(context) ? Math.max(rect.width(), rect.height()) : Math.min(rect.width(), rect.height()); |
|
|
|
|
} else { |
|
|
|
|
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
|
|
|
|
if (windowManager == null) { |
|
|
|
|
return getDisplayMetrics(context).widthPixels; |
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
|
|
|
|
return windowManager.getCurrentWindowMetrics().getBounds().width(); |
|
|
|
|
} else { |
|
|
|
|
DisplayMetrics displayMetrics = new DisplayMetrics(); |
|
|
|
|
windowManager.getDefaultDisplay().getMetrics(displayMetrics); |
|
|
|
|
return displayMetrics.widthPixels; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -56,11 +55,15 @@ public class ResUtil { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static int getScreenHeight(Context context) { |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
|
|
|
|
Rect rect = getWindowManager(context).getCurrentWindowMetrics().getBounds(); |
|
|
|
|
return isLand(context) ? Math.min(rect.width(), rect.height()) : Math.max(rect.width(), rect.height()); |
|
|
|
|
} else { |
|
|
|
|
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
|
|
|
|
if (windowManager == null) { |
|
|
|
|
return getDisplayMetrics(context).heightPixels; |
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
|
|
|
|
return windowManager.getCurrentWindowMetrics().getBounds().height(); |
|
|
|
|
} else { |
|
|
|
|
DisplayMetrics displayMetrics = new DisplayMetrics(); |
|
|
|
|
windowManager.getDefaultDisplay().getMetrics(displayMetrics); |
|
|
|
|
return displayMetrics.heightPixels; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|