Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Takeya-Yuki
RubyLib
提交
c56d72cb
R
RubyLib
项目概览
Takeya-Yuki
/
RubyLib
8 个月 前同步成功
通知
39
Star
19
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RubyLib
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c56d72cb
编写于
6月 29, 2017
作者:
T
Takeya Yuki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add UI Control Feature
上级
98ea27a9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
142 addition
and
2 deletion
+142
-2
app/src/main/java/jp/ruby/rubylibrary/MainActivity.java
app/src/main/java/jp/ruby/rubylibrary/MainActivity.java
+14
-2
rubylib/src/main/java/yuki/resource/extended/UIController.java
...ib/src/main/java/yuki/resource/extended/UIController.java
+128
-0
未找到文件。
app/src/main/java/jp/ruby/rubylibrary/MainActivity.java
浏览文件 @
c56d72cb
package
jp.ruby.rubylibrary
;
package
jp.ruby.rubylibrary
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.graphics.Color
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
yuki.resource.extended.StorageIOManager
;
import
yuki.resource.extended.StorageIOManager
;
import
yuki.resource.extended.UIController
;
public
class
MainActivity
extends
Activity
{
public
class
MainActivity
extends
Activity
{
...
@@ -16,9 +18,19 @@ public class MainActivity extends Activity {
...
@@ -16,9 +18,19 @@ public class MainActivity extends Activity {
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
TextView
tv
=(
TextView
)
findViewById
(
R
.
id
.
tv
);
TextView
tv
=(
TextView
)
findViewById
(
R
.
id
.
tv
);
String
s
=
null
;
String
s
=
null
;
UIController
.
SetStatusBarBackgroundColor
(
this
,
Color
.
BLACK
);
UIController
.
SetNavigationBarBackgroundColor
(
this
,
Color
.
RED
);
//UIController.HideStatusBar(this);
UIController
.
HideNavigationBar
(
this
);
//UIController.ShowStatusBar(this);
UIController
.
ShowNavigationBar
(
this
);
try
{
try
{
StorageIOManager
.
WriteStringToFileSystem
(
getApplicationContext
(),
"/storage/emulated/0/1.txt"
,
"TEST IO"
);
s
=
String
.
format
(
"Screen Size\nReal Size: %d px * %d px\n"
,
UIController
.
GetRealDisplayWidth
(
this
),
UIController
.
GetRealDisplayHeight
(
this
));
s
=
StorageIOManager
.
ReadStringFromFileSystem
(
getApplicationContext
(),
"/system/bin/sh"
,
true
);
s
+=
String
.
format
(
"Real Size: %d dp * %d dp\n"
,
UIController
.
PixelToDP
(
UIController
.
GetRealDisplayWidth
(
this
),
UIController
.
GetRealDisplayMetrics
(
this
).
density
),
UIController
.
PixelToDP
(
UIController
.
GetRealDisplayHeight
(
this
),
UIController
.
GetRealDisplayMetrics
(
this
).
density
));
s
+=
String
.
format
(
"Logical Size: %d px * %d px\n"
,
UIController
.
GetLogicalDisplayWidth
(
this
),
UIController
.
GetLogicalDisplayHeight
(
this
));
s
+=
String
.
format
(
"Logical Size: %d dp * %d dp\n"
,
UIController
.
PixelToDP
(
UIController
.
GetLogicalDisplayWidth
(
this
),
UIController
.
GetLogicalDisplayMetrics
(
this
).
density
),
UIController
.
PixelToDP
(
UIController
.
GetLogicalDisplayHeight
(
this
),
UIController
.
GetLogicalDisplayMetrics
(
this
).
density
));
tv
.
setText
(
s
);
tv
.
setText
(
s
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
rubylib/src/main/java/yuki/resource/extended/UIController.java
0 → 100644
浏览文件 @
c56d72cb
package
yuki.resource.extended
;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.support.annotation.ColorInt
;
import
android.util.DisplayMetrics
;
import
android.view.Display
;
import
android.view.View
;
import
android.view.WindowManager
;
import
static
android
.
view
.
View
.
SYSTEM_UI_FLAG_FULLSCREEN
;
/**
* Created by Akeno on 2017/06/29.
*/
public
class
UIController
{
public
static
void
SetStatusBarBackgroundColor
(
Activity
activity
,
int
a
,
int
r
,
int
g
,
int
b
){
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
activity
.
getWindow
().
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
activity
.
getWindow
().
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
);
activity
.
getWindow
().
setStatusBarColor
(
Color
.
argb
(
a
,
r
,
g
,
b
));
}
}
public
static
void
SetStatusBarBackgroundColor
(
Activity
activity
,
@ColorInt
int
color
){
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
activity
.
getWindow
().
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
activity
.
getWindow
().
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
);
activity
.
getWindow
().
setStatusBarColor
(
color
);
}
}
public
static
void
SetNavigationBarBackgroundColor
(
Activity
activity
,
int
a
,
int
r
,
int
g
,
int
b
){
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
activity
.
getWindow
().
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
activity
.
getWindow
().
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
);
activity
.
getWindow
().
setNavigationBarColor
(
Color
.
argb
(
a
,
r
,
g
,
b
));
}
}
public
static
void
SetNavigationBarBackgroundColor
(
Activity
activity
,
@ColorInt
int
color
){
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
activity
.
getWindow
().
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
activity
.
getWindow
().
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
);
activity
.
getWindow
().
setNavigationBarColor
(
color
);
}
}
public
static
DisplayMetrics
GetRealDisplayMetrics
(
Activity
activity
){
DisplayMetrics
dm
=
new
DisplayMetrics
();
activity
.
getWindowManager
().
getDefaultDisplay
().
getRealMetrics
(
dm
);
return
dm
;
}
public
static
DisplayMetrics
GetLogicalDisplayMetrics
(
Activity
activity
){
DisplayMetrics
dm
=
new
DisplayMetrics
();
activity
.
getWindowManager
().
getDefaultDisplay
().
getMetrics
(
dm
);
return
dm
;
}
public
static
int
GetRealDisplayHeight
(
Activity
activity
){
return
GetRealDisplayMetrics
(
activity
).
heightPixels
;
}
public
static
int
GetRealDisplayWidth
(
Activity
activity
){
return
GetRealDisplayMetrics
(
activity
).
widthPixels
;
}
public
static
int
GetLogicalDisplayHeight
(
Activity
activity
){
return
GetLogicalDisplayMetrics
(
activity
).
heightPixels
;
}
public
static
int
GetLogicalDisplayWidth
(
Activity
activity
){
return
GetLogicalDisplayMetrics
(
activity
).
widthPixels
;
}
public
static
int
PixelToDP
(
int
pixel
,
float
ratio
){
return
(
int
)
(
pixel
/
ratio
);
}
public
static
int
DPToPixel
(
int
dp
,
float
ratio
){
return
(
int
)(
dp
*
ratio
);
}
public
static
DisplayMetrics
SizeToDisplayMetrics
(
int
height
,
int
width
){
DisplayMetrics
dm
=
new
DisplayMetrics
();
dm
.
setToDefaults
();
dm
.
widthPixels
=
width
;
dm
.
heightPixels
=
height
;
return
dm
;
}
public
static
void
HideStatusBar
(
Activity
activity
){
View
mDecorView
=
activity
.
getWindow
().
getDecorView
();
int
uiv
=
mDecorView
.
getSystemUiVisibility
();
uiv
|=
View
.
SYSTEM_UI_FLAG_IMMERSIVE
;
uiv
|=
View
.
SYSTEM_UI_FLAG_FULLSCREEN
;
mDecorView
.
setSystemUiVisibility
(
uiv
);
}
public
static
void
ShowStatusBar
(
Activity
activity
){
View
mDecorView
=
activity
.
getWindow
().
getDecorView
();
int
uiv
=
mDecorView
.
getSystemUiVisibility
();
uiv
|=
View
.
SYSTEM_UI_FLAG_IMMERSIVE
;
uiv
&=~
View
.
SYSTEM_UI_FLAG_FULLSCREEN
;
mDecorView
.
setSystemUiVisibility
(
uiv
);
}
public
static
void
HideNavigationBar
(
Activity
activity
){
View
mDecorView
=
activity
.
getWindow
().
getDecorView
();
int
uiv
=
mDecorView
.
getSystemUiVisibility
();
uiv
|=
View
.
SYSTEM_UI_FLAG_IMMERSIVE
;
uiv
|=
View
.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
;
mDecorView
.
setSystemUiVisibility
(
uiv
);
}
public
static
void
ShowNavigationBar
(
Activity
activity
){
View
mDecorView
=
activity
.
getWindow
().
getDecorView
();
int
uiv
=
mDecorView
.
getSystemUiVisibility
();
uiv
|=
View
.
SYSTEM_UI_FLAG_IMMERSIVE
;
uiv
&=~
View
.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
;
mDecorView
.
setSystemUiVisibility
(
uiv
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录