mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-19 00:56:57 -04:00
Changes
- Experimental autoscale for control buttons. - [Custom control] Implements dynamic position.
This commit is contained in:
@@ -30,9 +30,10 @@ import net.kdt.pojavlaunch.*;
|
||||
import android.view.View.OnClickListener;
|
||||
import net.kdt.pojavlaunch.customcontrols.*;
|
||||
import android.support.v7.app.*;
|
||||
import android.content.res.*;
|
||||
|
||||
public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListener {
|
||||
private static final int POPUP_TEXT_LAYOUT = getInternalId("layout", "text_edit_action_popup_text");
|
||||
private final int POPUP_TEXT_LAYOUT = getInternalId("layout", "text_edit_action_popup_text");
|
||||
private TextView mEditTextView;
|
||||
private TextView mDeleteTextView;
|
||||
|
||||
@@ -40,37 +41,12 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
super(handleView);
|
||||
}
|
||||
|
||||
private static 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();
|
||||
}
|
||||
|
||||
// If unable to find in com.android.internal.R, go find in android.R
|
||||
for (Class perType : android.R.class.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
private int getInternalId(String type, String name) {
|
||||
int id = Resources.getSystem().getIdentifier(name, type, "com.android.internal.R");
|
||||
if (id == 0) {
|
||||
mHandleView.getContext().getResources().getIdentifier(name, type, "android");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,7 +140,29 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
|
||||
final CheckBox checkHidden = dialog.findViewById(R.id.controlsetting_checkbox_hidden);
|
||||
checkHidden.setChecked(properties.hidden);
|
||||
|
||||
final CheckBox checkDynamicPos = dialog.findViewById(R.id.controlsetting_checkbox_hidden);
|
||||
checkDynamicPos.setChecked(properties.isDynamicBtn);
|
||||
|
||||
final LinearLayout layoutDynamicBtn = dialog.findViewById(R.id.controlsetting_dynamicbtnlayout);
|
||||
|
||||
final EditText editDynamicX = dialog.findViewById(R.id.controlsetting_edit_dynamicpos_x);
|
||||
final EditText editDynamicY = dialog.findViewById(R.id.controlsetting_edit_dynamicpos_y);
|
||||
|
||||
editDynamicX.setHint(Float.toString(properties.x));
|
||||
editDynamicX.setText(properties.dynamicX);
|
||||
|
||||
editDynamicY.setHint(Float.toString(properties.y));
|
||||
editDynamicY.setText(properties.dynamicY);
|
||||
|
||||
checkDynamicPos.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton btn, boolean checked) {
|
||||
layoutDynamicBtn.setVisibility(checked ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@@ -180,6 +178,15 @@ 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);
|
||||
} if (properties.dynamicY.isEmpty()) {
|
||||
properties.dynamicY = Float.toString(properties.y);
|
||||
}
|
||||
|
||||
mHandleView.mView.updateProperties();
|
||||
|
||||
|
||||
@@ -1104,8 +1104,8 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
|
||||
|
||||
protected Button findButton(int id) {
|
||||
Button button = (Button) findViewById(id);
|
||||
button.setWidth((int) Tools.dpToPx(this, Tools.pxToDp(this, button.getWidth()) * LauncherPreferences.PREF_BUTTONSIZE));
|
||||
button.setHeight((int) Tools.dpToPx(this, Tools.pxToDp(this, button.getHeight()) * LauncherPreferences.PREF_BUTTONSIZE));
|
||||
button.setWidth((int) (button.getWidth() * LauncherPreferences.PREF_BUTTONSIZE));
|
||||
button.setHeight((int) (button.getHeight() * LauncherPreferences.PREF_BUTTONSIZE));
|
||||
button.setOnTouchListener(this);
|
||||
button.setFocusable(false);
|
||||
button.setFocusableInTouchMode(false);
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.apache.commons.compress.archivers.tar.*;
|
||||
import org.apache.commons.compress.compressors.xz.*;
|
||||
import org.apache.commons.io.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
public class PojavLoginActivity extends AppCompatActivity
|
||||
// MineActivity
|
||||
@@ -61,6 +62,7 @@ public class PojavLoginActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
Tools.updateWindowSize(this);
|
||||
|
||||
ControlData.pixelOf2dp = (int) Tools.dpToPx(this, 2);
|
||||
ControlData.pixelOf30dp = (int) Tools.dpToPx(this, 30);
|
||||
ControlData.pixelOf50dp = (int) Tools.dpToPx(this, 50);
|
||||
|
||||
@@ -345,7 +345,9 @@ public final class Tools
|
||||
}
|
||||
|
||||
public static float dpToPx(Context ctx, float dp) {
|
||||
return (dp * ctx.getResources().getDisplayMetrics().density);
|
||||
// 921600 = 1280 * 720, default scale
|
||||
float scaledDp = dp / 921600 * CallbackBridge.windowWidth * CallbackBridge.windowHeight;
|
||||
return (scaledDp * ctx.getResources().getDisplayMetrics().density);
|
||||
}
|
||||
|
||||
public static void copyAssetFile(Context ctx, String fileName, String output, boolean overwrite) throws Exception
|
||||
|
||||
@@ -10,138 +10,140 @@ import android.view.ViewGroup.*;
|
||||
|
||||
public class ControlButton extends Button implements OnLongClickListener, OnTouchListener
|
||||
{
|
||||
private GestureDetector mGestureDetector;
|
||||
private ControlData mProperties;
|
||||
private SelectionEndHandleView mHandleView;
|
||||
|
||||
private boolean mCanModify = false;
|
||||
private boolean mCanTriggerLongClick = true;
|
||||
|
||||
public ControlButton(Context ctx, ControlData properties) {
|
||||
super(ctx);
|
||||
|
||||
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
|
||||
|
||||
setBackgroundResource(R.drawable.control_button);
|
||||
|
||||
setOnLongClickListener(this);
|
||||
setOnTouchListener(this);
|
||||
|
||||
setProperties(properties);
|
||||
|
||||
mHandleView = new SelectionEndHandleView(this);
|
||||
}
|
||||
|
||||
public HandleView getHandleView() {
|
||||
return mHandleView;
|
||||
}
|
||||
private GestureDetector mGestureDetector;
|
||||
private ControlData mProperties;
|
||||
private SelectionEndHandleView mHandleView;
|
||||
|
||||
public ControlData getProperties() {
|
||||
return mProperties;
|
||||
}
|
||||
|
||||
public void setProperties(ControlData properties) {
|
||||
setProperties(properties, true);
|
||||
}
|
||||
|
||||
public void setProperties(ControlData properties, boolean changePos) {
|
||||
mProperties = properties;
|
||||
private boolean mCanModify = false;
|
||||
private boolean mCanTriggerLongClick = true;
|
||||
|
||||
public ControlButton(Context ctx, ControlData properties) {
|
||||
super(ctx);
|
||||
|
||||
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
|
||||
|
||||
setBackgroundResource(R.drawable.control_button);
|
||||
|
||||
setOnLongClickListener(this);
|
||||
setOnTouchListener(this);
|
||||
|
||||
setProperties(properties);
|
||||
|
||||
mHandleView = new SelectionEndHandleView(this);
|
||||
}
|
||||
|
||||
public HandleView getHandleView() {
|
||||
return mHandleView;
|
||||
}
|
||||
|
||||
public ControlData getProperties() {
|
||||
return mProperties;
|
||||
}
|
||||
|
||||
public void setProperties(ControlData properties) {
|
||||
setProperties(properties, true);
|
||||
}
|
||||
|
||||
public void setProperties(ControlData properties, boolean changePos) {
|
||||
mProperties = properties;
|
||||
properties.update();
|
||||
|
||||
// com.android.internal.R.string.delete
|
||||
// android.R.string.
|
||||
setText(properties.name);
|
||||
if (changePos) {
|
||||
setTranslationX(moveX = properties.x);
|
||||
setTranslationY(moveY = properties.y);
|
||||
}
|
||||
|
||||
if (properties.specialButtonListener == null) {
|
||||
|
||||
// com.android.internal.R.string.delete
|
||||
// android.R.string.
|
||||
setText(properties.name);
|
||||
if (changePos) {
|
||||
setTranslationX(moveX = properties.x);
|
||||
setTranslationY(moveY = properties.y);
|
||||
}
|
||||
|
||||
if (properties.specialButtonListener == null) {
|
||||
// A non-special button or inside custom controls screen so skip listener
|
||||
} else if (properties.specialButtonListener instanceof View.OnClickListener) {
|
||||
setOnClickListener((View.OnClickListener) properties.specialButtonListener);
|
||||
} else if (properties.specialButtonListener instanceof View.OnTouchListener) {
|
||||
setOnTouchListener((View.OnTouchListener) properties.specialButtonListener);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Field " + ControlData.class.getName() + ".specialButtonListener must be View.OnClickListener or View.OnTouchListener, but is " + properties.specialButtonListener.getClass().getName());
|
||||
}
|
||||
|
||||
setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height));
|
||||
}
|
||||
setOnClickListener((View.OnClickListener) properties.specialButtonListener);
|
||||
} else if (properties.specialButtonListener instanceof View.OnTouchListener) {
|
||||
setOnTouchListener((View.OnTouchListener) properties.specialButtonListener);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Field " + ControlData.class.getName() + ".specialButtonListener must be View.OnClickListener or View.OnTouchListener, but is " + properties.specialButtonListener.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayoutParams(ViewGroup.LayoutParams params)
|
||||
{
|
||||
super.setLayoutParams(params);
|
||||
|
||||
mProperties.width = params.width;
|
||||
mProperties.height = params.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTranslationX(float x)
|
||||
{
|
||||
super.setTranslationX(x);
|
||||
mProperties.x = x;
|
||||
}
|
||||
setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTranslationY(float y) {
|
||||
super.setTranslationY(y);
|
||||
mProperties.y = y;
|
||||
}
|
||||
|
||||
public void updateProperties() {
|
||||
setProperties(mProperties);
|
||||
}
|
||||
@Override
|
||||
public void setLayoutParams(ViewGroup.LayoutParams params)
|
||||
{
|
||||
super.setLayoutParams(params);
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View p1)
|
||||
{
|
||||
if (!mCanTriggerLongClick) return false;
|
||||
mProperties.width = params.width;
|
||||
mProperties.height = params.height;
|
||||
}
|
||||
|
||||
if (mHandleView.isShowing()) {
|
||||
mHandleView.hide();
|
||||
} else {
|
||||
if (getParent() != null) {
|
||||
((ControlLayout) getParent()).hideAllHandleViews();
|
||||
}
|
||||
mHandleView.show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private float moveX, moveY;
|
||||
private float downX, downY;
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (!mCanModify) {
|
||||
mCanTriggerLongClick = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mCanTriggerLongClick = true;
|
||||
downX = event.getX();
|
||||
downY = event.getY();
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
mCanTriggerLongClick = false;
|
||||
moveX += event.getX() - downX;
|
||||
moveY += event.getY() - downY;
|
||||
|
||||
setTranslationX(moveX);
|
||||
setTranslationY(moveY);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setModifiable(boolean z) {
|
||||
mCanModify = z;
|
||||
}
|
||||
@Override
|
||||
public void setTranslationX(float x) {
|
||||
super.setTranslationX(x);
|
||||
mProperties.x = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTranslationY(float y) {
|
||||
super.setTranslationY(y);
|
||||
mProperties.y = y;
|
||||
}
|
||||
|
||||
public void updateProperties() {
|
||||
setProperties(mProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View p1)
|
||||
{
|
||||
if (!mCanTriggerLongClick) return false;
|
||||
|
||||
if (mHandleView.isShowing()) {
|
||||
mHandleView.hide();
|
||||
} else {
|
||||
if (getParent() != null) {
|
||||
((ControlLayout) getParent()).hideAllHandleViews();
|
||||
}
|
||||
mHandleView.show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private float moveX, moveY;
|
||||
private float downX, downY;
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (!mCanModify) {
|
||||
mCanTriggerLongClick = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mCanTriggerLongClick = true;
|
||||
downX = event.getX();
|
||||
downY = event.getY();
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
mCanTriggerLongClick = false;
|
||||
moveX += event.getX() - downX;
|
||||
moveY += event.getY() - downY;
|
||||
|
||||
if (!mProperties.isDynamicBtn) {
|
||||
setTranslationX(moveX);
|
||||
setTranslationY(moveY);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setModifiable(boolean z) {
|
||||
mCanModify = z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class ControlData implements Cloneable
|
||||
* bigger device or vice versa.
|
||||
*/
|
||||
public String dynamicX, dynamicY;
|
||||
public boolean isDynamicBtn;
|
||||
|
||||
public static ControlData[] getSpecialButtons(){
|
||||
if (SPECIAL_BUTTONS == null) {
|
||||
@@ -98,6 +99,7 @@ public class ControlData implements Cloneable
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.isDynamicBtn = false;
|
||||
}
|
||||
|
||||
public ControlData(String name, int keycode, String dynamicX, String dynamicY) {
|
||||
@@ -116,6 +118,7 @@ public class ControlData implements Cloneable
|
||||
this(name, keycode, 0, 0, width, height);
|
||||
this.dynamicX = dynamicX;
|
||||
this.dynamicY = dynamicY;
|
||||
this.isDynamicBtn = true;
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -132,7 +135,7 @@ public class ControlData implements Cloneable
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (dynamicX == null || dynamicY == null) {
|
||||
if (!isDynamicBtn) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ static jint launchJVM(int argc, char** argv) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: com_oracle_embedded_launcher_VMLauncher
|
||||
* Class: com_oracle_dalvik_VMLauncher
|
||||
* Method: launchJVM
|
||||
* Signature: ([Ljava/lang/String;)I
|
||||
*/
|
||||
@@ -109,7 +109,7 @@ JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env,
|
||||
|
||||
res = launchJVM(argc, argv);
|
||||
|
||||
LOGD("Freeing args");
|
||||
LOGD("Going to free args");
|
||||
free_char_array(env, argsArray, argv);
|
||||
|
||||
LOGD("Free done");
|
||||
|
||||
@@ -32,13 +32,49 @@
|
||||
android:singleLine="true"
|
||||
android:id="@+id/controlsetting_edit_name"/>
|
||||
|
||||
<CheckBox
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/customctrl_hidden"
|
||||
android:id="@+id/controlsetting_checkbox_hidden"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/customctrl_hidden"
|
||||
android:id="@+id/controlsetting_checkbox_hidden"/>
|
||||
|
||||
<CheckBox
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/customctrl_dynamicpos"
|
||||
android:id="@+id/controlsetting_checkbox_dynamicpos"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/controlsetting_dynamicbtnlayout">
|
||||
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/customctrl_dynamicpos_x"/>
|
||||
|
||||
<EditText
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:singleLine="true"
|
||||
android:id="@+id/controlsetting_edit_dynamicpos_x"/>
|
||||
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/customctrl_dynamicpos_y"/>
|
||||
|
||||
<EditText
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:singleLine="true"
|
||||
android:id="@+id/controlsetting_edit_dynamicpos_y"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -189,6 +189,9 @@
|
||||
<string name="customctrl_keyname">Keycode</string>
|
||||
<string name="customctrl_specialkey">Special Key</string>
|
||||
<string name="customctrl_hidden">Hidden</string>
|
||||
<string name="customctrl_dynamicpos">Dynamic position</string>
|
||||
<string name="customctrl_dynamicpos_x">Dynamic X</string>
|
||||
<string name="customctrl_dynamicpos_y">Dynamic Y</string>
|
||||
<string name="customctrl_addbutton">Add button</string>
|
||||
<string name="customctrl_selectdefault">Select default Control json</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user