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..c7ee934 100755
--- a/build.gradle
+++ b/build.gradle
@@ -1,41 +1,19 @@
-apply plugin: 'com.android.library'
+buildscript {
+ ext.kotlin_version = '1.2.71'
-android {
- compileSdkVersion 25
- buildToolsVersion "25.0.2"
- defaultConfig {
- minSdkVersion 14
- targetSdkVersion 25
- versionCode 3
- versionName '0.3'
- version 0.3
- }
- buildTypes {
- release {
- minifyEnabled false
- 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'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
}
-repositories {
- jcenter()
- mavenCentral()
-}
-
-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'
+allprojects {
+ repositories {
+ jcenter()
+ mavenCentral()
+ google()
+ }
}
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..3ff0496
--- /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.7'
+ implementation 'com.bluelinelabs:logansquare:1.3.7'
+
+ 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..b563b9e
--- /dev/null
+++ b/demo/src/main/java/com/peak/salut/demo/MainActivity.kt
@@ -0,0 +1,175 @@
+package com.peak.salut.demo
+
+import android.app.PendingIntent.getActivity
+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 android.widget.Toast
+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)
+ Toast.makeText(this.baseContext, it.readableName + " connected.", Toast.LENGTH_SHORT).show();
+ }, {
+ 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")
+ Toast.makeText(this.baseContext, "Successfully connected to " + this.salut.registeredHost.readableName, Toast.LENGTH_SHORT).show();
+ }, {
+ 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 0000000..d26711c
Binary files /dev/null and b/demo/src/main/res/drawable-hdpi/ic_action_cancel.png differ
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 0000000..bc27fd1
Binary files /dev/null and b/demo/src/main/res/drawable-mdpi/ic_action_cancel.png differ
diff --git a/demo/src/main/res/drawable-v24/ic_launcher_foreground.xml b/demo/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 0000000..1f6bb29
--- /dev/null
+++ b/demo/src/main/res/drawable-v24/ic_launcher_foreground.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
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 0000000..8f037dc
Binary files /dev/null and b/demo/src/main/res/drawable-xhdpi/ic_action_cancel.png differ
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 0000000..c3ad30b
Binary files /dev/null and b/demo/src/main/res/drawable-xxhdpi/ic_action_cancel.png differ
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 0000000..a25191a
Binary files /dev/null and b/demo/src/main/res/drawable-xxxhdpi/ic_action_cancel.png differ
diff --git a/demo/src/main/res/drawable/ic_launcher_background.xml b/demo/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..0d025f9
--- /dev/null
+++ b/demo/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/layout/list_item_device.xml b/demo/src/main/res/layout/list_item_device.xml
new file mode 100644
index 0000000..d0410be
--- /dev/null
+++ b/demo/src/main/res/layout/list_item_device.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/menu/menu_demo.xml b/demo/src/main/res/menu/menu_demo.xml
new file mode 100644
index 0000000..2526e46
--- /dev/null
+++ b/demo/src/main/res/menu/menu_demo.xml
@@ -0,0 +1,7 @@
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000..eca70cf
--- /dev/null
+++ b/demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 0000000..eca70cf
--- /dev/null
+++ b/demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/mipmap-hdpi/ic_launcher.png b/demo/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..898f3ed
Binary files /dev/null and b/demo/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 0000000..dffca36
Binary files /dev/null and b/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/demo/src/main/res/mipmap-mdpi/ic_launcher.png b/demo/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..64ba76f
Binary files /dev/null and b/demo/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 0000000..dae5e08
Binary files /dev/null and b/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/demo/src/main/res/mipmap-xhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..e5ed465
Binary files /dev/null and b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..14ed0af
Binary files /dev/null and b/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..b0907ca
Binary files /dev/null and b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..d8ae031
Binary files /dev/null and b/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..2c18de9
Binary files /dev/null and b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..beed3cd
Binary files /dev/null and b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml
new file mode 100644
index 0000000..69b2233
--- /dev/null
+++ b/demo/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #008577
+ #00574B
+ #D81B60
+
diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml
new file mode 100644
index 0000000..f0a4064
--- /dev/null
+++ b/demo/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ Salut Demo
+
diff --git a/demo/src/main/res/values/styles.xml b/demo/src/main/res/values/styles.xml
new file mode 100644
index 0000000..5885930
--- /dev/null
+++ b/demo/src/main/res/values/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
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/gradlew b/gradlew
old mode 100644
new mode 100755
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..4cb4686
--- /dev/null
+++ b/library/build.gradle
@@ -0,0 +1,34 @@
+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-compiler:1.3.7'
+ annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.7'
+}
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 96%
rename from src/main/AndroidManifest.xml
rename to library/src/main/AndroidManifest.xml
index 151c45b..c7d7842 100755
--- a/src/main/AndroidManifest.xml
+++ b/library/src/main/AndroidManifest.xml
@@ -7,6 +7,4 @@
-
-
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 99%
rename from src/main/java/com/peak/salut/Salut.java
rename to library/src/main/java/com/peak/salut/Salut.java
index db1eebd..7707a16 100755
--- a/src/main/java/com/peak/salut/Salut.java
+++ b/library/src/main/java/com/peak/salut/Salut.java
@@ -506,6 +506,7 @@ public void onFailure(int error) {
Log.e(TAG, "Failed to create " + thisDevice.serviceName + " : Error Code: " + error);
if (onFailure != null)
onFailure.call();
+ isRunningAsHost = false;
}
});
}
@@ -547,6 +548,8 @@ public void startNetworkService(@Nullable SalutDeviceCallback onDeviceRegistered
//In order to have a service that you create be seen, you must also actively look for other services. This is an Android bug.
//For more information, read here. https://code.google.com/p/android/issues/detail?id=37425
//We do not need to setup DNS responders.
+ isRunningAsHost = true;
+
registeredClients = new ArrayList<>();
this.onDeviceRegisteredWithHost = onDeviceRegisteredWithHost;
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..4a469f3
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,3 @@
+include ':library', ':demo'
+
+
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