Add ControlButton cloning feature

This commit is contained in:
SerpentSpirale 2021-08-24 16:03:25 +02:00 committed by ArtDev
parent c435db640a
commit 3ef21ba5be
5 changed files with 21 additions and 8 deletions

View File

@ -133,7 +133,7 @@ public class ControlData implements Cloneable
this.dynamicY = dynamicY; this.dynamicY = dynamicY;
this.width = width; this.width = width;
this.height = height; this.height = height;
this.isDynamicBtn = true; this.isDynamicBtn = false;
this.isToggle = isToggle; this.isToggle = isToggle;
this.opacity = opacity; this.opacity = opacity;
this.bgColor = bgColor; this.bgColor = bgColor;

View File

@ -41,12 +41,13 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
private TextView mEditTextView; private TextView mEditTextView;
private TextView mDeleteTextView; private TextView mDeleteTextView;
private TextView mCloneTextView;
private Object editedButton; private ControlButton editedButton;
public ActionPopupWindow(HandleView handleView, Object object){ public ActionPopupWindow(HandleView handleView, ControlButton button){
super(handleView); super(handleView);
this.editedButton = object; this.editedButton = button;
} }
@Override @Override
@ -79,6 +80,12 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
mContentView.addView(mDeleteTextView); mContentView.addView(mDeleteTextView);
mDeleteTextView.setText(R.string.global_remove); mDeleteTextView.setText(R.string.global_remove);
mDeleteTextView.setOnClickListener(this); mDeleteTextView.setOnClickListener(this);
mCloneTextView = (TextView) inflater.inflate(R.layout.control_action_popup_text, null);
mCloneTextView.setLayoutParams(wrapContent);
mContentView.addView(mCloneTextView);
mCloneTextView.setText(R.string.global_clone);
mCloneTextView.setOnClickListener(this);
} }
@Override @Override
@ -132,6 +139,11 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
}); });
alertBuilder.setNegativeButton(android.R.string.cancel, null); alertBuilder.setNegativeButton(android.R.string.cancel, null);
alertBuilder.show(); alertBuilder.show();
}else if(view == mCloneTextView) {
ControlData cloneData = editedButton.getProperties().clone();
cloneData.dynamicX = "0.5 * ${screen_width}";
cloneData.dynamicY = "0.5 * ${screen_height}";
((ControlLayout) mHandleView.mView.getParent()).addControlButton(cloneData);
} }
hide(); hide();

View File

@ -189,9 +189,9 @@ public abstract class HandleView extends View implements ViewPositionListener, V
getPositionListener().removeSubscriber(this); getPositionListener().removeSubscriber(this);
} }
void showActionPopupWindow(int delay, Object object) { void showActionPopupWindow(int delay, ControlButton button) {
if (mActionPopupWindow == null) { if (mActionPopupWindow == null) {
mActionPopupWindow = new ActionPopupWindow(this, object); mActionPopupWindow = new ActionPopupWindow(this, button);
} }
if (mActionPopupShower == null) { if (mActionPopupShower == null) {
mActionPopupShower = new Runnable() { mActionPopupShower = new Runnable() {

View File

@ -50,9 +50,9 @@ public class SelectionEndHandleView extends HandleView
return 0; // mView.getSelectionEnd(); return 0; // mView.getSelectionEnd();
} }
public void show(Object object){ public void show(ControlButton button){
super.show(); super.show();
showActionPopupWindow(0, object); showActionPopupWindow(0, button);
} }
@Override @Override

View File

@ -118,6 +118,7 @@
<string name="global_load">Load</string> <string name="global_load">Load</string>
<string name="global_name">Name</string> <string name="global_name">Name</string>
<string name="global_remove">Remove</string> <string name="global_remove">Remove</string>
<string name="global_clone">Clone</string>
<string name="global_restart">Restart</string> <string name="global_restart">Restart</string>
<string name="global_save">Save</string> <string name="global_save">Save</string>
<string name="global_unpacking">Unpacking %s</string> <string name="global_unpacking">Unpacking %s</string>