mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-08 19:27:04 +01:00
Fossil Q Hybrid: Migrate global preferences to device-specific
This commit is contained in:
parent
690d01dcac
commit
41aab5135f
@ -764,15 +764,15 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".devices.qhybrid.ConfigActivity"
|
android:name=".devices.qhybrid.QHybridConfigActivity"
|
||||||
android:label="@string/qhybrid_title_watchface"
|
android:label="@string/qhybrid_title_watchface"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:parentActivityName=".activities.ControlCenterv2" />
|
android:parentActivityName=".activities.devicesettings.DeviceSettingsActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".devices.qhybrid.QHybridAppChoserActivity"
|
android:name=".devices.qhybrid.QHybridAppChoserActivity"
|
||||||
android:label="@string/qhybrid_title_apps"
|
android:label="@string/qhybrid_title_apps"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:parentActivityName=".devices.qhybrid.ConfigActivity" />
|
android:parentActivityName=".devices.qhybrid.QHybridConfigActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".devices.qhybrid.HRConfigActivity"
|
android:name=".devices.qhybrid.HRConfigActivity"
|
||||||
android:label="@string/qhybrid_title_watchface"
|
android:label="@string/qhybrid_title_watchface"
|
||||||
|
@ -124,7 +124,7 @@ public class GBApplication extends Application {
|
|||||||
private static SharedPreferences sharedPrefs;
|
private static SharedPreferences sharedPrefs;
|
||||||
private static final String PREFS_VERSION = "shared_preferences_version";
|
private static final String PREFS_VERSION = "shared_preferences_version";
|
||||||
//if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version
|
//if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version
|
||||||
private static final int CURRENT_PREFS_VERSION = 29;
|
private static final int CURRENT_PREFS_VERSION = 30;
|
||||||
|
|
||||||
private static final LimitedQueue<Integer, String> mIDSenderLookup = new LimitedQueue<>(16);
|
private static final LimitedQueue<Integer, String> mIDSenderLookup = new LimitedQueue<>(16);
|
||||||
private static Prefs prefs;
|
private static Prefs prefs;
|
||||||
@ -1468,6 +1468,28 @@ public class GBApplication extends Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < 30) {
|
||||||
|
// Migrate QHybrid preferences to device-specific
|
||||||
|
try (DBHandler db = acquireDB()) {
|
||||||
|
final DaoSession daoSession = db.getDaoSession();
|
||||||
|
final List<Device> activeDevices = DBHelper.getActiveDevices(daoSession);
|
||||||
|
|
||||||
|
for (Device dbDevice : activeDevices) {
|
||||||
|
final DeviceType deviceType = DeviceType.fromName(dbDevice.getTypeName());
|
||||||
|
if (deviceType == DeviceType.FOSSILQHYBRID) {
|
||||||
|
final SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier());
|
||||||
|
final SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit();
|
||||||
|
|
||||||
|
deviceSharedPrefsEdit.putInt("QHYBRID_TIME_OFFSET", sharedPrefs.getInt("QHYBRID_TIME_OFFSET", 0));
|
||||||
|
deviceSharedPrefsEdit.putInt("QHYBRID_TIMEZONE_OFFSET", sharedPrefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0));
|
||||||
|
deviceSharedPrefsEdit.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "error acquiring DB lock");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
|
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,6 @@ import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryPairin
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter;
|
import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.ConfigActivity;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimePreferenceActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimePreferenceActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||||
@ -138,14 +137,6 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pref = findPreference("pref_key_qhybrid");
|
|
||||||
if (pref != null) {
|
|
||||||
pref.setOnPreferenceClickListener(preference -> {
|
|
||||||
startActivity(new Intent(requireContext(), ConfigActivity.class));
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pref = findPreference("pref_key_pebble");
|
pref = findPreference("pref_key_pebble");
|
||||||
if (pref != null) {
|
if (pref != null) {
|
||||||
pref.setOnPreferenceClickListener(preference -> {
|
pref.setOnPreferenceClickListener(preference -> {
|
||||||
|
@ -80,7 +80,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.foss
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.buttonconfig.ConfigPayload;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.buttonconfig.ConfigPayload;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
public class ConfigActivity extends AbstractGBActivity {
|
public class QHybridConfigActivity extends AbstractGBActivity {
|
||||||
PackageAdapter adapter;
|
PackageAdapter adapter;
|
||||||
ArrayList<NotificationConfiguration> list;
|
ArrayList<NotificationConfiguration> list;
|
||||||
PackageConfigHelper helper;
|
PackageConfigHelper helper;
|
||||||
@ -97,45 +97,53 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (device == null) {
|
||||||
|
GB.toast(this, "Device is null", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setContentView(R.layout.activity_qhybrid_settings);
|
setContentView(R.layout.activity_qhybrid_settings);
|
||||||
|
|
||||||
findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS));
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
prefs = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress());
|
||||||
timeOffsetView = findViewById(R.id.qhybridTimeOffset);
|
timeOffsetView = findViewById(R.id.qhybridTimeOffset);
|
||||||
timeOffsetView.setOnClickListener(new View.OnClickListener() {
|
timeOffsetView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0);
|
int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0);
|
||||||
LinearLayout layout2 = new LinearLayout(ConfigActivity.this);
|
LinearLayout layout2 = new LinearLayout(QHybridConfigActivity.this);
|
||||||
layout2.setOrientation(LinearLayout.HORIZONTAL);
|
layout2.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
|
||||||
final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this);
|
final NumberPicker hourPicker = new NumberPicker(QHybridConfigActivity.this);
|
||||||
hourPicker.setMinValue(0);
|
hourPicker.setMinValue(0);
|
||||||
hourPicker.setMaxValue(23);
|
hourPicker.setMaxValue(23);
|
||||||
hourPicker.setValue(timeOffset / 60);
|
hourPicker.setValue(timeOffset / 60);
|
||||||
|
|
||||||
final NumberPicker minPicker = new NumberPicker(ConfigActivity.this);
|
final NumberPicker minPicker = new NumberPicker(QHybridConfigActivity.this);
|
||||||
minPicker.setMinValue(0);
|
minPicker.setMinValue(0);
|
||||||
minPicker.setMaxValue(59);
|
minPicker.setMaxValue(59);
|
||||||
minPicker.setValue(timeOffset % 60);
|
minPicker.setValue(timeOffset % 60);
|
||||||
|
|
||||||
layout2.addView(hourPicker);
|
layout2.addView(hourPicker);
|
||||||
TextView tw = new TextView(ConfigActivity.this);
|
TextView tw = new TextView(QHybridConfigActivity.this);
|
||||||
tw.setText(":");
|
tw.setText(":");
|
||||||
layout2.addView(tw);
|
layout2.addView(tw);
|
||||||
layout2.addView(minPicker);
|
layout2.addView(minPicker);
|
||||||
|
|
||||||
layout2.setGravity(Gravity.CENTER);
|
layout2.setGravity(Gravity.CENTER);
|
||||||
|
|
||||||
new MaterialAlertDialogBuilder(ConfigActivity.this)
|
new MaterialAlertDialogBuilder(QHybridConfigActivity.this)
|
||||||
.setTitle(getString(R.string.qhybrid_offset_time_by))
|
.setTitle(getString(R.string.qhybrid_offset_time_by))
|
||||||
.setView(layout2)
|
.setView(layout2)
|
||||||
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
||||||
@ -143,7 +151,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
prefs.edit().putInt("QHYBRID_TIME_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
|
prefs.edit().putInt("QHYBRID_TIME_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
|
||||||
updateTimeOffset();
|
updateTimeOffset();
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE));
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE));
|
||||||
GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
|
GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -159,28 +167,28 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
int timeOffset = prefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0);
|
int timeOffset = prefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0);
|
||||||
LinearLayout layout2 = new LinearLayout(ConfigActivity.this);
|
LinearLayout layout2 = new LinearLayout(QHybridConfigActivity.this);
|
||||||
layout2.setOrientation(LinearLayout.HORIZONTAL);
|
layout2.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
|
||||||
final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this);
|
final NumberPicker hourPicker = new NumberPicker(QHybridConfigActivity.this);
|
||||||
hourPicker.setMinValue(0);
|
hourPicker.setMinValue(0);
|
||||||
hourPicker.setMaxValue(23);
|
hourPicker.setMaxValue(23);
|
||||||
hourPicker.setValue(timeOffset / 60);
|
hourPicker.setValue(timeOffset / 60);
|
||||||
|
|
||||||
final NumberPicker minPicker = new NumberPicker(ConfigActivity.this);
|
final NumberPicker minPicker = new NumberPicker(QHybridConfigActivity.this);
|
||||||
minPicker.setMinValue(0);
|
minPicker.setMinValue(0);
|
||||||
minPicker.setMaxValue(59);
|
minPicker.setMaxValue(59);
|
||||||
minPicker.setValue(timeOffset % 60);
|
minPicker.setValue(timeOffset % 60);
|
||||||
|
|
||||||
layout2.addView(hourPicker);
|
layout2.addView(hourPicker);
|
||||||
TextView tw = new TextView(ConfigActivity.this);
|
TextView tw = new TextView(QHybridConfigActivity.this);
|
||||||
tw.setText(":");
|
tw.setText(":");
|
||||||
layout2.addView(tw);
|
layout2.addView(tw);
|
||||||
layout2.addView(minPicker);
|
layout2.addView(minPicker);
|
||||||
|
|
||||||
layout2.setGravity(Gravity.CENTER);
|
layout2.setGravity(Gravity.CENTER);
|
||||||
|
|
||||||
new MaterialAlertDialogBuilder(ConfigActivity.this)
|
new MaterialAlertDialogBuilder(QHybridConfigActivity.this)
|
||||||
.setTitle(getString(R.string.qhybrid_offset_timezone))
|
.setTitle(getString(R.string.qhybrid_offset_timezone))
|
||||||
.setView(layout2)
|
.setView(layout2)
|
||||||
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
||||||
@ -188,7 +196,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
prefs.edit().putInt("QHYBRID_TIMEZONE_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
|
prefs.edit().putInt("QHYBRID_TIMEZONE_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
|
||||||
updateTimezoneOffset();
|
updateTimezoneOffset();
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_TIMEZONE));
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_TIMEZONE));
|
||||||
GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
|
GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -215,7 +223,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
appList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
appList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(final AdapterView<?> adapterView, View view, final int i, long l) {
|
public boolean onItemLongClick(final AdapterView<?> adapterView, View view, final int i, long l) {
|
||||||
PopupMenu menu = new PopupMenu(ConfigActivity.this, view);
|
PopupMenu menu = new PopupMenu(QHybridConfigActivity.this, view);
|
||||||
menu.getMenu().add(0, 0, 0, "edit");
|
menu.getMenu().add(0, 0, 0, "edit");
|
||||||
menu.getMenu().add(0, 1, 1, "delete");
|
menu.getMenu().add(0, 1, 1, "delete");
|
||||||
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@ -223,7 +231,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case 0: {
|
case 0: {
|
||||||
TimePicker picker = new TimePicker(ConfigActivity.this, (NotificationConfiguration) adapterView.getItemAtPosition(i));
|
TimePicker picker = new TimePicker(QHybridConfigActivity.this, (NotificationConfiguration) adapterView.getItemAtPosition(i));
|
||||||
picker.finishListener = new TimePicker.OnFinishListener() {
|
picker.finishListener = new TimePicker.OnFinishListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFinish(boolean success, NotificationConfiguration config) {
|
public void onFinish(boolean success, NotificationConfiguration config) {
|
||||||
@ -231,7 +239,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
if (success) {
|
if (success) {
|
||||||
try {
|
try {
|
||||||
helper.saveNotificationConfiguration(config);
|
helper.saveNotificationConfiguration(config);
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
GB.toast("error saving notification", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast("error saving notification", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
}
|
}
|
||||||
@ -257,7 +265,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
case 1: {
|
case 1: {
|
||||||
try {
|
try {
|
||||||
helper.deleteNotificationConfiguration((NotificationConfiguration) adapterView.getItemAtPosition(i));
|
helper.deleteNotificationConfiguration((NotificationConfiguration) adapterView.getItemAtPosition(i));
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
GB.toast("error deleting setting", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast("error deleting setting", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
}
|
}
|
||||||
@ -278,7 +286,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
Intent notificationIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION);
|
Intent notificationIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION);
|
||||||
notificationIntent.putExtra("CONFIG", (NotificationConfiguration) adapterView.getItemAtPosition(i));
|
notificationIntent.putExtra("CONFIG", (NotificationConfiguration) adapterView.getItemAtPosition(i));
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(notificationIntent);
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(notificationIntent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
SeekBar vibeBar = findViewById(R.id.vibrationStrengthBar);
|
SeekBar vibeBar = findViewById(R.id.vibrationStrengthBar);
|
||||||
@ -302,23 +310,16 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, values[progress]));
|
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, values[progress]));
|
||||||
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
||||||
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_VIBRATION_STRENGTH);
|
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_VIBRATION_STRENGTH);
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// NOTE: this code always selects the first connected Q Hybrid device
|
if (device.getType() == DeviceType.FOSSILQHYBRID && device.isInitialized() && device.getFirmwareVersion().charAt(2) == '0') {
|
||||||
// because currently this class is unable to handle multiple
|
|
||||||
// connected Q Hybrid devices
|
|
||||||
List<GBDevice> devices = GBApplication.app().getDeviceManager().getSelectedDevices();
|
|
||||||
for(GBDevice candidate : devices){
|
|
||||||
if (candidate.getType() == DeviceType.FOSSILQHYBRID && candidate.getFirmwareVersion().charAt(2) == '0') {
|
|
||||||
device = candidate;
|
|
||||||
updateSettings();
|
updateSettings();
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
}
|
|
||||||
setSettingsError(getString(R.string.watch_not_connected));
|
setSettingsError(getString(R.string.watch_not_connected));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateTimeOffset() {
|
private void updateTimeOffset() {
|
||||||
int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0);
|
int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0);
|
||||||
@ -362,7 +363,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_GOAL, t));
|
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_GOAL, t));
|
||||||
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
||||||
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_STEP_GOAL);
|
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_STEP_GOAL);
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(intent);
|
||||||
updateSettings();
|
updateSettings();
|
||||||
}
|
}
|
||||||
((InputMethodManager) getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
|
((InputMethodManager) getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
|
||||||
@ -390,7 +391,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
|
||||||
if (!device.getDeviceInfo(QHybridSupport.ITEM_STEP_GOAL).getDetails().equals("1000000")) {
|
if (!device.getDeviceInfo(QHybridSupport.ITEM_STEP_GOAL).getDetails().equals("1000000")) {
|
||||||
new MaterialAlertDialogBuilder(ConfigActivity.this)
|
new MaterialAlertDialogBuilder(QHybridConfigActivity.this)
|
||||||
.setMessage(getString(R.string.qhybrid_prompt_million_steps))
|
.setMessage(getString(R.string.qhybrid_prompt_million_steps))
|
||||||
.setPositiveButton("ok", null)
|
.setPositiveButton("ok", null)
|
||||||
.show();
|
.show();
|
||||||
@ -400,7 +401,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_USE_ACTIVITY_HAND, String.valueOf(checked)));
|
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_USE_ACTIVITY_HAND, String.valueOf(checked)));
|
||||||
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
||||||
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_USE_ACTIVITY_HAND);
|
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_USE_ACTIVITY_HAND);
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -440,7 +441,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
for (int i = 0; i < buttonConfig.length(); i++) {
|
for (int i = 0; i < buttonConfig.length(); i++) {
|
||||||
final int currentIndex = i;
|
final int currentIndex = i;
|
||||||
String configName = buttonConfig.getString(i);
|
String configName = buttonConfig.getString(i);
|
||||||
TextView buttonTextView = new TextView(ConfigActivity.this);
|
TextView buttonTextView = new TextView(QHybridConfigActivity.this);
|
||||||
buttonTextView.setTextSize(20);
|
buttonTextView.setTextSize(20);
|
||||||
try {
|
try {
|
||||||
ConfigPayload payload = ConfigPayload.valueOf(configName);
|
ConfigPayload payload = ConfigPayload.valueOf(configName);
|
||||||
@ -452,7 +453,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
buttonTextView.setOnClickListener(new View.OnClickListener() {
|
buttonTextView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
AlertDialog dialog = new MaterialAlertDialogBuilder(ConfigActivity.this)
|
AlertDialog dialog = new MaterialAlertDialogBuilder(QHybridConfigActivity.this)
|
||||||
.setItems(names, new DialogInterface.OnClickListener() {
|
.setItems(names, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
@ -465,7 +466,7 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
updateSettings();
|
updateSettings();
|
||||||
Intent buttonIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS);
|
Intent buttonIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS);
|
||||||
buttonIntent.putExtra(FossilWatchAdapter.ITEM_BUTTONS, buttonConfig.toString());
|
buttonIntent.putExtra(FossilWatchAdapter.ITEM_BUTTONS, buttonConfig.toString());
|
||||||
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(buttonIntent);
|
LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(buttonIntent);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
GB.log("error", GB.ERROR, e);
|
GB.log("error", GB.ERROR, e);
|
||||||
}
|
}
|
||||||
@ -547,6 +548,16 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
this.onBackPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
private void setSettingsError(final String error) {
|
private void setSettingsError(final String error) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@ -575,13 +586,13 @@ public class ConfigActivity extends AbstractGBActivity {
|
|||||||
NotificationConfiguration settings = getItem(position);
|
NotificationConfiguration settings = getItem(position);
|
||||||
|
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
Button addButton = new Button(ConfigActivity.this);
|
Button addButton = new Button(QHybridConfigActivity.this);
|
||||||
addButton.setText("+");
|
addButton.setText("+");
|
||||||
addButton.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
addButton.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
addButton.setOnClickListener(new View.OnClickListener() {
|
addButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
startActivityForResult(new Intent(ConfigActivity.this, QHybridAppChoserActivity.class), REQUEST_CODE_ADD_APP);
|
startActivityForResult(new Intent(QHybridConfigActivity.this, QHybridAppChoserActivity.class), REQUEST_CODE_ADD_APP);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return addButton;
|
return addButton;
|
@ -41,10 +41,12 @@ import nodomain.freeyourgadget.gadgetbridge.GBException;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettings;
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettings;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsScreen;
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsScreen;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.cmfwatchpro.CmfWatchProSettingsCustomizer;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
@ -150,7 +152,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCannedRepliesSlotCount(final GBDevice device) {
|
public int getCannedRepliesSlotCount(final GBDevice device) {
|
||||||
if (isHybridHR()) {
|
if (isHybridHR(device)) {
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,17 +161,17 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsAlarmTitle(GBDevice device) {
|
public boolean supportsAlarmTitle(GBDevice device) {
|
||||||
return isHybridHR();
|
return isHybridHR(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsAlarmDescription(GBDevice device) {
|
public boolean supportsAlarmDescription(GBDevice device) {
|
||||||
return isHybridHR();
|
return isHybridHR(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
||||||
return this.isHybridHR();
|
return isHybridHR(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -189,7 +191,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Activity> getAppsManagementActivity() {
|
public Class<? extends Activity> getAppsManagementActivity() {
|
||||||
return isHybridHR() ? AppManagerActivity.class : ConfigActivity.class;
|
return isHybridHR() ? AppManagerActivity.class : QHybridConfigActivity.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -249,7 +251,8 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
@Override
|
@Override
|
||||||
public DeviceSpecificSettings getDeviceSpecificSettings(final GBDevice device) {
|
public DeviceSpecificSettings getDeviceSpecificSettings(final GBDevice device) {
|
||||||
final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings();
|
final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings();
|
||||||
if (!isHybridHR()) {
|
if (!isHybridHR(device)) {
|
||||||
|
deviceSpecificSettings.addRootScreen(R.xml.devicesettings_fossilqhybrid_legacy);
|
||||||
return deviceSpecificSettings;
|
return deviceSpecificSettings;
|
||||||
}
|
}
|
||||||
final List<Integer> generic = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.GENERIC);
|
final List<Integer> generic = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.GENERIC);
|
||||||
@ -280,6 +283,11 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return deviceSpecificSettings;
|
return deviceSpecificSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceSpecificSettingsCustomizer getDeviceSpecificSettingsCustomizer(final GBDevice device) {
|
||||||
|
return new QHybridSettingsCustomizer();
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends DeviceSupport> getDeviceSupportClass() {
|
public Class<? extends DeviceSupport> getDeviceSupportClass() {
|
||||||
@ -293,6 +301,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated // we should use the isHybridHR(GBDevice) instead of iterating every single device
|
||||||
private boolean isHybridHR() {
|
private boolean isHybridHR() {
|
||||||
List<GBDevice> devices = GBApplication.app().getDeviceManager().getSelectedDevices();
|
List<GBDevice> devices = GBApplication.app().getDeviceManager().getSelectedDevices();
|
||||||
for(GBDevice device : devices){
|
for(GBDevice device : devices){
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Parcel;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
|
public class QHybridSettingsCustomizer implements DeviceSpecificSettingsCustomizer {
|
||||||
|
@Override
|
||||||
|
public void onPreferenceChange(final Preference preference, final DeviceSpecificSettingsHandler handler) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void customizeSettings(final DeviceSpecificSettingsHandler handler, final Prefs prefs) {
|
||||||
|
final Preference pref = handler.findPreference("pref_key_qhybrid_legacy");
|
||||||
|
if (pref != null) {
|
||||||
|
pref.setOnPreferenceClickListener(preference -> {
|
||||||
|
final Intent intent = new Intent(handler.getContext(), QHybridConfigActivity.class);
|
||||||
|
intent.putExtra(GBDevice.EXTRA_DEVICE, handler.getDevice());
|
||||||
|
handler.getContext().startActivity(intent);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getPreferenceKeysWithSummary() {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<QHybridSettingsCustomizer> CREATOR = new Creator<QHybridSettingsCustomizer>() {
|
||||||
|
@Override
|
||||||
|
public QHybridSettingsCustomizer createFromParcel(final Parcel in) {
|
||||||
|
return new QHybridSettingsCustomizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QHybridSettingsCustomizer[] newArray(final int size) {
|
||||||
|
return new QHybridSettingsCustomizer[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
|
||||||
|
}
|
||||||
|
}
|
@ -1612,6 +1612,7 @@
|
|||||||
<string name="menuitem_cards">Cards</string>
|
<string name="menuitem_cards">Cards</string>
|
||||||
<string name="menuitem_mi_ai">MI AI</string>
|
<string name="menuitem_mi_ai">MI AI</string>
|
||||||
<string name="preferences_qhybrid_settings">Q Hybrid Settings</string>
|
<string name="preferences_qhybrid_settings">Q Hybrid Settings</string>
|
||||||
|
<string name="preferences_qhybrid_settings_summary">Legacy settings for Q Hybrid watches</string>
|
||||||
<string name="menuitem_music">Music</string>
|
<string name="menuitem_music">Music</string>
|
||||||
<string name="menuitem_more">More</string>
|
<string name="menuitem_more">More</string>
|
||||||
<string name="menuitem_nfc">NFC</string>
|
<string name="menuitem_nfc">NFC</string>
|
||||||
|
10
app/src/main/res/xml/devicesettings_fossilqhybrid_legacy.xml
Normal file
10
app/src/main/res/xml/devicesettings_fossilqhybrid_legacy.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:icon="@drawable/ic_settings"
|
||||||
|
android:key="pref_key_qhybrid_legacy"
|
||||||
|
android:summary="@string/preferences_qhybrid_settings_summary"
|
||||||
|
android:title="@string/preferences_qhybrid_settings" />
|
||||||
|
|
||||||
|
</androidx.preference.PreferenceScreen>
|
@ -270,11 +270,6 @@
|
|||||||
android:title="@string/preferences_category_device_specific_settings"
|
android:title="@string/preferences_category_device_specific_settings"
|
||||||
app:iconSpaceReserved="false">
|
app:iconSpaceReserved="false">
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:icon="@drawable/ic_device_pebble"
|
|
||||||
android:key="pref_key_qhybrid"
|
|
||||||
android:title="@string/preferences_qhybrid_settings" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:icon="@drawable/ic_device_miband"
|
android:icon="@drawable/ic_device_miband"
|
||||||
android:key="pref_key_miband"
|
android:key="pref_key_miband"
|
||||||
|
Loading…
Reference in New Issue
Block a user