mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -04:00
[Custom controls] Changes
- Fixes color in popup window. - Catch error when could not calculate dynamic position.
This commit is contained in:
parent
e1154efe6e
commit
84e178194f
@ -31,6 +31,7 @@ import android.view.View.OnClickListener;
|
||||
import net.kdt.pojavlaunch.customcontrols.*;
|
||||
import android.support.v7.app.*;
|
||||
import android.content.res.*;
|
||||
import net.objecthunter.exp4j.*;
|
||||
|
||||
public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListener {
|
||||
private TextView mEditTextView;
|
||||
@ -51,7 +52,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
LinearLayout linearLayout = new LinearLayout(mHandleView.getContext());
|
||||
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
mContentView = linearLayout;
|
||||
mContentView.setBackgroundResource(Resources.getSystem().getIdentifier("text_edit_paste_window", "drawable", "com.android.internal"));
|
||||
mContentView.setBackgroundResource(R.drawable.control_side_action_window);
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) mHandleView.getContext().
|
||||
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
@ -114,7 +115,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
if (properties.keycode < 0) {
|
||||
spinnerKeycode.setSelection(properties.keycode + specialArr.length);
|
||||
} else {
|
||||
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.keycode));
|
||||
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.keycode) + specialArr.length);
|
||||
}
|
||||
spinnerKeycode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
|
||||
|
||||
@ -162,6 +163,34 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
if (editName.getText().toString().isEmpty()) {
|
||||
editName.setError(view.getResources().getString(R.string.global_error_field_empty));
|
||||
} else {
|
||||
/*
|
||||
String errorAt = null;
|
||||
try {
|
||||
errorAt = "DynamicX";
|
||||
properties.insertDynamicPos(editDynamicX.getText().toString());
|
||||
errorAt = "DynamicY";
|
||||
properties.insertDynamicPos(editDynamicY.getText().toString());
|
||||
} catch (Throwable th) {
|
||||
Error e = new Error(errorAt, th);
|
||||
e.setStackTrace(null);
|
||||
Tools.showError(view.getContext(), e);
|
||||
return;
|
||||
}
|
||||
errorAt = null;
|
||||
*/
|
||||
|
||||
int errorAt = 0;
|
||||
try {
|
||||
properties.insertDynamicPos(editDynamicX.getText().toString());
|
||||
errorAt = 1;
|
||||
properties.insertDynamicPos(editDynamicY.getText().toString());
|
||||
} catch (Throwable th) {
|
||||
(errorAt == 0 ? editDynamicX : editDynamicY)
|
||||
.setError(th.getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (spinnerKeycode.getSelectedItemPosition() < specialArr.length) {
|
||||
properties.keycode = spinnerKeycode.getSelectedItemPosition() - specialArr.length;
|
||||
} else {
|
||||
@ -170,8 +199,6 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
properties.name = editName.getText().toString();
|
||||
properties.hidden = checkHidden.isChecked();
|
||||
properties.isDynamicBtn = checkDynamicPos.isChecked();
|
||||
properties.dynamicX = editDynamicX.getText().toString();
|
||||
properties.dynamicY = editDynamicY.getText().toString();
|
||||
|
||||
if (properties.dynamicX.isEmpty()) {
|
||||
properties.dynamicX = Float.toString(properties.x);
|
||||
|
@ -73,25 +73,6 @@ public abstract class HandleView extends View implements ViewPositionListener, V
|
||||
return mPositionListener;
|
||||
}
|
||||
|
||||
private int getInternalId(String type, String name) {
|
||||
try {
|
||||
for (Class perType : Class.forName("com.android.internal.R").getDeclaredClasses()) {
|
||||
if (perType.getSimpleName().equals(type)) {
|
||||
try {
|
||||
Field f = perType.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
return (int) f.get(null);
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public HandleView(ControlButton view) {
|
||||
super(view.getContext());
|
||||
|
||||
@ -100,7 +81,7 @@ public abstract class HandleView extends View implements ViewPositionListener, V
|
||||
mDownWidth = view.getLayoutParams().width;
|
||||
mDownHeight = view.getLayoutParams().height;
|
||||
|
||||
mContainer = new PopupWindow(view.getContext(), null, getInternalId("attr", "textSelectHandleWindowStyle"));
|
||||
mContainer = new PopupWindow(view.getContext(), null, android.R.attr.textSelectHandleWindowStyle);
|
||||
mContainer.setSplitTouchEnabled(true);
|
||||
mContainer.setClippingEnabled(false);
|
||||
mContainer.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
|
||||
@ -108,7 +89,7 @@ public abstract class HandleView extends View implements ViewPositionListener, V
|
||||
|
||||
mDrawableLtr = view.getContext().getDrawable(R.drawable.text_select_handle_left_material);
|
||||
mDrawableRtl = view.getContext().getDrawable(R.drawable.text_select_handle_right_material);
|
||||
mMinSize = view.getContext().getResources().getDimensionPixelSize(getInternalId("dimen", "text_handle_min_size"));
|
||||
mMinSize = view.getContext().getResources().getDimensionPixelSize(R.dimen.text_handle_min_size);
|
||||
|
||||
setOnLongClickListener(this);
|
||||
|
||||
|
@ -138,17 +138,7 @@ public class ControlData implements Cloneable
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (keycode < 0 && SPECIAL_BUTTONS != null) {
|
||||
for (ControlData data : getSpecialButtons()) {
|
||||
if (keycode == data.keycode) {
|
||||
specialButtonListener = data.specialButtonListener;
|
||||
}
|
||||
}
|
||||
} if (!isDynamicBtn) {
|
||||
return;
|
||||
}
|
||||
|
||||
public float insertDynamicPos(String dynamicPos) {
|
||||
// Values in the map below may be always changed
|
||||
Map<String, String> keyValueMap = new ArrayMap<>();
|
||||
keyValueMap.put("top", "0");
|
||||
@ -160,21 +150,30 @@ public class ControlData implements Cloneable
|
||||
keyValueMap.put("screen_width", Integer.toString(CallbackBridge.windowWidth));
|
||||
keyValueMap.put("screen_height", Integer.toString(CallbackBridge.windowHeight));
|
||||
keyValueMap.put("margin", Integer.toString(pixelOf2dp));
|
||||
|
||||
// Insert JSON values to variables
|
||||
String insertedX = JSONUtils.insertSingleJSONValue(dynamicX, keyValueMap);
|
||||
String insertedY = JSONUtils.insertSingleJSONValue(dynamicY, keyValueMap);
|
||||
|
||||
// Calculate and save, because the dynamic position contains some math equations
|
||||
x = calculate(insertedX);
|
||||
y = calculate(insertedY);
|
||||
|
||||
// Insert value to ${variable}
|
||||
String insertedPos = JSONUtils.insertSingleJSONValue(dynamicPos, keyValueMap);
|
||||
|
||||
// Calculate, because the dynamic position contains some math equations
|
||||
return calculate(insertedPos);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (keycode < 0 && SPECIAL_BUTTONS != null) {
|
||||
for (ControlData data : getSpecialButtons()) {
|
||||
if (keycode == data.keycode) {
|
||||
specialButtonListener = data.specialButtonListener;
|
||||
}
|
||||
}
|
||||
} if (!isDynamicBtn) {
|
||||
return;
|
||||
}
|
||||
|
||||
x = insertDynamicPos(dynamicX);
|
||||
y = insertDynamicPos(dynamicX);
|
||||
}
|
||||
|
||||
private static float calculate(String math) {
|
||||
// try {
|
||||
return (float) new ExpressionBuilder(math).build().evaluate();
|
||||
/* } catch (e) {
|
||||
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
BIN
app/src/main/res/drawable/control_side_action_window.9.png
Normal file
BIN
app/src/main/res/drawable/control_side_action_window.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 488 B |
@ -1,10 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<dimen name="text_handle_min_size">40dp</dimen>
|
||||
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
|
||||
|
||||
<!-- Padding -->
|
||||
<dimen name="padding_tiny">2dp</dimen>
|
||||
<dimen name="padding_tiny_plus_one">3dp</dimen>
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
<!-- Hint -->
|
||||
<string name="hint_select_account">To select, click it. To delete an account, hold it.</string>
|
||||
<string name="hint_control_mapping">"This feature is not yet finished so can't apply custom control at the moment!\nSwipe from right to left to open menu ◀\nHold a button to customize: edit, resize or delete."</string>
|
||||
<string name="hint_control_mapping">"Swipe from right to left to open menu ◀\nHold a button to customize: edit, resize or delete."</string>
|
||||
|
||||
<!-- Warning -->
|
||||
<string name="warning_title">Warning</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user