Commit 5df60dca by Karthik

migrated to androidX

parent f6fc0a87
## [3.0.0]
* Migrated to AndroidX
## [2.2.12] ## [2.2.12]
* Incomplete Text Fix * Incomplete Text Fix
......
...@@ -7,13 +7,13 @@ Android and iOS Toast Library for Flutter ...@@ -7,13 +7,13 @@ Android and iOS Toast Library for Flutter
> * Android > * Android
> * IOS > * IOS
If your project uses androidx then use `fluttertoast` version `2.2.4` or `2.2.5` If you dont want to use androidx then use `fluttertoast` version `2.2.12`
## How to Use ## How to Use
```yaml ```yaml
# add this line to your dependencies # add this line to your dependencies
fluttertoast: ^2.2.12 fluttertoast: ^3.0.0
``` ```
```dart ```dart
......
...@@ -26,7 +26,7 @@ android { ...@@ -26,7 +26,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
lintOptions { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
...@@ -34,6 +34,6 @@ android { ...@@ -34,6 +34,6 @@ android {
} }
dependencies { dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'com.android.support:support-compat:27.1.1' implementation 'androidx.core:core:1.0.0-beta01'
} }
...@@ -11,7 +11,7 @@ import android.view.View; ...@@ -11,7 +11,7 @@ import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.support.v4.content.ContextCompat; import androidx.core.content.ContextCompat;
import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
...@@ -21,109 +21,116 @@ import io.flutter.plugin.common.PluginRegistry.Registrar; ...@@ -21,109 +21,116 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
/** FluttertoastPlugin */ /** FluttertoastPlugin */
public class FluttertoastPlugin implements MethodCallHandler { public class FluttertoastPlugin implements MethodCallHandler {
Context ctx; Context ctx;
Toast toast;
FluttertoastPlugin(Context context) {
ctx = context;
}
/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "PonnamKarthik/fluttertoast");
channel.setMethodCallHandler(new FluttertoastPlugin(registrar.context()));
}
@Override
public void onMethodCall(MethodCall call, final 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();
Number bgcolor = call.argument("bgcolor");
Number textcolor = call.argument("textcolor");
Number textSize = call.argument("fontSize");
final 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);
}
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) {
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);
}
final TextView text = toast.getView().findViewById(android.R.id.message); FluttertoastPlugin(Context context) {
text.setTextSize(textSize.floatValue()); ctx = context;
text.setMaxLines(1); }
/** Plugin registration. */
if(bgcolor != null) { public static void registerWith(Registrar registrar) {
Drawable shapeDrawable = ContextCompat.getDrawable(ctx, R.drawable.toast_bg); final MethodChannel channel = new MethodChannel(registrar.messenger(), "PonnamKarthik/fluttertoast");
channel.setMethodCallHandler(new FluttertoastPlugin(registrar.context()));
if (shapeDrawable != null) { }
shapeDrawable.setColorFilter(bgcolor.intValue(), PorterDuff.Mode.SRC_IN);
if (Build.VERSION.SDK_INT <= 27) {
toast.getView().setBackground(shapeDrawable);
} else {
text.setBackground(shapeDrawable);
}
}
}
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; @Override
public void onMethodCall(MethodCall call, final 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();
Number bgcolor = call.argument("bgcolor");
Number textcolor = call.argument("textcolor");
Number textSize = call.argument("fontSize");
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);
} }
});
if(textcolor != null) { Boolean sent = false;
text.setTextColor(textcolor.intValue()); // 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) {
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(); final TextView text = toast.getView().findViewById(android.R.id.message);
handler.postDelayed(run,toast.getDuration()*1000); if(textSize != null)
text.setTextSize(textSize.floatValue());
} else { text.setMaxLines(1);
result.notImplemented();
if(bgcolor != null) {
Drawable shapeDrawable = ContextCompat.getDrawable(ctx, R.drawable.toast_bg);
if (shapeDrawable != null) {
shapeDrawable.setColorFilter(bgcolor.intValue(), PorterDuff.Mode.SRC_IN);
if (Build.VERSION.SDK_INT <= 27) {
toast.getView().setBackground(shapeDrawable);
} else {
toast.getView().setBackground(null);
text.setBackground(shapeDrawable);
}
}
}
// 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);
} else if(call.method.equals("cancel")){
if(toast != null)
toast.cancel();
result.success(true);
} else {
result.notImplemented();
}
} }
}
} }
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
android:color="#000000"> android:color="#000000">
</solid> </solid>
<padding <padding
android:left="10dp" android:left="16dp"
android:top="8dp" android:top="12dp"
android:right="10dp" android:right="16dp"
android:bottom="8dp" /> android:bottom="12dp" />
</shape> </shape>
\ No newline at end of file
...@@ -38,7 +38,7 @@ android { ...@@ -38,7 +38,7 @@ android {
targetSdkVersion 28 targetSdkVersion 28
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
...@@ -56,6 +56,8 @@ flutter { ...@@ -56,6 +56,8 @@ flutter {
dependencies { dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
} }
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
name: fluttertoast name: fluttertoast
description: Toast Library for FLutter description: Toast Library for FLutter
version: 2.2.12 version: 3.0.0
author: Karthik Ponnam <ponnamkarthik3@gmail.com> author: Karthik Ponnam <ponnamkarthik3@gmail.com>
homepage: https://github.com/PonnamKarthik/FlutterToast homepage: https://github.com/PonnamKarthik/FlutterToast
......
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