Compare commits
17 Commits
c2d7dfcd10
...
master
Author | SHA1 | Date |
---|---|---|
张萌 | 81e0daf448 | 2 years ago |
章文轩 | 3d16fd8ee1 | 2 years ago |
章文轩 | 1d11eb7b2c | 2 years ago |
章文轩 | 952b5c75b4 | 2 years ago |
章文轩 | da66b76e8d | 2 years ago |
章文轩 | 0094f481f3 | 2 years ago |
章文轩 | 921d52fb72 | 2 years ago |
章文轩 | 7764ef51a5 | 2 years ago |
meng-fucius | 2dce9eaf2a | 3 years ago |
张萌 | 5677de4120 | 3 years ago |
张萌 | d091fc3da4 | 3 years ago |
张萌 | fe3edb17df | 3 years ago |
张萌 | d90d55179a | 3 years ago |
张萌 | b3be7c8273 | 3 years ago |
张萌 | 88397f8589 | 3 years ago |
张萌 | c0db9d2871 | 3 years ago |
张萌 | 5ed5250622 | 3 years ago |
@ -0,0 +1,204 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Dart Packages" type="DartPackagesLibraryType">
|
||||
<properties>
|
||||
<option name="packageNameToDirsMap">
|
||||
<entry key="async">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/async-2.9.0/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="boolean_selector">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="bot_toast">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/bot_toast-4.0.3/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="characters">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/characters-1.2.1/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="clock">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/clock-1.1.1/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="collection">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/collection-1.16.0/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="cupertino_icons">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.5/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="fake_async">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/fake_async-1.3.1/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="flutter">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="flutter_lints">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/flutter_lints-1.0.4/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="flutter_test">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter_test/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="lints">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/lints-1.0.1/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="matcher">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/matcher-0.12.12/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="material_color_utilities">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/material_color_utilities-0.1.5/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="meta">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/meta-1.8.0/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="path">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/path-1.8.2/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="sky_engine">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../fvm/versions/3.3.0/bin/cache/pkg/sky_engine/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="source_span">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/source_span-1.9.0/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="stack_trace">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stack_trace-1.10.0/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="stream_channel">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stream_channel-2.1.0/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="string_scanner">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/string_scanner-1.1.1/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="term_glyph">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/term_glyph-1.2.1/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="test_api">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/test_api-0.4.12/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="vector_math">
|
||||
<value>
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.2/lib" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
</option>
|
||||
</properties>
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/async-2.9.0/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/bot_toast-4.0.3/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/characters-1.2.1/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/clock-1.1.1/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/collection-1.16.0/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.5/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/fake_async-1.3.1/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/flutter_lints-1.0.4/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/lints-1.0.1/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/matcher-0.12.12/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/material_color_utilities-0.1.5/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/meta-1.8.0/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/path-1.8.2/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/source_span-1.9.0/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stack_trace-1.10.0/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stream_channel-2.1.0/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/string_scanner-1.1.1/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/term_glyph-1.2.1/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/test_api-0.4.12/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.2/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../fvm/versions/3.3.0/bin/cache/pkg/sky_engine/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter/lib" />
|
||||
<root url="file://$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter_test/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,9 +1,6 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Flutter Plugins" type="FlutterPluginsLibraryType">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$" />
|
||||
<root url="file://$PROJECT_DIR$/../flutter/.pub-cache/hosted/pub.flutter-io.cn/flutter_blue-0.8.0" />
|
||||
</CLASSES>
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1 @@
|
||||
hy_printer
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/hy_printer.iml" filepath="$PROJECT_DIR$/.idea/modules/hy_printer.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
@ -1,7 +1,15 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hy.print.hy_printer">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.hy.print.hy_printer">
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" tools:remove="android:maxSdkVersion" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
</manifest>
|
||||
|
@ -0,0 +1,372 @@
|
||||
package com.hy.print.hy_printer;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import cpcl.PrinterHelper;
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
|
||||
//import com.sewoo.port.android.BluetoothPort;
|
||||
//import com.sewoo.request.android.RequestHandler;
|
||||
|
||||
|
||||
public class Bluetooth {
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
//private BluetoothPort bluetoothPort;
|
||||
|
||||
private BroadcastReceiver connectDevice;
|
||||
private BroadcastReceiver discoveryResult;
|
||||
private BroadcastReceiver searchFinish;
|
||||
private BroadcastReceiver searchStart;
|
||||
|
||||
private Thread btThread;
|
||||
|
||||
private boolean searchflags;
|
||||
private boolean disconnectflags;
|
||||
|
||||
public void init() {
|
||||
|
||||
// bluetoothPort = BluetoothPort.getInstance();
|
||||
// bluetoothPort.SetMacFilter(false);
|
||||
bluetoothSetup();
|
||||
searchflags = false;
|
||||
disconnectflags = false;
|
||||
System.out.println("打印机蓝牙初始化完成");
|
||||
}
|
||||
|
||||
//初始化连接监听
|
||||
public void createConnectBroadcast(Context context, EventChannel.EventSink eventSink) {
|
||||
|
||||
connectDevice = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
|
||||
eventSink.success("connected");
|
||||
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
|
||||
try {
|
||||
PrinterHelper.portClose();
|
||||
// if (bluetoothPort.isConnected()) {
|
||||
// System.out.println("1111s");
|
||||
// bluetoothPort.disconnect();
|
||||
// }
|
||||
if ((btThread != null) && (btThread.isAlive())) {
|
||||
cancelThread();
|
||||
}
|
||||
System.out.println("disconnected");
|
||||
eventSink.success("disconnected");
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
context.registerReceiver(connectDevice, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));
|
||||
context.registerReceiver(connectDevice, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||
System.out.println("注册连接广播");
|
||||
}
|
||||
|
||||
public boolean isValidAddress(String address) {
|
||||
String[] btDevAddr = new String[]{"00:12:6f", "00:13:7b", "00:07:80", "88:6b:0f", "40:19:20", "00:01:90", "ec:1b:bd", "58:8e:81", "14:b4:57", "90:fd:9f", "00:0b:57", "68:0a:e2", "84:2e:14", "08:6b:d7", "60:a4:23", "cc:cc:cc", "bc:33:ac", "74:f0:7d", "84:fd:27", "84:71:27", "80:4b:50", "5c:02:72", "cc:86:ec", "2c:11:65", "b4:e3:f9", "0c:43:14", "50:32:5f", "04:cd:15", "8c:f6:81", "90:35:ea"};
|
||||
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
||||
return false;
|
||||
} else {
|
||||
for(int i = 0; i < btDevAddr.length; ++i) {
|
||||
if (btDevAddr[i].equalsIgnoreCase(address.substring(0, 8))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//初始化搜索设备监听
|
||||
public void createDiscoveryBroadcast(Context context, EventChannel.EventSink eventSink) {
|
||||
discoveryResult = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String key = "";
|
||||
BluetoothDevice remoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
String name = remoteDevice.getName();
|
||||
System.out.println(name);
|
||||
System.out.println(remoteDevice.getAddress());
|
||||
System.out.println(remoteDevice.getBluetoothClass().getMajorDeviceClass());
|
||||
if (remoteDevice != null && name != null&&remoteDevice.getBluetoothClass().getMajorDeviceClass()==1536) {
|
||||
if (remoteDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
|
||||
key = "{" + "\"name\":" + "\"" + name + "\"" + ","
|
||||
+ "\"address\":" + "\"" + remoteDevice.getAddress() + "\"" + ","
|
||||
+ "\"isPaired\":" + false
|
||||
+ "}";
|
||||
|
||||
} else {
|
||||
|
||||
key = "{" + "\"name\":" + "\"" + name + "\"" + ","
|
||||
+ "\"address\":" + "\"" + remoteDevice.getAddress() + "\"" + ","
|
||||
+ "\"isPaired\":" + true
|
||||
+ "}";
|
||||
}
|
||||
System.out.println(key);
|
||||
eventSink.success(key);
|
||||
System.out.println(key);
|
||||
// if (isValidAddress(remoteDevice.getAddress())) {
|
||||
// eventSink.success(key);
|
||||
// System.out.println(key);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
context.registerReceiver(discoveryResult, new IntentFilter(BluetoothDevice.ACTION_FOUND));
|
||||
searchStart = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
eventSink.success("start");
|
||||
System.out.println("start");
|
||||
}
|
||||
};
|
||||
context.registerReceiver(searchStart, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED));
|
||||
|
||||
searchFinish = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
eventSink.success("finish");
|
||||
searchflags = true;
|
||||
System.out.println("finish");
|
||||
}
|
||||
};
|
||||
context.registerReceiver(searchFinish, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
|
||||
System.out.println("注册搜索广播");
|
||||
}
|
||||
|
||||
//蓝牙设置
|
||||
private void bluetoothSetup() {
|
||||
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
System.out.println("不支持蓝牙");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//搜索设备
|
||||
public void SearchingBTDevice() {
|
||||
|
||||
new CheckTypesTask().execute();
|
||||
System.out.println("开始搜索");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void btConn(final String address, Context context) throws Exception {
|
||||
|
||||
System.out.println("btConn");
|
||||
|
||||
btThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
System.out.println(address);
|
||||
final int result = PrinterHelper.portOpenBT(context,address);
|
||||
PrinterHelper.logcat("portOpen result:"+ result);
|
||||
System.out.println(result);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
btThread.start();
|
||||
//final int result = PrinterHelper.portOpenBT(context,address);
|
||||
//new connBT().execute(address);
|
||||
}
|
||||
|
||||
//断开连接
|
||||
public void DisconnectDevice(Context context) {
|
||||
try {
|
||||
// bluetoothPort.disconnect();
|
||||
PrinterHelper.portClose();
|
||||
// if ((btThread != null) && (btThread.isAlive()))
|
||||
// btThread.interrupt();
|
||||
if ((btThread != null) && (btThread.isAlive())) {
|
||||
Thread dummy = btThread;
|
||||
btThread = null;
|
||||
dummy.interrupt();
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
disconnectflags = true;
|
||||
context.unregisterReceiver(connectDevice);
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//取消搜索
|
||||
public void cancelDiscoveryResult(Context context) {
|
||||
System.out.println("取消搜索");
|
||||
mBluetoothAdapter.cancelDiscovery();
|
||||
context.unregisterReceiver(discoveryResult);
|
||||
context.unregisterReceiver(searchStart);
|
||||
context.unregisterReceiver(searchFinish);
|
||||
}
|
||||
|
||||
|
||||
public void cancelThread() {
|
||||
btThread.interrupt();
|
||||
btThread = null;
|
||||
}
|
||||
|
||||
private class CheckTypesTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
mBluetoothAdapter.startDiscovery();
|
||||
super.onPreExecute();
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
while (true) {
|
||||
if (searchflags)
|
||||
break;
|
||||
|
||||
Thread.sleep(100);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
|
||||
searchflags = false;
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// class connBT extends AsyncTask<String, Void, Integer> {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// protected Integer doInBackground(String... strings) {
|
||||
// Integer retVal = null;
|
||||
//
|
||||
// //bluetoothPort.connect(strings[0]);
|
||||
//
|
||||
// retVal = Integer.valueOf(0);
|
||||
//
|
||||
// return retVal;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPreExecute() {
|
||||
//
|
||||
// super.onPreExecute();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Integer result) {
|
||||
// if (result.intValue() == 0) // Connection success.
|
||||
// {
|
||||
//// RequestHandler rh = new RequestHandler();
|
||||
//// btThread = new Thread(rh);
|
||||
//// btThread.start();
|
||||
// } else // Connection failed.
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// super.onPostExecute(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void ExcuteDisconnect(Context context) {
|
||||
// new ExcuteDisconnectBT().execute(context);
|
||||
try {
|
||||
DisconnectDevice(context);
|
||||
|
||||
while (true) {
|
||||
if (disconnectflags)
|
||||
break;
|
||||
|
||||
Thread.sleep(100);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private class ExcuteDisconnectBT extends AsyncTask<Context, Void, Void> {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground(Context... contexts) {
|
||||
// try {
|
||||
// DisconnectDevice(contexts[0]);
|
||||
//
|
||||
// while (true) {
|
||||
// if (disconnectflags)
|
||||
// break;
|
||||
//
|
||||
// Thread.sleep(100);
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPreExecute() {
|
||||
// super.onPreExecute();
|
||||
// }
|
||||
//
|
||||
// ;
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Void result) {
|
||||
// disconnectflags = false;
|
||||
// super.onPostExecute(result);
|
||||
// }
|
||||
//
|
||||
// ;
|
||||
// }
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,38 @@
|
||||
PODS:
|
||||
- Flutter (1.0.0)
|
||||
- flutter_blue (0.0.1):
|
||||
- Flutter
|
||||
- flutter_blue/Protos (= 0.0.1)
|
||||
- flutter_blue/Protos (0.0.1):
|
||||
- Flutter
|
||||
- Protobuf (~> 3.11.4)
|
||||
- hy_printer (0.0.1):
|
||||
- Flutter
|
||||
- Protobuf (3.11.4)
|
||||
|
||||
DEPENDENCIES:
|
||||
- Flutter (from `Flutter`)
|
||||
- flutter_blue (from `.symlinks/plugins/flutter_blue/ios`)
|
||||
- hy_printer (from `.symlinks/plugins/hy_printer/ios`)
|
||||
|
||||
SPEC REPOS:
|
||||
trunk:
|
||||
- Protobuf
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Flutter:
|
||||
:path: Flutter
|
||||
flutter_blue:
|
||||
:path: ".symlinks/plugins/flutter_blue/ios"
|
||||
hy_printer:
|
||||
:path: ".symlinks/plugins/hy_printer/ios"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
|
||||
flutter_blue: eeb381dc4727a0954dede73515f683865494b370
|
||||
hy_printer: 93caaf83154d80a633bd57f43cdec0bb8b14b4c2
|
||||
Protobuf: 176220c526ad8bd09ab1fb40a978eac3fef665f7
|
||||
|
||||
PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
|
||||
|
||||
COCOAPODS: 1.11.0
|
@ -0,0 +1,58 @@
|
||||
/*!
|
||||
* \~chinese
|
||||
* @header PTBitmap.h
|
||||
* @abstract 图片处理
|
||||
*
|
||||
* \~english
|
||||
* @header PTBitmap.h
|
||||
* @abstract Image manager
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import "SDKDefine.h"
|
||||
|
||||
/// 压缩模式
|
||||
typedef NS_ENUM(NSInteger,PTBitmapCompressMode) {
|
||||
|
||||
PTBitmapCompressModeNone = 0, /*! *\~chinese 不压缩 *\~english None */
|
||||
PTBitmapCompressModeZPL2 = 16, /*! *\~chinese ZPL2压缩算法 *\~english ZPL2 compress */
|
||||
PTBitmapCompressModeTIFF = 32, /*! *\~chinese TIFF压缩算法 *\~english TIFF compress */
|
||||
PTBitmapCompressModeLZO = 48, /*! *\~chinese LZO压缩算法 *\~english LZO compress */
|
||||
};
|
||||
|
||||
/// 图片效果
|
||||
typedef NS_ENUM(NSInteger, PTBitmapMode) {
|
||||
|
||||
PTBitmapModeBinary = 0, /*! *\~chinese 黑白二值图像 *\~english Binary */
|
||||
PTBitmapModeDithering = 1, /*! *\~chinese 灰阶抖动图像 *\~english Dithering */
|
||||
PTBitmapModeColumn = 2, /*! *\~chinese 无效 *\~english not supported */
|
||||
};
|
||||
|
||||
@interface PTBitmap : NSObject
|
||||
|
||||
/// 生成打印机打印图片数据
|
||||
/// @param image 图片
|
||||
/// @param mode 图片效果
|
||||
/// @param compress 压缩模式
|
||||
/// @param package 数据是否分包
|
||||
/// @param inversion 数据是否需要取反
|
||||
+ (NSData *)getImageData:(CGImageRef)image mode:(PTBitmapMode)mode compress:(PTBitmapCompressMode)compress package:(BOOL)package inversion:(BOOL)inversion;
|
||||
|
||||
|
||||
/// 用column算法生成的图片数据
|
||||
/// @param sourceBitmap 输入数据
|
||||
+ (NSData *)generateColumnData:(CGImageRef)sourceBitmap;
|
||||
|
||||
|
||||
/// 将bitmap数据转成图片
|
||||
/// @param image 图片
|
||||
/// @param mode 生成的位图数据类型 简单的黑白二值化或者抖动处理
|
||||
+ (UIImage *)generateRenderingWithImage:(CGImageRef)image mode:(PTBitmapMode)mode;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,51 @@
|
||||
/*!
|
||||
* \~chinese
|
||||
* @header PTPrinter.h
|
||||
* @abstract 打印机属性
|
||||
*
|
||||
* \~english
|
||||
* @header PTPrinter.h
|
||||
* @abstract Printer properties
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import "PTRouter.h"
|
||||
|
||||
/// 打印机的连接模块
|
||||
typedef NS_ENUM(NSInteger, PTPrinterModule) {
|
||||
|
||||
PTPrinterModuleUnknown = 0, /// 未知类型
|
||||
PTPrinterModuleBLE = 1, /// 蓝牙
|
||||
PTPrinterModuleWiFi = 2, /// 无线
|
||||
PTPrinterModuleBoth = 3, /// 蓝牙和无线
|
||||
};
|
||||
|
||||
@interface PTPrinter : NSObject<NSCoding>
|
||||
|
||||
/// 打印机名称
|
||||
@property(strong,nonatomic,readwrite) NSString *name;
|
||||
/// 打印机mac地址
|
||||
@property(strong,nonatomic,readwrite) NSString *mac;
|
||||
/// 打印机蓝牙模块
|
||||
@property(assign,nonatomic,readwrite) PTPrinterModule module;
|
||||
/// 发现蓝牙时获取到的广播信息
|
||||
@property(strong,nonatomic,readwrite) NSDictionary *advertisement;
|
||||
/// 蓝牙外设UUID
|
||||
@property(strong,nonatomic,readwrite) NSString *uuid;
|
||||
/// 发现外设时获取到的信号强度值,单位分贝
|
||||
@property(strong,nonatomic,readwrite) NSNumber *rssi;
|
||||
/// 信号强度等级分0-5级
|
||||
@property(strong,nonatomic,readwrite) NSNumber *strength;
|
||||
/// 由信号强度计算的距离
|
||||
@property(strong,nonatomic,readwrite) NSNumber *distance;
|
||||
/// 蓝牙外设
|
||||
@property(strong,nonatomic,readwrite) CBPeripheral *peripheral;
|
||||
/// 外设的ip地址
|
||||
@property(strong,nonatomic,readwrite) NSString *ip;
|
||||
/// 端口
|
||||
@property(strong,nonatomic,readwrite) NSString *port;
|
||||
|
||||
- (instancetype)initWithPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI;
|
||||
|
||||
@end
|
@ -0,0 +1,96 @@
|
||||
/*!
|
||||
* \~chinese
|
||||
* @header PTRouter.h
|
||||
* @abstract 路由器属性
|
||||
*
|
||||
* \~english
|
||||
* @header PTRouter.h
|
||||
* @abstract Router properties
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface PTRouter : NSObject
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 广播地址
|
||||
*
|
||||
* \~english
|
||||
* Broadcast address
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *broadcastIP;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 本机地址
|
||||
*
|
||||
* \~english
|
||||
* Local address
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *localIP;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 子网掩码
|
||||
*
|
||||
* \~english
|
||||
* Netmask
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *netmask;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 接口
|
||||
*
|
||||
* \~english
|
||||
* Interface
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *interface;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 网关
|
||||
*
|
||||
* \~english
|
||||
* Gateway
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *gateway;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 是否连接路由器
|
||||
*
|
||||
* \~english
|
||||
* Whether to connect to the router
|
||||
*/
|
||||
@property(assign,nonatomic,readwrite) BOOL connected;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* mac地址
|
||||
*
|
||||
* \~english
|
||||
* Mac
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *MAC;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 热点名称
|
||||
*
|
||||
* \~english
|
||||
* ssid
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *SSID;
|
||||
|
||||
/*!
|
||||
* \~chinese
|
||||
* 热点详情
|
||||
*
|
||||
* \~english
|
||||
* SSIDDATA
|
||||
*/
|
||||
@property(strong,nonatomic,readwrite) NSString *SSIDDATA;
|
||||
|
||||
@end
|
@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
#import <UIKit/UIKit.h>
|
||||
#elif TARGET_OS_MAC
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
|
||||
#import <Foundation/NSObjCRuntime.h>
|
||||
|
||||
//! Project version number for PrinterSDK.
|
||||
FOUNDATION_EXPORT double PrinterSDKVersionNumber;
|
||||
|
||||
//! Project version string for PrinterSDK.
|
||||
FOUNDATION_EXPORT const unsigned char PrinterSDKVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <PrinterSDK/PublicHeader.h>
|
||||
|
||||
/*! *\~chinese ESC指令 *\~english ESC command */
|
||||
#import <PrinterSDK/PTCommandESC.h>
|
||||
|
||||
/*! *\~chinese TSPL指令 *\~english TSPL command */
|
||||
#import <PrinterSDK/PTCommandTSPL.h>
|
||||
|
||||
/*! *\~chinese ZPL指令 *\~english ZPL command */
|
||||
#import <PrinterSDK/PTCommandZPL.h>
|
||||
|
||||
/*! *\~chinese CPCL指令 *\~english CPCL command */
|
||||
#import <PrinterSDK/PTCommandCPCL.h>
|
||||
#import <PrinterSDK/PTLabel.h>
|
||||
|
||||
#import <PrinterSDK/PTCommandCommon.h>
|
||||
#import <PrinterSDK/PTOldCommandCPCL.h>
|
||||
#import <PrinterSDK/PTOldCommandTSPL.h>
|
||||
|
||||
/*! *\~chinese 图片处理 *\~english image manager */
|
||||
#import <PrinterSDK/PTBitmap.h>
|
||||
#import <PrinterSDK/PTBitmap+GrayLevel.h>
|
||||
#import <PrinterSDK/PTEncode.h>
|
||||
|
||||
// Dispatch
|
||||
|
||||
/*! *\~chinese 通讯 *\~english Communication */
|
||||
#import <PrinterSDK/PTDispatcher.h>
|
||||
#import <PrinterSDK/PTPrinter.h>
|
||||
#import <PrinterSDK/PTRouter.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
#ifndef PublicDefine_h
|
||||
#define PublicDefine_h
|
||||
|
||||
#ifdef DEBUG
|
||||
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
|
||||
#else
|
||||
#define NSLog(...)
|
||||
#endif
|
||||
|
||||
#endif /* PublicDefine_h */
|
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
framework module PrinterSDK {
|
||||
umbrella header "PrinterSDK.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
Binary file not shown.
@ -1,9 +1,11 @@
|
||||
class Device {
|
||||
final String name;
|
||||
final String address;
|
||||
String name;
|
||||
String address;
|
||||
bool isPaired;
|
||||
|
||||
const Device({
|
||||
Device({
|
||||
required this.name,
|
||||
required this.address,
|
||||
required this.isPaired,
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
// enum PRINT_STATUS {
|
||||
// normal,
|
||||
// busy,
|
||||
// paperEmpty,
|
||||
// coverOpen,
|
||||
// batteryLow,
|
||||
// }
|
||||
enum PRINT_STATUS {
|
||||
normal,
|
||||
fail,
|
||||
paperEmpty,
|
||||
coverOpen,
|
||||
}
|
Loading…
Reference in new issue