lines-num lines-num-old"> 88
-    public void onNewDeviceDiscovered() {
89
-
103
+    public void onNewDeviceDiscovered(BluetoothDevice device) {
104
+        newDeviceAdapter.addDevice(device);
90 105
     }
91 106
 
107
+
92 108
     @Override
93 109
     public void onPrinterTestPageFail() {
94 110
 
95 111
     }
96 112
 
97 113
     @Override
98
-    public void onPairedDeviceDiscovered() {
114
+    public void onPairedDeviceDiscovered(List<BluetoothDevice> devices) {
115
+        pairedDeviceAdapter.setDeviceList((ArrayList<BluetoothDevice>)devices);
116
+    }
117
+
99 118
 
119
+    @Override
120
+    public void showToast(String msg) {
121
+        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
100 122
     }
101 123
 
102 124
     @OnClick(R.id.tv_print_test)
103 125
     void testPrint(){
104 126
         presenter.printTestPage();
105 127
     }
128
+
129
+    @OnCheckedChanged(R.id.tb_bluetooth_switch)
130
+    void switchBluetooth(){
131
+        if(!presenter.queryBluetoothStatus()){
132
+            Intent enableIntent = new Intent(
133
+                    BluetoothAdapter.ACTION_REQUEST_ENABLE);
134
+            startActivityForResult(enableIntent,
135
+                    REQUEST_ENABLE_BT);
136
+        }else{
137
+            BluetoothAdapter.getDefaultAdapter().disable();
138
+            onBluetoothDisabled();
139
+        }
140
+    }
141
+
142
+    @Override
143
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
144
+        super.onActivityResult(requestCode, resultCode, data);
145
+        if(resultCode == Activity.RESULT_OK){
146
+            if(requestCode == REQUEST_ENABLE_BT){
147
+                onBluetoothEnabled();
148
+                onPairedDeviceDiscovered(presenter.queryPairedDevices());
149
+                presenter.discoverNewDevices();
150
+                presenter.queryPrinterStatus();
151
+            }else if(requestCode == REQUEST_CONNECT_DEVICE){
152
+
153
+            }
154
+        }
155
+    }
156
+
106 157
 }

+ 10 - 6
app/src/main/java/ai/pai/lensman/printer/PrinterSettingContract.java

@@ -1,5 +1,9 @@
1 1
 package ai.pai.lensman.printer;
2 2
 
3
+import android.bluetooth.BluetoothDevice;
4
+
5
+import java.util.List;
6
+
3 7
 /**
4 8
  * Created by chengzhenyu on 2016/9/1.
5 9
  */
@@ -11,12 +15,11 @@ public class PrinterSettingContract {
11 15
         void stop();
12 16
         void queryPrinterStatus();
13 17
         void printTestPage();
14
-        void queryBluetoothStatus();
15
-        void enableBluetooth();
16
-        void disableBluetooth();
17
-        void queryPairedDevices();
18
+        boolean queryBluetoothStatus();
19
+        List<BluetoothDevice> queryPairedDevices();
18 20
         void discoverNewDevices();
19 21
         void connectPrinter();
22
+        void cancelDiscovery();
20 23
     }
21 24
 
22 25
     public interface View{
@@ -26,8 +29,9 @@ public class PrinterSettingContract {
26 29
         void onPrinterError(String error);
27 30
         void onPrinterConnected();
28 31
         void onPrinterDisconnected();
29
-        void onNewDeviceDiscovered();
32
+        void onNewDeviceDiscovered(BluetoothDevice device);
30 33
         void onPrinterTestPageFail();
31
-        void onPairedDeviceDiscovered();
34
+        void onPairedDeviceDiscovered(List<BluetoothDevice> devices);
35
+        void showToast(String msg);
32 36
     }
33 37
 }

+ 65 - 13
app/src/main/java/ai/pai/lensman/printer/PrinterSettingPresenter.java

@@ -1,6 +1,15 @@
1 1
 package ai.pai.lensman.printer;
2 2
 
3
+import android.bluetooth.BluetoothAdapter;
4
+import android.bluetooth.BluetoothDevice;
5
+import android.content.BroadcastReceiver;
3 6
 import android.content.Context;
7
+import android.content.Intent;
8
+import android.content.IntentFilter;
9
+
10
+import java.util.List;
11
+
12
+import ai.pai.lensman.R;
4 13
 
