提交 c56d72cb 编写于 作者: T Takeya Yuki

Add UI Control Feature

上级 98ea27a9
package jp.ruby.rubylibrary;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;
import java.nio.charset.Charset;
import yuki.resource.extended.StorageIOManager;
import yuki.resource.extended.UIController;
public class MainActivity extends Activity {
......@@ -16,9 +18,19 @@ public class MainActivity extends Activity {
setContentView(R.layout.activity_main);
TextView tv=(TextView)findViewById(R.id.tv);
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 {
StorageIOManager.WriteStringToFileSystem(getApplicationContext(),"/storage/emulated/0/1.txt","TEST IO");
s = StorageIOManager.ReadStringFromFileSystem(getApplicationContext(),"/system/bin/sh",true);
s=String.format("Screen Size\nReal Size: %d px * %d px\n", UIController.GetRealDisplayWidth(this),UIController.GetRealDisplayHeight(this));
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);
} catch (Exception e) {
e.printStackTrace();
......
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.
先完成此消息的编辑!
想要评论请 注册