From 2c527a71b547908aea5827f07d75a0b74961b2f0 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Mon, 8 Oct 2018 14:27:18 +0800 Subject: [PATCH 1/4] Update gradle dependencies & build system --- .gitignore | 3 +++ build.gradle | 18 ++++++++---------- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/AndroidManifest.xml | 2 -- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index be7a8b3..e4cd4e0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,12 +17,15 @@ local.properties .idea/libraries/ .idea/workspace.xml .idea/tasks.xml +.idea/caches/ .idea/.name .idea/compiler.xml +.idea/gradle.xml .idea/copyright/profiles_settings.xml .idea/encodings.xml .idea/misc.xml .idea/modules.xml +.idea/runConfigurations.xml .idea/scopes/scope_settings.xml .idea/vcs.xml *.iml diff --git a/build.gradle b/build.gradle index ee2a4a9..2c036d7 100755 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 28 defaultConfig { minSdkVersion 14 - targetSdkVersion 25 + targetSdkVersion 28 versionCode 3 versionName '0.3' - version 0.3 } buildTypes { release { @@ -16,26 +14,26 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - productFlavors { - } } buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:3.2.0' } } repositories { jcenter() mavenCentral() + google() } dependencies { - compile 'com.android.support:support-annotations:25.3.1' - compile 'com.arasthel:asyncjob-library:1.0.3' - compile 'com.bluelinelabs:logansquare:1.0.6' + implementation 'com.android.support:support-annotations:28.0.0' + implementation 'com.arasthel:asyncjob-library:1.0.3' + implementation 'com.bluelinelabs:logansquare:1.0.6' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a778d6..55c5503 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 151c45b..c7d7842 100755 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -7,6 +7,4 @@ - - From 5c05a590b54b6a1d17e6b3145e362088f5dee6f2 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Mon, 8 Oct 2018 14:32:35 +0800 Subject: [PATCH 2/4] Move library code into dedicated folder --- build.gradle | 36 +--- library/.gitignore | 1 + library/build.gradle | 33 ++++ .../proguard-rules.pro | 0 {src => library/src}/main/AndroidManifest.xml | 0 .../BackgroundClientRegistrationJob.java | 0 .../com/peak/salut/BackgroundDataJob.java | 0 .../com/peak/salut/BackgroundDataSendJob.java | 0 .../BackgroundServerRegistrationJob.java | 0 .../peak/salut/Callbacks/SalutCallback.java | 0 .../salut/Callbacks/SalutDataCallback.java | 0 .../salut/Callbacks/SalutDeviceCallback.java | 14 +- .../salut/Callbacks/SalutServiceCallback.java | 0 .../src}/main/java/com/peak/salut/Salut.java | 0 .../peak/salut/SalutBroadcastReceiver.java | 160 +++++++++--------- .../com/peak/salut/SalutDataReceiver.java | 0 .../main/java/com/peak/salut/SalutDevice.java | 0 .../java/com/peak/salut/SalutServiceData.java | 0 .../src}/main/res/values/strings.xml | 0 settings.gradle | 3 + .../java/com/peak/salut/ApplicationTest.java | 13 -- 21 files changed, 131 insertions(+), 129 deletions(-) create mode 100644 library/.gitignore create mode 100644 library/build.gradle rename proguard-rules.pro => library/proguard-rules.pro (100%) rename {src => library/src}/main/AndroidManifest.xml (100%) rename {src => library/src}/main/java/com/peak/salut/BackgroundClientRegistrationJob.java (100%) rename {src => library/src}/main/java/com/peak/salut/BackgroundDataJob.java (100%) rename {src => library/src}/main/java/com/peak/salut/BackgroundDataSendJob.java (100%) rename {src => library/src}/main/java/com/peak/salut/BackgroundServerRegistrationJob.java (100%) rename {src => library/src}/main/java/com/peak/salut/Callbacks/SalutCallback.java (100%) rename {src => library/src}/main/java/com/peak/salut/Callbacks/SalutDataCallback.java (100%) rename {src => library/src}/main/java/com/peak/salut/Callbacks/SalutDeviceCallback.java (95%) rename {src => library/src}/main/java/com/peak/salut/Callbacks/SalutServiceCallback.java (100%) rename {src => library/src}/main/java/com/peak/salut/Salut.java (100%) rename {src => library/src}/main/java/com/peak/salut/SalutBroadcastReceiver.java (97%) rename {src => library/src}/main/java/com/peak/salut/SalutDataReceiver.java (100%) rename {src => library/src}/main/java/com/peak/salut/SalutDevice.java (100%) rename {src => library/src}/main/java/com/peak/salut/SalutServiceData.java (100%) rename {src => library/src}/main/res/values/strings.xml (100%) mode change 100755 => 100644 create mode 100644 settings.gradle delete mode 100644 src/androidTest/java/com/peak/salut/ApplicationTest.java diff --git a/build.gradle b/build.gradle index 2c036d7..34ea0bc 100755 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,3 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 28 - defaultConfig { - minSdkVersion 14 - targetSdkVersion 28 - versionCode 3 - versionName '0.3' - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - buildscript { repositories { jcenter() @@ -26,14 +8,10 @@ buildscript { } } -repositories { - jcenter() - mavenCentral() - google() -} - -dependencies { - implementation 'com.android.support:support-annotations:28.0.0' - implementation 'com.arasthel:asyncjob-library:1.0.3' - implementation 'com.bluelinelabs:logansquare:1.0.6' -} +allprojects { + repositories { + jcenter() + mavenCentral() + google() + } +} \ No newline at end of file diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/library/.gitignore @@ -0,0 +1 @@ +/build diff --git a/library/build.gradle b/library/build.gradle new file mode 100644 index 0000000..b997782 --- /dev/null +++ b/library/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 28 + + + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'com.android.support:support-annotations:28.0.0' + implementation 'com.arasthel:asyncjob-library:1.0.3' + implementation 'com.bluelinelabs:logansquare:1.0.6' +} diff --git a/proguard-rules.pro b/library/proguard-rules.pro similarity index 100% rename from proguard-rules.pro rename to library/proguard-rules.pro diff --git a/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml similarity index 100% rename from src/main/AndroidManifest.xml rename to library/src/main/AndroidManifest.xml diff --git a/src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java b/library/src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java similarity index 100% rename from src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java rename to library/src/main/java/com/peak/salut/BackgroundClientRegistrationJob.java diff --git a/src/main/java/com/peak/salut/BackgroundDataJob.java b/library/src/main/java/com/peak/salut/BackgroundDataJob.java similarity index 100% rename from src/main/java/com/peak/salut/BackgroundDataJob.java rename to library/src/main/java/com/peak/salut/BackgroundDataJob.java diff --git a/src/main/java/com/peak/salut/BackgroundDataSendJob.java b/library/src/main/java/com/peak/salut/BackgroundDataSendJob.java similarity index 100% rename from src/main/java/com/peak/salut/BackgroundDataSendJob.java rename to library/src/main/java/com/peak/salut/BackgroundDataSendJob.java diff --git a/src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java b/library/src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java similarity index 100% rename from src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java rename to library/src/main/java/com/peak/salut/BackgroundServerRegistrationJob.java diff --git a/src/main/java/com/peak/salut/Callbacks/SalutCallback.java b/library/src/main/java/com/peak/salut/Callbacks/SalutCallback.java similarity index 100% rename from src/main/java/com/peak/salut/Callbacks/SalutCallback.java rename to library/src/main/java/com/peak/salut/Callbacks/SalutCallback.java diff --git a/src/main/java/com/peak/salut/Callbacks/SalutDataCallback.java b/library/src/main/java/com/peak/salut/Callbacks/SalutDataCallback.java similarity index 100% rename from src/main/java/com/peak/salut/Callbacks/SalutDataCallback.java rename to library/src/main/java/com/peak/salut/Callbacks/SalutDataCallback.java diff --git a/src/main/java/com/peak/salut/Callbacks/SalutDeviceCallback.java b/library/src/main/java/com/peak/salut/Callbacks/SalutDeviceCallback.java similarity index 95% rename from src/main/java/com/peak/salut/Callbacks/SalutDeviceCallback.java rename to library/src/main/java/com/peak/salut/Callbacks/SalutDeviceCallback.java index e77f7a4..87fc094 100755 --- a/src/main/java/com/peak/salut/Callbacks/SalutDeviceCallback.java +++ b/library/src/main/java/com/peak/salut/Callbacks/SalutDeviceCallback.java @@ -1,7 +1,7 @@ -package com.peak.salut.Callbacks; - -import com.peak.salut.SalutDevice; - -public interface SalutDeviceCallback { - void call(SalutDevice device); -} +package com.peak.salut.Callbacks; + +import com.peak.salut.SalutDevice; + +public interface SalutDeviceCallback { + void call(SalutDevice device); +} diff --git a/src/main/java/com/peak/salut/Callbacks/SalutServiceCallback.java b/library/src/main/java/com/peak/salut/Callbacks/SalutServiceCallback.java similarity index 100% rename from src/main/java/com/peak/salut/Callbacks/SalutServiceCallback.java rename to library/src/main/java/com/peak/salut/Callbacks/SalutServiceCallback.java diff --git a/src/main/java/com/peak/salut/Salut.java b/library/src/main/java/com/peak/salut/Salut.java similarity index 100% rename from src/main/java/com/peak/salut/Salut.java rename to library/src/main/java/com/peak/salut/Salut.java diff --git a/src/main/java/com/peak/salut/SalutBroadcastReceiver.java b/library/src/main/java/com/peak/salut/SalutBroadcastReceiver.java similarity index 97% rename from src/main/java/com/peak/salut/SalutBroadcastReceiver.java rename to library/src/main/java/com/peak/salut/SalutBroadcastReceiver.java index bb1a70c..714ff79 100755 --- a/src/main/java/com/peak/salut/SalutBroadcastReceiver.java +++ b/library/src/main/java/com/peak/salut/SalutBroadcastReceiver.java @@ -1,81 +1,81 @@ -package com.peak.salut; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.net.NetworkInfo; -import android.net.wifi.p2p.WifiP2pDevice; -import android.net.wifi.p2p.WifiP2pManager; -import android.os.IBinder; -import android.util.Log; - - -public class SalutBroadcastReceiver extends BroadcastReceiver { - - private WifiP2pManager manager; - private WifiP2pManager.Channel channel; - private Salut salutInstance; - - final static String TAG = "Salut"; - - public SalutBroadcastReceiver(Salut salutInstance, WifiP2pManager manager, WifiP2pManager.Channel channel) { - super(); - this.manager = manager; - this.channel = channel; - this.salutInstance = salutInstance; - } - - @Override - public void onReceive(Context context, Intent intent) { - - String action = intent.getAction(); - - if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { - - int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1); - - if (state != WifiP2pManager.WIFI_P2P_STATE_ENABLED) { - Log.v(TAG, " WiFi P2P is no longer enabled."); - } - } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { - - if (manager == null) { - return; - } - - NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); - - if (networkInfo.isConnected() && networkInfo.getTypeName().equals("WIFI_P2P")) { - salutInstance.isConnectedToAnotherDevice = true; - manager.requestConnectionInfo(channel, salutInstance); - - } else { - - salutInstance.isConnectedToAnotherDevice = false; - - Log.v(TAG, "Not connected to another device."); - if (salutInstance.thisDevice.isRegistered) { - if (salutInstance.unexpectedDisconnect != null) { - salutInstance.unregisterClient(salutInstance.unexpectedDisconnect, null, false); - } - } - - } - - } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { - - WifiP2pDevice device = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); - - if (salutInstance.thisDevice.deviceName == null) { - salutInstance.thisDevice.deviceName = device.deviceName; - salutInstance.thisDevice.macAddress = device.deviceAddress; - } - } - - } - - @Override - public IBinder peekService(Context myContext, Intent service) { - return super.peekService(myContext, service); - } +package com.peak.salut; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.NetworkInfo; +import android.net.wifi.p2p.WifiP2pDevice; +import android.net.wifi.p2p.WifiP2pManager; +import android.os.IBinder; +import android.util.Log; + + +public class SalutBroadcastReceiver extends BroadcastReceiver { + + private WifiP2pManager manager; + private WifiP2pManager.Channel channel; + private Salut salutInstance; + + final static String TAG = "Salut"; + + public SalutBroadcastReceiver(Salut salutInstance, WifiP2pManager manager, WifiP2pManager.Channel channel) { + super(); + this.manager = manager; + this.channel = channel; + this.salutInstance = salutInstance; + } + + @Override + public void onReceive(Context context, Intent intent) { + + String action = intent.getAction(); + + if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { + + int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1); + + if (state != WifiP2pManager.WIFI_P2P_STATE_ENABLED) { + Log.v(TAG, " WiFi P2P is no longer enabled."); + } + } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { + + if (manager == null) { + return; + } + + NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); + + if (networkInfo.isConnected() && networkInfo.getTypeName().equals("WIFI_P2P")) { + salutInstance.isConnectedToAnotherDevice = true; + manager.requestConnectionInfo(channel, salutInstance); + + } else { + + salutInstance.isConnectedToAnotherDevice = false; + + Log.v(TAG, "Not connected to another device."); + if (salutInstance.thisDevice.isRegistered) { + if (salutInstance.unexpectedDisconnect != null) { + salutInstance.unregisterClient(salutInstance.unexpectedDisconnect, null, false); + } + } + + } + + } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { + + WifiP2pDevice device = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); + + if (salutInstance.thisDevice.deviceName == null) { + salutInstance.thisDevice.deviceName = device.deviceName; + salutInstance.thisDevice.macAddress = device.deviceAddress; + } + } + + } + + @Override + public IBinder peekService(Context myContext, Intent service) { + return super.peekService(myContext, service); + } } \ No newline at end of file diff --git a/src/main/java/com/peak/salut/SalutDataReceiver.java b/library/src/main/java/com/peak/salut/SalutDataReceiver.java similarity index 100% rename from src/main/java/com/peak/salut/SalutDataReceiver.java rename to library/src/main/java/com/peak/salut/SalutDataReceiver.java diff --git a/src/main/java/com/peak/salut/SalutDevice.java b/library/src/main/java/com/peak/salut/SalutDevice.java similarity index 100% rename from src/main/java/com/peak/salut/SalutDevice.java rename to library/src/main/java/com/peak/salut/SalutDevice.java diff --git a/src/main/java/com/peak/salut/SalutServiceData.java b/library/src/main/java/com/peak/salut/SalutServiceData.java similarity index 100% rename from src/main/java/com/peak/salut/SalutServiceData.java rename to library/src/main/java/com/peak/salut/SalutServiceData.java diff --git a/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml old mode 100755 new mode 100644 similarity index 100% rename from src/main/res/values/strings.xml rename to library/src/main/res/values/strings.xml diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..a01170b --- /dev/null +++ b/settings.gradle @@ -0,0 +1,3 @@ +include ':library' + + diff --git a/src/androidTest/java/com/peak/salut/ApplicationTest.java b/src/androidTest/java/com/peak/salut/ApplicationTest.java deleted file mode 100644 index 5d2602e..0000000 --- a/src/androidTest/java/com/peak/salut/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.peak.salut; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file From f952371abccc241b362872c9f8ec763a25aa8556 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Mon, 8 Oct 2018 16:10:12 +0800 Subject: [PATCH 3/4] Add a simple demo to test service discovery and connection. --- build.gradle | 8 +- demo/.gitignore | 1 + demo/build.gradle | 44 +++++ demo/proguard-rules.pro | 21 +++ demo/src/main/AndroidManifest.xml | 21 +++ .../java/com/peak/salut/demo/MainActivity.kt | 171 ++++++++++++++++++ .../res/drawable-hdpi/ic_action_cancel.png | Bin 0 -> 397 bytes .../res/drawable-mdpi/ic_action_cancel.png | Bin 0 -> 294 bytes .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../res/drawable-xhdpi/ic_action_cancel.png | Bin 0 -> 530 bytes .../res/drawable-xxhdpi/ic_action_cancel.png | Bin 0 -> 851 bytes .../res/drawable-xxxhdpi/ic_action_cancel.png | Bin 0 -> 1161 bytes .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ demo/src/main/res/layout/activity_main.xml | 68 +++++++ demo/src/main/res/layout/list_item_device.xml | 31 ++++ demo/src/main/res/menu/menu_demo.xml | 7 + .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + demo/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes demo/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes demo/src/main/res/values/colors.xml | 6 + demo/src/main/res/values/strings.xml | 3 + demo/src/main/res/values/styles.xml | 11 ++ gradlew | 0 settings.gradle | 2 +- 33 files changed, 604 insertions(+), 4 deletions(-) create mode 100644 demo/.gitignore create mode 100644 demo/build.gradle create mode 100644 demo/proguard-rules.pro create mode 100644 demo/src/main/AndroidManifest.xml create mode 100644 demo/src/main/java/com/peak/salut/demo/MainActivity.kt create mode 100644 demo/src/main/res/drawable-hdpi/ic_action_cancel.png create mode 100644 demo/src/main/res/drawable-mdpi/ic_action_cancel.png create mode 100644 demo/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 demo/src/main/res/drawable-xhdpi/ic_action_cancel.png create mode 100644 demo/src/main/res/drawable-xxhdpi/ic_action_cancel.png create mode 100644 demo/src/main/res/drawable-xxxhdpi/ic_action_cancel.png create mode 100644 demo/src/main/res/drawable/ic_launcher_background.xml create mode 100644 demo/src/main/res/layout/activity_main.xml create mode 100644 demo/src/main/res/layout/list_item_device.xml create mode 100644 demo/src/main/res/menu/menu_demo.xml create mode 100644 demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 demo/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 demo/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 demo/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 demo/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 demo/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 demo/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 demo/src/main/res/values/colors.xml create mode 100644 demo/src/main/res/values/strings.xml create mode 100644 demo/src/main/res/values/styles.xml mode change 100644 => 100755 gradlew diff --git a/build.gradle b/build.gradle index 34ea0bc..c7ee934 100755 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,13 @@ -buildscript { +buildscript { + ext.kotlin_version = '1.2.71' + repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.2.0' - } + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { @@ -14,4 +16,4 @@ allprojects { mavenCentral() google() } -} \ No newline at end of file +} diff --git a/demo/.gitignore b/demo/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/demo/.gitignore @@ -0,0 +1 @@ +/build diff --git a/demo/build.gradle b/demo/build.gradle new file mode 100644 index 0000000..0f1523a --- /dev/null +++ b/demo/build.gradle @@ -0,0 +1,44 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +android { + compileSdkVersion 28 + + + + defaultConfig { + applicationId "com.peak.salut.demo" + minSdkVersion 14 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation project(':library') + + annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.4' + implementation 'com.bluelinelabs:logansquare:1.3.4' + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.android.support:recyclerview-v7:28.0.0' + implementation 'com.pascalwelsch.arrayadapter:arrayadapter:1.3.0' +} diff --git a/demo/proguard-rules.pro b/demo/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/demo/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml new file mode 100644 index 0000000..1df0c72 --- /dev/null +++ b/demo/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/src/main/java/com/peak/salut/demo/MainActivity.kt b/demo/src/main/java/com/peak/salut/demo/MainActivity.kt new file mode 100644 index 0000000..1416cd4 --- /dev/null +++ b/demo/src/main/java/com/peak/salut/demo/MainActivity.kt @@ -0,0 +1,171 @@ +package com.peak.salut.demo + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.util.Log +import android.view.* +import android.widget.Button +import android.widget.TextView +import com.bluelinelabs.logansquare.LoganSquare +import com.pascalwelsch.arrayadapter.ArrayAdapter +import com.peak.salut.Callbacks.SalutCallback +import com.peak.salut.Callbacks.SalutDataCallback +import com.peak.salut.Callbacks.SalutDeviceCallback +import com.peak.salut.Salut +import com.peak.salut.SalutDataReceiver +import com.peak.salut.SalutDevice +import com.peak.salut.SalutServiceData +import kotlinx.android.synthetic.main.activity_main.* +import java.util.* + +class MainActivity : AppCompatActivity() { + + enum class UiState { + DEFAULT, + HOST_MODE, + CLIENT_MODE + } + + class MySalut(dataReceiver: SalutDataReceiver?, salutServiceData: SalutServiceData?, deviceNotSupported: SalutCallback?) : Salut(dataReceiver, salutServiceData, deviceNotSupported) { + override fun serialize(o: Any?): String { + return LoganSquare.serialize(o) + } + } + + private lateinit var salut: Salut + private var uiState = UiState.DEFAULT + + private lateinit var connectedDevicesAdapter: SimpleAdapter + + companion object { + const val TAG = "SalutDemo" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val dataReceiver = SalutDataReceiver(this, SalutDataCallback { + + }) + + val instanceName = "Demo ID ${Random().nextInt(200)}" + + instanceNameLabel.text = "My Instance Name: $instanceName" + + val serviceData = SalutServiceData("sas", 50489, instanceName) + + salut = MySalut(dataReceiver, serviceData, SalutCallback { + Log.e(TAG, "Device does not support WiFi P2P") + }) + + list.layoutManager = LinearLayoutManager(this) + connectedDevicesAdapter = SimpleAdapter() + list.adapter = connectedDevicesAdapter + + startService.setOnClickListener { _ -> + updateUiState(UiState.HOST_MODE) + + salut.startNetworkService({ + connectedDevicesAdapter.add(it) + }, { + Log.d(TAG, "Network service started") + }, { + Log.e(TAG, "Can not start network service") + }) + } + + connectService.setOnClickListener { _ -> + updateUiState(UiState.CLIENT_MODE) + + connectedDevicesAdapter.setAction("Connect") { position -> + val salutDevice = connectedDevicesAdapter.getItem(position) + salut.registerWithHost(salutDevice, { + Log.d(TAG, "Successfully registered") + }, { + Log.e(TAG, "Error registering") + }) + } + + salut.discoverNetworkServices(SalutDeviceCallback { + connectedDevicesAdapter.add(it) + + + }, true) + } + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + MenuInflater(this).inflate(R.menu.menu_demo, menu) + + if (uiState == UiState.DEFAULT) { + menu?.removeItem(R.id.stop) + } + + return true + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + if (item?.itemId == R.id.stop) { + if (uiState == UiState.HOST_MODE) { + salut.stopNetworkService(false) + updateUiState(UiState.DEFAULT) + } else if (uiState == UiState.CLIENT_MODE) { + salut.stopServiceDiscovery(true) + updateUiState(UiState.DEFAULT) + } + return true + } + + return false + } + + private fun updateUiState(mode: UiState) { + this.uiState = mode + startService.visibility = if (mode == UiState.HOST_MODE) View.VISIBLE else View.GONE + connectService.visibility = if (mode == UiState.CLIENT_MODE) View.VISIBLE else View.GONE + + invalidateOptionsMenu() + } + + class SimpleAdapter : ArrayAdapter() { + + private var actionTitle: String? = null + private var action: ((index: Int) -> Unit)? = null + + fun setAction(title: String, action: ((index: Int) -> Unit)) { + actionTitle = title + this.action = action + + notifyDataSetChanged() + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleViewHolder { + val view = LayoutInflater.from(parent.context) + return SimpleViewHolder(view.inflate(R.layout.list_item_device, parent, false)) + } + + override fun getItemId(item: SalutDevice): Any? { + return item.macAddress + } + + override fun onBindViewHolder(viewHolder: SimpleViewHolder, position: Int) { + viewHolder.titleView.text = getItem(position)?.instanceName + + viewHolder.action.visibility = if (action != null) View.VISIBLE else View.GONE + if (action != null) { + viewHolder.action.text = actionTitle + viewHolder.action.setOnClickListener { _ -> + action?.let { it -> it(position) } + } + } + } + } + + class SimpleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val titleView: TextView = itemView.findViewById(R.id.title) + val action: Button = itemView.findViewById(R.id.action) + } +} diff --git a/demo/src/main/res/drawable-hdpi/ic_action_cancel.png b/demo/src/main/res/drawable-hdpi/ic_action_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..d26711ce903a699c43dbf3cfb81f6291fb1ffe80 GIT binary patch literal 397 zcmV;80doF{P)|39S~M)P`?KV?~FilS&~Z;5V1gCp!MzJUk4y8$uAoJq-rl-x<-Q$pay8Jyh| z3<)n`y%dNC7|xcffiz8XAPYO9M=Y2(K?Y<&W;7VGtX~VnsVFBvYGTR~oU6~=&Z)N&!S!esR+jsXLCHrTbL?ZF2s z2F&}md8Y)759rtnDy|pQ5-?8A;6@kafYgOdV^Zt8_Ua0wy4IntxvCsL)D37VM_83Z rzPe|S%7>!br?kqS4QhYK{M>p0bwd#%W$FZB00000NkvXXu0mjf4g#!$ literal 0 HcmV?d00001 diff --git a/demo/src/main/res/drawable-mdpi/ic_action_cancel.png b/demo/src/main/res/drawable-mdpi/ic_action_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..bc27fd1746b5170c9f0cfb86f2c87ad254fec173 GIT binary patch literal 294 zcmV+>0oneEP)*f + + + + + + + + + + diff --git a/demo/src/main/res/drawable-xhdpi/ic_action_cancel.png b/demo/src/main/res/drawable-xhdpi/ic_action_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..8f037dc79c4d1ff904246e50f8ff13fbceaa76c2 GIT binary patch literal 530 zcmV+t0`2{YP)vHnF&nk(%?IR zZR-U)XUucfgz>^gTH|CJ8wWXkfx#%nA~$n#I6aT_%nj0J-u7)6j-E&FutSRRo+Rw? zo_q}Wjvqk>$JVGF8(TbM>W^x+;y8hC)a(LXL*WEWY+}aYHvLiLI-vv4ojqV;5x|yJ zvO|Fj$i!hyTHOyi0J=MNF{)0ez&PJ9<;02q!X%^oHo7)pqge+9$AQw2O=^MKhK=Gt z$teSC3rd{d;x9JfTmALT^0cjCua>+%*BLPl8$~zD)2&ikCLJe6>s z%sEe|MHDp7my{xkdgqT-L>z31I9hc6a970fx`+!7F;`3?F8RbRsUfX|eKVF=h UXb5*>sQ>@~07*qoM6N<$f}uC@ZU6uP literal 0 HcmV?d00001 diff --git a/demo/src/main/res/drawable-xxhdpi/ic_action_cancel.png b/demo/src/main/res/drawable-xxhdpi/ic_action_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..c3ad30b4ec24c1b359da02a5c467cb9b87493087 GIT binary patch literal 851 zcmV-Z1FZasP)e&+i!GBQ(WxpaOt+Fhyhr{8m40a*vS1MGT4o5?e3G#XvWo1Ke(GzCtL zQ6Fdce*uUlUgu-CkRf(q`Roz4em1~ zZ{@gFx`}3#6IthYuajaJZ7c-m9@O4Mm@XR+Ce4FRHSBX-r_%-iaPII zr<&Tkg%Q_{r8(M$t=Zpftd_O$W^ysj9dk8xi37*pSY1qON_;}_1^2L#CjxMS@AceR6O zF_}|u$0=KaG)tfb-rB%^WOa~K_Ci}G#IgZn#8_S2`y}MTPRE9731IWzfGhKfi~X4e z-X54TsS)OEv1sP9b6>{DW$D<_FmtMYEv<9qNc~2N$!P71iJb}z(6iN90304bemr8} z>fMG(`#fDhfL0i@m5awAg2=(EHxnj>aODPld9iZ!1c+12Z;H`K)6M(2c`g*W)$reH zaI?yAhhMmZ0W*eN{X?z{+B5Crm-b=ekf~=LUTEa-0*}A&02PnmML&YaL!3MY%!A~- zijc}xggTRWnZ>{+@j8^*LXsEiOzaY`WE!xEmwGKiCA=1Hz$kuLz%pCHPg7V5KW;*y dP$(29`467a=F(>g$SnW>002ovPDHLkV1hI%ixdC= literal 0 HcmV?d00001 diff --git a/demo/src/main/res/drawable-xxxhdpi/ic_action_cancel.png b/demo/src/main/res/drawable-xxxhdpi/ic_action_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..a25191ae7a3048b7e3d5e8c0eb666461ae00dabc GIT binary patch literal 1161 zcmV;41a|w0P)&Z)oSgXoSeKpJUo1d3qRxk z@H>2mG%2CkY<_6B+XtOaXV~p_C-QlAe0+Q<*R}lnPCkF*3O`@tclb{D?ht>AdyvT$ zA-(v0uh;t_M2>~PEBSmDGXIvjaF1}WG473Lkm(E>jm8@x=(}7~A?#j*^kt2KXW&_Q zCZ4^`y?sx}7zF8vM*6bG2vRmcS+<6FOqx>ZQ|Wd=c%utsD87 zdEpjybldamOn$Zz+>L~w`8RbZKPyLW<^)&>b((P3nV3CTN4qf7wvGJxg}R%r6R=RJ zvYoH7P6&%N8}~vLSGX}&%*ovra8|)zvhCz&M#3zq0}mcUO~;y4;K_irC*{~eCz(HA z)8vFN{^;na)$8?sr6M2C!ZS5v65u3BJOP0VP4b0|Z}YW;^rDLdntd_1;qh$cz|d** zFrrq0kSdqfON_){xK?b28MHqg7-l;^cp?nt>P61)pP?gW3e8XyBJ*2%KrI ze8;gCMA{NzB|8O;FxJ%ntCY6+roGizcJlMUl?wSt?~a{Nr9qsv>=en6N@_fE>{Iz? zHkA%9vQrSSIna=wVM5>f+P&D5>=ek*P{aK&NgUu|;*g;oa8O z5s$C82Vdae0eppt1Mnq2entadW90#Sk((3nRffJs1z+ar34EQc!*vB;=u8j + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b1f108d --- /dev/null +++ b/demo/src/main/res/layout/activity_main.xml @@ -0,0 +1,68 @@ + + + +