Skip to content

Commit ebc8912

Browse files
committed
Android: make the on-screen controls toggle persistent
1 parent dff44ce commit ebc8912

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/android/java/com/hydra/noods/NooActivity.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import androidx.appcompat.app.AppCompatActivity;
2323
import androidx.constraintlayout.widget.ConstraintLayout;
2424
import androidx.core.content.ContextCompat;
25+
import androidx.preference.PreferenceManager;
2526

2627
import android.app.AlertDialog;
2728
import android.content.DialogInterface;
2829
import android.content.Intent;
2930
import android.content.pm.PackageManager;
31+
import android.content.SharedPreferences;
3032
import android.graphics.Color;
3133
import android.opengl.GLSurfaceView;
3234
import android.os.Bundle;
@@ -49,22 +51,27 @@ public class NooActivity extends AppCompatActivity
4951
private NooRenderer renderer;
5052
private NooButton buttons[];
5153
private TextView fpsCounter;
54+
55+
private SharedPreferences prefs;
5256
private int fpsLimiterBackup = 0;
5357
private boolean initButtons = true;
54-
private boolean showingButtons = true;
58+
private boolean showingButtons;
5559
private boolean showingFps;
5660

5761
@Override
5862
protected void onCreate(Bundle savedInstanceState)
5963
{
6064
super.onCreate(savedInstanceState);
61-
6265
layout = new ConstraintLayout(this);
6366
view = new GLSurfaceView(this);
6467
renderer = new NooRenderer(this);
6568
buttons = new NooButton[9];
6669
fpsCounter = new TextView(this);
6770

71+
// Load the previous on-screen button state
72+
prefs = PreferenceManager.getDefaultSharedPreferences(this);
73+
showingButtons = prefs.getBoolean("show_buttons", true);
74+
6875
// Prepare the GL renderer
6976
view.setEGLContextClientVersion(2);
7077
view.setRenderer(renderer);
@@ -150,17 +157,18 @@ public boolean onOptionsItemSelected(MenuItem item)
150157
switch (item.getItemId())
151158
{
152159
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)
156167
for (int i = 0; i < 6; i++)
157168
layout.addView(buttons[i]);
158-
}
159169
else
160-
{
161170
for (int i = 0; i < 6; i++)
162171
layout.removeView(buttons[i]);
163-
}
164172
return true;
165173

166174
case R.id.restart_action:
@@ -279,11 +287,6 @@ public void onClick(DialogInterface dialog, int id)
279287
builder3.create().show();
280288
return true;
281289

282-
case R.id.bindings_action:
283-
// Open the input bindings menu
284-
startActivity(new Intent(this, BindingsMenu.class));
285-
return true;
286-
287290
case R.id.settings_action:
288291
// Open the settings menu
289292
startActivity(new Intent(this, SettingsMenu.class));
@@ -400,10 +403,8 @@ public void updateButtons()
400403
{
401404
// Remove old buttons from the layout if visible
402405
if (!initButtons && showingButtons)
403-
{
404406
for (int i = 0; i < 6; i++)
405407
layout.removeView(buttons[i]);
406-
}
407408

408409
// Set layout parameters based on display and settings
409410
DisplayMetrics metrics = new DisplayMetrics();
@@ -434,12 +435,10 @@ public void updateButtons()
434435
new int[] {2}, z, h - (int)(d * 38), (int)(d * 33), (int)(d * 33));
435436

436437
// Add new buttons to the layout if visible
437-
if (initButtons || showingButtons)
438-
{
438+
if (showingButtons)
439439
for (int i = 0; i < 6; i++)
440440
layout.addView(buttons[i]);
441-
initButtons = false;
442-
}
441+
initButtons = false;
443442
}
444443

445444
private boolean canEnableMic()

src/android/res/menu/noo_menu.xml

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<item android:id="@+id/save_type_action"
1818
android:title="Change Save Type" />
1919

20-
<item android:id="@+id/bindings_action"
21-
android:title="Input Bindings" />
22-
2320
<item android:id="@+id/settings_action"
2421
android:title="Settings" />
2522

0 commit comments

Comments
 (0)