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
3c94fdd8
Commit
3c94fdd8
authored
Dec 13, 2018
by
fallenstardust
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/fallenstardust/YGOMobile-cn-ko-en
parents
598d385c
9b1dbef3
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
446 additions
and
79 deletions
+446
-79
libcore/src/main/java/cn/garymb/ygomobile/utils/FullScreenUtils.java
.../main/java/cn/garymb/ygomobile/utils/FullScreenUtils.java
+1
-1
mobile/src/main/AndroidManifest.xml
mobile/src/main/AndroidManifest.xml
+3
-1
mobile/src/main/java/cn/garymb/ygomobile/App.java
mobile/src/main/java/cn/garymb/ygomobile/App.java
+5
-0
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
+60
-14
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
+1
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/FileLogActivity.java
...va/cn/garymb/ygomobile/ui/activities/FileLogActivity.java
+49
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
...c/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
+12
-1
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
...c/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
+2
-1
mobile/src/main/java/cn/garymb/ygomobile/utils/CrashHandler.java
...src/main/java/cn/garymb/ygomobile/utils/CrashHandler.java
+141
-0
mobile/src/main/java/cn/garymb/ygomobile/utils/FileLogUtil.java
.../src/main/java/cn/garymb/ygomobile/utils/FileLogUtil.java
+62
-0
mobile/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
...e/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
+85
-61
mobile/src/main/res/layout/file_log_activity.xml
mobile/src/main/res/layout/file_log_activity.xml
+25
-0
No files found.
libcore/src/main/java/cn/garymb/ygomobile/utils/FullScreenUtils.java
View file @
3c94fdd8
...
...
@@ -8,7 +8,7 @@ public class FullScreenUtils {
private
boolean
isFullscreen
;
private
Activity
activity
;
private
static
final
int
windowsFlags
=
Build
.
VERSION
.
SDK_INT
>=
19
?
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
?
(
View
.
SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View
.
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
View
.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
...
...
mobile/src/main/AndroidManifest.xml
View file @
3c94fdd8
...
...
@@ -22,6 +22,7 @@
<uses-permission
android:name=
"android.permission.SYSTEM_ALERT_WINDOW"
/>
<uses-permission
android:name=
"android.permission.REQUEST_INSTALL_PACKAGES"
/>
<uses-permission
android:name=
"android.permission.EXPAND_STATUS_BAR"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<uses-sdk
tools:overrideLibrary=
"com.toptoche.searchablespinnerlibrary"
/>
...
...
@@ -168,6 +169,7 @@
android:label=
"@string/app_name"
/>
<activity
android:name=
"cn.garymb.ygomobile.ui.mycard.mcchat.SplashActivity"
/>
<activity
android:name=
"cn.garymb.ygomobile.ui.activities.FileLogActivity"
/>
<service
android:name=
"cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant"
android:priority=
"1000"
/>
...
...
mobile/src/main/java/cn/garymb/ygomobile/App.java
View file @
3c94fdd8
...
...
@@ -5,6 +5,8 @@ import android.app.Activity;
import
android.content.Intent
;
import
android.support.v7.app.AppCompatDelegate
;
import
cn.garymb.ygomobile.utils.CrashHandler
;
public
class
App
extends
GameApplication
{
@Override
...
...
@@ -12,6 +14,9 @@ public class App extends GameApplication {
super
.
onCreate
();
AppCompatDelegate
.
setCompatVectorFromResourcesEnabled
(
true
);
AppsSettings
.
init
(
this
);
//初始化异常工具类
CrashHandler
crashHandler
=
CrashHandler
.
getInstance
();
crashHandler
.
init
(
getApplicationContext
());
if
(
AppsSettings
.
get
().
isSoundEffect
())
{
initSoundEffectPool
();
setInitSoundEffectPool
(
true
);
...
...
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
View file @
3c94fdd8
...
...
@@ -12,6 +12,7 @@ import org.json.JSONArray;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.IOException
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -19,6 +20,7 @@ import java.util.List;
import
java.util.Locale
;
import
cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus
;
import
cn.garymb.ygomobile.utils.FileLogUtil
;
import
cn.garymb.ygomobile.utils.ScreenUtil
;
import
cn.garymb.ygomobile.utils.SystemUtils
;
...
...
@@ -116,29 +118,66 @@ public class AppsSettings {
mDensity
=
context
.
getResources
().
getDisplayMetrics
().
density
;
mScreenHeight
=
context
.
getResources
().
getDisplayMetrics
().
heightPixels
;
mScreenWidth
=
context
.
getResources
().
getDisplayMetrics
().
widthPixels
;
if
(
isImmerSiveMode
()
&&
context
instanceof
Activity
)
{
if
(
context
instanceof
Activity
)
{
DisplayMetrics
dm
=
SystemUtils
.
getHasVirtualDisplayMetrics
((
Activity
)
context
);
if
(
dm
!=
null
)
{
int
height
=
Math
.
max
(
dm
.
widthPixels
,
dm
.
heightPixels
);
Log
.
i
(
"机横屏height1"
,
"横屏"
+
height
);
// if(dm.widthPixels / dm.heightPixels !=9/16 ) {
// height = height - getStatusBarHeight(context);
// }
if
(
ScreenUtil
.
isNotchInScreen
((
Activity
)
context
)&&
ScreenUtil
.
getNotchHeight
((
Activity
)
context
)!=
0
)
height
=
height
-
ScreenUtil
.
getNotchHeight
((
Activity
)
context
);
if
(
mScreenHeight
==
Math
.
max
(
mScreenHeight
,
mScreenWidth
))
{
try
{
FileLogUtil
.
writeAndTime
(
"原始长"
+
mScreenHeight
);
FileLogUtil
.
writeAndTime
(
"原始宽"
+
mScreenWidth
);
FileLogUtil
.
writeAndTime
(
"界面长"
+
dm
.
heightPixels
);
FileLogUtil
.
writeAndTime
(
"界面宽"
+
dm
.
widthPixels
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
isImmerSiveMode
())
return
;
ScreenUtil
.
findNotchInformation
(((
Activity
)
context
),
new
ScreenUtil
.
FindNotchInformation
()
{
@Override
public
void
onNotchInformation
(
boolean
isNotch
,
int
notchHeight
,
int
phoneType
)
{
int
height
=
Math
.
max
(
dm
.
widthPixels
,
dm
.
heightPixels
);
try
{
FileLogUtil
.
writeAndTime
(
"是否有刘海: "
+
isNotch
);
FileLogUtil
.
writeAndTime
(
"刘海高"
+
notchHeight
);
FileLogUtil
.
writeAndTime
(
"height值: "
+
height
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
isNotch
)
{
height
-=
notchHeight
;
}
try
{
FileLogUtil
.
writeAndTime
(
"处理后height值: "
+
height
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
mScreenHeight
>
mScreenWidth
)
{
mScreenHeight
=
height
;
}
else
{
mScreenWidth
=
height
;
}
try
{
FileLogUtil
.
writeAndTime
(
"转换后长"
+
mScreenHeight
);
FileLogUtil
.
writeAndTime
(
"转换后宽"
+
mScreenWidth
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
});
}
}
Log
.
i
(
"机屏幕高度"
,
""
+
mScreenHeight
);
Log
.
i
(
"机屏幕宽度"
,
""
+
mScreenWidth
);
for
(
int
i:
getNotchSize
(
context
))
Log
.
i
(
"机刘海高度"
,
"刘海高度"
+
i
);
for
(
int
i
:
getNotchSize
(
context
))
Log
.
i
(
"机刘海高度"
,
"刘海高度"
+
i
);
Log
.
i
(
"机状态栏高度"
,
""
+
getStatusBarHeight
(
context
));
Log
.
i
(
"机是否存在刘海"
,
""
+
hasNotchInScreen
(
context
));
Log
.
i
(
"机是否存在刘海"
,
""
+
hasNotchInScreen
(
context
));
}
public
int
getAppVersion
()
{
...
...
@@ -356,6 +395,13 @@ public class AppsSettings {
return
new
File
(
getResourcePath
(),
Constants
.
CORE_IMAGE_PATH
).
getAbsolutePath
();
}
/***
* log文件夹
*/
public
String
getMobileLogPath
()
{
return
new
File
(
getResourcePath
(),
Constants
.
MOBILE_LOG
).
getAbsolutePath
();
}
/***
* 当前数据库文件夹
*/
...
...
mobile/src/main/java/cn/garymb/ygomobile/Constants.java
View file @
3c94fdd8
...
...
@@ -65,6 +65,7 @@ public interface Constants {
String
CORE_EXPANSIONS
=
"expansions"
;
String
CORE_SINGLE_PATH
=
"single"
;
String
CORE_IMAGE_PATH
=
"pics"
;
String
MOBILE_LOG
=
"log"
;
String
CORE_EXPANSIONS_IMAGE_PATH
=
"expansions/pics"
;
String
CORE_IMAGE_FIELD_PATH
=
"field"
;
String
CORE_SCRIPT_PATH
=
"script"
;
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/FileLogActivity.java
0 → 100644
View file @
3c94fdd8
package
cn.garymb.ygomobile.ui.activities
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v7.widget.Toolbar
;
import
android.view.View
;
import
android.widget.TextView
;
import
java.io.IOException
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.utils.FileLogUtil
;
public
class
FileLogActivity
extends
BaseActivity
{
private
TextView
tv_log
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
file_log_activity
);
Toolbar
toolbar
=
findViewById
(
R
.
id
.
toolbar
);
tv_log
=
$
(
R
.
id
.
tv_log
);
setSupportActionBar
(
toolbar
);
enableBackHome
();
setTitle
(
"本地Log输出"
);
read
();
tv_log
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
read
();
}
});
}
private
void
read
()
{
try
{
tv_log
.
setText
(
FileLogUtil
.
read
());
}
catch
(
IOException
e
)
{
tv_log
.
setText
(
"读取日志失败,点击重新读取"
);
}
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
View file @
3c94fdd8
...
...
@@ -28,6 +28,7 @@ import android.view.animation.AnimationUtils;
import
android.view.inputmethod.EditorInfo
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.ListView
;
import
android.widget.Toast
;
...
...
@@ -57,6 +58,7 @@ import cn.garymb.ygomobile.bean.ServerInfo;
import
cn.garymb.ygomobile.bean.events.ServerInfoEvent
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.ui.activities.FileLogActivity
;
import
cn.garymb.ygomobile.ui.activities.WebActivity
;
import
cn.garymb.ygomobile.ui.adapters.ServerListAdapter
;
import
cn.garymb.ygomobile.ui.adapters.SimpleListAdapter
;
...
...
@@ -411,6 +413,7 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
doMenu
(
mMenuIds
.
get
(
index
));
}
});
}
private
void
addMenuButton
(
SparseArray
<
Integer
>
mMenuIds
,
BoomMenuButton
menuButton
,
int
menuId
,
int
stringId
,
int
image
)
{
...
...
@@ -530,11 +533,19 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
}
public
void
StartMycard
()
{
$
(
R
.
id
.
btn_mycard
).
setOnClickListener
((
v
)
->
{
ImageView
iv_mc
=
$
(
R
.
id
.
btn_mycard
);
iv_mc
.
setOnClickListener
((
v
)
->
{
if
(
Constants
.
SHOW_MYCARD
)
{
startActivity
(
new
Intent
(
this
,
MyCardActivity
.
class
));
}
});
iv_mc
.
setOnLongClickListener
(
new
View
.
OnLongClickListener
()
{
@Override
public
boolean
onLongClick
(
View
v
)
{
startActivity
(
new
Intent
(
HomeActivity
.
this
,
FileLogActivity
.
class
));
return
true
;
}
});
}
public
boolean
joinQQGroup
(
String
key
)
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
View file @
3c94fdd8
...
...
@@ -274,7 +274,8 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
Constants
.
CORE_DECK_PATH
,
Constants
.
CORE_REPLAY_PATH
,
Constants
.
FONT_DIRECTORY
,
Constants
.
CORE_IMAGE_PATH
Constants
.
CORE_IMAGE_PATH
,
Constants
.
MOBILE_LOG
};
File
dirFile
=
null
;
for
(
String
dir
:
dirs
)
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/CrashHandler.java
0 → 100644
View file @
3c94fdd8
package
cn.garymb.ygomobile.utils
;
import
android.content.Context
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.os.Looper
;
import
android.util.Log
;
import
android.widget.Toast
;
import
java.io.FileOutputStream
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.io.Writer
;
import
java.lang.reflect.Field
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
cn.garymb.ygomobile.AppsSettings
;
public
class
CrashHandler
implements
Thread
.
UncaughtExceptionHandler
{
public
static
final
String
TAG
=
"YGOMobile-Exception"
;
public
static
final
CrashHandler
INSTANCE
=
new
CrashHandler
();
private
Map
<
String
,
String
>
infos
=
new
HashMap
<
String
,
String
>();
private
DateFormat
formatter
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH.mm.ss"
);
private
Context
context
;
private
Thread
.
UncaughtExceptionHandler
defaultHandler
;
private
CrashHandler
()
{
}
public
static
CrashHandler
getInstance
()
{
return
INSTANCE
;
}
public
void
init
(
Context
context
)
{
this
.
context
=
context
;
defaultHandler
=
Thread
.
getDefaultUncaughtExceptionHandler
();
Thread
.
setDefaultUncaughtExceptionHandler
(
this
);
}
@Override
public
void
uncaughtException
(
Thread
thread
,
Throwable
ex
)
{
if
(!
handleException
(
ex
)
&&
defaultHandler
!=
null
)
{
defaultHandler
.
uncaughtException
(
thread
,
ex
);
}
else
{
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
Log
.
e
(
TAG
,
"error : "
,
e
);
}
System
.
exit
(
1
);
android
.
os
.
Process
.
killProcess
(
android
.
os
.
Process
.
myPid
());
}
}
private
boolean
handleException
(
Throwable
ex
)
{
if
(
ex
==
null
)
{
return
false
;
}
//使用Toast来显示异常信息
new
Thread
()
{
@Override
public
void
run
()
{
Looper
.
prepare
();
Toast
.
makeText
(
context
,
"软件错误退出"
,
Toast
.
LENGTH_LONG
).
show
();
Looper
.
loop
();
}
}.
start
();
collectDeviceInfo
(
context
);
saveCrashInfo2File
(
ex
);
return
true
;
}
public
void
collectDeviceInfo
(
Context
ctx
)
{
try
{
PackageManager
pm
=
ctx
.
getPackageManager
();
PackageInfo
pi
=
pm
.
getPackageInfo
(
ctx
.
getPackageName
(),
PackageManager
.
GET_ACTIVITIES
);
if
(
pi
!=
null
)
{
String
versionName
=
pi
.
versionName
==
null
?
"null"
:
pi
.
versionName
;
String
versionCode
=
pi
.
versionCode
+
""
;
infos
.
put
(
"versionName"
,
versionName
);
infos
.
put
(
"versionCode"
,
versionCode
);
}
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
Log
.
e
(
TAG
,
"an error occured when collect package info"
,
e
);
}
Field
[]
fields
=
Build
.
class
.
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
try
{
field
.
setAccessible
(
true
);
infos
.
put
(
field
.
getName
(),
field
.
get
(
null
).
toString
());
Log
.
d
(
TAG
,
field
.
getName
()
+
" : "
+
field
.
get
(
null
));
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"an error occured when collect crash info"
,
e
);
}
}
}
private
String
saveCrashInfo2File
(
Throwable
ex
)
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
infos
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
value
=
entry
.
getValue
();
sb
.
append
(
key
+
"="
+
value
+
"\n"
);
}
Writer
writer
=
new
StringWriter
();
PrintWriter
printWriter
=
new
PrintWriter
(
writer
);
ex
.
printStackTrace
(
printWriter
);
Throwable
cause
=
ex
.
getCause
();
while
(
cause
!=
null
)
{
cause
.
printStackTrace
(
printWriter
);
cause
=
cause
.
getCause
();
}
printWriter
.
close
();
String
result
=
writer
.
toString
();
sb
.
append
(
result
);
Log
.
e
(
TAG
,
sb
.
toString
());
try
{
// long timestamp = System.currentTimeMillis();
String
time
=
formatter
.
format
(
new
Date
());
String
fileName
=
"【Demo】"
+
time
+
/* timestamp +*/
".log"
;
String
path
=
AppsSettings
.
get
().
getMobileLogPath
()
+
"/"
;
FileOutputStream
fos
=
new
FileOutputStream
(
path
+
fileName
);
fos
.
write
(
sb
.
toString
().
getBytes
());
fos
.
close
();
return
fileName
;
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"an error occured while writing file..."
,
e
);
}
return
null
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/utils/FileLogUtil.java
0 → 100644
View file @
3c94fdd8
package
cn.garymb.ygomobile.utils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
cn.garymb.ygomobile.AppsSettings
;
public
class
FileLogUtil
{
private
static
int
writeNum
=
0
;
//获取配置文件路径
public
static
File
getConfigFile
()
{
return
new
File
(
AppsSettings
.
get
().
getResourcePath
(),
"YGOMobile.log"
);
}
public
static
void
writeAndTime
(
String
message
)
throws
IOException
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"MM-dd HH:mm"
);
// HH:mm:ss
// 获取当前时间
Date
date
=
new
Date
(
System
.
currentTimeMillis
());
write
(
simpleDateFormat
.
format
(
date
)
+
": "
+
message
);
}
public
static
void
write
(
String
message
)
throws
IOException
{
FileWriter
fw
=
null
;
//如果文件存在,则追加内容;如果文件不存在,则创建文件
File
f
=
getConfigFile
();
fw
=
new
FileWriter
(
f
,
true
);
PrintWriter
pw
=
new
PrintWriter
(
fw
);
if
(
writeNum
==
0
)
pw
.
println
();
pw
.
println
(
message
);
writeNum
++;
pw
.
flush
();
fw
.
flush
();
pw
.
close
();
fw
.
close
();
}
public
static
String
read
()
throws
IOException
{
String
encoding
=
"UTF-8"
;
File
file
=
getConfigFile
();
Long
filelength
=
file
.
length
();
byte
[]
filecontent
=
new
byte
[
filelength
.
intValue
()];
FileInputStream
in
=
new
FileInputStream
(
file
);
in
.
read
(
filecontent
);
in
.
close
();
return
new
String
(
filecontent
,
encoding
);
}
}
mobile/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
View file @
3c94fdd8
...
...
@@ -6,8 +6,8 @@ import android.graphics.Rect;
import
android.os.Build
;
import
android.support.annotation.RequiresApi
;
import
android.util.Log
;
import
android.view.Display
;
import
android.view.DisplayCutout
;
import
android.view.View
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
...
...
@@ -21,52 +21,75 @@ public class ScreenUtil {
public
static
final
int
VIVO_FILLET
=
0x00000008
;
//是否有圆角
public
static
final
int
NOTCH_TYPE_PHONE_VIVO
=
0
;
public
static
final
int
NOTCH_TYPE_PHONE_OPPO
=
1
;
public
static
final
int
NOTCH_TYPE_PHONE_HUAWEI
=
2
;
public
static
final
int
NOTCH_TYPE_PHONE_XIAOMI
=
3
;
public
static
final
int
NOTCH_TYPE_PHONE_ANDROID_P
=
4
;
public
static
final
int
NOTCH_TYPE_PHONE_OTHER
=
5
;
public
static
interface
FindNotchInformation
{
void
onNotchInformation
(
boolean
isNotch
,
int
notchHeight
,
int
phoneType
);
}
//是否是刘海屏
public
static
boolean
isNotchInScreen
(
Activity
activity
)
{
if
(!(
isNotchOPPO
(
activity
)
||
isNotchVivo
(
activity
)
||
isNotchHuawei
(
activity
))||
isNotchXiaomi
(
activity
))
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
P
)
return
isNotchP
(
activity
);
else
return
false
;
}
return
true
;
}
//获取刘海高度
public
static
int
getNotchHeight
(
Activity
activity
)
{
int
NotchHeight
=
0
;
if
((
NotchHeight
=
getNotchHeightOPPO
(
activity
))!=
0
)
return
NotchHeight
;
if
((
NotchHeight
=
getNotchHeightVivo
(
activity
))!=
0
)
return
NotchHeight
;
if
((
NotchHeight
=
getNotchHeightHuawei
(
activity
))!=
0
)
return
NotchHeight
;
if
((
NotchHeight
=
getNotchHeightXiaomi
(
activity
))!=
0
)
return
NotchHeight
;
public
static
void
findNotchInformation
(
Activity
activity
,
FindNotchInformation
findNotchInformation
)
{
if
(
isNotchVivo
(
activity
))
{
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightVivo
(
activity
),
NOTCH_TYPE_PHONE_VIVO
);
}
else
if
(
isNotchOPPO
(
activity
))
{
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightOPPO
(
activity
),
NOTCH_TYPE_PHONE_OPPO
);
}
else
if
(
isNotchHuawei
(
activity
))
{
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightHuawei
(
activity
),
NOTCH_TYPE_PHONE_HUAWEI
);
}
else
if
(
isNotchXiaomi
(
activity
))
{
findNotchInformation
.
onNotchInformation
(
true
,
getNotchHeightXiaomi
(
activity
),
NOTCH_TYPE_PHONE_XIAOMI
);
}
else
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
P
)
{
if
((
NotchHeight
=
getNotchHeightP
(
activity
))!=
0
)
return
NotchHeight
;
findNotchPInformation
(
activity
,
findNotchInformation
);
}
else
{
findNotchInformation
.
onNotchInformation
(
false
,
0
,
NOTCH_TYPE_PHONE_OTHER
);
}
}
return
0
;
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
P
)
public
static
int
getNotchHeightP
(
Activity
activity
)
{
DisplayCutout
displayCutout
=
getDisplayCutout
(
activity
);
if
(
displayCutout
==
null
)
return
0
;
return
displayCutout
.
getSafeInsetTop
();
// Log.e("TAG", "安全区域距离屏幕左边的距离 SafeInsetLeft:" + displayCutout.getSafeInsetLeft());
// Log.e("TAG", "安全区域距离屏幕右部的距离 SafeInsetRight:" + displayCutout.getSafeInsetRight());
// Log.e("TAG", "安全区域距离屏幕顶部的距离 SafeInsetTop:" + displayCutout.getSafeInsetTop());
// Log.e("TAG", "安全区域距离屏幕底部的距离 SafeInsetBottom:" + displayCutout.getSafeInsetBottom());
public
static
void
findNotchPInformation
(
Activity
activity
,
final
FindNotchInformation
findNotchPInformation
)
{
final
View
decorView
=
activity
.
getWindow
().
getDecorView
();
decorView
.
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
DisplayCutout
cutout
=
decorView
.
getRootWindowInsets
().
getDisplayCutout
();
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
)
public
static
DisplayCutout
getDisplayCutout
(
Activity
activity
)
{
return
activity
.
getWindow
().
getDecorView
().
getRootWindowInsets
().
getDisplayCutout
();
}
...
...
@@ -74,8 +97,8 @@ public class ScreenUtil {
//小米的状态栏高度会略高于刘海屏的高度,因此可以通过获取状态栏的高度来间接避开刘海屏
public
static
int
getNotchHeightXiaomi
(
Activity
activity
)
{
if
(
isNotchXiaomi
(
activity
))
return
0
;
return
getStatusBarHeight
(
activity
);
return
0
;
}
//获取状态栏高度
...
...
@@ -132,23 +155,24 @@ public class ScreenUtil {
}
}
public
static
boolean
isNotchXiaomi
(
Activity
activity
){
return
getInt
(
"ro.miui.notch"
,
activity
)==
1
;
public
static
boolean
isNotchXiaomi
(
Activity
activity
)
{
return
getInt
(
"ro.miui.notch"
,
activity
)
==
1
;
}
/**
* 小米刘海屏判断.
*
* @return 0 if it is not notch ; return 1 means notch
* @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
;
if
(
ROMUtil
.
isXiaomi
()){
if
(
ROMUtil
.
isXiaomi
())
{
try
{
ClassLoader
classLoader
=
activity
.
getClassLoader
();
@SuppressWarnings
(
"rawtypes"
)
Class
SystemProperties
=
classLoader
.
loadClass
(
"android.os.SystemProperties"
);
//参数类型
//参数类型
@SuppressWarnings
(
"rawtypes"
)
Class
[]
paramTypes
=
new
Class
[
2
];
paramTypes
[
0
]
=
String
.
class
;
...
...
@@ -175,23 +199,23 @@ public class ScreenUtil {
return
result
;
}
//其他安卓p的机子是否有刘海
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
P
)
public
static
boolean
isNotchP
(
Activity
activity
)
{
DisplayCutout
displayCutout
=
getDisplayCutout
(
activity
);
if
(
displayCutout
==
null
)
return
false
;
List
<
Rect
>
rects
=
displayCutout
.
getBoundingRects
();
return
rects
==
null
||
rects
.
size
()
==
0
;
// if (rects == null || rects.size() == 0) {
// Log.e("TAG", "不是刘海屏");
// } else {
// Log.e("TAG", "刘海屏数量:" + rects.size());
// for (Rect rect : rects) {
// Log.e("TAG", "刘海屏区域:" + rect);
// //其他安卓p的机子是否有刘海
// @RequiresApi(api = Build.VERSION_CODES.P)
// public static boolean isNotchP(Activity activity) {
// DisplayCutout displayCutout = getDisplayCutout(activity);
// if (displayCutout == null)
// return false;
// List<Rect> rects = displayCutout.getBoundingRects();
// return rects == null || rects.size() == 0;
//// if (rects == null || rects.size() == 0) {
//// Log.e("TAG", "不是刘海屏");
//// } else {
//// Log.e("TAG", "刘海屏数量:" + rects.size());
//// for (Rect rect : rects) {
//// Log.e("TAG", "刘海屏区域:" + rect);
//// }
//// }
// }
// }
}
//获取oppo刘海高度
...
...
@@ -221,7 +245,7 @@ public class ScreenUtil {
}
//获取华为刘海尺寸:width、height
//int[0]值为刘海宽度 int[1]值为刘海高度
//int[0]值为刘海宽度 int[1]值为刘海高度
public
static
int
[]
getNotchSizeAtHuawei
(
Context
context
)
{
int
[]
ret
=
new
int
[]{
0
,
0
};
try
{
...
...
mobile/src/main/res/layout/file_log_activity.xml
0 → 100644
View file @
3c94fdd8
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<include
layout=
"@layout/content_toolbar"
/>
<android.support.v4.widget.NestedScrollView
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:textStyle=
"bold"
android:id=
"@+id/tv_log"
android:textColor=
"@color/white"
android:textSize=
"18sp"
android:padding=
"15dp"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
\ No newline at end of file
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