Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile-Cn-Ko-En
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-Cn-Ko-En
Commits
f9f9ba08
Commit
f9f9ba08
authored
Dec 15, 2018
by
feihuaduo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复ygo界面Android p刘海检测不到的问题
parent
e5779772
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
164 additions
and
89 deletions
+164
-89
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
.../src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
+1
-0
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
+43
-89
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/DebugActivity.java
...java/cn/garymb/ygomobile/ui/activities/DebugActivity.java
+32
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/adapters/DebugListRecyclerAdapter.java
...arymb/ygomobile/ui/adapters/DebugListRecyclerAdapter.java
+34
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
...c/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
+22
-0
mobile/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
...e/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
+17
-0
mobile/src/main/res/layout/debug_activity.xml
mobile/src/main/res/layout/debug_activity.xml
+15
-0
No files found.
libcore/src/main/java/cn/garymb/ygomobile/YGOMobileActivity.java
View file @
f9f9ba08
...
...
@@ -201,6 +201,7 @@ public class YGOMobileActivity extends NativeActivity implements
}
private
void
fullscreen
()
{
//如果是沉浸模式
if
(
app
().
isImmerSiveMode
())
{
mFullScreenUtils
.
fullscreen
();
...
...
mobile/src/main/java/cn/garymb/ygomobile/AppsSettings.java
View file @
f9f9ba08
...
...
@@ -44,11 +44,14 @@ public class AppsSettings {
private
Context
context
;
private
PreferenceFragmentPlus
.
SharedPreferencesPlus
mSharedPreferences
;
private
float
mScreenHeight
,
mScreenWidth
,
mDensity
;
public
static
int
notchHeight
;
private
AppsSettings
(
Context
context
)
{
this
.
context
=
context
;
mSharedPreferences
=
PreferenceFragmentPlus
.
SharedPreferencesPlus
.
create
(
context
,
context
.
getPackageName
()
+
".settings"
);
mSharedPreferences
.
setAutoSave
(
true
);
Log
.
e
(
"YGOMobile"
,
"初始化AppsSettings"
);
update
(
context
);
}
...
...
@@ -62,52 +65,21 @@ public class AppsSettings {
return
sAppsSettings
;
}
//获取刘海屏的参数
public
static
int
[]
getNotchSize
(
Context
context
)
{
int
[]
notchSize
=
new
int
[]{
0
,
0
};
try
{
ClassLoader
cl
=
context
.
getClassLoader
();
Class
HwNotchSizeUtil
=
cl
.
loadClass
(
"com.huawei.android.util.HwNotchSizeUtil"
);
Method
get
=
HwNotchSizeUtil
.
getMethod
(
"getNotchSize"
);
notchSize
=
(
int
[])
get
.
invoke
(
HwNotchSizeUtil
);
}
catch
(
ClassNotFoundException
e
)
{
Log
.
e
(
"test"
,
"getNotchSize ClassNotFoundException"
);
}
catch
(
NoSuchMethodException
e
)
{
Log
.
e
(
"test"
,
"getNotchSize NoSuchMethodException"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
"test"
,
"getNotchSize Exception"
);
}
finally
{
return
notchSize
;
}
//获取刘海高度
public
int
getNotchHeight
()
{
return
notchHeight
;
}
//检测是否存在刘海屏
public
static
boolean
hasNotchInScreen
(
Context
context
)
{
boolean
ret
=
false
;
try
{
ClassLoader
cl
=
context
.
getClassLoader
();
Class
HwNotchSizeUtil
=
cl
.
loadClass
(
"com.huawei.android.util.HwNotchSizeUtil"
);
Method
get
=
HwNotchSizeUtil
.
getMethod
(
"hasNotchInScreen"
);
ret
=
(
boolean
)
get
.
invoke
(
HwNotchSizeUtil
);
}
catch
(
ClassNotFoundException
e
)
{
Log
.
e
(
"test"
,
"hasNotchInScreen ClassNotFoundException"
);
}
catch
(
NoSuchMethodException
e
)
{
Log
.
e
(
"test"
,
"hasNotchInScreen NoSuchMethodException"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
"test"
,
"hasNotchInScreen Exception"
);
}
finally
{
return
ret
;
}
}
//设置刘海高度
public
void
setNotchHeight
(
int
notchHeight
)
{
//获取系统状态栏高度
public
static
int
getStatusBarHeight
(
Context
context
)
{
int
StatusBarHeight
=
0
;
int
resourceId
=
context
.
getResources
().
getIdentifier
(
"status_bar_height"
,
"dimen"
,
"android"
);
if
(
resourceId
>
0
)
{
StatusBarHeight
=
context
.
getResources
().
getDimensionPixelSize
(
resourceId
);
this
.
notchHeight
=
notchHeight
;
try
{
FileLogUtil
.
writeAndTime
(
"设置刘海高度"
+
notchHeight
)
;
FileLogUtil
.
writeAndTime
(
"当前文件设置刘海高度"
+
this
.
notchHeight
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
(
);
}
return
StatusBarHeight
;
}
public
File
getSystemConfig
()
{
...
...
@@ -119,65 +91,47 @@ public class AppsSettings {
mScreenHeight
=
context
.
getResources
().
getDisplayMetrics
().
heightPixels
;
mScreenWidth
=
context
.
getResources
().
getDisplayMetrics
().
widthPixels
;
if
(
context
instanceof
Activity
)
{
if
(
isImmerSiveMode
()
&&
context
instanceof
Activity
)
{
DisplayMetrics
dm
=
SystemUtils
.
getHasVirtualDisplayMetrics
((
Activity
)
context
);
if
(
dm
!=
null
)
{
int
height
=
Math
.
max
(
dm
.
widthPixels
,
dm
.
heightPixels
);
try
{
FileLogUtil
.
writeAndTime
(
"原始长"
+
mScreenHeight
);
FileLogUtil
.
writeAndTime
(
"原始宽"
+
mScreenWidth
);
FileLogUtil
.
writeAndTime
(
"界面长"
+
dm
.
heightPixels
);
FileLogUtil
.
writeAndTime
(
"界面宽"
+
dm
.
widthPixels
);
FileLogUtil
.
writeAndTime
(
"是否沉浸: "
+
isImmerSiveMode
());
FileLogUtil
.
writeAndTime
(
"原始长: "
+
mScreenHeight
);
FileLogUtil
.
writeAndTime
(
"原始宽: "
+
mScreenWidth
);
FileLogUtil
.
writeAndTime
(
"界面长: "
+
dm
.
heightPixels
);
FileLogUtil
.
writeAndTime
(
"界面宽: "
+
dm
.
widthPixels
);
FileLogUtil
.
writeAndTime
(
"刘海长: "
+
notchHeight
);
FileLogUtil
.
writeAndTime
(
"get刘海长: "
+
getNotchHeight
());
}
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
();
}
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
);
Log
.
i
(
"机状态栏高度"
,
""
+
getStatusBarHeight
(
context
));
Log
.
i
(
"机是否存在刘海"
,
""
+
hasNotchInScreen
(
context
));
}
public
int
getAppVersion
()
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/DebugActivity.java
0 → 100644
View file @
f9f9ba08
package
cn.garymb.ygomobile.ui.activities
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.Toolbar
;
import
cn.garymb.ygomobile.lite.R
;
public
class
DebugActivity
extends
BaseActivity
{
private
RecyclerView
rv_list
;
private
Toolbar
toolbar
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
debug_activity
);
initView
();
}
private
void
initView
()
{
rv_list
=
$
(
R
.
id
.
rv_list
);
toolbar
=
$
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
enableBackHome
();
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/adapters/DebugListRecyclerAdapter.java
0 → 100644
View file @
f9f9ba08
package
cn.garymb.ygomobile.ui.adapters
;
import
android.support.annotation.NonNull
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.View
;
import
android.view.ViewGroup
;
public
class
DebugListRecyclerAdapter
extends
RecyclerView
.
Adapter
<
DebugListRecyclerAdapter
.
ViewHolder
>
{
@NonNull
@Override
public
ViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
return
null
;
}
@Override
public
void
onBindViewHolder
(
@NonNull
ViewHolder
holder
,
int
position
)
{
}
@Override
public
int
getItemCount
()
{
return
0
;
}
class
ViewHolder
extends
RecyclerView
.
ViewHolder
{
public
ViewHolder
(
View
itemView
)
{
super
(
itemView
);
}
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
View file @
f9f9ba08
package
cn.garymb.ygomobile.ui.home
;
import
android.app.Activity
;
import
android.app.NotificationManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
...
...
@@ -47,6 +48,7 @@ import org.greenrobot.eventbus.EventBus;
import
org.greenrobot.eventbus.Subscribe
;
import
org.greenrobot.eventbus.ThreadMode
;
import
java.io.IOException
;
import
java.util.List
;
import
cn.garymb.ygodata.YGOGameOptions
;
...
...
@@ -70,6 +72,8 @@ import cn.garymb.ygomobile.ui.plus.DialogPlus;
import
cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant
;
import
cn.garymb.ygomobile.ui.preference.SettingsActivity
;
import
cn.garymb.ygomobile.utils.AlipayPayUtils
;
import
cn.garymb.ygomobile.utils.FileLogUtil
;
import
cn.garymb.ygomobile.utils.ScreenUtil
;
public
abstract
class
HomeActivity
extends
BaseActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
{
protected
SwipeMenuRecyclerView
mServerList
;
...
...
@@ -130,6 +134,24 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
//萌卡
StartMycard
();
checkNotch
();
}
//检查是否有刘海
private
void
checkNotch
()
{
ScreenUtil
.
findNotchInformation
(
HomeActivity
.
this
,
new
ScreenUtil
.
FindNotchInformation
()
{
@Override
public
void
onNotchInformation
(
boolean
isNotch
,
int
notchHeight
,
int
phoneType
)
{
try
{
FileLogUtil
.
writeAndTime
(
"检查刘海"
+
isNotch
+
" "
+
notchHeight
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// AppsSettings.get().setNotchHeight(notchHeight);
AppsSettings
.
notchHeight
=
notchHeight
;
}
});
}
@Override
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/ScreenUtil.java
View file @
f9f9ba08
...
...
@@ -9,6 +9,7 @@ import android.util.Log;
import
android.view.DisplayCutout
;
import
android.view.View
;
import
java.io.IOException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.List
;
...
...
@@ -64,12 +65,28 @@ public class ScreenUtil {
public
void
run
()
{
DisplayCutout
cutout
=
decorView
.
getRootWindowInsets
().
getDisplayCutout
();
if
(
cutout
==
null
)
{
try
{
FileLogUtil
.
writeAndTime
(
"Android P刘海: cotout为空"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
findNotchPInformation
.
onNotchInformation
(
false
,
0
,
NOTCH_TYPE_PHONE_ANDROID_P
);
}
else
{
List
<
Rect
>
rects
=
cutout
.
getBoundingRects
();
if
(
rects
==
null
||
rects
.
size
()
==
0
)
{
try
{
FileLogUtil
.
writeAndTime
(
"Android P刘海: rects:"
+(
rects
==
null
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
findNotchPInformation
.
onNotchInformation
(
false
,
0
,
NOTCH_TYPE_PHONE_ANDROID_P
);
}
else
{
try
{
FileLogUtil
.
writeAndTime
(
"Android P刘海: 刘海存在,个数为"
+
rects
.
size
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
findNotchPInformation
.
onNotchInformation
(
true
,
cutout
.
getSafeInsetTop
(),
NOTCH_TYPE_PHONE_ANDROID_P
);
//刘海的数量可以是多个
// for (Rect rect : rects) {
...
...
mobile/src/main/res/layout/debug_activity.xml
0 → 100644
View file @
f9f9ba08
<?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.v7.widget.RecyclerView
android:id=
"@+id/rv_list"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</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