diff --git a/.gitignore b/.gitignore index db1555f..6ad636d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,180 @@ +*.iml .gradle /local.properties -/.idea/workspace.xml -/.idea/dictionaries/*.xml +/.idea/caches /.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store /build -/key* \ No newline at end of file +/captures +.externalNativeBuild +.cxx + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Gradle template +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Android template +# Built application files +*.apk +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ diff --git a/.gradle/2.4/taskArtifacts/cache.properties b/.gradle/2.4/taskArtifacts/cache.properties deleted file mode 100644 index 9b7e9e0..0000000 --- a/.gradle/2.4/taskArtifacts/cache.properties +++ /dev/null @@ -1 +0,0 @@ -#Tue Sep 01 14:08:01 CEST 2015 diff --git a/.gradle/2.4/taskArtifacts/cache.properties.lock b/.gradle/2.4/taskArtifacts/cache.properties.lock deleted file mode 100644 index 2c38677..0000000 Binary files a/.gradle/2.4/taskArtifacts/cache.properties.lock and /dev/null differ diff --git a/.gradle/2.4/taskArtifacts/fileHashes.bin b/.gradle/2.4/taskArtifacts/fileHashes.bin deleted file mode 100644 index e7ff9ee..0000000 Binary files a/.gradle/2.4/taskArtifacts/fileHashes.bin and /dev/null differ diff --git a/.gradle/2.4/taskArtifacts/fileSnapshots.bin b/.gradle/2.4/taskArtifacts/fileSnapshots.bin deleted file mode 100644 index a83e6ec..0000000 Binary files a/.gradle/2.4/taskArtifacts/fileSnapshots.bin and /dev/null differ diff --git a/.gradle/2.4/taskArtifacts/outputFileStates.bin b/.gradle/2.4/taskArtifacts/outputFileStates.bin deleted file mode 100644 index dadac45..0000000 Binary files a/.gradle/2.4/taskArtifacts/outputFileStates.bin and /dev/null differ diff --git a/.gradle/2.4/taskArtifacts/taskArtifacts.bin b/.gradle/2.4/taskArtifacts/taskArtifacts.bin deleted file mode 100644 index 36be43b..0000000 Binary files a/.gradle/2.4/taskArtifacts/taskArtifacts.bin and /dev/null differ diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index f5d5234..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -nRFUART_GoogleAPI_Android4.3+ \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 9a8b7e5..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index eb3ed0b..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_annotations_23_0_0.xml b/.idea/libraries/support_annotations_23_0_0.xml deleted file mode 100644 index d9910df..0000000 --- a/.idea/libraries/support_annotations_23_0_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_v4_23_0_0.xml b/.idea/libraries/support_v4_23_0_0.xml deleted file mode 100644 index c6d15b2..0000000 --- a/.idea/libraries/support_v4_23_0_0.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 10c6850..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 2db4b35..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 6564d52..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 44301fa..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,2101 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - localhost - 5050 - - - - - - - 1441109276965 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 7d85ea9..9d1de7d 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,5 @@ This source code can be compiled with Android Studio and Gradle. ### Note - Android 4.3 or later is required. -- Android Studio supported +- Android Studio supported +- AndroidX supported diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index c12f836..0000000 --- a/app/app.iml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index a84bae5..0513672 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 18 - buildToolsVersion "23.0.0" + compileSdkVersion 29 defaultConfig { applicationId "com.nordicsemi.nrfUARTv2" minSdkVersion 18 - targetSdkVersion 18 + targetSdkVersion 29 + versionCode 44 + versionName "2.0(44)" } @@ -19,5 +20,5 @@ android { } dependencies { - compile 'com.android.support:support-v4:23.0.0' + implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e2bf7c7..31f7d48 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,11 +26,9 @@ android:versionCode="43" android:versionName="2.0" > - + listAdapter; - private Button btnConnectDisconnect,btnSend; + private Button btnConnectDisconnect, btnSend; private EditText edtMessage; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -100,13 +90,12 @@ public void onCreate(Bundle savedInstanceState) { listAdapter = new ArrayAdapter(this, R.layout.message_detail); messageListView.setAdapter(listAdapter); messageListView.setDivider(null); - btnConnectDisconnect=(Button) findViewById(R.id.btn_select); - btnSend=(Button) findViewById(R.id.sendButton); + btnConnectDisconnect = (Button) findViewById(R.id.btn_select); + btnSend = (Button) findViewById(R.id.sendButton); edtMessage = (EditText) findViewById(R.id.sendText); service_init(); - - + // Handle Disconnect & Connect button btnConnectDisconnect.setOnClickListener(new View.OnClickListener() { @Override @@ -115,22 +104,20 @@ public void onClick(View v) { Log.i(TAG, "onClick - BT not enabled yet"); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); - } - else { - if (btnConnectDisconnect.getText().equals("Connect")){ - - //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices - - Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class); - startActivityForResult(newIntent, REQUEST_SELECT_DEVICE); - } else { - //Disconnect button pressed - if (mDevice!=null) - { - mService.disconnect(); - - } - } + } else { + if (btnConnectDisconnect.getText().equals("Connect")) { + + //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices + + Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class); + startActivityForResult(newIntent, REQUEST_SELECT_DEVICE); + } else { + //Disconnect button pressed + if (mDevice != null) { + mService.disconnect(); + + } + } } } }); @@ -138,54 +125,54 @@ public void onClick(View v) { btnSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - EditText editText = (EditText) findViewById(R.id.sendText); - String message = editText.getText().toString(); - byte[] value; - try { - //send data to service - value = message.getBytes("UTF-8"); - mService.writeRXCharacteristic(value); - //Update the log with time stamp - String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); - listAdapter.add("["+currentDateTimeString+"] TX: "+ message); - messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); - edtMessage.setText(""); - } catch (UnsupportedEncodingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + EditText editText = (EditText) findViewById(R.id.sendText); + String message = editText.getText().toString(); + byte[] value; + try { + //send data to service + value = message.getBytes("UTF-8"); + mService.writeRXCharacteristic(value); + //Update the log with time stamp + String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); + listAdapter.add("[" + currentDateTimeString + "] TX: " + message); + messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); + edtMessage.setText(""); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } }); - + // Set initial UI state - + } - + //UART service connected/disconnected private ServiceConnection mServiceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder rawBinder) { - mService = ((UartService.LocalBinder) rawBinder).getService(); - Log.d(TAG, "onServiceConnected mService= " + mService); - if (!mService.initialize()) { - Log.e(TAG, "Unable to initialize Bluetooth"); - finish(); - } + mService = ((UartService.LocalBinder) rawBinder).getService(); + Log.d(TAG, "onServiceConnected mService= " + mService); + if (!mService.initialize()) { + Log.e(TAG, "Unable to initialize Bluetooth"); + finish(); + } } public void onServiceDisconnected(ComponentName classname) { - //// mService.disconnect(mDevice); - mService = null; + //// mService.disconnect(mDevice); + mService = null; } }; private Handler mHandler = new Handler() { @Override - + //Handler events that received from UART service public void handleMessage(Message msg) { - + } }; @@ -195,81 +182,82 @@ public void onReceive(Context context, Intent intent) { String action = intent.getAction(); final Intent mIntent = intent; - //*********************// + //*********************// if (action.equals(UartService.ACTION_GATT_CONNECTED)) { - runOnUiThread(new Runnable() { - public void run() { - String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); - Log.d(TAG, "UART_CONNECT_MSG"); - btnConnectDisconnect.setText("Disconnect"); - edtMessage.setEnabled(true); - btnSend.setEnabled(true); - ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName()+ " - ready"); - listAdapter.add("["+currentDateTimeString+"] Connected to: "+ mDevice.getName()); - messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); - mState = UART_PROFILE_CONNECTED; - } - }); + runOnUiThread(new Runnable() { + public void run() { + String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); + Log.d(TAG, "UART_CONNECT_MSG"); + btnConnectDisconnect.setText("Disconnect"); + edtMessage.setEnabled(true); + btnSend.setEnabled(true); + ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - ready"); + listAdapter.add("[" + currentDateTimeString + "] Connected to: " + mDevice.getName()); + messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); + mState = UART_PROFILE_CONNECTED; + } + }); } - - //*********************// + + //*********************// if (action.equals(UartService.ACTION_GATT_DISCONNECTED)) { - runOnUiThread(new Runnable() { - public void run() { - String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); - Log.d(TAG, "UART_DISCONNECT_MSG"); - btnConnectDisconnect.setText("Connect"); - edtMessage.setEnabled(false); - btnSend.setEnabled(false); - ((TextView) findViewById(R.id.deviceName)).setText("Not Connected"); - listAdapter.add("["+currentDateTimeString+"] Disconnected to: "+ mDevice.getName()); - mState = UART_PROFILE_DISCONNECTED; - mService.close(); - //setUiState(); - - } - }); + runOnUiThread(new Runnable() { + public void run() { + String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); + Log.d(TAG, "UART_DISCONNECT_MSG"); + btnConnectDisconnect.setText("Connect"); + edtMessage.setEnabled(false); + btnSend.setEnabled(false); + ((TextView) findViewById(R.id.deviceName)).setText("Not Connected"); + listAdapter.add("[" + currentDateTimeString + "] Disconnected to: " + mDevice.getName()); + mState = UART_PROFILE_DISCONNECTED; + mService.close(); + //setUiState(); + + } + }); } - - - //*********************// + + + //*********************// if (action.equals(UartService.ACTION_GATT_SERVICES_DISCOVERED)) { - mService.enableTXNotification(); + mService.enableTXNotification(); } - //*********************// + //*********************// if (action.equals(UartService.ACTION_DATA_AVAILABLE)) { - - final byte[] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA); - runOnUiThread(new Runnable() { - public void run() { - try { - String text = new String(txValue, "UTF-8"); - String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); - listAdapter.add("["+currentDateTimeString+"] RX: "+text); - messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); - - } catch (Exception e) { - Log.e(TAG, e.toString()); - } - } - }); - } - //*********************// - if (action.equals(UartService.DEVICE_DOES_NOT_SUPPORT_UART)){ - showMessage("Device doesn't support UART. Disconnecting"); - mService.disconnect(); + + final byte[] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA); + runOnUiThread(new Runnable() { + public void run() { + try { + String text = new String(txValue, "UTF-8"); + String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); + listAdapter.add("[" + currentDateTimeString + "] RX: " + text); + messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); + + } catch (Exception e) { + Log.e(TAG, e.toString()); + } + } + }); + } + //*********************// + if (action.equals(UartService.DEVICE_DOES_NOT_SUPPORT_UART)) { + showMessage("Device doesn't support UART. Disconnecting"); + mService.disconnect(); } - - + + } }; private void service_init() { Intent bindIntent = new Intent(this, UartService.class); bindService(bindIntent, mServiceConnection, Context.BIND_AUTO_CREATE); - + LocalBroadcastManager.getInstance(this).registerReceiver(UARTStatusChangeReceiver, makeGattUpdateIntentFilter()); } + private static IntentFilter makeGattUpdateIntentFilter() { final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(UartService.ACTION_GATT_CONNECTED); @@ -279,6 +267,7 @@ private static IntentFilter makeGattUpdateIntentFilter() { intentFilter.addAction(UartService.DEVICE_DOES_NOT_SUPPORT_UART); return intentFilter; } + @Override public void onStart() { super.onStart(); @@ -286,18 +275,18 @@ public void onStart() { @Override public void onDestroy() { - super.onDestroy(); + super.onDestroy(); Log.d(TAG, "onDestroy()"); - + try { - LocalBroadcastManager.getInstance(this).unregisterReceiver(UARTStatusChangeReceiver); + LocalBroadcastManager.getInstance(this).unregisterReceiver(UARTStatusChangeReceiver); } catch (Exception ignore) { Log.e(TAG, ignore.toString()); - } + } unbindService(mServiceConnection); mService.stopSelf(); - mService= null; - + mService = null; + } @Override @@ -327,7 +316,7 @@ public void onResume() { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } - + } @Override @@ -339,46 +328,46 @@ public void onConfigurationChanged(Configuration newConfig) { public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { - case REQUEST_SELECT_DEVICE: - //When the DeviceListActivity return, with the selected device address - if (resultCode == Activity.RESULT_OK && data != null) { - String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); - mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); - - Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); - ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName()+ " - connecting"); - mService.connect(deviceAddress); - + case REQUEST_SELECT_DEVICE: + //When the DeviceListActivity return, with the selected device address + if (resultCode == Activity.RESULT_OK && data != null) { + String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); + mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); - } - break; - case REQUEST_ENABLE_BT: - // When the request to enable Bluetooth returns - if (resultCode == Activity.RESULT_OK) { - Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); - - } else { - // User did not enable Bluetooth or an error occurred - Log.d(TAG, "BT not enabled"); - Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); - finish(); - } - break; - default: - Log.e(TAG, "wrong request code"); - break; + Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); + ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); + mService.connect(deviceAddress); + + + } + break; + case REQUEST_ENABLE_BT: + // When the request to enable Bluetooth returns + if (resultCode == Activity.RESULT_OK) { + Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); + + } else { + // User did not enable Bluetooth or an error occurred + Log.d(TAG, "BT not enabled"); + Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); + finish(); + } + break; + default: + Log.e(TAG, "wrong request code"); + break; } } @Override public void onCheckedChanged(RadioGroup group, int checkedId) { - + } - + private void showMessage(String msg) { Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); - + } @Override @@ -389,21 +378,19 @@ public void onBackPressed() { startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(startMain); showMessage("nRFUART's running in background.\n Disconnect to exit"); - } - else { + } else { new AlertDialog.Builder(this) - .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle(R.string.popup_title) - .setMessage(R.string.popup_message) - .setPositiveButton(R.string.popup_yes, new DialogInterface.OnClickListener() - { - @Override - public void onClick(DialogInterface dialog, int which) { - finish(); - } - }) - .setNegativeButton(R.string.popup_no, null) - .show(); + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(R.string.popup_title) + .setMessage(R.string.popup_message) + .setPositiveButton(R.string.popup_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } + }) + .setNegativeButton(R.string.popup_no, null) + .show(); } } } diff --git a/app/src/main/java/com/nordicsemi/nrfUARTv2/UartService.java b/app/src/main/java/com/nordicsemi/nrfUARTv2/UartService.java index 8241dd4..9221266 100644 --- a/app/src/main/java/com/nordicsemi/nrfUARTv2/UartService.java +++ b/app/src/main/java/com/nordicsemi/nrfUARTv2/UartService.java @@ -36,9 +36,10 @@ import android.content.Intent; import android.os.Binder; import android.os.IBinder; -import android.support.v4.content.LocalBroadcastManager; import android.util.Log; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + import java.util.List; import java.util.UUID; @@ -71,7 +72,7 @@ public class UartService extends Service { "com.nordicsemi.nrfUART.EXTRA_DATA"; public final static String DEVICE_DOES_NOT_SUPPORT_UART = "com.nordicsemi.nrfUART.DEVICE_DOES_NOT_SUPPORT_UART"; - + public static final UUID TX_POWER_UUID = UUID.fromString("00001804-0000-1000-8000-00805f9b34fb"); public static final UUID TX_POWER_LEVEL_UUID = UUID.fromString("00002a07-0000-1000-8000-00805f9b34fb"); public static final UUID CCCD = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); @@ -80,15 +81,13 @@ public class UartService extends Service { public static final UUID RX_SERVICE_UUID = UUID.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e"); public static final UUID RX_CHAR_UUID = UUID.fromString("6e400002-b5a3-f393-e0a9-e50e24dcca9e"); public static final UUID TX_CHAR_UUID = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); - - // Implements callback methods for GATT events that the app cares about. For example, // connection change and services discovered. private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { String intentAction; - + if (newState == BluetoothProfile.STATE_CONNECTED) { intentAction = ACTION_GATT_CONNECTED; mConnectionState = STATE_CONNECTED; @@ -109,8 +108,8 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { - Log.w(TAG, "mBluetoothGatt = " + mBluetoothGatt ); - + Log.w(TAG, "mBluetoothGatt = " + mBluetoothGatt); + broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); } else { Log.w(TAG, "onServicesDiscovered received: " + status); @@ -144,11 +143,11 @@ private void broadcastUpdate(final String action, // This is handling for the notification on TX Character of NUS service if (TX_CHAR_UUID.equals(characteristic.getUuid())) { - - // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() )); + + // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() )); intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else { - + } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } @@ -204,11 +203,10 @@ public boolean initialize() { * Connects to the GATT server hosted on the Bluetooth LE device. * * @param address The device address of the destination device. - * * @return Return true if the connection is initiated successfully. The connection result - * is reported asynchronously through the - * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)} - * callback. + * is reported asynchronously through the + * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)} + * callback. */ public boolean connect(final String address) { if (mBluetoothAdapter == null || address == null) { @@ -254,7 +252,7 @@ public void disconnect() { return; } mBluetoothGatt.disconnect(); - // mBluetoothGatt.close(); + // mBluetoothGatt.close(); } /** @@ -290,15 +288,14 @@ public void readCharacteristic(BluetoothGattCharacteristic characteristic) { * Enables or disables notification on a give characteristic. * - */ - + */ + /** * Enable Notification on TX characteristic * - * @return + * @return */ - public void enableTXNotification() - { + public void enableTXNotification() { /* if (mBluetoothGatt == null) { showMessage("mBluetoothGatt null" + mBluetoothGatt); @@ -306,52 +303,50 @@ public void enableTXNotification() return; } */ - BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); - if (RxService == null) { + BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); + if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } - BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID); + BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID); if (TxChar == null) { showMessage("Tx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } - mBluetoothGatt.setCharacteristicNotification(TxChar,true); - + mBluetoothGatt.setCharacteristicNotification(TxChar, true); + BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); - + } - - public void writeRXCharacteristic(byte[] value) - { - - - BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); - showMessage("mBluetoothGatt null"+ mBluetoothGatt); - if (RxService == null) { + + public void writeRXCharacteristic(byte[] value) { + BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); + showMessage("mBluetoothGatt null" + mBluetoothGatt); + if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } - BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); + BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); if (RxChar == null) { showMessage("Rx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } RxChar.setValue(value); - boolean status = mBluetoothGatt.writeCharacteristic(RxChar); - - Log.d(TAG, "write TXchar - status=" + status); + boolean status = mBluetoothGatt.writeCharacteristic(RxChar); + + Log.d(TAG, "write TXchar - status=" + status); } - + private void showMessage(String msg) { Log.e(TAG, msg); } + /** * Retrieves a list of supported GATT services on the connected device. This should be * invoked only after {@code BluetoothGatt#discoverServices()} completes successfully. diff --git a/build.gradle b/build.gradle index a1d5c84..9bdd339 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' + classpath 'com.android.tools.build:gradle:3.5.3' } } allprojects { repositories { + google() jcenter() } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 8c0fb64..cc4fdc2 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0c71e76..1ba7206 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Apr 10 15:27:10 PDT 2013 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index 91a7e26..2fe81a7 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +75,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +105,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -110,10 +125,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -138,27 +154,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 8a0b282..9618d8d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,14 +24,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +62,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +75,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/import-summary.txt b/import-summary.txt deleted file mode 100644 index df446cd..0000000 --- a/import-summary.txt +++ /dev/null @@ -1,45 +0,0 @@ -ECLIPSE ANDROID PROJECT IMPORT SUMMARY -====================================== - -Risky Project Location: ------------------------ -The tools *should* handle project locations in any directory. However, -due to bugs, placing projects in directories containing spaces in the -path, or characters like ", ' and &, have had issues. We're working to -eliminate these bugs, but to save yourself headaches you may want to -move your project to a location where this is not a problem. -C:\Nordic Semiconductor\Android\Android_Studio_Tutor\nRFUART_GoogleAPI_Android4.3+ - - - -Ignored Files: --------------- -The following files were *not* copied into the new Gradle project; you -should evaluate whether these are still needed in your project and if -so manually move them: - -* Android.mk - -Moved Files: ------------- -Android Gradle projects use a different directory structure than ADT -Eclipse projects. Here's how the projects were restructured: - -* AndroidManifest.xml => app\src\main\AndroidManifest.xml -* assets\ => app\src\main\assets -* res\ => app\src\main\res\ -* src\ => app\src\main\java\ - -Next Steps: ------------ -You can now build the project. The Gradle project needs network -connectivity to download dependencies. - -Bugs: ------ -If for some reason your project does not build, and you determine that -it is due to a bug or limitation of the Eclipse to Gradle importer, -please file a bug at http://b.android.com with category -Component-Tools. - -(This import summary is for your information only, and can be deleted -after import once you are satisfied with the results.) diff --git a/local.properties b/local.properties deleted file mode 100644 index f7483b8..0000000 --- a/local.properties +++ /dev/null @@ -1,11 +0,0 @@ -## This file is automatically generated by Android Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Tue Sep 01 15:09:41 CEST 2015 -sdk.dir=C\:\\Users\\hubu\\AppData\\Local\\Android\\sdk diff --git a/nRFUART_GoogleAPI_Android4.3+.iml b/nRFUART_GoogleAPI_Android4.3+.iml deleted file mode 100644 index 4135c60..0000000 --- a/nRFUART_GoogleAPI_Android4.3+.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file