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,66 @@
|
|
1
|
+
package com.rhomobile.rhodes.bluetooth;
|
2
|
+
|
3
|
+
import com.rhomobile.rhodes.util.PerformOnUiThread;
|
4
|
+
|
5
|
+
import android.bluetooth.BluetoothDevice;
|
6
|
+
import android.content.Intent;
|
7
|
+
import android.util.Log;
|
8
|
+
|
9
|
+
public interface IRhoBluetoothManager {
|
10
|
+
|
11
|
+
// access from Native
|
12
|
+
|
13
|
+
public int is_bluetooth_available();
|
14
|
+
|
15
|
+
public void off_bluetooth();
|
16
|
+
|
17
|
+
public void set_device_name(String device_name);
|
18
|
+
|
19
|
+
public String get_device_name();
|
20
|
+
|
21
|
+
public String get_last_error();
|
22
|
+
|
23
|
+
public String create_session(String role, String callback_url);
|
24
|
+
|
25
|
+
public void session_set_callback(String connected_device_name, String callback_url);
|
26
|
+
|
27
|
+
public void session_disconnect(String connected_device_name);
|
28
|
+
|
29
|
+
public int session_get_status(String connected_device_name);
|
30
|
+
|
31
|
+
public String session_read_string(String connected_device_name);
|
32
|
+
|
33
|
+
public void session_write_string(String connected_device_name, String str);
|
34
|
+
|
35
|
+
public int session_read_data(String connected_device_name, Byte[] buf, int max_length);
|
36
|
+
|
37
|
+
public void session_write_data(String connected_device_name, Byte[] buf, int length);
|
38
|
+
|
39
|
+
// access from DeviceListActivity
|
40
|
+
|
41
|
+
public void onDeviceListActivityFinished( boolean is_ok, String adress);
|
42
|
+
|
43
|
+
// access from Session
|
44
|
+
|
45
|
+
public void onSessionConnectedOK();
|
46
|
+
|
47
|
+
public void onSessionDisconnected();
|
48
|
+
|
49
|
+
public void onSessionReadMessage(byte[] buf, int bytes);
|
50
|
+
|
51
|
+
public void onSessionConnectedDeviceName(String name);
|
52
|
+
|
53
|
+
public void onSessionToast(String message);
|
54
|
+
|
55
|
+
|
56
|
+
// access from Manager
|
57
|
+
|
58
|
+
public void init() ;
|
59
|
+
|
60
|
+
public void onActivityResultPrivate(int requestCode, int resultCode, Intent data);
|
61
|
+
|
62
|
+
public RhoBluetoothSession getSession();
|
63
|
+
|
64
|
+
public void setDeviceName(String device_name);
|
65
|
+
|
66
|
+
}
|
data/platform/android/Rhodes/src/com/rhomobile/rhodes/bluetooth/RhoBluetoothDeviceListActivity.java
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
package com.rhomobile.rhodes.bluetooth;
|
2
|
+
|
3
|
+
import java.util.Set;
|
4
|
+
|
5
|
+
import com.rhomobile.rhodes.AndroidR;
|
6
|
+
|
7
|
+
import android.app.Activity;
|
8
|
+
import android.bluetooth.BluetoothAdapter;
|
9
|
+
import android.bluetooth.BluetoothDevice;
|
10
|
+
import android.content.BroadcastReceiver;
|
11
|
+
import android.content.Context;
|
12
|
+
import android.content.Intent;
|
13
|
+
import android.content.IntentFilter;
|
14
|
+
import android.os.Bundle;
|
15
|
+
import android.util.Log;
|
16
|
+
import android.view.View;
|
17
|
+
import android.view.Window;
|
18
|
+
import android.view.View.OnClickListener;
|
19
|
+
import android.widget.AdapterView;
|
20
|
+
import android.widget.ArrayAdapter;
|
21
|
+
import android.widget.Button;
|
22
|
+
import android.widget.ListView;
|
23
|
+
import android.widget.TextView;
|
24
|
+
import android.widget.AdapterView.OnItemClickListener;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* This Activity appears as a dialog. It lists any paired devices and
|
28
|
+
* devices detected in the area after discovery. When a device is chosen
|
29
|
+
* by the user, the MAC address of the device is sent back to the parent
|
30
|
+
* Activity in the result Intent.
|
31
|
+
*/
|
32
|
+
public class RhoBluetoothDeviceListActivity extends Activity {
|
33
|
+
// Debugging
|
34
|
+
private static final String TAG = "RhoBluetoothDeviceListActivity";
|
35
|
+
private static final boolean D = true;
|
36
|
+
|
37
|
+
// Return Intent extra
|
38
|
+
public static String EXTRA_DEVICE_ADDRESS = "device_address";
|
39
|
+
|
40
|
+
// Member fields
|
41
|
+
private BluetoothAdapter mBtAdapter;
|
42
|
+
private ArrayAdapter<String> mPairedDevicesArrayAdapter;
|
43
|
+
private ArrayAdapter<String> mNewDevicesArrayAdapter;
|
44
|
+
|
45
|
+
private String mReturnAdress = null;
|
46
|
+
|
47
|
+
@Override
|
48
|
+
protected void onCreate(Bundle savedInstanceState) {
|
49
|
+
super.onCreate(savedInstanceState);
|
50
|
+
|
51
|
+
// Setup the window
|
52
|
+
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
53
|
+
setContentView(AndroidR.layout.bt_device_list);
|
54
|
+
|
55
|
+
// Set result CANCELED incase the user backs out
|
56
|
+
//setResult(Activity.RESULT_CANCELED);
|
57
|
+
mReturnAdress = null;
|
58
|
+
//RhoBluetoothManager.sharedInstance().onDeviceListActivityFinished(false, "");
|
59
|
+
|
60
|
+
// Initialize the button to perform device discovery
|
61
|
+
Button scanButton = (Button) findViewById(AndroidR.id.button_scan);
|
62
|
+
scanButton.setOnClickListener(new OnClickListener() {
|
63
|
+
public void onClick(View v) {
|
64
|
+
doDiscovery();
|
65
|
+
v.setVisibility(View.GONE);
|
66
|
+
}
|
67
|
+
});
|
68
|
+
|
69
|
+
// Initialize array adapters. One for already paired devices and
|
70
|
+
// one for newly discovered devices
|
71
|
+
mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, AndroidR.layout.bt_device_name);
|
72
|
+
mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, AndroidR.layout.bt_device_name);
|
73
|
+
|
74
|
+
// Find and set up the ListView for paired devices
|
75
|
+
ListView pairedListView = (ListView) findViewById(AndroidR.id.paired_devices);
|
76
|
+
pairedListView.setAdapter(mPairedDevicesArrayAdapter);
|
77
|
+
pairedListView.setOnItemClickListener(mDeviceClickListener);
|
78
|
+
|
79
|
+
// Find and set up the ListView for newly discovered devices
|
80
|
+
ListView newDevicesListView = (ListView) findViewById(AndroidR.id.new_devices);
|
81
|
+
newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
|
82
|
+
newDevicesListView.setOnItemClickListener(mDeviceClickListener);
|
83
|
+
|
84
|
+
// Register for broadcasts when a device is discovered
|
85
|
+
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
|
86
|
+
this.registerReceiver(mReceiver, filter);
|
87
|
+
|
88
|
+
// Register for broadcasts when discovery has finished
|
89
|
+
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
|
90
|
+
this.registerReceiver(mReceiver, filter);
|
91
|
+
|
92
|
+
// Get the local Bluetooth adapter
|
93
|
+
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
|
94
|
+
|
95
|
+
// Get a set of currently paired devices
|
96
|
+
Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();
|
97
|
+
|
98
|
+
// If there are paired devices, add each one to the ArrayAdapter
|
99
|
+
if (pairedDevices.size() > 0) {
|
100
|
+
findViewById(AndroidR.id.title_paired_devices).setVisibility(View.VISIBLE);
|
101
|
+
for (BluetoothDevice device : pairedDevices) {
|
102
|
+
mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
103
|
+
}
|
104
|
+
} else {
|
105
|
+
String noDevices = getResources().getText(AndroidR.string.none_paired).toString();
|
106
|
+
mPairedDevicesArrayAdapter.add(noDevices);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
@Override
|
111
|
+
protected void onDestroy() {
|
112
|
+
super.onDestroy();
|
113
|
+
|
114
|
+
// Make sure we're not doing discovery anymore
|
115
|
+
if (mBtAdapter != null) {
|
116
|
+
mBtAdapter.cancelDiscovery();
|
117
|
+
}
|
118
|
+
|
119
|
+
// Unregister broadcast listeners
|
120
|
+
this.unregisterReceiver(mReceiver);
|
121
|
+
|
122
|
+
if (mReturnAdress == null) {
|
123
|
+
RhoBluetoothManager.sharedInstance().onDeviceListActivityFinished(false, "");
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
RhoBluetoothManager.sharedInstance().onDeviceListActivityFinished(true, mReturnAdress);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Start device discover with the BluetoothAdapter
|
132
|
+
*/
|
133
|
+
private void doDiscovery() {
|
134
|
+
if (D) Log.d(TAG, "doDiscovery()");
|
135
|
+
|
136
|
+
// Indicate scanning in the title
|
137
|
+
setProgressBarIndeterminateVisibility(true);
|
138
|
+
setTitle(AndroidR.string.scanning);
|
139
|
+
|
140
|
+
// Turn on sub-title for new devices
|
141
|
+
findViewById(AndroidR.id.title_new_devices).setVisibility(View.VISIBLE);
|
142
|
+
|
143
|
+
// If we're already discovering, stop it
|
144
|
+
if (mBtAdapter.isDiscovering()) {
|
145
|
+
mBtAdapter.cancelDiscovery();
|
146
|
+
}
|
147
|
+
|
148
|
+
// Request discover from BluetoothAdapter
|
149
|
+
mBtAdapter.startDiscovery();
|
150
|
+
}
|
151
|
+
|
152
|
+
// The on-click listener for all devices in the ListViews
|
153
|
+
private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
|
154
|
+
public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {
|
155
|
+
// Cancel discovery because it's costly and we're about to connect
|
156
|
+
mBtAdapter.cancelDiscovery();
|
157
|
+
|
158
|
+
// Get the device MAC address, which is the last 17 chars in the View
|
159
|
+
String info = ((TextView) v).getText().toString();
|
160
|
+
String address = info.substring(info.length() - 17);
|
161
|
+
|
162
|
+
// Create the result Intent and include the MAC address
|
163
|
+
//Intent intent = new Intent();
|
164
|
+
//intent.putExtra(EXTRA_DEVICE_ADDRESS, address);
|
165
|
+
mReturnAdress = address;
|
166
|
+
|
167
|
+
// Set result and finish this Activity
|
168
|
+
//setResult(Activity.RESULT_OK, intent);
|
169
|
+
//RhoBluetoothManager.sharedInstance().onDeviceListActivityFinished(true, address);
|
170
|
+
finish();
|
171
|
+
}
|
172
|
+
};
|
173
|
+
|
174
|
+
// The BroadcastReceiver that listens for discovered devices and
|
175
|
+
// changes the title when discovery is finished
|
176
|
+
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
177
|
+
@Override
|
178
|
+
public void onReceive(Context context, Intent intent) {
|
179
|
+
String action = intent.getAction();
|
180
|
+
|
181
|
+
// When discovery finds a device
|
182
|
+
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
|
183
|
+
// Get the BluetoothDevice object from the Intent
|
184
|
+
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
185
|
+
// If it's already paired, skip it, because it's been listed already
|
186
|
+
if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
|
187
|
+
mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
188
|
+
}
|
189
|
+
// When discovery is finished, change the Activity title
|
190
|
+
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
|
191
|
+
setProgressBarIndeterminateVisibility(false);
|
192
|
+
setTitle(AndroidR.string.select_device);
|
193
|
+
if (mNewDevicesArrayAdapter.getCount() == 0) {
|
194
|
+
String noDevices = getResources().getText(AndroidR.string.none_found).toString();
|
195
|
+
mNewDevicesArrayAdapter.add(noDevices);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
};
|
200
|
+
|
201
|
+
}
|
@@ -0,0 +1,139 @@
|
|
1
|
+
package com.rhomobile.rhodes.bluetooth;
|
2
|
+
|
3
|
+
import java.security.BasicPermission;
|
4
|
+
import java.security.Permission;
|
5
|
+
|
6
|
+
import android.app.Activity;
|
7
|
+
import android.bluetooth.BluetoothAdapter;
|
8
|
+
import android.bluetooth.BluetoothDevice;
|
9
|
+
import android.content.Intent;
|
10
|
+
import android.content.pm.FeatureInfo;
|
11
|
+
import android.content.pm.PackageManager;
|
12
|
+
import android.os.Build;
|
13
|
+
import android.os.Handler;
|
14
|
+
import android.os.Looper;
|
15
|
+
import android.os.Message;
|
16
|
+
import android.util.Log;
|
17
|
+
import android.view.View;
|
18
|
+
import android.view.View.OnClickListener;
|
19
|
+
import android.widget.ArrayAdapter;
|
20
|
+
import android.widget.Button;
|
21
|
+
import android.widget.EditText;
|
22
|
+
import android.widget.ListView;
|
23
|
+
import android.widget.TextView;
|
24
|
+
import android.widget.Toast;
|
25
|
+
import com.rhomobile.rhodes.RhodesService;
|
26
|
+
import com.rhomobile.rhodes.phonebook.ContactAccessor;
|
27
|
+
import com.rhomobile.rhodes.util.PerformOnUiThread;
|
28
|
+
|
29
|
+
|
30
|
+
public class RhoBluetoothManager {
|
31
|
+
|
32
|
+
public static String BTC_OK = "OK";
|
33
|
+
public static String BTC_CANCEL = "CANCEL";
|
34
|
+
public static String BTC_ERROR = "ERROR";
|
35
|
+
|
36
|
+
public static String BT_ROLE_SERVER = "ROLE_SERVER";
|
37
|
+
public static String BT_ROLE_CLIENT = "ROLE_CLIENT";
|
38
|
+
|
39
|
+
private static final String TAG = "RhoBluetoothManager";
|
40
|
+
private static final boolean D = true;
|
41
|
+
|
42
|
+
|
43
|
+
// public only for external debug !!!
|
44
|
+
public static IRhoBluetoothManager ourInstance = null;
|
45
|
+
|
46
|
+
public RhoBluetoothManager () {
|
47
|
+
if(D) Log.d(TAG, "RhoBluetoothManager()");
|
48
|
+
}
|
49
|
+
|
50
|
+
public static void onActivityResult(int requestCode, int resultCode, Intent data) {
|
51
|
+
if (ourInstance != null) {
|
52
|
+
ourInstance.onActivityResultPrivate(requestCode, resultCode, data);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
public static IRhoBluetoothManager sharedInstance() {
|
59
|
+
if (ourInstance == null) {
|
60
|
+
String className = "RhoBluetoothManagerNew";
|
61
|
+
int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
|
62
|
+
if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
|
63
|
+
if(D) Log.d(TAG, "sharedInstance - old version of System - NO Bluetooth !");
|
64
|
+
className = "RhoBluetoothManagerOld";
|
65
|
+
}
|
66
|
+
try {
|
67
|
+
String pkgname = RhoBluetoothManager.class.getPackage().getName();
|
68
|
+
String fullName = pkgname + "." + className;
|
69
|
+
Class<? extends IRhoBluetoothManager> klass =
|
70
|
+
Class.forName(fullName).asSubclass(IRhoBluetoothManager.class);
|
71
|
+
ourInstance = klass.newInstance();
|
72
|
+
ourInstance.init();
|
73
|
+
}
|
74
|
+
catch (Exception e) {
|
75
|
+
throw new IllegalStateException(e);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return ourInstance;
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
public static int is_bluetooth_available() {
|
83
|
+
return sharedInstance().is_bluetooth_available();
|
84
|
+
}
|
85
|
+
|
86
|
+
public static void off_bluetooth() {
|
87
|
+
sharedInstance().off_bluetooth();
|
88
|
+
}
|
89
|
+
|
90
|
+
public static void set_device_name(String device_name) {
|
91
|
+
sharedInstance().set_device_name(device_name);
|
92
|
+
}
|
93
|
+
|
94
|
+
public static String get_device_name() {
|
95
|
+
return sharedInstance().get_device_name();
|
96
|
+
}
|
97
|
+
|
98
|
+
public static String get_last_error() {
|
99
|
+
return sharedInstance().get_last_error();
|
100
|
+
}
|
101
|
+
|
102
|
+
public static String create_session(String role, String callback_url) {
|
103
|
+
return sharedInstance().create_session(role, callback_url);
|
104
|
+
}
|
105
|
+
|
106
|
+
public static void session_set_callback(String connected_device_name, String callback_url) {
|
107
|
+
sharedInstance().session_set_callback(connected_device_name, callback_url);
|
108
|
+
}
|
109
|
+
|
110
|
+
// to native
|
111
|
+
public static native void onCallback(String callback_url, String body);
|
112
|
+
|
113
|
+
public static void session_disconnect(String connected_device_name) {
|
114
|
+
sharedInstance().session_disconnect(connected_device_name);
|
115
|
+
}
|
116
|
+
|
117
|
+
public static int session_get_status(String connected_device_name) {
|
118
|
+
return sharedInstance().session_get_status(connected_device_name);
|
119
|
+
}
|
120
|
+
|
121
|
+
public static String session_read_string(String connected_device_name) {
|
122
|
+
return sharedInstance().session_read_string(connected_device_name);
|
123
|
+
}
|
124
|
+
|
125
|
+
public static void session_write_string(String connected_device_name, String str) {
|
126
|
+
sharedInstance().session_write_string(connected_device_name, str);
|
127
|
+
}
|
128
|
+
|
129
|
+
public static int session_read_data(String connected_device_name, Byte[] buf, int max_length) {
|
130
|
+
return sharedInstance().session_read_data(connected_device_name, buf, max_length);
|
131
|
+
}
|
132
|
+
|
133
|
+
public static void session_write_data(String connected_device_name, Byte[] buf, int length) {
|
134
|
+
sharedInstance().session_write_data(connected_device_name, buf, length);
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
}
|
@@ -0,0 +1,401 @@
|
|
1
|
+
package com.rhomobile.rhodes.bluetooth;
|
2
|
+
|
3
|
+
|
4
|
+
import java.security.BasicPermission;
|
5
|
+
import java.security.Permission;
|
6
|
+
|
7
|
+
import android.app.Activity;
|
8
|
+
import android.bluetooth.BluetoothAdapter;
|
9
|
+
import android.bluetooth.BluetoothDevice;
|
10
|
+
import android.content.Intent;
|
11
|
+
import android.content.pm.FeatureInfo;
|
12
|
+
import android.content.pm.PackageManager;
|
13
|
+
import android.os.Build;
|
14
|
+
import android.os.Handler;
|
15
|
+
import android.os.Looper;
|
16
|
+
import android.os.Message;
|
17
|
+
import android.util.Log;
|
18
|
+
import android.view.View;
|
19
|
+
import android.view.View.OnClickListener;
|
20
|
+
import android.widget.ArrayAdapter;
|
21
|
+
import android.widget.Button;
|
22
|
+
import android.widget.EditText;
|
23
|
+
import android.widget.ListView;
|
24
|
+
import android.widget.TextView;
|
25
|
+
import android.widget.Toast;
|
26
|
+
import com.rhomobile.rhodes.RhodesService;
|
27
|
+
import com.rhomobile.rhodes.phonebook.ContactAccessor;
|
28
|
+
import com.rhomobile.rhodes.util.PerformOnUiThread;
|
29
|
+
|
30
|
+
public class RhoBluetoothManagerNew implements IRhoBluetoothManager {
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
private boolean mBluetoothIsEnabled = false;
|
35
|
+
|
36
|
+
private static final String TAG = "RhoBluetoothManagerNew";
|
37
|
+
private static final boolean D = true;
|
38
|
+
|
39
|
+
|
40
|
+
// Key names received from the BluetoothChatService Handler
|
41
|
+
public static final String DEVICE_NAME = "DEVICE_NAME";
|
42
|
+
public static final String TOAST = "toast";
|
43
|
+
|
44
|
+
// Intent request codes
|
45
|
+
private static final int REQUEST_CONNECT_DEVICE = 958061;
|
46
|
+
private static final int REQUEST_ENABLE_BT = 958062;
|
47
|
+
|
48
|
+
// Name of the connected device
|
49
|
+
private String mDeviceName = null;
|
50
|
+
|
51
|
+
private String mConnectedDeviceName = null;
|
52
|
+
StringBuffer mInput;
|
53
|
+
|
54
|
+
// Local Bluetooth adapter
|
55
|
+
private BluetoothAdapter mBluetoothAdapter = null;
|
56
|
+
|
57
|
+
// Member object for the chat services
|
58
|
+
private RhoBluetoothSession mSession = null;
|
59
|
+
|
60
|
+
private String mCreateSessionCallback;
|
61
|
+
|
62
|
+
private String mRole;
|
63
|
+
|
64
|
+
|
65
|
+
private Activity mActivity;
|
66
|
+
|
67
|
+
public RhoBluetoothManagerNew () {
|
68
|
+
if(D) Log.d(TAG, "RhoBluetoothManagerNew()");
|
69
|
+
}
|
70
|
+
|
71
|
+
public void init() {
|
72
|
+
// constructor
|
73
|
+
mActivity = RhodesService.getInstance().getMainActivity();
|
74
|
+
mDeviceName = "NONAME";
|
75
|
+
|
76
|
+
|
77
|
+
mBluetoothIsEnabled = false;
|
78
|
+
// check feature
|
79
|
+
PackageManager pm = RhodesService.getInstance().getContext().getPackageManager();
|
80
|
+
FeatureInfo[] fs = pm.getSystemAvailableFeatures();
|
81
|
+
int i;
|
82
|
+
for (i = 0; i < fs.length; i++) {
|
83
|
+
if (fs[i] != null)
|
84
|
+
if (fs[i].name != null)
|
85
|
+
if (fs[i].name.equals(PackageManager.FEATURE_BLUETOOTH)) {
|
86
|
+
if(D) Log.d(TAG, "sharedInstance - found Bluetooth feature in device !");
|
87
|
+
mBluetoothIsEnabled = true;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
// check permission
|
91
|
+
//if (pm.checkPermission(android.Manifest.permission.BLUETOOTH, RhodesService.getInstance().getMainActivity().getPackageName()) != PackageManager.PERMISSION_GRANTED) {
|
92
|
+
try {
|
93
|
+
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
94
|
+
if (bluetoothAdapter != null) {
|
95
|
+
if (!bluetoothAdapter.isEnabled()) {
|
96
|
+
if(D) Log.d(TAG, "sharedInstance - Bluetooth is not enabled !");
|
97
|
+
mBluetoothIsEnabled = false;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
if(D) Log.d(TAG, "sharedInstance - Bluetooth permission is active !");
|
101
|
+
}
|
102
|
+
catch (SecurityException e) {
|
103
|
+
if(D) Log.d(TAG, "sharedInstance - Bluetooth permission is INACTIVE !");
|
104
|
+
mBluetoothIsEnabled = false;
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
mInput = new StringBuffer("");
|
109
|
+
|
110
|
+
|
111
|
+
// Get local Bluetooth adapter
|
112
|
+
if (mBluetoothIsEnabled) {
|
113
|
+
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
114
|
+
|
115
|
+
if (mBluetoothAdapter != null) {
|
116
|
+
if (mBluetoothAdapter.isEnabled()) {
|
117
|
+
if (mSession == null) {
|
118
|
+
setupSession();
|
119
|
+
}
|
120
|
+
mDeviceName = mBluetoothAdapter.getName();
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
public void setDeviceName(String device_name) {
|
127
|
+
mDeviceName = device_name;
|
128
|
+
if (mBluetoothAdapter != null) {
|
129
|
+
mBluetoothAdapter.setName(device_name);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Sends a message.
|
135
|
+
* @param message A string of text to send.
|
136
|
+
*/
|
137
|
+
private void sendMessage(String message) {
|
138
|
+
if(D) Log.i(TAG, "sendMessage");
|
139
|
+
// Check that we're actually connected before trying anything
|
140
|
+
if (mSession.getState() != RhoBluetoothSession.STATE_CONNECTED) {
|
141
|
+
//Toast.makeText(this, R.string.not_connected, Toast.LENGTH_SHORT).show();
|
142
|
+
if(D) Log.i(TAG, "NOT CONNECTED");
|
143
|
+
return;
|
144
|
+
}
|
145
|
+
|
146
|
+
// Check that there's actually something to send
|
147
|
+
if (message.length() > 0) {
|
148
|
+
// Get the message bytes and tell the BluetoothChatService to write
|
149
|
+
byte[] send = message.getBytes();
|
150
|
+
mSession.write(send);
|
151
|
+
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
private void setupSession() {
|
157
|
+
Log.d(TAG, "setupSession()");
|
158
|
+
|
159
|
+
mSession = new RhoBluetoothSession(mActivity, null);
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
public void onSessionConnectedOK() {
|
165
|
+
mInput.setLength(0);
|
166
|
+
PerformOnUiThread.exec( new Runnable() {
|
167
|
+
public void run() {
|
168
|
+
fireCreateSessionCallback(RhoBluetoothManager.BTC_OK, mConnectedDeviceName);
|
169
|
+
}
|
170
|
+
},false);
|
171
|
+
}
|
172
|
+
|
173
|
+
public void onSessionDisconnected() {
|
174
|
+
PerformOnUiThread.exec( new Runnable() {
|
175
|
+
public void run() {
|
176
|
+
if (sharedInstance().getSession().getCallbackURL() == null) {
|
177
|
+
fireCreateSessionCallback(RhoBluetoothManager.BTC_ERROR, "");
|
178
|
+
}
|
179
|
+
else {
|
180
|
+
fireSessionCallback(mConnectedDeviceName, mSession.BT_SESSION_DISCONNECT);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
},false);
|
184
|
+
}
|
185
|
+
|
186
|
+
public void onSessionReadMessage(byte[] buf, int bytes) {
|
187
|
+
final String message = new String(buf, 0, bytes);
|
188
|
+
PerformOnUiThread.exec( new Runnable() {
|
189
|
+
public void run() {
|
190
|
+
mInput.append(message);
|
191
|
+
fireSessionCallback(mConnectedDeviceName, mSession.BT_SESSION_INPUT_DATA_RECEIVED);
|
192
|
+
}
|
193
|
+
},false);
|
194
|
+
}
|
195
|
+
|
196
|
+
public void onSessionConnectedDeviceName(String name) {
|
197
|
+
mConnectedDeviceName = name;
|
198
|
+
}
|
199
|
+
|
200
|
+
public void onSessionToast(String message) {
|
201
|
+
if (D) Log.d(TAG, "TOAST: " + message);
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
public void onDeviceListActivityFinished( boolean is_ok, String adress) {
|
206
|
+
if (is_ok) {
|
207
|
+
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(adress);
|
208
|
+
// Attempt to connect to the device
|
209
|
+
mSession.connect(device);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
public void onActivityResultPrivate(int requestCode, int resultCode, Intent data) {
|
214
|
+
if(D) Log.d(TAG, "onActivityResult " + resultCode);
|
215
|
+
switch (requestCode) {
|
216
|
+
case REQUEST_CONNECT_DEVICE:
|
217
|
+
// When DeviceListActivity returns with a device to connect
|
218
|
+
if (resultCode == Activity.RESULT_OK) {
|
219
|
+
// Get the device MAC address
|
220
|
+
String address = data.getExtras()
|
221
|
+
.getString(RhoBluetoothDeviceListActivity.EXTRA_DEVICE_ADDRESS);
|
222
|
+
// Get the BLuetoothDevice object
|
223
|
+
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
|
224
|
+
// Attempt to connect to the device
|
225
|
+
mSession.connect(device);
|
226
|
+
}
|
227
|
+
break;
|
228
|
+
case REQUEST_ENABLE_BT:
|
229
|
+
// When the request to enable Bluetooth returns
|
230
|
+
if (resultCode == Activity.RESULT_OK) {
|
231
|
+
// Bluetooth is now enabled, so set up a chat session
|
232
|
+
setupSession();
|
233
|
+
} else {
|
234
|
+
// User did not enable Bluetooth or an error occured
|
235
|
+
Log.d(TAG, "BT not enabled");
|
236
|
+
//Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
|
237
|
+
//finish();
|
238
|
+
PerformOnUiThread.exec( new Runnable() {
|
239
|
+
public void run() {
|
240
|
+
fireCreateSessionCallback(RhoBluetoothManager.BTC_ERROR, "");
|
241
|
+
}
|
242
|
+
},false);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
public RhoBluetoothManagerNew sharedInstance() {
|
250
|
+
return (RhoBluetoothManagerNew)RhoBluetoothManager.sharedInstance();
|
251
|
+
}
|
252
|
+
|
253
|
+
public RhoBluetoothSession getSession() {
|
254
|
+
return mSession;
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
private void startClient() {
|
259
|
+
PerformOnUiThread.exec( new Runnable() {
|
260
|
+
public void run() {
|
261
|
+
if(D) Log.i(TAG, "startClient");
|
262
|
+
Intent serverIntent = new Intent(mActivity, RhoBluetoothDeviceListActivity.class);
|
263
|
+
//mActivity.startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
|
264
|
+
RhodesService.getInstance().startActivity(serverIntent);
|
265
|
+
}
|
266
|
+
},false);
|
267
|
+
}
|
268
|
+
|
269
|
+
private void startServer() {
|
270
|
+
PerformOnUiThread.exec( new Runnable() {
|
271
|
+
public void run() {
|
272
|
+
if(D) Log.i(TAG, "startServer");
|
273
|
+
if (mBluetoothAdapter.getScanMode() !=
|
274
|
+
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
275
|
+
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
|
276
|
+
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
|
277
|
+
RhodesService.getInstance().startActivity(discoverableIntent);
|
278
|
+
}
|
279
|
+
}
|
280
|
+
},false);
|
281
|
+
}
|
282
|
+
|
283
|
+
public int is_bluetooth_available() {
|
284
|
+
if (!mBluetoothIsEnabled) return 0;
|
285
|
+
return 1;
|
286
|
+
}
|
287
|
+
|
288
|
+
public void off_bluetooth() {
|
289
|
+
if (!mBluetoothIsEnabled) return;
|
290
|
+
//TODO
|
291
|
+
if (sharedInstance().getSession() != null) {
|
292
|
+
sharedInstance().getSession().stop();
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
public void set_device_name(String device_name) {
|
297
|
+
if (!mBluetoothIsEnabled) return;
|
298
|
+
if(D) Log.i(TAG, "set_device_name() : "+device_name);
|
299
|
+
sharedInstance().setDeviceName(device_name);
|
300
|
+
}
|
301
|
+
|
302
|
+
public String get_device_name() {
|
303
|
+
if (!mBluetoothIsEnabled) return "bluetooth is not worked";
|
304
|
+
if(D) Log.i(TAG, "get_device_name() : "+sharedInstance().mDeviceName);
|
305
|
+
return sharedInstance().mDeviceName;
|
306
|
+
}
|
307
|
+
|
308
|
+
public String get_last_error() {
|
309
|
+
if (!mBluetoothIsEnabled) return RhoBluetoothManager.BTC_ERROR;
|
310
|
+
return RhoBluetoothManager.BTC_OK;
|
311
|
+
}
|
312
|
+
|
313
|
+
public String create_session(String role, String callback_url) {
|
314
|
+
if (!mBluetoothIsEnabled) return RhoBluetoothManager.BTC_ERROR;
|
315
|
+
if(D) Log.i(TAG, "create_session("+role+", "+callback_url+");");
|
316
|
+
|
317
|
+
sharedInstance().mCreateSessionCallback = callback_url;
|
318
|
+
sharedInstance().mRole = role;
|
319
|
+
if (role.equalsIgnoreCase(RhoBluetoothManager.BT_ROLE_SERVER)) {
|
320
|
+
sharedInstance().startServer();
|
321
|
+
}
|
322
|
+
else {
|
323
|
+
sharedInstance().startClient();
|
324
|
+
}
|
325
|
+
return RhoBluetoothManager.BTC_OK;
|
326
|
+
}
|
327
|
+
|
328
|
+
public void fireCreateSessionCallback(String status, String connected_device_name) {
|
329
|
+
if(D) Log.i(TAG, "fireCreateSessionCallback");
|
330
|
+
StringBuffer body = new StringBuffer();
|
331
|
+
body.append("&status=");
|
332
|
+
body.append(status);
|
333
|
+
body.append("&connected_device_name=");
|
334
|
+
body.append(connected_device_name);
|
335
|
+
if (mCreateSessionCallback != null) {
|
336
|
+
RhoBluetoothManager.onCallback(mCreateSessionCallback, body.toString());
|
337
|
+
}
|
338
|
+
}
|
339
|
+
|
340
|
+
|
341
|
+
public void session_set_callback(String connected_device_name, String callback_url) {
|
342
|
+
if (!mBluetoothIsEnabled) return;
|
343
|
+
if(D) Log.i(TAG, "session_set_callback : "+callback_url);
|
344
|
+
sharedInstance().getSession().setCallbackURL(callback_url);
|
345
|
+
}
|
346
|
+
|
347
|
+
public void fireSessionCallback(String connected_device_name, String event_type) {
|
348
|
+
if(D) Log.i(TAG, "fireSessionCallback");
|
349
|
+
StringBuffer body = new StringBuffer();
|
350
|
+
body.append("&connected_device_name=");
|
351
|
+
body.append(connected_device_name);
|
352
|
+
body.append("&event_type=");
|
353
|
+
body.append(event_type);
|
354
|
+
if (mSession.getCallbackURL() != null) {
|
355
|
+
RhoBluetoothManager.onCallback(mSession.getCallbackURL(), body.toString());
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
public void session_disconnect(String connected_device_name) {
|
361
|
+
if (!mBluetoothIsEnabled) return;
|
362
|
+
if(D) Log.i(TAG, "session_disconnect");
|
363
|
+
//TODO
|
364
|
+
if (sharedInstance().getSession() != null) {
|
365
|
+
sharedInstance().getSession().stop();
|
366
|
+
}
|
367
|
+
}
|
368
|
+
|
369
|
+
public int session_get_status(String connected_device_name) {
|
370
|
+
if (!mBluetoothIsEnabled) return -1;
|
371
|
+
if(D) Log.i(TAG, "session_get_status");
|
372
|
+
//if (sharedInstance().mInputStringsArrayAdapter.isEmpty()) {
|
373
|
+
return sharedInstance().mInput.length();
|
374
|
+
}
|
375
|
+
|
376
|
+
public String session_read_string(String connected_device_name) {
|
377
|
+
if (!mBluetoothIsEnabled) return RhoBluetoothManager.BTC_ERROR;
|
378
|
+
if(D) Log.i(TAG, "session_read_string");
|
379
|
+
String t = sharedInstance().mInput.toString();
|
380
|
+
sharedInstance().mInput.setLength(0);
|
381
|
+
return t;
|
382
|
+
}
|
383
|
+
|
384
|
+
public void session_write_string(String connected_device_name, String str) {
|
385
|
+
if (!mBluetoothIsEnabled) return;
|
386
|
+
if(D) Log.i(TAG, "session_write_string");
|
387
|
+
sharedInstance().sendMessage(str);
|
388
|
+
}
|
389
|
+
|
390
|
+
public int session_read_data(String connected_device_name, Byte[] buf, int max_length) {
|
391
|
+
if (!mBluetoothIsEnabled) return 0;
|
392
|
+
return 0;
|
393
|
+
}
|
394
|
+
|
395
|
+
public void session_write_data(String connected_device_name, Byte[] buf, int length) {
|
396
|
+
if (!mBluetoothIsEnabled) return;
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
}
|