android status bar api implement
This commit is contained in:
parent
73c06373ad
commit
2de57ff317
@ -44,7 +44,6 @@ dependencies {
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
||||
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.3'
|
||||
implementation 'jp.wasabeef:glide-transformations:4.1.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation "com.google.android.material:material:1.0.0"
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
|
@ -17,41 +17,42 @@ package pub.doric;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import pub.doric.plugin.AnimatePlugin;
|
||||
import pub.doric.plugin.DoricJavaPlugin;
|
||||
import pub.doric.plugin.ModalPlugin;
|
||||
import pub.doric.plugin.NavBarPlugin;
|
||||
import pub.doric.plugin.NavigatorPlugin;
|
||||
import pub.doric.plugin.NetworkPlugin;
|
||||
import pub.doric.plugin.NotificationPlugin;
|
||||
import pub.doric.plugin.PopoverPlugin;
|
||||
import pub.doric.plugin.ShaderPlugin;
|
||||
import pub.doric.plugin.StatusBarPlugin;
|
||||
import pub.doric.plugin.StoragePlugin;
|
||||
import pub.doric.refresh.RefreshableNode;
|
||||
import pub.doric.shader.DraggableNode;
|
||||
import pub.doric.shader.HLayoutNode;
|
||||
import pub.doric.shader.ImageNode;
|
||||
import pub.doric.shader.InputNode;
|
||||
import pub.doric.shader.ScrollerNode;
|
||||
import pub.doric.shader.flowlayout.FlowLayoutItemNode;
|
||||
import pub.doric.shader.flowlayout.FlowLayoutNode;
|
||||
import pub.doric.shader.list.ListItemNode;
|
||||
import pub.doric.shader.list.ListNode;
|
||||
import pub.doric.shader.RootNode;
|
||||
import pub.doric.shader.ScrollerNode;
|
||||
import pub.doric.shader.StackNode;
|
||||
import pub.doric.shader.TextNode;
|
||||
import pub.doric.shader.VLayoutNode;
|
||||
import pub.doric.shader.ViewNode;
|
||||
import pub.doric.shader.flowlayout.FlowLayoutItemNode;
|
||||
import pub.doric.shader.flowlayout.FlowLayoutNode;
|
||||
import pub.doric.shader.list.ListItemNode;
|
||||
import pub.doric.shader.list.ListNode;
|
||||
import pub.doric.shader.slider.NestedSliderNode;
|
||||
import pub.doric.shader.slider.SlideItemNode;
|
||||
import pub.doric.shader.slider.SliderNode;
|
||||
import pub.doric.utils.DoricMetaInfo;
|
||||
import pub.doric.plugin.DoricJavaPlugin;
|
||||
import pub.doric.plugin.ModalPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Description: pub.doric
|
||||
@ -89,6 +90,7 @@ public class DoricRegistry {
|
||||
this.registerNativePlugin(PopoverPlugin.class);
|
||||
this.registerNativePlugin(AnimatePlugin.class);
|
||||
this.registerNativePlugin(NotificationPlugin.class);
|
||||
this.registerNativePlugin(StatusBarPlugin.class);
|
||||
|
||||
this.registerViewNode(RootNode.class);
|
||||
this.registerViewNode(TextNode.class);
|
||||
|
@ -0,0 +1,153 @@
|
||||
package pub.doric.plugin;
|
||||
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
import pub.doric.utils.ThreadMode;
|
||||
|
||||
@DoricPlugin(name = "statusbar")
|
||||
public class StatusBarPlugin extends DoricJavaPlugin {
|
||||
|
||||
private int currentMode = 0;
|
||||
|
||||
public StatusBarPlugin(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void setHidden(JSDecoder jsDecoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = jsDecoder.decode().asObject();
|
||||
final boolean hidden = jsObject.getProperty("hidden").asBoolean().value();
|
||||
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext());
|
||||
View decorView = activity.getWindow().getDecorView();
|
||||
if (hidden) {
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
|
||||
} else {
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() {
|
||||
@Override
|
||||
public void onResult(Object result) {
|
||||
promise.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
promise.reject(new JavaValue(t.getLocalizedMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void setMode(JSDecoder jsDecoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = jsDecoder.decode().asObject();
|
||||
final int mode = jsObject.getProperty("mode").asNumber().toInt();
|
||||
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext());
|
||||
View decorView = activity.getWindow().getDecorView();
|
||||
|
||||
int flags = decorView.getSystemUiVisibility();
|
||||
if (mode == currentMode) {
|
||||
return null;
|
||||
} else {
|
||||
currentMode = mode;
|
||||
}
|
||||
flags ^= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
|
||||
decorView.setSystemUiVisibility(flags);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() {
|
||||
@Override
|
||||
public void onResult(Object result) {
|
||||
promise.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
promise.reject(new JavaValue(t.getLocalizedMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@DoricMethod
|
||||
public void setColor(JSDecoder jsDecoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = jsDecoder.decode().asObject();
|
||||
final int color = jsObject.getProperty("color").asNumber().toInt();
|
||||
getDoricContext().getDriver().asyncCall(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext());
|
||||
activity.getWindow().setStatusBarColor(color);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, ThreadMode.UI).setCallback(new AsyncResult.Callback<Object>() {
|
||||
@Override
|
||||
public void onResult(Object result) {
|
||||
promise.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
t.printStackTrace();
|
||||
promise.reject(new JavaValue(t.getLocalizedMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user