22
22
import androidx .appcompat .app .AppCompatActivity ;
23
23
import androidx .constraintlayout .widget .ConstraintLayout ;
24
24
import androidx .core .content .ContextCompat ;
25
+ import androidx .preference .PreferenceManager ;
25
26
26
27
import android .app .AlertDialog ;
27
28
import android .content .DialogInterface ;
28
29
import android .content .Intent ;
29
30
import android .content .pm .PackageManager ;
31
+ import android .content .SharedPreferences ;
30
32
import android .graphics .Color ;
31
33
import android .opengl .GLSurfaceView ;
32
34
import android .os .Bundle ;
@@ -49,22 +51,27 @@ public class NooActivity extends AppCompatActivity
49
51
private NooRenderer renderer ;
50
52
private NooButton buttons [];
51
53
private TextView fpsCounter ;
54
+
55
+ private SharedPreferences prefs ;
52
56
private int fpsLimiterBackup = 0 ;
53
57
private boolean initButtons = true ;
54
- private boolean showingButtons = true ;
58
+ private boolean showingButtons ;
55
59
private boolean showingFps ;
56
60
57
61
@ Override
58
62
protected void onCreate (Bundle savedInstanceState )
59
63
{
60
64
super .onCreate (savedInstanceState );
61
-
62
65
layout = new ConstraintLayout (this );
63
66
view = new GLSurfaceView (this );
64
67
renderer = new NooRenderer (this );
65
68
buttons = new NooButton [9 ];
66
69
fpsCounter = new TextView (this );
67
70
71
+ // Load the previous on-screen button state
72
+ prefs = PreferenceManager .getDefaultSharedPreferences (this );
73
+ showingButtons = prefs .getBoolean ("show_buttons" , true );
74
+
68
75
// Prepare the GL renderer
69
76
view .setEGLContextClientVersion (2 );
70
77
view .setRenderer (renderer );
@@ -150,17 +157,18 @@ public boolean onOptionsItemSelected(MenuItem item)
150
157
switch (item .getItemId ())
151
158
{
152
159
case R .id .controls_action :
153
- // Toggle hiding the on-screen buttons
154
- if (showingButtons = !showingButtons )
155
- {
160
+ // Toggle the on-screen button state
161
+ SharedPreferences .Editor editor = prefs .edit ();
162
+ editor .putBoolean ("show_buttons" , showingButtons = !showingButtons );
163
+ editor .commit ();
164
+
165
+ // Show or hide the on-screen buttons
166
+ if (showingButtons )
156
167
for (int i = 0 ; i < 6 ; i ++)
157
168
layout .addView (buttons [i ]);
158
- }
159
169
else
160
- {
161
170
for (int i = 0 ; i < 6 ; i ++)
162
171
layout .removeView (buttons [i ]);
163
- }
164
172
return true ;
165
173
166
174
case R .id .restart_action :
@@ -279,11 +287,6 @@ public void onClick(DialogInterface dialog, int id)
279
287
builder3 .create ().show ();
280
288
return true ;
281
289
282
- case R .id .bindings_action :
283
- // Open the input bindings menu
284
- startActivity (new Intent (this , BindingsMenu .class ));
285
- return true ;
286
-
287
290
case R .id .settings_action :
288
291
// Open the settings menu
289
292
startActivity (new Intent (this , SettingsMenu .class ));
@@ -400,10 +403,8 @@ public void updateButtons()
400
403
{
401
404
// Remove old buttons from the layout if visible
402
405
if (!initButtons && showingButtons )
403
- {
404
406
for (int i = 0 ; i < 6 ; i ++)
405
407
layout .removeView (buttons [i ]);
406
- }
407
408
408
409
// Set layout parameters based on display and settings
409
410
DisplayMetrics metrics = new DisplayMetrics ();
@@ -434,12 +435,10 @@ public void updateButtons()
434
435
new int [] {2 }, z , h - (int )(d * 38 ), (int )(d * 33 ), (int )(d * 33 ));
435
436
436
437
// Add new buttons to the layout if visible
437
- if (initButtons || showingButtons )
438
- {
438
+ if (showingButtons )
439
439
for (int i = 0 ; i < 6 ; i ++)
440
440
layout .addView (buttons [i ]);
441
- initButtons = false ;
442
- }
441
+ initButtons = false ;
443
442
}
444
443
445
444
private boolean canEnableMic ()
0 commit comments