1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-30 14:02:56 +01:00

Fossil Hybrid HR: Drop widget on recycle bin to delete

This commit is contained in:
Arjan Schrijver 2021-07-18 20:45:57 +02:00 committed by Gitea
parent 8fabf0d038
commit a710f0f677
2 changed files with 43 additions and 6 deletions

View File

@ -112,6 +112,7 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
renderWatchfacePreview();
backgroundImageView.setOnDragListener(this);
findViewById(R.id.watchface_widget_delete_droparea).setOnDragListener(this);
findViewById(R.id.button_edit_name).setOnClickListener(this);
findViewById(R.id.button_set_background).setOnClickListener(this);
findViewById(R.id.button_add_widget).setOnClickListener(this);
@ -201,17 +202,37 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
public boolean onDrag(View targetView, DragEvent event) {
View draggedWidget = (View) event.getLocalState();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
findViewById(R.id.watchface_widget_delete_layout).setVisibility(View.VISIBLE);
break;
case DragEvent.ACTION_DRAG_ENTERED:
if (targetView.getId() == R.id.watchface_widget_delete_droparea) {
findViewById(R.id.watchface_widget_delete_droparea).setBackgroundColor(Color.RED);
}
break;
case DragEvent.ACTION_DRAG_EXITED:
if (targetView.getId() == R.id.watchface_widget_delete_droparea) {
findViewById(R.id.watchface_widget_delete_droparea).setBackgroundColor(Color.TRANSPARENT);
}
break;
case DragEvent.ACTION_DROP:
int posX = (int)(event.getX() / scaleFactor);
int posY = (int)(event.getY() / scaleFactor);
if (targetView.getId() == R.id.watchface_widget_delete_droparea) {
widgets.remove(draggedWidget.getId());
renderWatchfacePreview();
} else if (targetView.getId() == R.id.hybridhr_background_image) {
int posX = (int) (event.getX() / scaleFactor);
int posY = (int) (event.getY() / scaleFactor);
widgets.get(draggedWidget.getId()).setPosX(posX);
widgets.get(draggedWidget.getId()).setPosY(posY);
renderWatchfacePreview();
}
break;
case DragEvent.ACTION_DRAG_ENDED:
if (!event.getResult()) {
draggedWidget.setVisibility(View.VISIBLE);
}
findViewById(R.id.watchface_widget_delete_droparea).setBackgroundColor(Color.TRANSPARENT);
findViewById(R.id.watchface_widget_delete_layout).setVisibility(View.GONE);
break;
}
return true;

View File

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".devices.qhybrid.HybridHRWatchfaceDesignerActivity">
<RelativeLayout
@ -45,6 +46,21 @@
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/watchface_widget_delete_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:visibility="gone">
<ImageView
android:id="@+id/watchface_widget_delete_droparea"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/ic_delete_forever" />
</RelativeLayout>
<Button
android:id="@+id/button_set_background"
android:layout_width="wrap_content"