Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
d718dbf3
Commit
d718dbf3
authored
Dec 12, 2018
by
feihuaduo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复安卓P判断刘海崩溃的问题
parent
0446b0bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
71 deletions
+110
-71
mobile/src/main/AndroidManifest.xml
mobile/src/main/AndroidManifest.xml
+2
-1
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
+10
-9
mobile/src/main/java/cn/garymb/ygomobile/utils/FileLogUtil.java
.../src/main/java/cn/garymb/ygomobile/utils/FileLogUtil.java
+13
-0
mobile/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
...e/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
+85
-61
No files found.
mobile/src/main/AndroidManifest.xml
View file @
d718dbf3
...
@@ -22,7 +22,8 @@
...
@@ -22,7 +22,8 @@
<uses-permission
android:name=
"android.permission.SYSTEM_ALERT_WINDOW"
/>
<uses-permission
android:name=
"android.permission.SYSTEM_ALERT_WINDOW"
/>
<uses-permission
android:name=
"android.permission.REQUEST_INSTALL_PACKAGES"
/>
<uses-permission
android:name=
"android.permission.REQUEST_INSTALL_PACKAGES"
/>
<uses-permission
android:name=
"android.permission.EXPAND_STATUS_BAR"
/>
<uses-permission
android:name=
"android.permission.EXPAND_STATUS_BAR"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<uses-sdk
<uses-sdk
tools:overrideLibrary=
"com.toptoche.searchablespinnerlibrary"
/>
tools:overrideLibrary=
"com.toptoche.searchablespinnerlibrary"
/>
<application
<application
...
...
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
View file @
d718dbf3
...
@@ -120,12 +120,13 @@ public class AppsSettings {
...
@@ -120,12 +120,13 @@ public class AppsSettings {
DisplayMetrics
dm
=
SystemUtils
.
getHasVirtualDisplayMetrics
((
Activity
)
context
);
DisplayMetrics
dm
=
SystemUtils
.
getHasVirtualDisplayMetrics
((
Activity
)
context
);
if
(
dm
!=
null
)
{
if
(
dm
!=
null
)
{
int
height
=
Math
.
max
(
dm
.
widthPixels
,
dm
.
heightPixels
);
int
height
=
Math
.
max
(
dm
.
widthPixels
,
dm
.
heightPixels
);
Log
.
i
(
"机横屏height1"
,
"横屏"
+
height
);
ScreenUtil
.
findNotchInformation
(((
Activity
)
context
),
new
ScreenUtil
.
FindNotchInformation
()
{
// if(dm.widthPixels / dm.heightPixels !=9/16 ) {
@Override
// height = height - getStatusBarHeight(context);
public
void
onNotchInformation
(
boolean
isNotch
,
int
notchHeight
,
int
phoneType
)
{
// }
if
(
isNotch
)
if
(
ScreenUtil
.
isNotchInScreen
((
Activity
)
context
)&&
ScreenUtil
.
getNotchHeight
((
Activity
)
context
)!=
0
)
mScreenHeight
-=
notchHeight
;
height
=
height
-
ScreenUtil
.
getNotchHeight
((
Activity
)
context
);
}
});
if
(
mScreenHeight
==
Math
.
max
(
mScreenHeight
,
mScreenWidth
))
{
if
(
mScreenHeight
==
Math
.
max
(
mScreenHeight
,
mScreenWidth
))
{
mScreenHeight
=
height
;
mScreenHeight
=
height
;
}
else
{
}
else
{
...
@@ -135,10 +136,10 @@ public class AppsSettings {
...
@@ -135,10 +136,10 @@ public class AppsSettings {
}
}
Log
.
i
(
"机屏幕高度"
,
""
+
mScreenHeight
);
Log
.
i
(
"机屏幕高度"
,
""
+
mScreenHeight
);
Log
.
i
(
"机屏幕宽度"
,
""
+
mScreenWidth
);
Log
.
i
(
"机屏幕宽度"
,
""
+
mScreenWidth
);
for
(
int
i:
getNotchSize
(
context
))
for
(
int
i
:
getNotchSize
(
context
))
Log
.
i
(
"机刘海高度"
,
"刘海高度"
+
i
);
Log
.
i
(
"机刘海高度"
,
"刘海高度"
+
i
);
Log
.
i
(
"机状态栏高度"
,
""
+
getStatusBarHeight
(
context
));
Log
.
i
(
"机状态栏高度"
,
""
+
getStatusBarHeight
(
context
));
Log
.
i
(
"机是否存在刘海"
,
""
+
hasNotchInScreen
(
context
));
Log
.
i
(
"机是否存在刘海"
,
""
+
hasNotchInScreen
(
context
));
}
}
public
int
getAppVersion
()
{
public
int
getAppVersion
()
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/FileLogUtil.java
0 → 100644
View file @
d718dbf3
package
cn.garymb.ygomobile.utils
;
public
class
FileLogUtil
{
public
static
void
write
(
String
messag
){
}
public
static
void
read
(){
}
}
mobile/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
View file @
d718dbf3
...
@@ -6,8 +6,8 @@ import android.graphics.Rect;
...
@@ -6,8 +6,8 @@ import android.graphics.Rect;
import
android.os.Build
;
import
android.os.Build
;
import
android.support.annotation.RequiresApi
;
import
android.support.annotation.RequiresApi
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.Display
;
import
android.view.DisplayCutout
;
import
android.view.DisplayCutout
;
import
android.view.View
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -21,52 +21,75 @@ public class ScreenUtil {
...
@@ -21,52 +21,75 @@ public class ScreenUtil {
public
static
final
int
VIVO_FILLET
=
0x00000008
;
//是否有圆角
public
static
final
int
VIVO_FILLET
=
0x00000008
;
//是否有圆角
//是否是刘海屏
public
static
final
int
NOTCH_TYPE_PHONE_VIVO
=
0
;
public
static
boolean
isNotchInScreen
(
Activity
activity
)
{
public
static
final
int
NOTCH_TYPE_PHONE_OPPO
=
1
;
if
(!(
isNotchOPPO
(
activity
)
||
isNotchVivo
(
activity
)
||
isNotchHuawei
(
activity
))||
isNotchXiaomi
(
activity
))
{
public
static
final
int
NOTCH_TYPE_PHONE_HUAWEI
=
2
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
P
)
public
static
final
int
NOTCH_TYPE_PHONE_XIAOMI
=
3
;
return
isNotchP
(
activity
)
;
public
static
final
int
NOTCH_TYPE_PHONE_ANDROID_P
=
4
;
else
public
static
final
int
NOTCH_TYPE_PHONE_OTHER
=
5
;
return
false
;
}
public
static
interface
FindNotchInformation
{
return
true
;
void
onNotchInformation
(
boolean
isNotch
,
int
notchHeight
,
int
phoneType
)
;
}
}
//获取刘海高度
public
static
int
getNotchHeight
(
Activity
activity
)
{
//是否是刘海屏
int
NotchHeight
=
0
;
public
static
void
findNotchInformation
(
Activity
activity
,
FindNotchInformation
findNotchInformation
)
{
if
((
NotchHeight
=
getNotchHeightOPPO
(
activity
))!=
0
)
return
NotchHeight
;
if
(
isNotchVivo
(
activity
))
{
if
((
NotchHeight
=
getNotchHeightVivo
(
activity
))!=
0
)
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightVivo
(
activity
),
NOTCH_TYPE_PHONE_VIVO
);
return
NotchHeight
;
}
else
if
(
isNotchOPPO
(
activity
))
{
if
((
NotchHeight
=
getNotchHeightHuawei
(
activity
))!=
0
)
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightOPPO
(
activity
),
NOTCH_TYPE_PHONE_OPPO
);
return
NotchHeight
;
}
else
if
(
isNotchHuawei
(
activity
))
{
if
((
NotchHeight
=
getNotchHeightXiaomi
(
activity
))!=
0
)
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightHuawei
(
activity
),
NOTCH_TYPE_PHONE_HUAWEI
);
return
NotchHeight
;
}
else
if
(
isNotchXiaomi
(
activity
))
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
P
)
{
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightXiaomi
(
activity
),
NOTCH_TYPE_PHONE_XIAOMI
);
if
((
NotchHeight
=
getNotchHeightP
(
activity
))!=
0
)
}
else
{
return
NotchHeight
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
P
)
{
findNotchPInformation
(
activity
,
findNotchInformation
);
}
else
{
findNotchInformation
.
onNotchInformation
(
false
,
0
,
NOTCH_TYPE_PHONE_OTHER
);
}
}
}
return
0
;
}
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
P
)
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
P
)
public
static
int
getNotchHeightP
(
Activity
activity
)
{
public
static
void
findNotchPInformation
(
Activity
activity
,
final
FindNotchInformation
findNotchPInformation
)
{
DisplayCutout
displayCutout
=
getDisplayCutout
(
activity
);
if
(
displayCutout
==
null
)
final
View
decorView
=
activity
.
getWindow
().
getDecorView
();
return
0
;
return
displayCutout
.
getSafeInsetTop
();
decorView
.
post
(
new
Runnable
()
{
// Log.e("TAG", "安全区域距离屏幕左边的距离 SafeInsetLeft:" + displayCutout.getSafeInsetLeft());
@Override
// Log.e("TAG", "安全区域距离屏幕右部的距离 SafeInsetRight:" + displayCutout.getSafeInsetRight());
public
void
run
()
{
// Log.e("TAG", "安全区域距离屏幕顶部的距离 SafeInsetTop:" + displayCutout.getSafeInsetTop());
DisplayCutout
cutout
=
decorView
.
getRootWindowInsets
().
getDisplayCutout
();
// Log.e("TAG", "安全区域距离屏幕底部的距离 SafeInsetBottom:" + displayCutout.getSafeInsetBottom());
if
(
cutout
==
null
)
{
findNotchPInformation
.
onNotchInformation
(
false
,
0
,
NOTCH_TYPE_PHONE_ANDROID_P
);
}
else
{
List
<
Rect
>
rects
=
cutout
.
getBoundingRects
();
if
(
rects
==
null
||
rects
.
size
()
==
0
)
{
findNotchPInformation
.
onNotchInformation
(
false
,
0
,
NOTCH_TYPE_PHONE_ANDROID_P
);
}
else
{
findNotchPInformation
.
onNotchInformation
(
true
,
cutout
.
getSafeInsetTop
(),
NOTCH_TYPE_PHONE_ANDROID_P
);
//刘海的数量可以是多个
// for (Rect rect : rects) {
// Log.e(TAG, "cutout.getSafeInsetTop():" + cutout.getSafeInsetTop()
// + ", cutout.getSafeInsetBottom():" + cutout.getSafeInsetBottom()
// + ", cutout.getSafeInsetLeft():" + cutout.getSafeInsetLeft()
// + ", cutout.getSafeInsetRight():" + cutout.getSafeInsetRight()
// + ", cutout.rects:" + rect
// );
// }
}
}
}
});
}
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
P
)
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
P
)
public
static
DisplayCutout
getDisplayCutout
(
Activity
activity
)
{
public
static
DisplayCutout
getDisplayCutout
(
Activity
activity
)
{
return
activity
.
getWindow
().
getDecorView
().
getRootWindowInsets
().
getDisplayCutout
();
return
activity
.
getWindow
().
getDecorView
().
getRootWindowInsets
().
getDisplayCutout
();
}
}
...
@@ -74,8 +97,8 @@ public class ScreenUtil {
...
@@ -74,8 +97,8 @@ public class ScreenUtil {
//小米的状态栏高度会略高于刘海屏的高度,因此可以通过获取状态栏的高度来间接避开刘海屏
//小米的状态栏高度会略高于刘海屏的高度,因此可以通过获取状态栏的高度来间接避开刘海屏
public
static
int
getNotchHeightXiaomi
(
Activity
activity
)
{
public
static
int
getNotchHeightXiaomi
(
Activity
activity
)
{
if
(
isNotchXiaomi
(
activity
))
if
(
isNotchXiaomi
(
activity
))
return
0
;
return
getStatusBarHeight
(
activity
)
;
return
getStatusBarHeight
(
activity
)
;
return
0
;
}
}
//获取状态栏高度
//获取状态栏高度
...
@@ -132,23 +155,24 @@ public class ScreenUtil {
...
@@ -132,23 +155,24 @@ public class ScreenUtil {
}
}
}
}
public
static
boolean
isNotchXiaomi
(
Activity
activity
){
public
static
boolean
isNotchXiaomi
(
Activity
activity
)
{
return
getInt
(
"ro.miui.notch"
,
activity
)==
1
;
return
getInt
(
"ro.miui.notch"
,
activity
)
==
1
;
}
}
/**
/**
* 小米刘海屏判断.
* 小米刘海屏判断.
*
* @return 0 if it is not notch ; return 1 means notch
* @return 0 if it is not notch ; return 1 means notch
* @throws IllegalArgumentException if the key exceeds 32 characters
* @throws IllegalArgumentException if the key exceeds 32 characters
*/
*/
public
static
int
getInt
(
String
key
,
Activity
activity
)
{
public
static
int
getInt
(
String
key
,
Activity
activity
)
{
int
result
=
0
;
int
result
=
0
;
if
(
ROMUtil
.
isXiaomi
()){
if
(
ROMUtil
.
isXiaomi
())
{
try
{
try
{
ClassLoader
classLoader
=
activity
.
getClassLoader
();
ClassLoader
classLoader
=
activity
.
getClassLoader
();
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
Class
SystemProperties
=
classLoader
.
loadClass
(
"android.os.SystemProperties"
);
Class
SystemProperties
=
classLoader
.
loadClass
(
"android.os.SystemProperties"
);
//参数类型
//参数类型
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
Class
[]
paramTypes
=
new
Class
[
2
];
Class
[]
paramTypes
=
new
Class
[
2
];
paramTypes
[
0
]
=
String
.
class
;
paramTypes
[
0
]
=
String
.
class
;
...
@@ -175,23 +199,23 @@ public class ScreenUtil {
...
@@ -175,23 +199,23 @@ public class ScreenUtil {
return
result
;
return
result
;
}
}
//其他安卓p的机子是否有刘海
//
//其他安卓p的机子是否有刘海
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
P
)
//
@RequiresApi(api = Build.VERSION_CODES.P)
public
static
boolean
isNotchP
(
Activity
activity
)
{
//
public static boolean isNotchP(Activity activity) {
DisplayCutout
displayCutout
=
getDisplayCutout
(
activity
);
//
DisplayCutout displayCutout = getDisplayCutout(activity);
if
(
displayCutout
==
null
)
//
if (displayCutout == null)
return
false
;
//
return false;
List
<
Rect
>
rects
=
displayCutout
.
getBoundingRects
();
//
List<Rect> rects = displayCutout.getBoundingRects();
return
rects
==
null
||
rects
.
size
()
==
0
;
//
return rects == null || rects.size() == 0;
// if (rects == null || rects.size() == 0) {
//
//
if (rects == null || rects.size() == 0) {
// Log.e("TAG", "不是刘海屏");
//
//
Log.e("TAG", "不是刘海屏");
// } else {
//
//
} else {
// Log.e("TAG", "刘海屏数量:" + rects.size());
//
//
Log.e("TAG", "刘海屏数量:" + rects.size());
// for (Rect rect : rects) {
//
//
for (Rect rect : rects) {
// Log.e("TAG", "刘海屏区域:" + rect);
//
//
Log.e("TAG", "刘海屏区域:" + rect);
// }
//
//
}
// }
//
//
}
}
//
}
//获取oppo刘海高度
//获取oppo刘海高度
...
@@ -221,7 +245,7 @@ public class ScreenUtil {
...
@@ -221,7 +245,7 @@ public class ScreenUtil {
}
}
//获取华为刘海尺寸:width、height
//获取华为刘海尺寸:width、height
//int[0]值为刘海宽度 int[1]值为刘海高度
//int[0]值为刘海宽度 int[1]值为刘海高度
public
static
int
[]
getNotchSizeAtHuawei
(
Context
context
)
{
public
static
int
[]
getNotchSizeAtHuawei
(
Context
context
)
{
int
[]
ret
=
new
int
[]{
0
,
0
};
int
[]
ret
=
new
int
[]{
0
,
0
};
try
{
try
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment