Commit 44dc3fe7 by Karthik

2.2.11

parent 1fd36b3b
...@@ -21,10 +21,9 @@ import io.flutter.plugin.common.PluginRegistry.Registrar; ...@@ -21,10 +21,9 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
/** FluttertoastPlugin */ /** FluttertoastPlugin */
public class FluttertoastPlugin implements MethodCallHandler { public class FluttertoastPlugin implements MethodCallHandler {
private Context ctx; Context ctx;
private Toast toast = null;
private FluttertoastPlugin(Context context) { FluttertoastPlugin(Context context) {
ctx = context; ctx = context;
} }
...@@ -36,23 +35,7 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -36,23 +35,7 @@ public class FluttertoastPlugin implements MethodCallHandler {
@Override @Override
public void onMethodCall(MethodCall call, final Result result) { public void onMethodCall(MethodCall call, final Result result) {
switch (call.method) { if (call.method.equals("showToast")) {
case "showToast":
showToast(call, result);
break;
case "cancel":
if(toast != null) {
toast.cancel();
}
result.success(true);
break;
default:
result.notImplemented();
break;
}
}
private void showToast(MethodCall call, Result result) {
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();
...@@ -61,7 +44,7 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -61,7 +44,7 @@ public class FluttertoastPlugin implements MethodCallHandler {
Number textSize = call.argument("fontSize"); Number textSize = call.argument("fontSize");
toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); final Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
toast.setText(msg); toast.setText(msg);
...@@ -71,21 +54,20 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -71,21 +54,20 @@ public class FluttertoastPlugin implements MethodCallHandler {
toast.setDuration(Toast.LENGTH_SHORT); toast.setDuration(Toast.LENGTH_SHORT);
} }
// later Boolean sent = false;
// Boolean sent = false; final Handler handler = new Handler();
// final Handler handler = new Handler(); final Runnable run = new Runnable() {
// final Runnable run = new Runnable() {
// @Override
// @Override public void run() {
// public void run() { try {
// try { result.success(false);
// result.success(false);
// } catch (Exception e){
// } catch (Exception e){ e.printStackTrace();
// e.printStackTrace(); }
// } }
// } };
// };
switch (gravity) { switch (gravity) {
...@@ -101,6 +83,7 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -101,6 +83,7 @@ public class FluttertoastPlugin implements MethodCallHandler {
final TextView text = toast.getView().findViewById(android.R.id.message); final TextView text = toast.getView().findViewById(android.R.id.message);
text.setTextSize(textSize.floatValue()); text.setTextSize(textSize.floatValue());
text.setMaxLines(1);
if(bgcolor != null) { if(bgcolor != null) {
...@@ -116,31 +99,31 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -116,31 +99,31 @@ public class FluttertoastPlugin implements MethodCallHandler {
} }
} }
//later text.setOnTouchListener(new View.OnTouchListener() {
// text.setOnTouchListener(new View.OnTouchListener() { @Override
// @Override public boolean onTouch(View v, MotionEvent event) {
// public boolean onTouch(View v, MotionEvent event) { handler.removeCallbacks(run);
// handler.removeCallbacks(run); text.setOnTouchListener(null);
// text.setOnTouchListener(null); toast.cancel();
// toast.cancel(); try {
// try { result.success(true);
// } catch (Exception e){
// result.success(true); e.printStackTrace();
// }
// } catch (Exception e){
// e.printStackTrace(); return false;
// } }
// });
// return false;
// }
// });
if(textcolor != null) { if(textcolor != null) {
text.setTextColor(textcolor.intValue()); text.setTextColor(textcolor.intValue());
} }
toast.show(); toast.show();
result.success(true); handler.postDelayed(run,toast.getDuration()*1000);
// handler.postDelayed(run,toast.getDuration()*1000);
} else {
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