From d9a2d85f6d5789dfc741d2685e024fd0e60190e7 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 29 Mar 2015 17:12:06 +0200 Subject: [PATCH] Fix for DST (summer time), option to sync time on connect (enabled by default) --- CHANGELOG.md | 6 ++++++ .../gadgetbridge/BluetoothCommunicationService.java | 8 ++++++++ .../gadgetbridge/SettingsActivity.java | 6 ++++++ .../gadgetbridge/protocol/PebbleProtocol.java | 10 +++++++--- app/src/main/res/values/strings.xml | 5 +++++ app/src/main/res/xml/pref_datetime.xml | 6 ++++++ app/src/main/res/xml/pref_general.xml | 1 - app/src/main/res/xml/pref_headers.xml | 12 ------------ 8 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 app/src/main/res/xml/pref_datetime.xml delete mode 100644 app/src/main/res/xml/pref_headers.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aa778559..bdf0195cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ###Changelog +####Version 0.1.5 +* Fix for DST (summer time) +* Option to sync time on connect (enabled by default) +* Opening .pbw files with Gadgetbridge prints some package information + (Tbis was not meant to be released yet, but the DST fix made a new release neccessary) + ####Version 0.1.4 * New AppManager shows installed Apps/Watchfaces (removal possible via context menu) * Allow back navigation in ActionBar (Debug and AppMananger Activities) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java index 096f1aac2..184d569c5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java @@ -396,6 +396,7 @@ public class BluetoothCommunicationService extends Service { gbdevice.setState(GBDevice.State.CONNECTED); sendDeviceUpdateIntent(); updateNotification("connected to " + btDevice.getName()); + return true; } @@ -441,6 +442,13 @@ public class BluetoothCommunicationService extends Service { Log.i(TAG, "Pebble asked for Phone/App Version - repLYING!"); write(PebbleProtocol.encodePhoneVersion(PebbleProtocol.PHONEVERSION_REMOTE_OS_ANDROID)); write(PebbleProtocol.encodeFirmwareVersionReq()); + + // this does not really belong here, but since the pebble only asks for our version once it should do the job + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(BluetoothCommunicationService.this); + if (sharedPrefs.getBoolean("datetime_synconconnect", true)) { + Log.i(TAG, "syncing time"); + write(PebbleProtocol.encodeSetTime(-1)); + } } else if (endpoint != PebbleProtocol.ENDPOINT_DATALOG) { GBDeviceCommand deviceCmd = PebbleProtocol.decodeResponse(buffer); if (deviceCmd == null) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java index ad09b5844..f6583101f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/SettingsActivity.java @@ -22,6 +22,12 @@ public class SettingsActivity extends PreferenceActivity { // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); + // Add 'date' preferences, and a corresponding header. + PreferenceCategory fakeHeaderDateTime = new PreferenceCategory(this); + fakeHeaderDateTime.setTitle(R.string.pref_header_datetime); + getPreferenceScreen().addPreference(fakeHeaderDateTime); + addPreferencesFromResource(R.xml.pref_datetime); + // Add 'notifications' preferences, and a corresponding header. PreferenceCategory fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_notifications); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/protocol/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/protocol/PebbleProtocol.java index 5f4efe0df..7962b9382 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/protocol/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/protocol/PebbleProtocol.java @@ -5,6 +5,7 @@ import android.util.Log; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.SimpleTimeZone; +import java.util.TimeZone; import nodomain.freeyourgadget.gadgetbridge.GBCommand; import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp; @@ -149,7 +150,8 @@ public class PebbleProtocol { public static byte[] encodeSMS(String from, String body) { Long ts = System.currentTimeMillis() / 1000; - ts += SimpleTimeZone.getDefault().getOffset(ts) / 1000; + TimeZone tz = SimpleTimeZone.getDefault(); + ts += (tz.getOffset(ts) + tz.getDSTSavings()) / 1000; String tsstring = ts.toString(); // SIC String[] parts = {from, body, tsstring}; @@ -158,7 +160,8 @@ public class PebbleProtocol { public static byte[] encodeEmail(String from, String subject, String body) { Long ts = System.currentTimeMillis() / 1000; - ts += SimpleTimeZone.getDefault().getOffset(ts) / 1000; + TimeZone tz = SimpleTimeZone.getDefault(); + ts += (tz.getOffset(ts) + tz.getDSTSavings()) / 1000; String tsstring = ts.toString(); // SIC String[] parts = {from, body, tsstring, subject}; @@ -168,7 +171,8 @@ public class PebbleProtocol { public static byte[] encodeSetTime(long ts) { if (ts == -1) { ts = System.currentTimeMillis() / 1000; - ts += SimpleTimeZone.getDefault().getOffset(ts) / 1000; + TimeZone tz = SimpleTimeZone.getDefault(); + ts += (tz.getOffset(ts) + tz.getDSTSavings()) / 1000; } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SETTIME); buf.order(ByteOrder.BIG_ENDIAN); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd3c92e3b..50a3d326c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,8 +19,13 @@ Settings + General Settings Connect to device when Bluetooth turned on + + Date and Time + Sync time when connecting + Notifications Notification for SMS Notification for K9-Mail diff --git a/app/src/main/res/xml/pref_datetime.xml b/app/src/main/res/xml/pref_datetime.xml new file mode 100644 index 000000000..1a23aedf7 --- /dev/null +++ b/app/src/main/res/xml/pref_datetime.xml @@ -0,0 +1,6 @@ + + + diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 6a1453075..ea81e2102 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -3,5 +3,4 @@ android:defaultValue="false" android:key="general_autoconnectonbluetooth" android:title="@string/pref_title_general_autoconnectonbluetooth" /> - diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml deleted file mode 100644 index f91f7682b..000000000 --- a/app/src/main/res/xml/pref_headers.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - -
- -
- -