control button size directly edit #480

This commit is contained in:
ShirosakiMio 2024-08-03 09:28:18 +08:00
parent 42460e4b08
commit 456e0b6222
7 changed files with 183 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.ScrollView;
import android.widget.Toast;
@ -17,7 +18,9 @@ import com.google.android.material.tabs.TabLayout;
import com.tungsten.fcl.R;
import com.tungsten.fcl.control.data.ButtonStyles;
import com.tungsten.fcl.control.data.ControlButtonStyle;
import com.tungsten.fcl.ui.manage.EditDialog;
import com.tungsten.fclcore.fakefx.beans.binding.Bindings;
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
import com.tungsten.fclcore.util.StringUtils;
import com.tungsten.fcllibrary.component.dialog.FCLColorPickerDialog;
import com.tungsten.fcllibrary.component.dialog.FCLDialog;
@ -87,6 +90,10 @@ public class AddButtonStyleDialog extends FCLDialog implements View.OnClickListe
FCLTextView strokeWidthText = normalStyleLayout.findViewById(R.id.stroke_width_text);
FCLTextView cornerRadiusText = normalStyleLayout.findViewById(R.id.corner_radius_text);
textSizeText.setOnClickListener(v -> openTextEditDialog(context, textSize.progressProperty(), false));
strokeWidthText.setOnClickListener(v -> openTextEditDialog(context, strokeWidth.progressProperty(), true));
cornerRadiusText.setOnClickListener(v -> openTextEditDialog(context, cornerRadius.progressProperty(), true));
textSize.setProgress(style.getTextSize());
strokeWidth.setProgress(style.getStrokeWidth());
cornerRadius.setProgress(style.getCornerRadius());
@ -197,6 +204,10 @@ public class AddButtonStyleDialog extends FCLDialog implements View.OnClickListe
FCLTextView strokeWidthText = pressedStyleLayout.findViewById(R.id.stroke_width_text);
FCLTextView cornerRadiusText = pressedStyleLayout.findViewById(R.id.corner_radius_text);
textSizeText.setOnClickListener(v -> openTextEditDialog(context, textSize.progressProperty(), false));
strokeWidthText.setOnClickListener(v -> openTextEditDialog(context, strokeWidth.progressProperty(), true));
cornerRadiusText.setOnClickListener(v -> openTextEditDialog(context, cornerRadius.progressProperty(), true));
textSize.setProgress(style.getTextSizePressed());
strokeWidth.setProgress(style.getStrokeWidthPressed());
cornerRadius.setProgress(style.getCornerRadiusPressed());
@ -373,4 +384,20 @@ public class AddButtonStyleDialog extends FCLDialog implements View.OnClickListe
public void onTabReselected(TabLayout.Tab tab) {
}
private void openTextEditDialog(Context context, IntegerProperty property, boolean isPercentage) {
EditDialog dialog = new EditDialog(context, s -> {
if (s.matches("\\d+(\\.\\d+)?$")) {
float progress = Float.parseFloat(s);
if (isPercentage) {
progress = progress > 100 ? 100 : progress;
property.set((int) (progress * 10));
} else {
property.set((int) progress);
}
}
});
dialog.getEditText().setInputType(EditorInfo.TYPE_NUMBER_FLAG_DECIMAL);
dialog.show();
}
}

View File

