Skip to content

Commit

Permalink
change delete view to EditViewDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirosakiMio committed Mar 8, 2024
1 parent 127b85a commit ec6acfb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.tungsten.fcl.control.data.ControlViewGroup;
import com.tungsten.fcl.control.data.CustomControl;
import com.tungsten.fcl.control.data.DirectionEventData;
import com.tungsten.fcl.control.view.ControlButton;
import com.tungsten.fcl.util.AndroidUtils;
import com.tungsten.fcl.util.FXUtils;
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
Expand Down Expand Up @@ -49,13 +50,15 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
private FCLButton positive;
private FCLButton negative;
private FCLButton clone;
private FCLButton delete;

private FCLLinearLayout container;
private Details details;

public interface Callback {
void onPositive(CustomControl view);
void onClone(CustomControl view);
default void onDelete(){}
}

public EditViewDialog(@NonNull Context context, CustomControl cloneView, GameMenu menu, Callback callback, boolean cloneable) {
Expand All @@ -75,9 +78,11 @@ public EditViewDialog(@NonNull Context context, CustomControl cloneView, GameMen
positive = findViewById(R.id.positive);
negative = findViewById(R.id.negative);
clone = findViewById(R.id.clone);
delete = findViewById(R.id.delete);
positive.setOnClickListener(this);
negative.setOnClickListener(this);
clone.setOnClickListener(this);
delete.setOnClickListener(this);

clone.setVisibility(cloneable ? View.VISIBLE : View.GONE);

Expand All @@ -102,6 +107,10 @@ public void onClick(View v) {
callback.onClone(customControl.cloneView());
dismiss();
}
if (v == delete) {
callback.onDelete();
dismiss();
}
if (v == positive) {
callback.onPositive(details.getView());
dismiss();
Expand Down
25 changes: 5 additions & 20 deletions FCL/src/main/java/com/tungsten/fcl/control/view/ControlButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,6 @@ protected void onDraw(Canvas canvas) {

private final Handler handler = new Handler();
private final Runnable runnable = () -> handleLongPressEvent(!longPressEvent);
private final Runnable deleteRunnable = () -> {
Vibrator vibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE));
FCLAlertDialog.Builder builder = new FCLAlertDialog.Builder(getContext());
builder.setAlertLevel(FCLAlertDialog.AlertLevel.ALERT);
builder.setCancelable(false);
builder.setMessage(getContext().getString(R.string.edit_button_delete));
builder.setPositiveButton(this::deleteView);
builder.setNegativeButton(() -> {
setX(positionX);
setY(positionY);
});
builder.create().show();
};

private void deleteView() {
if (menu != null) {
menu.getViewManager().removeView(getData());
Expand All @@ -304,7 +289,6 @@ public boolean onTouchEvent(MotionEvent event) {
positionX = getX();
positionY = getY();
downTime = System.currentTimeMillis();
handler.postDelayed(deleteRunnable, 400);
break;
case MotionEvent.ACTION_MOVE:
int deltaX = (int) (event.getX() - downX);
Expand All @@ -313,17 +297,13 @@ public boolean onTouchEvent(MotionEvent event) {
float targetY = Math.max(0, Math.min(screenHeight - getHeight(), getY() + deltaY));
setX(targetX);
setY(targetY);
if ((Math.abs(event.getX() - downX) > 2 || Math.abs(event.getY() - downY) > 2) && System.currentTimeMillis() - downTime < 400) {
handler.removeCallbacks(deleteRunnable);
}
autoFitPosition();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
removeLine(0);
removeLine(1);
setNormalStyle();
handler.removeCallbacks(deleteRunnable);
if (System.currentTimeMillis() - downTime <= 100
&& Math.abs(event.getX() - downX) <= 10
&& Math.abs(event.getY() - downY) <= 10) {
Expand All @@ -344,6 +324,11 @@ public void onPositive(CustomControl view) {
public void onClone(CustomControl view) {
menu.getViewManager().addView(view);
}

@Override
public void onDelete() {
menu.getViewManager().removeView(getData());
}
}, true);
dialog.show();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,6 @@ protected void onDraw(Canvas canvas) {
private boolean startRecord = false;

private final Handler handler = new Handler();
private final Runnable deleteRunnable = () -> {
Vibrator vibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE));
FCLAlertDialog.Builder builder = new FCLAlertDialog.Builder(getContext());
builder.setAlertLevel(FCLAlertDialog.AlertLevel.ALERT);
builder.setCancelable(false);
builder.setMessage(getContext().getString(R.string.edit_direction_delete));
builder.setPositiveButton(this::deleteView);
builder.setNegativeButton(() -> {
setX(positionX);
setY(positionY);
});
builder.create().show();
};

private void deleteView() {
if (menu != null) {
Expand All @@ -456,7 +442,6 @@ public boolean onTouchEvent(MotionEvent event) {
positionX = getX();
positionY = getY();
downTime = System.currentTimeMillis();
handler.postDelayed(deleteRunnable, 400);
break;
case MotionEvent.ACTION_MOVE:
int deltaX = (int) ((event.getX() - downX) * menu.getMenuSetting().getMouseSensitivity());
Expand All @@ -465,16 +450,12 @@ public boolean onTouchEvent(MotionEvent event) {
float targetY = Math.max(0, Math.min(screenHeight - getSize(), getY() + deltaY));
setX(targetX);
setY(targetY);
if ((Math.abs(event.getX() - downX) > 2 || Math.abs(event.getY() - downY) > 2) && System.currentTimeMillis() - downTime < 400) {
handler.removeCallbacks(deleteRunnable);
}
autoFitPosition();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
removeLine(0);
removeLine(1);
handler.removeCallbacks(deleteRunnable);
if (System.currentTimeMillis() - downTime <= 100
&& Math.abs(event.getX() - downX) <= 10
&& Math.abs(event.getY() - downY) <= 10) {
Expand All @@ -494,6 +475,11 @@ public void onPositive(CustomControl view) {
public void onClone(CustomControl view) {
menu.getViewManager().addView(view);
}

@Override
public void onDelete() {
menu.getViewManager().removeView(getData());
}
}, true);
dialog.show();
} else {
Expand Down
10 changes: 10 additions & 0 deletions FCL/src/main/res/layout/dialog_edit_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/delete"
app:layout_constraintBottom_toBottomOf="parent"/>

<com.tungsten.fcllibrary.component.view.FCLButton
android:id="@+id/delete"
android:text="@string/edit_view_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintStart_toEndOf="@id/clone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

Expand Down
1 change: 1 addition & 0 deletions FCL/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
<string name="download_provider_mirror">尽量使用镜像源</string>

<string name="edit_view_clone">复制控件</string>
<string name="edit_view_delete">删除控件</string>
<string name="edit_view_event">控件事件</string>
<string name="edit_view_info">控件基本信息</string>
<string name="edit_view_no_group">请先添加或选择一个控件组!</string>
Expand Down
1 change: 1 addition & 0 deletions FCL/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
<string name="download_provider_mirror">From Mirror</string>

<string name="edit_view_clone">Clone View</string>
<string name="edit_view_delete">Delete View</string>
<string name="edit_view_event">View Event</string>
<string name="edit_view_info">Base View Info</string>
<string name="edit_view_no_group">Please add or select a view group first!</string>
Expand Down

0 comments on commit ec6acfb

Please sign in to comment.