Added preferences with setting for scan interval.

This commit is contained in:
Felix Ableitner 2014-11-13 23:01:33 +02:00
parent 7af368ce31
commit 8a1e9b4d5d
13 changed files with 101 additions and 6 deletions

View file

@ -19,6 +19,10 @@
-dontwarn scala.** -dontwarn scala.**
-keep class !scala*.** { *; } -keep class !scala*.** { *; }
-ignorewarnings -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). # Suppress warnings caused by msgpack (code works fine anyway).
-dontwarn -dontwarn

View file

@ -12,6 +12,7 @@
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme" > android:theme="@style/AppTheme" >
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:label="@string/app_name" > android:label="@string/app_name" >
@ -21,7 +22,14 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".activities.SettingsActivity"
android:label="@string/settings"
android:parentActivityName=".activities.MainActivity" />
<service android:name=".bluetooth.ChatService" /> <service android:name=".bluetooth.ChatService" />
</application> </application>
</manifest> </manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 807 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -2,7 +2,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/settings"
android:icon="@drawable/ic_action_settings"
android:title="@string/settings"
android:showAsAction="ifRoom" />
<item <item
android:id="@+id/exit" android:id="@+id/exit"
android:title="Exit" /> android:title="Exit" />
</menu> </menu>

View file

@ -5,8 +5,8 @@
<string name="app_name">EnsiChat</string> <string name="app_name">EnsiChat</string>
<!-- MainActivity -->
<!-- MainActivity -->
<!-- Toast shown if user denies request to enable bluetooth --> <!-- Toast shown if user denies request to enable bluetooth -->
<string name="bluetooth_required">Bluetooth is required for this app.</string> <string name="bluetooth_required">Bluetooth is required for this app.</string>
@ -14,10 +14,19 @@
<!-- Menu item to close app and stop service --> <!-- Menu item to close app and stop service -->
<string name="exit">Exit</string> <string name="exit">Exit</string>
<!-- ContactsFragment -->
<!-- ContactsFragment -->
<!-- Empty text for contacts list --> <!-- Empty text for contacts list -->
<string name="no_contacts_found">No contacts found :(</string> <string name="no_contacts_found">No contacts found :(</string>
<!-- SettingsActivity -->
<!-- Activity title -->
<string name="settings">Settings</string>
<!-- Preference title -->
<string name="scan_interval_seconds">Scan Interval (seconds)</string>
</resources> </resources>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:title="@string/scan_interval_seconds"
android:key="scan_interval_seconds"
android:defaultValue="5"
android:inputType="number"
android:numeric="integer" />
</PreferenceScreen>

View file

@ -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)
}
}

View file

@ -6,6 +6,7 @@ import android.app.Service
import android.bluetooth.{BluetoothAdapter, BluetoothDevice, BluetoothSocket} import android.bluetooth.{BluetoothAdapter, BluetoothDevice, BluetoothSocket}
import android.content.{BroadcastReceiver, Context, Intent, IntentFilter} import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import android.os.Handler import android.os.Handler
import android.preference.PreferenceManager
import android.util.Log import android.util.Log
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.bluetooth.ChatService.{OnConnectionChangedListener, OnMessageReceivedListener} import com.nutomic.ensichat.bluetooth.ChatService.{OnConnectionChangedListener, OnMessageReceivedListener}
@ -41,8 +42,6 @@ class ChatService extends Service {
private val Tag = "ChatService" private val Tag = "ChatService"
private val ScanInterval = 5000
private val Binder = new ChatServiceBinder(this) private val Binder = new ChatServiceBinder(this)
private var bluetoothAdapter: BluetoothAdapter = _ private var bluetoothAdapter: BluetoothAdapter = _
@ -124,9 +123,11 @@ class ChatService extends Service {
bluetoothAdapter.startDiscovery() bluetoothAdapter.startDiscovery()
} }
val scanInterval = PreferenceManager.getDefaultSharedPreferences(this)
.getString("scan_interval_seconds", "5").toInt * 1000
MainHandler.postDelayed(new Runnable { MainHandler.postDelayed(new Runnable {
override def run(): Unit = discover() override def run(): Unit = discover()
}, ScanInterval) }, scanInterval)
} }
/** /**

View file

@ -6,7 +6,7 @@ import android.os.{Bundle, IBinder}
import android.view._ import android.view._
import android.widget.{ArrayAdapter, ListView} import android.widget.{ArrayAdapter, ListView}
import com.nutomic.ensichat.R 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.bluetooth.{ChatService, ChatServiceBinder, Device}
import com.nutomic.ensichat.util.{MessagesAdapter, DevicesAdapter} import com.nutomic.ensichat.util.{MessagesAdapter, DevicesAdapter}
@ -44,6 +44,9 @@ class ContactsFragment extends ListFragment with ChatService.OnConnectionChanged
override def onOptionsItemSelected(item: MenuItem): Boolean = { override def onOptionsItemSelected(item: MenuItem): Boolean = {
item.getItemId match { item.getItemId match {
case R.id.settings =>
startActivity(new Intent(getActivity, classOf[SettingsActivity]))
true
case R.id.exit => case R.id.exit =>
getActivity.stopService(new Intent(getActivity, classOf[ChatService])) getActivity.stopService(new Intent(getActivity, classOf[ChatService]))
getActivity.finish() getActivity.finish()

View file

@ -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)
}
}