Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
IoTServ committed Apr 8, 2021
1 parent 431a8aa commit 03e876e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 82 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@

## 0.0.4

* update.

## 0.0.4+1

* update.
Original file line number Diff line number Diff line change
@@ -1,100 +1,71 @@
package com.iotserv.flutter_oneshot;

import android.app.Activity;
import android.net.wifi.WifiManager;
import android.util.Log;

import androidx.annotation.NonNull;

import com.winnermicro.smartconfig.ConfigType;
import com.winnermicro.smartconfig.IOneShotConfig;
import com.winnermicro.smartconfig.SmartConfigFactory;

import java.util.HashMap;
import java.util.Map;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;

import com.winnermicro.smartconfig.*;

import java.util.HashMap;
import java.util.Map;

/** FlutterOneshotPlugin */
/**
* FlutterOneshotPlugin
*/
public class FlutterOneshotPlugin implements FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private int timeout = 60;//miao
private FlutterPluginBinding myFlutterPluginBinding;
private MethodChannel channel;
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private int timeout = 60;//miao
private FlutterPluginBinding myFlutterPluginBinding;
private MethodChannel channel;

private String ssid;
private String password = null;
private IOneShotConfig oneshotConfig = null;
private SmartConfigFactory factory = null;
private String ssid;
private String password = null;
private IOneShotConfig oneshotConfig = null;
private SmartConfigFactory factory = null;

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
myFlutterPluginBinding = flutterPluginBinding;
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_oneshot");
channel.setMethodCallHandler(this);
}

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("start")){
//参数获取
ssid = call.argument("ssid");
password = call.argument("password");
try {
timeout = call.argument("timeout");
}catch (Exception e){
e.printStackTrace();
timeout = 30;
}
new Thread(new UDPReqThread(result)).start();
}
else {
result.notImplemented();
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
myFlutterPluginBinding = flutterPluginBinding;
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_oneshot");
channel.setMethodCallHandler(this);
}
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}

class UDPReqThread implements Runnable {
private Result result;
public UDPReqThread(Result result)
{
this.result = result;
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("start")) {
//参数获取
ssid = call.argument("ssid");
password = call.argument("password");
try {
timeout = call.argument("timeout");
} catch (Exception e) {
e.printStackTrace();
timeout = 30;
}
factory = new SmartConfigFactory();
oneshotConfig = factory.createOneShotConfig(ConfigType.UDP);
oneshotConfig.start(ssid, password, timeout, myFlutterPluginBinding.getApplicationContext());
final Map<String, String> ret = new HashMap<String, String>();
ret.put("result", "success");
result.success(ret);
} else {
result.notImplemented();
}
}

public void run() {
final Map<String, String> ret = new HashMap<String, String>();
factory = new SmartConfigFactory();
oneshotConfig = factory.createOneShotConfig(ConfigType.UDP);
// start config
try {
oneshotConfig.start(ssid, password, timeout, myFlutterPluginBinding.getApplicationContext());
}
catch (OneShotException e) {
Log.d("===oneshot-OneShotE===",e.getMessage());
e.printStackTrace();
int code = e.getErrorID();
Log.d("onshot err", String.valueOf(code));
}
catch (Exception e) {
Log.d("===oneshot-exception===",e.getMessage());
e.printStackTrace();
} finally {
oneshotConfig.stop( );
ret.put("result","success");
Log.d("===oneshot-success===","success");
result.success(ret);
}
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_oneshot
description: OneShot for w60x wifi config
version: 0.0.4
version: 0.0.4+1
homepage: https://github.com/iotdevice/flutter_oneshot

environment:
Expand Down

0 comments on commit 03e876e

Please sign in to comment.