mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 15:48:26 -04:00
Make use of the OOP to clean up ControlLayout.
This commit is contained in:
parent
0479e13f6e
commit
fed34eedf9
@ -59,47 +59,20 @@ public class ControlLayout extends FrameLayout
|
||||
|
||||
//CONTROL BUTTON
|
||||
for (ControlData button : controlLayout.mControlDataList) {
|
||||
button.isHideable = button.keycodes[0] != ControlData.SPECIALBTN_TOGGLECTRL && button.keycodes[0] != ControlData.SPECIALBTN_VIRTUALMOUSE;
|
||||
button.setWidth(button.getWidth() / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
button.setHeight(button.getHeight() / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
if (!button.isDynamicBtn) {
|
||||
button.dynamicX = button.x / CallbackBridge.physicalWidth + " * ${screen_width}";
|
||||
button.dynamicY = button.y / CallbackBridge.physicalHeight + " * ${screen_height}";
|
||||
}
|
||||
button.update();
|
||||
addControlView(button);
|
||||
}
|
||||
|
||||
//CONTROL DRAWER
|
||||
for(ControlDrawerData drawerData : controlLayout.mDrawerDataList){
|
||||
drawerData.properties.isHideable = true;
|
||||
drawerData.properties.setWidth(drawerData.properties.getWidth() / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
drawerData.properties.setHeight(drawerData.properties.getHeight() / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
if (!drawerData.properties.isDynamicBtn) {
|
||||
drawerData.properties.dynamicX = drawerData.properties.x / CallbackBridge.physicalWidth + " * ${screen_width}";
|
||||
drawerData.properties.dynamicY = drawerData.properties.y / CallbackBridge.physicalHeight + " * ${screen_height}";
|
||||
}
|
||||
|
||||
ControlDrawer drawer = addDrawerView(drawerData);
|
||||
if(mModifiable) drawer.areButtonsVisible = true;
|
||||
|
||||
//CONTROL SUB BUTTON
|
||||
for (ControlData subButton : drawerData.buttonProperties){
|
||||
subButton.isHideable = subButton.keycodes[0] != ControlData.SPECIALBTN_TOGGLECTRL && subButton.keycodes[0] != ControlData.SPECIALBTN_VIRTUALMOUSE;
|
||||
subButton.setWidth(subButton.getWidth() / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
subButton.setHeight(subButton.getHeight() / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
if (!subButton.isDynamicBtn) {
|
||||
subButton.dynamicX = subButton.x / CallbackBridge.physicalWidth + " * ${screen_width}";
|
||||
subButton.dynamicY = subButton.y / CallbackBridge.physicalHeight + " * ${screen_height}";
|
||||
}
|
||||
subButton.update();
|
||||
addSubView(drawer, subButton);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
mLayout.scaledAt = LauncherPreferences.PREF_BUTTONSIZE;
|
||||
|
||||
setModified(false);
|
||||
@ -218,6 +191,10 @@ public class ControlLayout extends FrameLayout
|
||||
setControlVisible(mControlVisible);
|
||||
}
|
||||
|
||||
public float getLayoutScale(){
|
||||
return mLayout.scaledAt;
|
||||
}
|
||||
|
||||
public void setControlVisible(boolean isVisible) {
|
||||
if (mModifiable) return; // Not using on custom controls activity
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.kdt.pojavlaunch.customcontrols.buttons;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.*;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.util.*;
|
||||
@ -11,8 +12,11 @@ import net.kdt.pojavlaunch.customcontrols.ControlData;
|
||||
import net.kdt.pojavlaunch.customcontrols.ControlLayout;
|
||||
import net.kdt.pojavlaunch.customcontrols.handleview.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener
|
||||
{
|
||||
private Paint mRectPaint;
|
||||
@ -34,15 +38,18 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
||||
mGestureDetector = new GestureDetector(getContext(), new SingleTapConfirm());
|
||||
|
||||
setOnLongClickListener(this);
|
||||
//When a button is created, the width/height has yet to be processed to fit the scaling.
|
||||
|
||||
setProperties(properties);
|
||||
setProperties(preProcessProperties(properties, layout));
|
||||
setModified(false);
|
||||
|
||||
mHandleView = new SelectionEndHandleView(this);
|
||||
|
||||
|
||||
|
||||
//For the toggle layer
|
||||
final TypedValue value = new TypedValue();
|
||||
getContext().getTheme().resolveAttribute(R.attr.colorAccent, value, true);
|
||||
|
||||
|
||||
mRectPaint = new Paint();
|
||||
mRectPaint.setColor(value.data);
|
||||
mRectPaint.setAlpha(128);
|
||||
@ -60,6 +67,24 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
||||
setProperties(properties, true);
|
||||
}
|
||||
|
||||
public ControlData preProcessProperties(ControlData properties, ControlLayout layout){
|
||||
//Size
|
||||
properties.setWidth(properties.getWidth() / layout.getLayoutScale() * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
properties.setHeight(properties.getHeight() / layout.getLayoutScale() * LauncherPreferences.PREF_BUTTONSIZE);
|
||||
|
||||
//Visibility
|
||||
properties.isHideable = properties.keycodes[0] != ControlData.SPECIALBTN_TOGGLECTRL && properties.keycodes[0] != ControlData.SPECIALBTN_VIRTUALMOUSE;
|
||||
|
||||
//Position
|
||||
if (!properties.isDynamicBtn) {
|
||||
properties.dynamicX = properties.x / CallbackBridge.physicalWidth + " * ${screen_width}";
|
||||
properties.dynamicY = properties.y / CallbackBridge.physicalHeight + " * ${screen_height}";
|
||||
}
|
||||
|
||||
properties.update();
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(ControlData properties, boolean changePos) {
|
||||
mProperties = properties;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.kdt.pojavlaunch.customcontrols.buttons;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -13,6 +14,7 @@ import java.util.ArrayList;
|
||||
|
||||
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
public class ControlDrawer extends ControlButton {
|
||||
|
||||
|
||||
@ -115,6 +117,13 @@ public class ControlDrawer extends ControlButton {
|
||||
resizeButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControlData preProcessProperties(ControlData properties, ControlLayout layout) {
|
||||
ControlData data = super.preProcessProperties(properties, layout);
|
||||
data.isHideable = true;
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean isVisible) {
|
||||
//TODO replicate changes to his children ?
|
||||
|
Loading…
x
Reference in New Issue
Block a user