5 14
 /**
6 15
  * Created by chengzhenyu on 2016/9/1.
@@ -10,20 +19,29 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
10 19
 
11 20
     private Context context;
12 21
     private PrinterSettingContract.View view;
22
+    private  BluetoothAdapter bluetoothAdapter;
13 23
 
14 24
     public PrinterSettingPresenter(Context context, PrinterSettingContract.View view){
15 25
         this.view = view;
16 26
         this.context = context;
27
+        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
17 28
     }
18 29
 
19 30
     @Override
20 31
     public void start() {
21
-
32
+        if(queryBluetoothStatus()){
33
+            view.onBluetoothEnabled();
34
+            view.showToast(context.getString(R.string.query_processing));
35
+            queryPrinterStatus();
36
+        }else{
37
+            view.onBluetoothDisabled();
38
+            view.showToast(context.getString(R.string.bt_is_disabled));
39
+        }
22 40
     }
23 41
 
24 42
     @Override
25 43
     public void stop() {
26
-
44
+        cancelDiscovery();
27 45
     }
28 46
 
29 47
     @Override
@@ -37,32 +55,66 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
37 55
     }
38 56
 
39 57
     @Override
40
-    public void queryBluetoothStatus() {
41
-
58
+    public boolean queryBluetoothStatus() {
59
+        if(bluetoothAdapter==null){
60
+            return false;
61
+        }
62
+        return bluetoothAdapter.isEnabled();
42 63
     }
43 64
 
44 65
     @Override
45
-    public void enableBluetooth() {
66
+    public List<BluetoothDevice> queryPairedDevices() {
67
+        return (List<BluetoothDevice>) bluetoothAdapter.getBondedDevices();
46 68
 
47 69
     }
48 70
 
49 71
     @Override
50
-    public void disableBluetooth() {
51
-
72
+    public void discoverNewDevices() {
73
+        // Register for broadcasts when a device is discovered
74
+        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
75
+        context.registerReceiver(mFindBlueToothReceiver, filter);
76
+        // Register for broadcasts when discovery has finished
77
+        filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
78
+        context.registerReceiver(mFindBlueToothReceiver, filter);
79
+        bluetoothAdapter.startDiscovery();
52 80
     }
53 81
 
54 82
     @Override
55
-    public void queryPairedDevices() {
83
+    public void connectPrinter() {
56 84
 
57 85
     }
58 86
 
59 87
     @Override
60
-    public void discoverNewDevices() {
61
-
88
+    public void cancelDiscovery() {
89
+        try{
90
+            bluetoothAdapter.cancelDiscovery();
91
+            context.unregisterReceiver(mFindBlueToothReceiver);
92
+        }catch (Exception e){
93
+            e.printStackTrace();
94
+        }
62 95
     }
63 96
 
64
-    @Override
65
-    public void connectPrinter() {
97
+    // changes the title when discovery is finished
98
+    private final BroadcastReceiver mFindBlueToothReceiver = new BroadcastReceiver() {
99
+        @Override
100
+        public void onReceive(Context context, Intent intent) {
101
+            String action = intent.getAction();
102
+            // When discovery finds a device
103
+            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
104
+                // Get the BluetoothDevice object from the Intent
105
+                BluetoothDevice device = intent
106
+                        .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
107
+                // If it's already paired, skip it, because it's been listed
108
+                // already
109
+                if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
110
+                    view.onNewDeviceDiscovered(device);
111
+                }
112
+                // When discovery is finished, change the Activity title
113
+            } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED
114
+                    .equals(action)) {
115
+                view.showToast(context.getString(R.string.bt_discover_complete));
116
+            }
117
+        }
118
+    };
66 119
 
67
-    }
68 120
 }

+ 1 - 1
app/src/main/res/layout/activity_printer_setting.xml

@@ -165,7 +165,7 @@
165 165
         </LinearLayout>
166 166
 
167 167
         <ListView
168
-            android:id="@+id/list_bt_devices"
168
+            android:id="@+id/listview_bt_devices"
169 169
             android:layout_width="match_parent"
170 170
             android:layout_height="match_parent"
171 171
             android:background="@color/white"

+ 28 - 13
app/src/main/res/layout/layout_bt_device_list_item.xml

@@ -1,23 +1,38 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-    android:orientation="vertical" android:layout_width="match_parent"
3
+    android:layout_width="match_parent"
4 4
     android:layout_height="wrap_content"
5
-    android:paddingTop="4dp"
6
-    android:paddingBottom="4dp">
5
+    android:orientation="horizontal"
6
+    android:paddingBottom="4dp"
7
+    android:paddingTop="4dp">
7 8
 
8
-    <TextView
9
-        android:id="@+id/tv_device_name"
10
-        android:layout_width="wrap_content"
9
+    <LinearLayout
10
+        android:layout_width="0dp"
11 11
         android:layout_height="wrap_content"
12
-        android:textSize="14sp"
13
-        android:textColor="@color/dark_grey"/>
12
+        android:layout_gravity="center_vertical"
13
+        android:layout_weight="1">
14
+
15
+        <TextView
16
+            android:id="@+id/tv_device_name"
17
+            android:layout_width="wrap_content"
18
+            android:layout_height="wrap_content"
19
+            android:textColor="@color/dark_grey"
20
+            android:textSize="14sp" />
21
+
22
+        <TextView
23
+            android:id="@+id/tv_device_mac"
24
+            android:layout_width="wrap_content"
25
+            android:layout_height="wrap_content"
26
+            android:paddingTop="3dp"
27
+            android:textColor="@color/grey"
28
+            android:textSize="12sp" />
29
+    </LinearLayout>
14 30
 
15 31
     <TextView
16
-        android:id="@+id/tv_device_mac"
32
+        android:id="@+id/tv_device_status"
17 33
         android:layout_width="wrap_content"
18 34
         android:layout_height="wrap_content"
19
-        android:paddingTop="3dp"
20
-        android:textSize="12sp"
21
-        android:textColor="@color/grey"/>
22
-
35
+        android:layout_gravity="center_vertical"
36
+        android:textColor="@color/grey"
37
+        android:textSize="14sp" />
23 38
 </LinearLayout>

+ 3 - 1
app/src/main/res/values/strings.xml

@@ -69,7 +69,7 @@
69 69
 
70 70
     <string name="printer_status">打印机状态</string>
71 71
 
72
-    <string name="query_processing">正在查询</string>
72
+    <string name="query_processing">正在查询打印机状态</string>
73 73
 
74 74
     <string name="print_test">打印测试页</string>
75 75
 
@@ -85,6 +85,8 @@
85 85
 
86 86
     <string name="paired_devices">已配对设备</string>
87 87
 
88
+    <string name="bt_discover_complete">蓝牙设备搜索完成</string>
89
+
88 90
     <string name="new_usable_devices">新可用设备</string>
89 91
 
90 92
     <string name="printer_is_ok">打印机工作正常</string>

kodo - Gogs: Go Git Service

暫無描述

FFIB: 765fc4a615 update 6 月之前
..
0001_initial.py aa31a5f59a Add kodo 8 年之前
0002_auto_20180104_0414.py 018d52f61d Update package django_xxx 8 年之前
0003_auto_20180104_0428.py 9ec76d526a TextField => CharField 8 年之前
0004_latestappinfo.py 018d52f61d Update package django_xxx 8 年之前
0005_auto_20180115_0021.py 49634dc097 Add api operator login 8 年之前
0006_auto_20180115_0047.py 49634dc097 Add api operator login 8 年之前
0007_consumeinfosubmitloginfo.py 1b1f0192f8 ConsumeInfoSubmitLogInfo 8 年之前
0008_auto_20180129_0422.py a77c4993f8 FloatField 8 年之前
0009_auto_20180129_0426.py e04f95dc5e long => lon 8 年之前
0010_modelinfo_integral.py 71993af1e4 Add integral for ModelInfo 8 年之前
0011_modelinfo_model_full_name.py 145973f8f0 Add brand_full_name for BrandInfo 8 年之前
0012_auto_20180401_2012.py f1260953bf Move image/url from ModelImageInfo to ModelInfo 8 年之前
0013_consumeinfosubmitloginfo_test_user.py e47aa7f8c4 Add field test_user 8 年之前
0014_auto_20180508_1058.py c7b55979c0 Add province code/name for DistributorInfo 8 年之前
0015_auto_20180508_1433.py d10bd672ea AdministratorInfo/BrandModelDistributorPriceInfo 8 年之前
0016_auto_20180508_1507.py d10bd672ea AdministratorInfo/BrandModelDistributorPriceInfo 8 年之前
0017_auto_20180508_1830.py 537c495621 Statistic 8 年之前
0018_auto_20180514_1519.py 62948fb5c3 Operator add/delete/update/list 8 年之前
0019_saleclerkinfo.py 137ed6dee2 Clerk add/delete/update/list 8 年之前
0020_auto_20180517_1819.py 2988703c52 Update 8 年之前
0021_auto_20180522_1100.py e7dcf47e22 SaleclerkInfo 8 年之前
0022_auto_20180522_1355.py b90bf186bc brand_domain 8 年之前
0023_auto_20180826_0448.py 3f9969cafc Support scan jancode 8 年之前
0024_latestappscreeninfo.py 900c3fd386 Makemigrations 8 年之前
0025_auto_20180917_1554.py 9c585b197e Mch migrations 8 年之前
0026_auto_20180930_1159.py 66a598b30c Makemigrations 8 年之前
0027_distributorinfo_distributor_short_name.py deb84bfcb5 Makemigrations 8 年之前
0028_consumeinfosubmitloginfo_dupload.py e9f8a35b9d Makemigrations 8 年之前
0029_auto_20181117_0052.py b8784eee8a Makemigrations 8 年之前
0030_auto_20190301_1402.py ff3a23ccf0 Activity 7 年之前
0031_activityinfo_model_uni_names.py ded4db2cda activityinfo_model_uni_names 7 年之前
0032_auto_20190521_1544.py 5a8859fa5e Makemigrations 7 年之前
0033_consumeinfosubmitloginfo_activity_id.py 3ade638ea3 Makemigrations 7 年之前
0034_auto_20190620_1709.py d666c88eac COUPON_EXPIRED_TIME_TUPLE 7 年之前
0035_auto_20190625_1443.py 219acdedb1 Add field has_used 7 年之前
0036_auto_20190701_1441.py 77c612316a queryusedsn 7 年之前
0037_auto_20190826_1537.py 8d998319f7 Makemigrations 7 年之前
0038_auto_20190826_1625.py 9db41fee66 default False 7 年之前
0039_auto_20191119_1348.py 3d0d214667 :sparkles: Member Infos 7 年之前
0040_modelinfo_shot_member_name.py 4ce7f5c87b :art: Member Relative APIs 7 年之前
0041_activityinfo_coupon_id.py a8239c077f :art: CouponInfo for coupon app 6 年之前
0042_auto_20200113_1832.py 212f24c882 MarketCode 6 年之前
0043_modelcamerabodyinfo.py 72656ceaff :art: model/cameras 6 年之前
0044_modelcamerabodyinfo_camera_brand_name.py 9619c195e6 :art: Makemigrations 6 年之前
0045_auto_20200304_1826.py dccd94c448 :art: Opt api model/cameras 6 年之前
0046_cameramodelinfo.py dccd94c448 :art: Opt api model/cameras 6 年之前
0047_auto_20200304_1848.py dccd94c448 :art: Opt api model/cameras 6 年之前
0048_modelcamerabodyinfo_is_important.py 43455cdf4e :art: Support is_important 6 年之前
0049_modelcamerabodyinfo_camera_market_time.py da799e7af6 :art: Add field camera_market_time for CameraModelInfo/ModelCameraBodyInfo 6 年之前
0050_cameramodelinfo_camera_market_time.py da799e7af6 :art: Add field camera_market_time for CameraModelInfo/ModelCameraBodyInfo 6 年之前
0051_auto_20200314_2340.py 7dc0b7fc6b :art: Makemigrations 6 年之前
0052_consumeinfosubmitloginfo_code_version.py 03631cb847 add code_version 6 年之前
0053_auto_20200407_1118.py 608bdf8508 makemigrations 6 年之前
0054_auto_20200411_2143.py 58c38a0546 整理 优惠券 6 年之前
0055_auto_20200601_1634.py 89c3cefcc7 saleclerk migrate 6 年之前
0056_auto_20200601_1640.py 3872355991 add department_name 6 年之前
0057_auto_20200602_1403.py 11df57b63d support qy login 6 年之前
0058_auto_20201202_1203.py 6a9e324f6f :art: Re Makemigrations 5 年之前
0059_auto_20201221_1115.py 4ba79f76cd 后台管理,添加运营人员角色 5 年之前
0060_modelinfo_is_show_shot.py 45f886651e 添加 is_show_shot 用于控制是否在前端显示 5 年之前
0061_consumeinfosubmitloginfo_integral.py 39290e111b ConsumeInfoSubmitLogInfo 记录用户积分 5 年之前
0062_distributorinfo_office.py 8dcde2c80c 销售员提交新增事务所和销售担当,以及经销商ID 5 年之前
0063_auto_20210915_1653.py 414cc1ada2 :art: back_express_name / back_tracking_number 5 年之前
0064_alter_modelinfo_display.py 28f8bc3cb9 :art: Models update for tenancy 4 年之前
0065_auto_20221118_1657.py 7f990a3af6 增加型号卡口, 4 年之前
0066_auto_20230208_1344.py ed0e1dba9a 清除一些无用字段 3 年之前
0067_consumeshotunbindinginfo.py 0a9dd97a7e 增加解绑功能 3 年之前
0068_alter_consumeshotunbindinginfo_reason.py 0a9dd97a7e 增加解绑功能 3 年之前
0069_auto_20230302_1754.py c25c1f86d3 处理解绑后,再次扫码,不发放相关权益 3 年之前
0070_alter_administratorinfo_admin_type.py 765fc4a615 update 6 月之前
__init__.py aa31a5f59a Add kodo 8 年之前