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
ccee9180
Commit
ccee9180
authored
Jun 02, 2022
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
009999cc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
250 additions
and
141 deletions
+250
-141
mobile/src/main/java/cn/garymb/ygomobile/base/BaseFragemnt.java
.../src/main/java/cn/garymb/ygomobile/base/BaseFragemnt.java
+172
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/BaseActivity.java
.../java/cn/garymb/ygomobile/ui/activities/BaseActivity.java
+0
-141
mobile/src/main/java/cn/garymb/ygomobile/utils/ScaleUtils.java
...e/src/main/java/cn/garymb/ygomobile/utils/ScaleUtils.java
+78
-0
No files found.
mobile/src/main/java/cn/garymb/ygomobile/base/BaseFragemnt.java
0 → 100644
View file @
ccee9180
package
cn.garymb.ygomobile.base
;
import
android.content.pm.ActivityInfo
;
import
android.content.res.Configuration
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.Fragment
;
import
cn.garymb.ygomobile.utils.ScaleUtils
;
/**
* Create By feihua On 2020/4/7
*/
public
abstract
class
BaseFragemnt
extends
Fragment
{
// void onVisible(boolean isVisible);
private
static
final
String
TAG
=
BaseFragemnt
.
class
.
getSimpleName
();
protected
boolean
isHorizontal
=
false
;
private
boolean
isPrepared
;
private
boolean
isFirstResume
=
true
;
/**
* 第一次onResume中的调用onUserVisible避免操作与onFirstUserVisible操作重复
*/
private
boolean
isFirstVisible
=
true
;
private
boolean
isFirstInvisible
=
true
;
@Override
public
void
onConfigurationChanged
(
@NonNull
Configuration
newConfig
)
{
super
.
onConfigurationChanged
(
newConfig
);
// 获取到屏幕的方向
int
orientation
=
newConfig
.
orientation
;
switch
(
orientation
)
{
// 横屏
case
Configuration
.
ORIENTATION_LANDSCAPE
:
isHorizontal
=
true
;
break
;
// 竖屏
case
Configuration
.
ORIENTATION_PORTRAIT
:
isHorizontal
=
false
;
break
;
}
}
@Nullable
@Override
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
if
(
savedInstanceState
!=
null
)
{
//竖屏
if
(
ScaleUtils
.
ScreenOrient
(
getActivity
())
==
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
)
{
// setContentView(R.layout.ending_activity);
isHorizontal
=
false
;
}
else
if
(
ScaleUtils
.
ScreenOrient
(
getActivity
())
==
ActivityInfo
.
SCREEN_ORIENTATION_PORTRAIT
)
{
//横屏
// setContentView(R.layout.ending_horizontal_activity);
isHorizontal
=
true
;
}
}
else
{
if
(
ScaleUtils
.
isScreenOriatationPortrait
())
{
// setContentView(R.layout.ending_activity);
isHorizontal
=
false
;
}
else
{
// setContentView(R.layout.ending_horizontal_activity);
isHorizontal
=
true
;
}
}
return
super
.
onCreateView
(
inflater
,
container
,
savedInstanceState
);
}
@Override
public
void
onActivityCreated
(
Bundle
savedInstanceState
)
{
super
.
onActivityCreated
(
savedInstanceState
);
initPrepare
();
Log
.
e
(
"BaseFragment"
,
"创建"
);
if
(
savedInstanceState
!=
null
)
{
//竖屏
if
(
ScaleUtils
.
ScreenOrient
(
getActivity
())
==
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
)
{
// setContentView(R.layout.ending_activity);
isHorizontal
=
false
;
}
else
if
(
ScaleUtils
.
ScreenOrient
(
getActivity
())
==
ActivityInfo
.
SCREEN_ORIENTATION_PORTRAIT
)
{
//横屏
// setContentView(R.layout.ending_horizontal_activity);
isHorizontal
=
true
;
}
}
else
{
if
(
ScaleUtils
.
isScreenOriatationPortrait
())
{
// setContentView(R.layout.ending_activity);
isHorizontal
=
false
;
}
else
{
// setContentView(R.layout.ending_horizontal_activity);
isHorizontal
=
true
;
}
}
}
@Override
public
void
onResume
()
{
super
.
onResume
();
if
(
isFirstResume
)
{
isFirstResume
=
false
;
return
;
}
if
(
getUserVisibleHint
())
{
onUserVisible
();
}
}
@Override
public
void
onPause
()
{
super
.
onPause
();
if
(
getUserVisibleHint
())
{
onUserInvisible
();
}
}
@Override
public
void
setUserVisibleHint
(
boolean
isVisibleToUser
)
{
super
.
setUserVisibleHint
(
isVisibleToUser
);
if
(
isVisibleToUser
)
{
if
(
isFirstVisible
)
{
isFirstVisible
=
false
;
initPrepare
();
}
else
{
onUserVisible
();
}
}
else
{
if
(
isFirstInvisible
)
{
isFirstInvisible
=
false
;
onFirstUserInvisible
();
}
else
{
onUserInvisible
();
}
}
}
public
synchronized
void
initPrepare
()
{
if
(
isPrepared
)
{
onFirstUserVisible
();
}
else
{
isPrepared
=
true
;
}
}
/**
* 第一次fragment可见(进行初始化工作)
*/
public
abstract
void
onFirstUserVisible
();
/**
* fragment可见(切换回来或者onResume)
*/
public
abstract
void
onUserVisible
();
/**
* 第一次fragment不可见(不建议在此处理事件)
*/
public
abstract
void
onFirstUserInvisible
();
/**
* fragment不可见(切换掉或者onPause)
*/
public
abstract
void
onUserInvisible
();
}
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/BaseActivity.java
View file @
ccee9180
...
@@ -107,127 +107,6 @@ public class BaseActivity extends AppCompatActivity {
...
@@ -107,127 +107,6 @@ public class BaseActivity extends AppCompatActivity {
@Override
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
/*
M 是 6.0,6.0修改了新的api,并且就已经支持修改window的刷新率了。
但是6.0那会儿,也没什么手机支持高刷新率吧,所以也没什么人注意它。
我更倾向于直接判断 O,也就是 Android 8.0,我觉得这个时候支持高刷新率的手机已经开始了。
*/
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// // 获取系统window支持的模式
//// val = window.windowManager.defaultDisplay.supportedModes;
// Display display = getWindowManager().getDefaultDisplay();
//
// Surface surface = new Surface(new SurfaceTexture(10));
// TextView textVie
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// SurfaceHolder surfaceHolder=new SurfaceHolder() {
// @Override
// public void addCallback(Callback callback) {
//
// }
//
// @Override
// public void removeCallback(Callback callback) {
//
// }
//
// @Override
// public boolean isCreating() {
// return false;
// }
//
// @Override
// public void setType(int type) {
//
// }
//
// @Override
// public void setFixedSize(int width, int height) {
//
// }
//
// @Override
// public void setSizeFromLayout() {
//
// }
//
// @Override
// public void setFormat(int format) {
//
// }
//
// @Override
// public void setKeepScreenOn(boolean screenOn) {
//
// }
//
// @Override
// public Canvas lockCanvas() {
// return null;
// }
//
// @Override
// public Canvas lockCanvas(Rect dirty) {
// return null;
// }
//
// @Override
// public void unlockCanvasAndPost(Canvas canvas) {
//
// }
//
// @Override
// public Rect getSurfaceFrame() {
// return null;
// }
//
// @Override
// public Surface getSurface() {
// return null;
// }
// }
// getWindow().getDecorView().getd.setFrameRate(90, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT);
// } else {
//
// Display.Mode[] modes = display.getSupportedModes();
// Log.e("BaseActivity", "个数" + modes.length);
// try {
// FileLogUtil.writeAndTime("刷新率个数" + modes.length);
//
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// Display.Mode maxMode = null;
// for (Display.Mode mode : modes) {
// if (maxMode == null) {
// maxMode = mode;
// } else {
// if (mode.getRefreshRate() > maxMode.getRefreshRate())
// maxMode = mode;
// }
// try {
// FileLogUtil.writeAndTime("" + "状态信息" + mode.getModeId() + " " + mode.getRefreshRate() + " " + mode.getPhysicalWidth() + " " + mode.getPhysicalHeight());
// } catch (IOException e) {
// e.printStackTrace();
// }
// Log.e("BaseActivity", "状态信息" + mode.getModeId() + " " + mode.getRefreshRate() + " " + mode.getPhysicalWidth() + " " + mode.getPhysicalHeight());
// }
//// if (maxMode!=null) {
//// Log.e("BaseACtivity","设置刷新率"+maxMode.getRefreshRate());
// try {
// FileLogUtil.writeAndTime("设置刷新率" + modes[0].getRefreshRate());
// } catch (IOException e) {
// e.printStackTrace();
// }
// WindowManager.LayoutParams att = getWindow().getAttributes();
// att.preferredDisplayModeId = modes[0].getModeId();
// getWindow().setAttributes(att);
//
// }
// }
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
}
}
...
@@ -301,26 +180,6 @@ public class BaseActivity extends AppCompatActivity {
...
@@ -301,26 +180,6 @@ public class BaseActivity extends AppCompatActivity {
return
rect
.
top
;
return
rect
.
top
;
}
}
// @Override
// public void onWindowFocusChanged(boolean hasFocus) {
// if (hasFocus) {
// hideSystemNavBar();
// }
// super.onWindowFocusChanged(hasFocus);
// }
protected
void
hideSystemNavBar
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
19
)
{
// final WindowManager.LayoutParams params = getWindow().getAttributes();
// params.systemUiVisibility |=
// View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
// View.SYSTEM_UI_FLAG_IMMERSIVE |
// View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
// View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
// getWindow().setAttributes(params);
}
}
public
void
setActionBarTitle
(
String
title
)
{
public
void
setActionBarTitle
(
String
title
)
{
if
(
TextUtils
.
isEmpty
(
title
))
{
if
(
TextUtils
.
isEmpty
(
title
))
{
return
;
return
;
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/ScaleUtils.java
0 → 100644
View file @
ccee9180
package
cn.garymb.ygomobile.utils
;
import
android.app.Activity
;
import
android.content.pm.ActivityInfo
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.util.TypedValue
;
import
android.view.Display
;
import
android.view.WindowManager
;
import
cn.garymb.ygomobile.App
;
/**
* Create By feihua On 2022/1/16
*/
public
class
ScaleUtils
{
//dp转px
public
static
int
dp2px
(
float
dpValue
)
{
final
float
scale
=
App
.
get
().
getResources
().
getDisplayMetrics
().
density
;
return
(
int
)
(
dpValue
*
scale
+
0.5f
);
}
//px转dp
public
static
int
px2dp
(
int
pxValue
)
{
return
((
int
)
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_DIP
,
pxValue
,
App
.
get
().
getResources
().
getDisplayMetrics
()));
}
/**
* sp转换成px
*/
public
static
int
sp2px
(
float
spValue
)
{
float
fontScale
=
App
.
get
().
getResources
().
getDisplayMetrics
().
scaledDensity
;
return
(
int
)
(
spValue
*
fontScale
+
0.5f
);
}
/**
* px转换成sp
*/
public
static
int
px2sp
(
float
pxValue
)
{
float
fontScale
=
App
.
get
().
getResources
().
getDisplayMetrics
().
scaledDensity
;
return
(
int
)
(
pxValue
/
fontScale
+
0.5f
);
}
public
static
int
getStatusBarHeight
()
{
Resources
resources
=
App
.
get
().
getResources
();
int
resourceId
=
resources
.
getIdentifier
(
"status_bar_height"
,
"dimen"
,
"android"
);
return
resources
.
getDimensionPixelSize
(
resourceId
);
}
public
static
int
[]
getScreenInfo
(
Activity
context
)
{
int
screenWidth
=
context
.
getWindowManager
().
getDefaultDisplay
().
getWidth
();
// 屏幕宽(像素,如:480px)
int
screenHeight
=
context
.
getWindowManager
().
getDefaultDisplay
().
getHeight
();
// 屏幕高(像素,如:800p)
return
new
int
[]{
screenHeight
,
screenWidth
};
}
/**
* 返回当前屏幕是否为竖屏。
*
* @return 当且仅当当前屏幕为竖屏时返回true, 否则返回false。
*/
public
static
boolean
isScreenOriatationPortrait
()
{
return
App
.
get
().
getResources
().
getConfiguration
().
orientation
==
Configuration
.
ORIENTATION_PORTRAIT
;
}
//判定当前的屏幕是竖屏还是横屏
public
static
int
ScreenOrient
(
Activity
activity
)
{
int
orient
=
activity
.
getRequestedOrientation
();
if
(
orient
!=
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
&&
orient
!=
ActivityInfo
.
SCREEN_ORIENTATION_PORTRAIT
)
{
WindowManager
windowManager
=
activity
.
getWindowManager
();
Display
display
=
windowManager
.
getDefaultDisplay
();
int
screenWidth
=
display
.
getWidth
();
int
screenHeight
=
display
.
getHeight
();
orient
=
screenWidth
<
screenHeight
?
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
:
ActivityInfo
.
SCREEN_ORIENTATION_PORTRAIT
;
}
return
orient
;
}
}
\ 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