Commit aa4dd550 by Ben Getsug

updating android plugin to reflect changes made in dart

parent eb80de17
...@@ -37,64 +37,62 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -37,64 +37,62 @@ public class FluttertoastPlugin implements MethodCallHandler {
String msg = call.argument("msg").toString(); String msg = call.argument("msg").toString();
String length = call.argument("length").toString(); String length = call.argument("length").toString();
String gravity = call.argument("gravity").toString(); String gravity = call.argument("gravity").toString();
Integer bgcolor = call.argument("bgcolor"); Long bgcolor = call.argument("bgcolor");
Integer textcolor = call.argument("textcolor"); Long textcolor = call.argument("textcolor");
Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
toast.setText(msg);
if(length.equals("long")) {
toast.setDuration(Toast.LENGTH_LONG);
} else {
toast.setDuration(Toast.LENGTH_SHORT);
}
switch (gravity) { toast.setText(msg);
case "top":
toast.setGravity(Gravity.TOP, 0, 100); if(length.equals("long")) {
break; toast.setDuration(Toast.LENGTH_LONG);
case "center": } else {
toast.setGravity(Gravity.CENTER, 0, 0); toast.setDuration(Toast.LENGTH_SHORT);
break; }
default:
toast.setGravity(Gravity.BOTTOM, 0, 100);
} switch (gravity) {
TextView text = toast.getView().findViewById(android.R.id.message); case "top":
if (defaultTextColor == 0) { toast.setGravity(Gravity.TOP, 0, 100);
defaultTextColor = text.getCurrentTextColor(); break;
} case "center":
if (!bgcolor.equals("null")) { toast.setGravity(Gravity.CENTER, 0, 0);
break;
try { default:
toast.setGravity(Gravity.BOTTOM, 0, 100);
RoundRectShape rectShape = new RoundRectShape(new float[] {100f, 100f, 100f, 100f, 100f, 100f, 100f, 100f}, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(rectShape);
shapeDrawable.getPaint().setColor(bgcolor);
shapeDrawable.getPaint().setStyle(Paint.Style.FILL);
shapeDrawable.getPaint().setAntiAlias(true);
shapeDrawable.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);
if (android.os.Build.VERSION.SDK_INT <= 27) {
toast.getView().setBackground(shapeDrawable);
} else {
text.setBackground(shapeDrawable);
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (!textcolor.equals("null")) {
try {
text.setTextColor(textcolor);
} catch (Exception e) {
e.printStackTrace();
}
} else {
text.setTextColor(defaultTextColor);
} }
toast.show(); TextView text = toast.getView().findViewById(android.R.id.message);
if (defaultTextColor == 0) {
defaultTextColor = text.getCurrentTextColor();
}
try {
RoundRectShape rectShape = new RoundRectShape(new float[] {100f, 100f, 100f, 100f, 100f, 100f, 100f, 100f}, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(rectShape);
shapeDrawable.getPaint().setColor(bgcolor != null ? bgcolor.intValue() : Color.BLACK);
shapeDrawable.getPaint().setStyle(Paint.Style.FILL);
shapeDrawable.getPaint().setAntiAlias(true);
shapeDrawable.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);
if (android.os.Build.VERSION.SDK_INT <= 27) {
toast.getView().setBackground(shapeDrawable);
} else {
text.setBackground(shapeDrawable);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
text.setTextColor(textcolor != null ? textcolor.intValue() : defaultTextColor);
} catch (Exception e) {
e.printStackTrace();
}
toast.show();
result.success("Success"); result.success("Success");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment