diff --git a/app/build.gradle b/app/build.gradle
index 1a9e76995..ed4cfb9d8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -67,6 +67,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "androidx.appcompat:appcompat:1.0.2"
+ implementation "androidx.preference:preference:1.0.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9597b4a21..6bfd292b9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -406,7 +406,10 @@
+ android:parentActivityName=".activities.ControlCenterv2" />
+
adapterView, View view, int position, long id) {
+ GBDeviceCandidate deviceCandidate = deviceCandidates.get(position);
+ if (deviceCandidate == null) {
+ LOG.error("Device candidate clicked, but item not found");
+ return true;
+ }
+
+ DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(deviceCandidate);
+ GBDevice device = DeviceHelper.getInstance().toSupportedDevice(deviceCandidate);
+ if (!coordinator.supportsDeviceSpecificSettings(device)) {
+ return true;
+ }
+
+ Intent startIntent;
+ startIntent = new Intent(this, DeviceSettingsActivity.class);
+ startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
+ startActivity(startIntent);
+ return true;
+ }
+
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
GBDeviceCandidate deviceCandidate = deviceCandidates.get(position);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsActivity.java
new file mode 100644
index 000000000..9daa84068
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsActivity.java
@@ -0,0 +1,64 @@
+/* Copyright (C) 2018-2019 Andreas Shimokawa, Carsten Pfeiffer, Daniele
+ Gobbetti
+
+ This file is part of Gadgetbridge.
+
+ Gadgetbridge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Gadgetbridge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see . */
+package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
+
+import android.os.Bundle;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+import androidx.preference.PreferenceFragmentCompat;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import nodomain.freeyourgadget.gadgetbridge.R;
+import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
+import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
+import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
+import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
+
+
+public class DeviceSettingsActivity extends AbstractGBActivity {
+ private static final Logger LOG = LoggerFactory.getLogger(DeviceSettingsActivity.class);
+
+ private GBDevice device;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_device_settings);
+
+ DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
+ PreferenceFragmentCompat fragment = coordinator.getDeviceSpecificSettingsFragment(device);
+
+ getSupportFragmentManager()
+ .beginTransaction()
+ .replace(R.id.settings_container, fragment)
+ .commit();
+ }
+
+
+ public class DoesNotExistSettingsFragment extends PreferenceFragmentCompat {
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ }
+ }
+
+}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
new file mode 100644
index 000000000..0a95740b4
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
@@ -0,0 +1,22 @@
+package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
+
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+
+abstract public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
+
+ void setSettingsFileSuffix(String settingsFileSuffix) {
+ Bundle args = new Bundle();
+ args.putString("settingsFileSuffix", settingsFileSuffix);
+ setArguments(args);
+ }
+
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ String settingsFileSuffix = getArguments().getString("settingsFileSuffix", "_bug");
+ getPreferenceManager().setSharedPreferencesName("devicesettings_" + settingsFileSuffix);
+ }
+}
+
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/HuamiSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/HuamiSettingsFragment.java
new file mode 100644
index 000000000..ff0935092
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/HuamiSettingsFragment.java
@@ -0,0 +1,24 @@
+package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
+
+import android.os.Bundle;
+
+import nodomain.freeyourgadget.gadgetbridge.R;
+
+public class HuamiSettingsFragment extends DeviceSpecificSettingsFragment {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ super.onCreatePreferences(savedInstanceState, rootKey);
+ setPreferencesFromResource(R.xml.devicesettings_huami, rootKey);
+ }
+
+ public static HuamiSettingsFragment newInstance(String settingsFileSuffix) {
+ HuamiSettingsFragment fragment = new HuamiSettingsFragment();
+ fragment.setSettingsFileSuffix(settingsFileSuffix);
+
+ return fragment;
+ }
+
+}
+
+
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java
index 86dec08a9..5a7d8a989 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java
@@ -55,6 +55,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.ActivitySummariesActivity
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms;
import nodomain.freeyourgadget.gadgetbridge.activities.VibrationActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
import nodomain.freeyourgadget.gadgetbridge.devices.watch9.Watch9CalibrationActivity;
@@ -152,6 +153,18 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter {
}
private byte[] getSecretKey() {
- return new byte[]{0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45};
+ byte[] authKeyBytes = new byte[]{0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45};
+
+ SharedPreferences preferences = getContext().getSharedPreferences("devicesettings_" + getDevice().getAddress(),Context.MODE_PRIVATE);
+ String authKey = preferences.getString("authkey", null);
+ if (authKey != null && !authKey.isEmpty()) {
+ byte[] srcBytes = authKey.getBytes();
+ System.arraycopy(srcBytes, 0, authKeyBytes, 0, Math.min(srcBytes.length,16));
+ }
+ return authKeyBytes;
}
@Override
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f43ce46f5..8bd43fb43 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -219,6 +219,11 @@
Beep twice
Vibrate and beep once
+
+ Device specific settings
+ Auth Key
+ Change the auth key to a common key on all your Android devices from which you would like to connect from. The previous default key for all devices is 0123456789@ABCDE
+
Auto export
Auto export enabled
diff --git a/app/src/main/res/xml/devicesettings_huami.xml b/app/src/main/res/xml/devicesettings_huami.xml
new file mode 100644
index 000000000..0b0013585
--- /dev/null
+++ b/app/src/main/res/xml/devicesettings_huami.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+