rhodes 2.1.0 → 2.2.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.textile +4 -5
- data/Rakefile +8 -1
- data/lib/build/jake.rb +22 -16
- data/lib/extensions/rhoxml/rexml/cdata.rb +67 -0
- data/lib/extensions/rhoxml/rexml/document.rb +2 -116
- data/lib/extensions/rhoxml/rexml/element.rb +1 -1
- data/lib/extensions/rhoxml/rexml/text.rb +117 -0
- data/lib/framework/rho/render.rb +19 -11
- data/lib/framework/rho/rho.rb +17 -10
- data/lib/framework/rho/rhobluetooth.rb +103 -0
- data/lib/framework/rho/rhocontroller.rb +2 -0
- data/lib/framework/rho/rhoevent.rb +43 -0
- data/lib/framework/rho/rhoevent_bb.rb +80 -0
- data/lib/framework/rho/rhoevent_c.rb +47 -0
- data/lib/framework/rhodes.rb +2 -2
- data/lib/framework/rhom/rhom_db_adapter.rb +2 -1
- data/lib/framework/rhom/rhom_model.rb +9 -3
- data/lib/framework/rhom/rhom_object_factory.rb +46 -22
- data/lib/framework/rhom/rhom_source.rb +12 -10
- data/lib/framework/version.rb +2 -2
- data/lib/rhodes.rb +2 -2
- data/platform/android/Rhodes/AndroidManifest.xml +23 -2
- data/platform/android/Rhodes/gen/com/rhomobile/rhodes/R.java +54 -38
- data/platform/android/Rhodes/jni/include/rhodes.h +3 -0
- data/platform/android/Rhodes/jni/include/rhodes/JNIRhodes.h +2 -2
- data/platform/android/Rhodes/jni/include/rhodes/details/rhojava.inc +4 -0
- data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_RhodesService.h +16 -0
- data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_bluetooth_RhoBluetoothManager.h +21 -0
- data/platform/android/Rhodes/jni/src/bluetooth.cpp +169 -0
- data/platform/android/Rhodes/jni/src/callbacks.cpp +10 -0
- data/platform/android/Rhodes/jni/src/event.cpp +429 -0
- data/platform/android/Rhodes/jni/src/fileapi.cpp +51 -1
- data/platform/android/Rhodes/jni/src/rhodes.cpp +16 -0
- data/platform/android/Rhodes/jni/src/sslimpl.cpp +3 -0
- data/platform/android/Rhodes/res/layout/bt_device_list.xml +42 -0
- data/platform/android/Rhodes/res/layout/bt_device_name.xml +7 -0
- data/platform/android/Rhodes/res/values/strings.xml +8 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/AndroidR.java +14 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Capabilities.java +2 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Push.java +7 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushReceiver.java +58 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushService.java +53 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/Rhodes.java +8 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +144 -3
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/IRhoBluetoothManager.java +66 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothDeviceListActivity.java +201 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManager.java +139 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManagerNew.java +401 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothManagerOld.java +136 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothSession.java +457 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/UUIDHelper.java +71 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/camera/ImageCapture.java +12 -7
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/Event.java +19 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/EventStore.java +261 -0
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +4 -2
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +2 -2
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/MailUriHandler.java +10 -2
- data/platform/android/build/RhodesSRC_build.files +33 -22
- data/platform/android/build/android.rake +198 -27
- data/platform/android/build/librhodes_build.files +3 -1
- data/platform/android/build/libruby_build.files +4 -1
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java +2 -2
- data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBRowResult.java +1 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/Expression.java +7 -4
- data/platform/bb/Hsqldb/src/org/hsqldb/Like.java +3 -3
- data/platform/bb/Hsqldb/src/org/hsqldb/Table.java +3 -1
- data/platform/bb/Hsqldb/src/org/hsqldb/Tokenizer.java +1 -1
- data/platform/bb/RubyVM/RubyVM.jdp +1 -0
- data/platform/bb/RubyVM/src/com/rho/RhoConf.java +108 -1
- data/platform/bb/RubyVM/src/com/rho/RhoLogConf.java +7 -1
- data/platform/bb/RubyVM/src/com/rho/RhoRuby.java +7 -4
- data/platform/bb/RubyVM/src/com/rho/ThreadQueue.java +7 -1
- data/platform/bb/RubyVM/src/com/rho/net/AsyncHttp.java +1 -1
- data/platform/bb/RubyVM/src/com/rho/net/NetRequest.java +21 -23
- data/platform/bb/RubyVM/src/com/rho/net/RhoConnection.java +19 -10
- data/platform/bb/RubyVM/src/com/rho/sync/SyncEngine.java +8 -0
- data/platform/bb/RubyVM/src/com/rho/sync/SyncNotify.java +3 -0
- data/platform/bb/RubyVM/src/com/rho/sync/SyncThread.java +14 -17
- data/platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyFile.java +7 -5
- data/platform/bb/RubyVM/src/com/xruby/runtime/lang/RhoSupport.java +2 -0
- data/platform/bb/RubyVM/src/com/xruby/runtime/lang/RubyRuntime.java +10 -1
- data/platform/bb/RubyVM/src/j2me/io/File.java +7 -6
- data/platform/bb/build/RubyVM_build.files +412 -412
- data/platform/bb/build/bb.rake +42 -18
- data/platform/bb/build/hsqldb_build.files +151 -151
- data/platform/bb/build/rhodes_build.files +44 -40
- data/platform/bb/rhodes/platform/5.0/com/rho/BrowserAdapter5.java +2 -0
- data/platform/bb/rhodes/platform/5.0/com/rho/RhodesApplicationPlatform.java +237 -0
- data/platform/bb/rhodes/platform/common/com/rho/RhodesApplicationPlatform.java +14 -0
- data/platform/bb/rhodes/rhodes.jdp +6 -1
- data/platform/bb/rhodes/src/com/rho/RhoRubyHelper.java +7 -1
- data/platform/bb/rhodes/src/com/rho/RhodesApplicationPlatform.java +14 -0
- data/platform/bb/rhodes/src/com/rho/net/NetworkAccess.java +62 -76
- data/platform/bb/rhodes/src/com/rho/rubyext/RhoCalendar.java +660 -0
- data/platform/bb/rhodes/src/{rhomobile → com/rho/rubyext}/RhoPhonebook.java +95 -38
- data/platform/bb/rhodes/src/com/rho/rubyext/System.java +22 -1
- data/platform/bb/rhodes/src/rhomobile/PushListeningThread.java +26 -6
- data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +21 -7
- data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothManager.java +528 -0
- data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothPort.java +281 -0
- data/platform/bb/rhodes/src/rhomobile/bluetooth/BluetoothScreen.java +119 -0
- data/platform/bb/rhodes/src/rhomobile/camera/CameraFilesListener.java +2 -2
- data/platform/iphone/Classes/AppManager/AppManager.m +70 -7
- data/platform/iphone/Classes/Bluetooth/Bluetooth.h +72 -0
- data/platform/iphone/Classes/Bluetooth/Bluetooth.m +414 -0
- data/platform/iphone/Classes/Event/Event.h +12 -0
- data/platform/iphone/Classes/Event/Event.m +300 -0
- data/platform/iphone/Classes/LogOptionsController.h +2 -1
- data/platform/iphone/Classes/LogOptionsController.m +1 -1
- data/platform/iphone/Classes/LogViewController.h +2 -1
- data/platform/iphone/Classes/MapView/MapViewController.h +2 -1
- data/platform/iphone/Classes/RhoViewController.h +16 -0
- data/platform/iphone/Classes/RhoViewController.m +20 -0
- data/platform/iphone/Classes/Rhodes.h +12 -0
- data/platform/iphone/Classes/Rhodes.m +34 -6
- data/platform/iphone/Classes/Signature/SignatureViewController.h +2 -2
- data/platform/iphone/Classes/Signature/SignatureViewController.m +0 -10
- data/platform/iphone/Classes/SimpleMainView.h +2 -2
- data/platform/iphone/Classes/SimpleMainView.m +5 -14
- data/platform/iphone/Classes/SplashViewController.h +2 -2
- data/platform/iphone/Classes/TabbedMainView.h +2 -2
- data/platform/iphone/Classes/TabbedMainView.m +5 -10
- data/platform/iphone/Info.plist +5 -5
- data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +39 -0
- data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +47 -4
- data/platform/osx/Rhodes Debugger/NoodleLineNumberView.m +3 -2
- data/platform/shared/common/AutoPointer.h +3 -0
- data/platform/shared/common/RhoConf.cpp +2 -1
- data/platform/shared/common/RhoThread.h +1 -1
- data/platform/shared/common/RhoTime.h +3 -3
- data/platform/shared/common/RhodesApp.cpp +75 -23
- data/platform/shared/common/RhodesApp.h +4 -0
- data/platform/shared/common/RhodesAppBase.h +2 -0
- data/platform/shared/common/ThreadQueue.cpp +23 -18
- data/platform/shared/common/ThreadQueue.h +2 -0
- data/platform/shared/db/res/db/syncdb.schema +39 -39
- data/platform/shared/logging/RhoLogConf.cpp +58 -3
- data/platform/shared/logging/RhoLogConf.h +3 -1
- data/platform/shared/net/CURLNetRequest.cpp +17 -6
- data/platform/shared/net/HttpServer.cpp +125 -25
- data/platform/shared/net/HttpServer.h +4 -3
- data/platform/shared/ruby/ext/bluetooth/bluetooth.i +56 -0
- data/platform/shared/ruby/ext/bluetooth/bluetooth_wrap.c +2563 -0
- data/platform/shared/ruby/ext/calendar/calendar.i +28 -0
- data/platform/shared/ruby/ext/calendar/calendar_wrap.c +2251 -0
- data/platform/shared/ruby/ext/calendar/event.h +41 -0
- data/platform/shared/ruby/ext/calendar/event.i +28 -0
- data/platform/shared/ruby/ext/calendar/event_wrap.c +2151 -0
- data/platform/shared/ruby/ext/rho/rhoruby.c +103 -3
- data/platform/shared/ruby/ext/rho/rhoruby.h +16 -2
- data/platform/shared/ruby/ext/rhoconf/rhoconf.i +12 -0
- data/platform/shared/ruby/ext/rhoconf/rhoconf_wrap.c +101 -0
- data/platform/shared/ruby/ext/system/system.i +14 -0
- data/platform/shared/ruby/ext/system/system_wrap.c +2568 -2208
- data/platform/shared/ruby/main.c +8 -0
- data/platform/shared/rubyext/GeoLocation.cpp +6 -3
- data/platform/shared/rubyext/System.cpp +14 -0
- data/platform/shared/sync/SyncEngine.cpp +9 -1
- data/platform/shared/sync/SyncNotify.cpp +16 -8
- data/platform/shared/sync/SyncNotify.h +1 -0
- data/platform/shared/sync/SyncThread.cpp +7 -12
- data/platform/shared/sync/SyncThread.h +5 -3
- data/platform/wm/build/wm.rake +7 -1
- data/platform/wm/rhodes/Alert.cpp +1 -1
- data/platform/wm/rhodes/MainWindow.cpp +28 -0
- data/platform/wm/rhodes/MainWindow.h +9 -0
- data/platform/wm/rhodes/OutlookApp.cpp +72 -0
- data/platform/wm/rhodes/OutlookApp.h +22 -0
- data/platform/wm/rhodes/Rhodes.cpp +8 -0
- data/platform/wm/rhodes/Rhodes.rc +31 -0
- data/platform/wm/rhodes/bluetooth/Bluetooth.cpp +1274 -0
- data/platform/wm/rhodes/bluetooth/Bluetooth.h +321 -0
- data/platform/wm/rhodes/phonebook/NativeAddressBook.cpp +37 -70
- data/platform/wm/rhodes/phonebook/NativeAddressBook.h +0 -4
- data/platform/wm/rhodes/resource.h +8 -1
- data/platform/wm/rhodes/rho/net/NetRequest.cpp +4 -0
- data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +6 -4
- data/platform/wm/rhodes/rho/rubyext/calendar.cpp +487 -0
- data/platform/wm/rhodes/rhodes.vcproj +28 -11
- data/platform/wm/rhodes/stdafx.h +1 -0
- data/platform/wm/rubylib/rubylib.vcproj +32 -0
- data/rakefile.rb +8 -1
- data/res/generators/templates/application/Rakefile +1 -1
- data/res/generators/templates/application/app/layout.erb +4 -1
- data/res/generators/templates/application/build.yml +0 -1
- data/res/generators/templates/application/public/css/iphone.css +2 -2
- data/res/generators/templates/application/public/jqtouch/jqtouch-iphone.css +9 -0
- data/res/generators/templates/application/public/jqtouch/jqtouch.css +1 -5
- data/res/generators/templates/application/public/jqtouch/jqtouch.js +3 -2
- data/rhodes.gemspec +1 -1
- data/spec/perfomance_spec/app/Benchmark/benchmark.rb +4 -0
- data/spec/perfomance_spec/app/Benchmark/bulk_results.erb +13 -0
- data/spec/perfomance_spec/app/Benchmark/controller.rb +178 -0
- data/spec/perfomance_spec/app/Benchmark/create_results.erb +13 -0
- data/spec/perfomance_spec/app/Benchmark/customers.erb +35 -0
- data/spec/perfomance_spec/app/Benchmark/index.erb +9 -0
- data/spec/perfomance_spec/app/Benchmark/products.erb +25 -0
- data/spec/perfomance_spec/app/Benchmark/search_results.erb +13 -0
- data/spec/perfomance_spec/app/Customer/customer.rb +6 -0
- data/spec/perfomance_spec/app/Perftest/index.erb +5 -0
- data/spec/perfomance_spec/app/Product/index.erb +25 -0
- data/spec/perfomance_spec/app/Product/product.rb +6 -0
- data/spec/perfomance_spec/app/helpers/application_helper.rb +126 -0
- data/spec/perfomance_spec/app/helpers/browser_helper.rb +18 -0
- data/spec/perfomance_spec/rhoconfig.txt +1 -1
- data/spec/phone_spec/app/Account_s/account_s.rb +5 -2
- data/spec/phone_spec/app/Case/case.rb +1 -0
- data/spec/phone_spec/app/Case_s/case_s.rb +2 -0
- data/spec/phone_spec/app/Data/perftest.json +35 -0
- data/spec/phone_spec/app/Data/testCDATA.xml +11 -0
- data/spec/phone_spec/app/Product/product.rb +1 -1
- data/spec/phone_spec/app/{Spec → spec}/asynchttp_spec.rb +66 -17
- data/spec/phone_spec/app/{Spec → spec}/barcode_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/blobsync_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/bsearch_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/bulksync_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/contacts_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/crypt_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/date_spec.rb +0 -0
- data/spec/phone_spec/app/spec/events_spec.rb +199 -0
- data/spec/phone_spec/app/{Spec → spec}/fixtures/client_info.txt +0 -0
- data/spec/phone_spec/app/{Spec → spec}/fixtures/object_values.txt +0 -0
- data/spec/phone_spec/app/{Spec → spec}/json_spec.rb +11 -2
- data/spec/phone_spec/app/{Spec → spec}/mapview_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/nativebar_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/navbar_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/pagination/fixtures/object_values.txt +0 -0
- data/spec/phone_spec/app/{Spec → spec}/rho_controller_spec.rb +5 -0
- data/spec/phone_spec/app/{Spec → spec}/rho_spec.rb +48 -0
- data/spec/phone_spec/app/{Spec → spec}/rhofile_spec.rb +9 -6
- data/spec/phone_spec/app/{Spec → spec}/rhom_object_spec.rb +188 -9
- data/spec/phone_spec/app/{Spec → spec}/syncengine_spec.rb +0 -0
- data/spec/phone_spec/app/{Spec → spec}/xml_spec.rb +15 -0
- data/spec/phone_spec/app/{Spec → spec}/xruby_spec.rb +0 -0
- data/spec/phone_spec/app/spec_runner.rb +4 -1
- data/spec/phone_spec/build.yml +2 -1
- metadata +95 -31
- data/platform/bb/rhodes/platform/5.0/com/rho/RhoMainScreen.java +0 -36
- data/platform/bb/rhodes/platform/6.0/com/rho/BrowserAdapter5.java +0 -155
- data/platform/bb/rhodes/platform/6.0/com/rho/RhoMainScreen.java +0 -36
@@ -0,0 +1,136 @@
|
|
1
|
+
package com.rhomobile.rhodes.bluetooth;
|
2
|
+
|
3
|
+
import android.app.Activity;
|
4
|
+
import android.bluetooth.BluetoothAdapter;
|
5
|
+
import android.bluetooth.BluetoothDevice;
|
6
|
+
import android.content.Intent;
|
7
|
+
import android.os.Handler;
|
8
|
+
import android.os.Looper;
|
9
|
+
import android.os.Message;
|
10
|
+
import android.util.Log;
|
11
|
+
import android.view.View;
|
12
|
+
import android.view.View.OnClickListener;
|
13
|
+
import android.widget.ArrayAdapter;
|
14
|
+
import android.widget.Button;
|
15
|
+
import android.widget.EditText;
|
16
|
+
import android.widget.ListView;
|
17
|
+
import android.widget.TextView;
|
18
|
+
import android.widget.Toast;
|
19
|
+
import com.rhomobile.rhodes.RhodesService;
|
20
|
+
import com.rhomobile.rhodes.util.PerformOnUiThread;
|
21
|
+
|
22
|
+
|
23
|
+
public class RhoBluetoothManagerOld implements IRhoBluetoothManager {
|
24
|
+
|
25
|
+
private static final String TAG = "RhoBluetoothManagerOld";
|
26
|
+
private static final boolean D = true;
|
27
|
+
|
28
|
+
|
29
|
+
public RhoBluetoothManagerOld () {
|
30
|
+
if(D) Log.d(TAG, "RhoBluetoothManagerOld()");
|
31
|
+
}
|
32
|
+
|
33
|
+
public void init(){
|
34
|
+
}
|
35
|
+
|
36
|
+
public void setDeviceName(String device_name) {
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
private void sendMessage(String message) {
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
private void setupSession() {
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
public void onSessionConnectedOK() {
|
49
|
+
}
|
50
|
+
|
51
|
+
public void onSessionDisconnected() {
|
52
|
+
}
|
53
|
+
|
54
|
+
public void onSessionReadMessage(byte[] buf, int bytes) {
|
55
|
+
}
|
56
|
+
|
57
|
+
public void onSessionConnectedDeviceName(String name) {
|
58
|
+
}
|
59
|
+
|
60
|
+
public void onSessionToast(String message) {
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
public static void onActivityResult(int requestCode, int resultCode, Intent data) {
|
65
|
+
}
|
66
|
+
|
67
|
+
public void onDeviceListActivityFinished( boolean is_ok, String adress) {
|
68
|
+
}
|
69
|
+
|
70
|
+
public void onActivityResultPrivate(int requestCode, int resultCode, Intent data) {
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
public RhoBluetoothSession getSession() {
|
75
|
+
return null;
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
public int is_bluetooth_available() {
|
81
|
+
return 0;
|
82
|
+
}
|
83
|
+
|
84
|
+
public void off_bluetooth() {
|
85
|
+
}
|
86
|
+
|
87
|
+
public void set_device_name(String device_name) {
|
88
|
+
}
|
89
|
+
|
90
|
+
public String get_device_name() {
|
91
|
+
return "";
|
92
|
+
}
|
93
|
+
|
94
|
+
public String get_last_error() {
|
95
|
+
return RhoBluetoothManager.BTC_ERROR;
|
96
|
+
}
|
97
|
+
|
98
|
+
public String create_session(String role, String callback_url) {
|
99
|
+
fireCreateSessionCallback(RhoBluetoothManager.BTC_ERROR, "");
|
100
|
+
return RhoBluetoothManager.BTC_ERROR;
|
101
|
+
}
|
102
|
+
|
103
|
+
public void fireCreateSessionCallback(String status, String connected_device_name) {
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
public void session_set_callback(String connected_device_name, String callback_url) {
|
108
|
+
}
|
109
|
+
|
110
|
+
public void fireSessionCallback(String connected_device_name, String event_type) {
|
111
|
+
}
|
112
|
+
|
113
|
+
public void session_disconnect(String connected_device_name) {
|
114
|
+
}
|
115
|
+
|
116
|
+
public int session_get_status(String connected_device_name) {
|
117
|
+
return -1;
|
118
|
+
}
|
119
|
+
|
120
|
+
public String session_read_string(String connected_device_name) {
|
121
|
+
return "";
|
122
|
+
}
|
123
|
+
|
124
|
+
public void session_write_string(String connected_device_name, String str) {
|
125
|
+
}
|
126
|
+
|
127
|
+
public int session_read_data(String connected_device_name, Byte[] buf, int max_length) {
|
128
|
+
return 0;
|
129
|
+
}
|
130
|
+
|
131
|
+
public void session_write_data(String connected_device_name, Byte[] buf, int length) {
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
}
|
@@ -0,0 +1,457 @@
|
|
1
|
+
package com.rhomobile.rhodes.bluetooth;
|
2
|
+
|
3
|
+
import java.io.IOException;
|
4
|
+
import java.io.InputStream;
|
5
|
+
import java.io.OutputStream;
|
6
|
+
import java.util.UUID;
|
7
|
+
|
8
|
+
|
9
|
+
import android.bluetooth.BluetoothAdapter;
|
10
|
+
import android.bluetooth.BluetoothDevice;
|
11
|
+
import android.bluetooth.BluetoothServerSocket;
|
12
|
+
import android.bluetooth.BluetoothSocket;
|
13
|
+
import android.content.Context;
|
14
|
+
import android.os.Bundle;
|
15
|
+
import android.os.Handler;
|
16
|
+
import android.os.Message;
|
17
|
+
import android.util.Log;
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
public class RhoBluetoothSession {
|
22
|
+
|
23
|
+
// events for listener
|
24
|
+
public static String BT_SESSION_INPUT_DATA_RECEIVED = "SESSION_INPUT_DATA_RECEIVED";
|
25
|
+
public static String BT_SESSION_DISCONNECT = "SESSION_DISCONNECT";
|
26
|
+
|
27
|
+
|
28
|
+
// Debugging
|
29
|
+
private static final String TAG = "RhoBluetoothSession";
|
30
|
+
private static final boolean D = true;
|
31
|
+
|
32
|
+
// Name for the SDP record when creating server socket
|
33
|
+
private static final String NAME = "btspp";
|
34
|
+
|
35
|
+
// Unique UUID for this application
|
36
|
+
private static final UUID MY_UUID = UUIDHelper.SERIAL_PORT_PROTOCOL_UUID;
|
37
|
+
|
38
|
+
// Member fields
|
39
|
+
private final BluetoothAdapter mAdapter;
|
40
|
+
private final Handler mHandler;
|
41
|
+
private AcceptThread mAcceptThread;
|
42
|
+
private ConnectThread mConnectThread;
|
43
|
+
private ConnectedThread mConnectedThread;
|
44
|
+
private int mState;
|
45
|
+
|
46
|
+
// Constants that indicate the current connection state
|
47
|
+
public static final int STATE_NONE = 0; // we're doing nothing
|
48
|
+
public static final int STATE_LISTEN = 1; // now listening for incoming connections
|
49
|
+
public static final int STATE_CONNECTING = 2; // now initiating an outgoing connection
|
50
|
+
public static final int STATE_CONNECTED = 3; // now connected to a remote device
|
51
|
+
|
52
|
+
private String mCallbackUrl;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Constructor. Prepares a new RhoBluetoothSession session.
|
56
|
+
* @param context The UI Activity Context
|
57
|
+
* @param handler A Handler to send messages back to the UI Activity
|
58
|
+
*/
|
59
|
+
public RhoBluetoothSession(Context context, Handler handler) {
|
60
|
+
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
61
|
+
mState = STATE_NONE;
|
62
|
+
mHandler = handler;
|
63
|
+
mCallbackUrl = null;
|
64
|
+
}
|
65
|
+
|
66
|
+
public void setCallbackURL(String url) {
|
67
|
+
mCallbackUrl = url;
|
68
|
+
}
|
69
|
+
|
70
|
+
public String getCallbackURL() {
|
71
|
+
return mCallbackUrl;
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Set the current state of the chat connection
|
76
|
+
* @param state An integer defining the current connection state
|
77
|
+
*/
|
78
|
+
private synchronized void setState(int state) {
|
79
|
+
if (D) Log.d(TAG, "setState() " + mState + " -> " + state);
|
80
|
+
mState = state;
|
81
|
+
|
82
|
+
// Give the new state to the Handler so the UI Activity can update
|
83
|
+
//mHandler.obtainMessage(RhoBluetoothManager.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
|
84
|
+
switch (mState) {
|
85
|
+
case RhoBluetoothSession.STATE_CONNECTED:
|
86
|
+
//fireCreateSessionCallback(BTC_OK, mConnectedDeviceName);
|
87
|
+
mCallbackUrl = null;
|
88
|
+
RhoBluetoothManager.sharedInstance().onSessionConnectedOK();
|
89
|
+
break;
|
90
|
+
case RhoBluetoothSession.STATE_LISTEN:
|
91
|
+
case RhoBluetoothSession.STATE_NONE:
|
92
|
+
//fireSessionCallback(mConnectedDeviceName, mSession.BT_SESSION_DISCONNECT);
|
93
|
+
mCallbackUrl = null;
|
94
|
+
RhoBluetoothManager.sharedInstance().onSessionDisconnected();
|
95
|
+
break;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Return the current connection state. */
|
101
|
+
public synchronized int getState() {
|
102
|
+
return mState;
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Start the chat service. Specifically start AcceptThread to begin a
|
107
|
+
* session in listening (server) mode. Called by the Activity onResume() */
|
108
|
+
public synchronized void start() {
|
109
|
+
if (D) Log.d(TAG, "start");
|
110
|
+
|
111
|
+
// Cancel any thread attempting to make a connection
|
112
|
+
if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}
|
113
|
+
|
114
|
+
// Cancel any thread currently running a connection
|
115
|
+
if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}
|
116
|
+
|
117
|
+
// Start the thread to listen on a BluetoothServerSocket
|
118
|
+
if (mAcceptThread == null) {
|
119
|
+
mAcceptThread = new AcceptThread();
|
120
|
+
mAcceptThread.start();
|
121
|
+
}
|
122
|
+
setState(STATE_LISTEN);
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Start the ConnectThread to initiate a connection to a remote device.
|
127
|
+
* @param device The BluetoothDevice to connect
|
128
|
+
*/
|
129
|
+
public synchronized void connect(BluetoothDevice device) {
|
130
|
+
if (D) Log.d(TAG, "connect to: " + device);
|
131
|
+
|
132
|
+
// Cancel any thread attempting to make a connection
|
133
|
+
if (mState == STATE_CONNECTING) {
|
134
|
+
if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}
|
135
|
+
}
|
136
|
+
|
137
|
+
// Cancel any thread currently running a connection
|
138
|
+
if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}
|
139
|
+
|
140
|
+
// Start the thread to connect with the given device
|
141
|
+
mConnectThread = new ConnectThread(device);
|
142
|
+
mConnectThread.start();
|
143
|
+
setState(STATE_CONNECTING);
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Start the ConnectedThread to begin managing a Bluetooth connection
|
148
|
+
* @param socket The BluetoothSocket on which the connection was made
|
149
|
+
* @param device The BluetoothDevice that has been connected
|
150
|
+
*/
|
151
|
+
public synchronized void connected(BluetoothSocket socket, BluetoothDevice device) {
|
152
|
+
if (D) Log.d(TAG, "connected");
|
153
|
+
|
154
|
+
// Cancel the thread that completed the connection
|
155
|
+
if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}
|
156
|
+
|
157
|
+
// Cancel any thread currently running a connection
|
158
|
+
if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}
|
159
|
+
|
160
|
+
// Cancel the accept thread because we only want to connect to one device
|
161
|
+
if (mAcceptThread != null) {mAcceptThread.cancel(); mAcceptThread = null;}
|
162
|
+
|
163
|
+
// Start the thread to manage the connection and perform transmissions
|
164
|
+
mConnectedThread = new ConnectedThread(socket);
|
165
|
+
mConnectedThread.start();
|
166
|
+
|
167
|
+
// Send the name of the connected device back to the UI Activity
|
168
|
+
//Message msg = mHandler.obtainMessage(RhoBluetoothManager.MESSAGE_DEVICE_NAME);
|
169
|
+
//Bundle bundle = new Bundle();
|
170
|
+
//bundle.putString(RhoBluetoothManager.sharedInstance().DEVICE_NAME, device.getName());
|
171
|
+
//msg.setData(bundle);
|
172
|
+
//mHandler.sendMessage(msg);
|
173
|
+
RhoBluetoothManager.sharedInstance().onSessionConnectedDeviceName(device.getName());
|
174
|
+
|
175
|
+
|
176
|
+
setState(STATE_CONNECTED);
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Stop all threads
|
181
|
+
*/
|
182
|
+
public synchronized void stop() {
|
183
|
+
if (D) Log.d(TAG, "stop");
|
184
|
+
if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}
|
185
|
+
if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}
|
186
|
+
if (mAcceptThread != null) {mAcceptThread.cancel(); mAcceptThread = null;}
|
187
|
+
setState(STATE_NONE);
|
188
|
+
}
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Write to the ConnectedThread in an unsynchronized manner
|
192
|
+
* @param out The bytes to write
|
193
|
+
* @see ConnectedThread#write(byte[])
|
194
|
+
*/
|
195
|
+
public void write(byte[] out) {
|
196
|
+
// Create temporary object
|
197
|
+
ConnectedThread r;
|
198
|
+
// Synchronize a copy of the ConnectedThread
|
199
|
+
synchronized (this) {
|
200
|
+
if (mState != STATE_CONNECTED) return;
|
201
|
+
r = mConnectedThread;
|
202
|
+
}
|
203
|
+
// Perform the write unsynchronized
|
204
|
+
r.write(out);
|
205
|
+
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* Indicate that the connection attempt failed and notify the UI Activity.
|
209
|
+
*/
|
210
|
+
private void connectionFailed() {
|
211
|
+
if (D) Log.d(TAG, "connectionFailed()");
|
212
|
+
setState(STATE_LISTEN);
|
213
|
+
|
214
|
+
// Send a failure message back to the Activity
|
215
|
+
//Message msg = mHandler.obtainMessage(RhoBluetoothManager.MESSAGE_TOAST);
|
216
|
+
//Bundle bundle = new Bundle();
|
217
|
+
//bundle.putString(RhoBluetoothManager.TOAST, "Unable to connect device");
|
218
|
+
//msg.setData(bundle);
|
219
|
+
//mHandler.sendMessage(msg);
|
220
|
+
RhoBluetoothManager.sharedInstance().onSessionToast("Unable to connect device");
|
221
|
+
}
|
222
|
+
|
223
|
+
/**
|
224
|
+
* Indicate that the connection was lost and notify the UI Activity.
|
225
|
+
*/
|
226
|
+
public void connectionLost() {
|
227
|
+
if (D) Log.d(TAG, "connectionLost()");
|
228
|
+
setState(STATE_LISTEN);
|
229
|
+
|
230
|
+
// Send a failure message back to the Activity
|
231
|
+
//Message msg = mHandler.obtainMessage(RhoBluetoothManager.MESSAGE_TOAST);
|
232
|
+
//Bundle bundle = new Bundle();
|
233
|
+
//bundle.putString(RhoBluetoothManager.TOAST, "Device connection was lost");
|
234
|
+
//msg.setData(bundle);
|
235
|
+
//mHandler.sendMessage(msg);
|
236
|
+
RhoBluetoothManager.sharedInstance().onSessionToast("Device connection was lost");
|
237
|
+
}
|
238
|
+
|
239
|
+
/**
|
240
|
+
* This thread runs while listening for incoming connections. It behaves
|
241
|
+
* like a server-side client. It runs until a connection is accepted
|
242
|
+
* (or until cancelled).
|
243
|
+
*/
|
244
|
+
private class AcceptThread extends Thread {
|
245
|
+
// The local server socket
|
246
|
+
private final BluetoothServerSocket mmServerSocket;
|
247
|
+
|
248
|
+
public AcceptThread() {
|
249
|
+
BluetoothServerSocket tmp = null;
|
250
|
+
|
251
|
+
// Create a new listening server socket
|
252
|
+
try {
|
253
|
+
tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
|
254
|
+
} catch (IOException e) {
|
255
|
+
Log.e(TAG, "listen() failed", e);
|
256
|
+
}
|
257
|
+
mmServerSocket = tmp;
|
258
|
+
}
|
259
|
+
|
260
|
+
public void run() {
|
261
|
+
if (D) Log.d(TAG, "BEGIN mAcceptThread" + this);
|
262
|
+
setName("AcceptThread");
|
263
|
+
BluetoothSocket socket = null;
|
264
|
+
|
265
|
+
// Listen to the server socket if we're not connected
|
266
|
+
while (mState != STATE_CONNECTED) {
|
267
|
+
try {
|
268
|
+
// This is a blocking call and will only return on a
|
269
|
+
// successful connection or an exception
|
270
|
+
socket = mmServerSocket.accept();
|
271
|
+
} catch (IOException e) {
|
272
|
+
Log.e(TAG, "accept() failed", e);
|
273
|
+
break;
|
274
|
+
}
|
275
|
+
|
276
|
+
// If a connection was accepted
|
277
|
+
if (socket != null) {
|
278
|
+
synchronized (RhoBluetoothSession.this) {
|
279
|
+
switch (mState) {
|
280
|
+
case STATE_LISTEN:
|
281
|
+
case STATE_CONNECTING:
|
282
|
+
// Situation normal. Start the connected thread.
|
283
|
+
connected(socket, socket.getRemoteDevice());
|
284
|
+
break;
|
285
|
+
case STATE_NONE:
|
286
|
+
case STATE_CONNECTED:
|
287
|
+
// Either not ready or already connected. Terminate new socket.
|
288
|
+
try {
|
289
|
+
socket.close();
|
290
|
+
} catch (IOException e) {
|
291
|
+
Log.e(TAG, "Could not close unwanted socket", e);
|
292
|
+
}
|
293
|
+
break;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
297
|
+
}
|
298
|
+
if (D) Log.i(TAG, "END mAcceptThread");
|
299
|
+
}
|
300
|
+
|
301
|
+
public void cancel() {
|
302
|
+
if (D) Log.d(TAG, "cancel " + this);
|
303
|
+
try {
|
304
|
+
mmServerSocket.close();
|
305
|
+
} catch (IOException e) {
|
306
|
+
Log.e(TAG, "close() of server failed", e);
|
307
|
+
}
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
/**
|
313
|
+
* This thread runs while attempting to make an outgoing connection
|
314
|
+
* with a device. It runs straight through; the connection either
|
315
|
+
* succeeds or fails.
|
316
|
+
*/
|
317
|
+
private class ConnectThread extends Thread {
|
318
|
+
private final BluetoothSocket mmSocket;
|
319
|
+
private final BluetoothDevice mmDevice;
|
320
|
+
|
321
|
+
public ConnectThread(BluetoothDevice device) {
|
322
|
+
mmDevice = device;
|
323
|
+
BluetoothSocket tmp = null;
|
324
|
+
|
325
|
+
// Get a BluetoothSocket for a connection with the
|
326
|
+
// given BluetoothDevice
|
327
|
+
try {
|
328
|
+
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
|
329
|
+
} catch (IOException e) {
|
330
|
+
Log.e(TAG, "create() failed", e);
|
331
|
+
}
|
332
|
+
mmSocket = tmp;
|
333
|
+
}
|
334
|
+
|
335
|
+
public void run() {
|
336
|
+
Log.i(TAG, "BEGIN mConnectThread");
|
337
|
+
setName("ConnectThread");
|
338
|
+
|
339
|
+
// Always cancel discovery because it will slow down a connection
|
340
|
+
mAdapter.cancelDiscovery();
|
341
|
+
|
342
|
+
// Make a connection to the BluetoothSocket
|
343
|
+
try {
|
344
|
+
// This is a blocking call and will only return on a
|
345
|
+
// successful connection or an exception
|
346
|
+
mmSocket.connect();
|
347
|
+
} catch (IOException e) {
|
348
|
+
connectionFailed();
|
349
|
+
// Close the socket
|
350
|
+
try {
|
351
|
+
mmSocket.close();
|
352
|
+
} catch (IOException e2) {
|
353
|
+
Log.e(TAG, "unable to close() socket during connection failure", e2);
|
354
|
+
}
|
355
|
+
// Start the service over to restart listening mode
|
356
|
+
RhoBluetoothSession.this.start();
|
357
|
+
return;
|
358
|
+
}
|
359
|
+
|
360
|
+
// Reset the ConnectThread because we're done
|
361
|
+
synchronized (RhoBluetoothSession.this) {
|
362
|
+
mConnectThread = null;
|
363
|
+
}
|
364
|
+
|
365
|
+
// Start the connected thread
|
366
|
+
connected(mmSocket, mmDevice);
|
367
|
+
}
|
368
|
+
|
369
|
+
public void cancel() {
|
370
|
+
try {
|
371
|
+
mmSocket.close();
|
372
|
+
} catch (IOException e) {
|
373
|
+
Log.e(TAG, "close() of connect socket failed", e);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
/**
|
379
|
+
* This thread runs during a connection with a remote device.
|
380
|
+
* It handles all incoming and outgoing transmissions.
|
381
|
+
*/
|
382
|
+
private class ConnectedThread extends Thread {
|
383
|
+
private final BluetoothSocket mmSocket;
|
384
|
+
private final InputStream mmInStream;
|
385
|
+
private final OutputStream mmOutStream;
|
386
|
+
|
387
|
+
public ConnectedThread(BluetoothSocket socket) {
|
388
|
+
Log.d(TAG, "create ConnectedThread");
|
389
|
+
mmSocket = socket;
|
390
|
+
InputStream tmpIn = null;
|
391
|
+
OutputStream tmpOut = null;
|
392
|
+
|
393
|
+
// Get the BluetoothSocket input and output streams
|
394
|
+
try {
|
395
|
+
tmpIn = socket.getInputStream();
|
396
|
+
tmpOut = socket.getOutputStream();
|
397
|
+
} catch (IOException e) {
|
398
|
+
Log.e(TAG, "temp sockets not created", e);
|
399
|
+
}
|
400
|
+
|
401
|
+
mmInStream = tmpIn;
|
402
|
+
mmOutStream = tmpOut;
|
403
|
+
}
|
404
|
+
|
405
|
+
public void run() {
|
406
|
+
Log.i(TAG, "BEGIN mConnectedThread");
|
407
|
+
byte[] buffer = new byte[1024];
|
408
|
+
int bytes;
|
409
|
+
|
410
|
+
// Keep listening to the InputStream while connected
|
411
|
+
while (true) {
|
412
|
+
try {
|
413
|
+
// Read from the InputStream
|
414
|
+
bytes = mmInStream.read(buffer);
|
415
|
+
|
416
|
+
// Send the obtained bytes to the UI Activity
|
417
|
+
//mHandler.obtainMessage(RhoBluetoothManager.MESSAGE_READ, bytes, -1, buffer)
|
418
|
+
// .sendToTarget();
|
419
|
+
byte[] buf_for_send = buffer.clone();
|
420
|
+
RhoBluetoothManager.sharedInstance().onSessionReadMessage(buf_for_send, bytes);
|
421
|
+
} catch (IOException e) {
|
422
|
+
Log.e(TAG, "disconnected", e);
|
423
|
+
connectionLost();
|
424
|
+
break;
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}
|
428
|
+
|
429
|
+
/**
|
430
|
+
* Write to the connected OutStream.
|
431
|
+
* @param buffer The bytes to write
|
432
|
+
*/
|
433
|
+
public void write(byte[] buffer) {
|
434
|
+
try {
|
435
|
+
mmOutStream.write(buffer);
|
436
|
+
|
437
|
+
// Share the sent message back to the UI Activity
|
438
|
+
//mHandler.obtainMessage(RhoBluetoothManager.MESSAGE_WRITE, -1, -1, buffer)
|
439
|
+
// .sendToTarget();
|
440
|
+
} catch (IOException e) {
|
441
|
+
Log.e(TAG, "Exception during write", e);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
445
|
+
public void cancel() {
|
446
|
+
try {
|
447
|
+
mmSocket.close();
|
448
|
+
} catch (IOException e) {
|
449
|
+
Log.e(TAG, "close() of connect socket failed", e);
|
450
|
+
}
|
451
|
+
}
|
452
|
+
}
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
}
|