diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
index 1c42e53..3d4b47b 100644
--- a/app/proguard-rules.pro
+++ b/app/proguard-rules.pro
@@ -19,6 +19,10 @@
-dontwarn scala.**
-keep class !scala*.** { *; }
-ignorewarnings
+# Avoid crash when invoking String.toInt (see https://issues.scala-lang.org/browse/SI-5397).
+-keep class scala.collection.SeqLike {
+ public protected *;
+}
# Suppress warnings caused by msgpack (code works fine anyway).
-dontwarn
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 98bc7f3..e039d72 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -12,6 +12,7 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
+
@@ -21,7 +22,14 @@
+
+
+
+
diff --git a/app/src/main/res/drawable-hdpi/ic_action_settings.png b/app/src/main/res/drawable-hdpi/ic_action_settings.png
new file mode 100644
index 0000000..54eecde
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_settings.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_settings.png b/app/src/main/res/drawable-mdpi/ic_action_settings.png
new file mode 100644
index 0000000..25c36db
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_settings.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_settings.png b/app/src/main/res/drawable-xhdpi/ic_action_settings.png
new file mode 100644
index 0000000..425a8bc
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_settings.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_settings.png b/app/src/main/res/drawable-xxhdpi/ic_action_settings.png
new file mode 100644
index 0000000..fe5fec4
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_settings.png differ
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index 25f490e..6040564 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -2,7 +2,14 @@
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1d5a8e9..482d4cf 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -5,8 +5,8 @@
EnsiChat
-
+
Bluetooth is required for this app.
@@ -14,10 +14,19 @@
Exit
-
+
No contacts found :(
+
+
+
+
+ Settings
+
+
+ Scan Interval (seconds)
+
diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml
new file mode 100644
index 0000000..e9b9486
--- /dev/null
+++ b/app/src/main/res/xml/settings.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/scala/com/nutomic/ensichat/activities/SettingsActivity.scala b/app/src/main/scala/com/nutomic/ensichat/activities/SettingsActivity.scala
new file mode 100644
index 0000000..31cb3b3
--- /dev/null
+++ b/app/src/main/scala/com/nutomic/ensichat/activities/SettingsActivity.scala
@@ -0,0 +1,36 @@
+package com.nutomic.ensichat.activities
+
+import android.app.Fragment
+import android.os.Bundle
+import com.nutomic.ensichat.fragments.SettingsFragment
+
+/**
+ * Holder for [[SettingsFragment]].
+ */
+class SettingsActivity extends EnsiChatActivity {
+
+ private var fragment: Fragment = _
+
+ override def onCreate(savedInstanceState: Bundle): Unit = {
+ super.onCreate(savedInstanceState)
+ getActionBar.setDisplayHomeAsUpEnabled(true)
+
+ val fm = getFragmentManager
+ fragment =
+ if (savedInstanceState != null) {
+ fm.getFragment(savedInstanceState, "settings_fragment")
+ } else {
+ new SettingsFragment()
+ }
+ fm.beginTransaction()
+ .replace(android.R.id.content, fragment)
+ .commit()
+ }
+
+ override def onSaveInstanceState(outState: Bundle): Unit = {
+ super.onSaveInstanceState(outState)
+
+ getFragmentManager.putFragment(outState, "settings_fragment", fragment)
+ }
+
+}
diff --git a/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala b/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala
index 0adfcdf..8cace06 100644
--- a/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala
+++ b/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala
@@ -6,6 +6,7 @@ import android.app.Service
import android.bluetooth.{BluetoothAdapter, BluetoothDevice, BluetoothSocket}
import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import android.os.Handler
+import android.preference.PreferenceManager
import android.util.Log
import com.nutomic.ensichat.R
import com.nutomic.ensichat.bluetooth.ChatService.{OnConnectionChangedListener, OnMessageReceivedListener}
@@ -41,8 +42,6 @@ class ChatService extends Service {
private val Tag = "ChatService"
- private val ScanInterval = 5000
-
private val Binder = new ChatServiceBinder(this)
private var bluetoothAdapter: BluetoothAdapter = _
@@ -124,9 +123,11 @@ class ChatService extends Service {
bluetoothAdapter.startDiscovery()
}
+ val scanInterval = PreferenceManager.getDefaultSharedPreferences(this)
+ .getString("scan_interval_seconds", "5").toInt * 1000
MainHandler.postDelayed(new Runnable {
override def run(): Unit = discover()
- }, ScanInterval)
+ }, scanInterval)
}
/**
diff --git a/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala b/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala
index 80f2f0a..c437ec8 100644
--- a/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala
+++ b/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala
@@ -6,7 +6,7 @@ import android.os.{Bundle, IBinder}
import android.view._
import android.widget.{ArrayAdapter, ListView}
import com.nutomic.ensichat.R
-import com.nutomic.ensichat.activities.{EnsiChatActivity, MainActivity}
+import com.nutomic.ensichat.activities.{SettingsActivity, EnsiChatActivity, MainActivity}
import com.nutomic.ensichat.bluetooth.{ChatService, ChatServiceBinder, Device}
import com.nutomic.ensichat.util.{MessagesAdapter, DevicesAdapter}
@@ -44,6 +44,9 @@ class ContactsFragment extends ListFragment with ChatService.OnConnectionChanged
override def onOptionsItemSelected(item: MenuItem): Boolean = {
item.getItemId match {
+ case R.id.settings =>
+ startActivity(new Intent(getActivity, classOf[SettingsActivity]))
+ true
case R.id.exit =>
getActivity.stopService(new Intent(getActivity, classOf[ChatService]))
getActivity.finish()
diff --git a/app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala b/app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala
new file mode 100644
index 0000000..cbb67e3
--- /dev/null
+++ b/app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala
@@ -0,0 +1,16 @@
+package com.nutomic.ensichat.fragments
+
+import android.os.Bundle
+import android.preference.PreferenceFragment
+
+import com.nutomic.ensichat.R
+
+class SettingsFragment extends PreferenceFragment {
+
+ override def onCreate(savedInstanceState: Bundle): Unit = {
+ super.onCreate(savedInstanceState)
+
+ addPreferencesFromResource(R.xml.settings)
+ }
+
+}