@ -3,6 +3,7 @@ package com.tungsten.fcl.control;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.ScrollView;
import android.widget.Toast;
@ -16,8 +17,10 @@ import com.tungsten.fcl.control.data.ControlButtonStyle;
import com.tungsten.fcl.control.data.ControlDirectionStyle;
import com.tungsten.fcl.control.data.DirectionStyles;
import com.tungsten.fcl.control.view.ControlDirection;
import com.tungsten.fcl.ui.manage.EditDialog;
import com.tungsten.fcl.util.FXUtils;
import com.tungsten.fclcore.fakefx.beans.binding.Bindings;
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
import com.tungsten.fclcore.util.StringUtils;
import com.tungsten.fcllibrary.component.dialog.FCLColorPickerDialog;
import com.tungsten.fcllibrary.component.dialog.FCLDialog;
@ -95,6 +98,8 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
FCLTextView intervalText = buttonStyleLayout.findViewById(R.id.interval_text);
intervalText.setOnClickListener(v -> openTextEditDialog(context, interval.progressProperty(), true));
interval.setProgress(style.getButtonStyle().getInterval());
style.getButtonStyle().intervalProperty().bindBidirectional(interval.progressProperty());
@ -152,6 +157,12 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
FCLTextView strokeWidthText = rockerStyleLayout.findViewById(R.id.stroke_width_text);
FCLTextView cornerRadiusText = rockerStyleLayout.findViewById(R.id.corner_radius_text);
rockerSizeText.setOnClickListener(v -> openTextEditDialog(context, rockerSize.progressProperty(), true));
bgStrokeWidthText.setOnClickListener(v -> openTextEditDialog(context, bgStrokeWidth.progressProperty(), true));
bgCornerRadiusText.setOnClickListener(v -> openTextEditDialog(context, bgCornerRadius.progressProperty(), true));
strokeWidthText.setOnClickListener(v -> openTextEditDialog(context, strokeWidth.progressProperty(), true));
cornerRadiusText.setOnClickListener(v -> openTextEditDialog(context, cornerRadius.progressProperty(), true));
rockerSize.setProgress(style.getRockerStyle().getRockerSize());
bgStrokeWidth.setProgress(style.getRockerStyle().getBgStrokeWidth());
bgCornerRadius.setProgress(style.getRockerStyle().getBgCornerRadius());
@ -324,4 +335,20 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
dismiss();
}
}
private void openTextEditDialog(Context context, IntegerProperty property, boolean isPercentage) {
EditDialog dialog = new EditDialog(context, s -> {
if (s.matches("\\d+(\\.\\d+)?$")) {
float progress = Float.parseFloat(s);
if (isPercentage) {
progress = progress > 100 ? 100 : progress;
property.set((int) (progress * 10));
} else {
property.set((int) progress);
}
}
});
dialog.getEditText().setInputType(EditorInfo.TYPE_NUMBER_FLAG_DECIMAL);
dialog.show();
}
}

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
@ -18,10 +19,12 @@ 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.ui.manage.EditDialog;
import com.tungsten.fcl.util.AndroidUtils;
import com.tungsten.fcl.util.FXUtils;
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
import com.tungsten.fclcore.fakefx.beans.binding.Bindings;
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
import com.tungsten.fclcore.fakefx.collections.FXCollections;
import com.tungsten.fclcore.fakefx.collections.ObservableList;
import com.tungsten.fcllibrary.component.dialog.FCLDialog;
@ -169,6 +172,9 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
FCLTextView xPositionText = findInfoView(R.id.x_position_text);
FCLTextView yPositionText = findInfoView(R.id.y_position_text);
xPositionText.setOnClickListener(v -> openTextEditDialog(context, xPosition.progressProperty(), true));
yPositionText.setOnClickListener(v -> openTextEditDialog(context, yPosition.progressProperty(), true));
xPosition.setProgress(data.getBaseInfo().getXPosition());
yPosition.setProgress(data.getBaseInfo().getYPosition());
data.getBaseInfo().xPositionProperty().bindBidirectional(xPosition.progressProperty());
@ -225,6 +231,9 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
FCLTextView widthText = findInfoView(R.id.width_text);
FCLTextView heightText = findInfoView(R.id.height_text);
widthText.setOnClickListener(v -> openTextEditDialog(context, width.progressProperty(), false));
heightText.setOnClickListener(v -> openTextEditDialog(context, height.progressProperty(), false));
if (data.getBaseInfo().getSizeType() == BaseInfoData.SizeType.PERCENTAGE) {
width.setMax(1000);
height.setMax(1000);
@ -409,6 +418,22 @@ public class EditViewDialog extends FCLDialog implements View.OnClickListener {
public final <T extends View> T findEventView(int id) {
return eventLayout.findViewById(id);
}
private void openTextEditDialog(Context context, IntegerProperty property, boolean isPercentage) {
EditDialog dialog = new EditDialog(context, s -> {
if (s.matches("\\d+(\\.\\d+)?$")) {
float progress = Float.parseFloat(s);
if (isPercentage) {
progress = progress > 100 ? 100 : progress;
property.set((int) (progress * 10));
} else {
property.set((int) progress);
}
}
});
dialog.getEditText().setInputType(EditorInfo.TYPE_NUMBER_FLAG_DECIMAL);
dialog.show();
}
}
private static class EditDirectionDetails implements Details {

View File

@ -0,0 +1,55 @@
package com.tungsten.fcl.ui.manage;
import android.content.Context;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.tungsten.fcl.R;
import com.tungsten.fclcore.util.FutureCallback;
import com.tungsten.fcllibrary.component.dialog.FCLDialog;
import com.tungsten.fcllibrary.component.view.FCLButton;
import com.tungsten.fcllibrary.component.view.FCLEditText;
import java.util.function.Consumer;
public class EditDialog extends FCLDialog implements View.OnClickListener {
private final Consumer<String> callback;
private FCLEditText editText;
private FCLButton positive;
private FCLButton negative;
public EditDialog(@NonNull Context context, Consumer<String> callback) {
super(context);
this.callback = callback;
setCancelable(false);
setContentView(R.layout.dialog_edit);
editText = findViewById(R.id.name);
positive = findViewById(R.id.positive);
negative = findViewById(R.id.negative);
positive.setOnClickListener(this);
negative.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == positive) {
String s = editText.getText().toString();
if (!s.trim().equals("")) {
callback.accept(s);
dismiss();
}
}
if (v == negative) {
dismiss();
}
}
public FCLEditText getEditText() {
return editText;
}
}

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="10dp">
<com.tungsten.fcllibrary.component.view.FCLTextView
android:id="@+id/title"
android:text="@string/edit"
android:textSize="16sp"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.5"/>
<com.tungsten.fcllibrary.component.view.FCLEditText
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:singleLine="true"
android:id="@+id/name"
android:textSize="14sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintBottom_toTopOf="@+id/positive"/>
<com.tungsten.fcllibrary.component.view.FCLButton
android:id="@+id/positive"
android:text="@string/dialog_positive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.tungsten.fcllibrary.component.view.FCLButton
android:id="@+id/negative"
android:text="@string/dialog_negative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -907,4 +907,5 @@
<string name="menu_settings_gamepad_aimzone">辅助瞄准区</string>
<string name="account_failed_expired">凭据已过期,请删除账户重新登录。</string>
<string name="install_apk">安装apk文件</string>
<string name="edit">编辑</string>
</resources>

View File

@ -951,5 +951,6 @@
<string name="world_time">EEE, MMM d, yyyy HH:mm:ss</string>
<string name="install_apk">Install .apk</string>
<string name="edit">Edit</string>
</resources>