Fossil HR: try guessing new widget position

This commit is contained in:
Daniel Dakhno 2022-03-09 10:44:49 +01:00
parent c0ca52d2b8
commit f49184ef62
3 changed files with 40 additions and 31 deletions

View File

@ -576,39 +576,46 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
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
public void onClick(View v) {
posX.setText("120");
posY.setText("58");
class WidgetPosition{
final int posX, posY, buttonResource, hintStringResource;
public WidgetPosition(int posX, int posY, int buttonResource, int hintStringResource) {
this.posX = posX;
this.posY = posY;
this.buttonResource = buttonResource;
this.hintStringResource = hintStringResource;
}
});
Button btnBottom = layout.findViewById(R.id.watchface_widget_preset_bottom);
btnBottom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
posX.setText("120");
posY.setText("182");
}
WidgetPosition[] positions = new WidgetPosition[]{
new WidgetPosition(120, 58, R.id.watchface_widget_preset_top, R.string.watchface_dialog_widget_preset_top),
new WidgetPosition(182, 120, R.id.watchface_widget_preset_right, R.string.watchface_dialog_widget_preset_right),
new WidgetPosition(120, 182, R.id.watchface_widget_preset_bottom, R.string.watchface_dialog_widget_preset_bottom),
new WidgetPosition(58, 120, R.id.watchface_widget_preset_left, R.string.watchface_dialog_widget_preset_left),
};
for(final WidgetPosition position : positions){
Button btn = layout.findViewById(position.buttonResource);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
posX.setText(String.valueOf(position.posX));
posY.setText(String.valueOf(position.posY));
}
});
}
if(widget == null){
int currentIndex = widgets.size();
if(currentIndex < 4){
WidgetPosition newPosition = positions[currentIndex];
posX.setText(String.valueOf(newPosition.posX));
posY.setText(String.valueOf(newPosition.posY));
GB.toast(getString(R.string.watchface_dialog_pre_setting_position, getString(newPosition.hintStringResource)), Toast.LENGTH_SHORT, GB.INFO);
}
});
Button btnLeft = layout.findViewById(R.id.watchface_widget_preset_left);
btnLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
posX.setText("58");
posY.setText("120");
}
});
Button btnRight = layout.findViewById(R.id.watchface_widget_preset_right);
btnRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
posX.setText("182");
posY.setText("120");
}
});
}
// Set widget size
final LinearLayout sizeLayout = layout.findViewById(R.id.watchface_widget_size_layout);
sizeLayout.setVisibility(View.GONE);

View File

@ -1589,4 +1589,5 @@
<string name="sony_anc_optimize_confirmation_description">Verwende den Kopfhörer wie gewohnt. Wenn sich die Tragebedingungen oder der Luftdruck ändern, führe den Optimierer erneut aus.</string>
<string name="devicetype_amazfit_pop">Amazfit Pop</string>
<string name="devicetype_amazfit_pop_pro">Amazfit Pop Pro</string>
<string name="watchface_dialog_pre_setting_position">Setze position auf %s</string>
</resources>

View File

@ -1527,4 +1527,5 @@
<string name="watchface_dialog_widget_width">Width:</string>
<string name="pref_title_opentracks_packagename">OpenTracks package name</string>
<string name="pref_summary_opentracks_packagename">Used for starting/stopping GPS track recording in external fitness app.</string>
<string name="watchface_dialog_pre_setting_position">pre-setting position to %s</string>
</resources>