From 8a1e9b4d5dc5854689a7815dfd9c63cc99e7838d Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 13 Nov 2014 23:01:33 +0200 Subject: [PATCH] Added preferences with setting for scan interval. --- app/proguard-rules.pro | 4 ++ app/src/main/AndroidManifest.xml | 8 ++++ .../res/drawable-hdpi/ic_action_settings.png | Bin 0 -> 807 bytes .../res/drawable-mdpi/ic_action_settings.png | Bin 0 -> 550 bytes .../res/drawable-xhdpi/ic_action_settings.png | Bin 0 -> 1124 bytes .../drawable-xxhdpi/ic_action_settings.png | Bin 0 -> 1661 bytes app/src/main/res/menu/main.xml | 7 ++++ app/src/main/res/values/strings.xml | 13 ++++++- app/src/main/res/xml/settings.xml | 11 ++++++ .../activities/SettingsActivity.scala | 36 ++++++++++++++++++ .../ensichat/bluetooth/ChatService.scala | 7 ++-- .../ensichat/fragments/ContactsFragment.scala | 5 ++- .../ensichat/fragments/SettingsFragment.scala | 16 ++++++++ 13 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_action_settings.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_settings.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_settings.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_settings.png create mode 100644 app/src/main/res/xml/settings.xml create mode 100644 app/src/main/scala/com/nutomic/ensichat/activities/SettingsActivity.scala create mode 100644 app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala 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 0000000000000000000000000000000000000000..54eecded35495a5d6e6bf2ea5f68003aec682bd0 GIT binary patch literal 807 zcmV+?1K9kDP)(RCwC#S<7+TFc77D4hvukUH5EY;Tl!fNOv$F$$;0UCBz|LUcA)v)R>>tju zM2Qk5O7s9NreJ!z-Ik7}^J1~MerW(Cd`Z)rV|h;i4l&Prnm_?d&)SdJhs_P(=a&XR z=9AO3@@&aH{_(j0NU-lTZ3DJ8*gL-y)4>f*YZ~t~dKyYc6?|`OQ3rErS?lPx9n;(r z+WTj|M+GntT@2|Ec>uTz6I=r+AYhHZGwiuq0B#6`iVfh+ag!f6O5+3#t(cG*6IKH| zV!iS3x)6Xmnh%ih^?>lN5b!Sm6qY>&)>_>92D6O{oEb+0#O&x0$_TIRw;JhxCupO6 zL<>)W(dCbvrX+da zHAFmiQ%0c!1Zaft8&|=GaM=nFMvLpQ!jDR1xY1Ykskda^y|3EDniOmWU-;k~D*Wh7 zOpK50ZzXQ>91^>65!}2AVQ$?RnMMKNPGu0@?kEP)q{gd6P_X zX7OEux~{vX%Li$IrIs}FeZL;N*M%eS8Atv`8jP zU!`JLwub=lbF6Q{5P;YWk$9tIfTATmy8}=>!1kA5yq6yTQ~)Rh&^Ox&u$}@0ND>Os zOEU{I_>`h5k?8%mAS(9f;e6oJwJ#C9lRh4uhy?L?s;8WMg(O;v9Ce7<_aJHGq&RX4vc53+DiCGD1UqCU$Uhby1%a>C3-s5A5l5L of+qpc$SHRPFv%ommtO$}002SWC@^W*^#A|>07*qoM6N<$g24Xmxc~qF literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..425a8bc8dce5daa8c5f4f78b0b7052805a66e950 GIT binary patch literal 1124 zcmV-q1e^PbP)a#gEG{9ZUYOS($BP^+nHK00&W5;K-y8C zuT21H%J9n(0HM+jiTZRJkoDB}`U#-ZA6pnd5%(B#-ENRJ$?j}M?Le-p&`@GIpgkYtNzZ4Fa~CxJF&F^|XkKhLM{Ug~MB^Ul?>mE$D?n5Za#ju= zVM%M`p$OO+!dVflx?2dYx(+&sYR|@VVKL@H{U3S{g&~ZM@M}IvkE@b^s0B2Q=lKO~ zFk!@dBN7h1Y5*;AP#7v1dp<#2lS$GJY#Say;-YIUxN#JIY$1F}o7iBplLo;GG*j}! zbFBC}pl_2Fqsgg9qOZe8w5R9D|#3TrGWb8bq-x{(+(HMFQ-S=JoN5js904$ZVoIDUEOd>z#}ac*x-4teDmVdx@I&c&hFtzH_l4-ucK%Eg z?VS)Q4yCyl!3Yq9SE=hxYJ^Q{TA{Wv;Cd|nwystcV%Pb0Wd&5yP3K)QE65agev6dzJ;?8dUq zSKq6u2jB!<+~FaF@SzJLxkKO6XDNudXhESVaj8P-^OqyQP%H516A9=Fw}A;b!4s&W qJ6(Jb5fKp)5fKp)5zzyF3orown8LjDzzdE50000vCP)|sA)KjZ*#03Tp{faCz4eV)Z@O%#u9HB!sSNq<#TswhjA`fK%% z)FMJK7z_r3!C){L3$HDGAt^ z#-WWzCUdvt^T*y10E2(5eEkAKkP~{hS5rPe2eM3%eLRc*_j^?P2r}OYnE}^sQS z2A+hE)#f(H$?id03q*4EQa<-wLq-Z?89I*VsqB9pJOP$Fmw%ZEaGHhI=Lm#p@(;?y zofIKJ#FRiO7SxX12LW3LCn`Rc zKx3DLNt9d>-?YB(9Y~e^96}}FU}pAZOt z0xO7G_$pN0!aD>wRGZLpsQL(M1z2kTpYRSQb>C3}dNw0qjF6~ zV@eTDEhcm4LrC5T0F7EU?9T|pR=_1T8S4|;qNAiTw(9=R+LxTXo(b1!u=ZVB@^kXA z_kJ`H0IQ|?-jz=ob$uwW6B1hr%Lf5b!x&BD44VMRaI2=}Qlh9C@p5Kt2ZVFgR>_)Ipw#YYsqB>=Kr9Ydt8O+5@J zMXuD?6iWBW1U+;*>>O-vEvCMRLgvF5+CyXE9p&>o|yDqK8)&CV;epQ@~U zEbs^XGcZ3(BmqK;;1(1+wp0Yz7UZ7m?xFn;fj<x8e zJ{RqGz1kq_lXhCPlz`2*b@pLj(9neD8qplVQR-o43Snm3Wjb{WGlMX<(Ara6`1neF zS{L#qy}vZLhUlSYmz$m$LyYel;_iIZ23_NtY5`6*6K{8YCkE}5&mF)7m@a$A;{9FU zMsouFs^?KjTb~GswJ zeK`+p(rU($g7ZK5s0rlvvz3l_j=eh1P!lm9CL@GCJ}m)9$M$)M zW~Vm + + + \ 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) + } + +}