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