1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 09:17:29 +01:00

Fossil Hybrid HR: Replace hardcoded widget type radio buttons with generated dropdown

This commit is contained in:
Arjan Schrijver 2021-07-14 22:40:02 +02:00 committed by Gitea
parent 2b7fc8dee1
commit 6743af98e9
3 changed files with 31 additions and 40 deletions

View File

@ -37,13 +37,13 @@ import android.util.DisplayMetrics;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -61,6 +61,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.UUID; import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -326,23 +327,26 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
if (index >= 0) { if (index >= 0) {
widget = widgets.get(index); widget = widgets.get(index);
} }
final RadioGroup typeSelector = layout.findViewById(R.id.watchface_widget_type_selector); // Configure widget type dropdown
RadioButton typeDate = layout.findViewById(R.id.watchface_widget_type_date); final Spinner typeSpinner = layout.findViewById(R.id.watchface_widget_type_spinner);
RadioButton typeWeather = layout.findViewById(R.id.watchface_widget_type_weather); LinkedHashMap<String, String> widgetTypes = HybridHRWatchfaceWidget.getAvailableWidgetTypes(this);
if ((widget != null) && (widget.getWidgetType().equals("widgetDate"))) { ArrayAdapter<String> widgetTypeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, widgetTypes.values().toArray(new String[0]));
typeDate.setChecked(true); typeSpinner.setAdapter(widgetTypeAdapter);
} final ArrayList<String> widgetTypesArray = new ArrayList<>(widgetTypes.keySet());
if ((widget != null) && (widget.getWidgetType().equals("widgetWeather"))) { if ((widget != null) && (widgetTypesArray.contains(widget.getWidgetType()))) {
typeWeather.setChecked(true); typeSpinner.setSelection(widgetTypesArray.indexOf(widget.getWidgetType()));
} }
// Set X coordinate
final EditText posX = layout.findViewById(R.id.watchface_widget_pos_x); final EditText posX = layout.findViewById(R.id.watchface_widget_pos_x);
if (widget != null) { if (widget != null) {
posX.setText(Integer.toString(widget.getPosX())); posX.setText(Integer.toString(widget.getPosX()));
} }
// Set Y coordinate
final EditText posY = layout.findViewById(R.id.watchface_widget_pos_y); final EditText posY = layout.findViewById(R.id.watchface_widget_pos_y);
if (widget != null) { if (widget != null) {
posY.setText(Integer.toString(widget.getPosY())); posY.setText(Integer.toString(widget.getPosY()));
} }
// Configure position preset buttons
Button btnTop = layout.findViewById(R.id.watchface_widget_preset_top); Button btnTop = layout.findViewById(R.id.watchface_widget_preset_top);
btnTop.setOnClickListener(new View.OnClickListener() { btnTop.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -403,21 +407,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
if (selectedPosX > 240) selectedPosX = 240; if (selectedPosX > 240) selectedPosX = 240;
if (selectedPosY < 1) selectedPosY = 1; if (selectedPosY < 1) selectedPosY = 1;
if (selectedPosY > 240) selectedPosY = 240; if (selectedPosY > 240) selectedPosY = 240;
switch (typeSelector.getCheckedRadioButtonId()) { String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition());
case R.id.watchface_widget_type_date: if (index >= 0) {
if (index >= 0) { widgets.set(index, new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY));
widgets.set(index, new HybridHRWatchfaceWidget("widgetDate", selectedPosX, selectedPosY)); } else {
} else { widgets.add(new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY));
widgets.add(new HybridHRWatchfaceWidget("widgetDate", selectedPosX, selectedPosY));
}
break;
case R.id.watchface_widget_type_weather:
if (index >= 0) {
widgets.set(index, new HybridHRWatchfaceWidget("widgetWeather", selectedPosX, selectedPosY));
} else {
widgets.add(new HybridHRWatchfaceWidget("widgetWeather", selectedPosX, selectedPosY));
}
break;
} }
renderWatchfacePreview(); renderWatchfacePreview();
} }

View File

@ -21,6 +21,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashMap;
public class HybridHRWatchfaceWidget { public class HybridHRWatchfaceWidget {
private String widgetType; private String widgetType;
@ -33,6 +34,13 @@ public class HybridHRWatchfaceWidget {
this.posY = posY; this.posY = posY;
} }
public static LinkedHashMap<String, String> getAvailableWidgetTypes(Context context) {
LinkedHashMap<String, String> widgetTypes = new LinkedHashMap<>();
widgetTypes.put("widgetDate", "Date");
widgetTypes.put("widgetWeather", "Weather");
return widgetTypes;
}
public String getWidgetType() { public String getWidgetType() {
return widgetType; return widgetType;
} }

View File

@ -9,21 +9,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Type:" /> android:text="Type:" />
<RadioGroup <Spinner
android:id="@+id/watchface_widget_type_selector" android:id="@+id/watchface_widget_type_spinner"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/watchface_widget_type_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"/>
<RadioButton
android:id="@+id/watchface_widget_type_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Weather"/>
</RadioGroup>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"