Revision 917d15f5
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/dialogs/RubikDialogBandagedSettings.java | ||
---|---|---|
27 | 27 |
import android.view.LayoutInflater; |
28 | 28 |
import android.view.View; |
29 | 29 |
import android.view.Window; |
30 |
import android.widget.AdapterView; |
|
31 |
import android.widget.ArrayAdapter; |
|
30 | 32 |
import android.widget.Button; |
33 |
import android.widget.Spinner; |
|
31 | 34 |
import android.widget.TextView; |
32 | 35 |
|
33 | 36 |
import androidx.annotation.NonNull; |
... | ... | |
35 | 38 |
import androidx.appcompat.app.AppCompatDialogFragment; |
36 | 39 |
import androidx.fragment.app.FragmentActivity; |
37 | 40 |
|
41 |
import org.distorted.bandaged.BandagedPlayActivity; |
|
42 |
import org.distorted.bandaged.BandagedPlayScreen; |
|
38 | 43 |
import org.distorted.main.R; |
39 | 44 |
import org.distorted.main.RubikActivity; |
40 | 45 |
|
41 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 47 |
|
43 |
public class RubikDialogBandagedSettings extends AppCompatDialogFragment |
|
48 |
public class RubikDialogBandagedSettings extends AppCompatDialogFragment implements AdapterView.OnItemSelectedListener
|
|
44 | 49 |
{ |
50 |
public static final int[] DEPTHS = new int[] {20,50,100,200,500,1000}; |
|
51 |
private int mAnimPos, mScraPos; |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
private String[] createScrambleModes() |
|
56 |
{ |
|
57 |
int len = DEPTHS.length; |
|
58 |
String[] ret = new String[len]; |
|
59 |
|
|
60 |
for(int i=0; i<len; i++) |
|
61 |
{ |
|
62 |
ret[i] = String.valueOf(DEPTHS[i]); |
|
63 |
} |
|
64 |
|
|
65 |
return ret; |
|
66 |
} |
|
67 |
|
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
|
70 |
private void configureView(FragmentActivity act, View view, float textSize, int scraPos, int animPos) |
|
71 |
{ |
|
72 |
TextView text1 = view.findViewById(R.id.bandaged_text_scramble); |
|
73 |
text1.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
74 |
TextView text2 = view.findViewById(R.id.bandaged_text_animation); |
|
75 |
text2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
76 |
|
|
77 |
mScraPos = scraPos; |
|
78 |
mAnimPos = animPos; |
|
79 |
|
|
80 |
Spinner scramble = view.findViewById(R.id.bandaged_spinner_scramble); |
|
81 |
scramble.setOnItemSelectedListener(this); |
|
82 |
String[] scrambleModes = createScrambleModes(); |
|
83 |
|
|
84 |
ArrayAdapter<String> scrambleAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, scrambleModes ); |
|
85 |
scrambleAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
86 |
scramble.setAdapter(scrambleAdapter); |
|
87 |
scramble.setSelection(mScraPos); |
|
88 |
|
|
89 |
Spinner animation = view.findViewById(R.id.bandaged_spinner_animation); |
|
90 |
animation.setOnItemSelectedListener(this); |
|
91 |
String[] animationModes = { "ON" , "OFF" }; |
|
92 |
|
|
93 |
ArrayAdapter<String> animationAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, animationModes ); |
|
94 |
animationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
95 |
animation.setAdapter(animationAdapter); |
|
96 |
animation.setSelection(mAnimPos); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
@Override |
|
102 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
103 |
{ |
|
104 |
int spinnerID = parent.getId(); |
|
105 |
|
|
106 |
if( spinnerID == R.id.bandaged_spinner_scramble ) |
|
107 |
{ |
|
108 |
mScraPos = pos; |
|
109 |
} |
|
110 |
else if( spinnerID == R.id.bandaged_spinner_animation ) |
|
111 |
{ |
|
112 |
mAnimPos = pos; |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
@Override |
|
119 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
120 |
|
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
45 | 123 |
@NonNull |
46 | 124 |
@Override |
47 | 125 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
... | ... | |
54 | 132 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
55 | 133 |
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE; |
56 | 134 |
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE; |
57 |
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
|
|
135 |
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
|
58 | 136 |
|
59 | 137 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
60 | 138 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
61 | 139 |
tv.setText(R.string.settings); |
62 | 140 |
builder.setCustomTitle(tv); |
63 | 141 |
|
142 |
Bundle args = getArguments(); |
|
143 |
int scraPos, animPos; |
|
144 |
|
|
145 |
try |
|
146 |
{ |
|
147 |
scraPos = args.getInt("scraPos"); |
|
148 |
animPos = args.getInt("animPos"); |
|
149 |
} |
|
150 |
catch(Exception e) |
|
151 |
{ |
|
152 |
scraPos = 0; |
|
153 |
animPos = 0; |
|
154 |
} |
|
155 |
|
|
156 |
final BandagedPlayActivity bact = (BandagedPlayActivity)getContext(); |
|
157 |
|
|
64 | 158 |
builder.setCancelable(true); |
65 | 159 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
66 | 160 |
{ |
67 | 161 |
@Override |
68 | 162 |
public void onClick(DialogInterface dialog, int which) |
69 | 163 |
{ |
164 |
BandagedPlayScreen screen = bact!=null ? bact.getScreen() : null; |
|
70 | 165 |
|
166 |
if( screen!=null ) |
|
167 |
{ |
|
168 |
screen.setScrambleDepth(mScraPos); |
|
169 |
screen.setAnimationMode(mAnimPos); |
|
170 |
} |
|
71 | 171 |
} |
72 | 172 |
}); |
73 | 173 |
|
74 | 174 |
final View view = inflater.inflate(R.layout.dialog_settings, null); |
75 |
|
|
76 |
|
|
175 |
configureView(act,view,textSize,scraPos,animPos); |
|
77 | 176 |
builder.setView(view); |
78 | 177 |
|
79 | 178 |
Dialog dialog = builder.create(); |
Also available in: Unified diff
BandagedPlay: configurable mode and scramble depth