Added preferences with setting for scan interval.
This commit is contained in:
parent
7af368ce31
commit
8a1e9b4d5d
13 changed files with 101 additions and 6 deletions
4
app/proguard-rules.pro
vendored
4
app/proguard-rules.pro
vendored
|
@ -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
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
|
@ -21,7 +22,14 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/settings"
|
||||
android:parentActivityName=".activities.MainActivity" />
|
||||
|
||||
<service android:name=".bluetooth.ChatService" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
BIN
app/src/main/res/drawable-hdpi/ic_action_settings.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 807 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_settings.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 550 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_settings.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_settings.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
|
@ -2,7 +2,14 @@
|
|||
|
||||
<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
|
||||
android:id="@+id/exit"
|
||||
android:title="Exit" />
|
||||
|
||||
</menu>
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
<string name="app_name">EnsiChat</string>
|
||||
|
||||
<!-- MainActivity -->
|
||||
|
||||
<!-- MainActivity -->
|
||||
|
||||
<!-- Toast shown if user denies request to enable bluetooth -->
|
||||
<string name="bluetooth_required">Bluetooth is required for this app.</string>
|
||||
|
@ -14,10 +14,19 @@
|
|||
<!-- Menu item to close app and stop service -->
|
||||
<string name="exit">Exit</string>
|
||||
|
||||
<!-- ContactsFragment -->
|
||||
|
||||
<!-- ContactsFragment -->
|
||||
|
||||
<!-- Empty text for contacts list -->
|
||||
<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>
|
||||
|
|
11
app/src/main/res/xml/settings.xml
Normal file
11
app/src/main/res/xml/settings.xml
Normal 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>
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue