Syle[control]: use consistent mapping dropdown

This commit is contained in:
Mathias-Boulay 2023-05-16 12:19:22 +02:00 committed by ArtDev
parent efca2c98c3
commit fd5f46f243
3 changed files with 274 additions and 171 deletions

View File

@ -20,7 +20,6 @@ import android.view.animation.Interpolator;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.Spinner; import android.widget.Spinner;
@ -45,56 +44,54 @@ import java.util.List;
* Class providing a sort of popup on top of a Layout, allowing to edit a given ControlButton * Class providing a sort of popup on top of a Layout, allowing to edit a given ControlButton
*/ */
public class EditControlPopup { public class EditControlPopup {
protected final Spinner[] mKeycodeSpinners = new Spinner[4];
private final DefocusableScrollView mScrollView; private final DefocusableScrollView mScrollView;
private ConstraintLayout mRootView;
private final ColorSelector mColorSelector; private final ColorSelector mColorSelector;
private final ObjectAnimator mEditPopupAnimator; private final ObjectAnimator mEditPopupAnimator;
private final ObjectAnimator mColorEditorAnimator; private final ObjectAnimator mColorEditorAnimator;
private boolean mDisplaying = false;
private boolean mDisplayingColor = false;
public boolean internalChanges = false; // True when we programmatically change stuff.
private ControlInterface mCurrentlyEditedButton;
private final int mMargin; private final int mMargin;
public boolean internalChanges = false; // True when we programmatically change stuff.
private final View.OnLayoutChangeListener mLayoutChangedListener = new View.OnLayoutChangeListener() { private final View.OnLayoutChangeListener mLayoutChangedListener = new View.OnLayoutChangeListener() {
@Override @Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
if(internalChanges) return; if (internalChanges) return;
internalChanges = true; internalChanges = true;
int width = (int)(safeParseFloat(mWidthEditText.getText().toString())); int width = (int) (safeParseFloat(mWidthEditText.getText().toString()));
if(width >= 0 && Math.abs(right - width) > 1){ if (width >= 0 && Math.abs(right - width) > 1) {
mWidthEditText.setText(String.valueOf(right - left)); mWidthEditText.setText(String.valueOf(right - left));
} }
int height = (int)(safeParseFloat(mHeightEditText.getText().toString())); int height = (int) (safeParseFloat(mHeightEditText.getText().toString()));
if(height >= 0 && Math.abs(bottom - height) > 1){ if (height >= 0 && Math.abs(bottom - height) > 1) {
mHeightEditText.setText(String.valueOf(bottom - top)); mHeightEditText.setText(String.valueOf(bottom - top));
} }
internalChanges = false; internalChanges = false;
} }
}; };
protected EditText mNameEditText, mWidthEditText, mHeightEditText; protected EditText mNameEditText, mWidthEditText, mHeightEditText;
@SuppressLint("UseSwitchCompatOrMaterialCode") @SuppressLint("UseSwitchCompatOrMaterialCode")
protected Switch mToggleSwitch, mPassthroughSwitch, mSwipeableSwitch; protected Switch mToggleSwitch, mPassthroughSwitch, mSwipeableSwitch;
protected Spinner mOrientationSpinner; protected Spinner mOrientationSpinner;
protected final Spinner[] mKeycodeSpinners = new Spinner[4]; protected TextView[] mKeycodeTextviews = new TextView[4];
protected SeekBar mStrokeWidthSeekbar, mCornerRadiusSeekbar, mAlphaSeekbar; protected SeekBar mStrokeWidthSeekbar, mCornerRadiusSeekbar, mAlphaSeekbar;
protected TextView mStrokePercentTextView, mCornerRadiusPercentTextView, mAlphaPercentTextView; protected TextView mStrokePercentTextView, mCornerRadiusPercentTextView, mAlphaPercentTextView;
protected TextView mSelectBackgroundColor, mSelectStrokeColor; protected TextView mSelectBackgroundColor, mSelectStrokeColor;
protected ArrayAdapter<String> mAdapter; protected ArrayAdapter<String> mAdapter;
protected List<String> mSpecialArray; protected List<String> mSpecialArray;
protected CheckBox mDisplayInGameCheckbox, mDisplayInMenuCheckbox; protected CheckBox mDisplayInGameCheckbox, mDisplayInMenuCheckbox;
private ConstraintLayout mRootView;
private boolean mDisplaying = false;
private boolean mDisplayingColor = false;
private ControlInterface mCurrentlyEditedButton;
// Decorative textviews // Decorative textviews
private TextView mOrientationTextView, mMappingTextView, mNameTextView, private TextView mOrientationTextView, mMappingTextView, mNameTextView,
mCornerRadiusTextView, mVisibilityTextView, mSizeTextview, mSizeXTextView; mCornerRadiusTextView, mVisibilityTextView, mSizeTextview, mSizeXTextView;
public EditControlPopup(Context context, ViewGroup parent) {
public EditControlPopup(Context context, ViewGroup parent){
mScrollView = (DefocusableScrollView) LayoutInflater.from(context).inflate(R.layout.dialog_control_button_setting, parent, false); mScrollView = (DefocusableScrollView) LayoutInflater.from(context).inflate(R.layout.dialog_control_button_setting, parent, false);
parent.addView(mScrollView); parent.addView(mScrollView);
@ -121,18 +118,23 @@ public class EditControlPopup {
setupRealTimeListeners(); setupRealTimeListeners();
} }
public static void setPercentageText(TextView textView, int progress) {
textView.setText(textView.getContext().getString(R.string.percent_format, progress));
}
/** Slide the layout into the visible screen area */ /**
public void appear(boolean fromRight){ * Slide the layout into the visible screen area
*/
public void appear(boolean fromRight) {
disappearColor(); // When someone jumps from a button to another disappearColor(); // When someone jumps from a button to another
if(fromRight){ if (fromRight) {
if(!mDisplaying || !isAtRight()){ if (!mDisplaying || !isAtRight()) {
mEditPopupAnimator.setFloatValues(currentDisplayMetrics.widthPixels, currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin); mEditPopupAnimator.setFloatValues(currentDisplayMetrics.widthPixels, currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin);
mEditPopupAnimator.start(); mEditPopupAnimator.start();
} }
}else{ } else {
if (!mDisplaying || isAtRight()){ if (!mDisplaying || isAtRight()) {
mEditPopupAnimator.setFloatValues(-mScrollView.getWidth(), mMargin); mEditPopupAnimator.setFloatValues(-mScrollView.getWidth(), mMargin);
mEditPopupAnimator.start(); mEditPopupAnimator.start();
} }
@ -141,12 +143,14 @@ public class EditControlPopup {
mDisplaying = true; mDisplaying = true;
} }
/** Slide out the layout */ /**
public void disappear(){ * Slide out the layout
if(!mDisplaying) return; */
public void disappear() {
if (!mDisplaying) return;
mDisplaying = false; mDisplaying = false;
if(isAtRight()) if (isAtRight())
mEditPopupAnimator.setFloatValues(currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin, currentDisplayMetrics.widthPixels); mEditPopupAnimator.setFloatValues(currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin, currentDisplayMetrics.widthPixels);
else else
mEditPopupAnimator.setFloatValues(mMargin, -mScrollView.getWidth()); mEditPopupAnimator.setFloatValues(mMargin, -mScrollView.getWidth());
@ -154,15 +158,17 @@ public class EditControlPopup {
mEditPopupAnimator.start(); mEditPopupAnimator.start();
} }
/** Slide the layout into the visible screen area */ /**
public void appearColor(boolean fromRight, int color){ * Slide the layout into the visible screen area
if(fromRight){ */
if(!mDisplayingColor || !isAtRight()){ public void appearColor(boolean fromRight, int color) {
if (fromRight) {
if (!mDisplayingColor || !isAtRight()) {
mColorEditorAnimator.setFloatValues(currentDisplayMetrics.widthPixels, currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin); mColorEditorAnimator.setFloatValues(currentDisplayMetrics.widthPixels, currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin);
mColorEditorAnimator.start(); mColorEditorAnimator.start();
} }
}else{ } else {
if (!mDisplayingColor || isAtRight()){ if (!mDisplayingColor || isAtRight()) {
mColorEditorAnimator.setFloatValues(-mScrollView.getWidth(), mMargin); mColorEditorAnimator.setFloatValues(-mScrollView.getWidth(), mMargin);
mColorEditorAnimator.start(); mColorEditorAnimator.start();
} }
@ -172,12 +178,14 @@ public class EditControlPopup {
mColorSelector.show(color == -1 ? Color.WHITE : color); mColorSelector.show(color == -1 ? Color.WHITE : color);
} }
/** Slide out the layout */ /**
public void disappearColor(){ * Slide out the layout
if(!mDisplayingColor) return; */
public void disappearColor() {
if (!mDisplayingColor) return;
mDisplayingColor = false; mDisplayingColor = false;
if(isAtRight()) if (isAtRight())
mColorEditorAnimator.setFloatValues(currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin, currentDisplayMetrics.widthPixels); mColorEditorAnimator.setFloatValues(currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin, currentDisplayMetrics.widthPixels);
else else
mColorEditorAnimator.setFloatValues(mMargin, -mScrollView.getWidth()); mColorEditorAnimator.setFloatValues(mMargin, -mScrollView.getWidth());
@ -185,33 +193,37 @@ public class EditControlPopup {
mColorEditorAnimator.start(); mColorEditorAnimator.start();
} }
/** Slide out the first visible layer. /**
* @return True if the last layer is disappearing */ * Slide out the first visible layer.
public boolean disappearLayer(){ *
if(mDisplayingColor){ * @return True if the last layer is disappearing
*/
public boolean disappearLayer() {
if (mDisplayingColor) {
disappearColor(); disappearColor();
return false; return false;
}else{ } else {
disappear(); disappear();
return true; return true;
} }
} }
/** Switch the panels position if needed */ /**
public void adaptPanelPosition(){ * Switch the panels position if needed
if(mDisplaying){ */
boolean isAtRight = mCurrentlyEditedButton.getControlView().getX() + mCurrentlyEditedButton.getControlView().getWidth()/2f < currentDisplayMetrics.widthPixels/2f; public void adaptPanelPosition() {
if (mDisplaying) {
boolean isAtRight = mCurrentlyEditedButton.getControlView().getX() + mCurrentlyEditedButton.getControlView().getWidth() / 2f < currentDisplayMetrics.widthPixels / 2f;
appear(isAtRight); appear(isAtRight);
} }
} }
public void destroy() {
public void destroy(){
((ViewGroup) mScrollView.getParent()).removeView(mColorSelector.getRootView()); ((ViewGroup) mScrollView.getParent()).removeView(mColorSelector.getRootView());
((ViewGroup) mScrollView.getParent()).removeView(mScrollView); ((ViewGroup) mScrollView.getParent()).removeView(mScrollView);
} }
private void loadAdapter(){ private void loadAdapter() {
//Initialize adapter for keycodes //Initialize adapter for keycodes
mAdapter = new ArrayAdapter<>(mRootView.getContext(), R.layout.item_centered_textview); mAdapter = new ArrayAdapter<>(mRootView.getContext(), R.layout.item_centered_textview);
mSpecialArray = ControlData.buildSpecialButtonArray(); mSpecialArray = ControlData.buildSpecialButtonArray();
@ -232,27 +244,22 @@ public class EditControlPopup {
mOrientationSpinner.setAdapter(adapter); mOrientationSpinner.setAdapter(adapter);
} }
private void setDefaultVisibilitySetting() {
for (int i = 0; i < mRootView.getChildCount(); ++i) {
private void setDefaultVisibilitySetting(){
for(int i=0; i<mRootView.getChildCount(); ++i){
mRootView.getChildAt(i).setVisibility(VISIBLE); mRootView.getChildAt(i).setVisibility(VISIBLE);
} }
} }
private boolean isAtRight(){ private boolean isAtRight() {
return mScrollView.getX() > currentDisplayMetrics.widthPixels/2f; return mScrollView.getX() > currentDisplayMetrics.widthPixels / 2f;
}
public static void setPercentageText(TextView textView, int progress){
textView.setText(textView.getContext().getString(R.string.percent_format, progress));
} }
/* LOADING VALUES */ /* LOADING VALUES */
/** Load values for basic control data */ /**
public void loadValues(ControlData data){ * Load values for basic control data
*/
public void loadValues(ControlData data) {
setDefaultVisibilitySetting(); setDefaultVisibilitySetting();
mOrientationTextView.setVisibility(GONE); mOrientationTextView.setVisibility(GONE);
mOrientationSpinner.setVisibility(GONE); mOrientationSpinner.setVisibility(GONE);
@ -261,11 +268,11 @@ public class EditControlPopup {
mWidthEditText.setText(String.valueOf(data.getWidth())); mWidthEditText.setText(String.valueOf(data.getWidth()));
mHeightEditText.setText(String.valueOf(data.getHeight())); mHeightEditText.setText(String.valueOf(data.getHeight()));
mAlphaSeekbar.setProgress((int) (data.opacity*100)); mAlphaSeekbar.setProgress((int) (data.opacity * 100));
mStrokeWidthSeekbar.setProgress(data.strokeWidth); mStrokeWidthSeekbar.setProgress(data.strokeWidth);
mCornerRadiusSeekbar.setProgress((int) data.cornerRadius); mCornerRadiusSeekbar.setProgress((int) data.cornerRadius);
setPercentageText(mAlphaPercentTextView, (int) (data.opacity*100)); setPercentageText(mAlphaPercentTextView, (int) (data.opacity * 100));
setPercentageText(mStrokePercentTextView, data.strokeWidth); setPercentageText(mStrokePercentTextView, data.strokeWidth);
setPercentageText(mCornerRadiusPercentTextView, (int) data.cornerRadius); setPercentageText(mCornerRadiusPercentTextView, (int) data.cornerRadius);
@ -276,7 +283,7 @@ public class EditControlPopup {
mDisplayInGameCheckbox.setChecked(data.displayInGame); mDisplayInGameCheckbox.setChecked(data.displayInGame);
mDisplayInMenuCheckbox.setChecked(data.displayInMenu); mDisplayInMenuCheckbox.setChecked(data.displayInMenu);
for(int i = 0; i< data.keycodes.length; i++){ for (int i = 0; i < data.keycodes.length; i++) {
if (data.keycodes[i] < 0) { if (data.keycodes[i] < 0) {
mKeycodeSpinners[i].setSelection(data.keycodes[i] + mSpecialArray.size()); mKeycodeSpinners[i].setSelection(data.keycodes[i] + mSpecialArray.size());
} else { } else {
@ -285,18 +292,20 @@ public class EditControlPopup {
} }
} }
/** Load values for extended control data */ /**
public void loadValues(ControlDrawerData data){ * Load values for extended control data
*/
public void loadValues(ControlDrawerData data) {
loadValues(data.properties); loadValues(data.properties);
mOrientationSpinner.setSelection( mOrientationSpinner.setSelection(
ControlDrawerData.orientationToInt(data.orientation)); ControlDrawerData.orientationToInt(data.orientation));
mMappingTextView.setVisibility(GONE); mMappingTextView.setVisibility(GONE);
mKeycodeSpinners[0].setVisibility(GONE); for (int i = 0; i < mKeycodeSpinners.length; i++) {
mKeycodeSpinners[1].setVisibility(GONE); mKeycodeSpinners[i].setVisibility(GONE);
mKeycodeSpinners[2].setVisibility(GONE); mKeycodeTextviews[i].setVisibility(GONE);
mKeycodeSpinners[3].setVisibility(GONE); }
mOrientationTextView.setVisibility(VISIBLE); mOrientationTextView.setVisibility(VISIBLE);
mOrientationSpinner.setVisibility(VISIBLE); mOrientationSpinner.setVisibility(VISIBLE);
@ -306,15 +315,17 @@ public class EditControlPopup {
mToggleSwitch.setVisibility(View.GONE); mToggleSwitch.setVisibility(View.GONE);
} }
/** Load values for the joystick */ /**
public void loadJoystickValues(ControlData data){ * Load values for the joystick
*/
public void loadJoystickValues(ControlData data) {
loadValues(data); loadValues(data);
mMappingTextView.setVisibility(GONE); mMappingTextView.setVisibility(GONE);
mKeycodeSpinners[0].setVisibility(GONE); for (int i = 0; i < mKeycodeSpinners.length; i++) {
mKeycodeSpinners[1].setVisibility(GONE); mKeycodeSpinners[i].setVisibility(GONE);
mKeycodeSpinners[2].setVisibility(GONE); mKeycodeTextviews[i].setVisibility(GONE);
mKeycodeSpinners[3].setVisibility(GONE); }
mNameTextView.setVisibility(GONE); mNameTextView.setVisibility(GONE);
mNameEditText.setVisibility(GONE); mNameEditText.setVisibility(GONE);
@ -328,8 +339,10 @@ public class EditControlPopup {
mToggleSwitch.setVisibility(View.GONE); mToggleSwitch.setVisibility(View.GONE);
} }
/** Load values for sub buttons */ /**
public void loadSubButtonValues(ControlData data){ * Load values for sub buttons
*/
public void loadSubButtonValues(ControlData data) {
loadValues(data); loadValues(data);
// Size linked to the parent drawer // Size linked to the parent drawer
@ -345,7 +358,7 @@ public class EditControlPopup {
} }
private void bindLayout(){ private void bindLayout() {
mRootView = mScrollView.findViewById(R.id.edit_layout); mRootView = mScrollView.findViewById(R.id.edit_layout);
mNameEditText = mScrollView.findViewById(R.id.editName_editText); mNameEditText = mScrollView.findViewById(R.id.editName_editText);
mWidthEditText = mScrollView.findViewById(R.id.editSize_editTextX); mWidthEditText = mScrollView.findViewById(R.id.editSize_editTextX);
@ -357,6 +370,10 @@ public class EditControlPopup {
mKeycodeSpinners[1] = mScrollView.findViewById(R.id.editMapping_spinner_2); mKeycodeSpinners[1] = mScrollView.findViewById(R.id.editMapping_spinner_2);
mKeycodeSpinners[2] = mScrollView.findViewById(R.id.editMapping_spinner_3); mKeycodeSpinners[2] = mScrollView.findViewById(R.id.editMapping_spinner_3);
mKeycodeSpinners[3] = mScrollView.findViewById(R.id.editMapping_spinner_4); mKeycodeSpinners[3] = mScrollView.findViewById(R.id.editMapping_spinner_4);
mKeycodeTextviews[0] = mScrollView.findViewById(R.id.mapping_1_textview);
mKeycodeTextviews[1] = mScrollView.findViewById(R.id.mapping_2_textview);
mKeycodeTextviews[2] = mScrollView.findViewById(R.id.mapping_3_textview);
mKeycodeTextviews[3] = mScrollView.findViewById(R.id.mapping_4_textview);
mOrientationSpinner = mScrollView.findViewById(R.id.editOrientation_spinner); mOrientationSpinner = mScrollView.findViewById(R.id.editOrientation_spinner);
mStrokeWidthSeekbar = mScrollView.findViewById(R.id.editStrokeWidth_seekbar); mStrokeWidthSeekbar = mScrollView.findViewById(R.id.editStrokeWidth_seekbar);
mCornerRadiusSeekbar = mScrollView.findViewById(R.id.editCornerRadius_seekbar); mCornerRadiusSeekbar = mScrollView.findViewById(R.id.editCornerRadius_seekbar);
@ -383,16 +400,19 @@ public class EditControlPopup {
* A long function linking all the displayed data on the popup and, * A long function linking all the displayed data on the popup and,
* the currently edited mCurrentlyEditedButton * the currently edited mCurrentlyEditedButton
*/ */
public void setupRealTimeListeners(){ public void setupRealTimeListeners() {
mNameEditText.addTextChangedListener(new TextWatcher() { mNameEditText.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {} public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().name = s.toString(); mCurrentlyEditedButton.getProperties().name = s.toString();
@ -403,16 +423,19 @@ public class EditControlPopup {
mWidthEditText.addTextChangedListener(new TextWatcher() { mWidthEditText.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {} public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if(internalChanges) return; if (internalChanges) return;
float width = safeParseFloat(s.toString()); float width = safeParseFloat(s.toString());
if(width >= 0){ if (width >= 0) {
mCurrentlyEditedButton.getProperties().setWidth(width); mCurrentlyEditedButton.getProperties().setWidth(width);
mCurrentlyEditedButton.updateProperties(); mCurrentlyEditedButton.updateProperties();
} }
@ -421,16 +444,19 @@ public class EditControlPopup {
mHeightEditText.addTextChangedListener(new TextWatcher() { mHeightEditText.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {} public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if(internalChanges) return; if (internalChanges) return;
float height = safeParseFloat(s.toString()); float height = safeParseFloat(s.toString());
if(height >= 0){ if (height >= 0) {
mCurrentlyEditedButton.getProperties().setHeight(height); mCurrentlyEditedButton.getProperties().setHeight(height);
mCurrentlyEditedButton.updateProperties(); mCurrentlyEditedButton.updateProperties();
} }
@ -438,66 +464,77 @@ public class EditControlPopup {
}); });
mSwipeableSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { mSwipeableSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().isSwipeable = isChecked; mCurrentlyEditedButton.getProperties().isSwipeable = isChecked;
}); });
mToggleSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { mToggleSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().isToggle = isChecked; mCurrentlyEditedButton.getProperties().isToggle = isChecked;
}); });
mPassthroughSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { mPassthroughSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().passThruEnabled = isChecked; mCurrentlyEditedButton.getProperties().passThruEnabled = isChecked;
}); });
mAlphaSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { mAlphaSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().opacity = mAlphaSeekbar.getProgress()/100f; mCurrentlyEditedButton.getProperties().opacity = mAlphaSeekbar.getProgress() / 100f;
mCurrentlyEditedButton.getControlView().setAlpha(mAlphaSeekbar.getProgress()/100f); mCurrentlyEditedButton.getControlView().setAlpha(mAlphaSeekbar.getProgress() / 100f);
setPercentageText(mAlphaPercentTextView, progress); setPercentageText(mAlphaPercentTextView, progress);
} }
@Override @Override
public void onStartTrackingTouch(SeekBar seekBar) {} public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) {} public void onStopTrackingTouch(SeekBar seekBar) {
}
}); });
mStrokeWidthSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { mStrokeWidthSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().strokeWidth = mStrokeWidthSeekbar.getProgress(); mCurrentlyEditedButton.getProperties().strokeWidth = mStrokeWidthSeekbar.getProgress();
mCurrentlyEditedButton.setBackground(); mCurrentlyEditedButton.setBackground();
setPercentageText(mStrokePercentTextView, progress); setPercentageText(mStrokePercentTextView, progress);
} }
@Override @Override
public void onStartTrackingTouch(SeekBar seekBar) {} public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) {} public void onStopTrackingTouch(SeekBar seekBar) {
}
}); });
mCornerRadiusSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { mCornerRadiusSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().cornerRadius = mCornerRadiusSeekbar.getProgress(); mCurrentlyEditedButton.getProperties().cornerRadius = mCornerRadiusSeekbar.getProgress();
mCurrentlyEditedButton.setBackground(); mCurrentlyEditedButton.setBackground();
setPercentageText(mCornerRadiusPercentTextView, progress); setPercentageText(mCornerRadiusPercentTextView, progress);
} }
@Override @Override
public void onStartTrackingTouch(SeekBar seekBar) {} public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) {} public void onStopTrackingTouch(SeekBar seekBar) {
}
}); });
for(int i = 0; i< mKeycodeSpinners.length; ++i){ for (int i = 0; i < mKeycodeSpinners.length; ++i) {
int finalI = i; int finalI = i;
mKeycodeTextviews[i].setOnClickListener(v -> mKeycodeSpinners[finalI].performClick());
mKeycodeSpinners[i].setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { mKeycodeSpinners[i].setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
@ -508,10 +545,12 @@ public class EditControlPopup {
} else { } else {
mCurrentlyEditedButton.getProperties().keycodes[finalI] = EfficientAndroidLWJGLKeycode.getValueByIndex(mKeycodeSpinners[finalI].getSelectedItemPosition() - mSpecialArray.size()); mCurrentlyEditedButton.getProperties().keycodes[finalI] = EfficientAndroidLWJGLKeycode.getValueByIndex(mKeycodeSpinners[finalI].getSelectedItemPosition() - mSpecialArray.size());
} }
mKeycodeTextviews[finalI].setText((String) mKeycodeSpinners[finalI].getSelectedItem());
} }
@Override @Override
public void onNothingSelected(AdapterView<?> parent) {} public void onNothingSelected(AdapterView<?> parent) {
}
}); });
} }
@ -522,23 +561,24 @@ public class EditControlPopup {
// Side note, spinner listeners are fired later than all the other ones. // Side note, spinner listeners are fired later than all the other ones.
// Meaning the internalChanges bool is useless here. // Meaning the internalChanges bool is useless here.
if(mCurrentlyEditedButton instanceof ControlDrawer){ if (mCurrentlyEditedButton instanceof ControlDrawer) {
((ControlDrawer)mCurrentlyEditedButton).drawerData.orientation = ControlDrawerData.intToOrientation(mOrientationSpinner.getSelectedItemPosition()); ((ControlDrawer) mCurrentlyEditedButton).drawerData.orientation = ControlDrawerData.intToOrientation(mOrientationSpinner.getSelectedItemPosition());
((ControlDrawer)mCurrentlyEditedButton).syncButtons(); ((ControlDrawer) mCurrentlyEditedButton).syncButtons();
} }
} }
@Override @Override
public void onNothingSelected(AdapterView<?> parent) {} public void onNothingSelected(AdapterView<?> parent) {
}
}); });
mDisplayInGameCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { mDisplayInGameCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().displayInGame = isChecked; mCurrentlyEditedButton.getProperties().displayInGame = isChecked;
}); });
mDisplayInMenuCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { mDisplayInMenuCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(internalChanges) return; if (internalChanges) return;
mCurrentlyEditedButton.getProperties().displayInMenu = isChecked; mCurrentlyEditedButton.getProperties().displayInMenu = isChecked;
}); });
@ -561,18 +601,18 @@ public class EditControlPopup {
}); });
} }
private float safeParseFloat(String string){ private float safeParseFloat(String string) {
float out = -1; // -1 float out = -1; // -1
try { try {
out = Float.parseFloat(string); out = Float.parseFloat(string);
}catch (NumberFormatException e){ } catch (NumberFormatException e) {
Log.e("EditControlPopup", e.toString()); Log.e("EditControlPopup", e.toString());
} }
return out; return out;
} }
public void setCurrentlyEditedButton(ControlInterface button){ public void setCurrentlyEditedButton(ControlInterface button) {
if(mCurrentlyEditedButton != null) if (mCurrentlyEditedButton != null)
mCurrentlyEditedButton.getControlView().removeOnLayoutChangeListener(mLayoutChangedListener); mCurrentlyEditedButton.getControlView().removeOnLayoutChangeListener(mLayoutChangedListener);
mCurrentlyEditedButton = button; mCurrentlyEditedButton = button;
mCurrentlyEditedButton.getControlView().addOnLayoutChangeListener(mLayoutChangedListener); mCurrentlyEditedButton.getControlView().addOnLayoutChangeListener(mLayoutChangedListener);

View File

@ -3,9 +3,9 @@
android:shape="rectangle"> android:shape="rectangle">
<corners android:radius="@dimen/_8sdp" /> <corners android:radius="@dimen/_8sdp" />
<padding <padding
android:bottom="2dp" android:bottom="@dimen/_2sdp"
android:left="2dp" android:left="@dimen/_2sdp"
android:right="2dp" android:right="@dimen/_2sdp"
android:top="2dp" /> android:top="@dimen/_2sdp" />
<solid android:color="@color/background_app" /> <solid android:color="@color/background_app" />
</shape> </shape>

View File

@ -56,7 +56,7 @@
<EditText <EditText
android:id="@+id/editSize_editTextX" android:id="@+id/editSize_editTextX"
android:layout_width="@dimen/_138sdp" android:layout_width="@dimen/_134sdp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:imeOptions="flagNoExtractUi" android:imeOptions="flagNoExtractUi"
@ -104,20 +104,83 @@
<Spinner <Spinner
android:id="@+id/editMapping_spinner_1" android:id="@+id/editMapping_spinner_1"
android:layout_width="0dp" android:layout_width="1px"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_marginTop="@dimen/_2sdp"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:dropDownWidth="@dimen/_267sdp"
android:dropDownVerticalOffset="30dp"
android:gravity="center" android:gravity="center"
app:layout_constraintBottom_toTopOf="@id/editMapping_spinner_3" app:layout_constraintBottom_toTopOf="@id/editMapping_spinner_3"
app:layout_constraintEnd_toStartOf="@id/editMapping_spinner_2"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editMapping_textView" app:layout_constraintTop_toBottomOf="@+id/editMapping_textView" />
app:layout_constraintVertical_chainStyle="spread" />
<Spinner
android:id="@+id/editMapping_spinner_2"
android:layout_width="1px"
android:layout_height="30dp"
android:background="@android:color/transparent"
android:dropDownWidth="@dimen/_267sdp"
android:dropDownHorizontalOffset="30dp"
android:dropDownVerticalOffset="30dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="@+id/editMapping_spinner_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/editMapping_spinner_1" />
<Spinner
android:id="@+id/editMapping_spinner_3"
android:layout_width="1px"
android:layout_height="30dp"
android:background="@android:color/transparent"
android:dropDownWidth="@dimen/_267sdp"
android:dropDownVerticalOffset="30dp"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editMapping_spinner_1" />
<Spinner
android:id="@+id/editMapping_spinner_4"
android:layout_width="1px"
android:layout_height="30dp"
android:background="@android:color/transparent"
android:dropDownWidth="@dimen/_267sdp"
android:dropDownVerticalOffset="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editMapping_spinner_2" />
<!-- Clickable textview linked to the spinners
Spinners are hidden at the same place because the dropdown offset doesn't work
Do those textview acts as the spinner idle state
-->
<TextView
android:id="@+id/mapping_1_textview"
style="?android:attr/spinnerItemStyle"
android:layout_width="0dp"
android:layout_height="@dimen/_30sdp"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:textAlignment="inherit"
app:layout_constraintEnd_toStartOf="@id/mapping_2_textview"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editMapping_textView"
tools:text="HELLO" />
<TextView <TextView
android:id="@+id/editMapping_plus_1" android:id="@+id/editMapping_plus_1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -125,47 +188,42 @@
android:gravity="center" android:gravity="center"
android:text="+" android:text="+"
app:layout_constraintBottom_toBottomOf="@+id/editMapping_spinner_1" app:layout_constraintBottom_toBottomOf="@+id/mapping_1_textview"
app:layout_constraintEnd_toEndOf="@+id/editMapping_spinner_1" app:layout_constraintEnd_toEndOf="@+id/mapping_1_textview"
app:layout_constraintTop_toTopOf="@+id/editMapping_spinner_1" /> app:layout_constraintStart_toEndOf="@id/mapping_1_textview"
app:layout_constraintTop_toTopOf="@+id/mapping_1_textview" />
<Spinner
android:id="@+id/editMapping_spinner_2"
android:layout_width="0dp"
android:layout_height="30dp"
android:background="@android:color/transparent"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="@+id/editMapping_spinner_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/editMapping_spinner_1"
app:layout_constraintTop_toTopOf="@+id/editMapping_spinner_1" />
<TextView <TextView
android:id="@+id/editMapping_plus_2" android:id="@+id/mapping_2_textview"
android:layout_width="wrap_content" style="?android:attr/spinnerItemStyle"
android:layout_height="0dp"
android:gravity="center"
android:text="+"
app:layout_constraintBottom_toBottomOf="@id/editMapping_textView"
app:layout_constraintEnd_toEndOf="@id/editMapping_textView"
app:layout_constraintTop_toTopOf="@id/editMapping_spinner_3"
/>
<Spinner
android:id="@+id/editMapping_spinner_3"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="30dp" android:layout_height="@dimen/_30sdp"
android:background="@android:color/transparent" android:ellipsize="marquee"
android:gravity="center" android:gravity="center"
android:singleLine="true"
android:textAlignment="inherit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/mapping_1_textview"
app:layout_constraintEnd_toStartOf="@id/editMapping_spinner_4" app:layout_constraintTop_toTopOf="@+id/mapping_1_textview"
tools:text="HELLO" />
<TextView
android:id="@+id/mapping_3_textview"
style="?android:attr/spinnerItemStyle"
android:layout_width="0dp"
android:layout_height="@dimen/_30sdp"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:textAlignment="inherit"
app:layout_constraintEnd_toStartOf="@id/mapping_4_textview"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editMapping_spinner_1" /> app:layout_constraintTop_toBottomOf="@id/mapping_1_textview"
tools:text="HELLO" />
<TextView <TextView
android:id="@+id/editMapping_plus_3" android:id="@+id/editMapping_plus_3"
@ -175,21 +233,26 @@
android:text="+" android:text="+"
app:layout_constraintBottom_toBottomOf="@+id/editMapping_spinner_3" app:layout_constraintBottom_toBottomOf="@+id/mapping_3_textview"
app:layout_constraintEnd_toEndOf="@+id/editMapping_spinner_3" app:layout_constraintEnd_toEndOf="@+id/mapping_3_textview"
app:layout_constraintTop_toBottomOf="@+id/editMapping_spinner_1" /> app:layout_constraintStart_toEndOf="@id/mapping_3_textview"
app:layout_constraintTop_toBottomOf="@+id/mapping_1_textview" />
<Spinner <TextView
android:id="@+id/editMapping_spinner_4" android:id="@+id/mapping_4_textview"
style="?android:attr/spinnerItemStyle"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="30dp" android:layout_height="@dimen/_30sdp"
android:background="@android:color/transparent" android:ellipsize="marquee"
android:gravity="center" android:gravity="center"
android:singleLine="true"
android:textAlignment="inherit"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/editMapping_spinner_3" app:layout_constraintStart_toEndOf="@id/mapping_3_textview"
app:layout_constraintTop_toBottomOf="@id/editMapping_spinner_2" /> app:layout_constraintTop_toTopOf="@id/mapping_3_textview"
tools:text="HELLO" />
<!-- ORIENTATION SECTION --> <!-- ORIENTATION SECTION -->