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 {
String msg = call.argument("msg").toString();
String length = call.argument("length").toString();
String gravity = call.argument("gravity").toString();
Integer bgcolor = call.argument("bgcolor");
Integer textcolor = call.argument("textcolor");
Long bgcolor = call.argument("bgcolor");
Long textcolor = call.argument("textcolor");
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) {
case "top":
toast.setGravity(Gravity.TOP, 0, 100);
break;
case "center":
toast.setGravity(Gravity.CENTER, 0, 0);
break;
default:
toast.setGravity(Gravity.BOTTOM, 0, 100);
}
TextView text = toast.getView().findViewById(android.R.id.message);
if (defaultTextColor == 0) {
defaultTextColor = text.getCurrentTextColor();
}
if (!bgcolor.equals("null")) {
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);
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.setText(msg);
if(length.equals("long")) {
toast.setDuration(Toast.LENGTH_LONG);
} else {
toast.setDuration(Toast.LENGTH_SHORT);
}
switch (gravity) {
case "top":
toast.setGravity(Gravity.TOP, 0, 100);
break;
case "center":
toast.setGravity(Gravity.CENTER, 0, 0);
break;
default:
toast.setGravity(Gravity.BOTTOM, 0, 100);
}
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");
......
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