Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
react-native-extra-dimensions-android
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
放牛的园子
react-native-extra-dimensions-android
Commits
a17dee14
Commit
a17dee14
authored
Jan 04, 2016
by
Jack Hsu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from Spikef/master
Add "SMART_BAR_SIZE" for MeiZu device.
parents
6e31127b
4bb144b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
README.md
README.md
+2
-0
ExtraDimensionsModule.java
...java/ca/jaysoo/extradimensions/ExtraDimensionsModule.java
+52
-0
No files found.
README.md
View file @
a17dee14
...
@@ -5,6 +5,7 @@ This module allows you to access additional display metrics on Android devices.
...
@@ -5,6 +5,7 @@ This module allows you to access additional display metrics on Android devices.
-
Actual width and height of the screen (including elements such as soft menu bar)
-
Actual width and height of the screen (including elements such as soft menu bar)
-
Soft menu height
-
Soft menu height
-
Status bar height
-
Status bar height
-
Smart bar height(MeiZu)
### Why?
### Why?
...
@@ -84,3 +85,4 @@ Supported dimensions are:
...
@@ -84,3 +85,4 @@ Supported dimensions are:
-
`REAL_WINDOW_WIDTH`
- Actual width of screen including system decor elements
-
`REAL_WINDOW_WIDTH`
- Actual width of screen including system decor elements
-
`STATUS_BAR_HEIGHT`
- Height of the status bar
-
`STATUS_BAR_HEIGHT`
- Height of the status bar
-
`SOFT_MENU_BAR_HEIGHT`
- Height of the soft menu bar (supported on most new Android devices)
-
`SOFT_MENU_BAR_HEIGHT`
- Height of the soft menu bar (supported on most new Android devices)
-
`SMART_BAR_HEIGHT`
- Height of the MeiZu's device smart bar
android/src/main/java/ca/jaysoo/extradimensions/ExtraDimensionsModule.java
View file @
a17dee14
...
@@ -8,6 +8,8 @@ import android.content.Context;
...
@@ -8,6 +8,8 @@ import android.content.Context;
import
android.os.Build
;
import
android.os.Build
;
import
android.util.DisplayMetrics
;
import
android.util.DisplayMetrics
;
import
android.view.Display
;
import
android.view.Display
;
import
android.provider.Settings
;
import
android.content.res.Resources
;
import
com.facebook.react.bridge.ReactApplicationContext
;
import
com.facebook.react.bridge.ReactApplicationContext
;
import
com.facebook.react.bridge.ReactContextBaseJavaModule
;
import
com.facebook.react.bridge.ReactContextBaseJavaModule
;
...
@@ -15,6 +17,8 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
...
@@ -15,6 +17,8 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.lang.reflect.Field
;
public
class
ExtraDimensionsModule
extends
ReactContextBaseJavaModule
{
public
class
ExtraDimensionsModule
extends
ReactContextBaseJavaModule
{
private
Activity
mCurrentActivity
;
private
Activity
mCurrentActivity
;
...
@@ -53,6 +57,7 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule {
...
@@ -53,6 +57,7 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule {
constants
.
put
(
"REAL_WINDOW_WIDTH"
,
getRealWidth
(
metrics
));
constants
.
put
(
"REAL_WINDOW_WIDTH"
,
getRealWidth
(
metrics
));
constants
.
put
(
"STATUS_BAR_HEIGHT"
,
getStatusBarHeight
(
metrics
));
constants
.
put
(
"STATUS_BAR_HEIGHT"
,
getStatusBarHeight
(
metrics
));
constants
.
put
(
"SOFT_MENU_BAR_HEIGHT"
,
getSoftMenuBarHeight
(
metrics
));
constants
.
put
(
"SOFT_MENU_BAR_HEIGHT"
,
getSoftMenuBarHeight
(
metrics
));
constants
.
put
(
"SMART_BAR_HEIGHT"
,
getSmartBarHeight
(
metrics
));
return
constants
;
return
constants
;
}
}
...
@@ -84,5 +89,52 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule {
...
@@ -84,5 +89,52 @@ public class ExtraDimensionsModule extends ReactContextBaseJavaModule {
private
float
getRealWidth
(
DisplayMetrics
metrics
)
{
private
float
getRealWidth
(
DisplayMetrics
metrics
)
{
return
metrics
.
widthPixels
/
metrics
.
density
;
return
metrics
.
widthPixels
/
metrics
.
density
;
}
}
// 获取魅族SmartBar高度
private
float
getSmartBarHeight
(
DisplayMetrics
metrics
)
{
final
Context
context
=
getReactApplicationContext
();
final
boolean
isMeiZu
=
Build
.
MANUFACTURER
.
equals
(
"Meizu"
);
final
boolean
autoHideSmartBar
=
Settings
.
System
.
getInt
(
context
.
getContentResolver
(),
"mz_smartbar_auto_hide"
,
0
)
==
1
;
if
(
isMeiZu
)
{
if
(
autoHideSmartBar
)
{
return
0
;
}
else
{
try
{
Class
c
=
Class
.
forName
(
"com.android.internal.R$dimen"
);
Object
obj
=
c
.
newInstance
();
Field
field
=
c
.
getField
(
"mz_action_button_min_height"
);
int
height
=
Integer
.
parseInt
(
field
.
get
(
obj
).
toString
());
return
context
.
getResources
().
getDimensionPixelSize
(
height
)
/
metrics
.
density
;
}
catch
(
Throwable
e
)
{
// 不自动隐藏smartbar同时又没有smartbar高度字段供访问,取系统navigationbar的高度
return
getNormalNavigationBarHeight
(
context
)
/
metrics
.
density
;
}
}
}
else
{
return
0
;
//return getNormalNavigationBarHeight(context) / metrics.density;
}
}
protected
static
float
getNormalNavigationBarHeight
(
final
Context
ctx
)
{
try
{
final
Resources
res
=
ctx
.
getResources
();
int
rid
=
res
.
getIdentifier
(
"config_showNavigationBar"
,
"bool"
,
"android"
);
if
(
rid
>
0
)
{
boolean
flag
=
res
.
getBoolean
(
rid
);
if
(
flag
)
{
int
resourceId
=
res
.
getIdentifier
(
"navigation_bar_height"
,
"dimen"
,
"android"
);
if
(
resourceId
>
0
)
{
return
res
.
getDimensionPixelSize
(
resourceId
);
}
}
}
}
catch
(
Throwable
e
)
{
return
0
;
}
return
0
;
}
}
}
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