feat:add toast gravity for Android
This commit is contained in:
parent
2d0570c09f
commit
1345d75a7f
@ -15,17 +15,20 @@
|
||||
*/
|
||||
package pub.doric.plugin;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
import pub.doric.utils.ThreadMode;
|
||||
|
||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
/**
|
||||
* @Description: Doric
|
||||
@ -43,9 +46,24 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
public void toast(JSDecoder decoder, DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
Toast.makeText(getDoricContext().getContext(),
|
||||
String msg = jsObject.getProperty("msg").asString().value();
|
||||
JSValue gravityVal = jsObject.getProperty("gravity");
|
||||
int gravity = Gravity.BOTTOM;
|
||||
if (gravityVal.isNumber()) {
|
||||
gravity = gravityVal.asNumber().toInt();
|
||||
}
|
||||
Toast toast = Toast.makeText(getDoricContext().getContext(),
|
||||
jsObject.getProperty("msg").asString().value(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.LENGTH_SHORT);
|
||||
if ((gravity & Gravity.TOP) == Gravity.TOP) {
|
||||
toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, DoricUtils.dp2px(50));
|
||||
} else if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
|
||||
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, DoricUtils.dp2px(50));
|
||||
} else {
|
||||
toast.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL, 0, 0);
|
||||
|
||||
}
|
||||
toast.show();
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Reference in New Issue
Block a user