From b9c13324427feb46bf5db353c59fb92c75ce846c Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 22 Jan 2016 20:21:18 +0100 Subject: [PATCH 1/3] Testing content provdider --- app/src/main/AndroidManifest.xml | 1 + .../devices/pebble/PebbleContentProvider.java | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleContentProvider.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 73064a6d..ff88522a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -245,6 +245,7 @@ android:name=".activities.AlarmDetails" android:label="@string/title_activity_alarm_details" android:parentActivityName=".activities.ConfigureAlarms"/> + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleContentProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleContentProvider.java new file mode 100644 index 00000000..f00f0da4 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleContentProvider.java @@ -0,0 +1,63 @@ +package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.net.Uri; +import android.support.annotation.NonNull; + +public class PebbleContentProvider extends ContentProvider { + + public static final int COLUMN_CONNECTED = 0; + public static final int COLUMN_APPMSG_SUPPORT = 1; + public static final int COLUMN_DATALOGGING_SUPPORT = 2; + public static final int COLUMN_VERSION_MAJOR = 3; + public static final int COLUMN_VERSION_MINOR = 4; + public static final int COLUMN_VERSION_POINT = 5; + public static final int COLUMN_VERSION_TAG = 6; + + // this is only needed for the MatrixCursor constructor + public static final String[] columnNames = new String[]{"0", "1", "2", "3", "4", "5", "6"}; + + static final String PROVIDER_NAME = "com.getpebble.android.provider"; + static final String URL = "content://" + PROVIDER_NAME + "/state"; + static final Uri CONTENT_URI = Uri.parse(URL); + + @Override + public boolean onCreate() { + return true; + } + + @Override + public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { + if (uri.equals(CONTENT_URI)) { + MatrixCursor mc = new MatrixCursor(columnNames); + mc.addRow(new Object[]{1, 1, 0, 3, 8, 0, "Gadgetbridge"}); + return mc; + } else { + return null; + } + } + + @Override + public String getType(@NonNull Uri uri) { + return null; + } + + @Override + public Uri insert(@NonNull Uri uri, ContentValues values) { + return null; + } + + @Override + public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { + return 0; + } + + @Override + public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) { + return 0; + } +} \ No newline at end of file From a72373c17c95c2c898194c0d126b11f688bb0815 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 22 Jan 2016 20:38:44 +0100 Subject: [PATCH 2/3] move PebbleContentProvider.java --- app/src/main/AndroidManifest.xml | 2 +- .../pebble => contentprovider}/PebbleContentProvider.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) rename app/src/main/java/nodomain/freeyourgadget/gadgetbridge/{service/devices/pebble => contentprovider}/PebbleContentProvider.java (94%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ff88522a..b238d986 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -245,7 +245,7 @@ android:name=".activities.AlarmDetails" android:label="@string/title_activity_alarm_details" android:parentActivityName=".activities.ConfigureAlarms"/> - + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleContentProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/contentprovider/PebbleContentProvider.java similarity index 94% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleContentProvider.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/contentprovider/PebbleContentProvider.java index f00f0da4..a6bf3792 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleContentProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/contentprovider/PebbleContentProvider.java @@ -1,8 +1,7 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble; +package nodomain.freeyourgadget.gadgetbridge.contentprovider; import android.content.ContentProvider; import android.content.ContentValues; -import android.content.UriMatcher; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; From 3d3643ece3531f9b551843767ac549ec929a9b56 Mon Sep 17 00:00:00 2001 From: danielegobbetti Date: Fri, 22 Jan 2016 21:04:01 +0100 Subject: [PATCH 3/3] Add weather to PebStyle as well. --- .../pebble/AppMessageHandlerPebStyle.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java index c29460da..37468e75 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java @@ -12,6 +12,8 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleColor; +import nodomain.freeyourgadget.gadgetbridge.model.Weather; +import ru.gelin.android.weather.notification.ParcelableWeather2; public class AppMessageHandlerPebStyle extends AppMessageHandler { public static final int KEY_AMPM_TEXT = 21; @@ -57,7 +59,7 @@ public class AppMessageHandlerPebStyle extends AppMessageHandler { pairs.add(new Pair<>(KEY_SECOND_HAND, (Object) 0)); //1 enabled pairs.add(new Pair<>(KEY_BLUETOOTH_ALERT, (Object) 0)); //1 silent, 2 weak, up to 5 pairs.add(new Pair<>(KEY_TEMPERATURE_FORMAT, (Object) 1)); //0 fahrenheit - pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 2)); //0 uto, 1 manual + //pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 2)); //0 uto, 1 manual pairs.add(new Pair<>(KEY_SIDEBAR_LOCATION, (Object) 1)); //0 right pairs.add(new Pair<>(KEY_COLOR_SELECTION, (Object) 1)); //1 custom pairs.add(new Pair<>(KEY_MAIN_COLOR, (Object) PebbleColor.Black)); @@ -65,7 +67,7 @@ public class AppMessageHandlerPebStyle extends AppMessageHandler { pairs.add(new Pair<>(KEY_SIDEBAR_BG_COLOR, (Object) PebbleColor.MediumSpringGreen)); //DIGITAL settings - /* + /* pairs.add(new Pair<>(KEY_MAIN_CLOCK, (Object) 1)); //0 analog pairs.add(new Pair<>(KEY_SECONDARY_INFO_TYPE, (Object) 3)); //1 time, 2 location */ @@ -75,12 +77,13 @@ public class AppMessageHandlerPebStyle extends AppMessageHandler { //WEATHER - /* - //comment the same key in the general section above! - pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 0)); //0 auto, 1 manual - pairs.add(new Pair<>(KEY_WEATHER_CODE, (Object) 3)); - pairs.add(new Pair<>(KEY_WEATHER_TEMP, (Object) 10)); - */ + ParcelableWeather2 weather = Weather.getInstance().getWeather2(); + if (weather != null) { + //comment the same key in the general section above! + pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 0)); //0 auto, 1 manual + pairs.add(new Pair<>(KEY_WEATHER_CODE, (Object) Weather.mapToYahooCondition(weather.currentConditionCode))); + pairs.add(new Pair<>(KEY_WEATHER_TEMP, (Object) (weather.currentTemp - 273))); + } byte[] testMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);