* Add option to start Gadgetbridge and connect automatically when bluetooth is turned on.

This closes #9
master
Andreas Shimokawa 2015-03-17 21:41:58 +01:00
parent 0f3cd9b7c7
commit c56194c0e5
9 changed files with 57 additions and 8 deletions

View File

@ -1,5 +1,8 @@
###Changelog
####Version 0.1.2
* Added option to start Gadgetbridge and connect automatically when bluetooth is turned on
####Version 0.1.1
* Fixed various bugs regarding K-9 Mail notifications.
* "Generic notification support" in Setting now opens Androids "Notifcaion access" dialog.

View File

@ -27,8 +27,6 @@ How to use:
Known Issues:
* No reconnect, if connection is lost, you have to press "connect" again
* Notifications are not properly queued, if two arrive at about the same time,
one of them might get lost (TODO: confirm)
* Android 4.4+ only, we can only change this by not handling generic
notifications or by using AccessibiltyService. Don't know if it is worth the
hassle.

View File

@ -23,7 +23,6 @@
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@ -60,7 +59,6 @@
android:enabled="false">
<intent-filter>
<data android:scheme="email" />
<action android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" />
</intent-filter>
</receiver>
@ -71,7 +69,11 @@
<action android:name="com.andrew.apollo.metachanged" />
</intent-filter>
</receiver>
<receiver android:name=".BluetoothStateChangeReceiver">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>
<receiver android:name=".StopServiceReceiver" />
<receiver android:name=".GBMusicControlReceiver">
<intent-filter>

View File

@ -138,6 +138,10 @@ public class BluetoothCommunicationService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent.getAction();
if (action == null) {
Log.i(TAG, "no action");
return START_NOT_STICKY;
}
if (!mStarted && !action.equals(ACTION_START)) {
// using the service before issuing ACTION_START
@ -172,8 +176,7 @@ public class BluetoothCommunicationService extends Service {
}
if (btDeviceAddress == null) {
Toast.makeText(this, "No supported device paired", Toast.LENGTH_SHORT).show();
}
else if (mBtSocket == null || !mBtSocket.isConnected()) {
} else if (mBtSocket == null || !mBtSocket.isConnected()) {
// currently only one thread allowed
if (mBtSocketIoThread != null) {
mBtSocketIoThread.quit();

View File

@ -0,0 +1,31 @@
package nodomain.freeyourgadget.gadgetbridge;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class BluetoothStateChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!sharedPrefs.getBoolean("general_autoconnectonbluetooth", false)) {
return;
}
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_START);
context.startService(startIntent);
Intent connectIntent = new Intent(context, BluetoothCommunicationService.class);
connectIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
context.startService(connectIntent);
}
}
}
}

View File

@ -49,7 +49,6 @@ public class ControlCenter extends Activity {
});
/*
* Ask for permission to intercept notifications on first run.
* TODO: allow re-request in preferences
*/
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPrefs.getBoolean("firstrun", true)) {

View File

@ -2,6 +2,7 @@
<!-- Strings related to Settings -->
<string name="pref_header_general">General Settings</string>
<string name="pref_title_general_autoconnectonbluetooth">Connect to device when Bluetooth turned on</string>
<!-- Strings related to Notifications -->
<string name="pref_header_notifications">Notifications</string>

View File

@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -1,3 +1,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:defaultValue="false"
android:key="general_autoconnectonbluetooth"
android:title="@string/pref_title_general_autoconnectonbluetooth" />
</PreferenceScreen>