Skip to content

Commit c72ad23

Browse files
committed
fix for uiPager sort/search, added PageDataModel & some fields refractors for GamePadButtons & the speedometer
1 parent b0b930d commit c72ad23

File tree

15 files changed

+332
-312
lines changed

15 files changed

+332
-312
lines changed

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/gamePad/ControlButtonsView.java

+93-64
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,68 @@
1515
import android.view.ViewGroup;
1616
import android.widget.ImageView;
1717
import android.widget.RelativeLayout;
18-
1918
import com.scrappers.GamePad.R;
20-
2119
import androidx.annotation.NonNull;
2220
import androidx.annotation.Nullable;
2321
import androidx.appcompat.app.AppCompatActivity;
2422
import androidx.core.content.ContextCompat;
2523

2624
public class ControlButtonsView extends RelativeLayout {
27-
public static final int GAMEPAD_BUTTON_X = 'X';
28-
public static final int GAMEPAD_BUTTON_Y = 'Y';
29-
public static final int GAMEPAD_BUTTON_A = 'A';
30-
public static final int GAMEPAD_BUTTON_B = 'B';
31-
public static final int DEFAULT_GAMEPAD_DOMAIN=R.drawable.gamepad_domain;
32-
public static final int DEFAULT_COLOR_STICK_DOMAIN=R.drawable.moving_stick_domain;
33-
public static final int FLIPPED_COLOR_STICK_DOMAIN=R.drawable.moving_stick_flipped_domain;
34-
public static final int OPACIFIED_COLOR_STICK_DOMAIN=R.drawable.opacified_domain;
35-
public static final int NOTHING_IMAGE=R.drawable.nothing;
36-
public static final int DEFAULT_BUTTONS=R.drawable.moving_stick;
37-
public static final int CRYSTAL_BUTTONS= R.drawable.crystal_buttons;
38-
public static final int CRYSTAL_QUADS=R.drawable.crystal_buttons_quad;
39-
public static final int MATERIALISTIC_BUTTONS=R.drawable.material_buttons;
40-
public static final int MATERIALISTIC_QUADS=R.drawable.material_buttons_quad;
41-
public static final int TEAL_HEXAS=R.drawable.teal_hexagons;
42-
public static final int TRIS_BUTTONS=R.drawable.tris_buttons;
43-
public static final int X_BUTTON_ALPHA=R.drawable.x_button_alpha;
44-
public static final int X_BUTTON_OUTLINE=R.drawable.x_button_outline;
45-
public static final int Y_BUTTON_ALPHA=R.drawable.y_button_alpha;
46-
public static final int Y_BUTTON_OUTLINE=R.drawable.y_button_outline;
47-
public static final int A_BUTTON_ALPHA=R.drawable.a_button_alpha;
48-
public static final int A_BUTTON_OUTLINE=R.drawable.a_button_outline;
49-
public static final int B_BUTTON_ALPHA=R.drawable.b_button_alpha;
50-
public static final int B_BUTTON_OUTLINE=R.drawable.b_button_outline;
51-
public static final int STICK_DASHES=R.drawable.stick_dash;
25+
/**
26+
* Grouping up the ButtonSignatures.
27+
* @author pavl_g
28+
*/
29+
public enum ButtonSignature {
30+
GAMEPAD_BUTTON_X('X', "X"),
31+
GAMEPAD_BUTTON_Y('Y', "Y"),
32+
GAMEPAD_BUTTON_A('A', "A"),
33+
GAMEPAD_BUTTON_B('B', "B");
5234

35+
public final int ID;
36+
public String NAME;
5337

38+
ButtonSignature(final int ID){
39+
this.ID = ID;
40+
}
41+
ButtonSignature(final int ID, final String NAME){
42+
this.ID = ID;
43+
this.NAME = NAME;
44+
}
45+
}
46+
47+
/**
48+
* Grouping up the ButtonIcons.
49+
* @author pavl_g
50+
*/
51+
public enum ButtonIcon {
52+
X_BUTTON_ALPHA(R.drawable.x_button_alpha), X_BUTTON_OUTLINE(R.drawable.x_button_outline),
53+
Y_BUTTON_ALPHA(R.drawable.y_button_alpha), Y_BUTTON_OUTLINE(R.drawable.y_button_outline),
54+
A_BUTTON_ALPHA(R.drawable.a_button_alpha), A_BUTTON_OUTLINE(R.drawable.a_button_outline),
55+
B_BUTTON_ALPHA(R.drawable.b_button_alpha), B_BUTTON_OUTLINE(R.drawable.b_button_outline);
56+
public final int ID;
57+
58+
ButtonIcon(final int ID){
59+
this.ID = ID;
60+
}
61+
}
62+
63+
/**
64+
* Grouping up the ButtonsStyles.
65+
* @author pavl_g
66+
*/
67+
public enum ButtonStyle {
68+
DEFAULT_GAMEPAD_DOMAIN(R.drawable.gamepad_domain), DEFAULT_COLOR_STICK_DOMAIN(R.drawable.moving_stick_domain),
69+
FLIPPED_COLOR_STICK_DOMAIN(R.drawable.moving_stick_flipped_domain), OPACIFIED_COLOR_STICK_DOMAIN(R.drawable.opacified_domain),
70+
NOTHING_IMAGE(R.drawable.nothing), DEFAULT_BUTTONS(R.drawable.moving_stick), CRYSTAL_BUTTONS(R.drawable.crystal_buttons),
71+
CRYSTAL_QUADS(R.drawable.crystal_buttons_quad), MATERIALISTIC_BUTTONS(R.drawable.material_buttons),
72+
TEAL_HEXAS(R.drawable.teal_hexagons), TRIS_BUTTONS(R.drawable.tris_buttons), STICK_DASHES(R.drawable.stick_dash);
73+
74+
public final int STYLE;
75+
76+
ButtonStyle(final int STYLE){
77+
this.STYLE = STYLE;
78+
}
79+
}
5480

5581
public ControlButtonsView(@NonNull Context context, @Nullable AttributeSet attrs) {
5682
super(context, attrs);
@@ -60,60 +86,63 @@ public ControlButtonsView(@NonNull Context context, @Nullable AttributeSet attrs
6086
super(context, attrs, defStyleAttr);
6187
}
6288

63-
public ImageView addControlButton(String buttonName,int buttonID, int backgroundDrawable, int drawableIcon){
89+
/**
90+
* Adds a GamePad button & apply the UI.
91+
* @param button the button to add from the enum #{@link ControlButtonsView.ButtonSignature} : eg : #{@link ButtonSignature#GAMEPAD_BUTTON_X},...etc.
92+
* @param backgroundDrawable the drawable style, you can get some from enum : #{@link ControlButtonsView.ButtonStyle}
93+
* @param drawableIcon the button icon, you can get some from enum : #{@link ControlButtonsView.ButtonIcon}
94+
* @return an imageView instance representing the added button.
95+
*/
96+
public ImageView addControlButton(@NonNull ButtonSignature button, int backgroundDrawable, int drawableIcon){
6497
ImageView controlButton = new ImageView(this.getContext());
65-
((AppCompatActivity)getContext()).runOnUiThread(()->{
66-
controlButton.setId(buttonID);
67-
ViewGroup.LayoutParams layoutParams = new LayoutParams(this.getLayoutParams().width /3, this.getLayoutParams().height/3);
68-
controlButton.setLayoutParams(layoutParams);
69-
controlButton.setImageDrawable(ContextCompat.getDrawable(this.getContext(), drawableIcon));
70-
controlButton.setBackground(ContextCompat.getDrawable(this.getContext(), backgroundDrawable));
71-
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ){
72-
controlButton.setTooltipText(buttonName);
73-
}
74-
switch (buttonID){
75-
case GAMEPAD_BUTTON_X:
98+
((AppCompatActivity)getContext()).runOnUiThread(()->{
99+
controlButton.setId(button.ID);
100+
ViewGroup.LayoutParams layoutParams = new LayoutParams(this.getLayoutParams().width /3, this.getLayoutParams().height/3);
101+
controlButton.setLayoutParams(layoutParams);
102+
controlButton.setImageDrawable(ContextCompat.getDrawable(this.getContext(), drawableIcon));
103+
controlButton.setBackground(ContextCompat.getDrawable(this.getContext(), backgroundDrawable));
104+
105+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
106+
controlButton.setTooltipText(button.NAME);
107+
}
108+
109+
if (button == ButtonSignature.GAMEPAD_BUTTON_X){
76110
controlButton.setX(0f);
77111
controlButton.setY(layoutParams.height);
78-
break;
79-
case GAMEPAD_BUTTON_B:
80-
controlButton.setX(layoutParams.width*2);
112+
}else if(button == ButtonSignature.GAMEPAD_BUTTON_B){
113+
controlButton.setX(layoutParams.width * 2);
81114
controlButton.setY(layoutParams.height);
82-
break;
83-
84-
case GAMEPAD_BUTTON_Y:
115+
}else if(button == ButtonSignature.GAMEPAD_BUTTON_Y){
85116
controlButton.setX(layoutParams.width);
86117
controlButton.setY(0f);
87-
break;
88-
case GAMEPAD_BUTTON_A:
118+
}else if(button == ButtonSignature.GAMEPAD_BUTTON_A){
89119
controlButton.setX(layoutParams.width);
90-
controlButton.setY(layoutParams.height*2);
91-
break;
92-
}
93-
this.addView(controlButton);
94-
});
120+
controlButton.setY(layoutParams.height * 2);
121+
}
122+
this.addView(controlButton);
123+
});
95124
return controlButton;
96125
}
97-
public void setButtonListener(int buttonID,OnClickListener onClickListener){
98-
ImageView pushButton=findViewById(buttonID);
126+
public void setButtonListener(@NonNull ButtonSignature button, OnClickListener onClickListener){
127+
ImageView pushButton=findViewById(button.ID);
99128
pushButton.setOnClickListener(onClickListener);
100129
}
101-
public void setButtonLongClickListener(int buttonID,OnLongClickListener onLongClickListener){
102-
ImageView pushButton=findViewById(buttonID);
130+
public void setButtonLongClickListener(@NonNull ButtonSignature button, OnLongClickListener onLongClickListener){
131+
ImageView pushButton=findViewById(button.ID);
103132
pushButton.setOnLongClickListener(onLongClickListener);
104133
}
105-
public void setButtonBackgroundDrawable(int buttonID,int drawable){
106-
(findViewById(buttonID)).setBackground(ContextCompat.getDrawable(getContext(),drawable));
134+
public void setButtonBackgroundDrawable(@NonNull ButtonSignature button,int drawable){
135+
(findViewById(button.ID)).setBackground(ContextCompat.getDrawable(getContext(),drawable));
107136
}
108-
public void setButtonSrcDrawable(int buttonID,int drawable){
109-
((ImageView)findViewById(buttonID)).setImageDrawable(ContextCompat.getDrawable(getContext(),drawable));
137+
public void setButtonSrcDrawable(@NonNull ButtonSignature button, int drawable){
138+
((ImageView)findViewById(button.ID)).setImageDrawable(ContextCompat.getDrawable(getContext(),drawable));
110139
}
111-
public void setButtonSrcBitmap(int buttonID,String srcPath){
112-
((ImageView)findViewById(buttonID)).setImageBitmap(BitmapFactory.decodeFile(srcPath));
140+
public void setButtonSrcBitmap(@NonNull ButtonSignature button, String srcPath){
141+
((ImageView)findViewById(button.ID)).setImageBitmap(BitmapFactory.decodeFile(srcPath));
113142
}
114-
public void setButtonSrcIcon(int buttonID,String srcPath){
143+
public void setButtonSrcIcon(@NonNull ButtonSignature button, String srcPath){
115144
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ){
116-
((ImageView)findViewById(buttonID)).setImageIcon(Icon.createWithFilePath(srcPath));
145+
((ImageView)findViewById(button.ID)).setImageIcon(Icon.createWithFilePath(srcPath));
117146
}
118147
}
119148
/**

SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/UiStateManager.java

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.scrappers.superiorExtendedEngine.menuStates;
22

33
import android.annotation.SuppressLint;
4+
import android.content.Context;
5+
import android.util.AttributeSet;
46
import android.view.LayoutInflater;
57
import android.view.View;
68
import android.view.ViewGroup;
@@ -22,7 +24,7 @@
2224
*/
2325
@SuppressLint("ViewConstructor")
2426
public class UiStateManager extends RelativeLayout {
25-
private final ViewGroup context;
27+
private ViewGroup context;
2628
private int stateIndex=0;
2729
private final HashMap<Integer, View> uiStates=new HashMap<>();
2830
/**
@@ -36,11 +38,22 @@ public UiStateManager(ViewGroup context) {
3638
context.addView(this);
3739
this.context=context;
3840
}
39-
/**
40-
* gets the map of the UiStates stack
41-
* @return a HashMap representing the UiStates stack ,
42-
* where the key is the index of the UiState & the value represents the UiState instance.
43-
*/
41+
public UiStateManager(Context context, AttributeSet attrs) {
42+
super(context, attrs);
43+
}
44+
45+
public UiStateManager(Context context, AttributeSet attrs, int defStyleAttr) {
46+
super(context, attrs, defStyleAttr);
47+
}
48+
49+
public UiStateManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
50+
super(context, attrs, defStyleAttr, defStyleRes);
51+
}
52+
/**
53+
* gets the map of the UiStates stack
54+
* @return a HashMap representing the UiStates stack ,
55+
* where the key is the index of the UiState & the value represents the UiState instance.
56+
*/
4457
public HashMap<Integer, View> getUiStates() {
4558
return uiStates;
4659
}

SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/ActionInjector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import android.view.View;
44

55
public interface ActionInjector {
6-
void execute(View uiState, int position, String currentItem);
6+
void execute(View uiState, int position, PageDataModel currentItem);
77
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.scrappers.superiorExtendedEngine.menuStates.uiPager;
2+
3+
public abstract class PageDataModel {
4+
public abstract String getComparingData();
5+
6+
public abstract String getSortingData();
7+
}

0 commit comments

Comments
 (0)