mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-30 14:02:56 +01:00
Fossil Hybrid HR: Support configuring watchface internal values
This commit is contained in:
parent
6000dd525e
commit
8fabf0d038
Binary file not shown.
@ -40,6 +40,7 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
@ -84,6 +85,7 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
private Bitmap selectedBackgroundImage, processedBackgroundImage;
|
||||
private String watchfaceName = "NewWatchface";
|
||||
final private ArrayList<HybridHRWatchfaceWidget> widgets = new ArrayList<>();
|
||||
private HybridHRWatchfaceSettings watchfaceSettings = new HybridHRWatchfaceSettings();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -183,6 +185,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
startActivityForResult(intent, 42);
|
||||
} else if (v.getId() == R.id.button_add_widget) {
|
||||
showWidgetEditPopup(-1);
|
||||
} else if (v.getId() == R.id.button_watchface_settings) {
|
||||
showWatchfaceSettingsPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,6 +288,30 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
} catch (JSONException e) {
|
||||
LOG.warn("JSON parsing error", e);
|
||||
}
|
||||
} else if (key.equals("config")) {
|
||||
try {
|
||||
JSONObject watchfaceConfig = configJSON.getJSONObject(key);
|
||||
if (watchfaceConfig.has("timeout_display_full")) {
|
||||
watchfaceSettings.setDisplayTimeoutFull(watchfaceConfig.getInt("timeout_display_full") / 60 / 1000);
|
||||
}
|
||||
if (watchfaceConfig.has("timeout_display_partial")) {
|
||||
watchfaceSettings.setDisplayTimeoutPartial(watchfaceConfig.getInt("timeout_display_partial") / 60 / 1000);
|
||||
}
|
||||
if (watchfaceConfig.has("wrist_flick_hands_relative")) {
|
||||
watchfaceSettings.setWristFlickHandsMoveRelative(watchfaceConfig.getBoolean("wrist_flick_hands_relative"));
|
||||
}
|
||||
if (watchfaceConfig.has("wrist_flick_duration")) {
|
||||
watchfaceSettings.setWristFlickDuration(watchfaceConfig.getInt("wrist_flick_duration"));
|
||||
}
|
||||
if (watchfaceConfig.has("wrist_flick_move_hour")) {
|
||||
watchfaceSettings.setWristFlickMoveHour(watchfaceConfig.getInt("wrist_flick_move_hour"));
|
||||
}
|
||||
if (watchfaceConfig.has("wrist_flick_move_minute")) {
|
||||
watchfaceSettings.setWristFlickMoveMinute(watchfaceConfig.getInt("wrist_flick_move_minute"));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
LOG.warn("JSON parsing error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -466,6 +494,38 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
.show();
|
||||
}
|
||||
|
||||
private void showWatchfaceSettingsPopup() {
|
||||
View layout = getLayoutInflater().inflate(R.layout.dialog_hybridhr_watchface_settings, null);
|
||||
final EditText displayTimeoutFullInput = layout.findViewById(R.id.watchface_setting_display_full);
|
||||
displayTimeoutFullInput.setText(String.valueOf(watchfaceSettings.getDisplayTimeoutFull()));
|
||||
final EditText displayTimeoutPartialInput = layout.findViewById(R.id.watchface_setting_display_partial);
|
||||
displayTimeoutPartialInput.setText(String.valueOf(watchfaceSettings.getDisplayTimeoutPartial()));
|
||||
final CheckBox wristFlickHandsMoveRelativeInput = layout.findViewById(R.id.watchface_setting_flick_relative);
|
||||
wristFlickHandsMoveRelativeInput.setChecked(watchfaceSettings.isWristFlickHandsMoveRelative());
|
||||
final EditText wristFlickDurationInput = layout.findViewById(R.id.watchface_setting_flick_timeout);
|
||||
wristFlickDurationInput.setText(String.valueOf(watchfaceSettings.getWristFlickDuration()));
|
||||
final EditText wristFlickMoveHourInput = layout.findViewById(R.id.watchface_setting_flick_hour);
|
||||
wristFlickMoveHourInput.setText(String.valueOf(watchfaceSettings.getWristFlickMoveHour()));
|
||||
final EditText wristFlickMoveMinuteInput = layout.findViewById(R.id.watchface_setting_flick_minute);
|
||||
wristFlickMoveMinuteInput.setText(String.valueOf(watchfaceSettings.getWristFlickMoveMinute()));
|
||||
new AlertDialog.Builder(this)
|
||||
.setView(layout)
|
||||
.setNegativeButton(R.string.fossil_hr_new_action_cancel, null)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
watchfaceSettings.setDisplayTimeoutFull(Integer.parseInt(displayTimeoutFullInput.getText().toString()));
|
||||
watchfaceSettings.setDisplayTimeoutPartial(Integer.parseInt(displayTimeoutPartialInput.getText().toString()));
|
||||
watchfaceSettings.setWristFlickHandsMoveRelative(wristFlickHandsMoveRelativeInput.isChecked());
|
||||
watchfaceSettings.setWristFlickDuration(Integer.parseInt(wristFlickDurationInput.getText().toString()));
|
||||
watchfaceSettings.setWristFlickMoveHour(Integer.parseInt(wristFlickMoveHourInput.getText().toString()));
|
||||
watchfaceSettings.setWristFlickMoveMinute(Integer.parseInt(wristFlickMoveMinuteInput.getText().toString()));
|
||||
}
|
||||
})
|
||||
.setTitle(R.string.watchface_dialog_title_settings)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void calculateDisplayImageSize() {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
@ -504,6 +564,7 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
} else {
|
||||
wfFactory = new HybridHRWatchfaceFactory(watchfaceName);
|
||||
}
|
||||
wfFactory.setSettings(watchfaceSettings);
|
||||
wfFactory.setBackground(processedBackgroundImage);
|
||||
wfFactory.addWidgets(widgets);
|
||||
try {
|
||||
|
@ -36,6 +36,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
|
||||
public class HybridHRWatchfaceFactory {
|
||||
private final Logger LOG = LoggerFactory.getLogger(HybridHRWatchfaceFactory.class);
|
||||
private String watchfaceName;
|
||||
private HybridHRWatchfaceSettings settings;
|
||||
private Bitmap background;
|
||||
private ArrayList<JSONObject> widgets = new ArrayList<>();
|
||||
|
||||
@ -45,6 +46,10 @@ public class HybridHRWatchfaceFactory {
|
||||
if (watchfaceName.endsWith("App")) watchfaceName += "Watchface";
|
||||
}
|
||||
|
||||
public void setSettings(HybridHRWatchfaceSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public void setBackground(Bitmap background) {
|
||||
if ((background.getWidth() == 240) && (background.getHeight() == 240)) {
|
||||
this.background = background;
|
||||
@ -259,8 +264,8 @@ public class HybridHRWatchfaceFactory {
|
||||
|
||||
private String getConfiguration() throws JSONException {
|
||||
JSONObject configuration = new JSONObject();
|
||||
JSONArray layout = new JSONArray();
|
||||
|
||||
JSONArray layout = new JSONArray();
|
||||
JSONObject background = new JSONObject();
|
||||
background.put("type", "image");
|
||||
background.put("name", "background.raw");
|
||||
@ -273,12 +278,20 @@ public class HybridHRWatchfaceFactory {
|
||||
pos.put("y", 120);
|
||||
background.put("pos", pos);
|
||||
layout.put(background);
|
||||
|
||||
for (JSONObject widget : widgets) {
|
||||
layout.put(widget);
|
||||
}
|
||||
|
||||
configuration.put("layout", layout);
|
||||
|
||||
JSONObject config = new JSONObject();
|
||||
config.put("timeout_display_full", settings.getDisplayTimeoutFull() * 60 * 1000);
|
||||
config.put("timeout_display_partial", settings.getDisplayTimeoutPartial() * 60 * 1000);
|
||||
config.put("wrist_flick_hands_relative", settings.isWristFlickHandsMoveRelative());
|
||||
config.put("wrist_flick_duration", settings.getWristFlickDuration());
|
||||
config.put("wrist_flick_move_hour", settings.getWristFlickMoveHour());
|
||||
config.put("wrist_flick_move_minute", settings.getWristFlickMoveMinute());
|
||||
configuration.put("config", config);
|
||||
|
||||
return configuration.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
/* Copyright (C) 2021 Arjan Schrijver
|
||||
|
||||
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 <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
|
||||
|
||||
public class HybridHRWatchfaceSettings {
|
||||
private int displayTimeoutFull = 60;
|
||||
private int displayTimeoutPartial = 15;
|
||||
private boolean wristFlickHandsMoveRelative = true;
|
||||
private int wristFlickDuration = 2200;
|
||||
private int wristFlickMoveHour = 360;
|
||||
private int wristFlickMoveMinute = -360;
|
||||
|
||||
public HybridHRWatchfaceSettings() {
|
||||
}
|
||||
|
||||
public int getDisplayTimeoutFull() {
|
||||
return displayTimeoutFull;
|
||||
}
|
||||
|
||||
public void setDisplayTimeoutFull(int displayTimeoutFull) {
|
||||
this.displayTimeoutFull = displayTimeoutFull;
|
||||
}
|
||||
|
||||
public int getDisplayTimeoutPartial() {
|
||||
return displayTimeoutPartial;
|
||||
}
|
||||
|
||||
public void setDisplayTimeoutPartial(int displayTimeoutPartial) {
|
||||
this.displayTimeoutPartial = displayTimeoutPartial;
|
||||
}
|
||||
|
||||
public boolean isWristFlickHandsMoveRelative() {
|
||||
return wristFlickHandsMoveRelative;
|
||||
}
|
||||
|
||||
public void setWristFlickHandsMoveRelative(boolean wristFlickHandsMoveRelative) {
|
||||
this.wristFlickHandsMoveRelative = wristFlickHandsMoveRelative;
|
||||
}
|
||||
|
||||
public int getWristFlickDuration() {
|
||||
return wristFlickDuration;
|
||||
}
|
||||
|
||||
public void setWristFlickDuration(int wristFlickDuration) {
|
||||
this.wristFlickDuration = wristFlickDuration;
|
||||
}
|
||||
|
||||
public int getWristFlickMoveHour() {
|
||||
return wristFlickMoveHour;
|
||||
}
|
||||
|
||||
public void setWristFlickMoveHour(int wristFlickMoveHour) {
|
||||
if (wristFlickMoveHour < -360) {
|
||||
this.wristFlickMoveHour = -360;
|
||||
} else if (wristFlickMoveHour > 360) {
|
||||
this.wristFlickMoveHour = 360;
|
||||
} else {
|
||||
this.wristFlickMoveHour = wristFlickMoveHour;
|
||||
}
|
||||
}
|
||||
|
||||
public int getWristFlickMoveMinute() {
|
||||
return wristFlickMoveMinute;
|
||||
}
|
||||
|
||||
public void setWristFlickMoveMinute(int wristFlickMoveMinute) {
|
||||
if (wristFlickMoveMinute < -360) {
|
||||
this.wristFlickMoveMinute = -360;
|
||||
} else if (wristFlickMoveMinute > 360) {
|
||||
this.wristFlickMoveMinute = 360;
|
||||
} else {
|
||||
this.wristFlickMoveMinute = wristFlickMoveMinute;
|
||||
}
|
||||
}
|
||||
}
|
@ -61,7 +61,6 @@
|
||||
android:id="@+id/button_watchface_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:enabled="false"
|
||||
android:text="@string/button_watchface_settings" />
|
||||
|
||||
</LinearLayout>
|
||||
|
122
app/src/main/res/layout/dialog_hybridhr_watchface_settings.xml
Normal file
122
app/src/main/res/layout/dialog_hybridhr_watchface_settings.xml
Normal file
@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/watchface_setting_title_display_refresh_timeout"
|
||||
android:textSize="20dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_setting_display_refresh_full" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/watchface_setting_display_full"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_setting_display_refresh_partial" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/watchface_setting_display_partial"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/watchface_setting_title_wrist_flick"
|
||||
android:textSize="20dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_setting_desc_wrist_flick"
|
||||
android:textStyle="italic" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_setting_wrist_flick_move_relative" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/watchface_setting_flick_relative"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_setting_wrist_flick_hour" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/watchface_setting_flick_hour"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_setting_wrist_flick_minute" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/watchface_setting_flick_minute"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_setting_wrist_flick_duration" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/watchface_setting_flick_timeout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1230,4 +1230,14 @@
|
||||
<string name="watchface_dialog_widget_color">Color:</string>
|
||||
<string name="watchface_dialog_widget_color_white">White on black</string>
|
||||
<string name="watchface_dialog_widget_color_black">Black on white</string>
|
||||
<string name="watchface_dialog_title_settings">Watchface settings</string>
|
||||
<string name="watchface_setting_title_display_refresh_timeout">Display refresh timeout</string>
|
||||
<string name="watchface_setting_display_refresh_full">Full refresh (in minutes):</string>
|
||||
<string name="watchface_setting_display_refresh_partial">Partial refresh (in minutes):</string>
|
||||
<string name="watchface_setting_title_wrist_flick">Wrist flick</string>
|
||||
<string name="watchface_setting_desc_wrist_flick">(to disable completely, enable relative movement and set all values to 0)</string>
|
||||
<string name="watchface_setting_wrist_flick_move_relative">Hands move relative to time:</string>
|
||||
<string name="watchface_setting_wrist_flick_hour">Hour hand (-360 to 360):</string>
|
||||
<string name="watchface_setting_wrist_flick_minute">Minute hand (-360 to 360):</string>
|
||||
<string name="watchface_setting_wrist_flick_duration">Duration (in ms):</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user