Commit 9de5a8f8 by Zac Chan

Attempting Android fix

parent 730145ee
...@@ -4,7 +4,10 @@ import android.content.Context; ...@@ -4,7 +4,10 @@ import android.content.Context;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Handler;
import android.view.Gravity; import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
...@@ -31,16 +34,19 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -31,16 +34,19 @@ public class FluttertoastPlugin implements MethodCallHandler {
} }
@Override @Override
public void onMethodCall(MethodCall call, Result result) { public void onMethodCall(MethodCall call, final Result result) {
if (call.method.equals("showToast")) { if (call.method.equals("showToast")) {
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();
Number bgcolor = call.argument("bgcolor"); Number bgcolor = call.argument("bgcolor");
Number textcolor = call.argument("textcolor"); Number textcolor = call.argument("textcolor");
Number textSize = call.argument("fontSize");
final Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
toast.setText(msg); toast.setText(msg);
...@@ -50,6 +56,16 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -50,6 +56,16 @@ public class FluttertoastPlugin implements MethodCallHandler {
toast.setDuration(Toast.LENGTH_SHORT); toast.setDuration(Toast.LENGTH_SHORT);
} }
final Handler handler = new Handler();
final Runnable run = new Runnable() {
@Override
public void run() {
result.success(false);
}
};
switch (gravity) { switch (gravity) {
case "top": case "top":
toast.setGravity(Gravity.TOP, 0, 100); toast.setGravity(Gravity.TOP, 0, 100);
...@@ -62,6 +78,9 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -62,6 +78,9 @@ public class FluttertoastPlugin implements MethodCallHandler {
} }
TextView text = toast.getView().findViewById(android.R.id.message); TextView text = toast.getView().findViewById(android.R.id.message);
text.setTextSize(textSize.floatValue());
final View toastView = toast.getView();
if(bgcolor != null) { if(bgcolor != null) {
Drawable shapeDrawable = ContextCompat.getDrawable(ctx, R.drawable.toast_bg); Drawable shapeDrawable = ContextCompat.getDrawable(ctx, R.drawable.toast_bg);
...@@ -77,13 +96,40 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -77,13 +96,40 @@ public class FluttertoastPlugin implements MethodCallHandler {
} }
toastView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
result.success(true);
handler.removeCallbacks(run);
return false;
}
});
if(textcolor != null) { if(textcolor != null) {
text.setTextColor(textcolor.intValue()); text.setTextColor(textcolor.intValue());
} }
// Thread thread = new Thread(){
// @Override
// public void run(){
// try {
// Thread.sleep(toast.getDuration());
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// result
//
// }
// };
toast.show(); toast.show();
handler.postDelayed(run,toast.getDuration()*1000 );
// thread.run();
result.success("Success"); // result.success("Success");
} else { } else {
result.notImplemented(); result.notImplemented();
......
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