1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-03 08:52:58 +01:00

Pebble: Report correct connection state to PebbleKit companion apps (not always connected)

This commit is contained in:
Andreas Shimokawa 2016-01-24 00:06:44 +01:00
parent e6f68f445a
commit 9af976657b
2 changed files with 39 additions and 1 deletions

View File

@ -1,5 +1,9 @@
###Changelog ###Changelog
####Next Version
* Pebble: Report connection state to PebbleKit companion apps via content provider. NOTE: Makes Gadgetbridge mutual exclusive with the original Pebble app.
* Ignore generic notification when from SMSSecure when SMS Notifications are on
####Version 0.7.2 ####Version 0.7.2
* Pebble: Allow replying to generic notifications that contain a wearable reply action (tested with Signal) * Pebble: Allow replying to generic notifications that contain a wearable reply action (tested with Signal)
* Pebble: Support seting up a common suffix for canned replies (defaults to " (canned reply)") * Pebble: Support seting up a common suffix for canned replies (defaults to " (canned reply)")

View File

@ -1,11 +1,21 @@
package nodomain.freeyourgadget.gadgetbridge.contentprovider; package nodomain.freeyourgadget.gadgetbridge.contentprovider;
import android.content.BroadcastReceiver;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.MatrixCursor; import android.database.MatrixCursor;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class PebbleContentProvider extends ContentProvider { public class PebbleContentProvider extends ContentProvider {
@ -24,8 +34,22 @@ public class PebbleContentProvider extends ContentProvider {
static final String URL = "content://" + PROVIDER_NAME + "/state"; static final String URL = "content://" + PROVIDER_NAME + "/state";
static final Uri CONTENT_URI = Uri.parse(URL); static final Uri CONTENT_URI = Uri.parse(URL);
private GBDevice mGBDevice = null;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
mGBDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
}
}
};
@Override @Override
public boolean onCreate() { public boolean onCreate() {
LocalBroadcastManager.getInstance(this.getContext()).registerReceiver(mReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED));
return true; return true;
} }
@ -33,7 +57,17 @@ public class PebbleContentProvider extends ContentProvider {
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (uri.equals(CONTENT_URI)) { if (uri.equals(CONTENT_URI)) {
MatrixCursor mc = new MatrixCursor(columnNames); MatrixCursor mc = new MatrixCursor(columnNames);
mc.addRow(new Object[]{1, 1, 0, 3, 8, 0, "Gadgetbridge"}); int connected = 0;
int appMessage = 0;
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getContext());
if (sharedPrefs.getBoolean("pebble_enable_pebblekit", false)) {
appMessage = 1;
}
if (mGBDevice != null && mGBDevice.getType() == DeviceType.PEBBLE && mGBDevice.isInitialized()) {
connected = 1;
}
mc.addRow(new Object[]{connected, appMessage, 0, 3, 8, 2, "Gadgetbridge"});
return mc; return mc;
} else { } else {
return null; return null;