Make use of the OOP to clean up ControlLayout.

This commit is contained in:
SerpentSpirale 2021-06-30 22:55:47 +02:00
parent 0479e13f6e
commit fed34eedf9
3 changed files with 42 additions and 31 deletions

View File

@ -59,47 +59,20 @@ public class ControlLayout extends FrameLayout
//CONTROL BUTTON //CONTROL BUTTON
for (ControlData button : controlLayout.mControlDataList) { 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); addControlView(button);
} }
//CONTROL DRAWER //CONTROL DRAWER
for(ControlDrawerData drawerData : controlLayout.mDrawerDataList){ 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); ControlDrawer drawer = addDrawerView(drawerData);
if(mModifiable) drawer.areButtonsVisible = true;
//CONTROL SUB BUTTON //CONTROL SUB BUTTON
for (ControlData subButton : drawerData.buttonProperties){ 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); addSubView(drawer, subButton);
} }
} }
mLayout.scaledAt = LauncherPreferences.PREF_BUTTONSIZE; mLayout.scaledAt = LauncherPreferences.PREF_BUTTONSIZE;
setModified(false); setModified(false);
@ -218,6 +191,10 @@ public class ControlLayout extends FrameLayout
setControlVisible(mControlVisible); setControlVisible(mControlVisible);
} }
public float getLayoutScale(){
return mLayout.scaledAt;
}
public void setControlVisible(boolean isVisible) { public void setControlVisible(boolean isVisible) {
if (mModifiable) return; // Not using on custom controls activity if (mModifiable) return; // Not using on custom controls activity

View File

@ -1,5 +1,6 @@
package net.kdt.pojavlaunch.customcontrols.buttons; package net.kdt.pojavlaunch.customcontrols.buttons;
import android.annotation.SuppressLint;
import android.graphics.*; import android.graphics.*;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.util.*; import android.util.*;
@ -11,8 +12,11 @@ import net.kdt.pojavlaunch.customcontrols.ControlData;
import net.kdt.pojavlaunch.customcontrols.ControlLayout; import net.kdt.pojavlaunch.customcontrols.ControlLayout;
import net.kdt.pojavlaunch.customcontrols.handleview.*; import net.kdt.pojavlaunch.customcontrols.handleview.*;
import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.*;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import org.lwjgl.glfw.*; import org.lwjgl.glfw.*;
@SuppressLint("ViewConstructor")
public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener
{ {
private Paint mRectPaint; private Paint mRectPaint;
@ -34,15 +38,18 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
mGestureDetector = new GestureDetector(getContext(), new SingleTapConfirm()); mGestureDetector = new GestureDetector(getContext(), new SingleTapConfirm());
setOnLongClickListener(this); 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); setModified(false);
mHandleView = new SelectionEndHandleView(this); mHandleView = new SelectionEndHandleView(this);
//For the toggle layer
final TypedValue value = new TypedValue(); final TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(R.attr.colorAccent, value, true); getContext().getTheme().resolveAttribute(R.attr.colorAccent, value, true);
mRectPaint = new Paint(); mRectPaint = new Paint();
mRectPaint.setColor(value.data); mRectPaint.setColor(value.data);
mRectPaint.setAlpha(128); mRectPaint.setAlpha(128);
@ -60,6 +67,24 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
setProperties(properties, true); 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) { public void setProperties(ControlData properties, boolean changePos) {
mProperties = properties; mProperties = properties;

View File

@ -1,5 +1,6 @@
package net.kdt.pojavlaunch.customcontrols.buttons; package net.kdt.pojavlaunch.customcontrols.buttons;
import android.annotation.SuppressLint;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,6 +14,7 @@ import java.util.ArrayList;
@SuppressLint("ViewConstructor")
public class ControlDrawer extends ControlButton { public class ControlDrawer extends ControlButton {
@ -115,6 +117,13 @@ public class ControlDrawer extends ControlButton {
resizeButtons(); resizeButtons();
} }
@Override
public ControlData preProcessProperties(ControlData properties, ControlLayout layout) {
ControlData data = super.preProcessProperties(properties, layout);
data.isHideable = true;
return data;
}
@Override @Override
public void setVisible(boolean isVisible) { public void setVisible(boolean isVisible) {
//TODO replicate changes to his children ? //TODO replicate changes to his children ?