Commit 44dc3fe7 by Karthik

2.2.11

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