1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Fossil Hybrid HR: Add drag&drop for widgets

This commit is contained in:
Arjan Schrijver 2021-07-16 11:36:46 +02:00 committed by Gitea
parent d4c69ebca3
commit d4b5796267
3 changed files with 46 additions and 7 deletions

View File

@ -34,6 +34,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.view.DragEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -73,7 +74,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implements View.OnClickListener {
public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implements View.OnClickListener, View.OnLongClickListener, View.OnDragListener {
private final Logger LOG = LoggerFactory.getLogger(HybridHRWatchfaceDesignerActivity.class);
private GBDevice mGBDevice;
private DeviceCoordinator mCoordinator;
@ -108,6 +109,7 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
renderWatchfacePreview();
backgroundImageView.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);
@ -184,6 +186,33 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
}
}
@Override
public boolean onLongClick(View view) {
view.startDrag(null, new View.DragShadowBuilder(view), view, 0);
view.setVisibility(View.INVISIBLE);
return true;
}
@Override
public boolean onDrag(View targetView, DragEvent event) {
View draggedWidget = (View) event.getLocalState();
switch (event.getAction()) {
case DragEvent.ACTION_DROP:
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);
}
break;
}
return true;
}
private void loadConfigurationFromApp(String appUUID) {
File appCacheDir;
try {
@ -279,15 +308,15 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
processedBackgroundImage = Bitmap.createScaledBitmap(selectedBackgroundImage, displayImageSize, displayImageSize, true);
}
// Remove existing widget ImageViews
RelativeLayout imageContainer = this.findViewById(R.id.watchface_preview_image);
RelativeLayout previewLayout = this.findViewById(R.id.watchface_preview_layout);
boolean onlyPreviewIsRemaining = false;
while (!onlyPreviewIsRemaining) {
int childCount = imageContainer.getChildCount();
int childCount = previewLayout.getChildCount();
int i;
for(i=0; i<childCount; i++) {
View currentChild = imageContainer.getChildAt(i);
View currentChild = previewLayout.getChildAt(i);
if (currentChild.getId() != R.id.hybridhr_background_image) {
imageContainer.removeView(currentChild);
previewLayout.removeView(currentChild);
break;
}
}
@ -323,7 +352,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
showWidgetEditPopup(v.getId());
}
});
imageContainer.addView(widgetView);
widgetView.setOnLongClickListener(this);
previewLayout.addView(widgetView);
}
backgroundImageView.setImageBitmap(processedBackgroundImage);
}

View File

@ -58,4 +58,12 @@ public class HybridHRWatchfaceWidget {
public int getPosY() {
return posY;
}
public void setPosX(int posX) {
this.posX = posX;
}
public void setPosY(int posY) {
this.posY = posY;
}
}

View File

@ -11,6 +11,7 @@
tools:context=".devices.qhybrid.HybridHRWatchfaceDesignerActivity">
<RelativeLayout
android:id="@+id/watchface_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -32,7 +33,7 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/watchface_preview_image"
android:id="@+id/watchface_preview_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"