Android: Add touchscreen controller toggle
This commit is contained in:
parent
9321fcb627
commit
6592b59597
|
@ -5,9 +5,11 @@ import android.annotation.SuppressLint;
|
|||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
|
@ -31,6 +33,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
|||
* Touchscreen controller overlay
|
||||
*/
|
||||
TouchscreenControllerView mTouchscreenController;
|
||||
private boolean mTouchscreenControllerVisible = true;
|
||||
|
||||
/**
|
||||
* Whether or not the system UI should be auto-hidden after
|
||||
|
@ -148,6 +151,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
|||
mTouchscreenController = new TouchscreenControllerView(this);
|
||||
activityLayout.addView(mTouchscreenController);
|
||||
mTouchscreenController.init(0, "DigitalController", mHostInterface);
|
||||
setTouchscreenControllerVisibility(true);
|
||||
|
||||
// Hook up controller input.
|
||||
mContentView.initControllerKeyMapping(mHostInterface, "DigitalController");
|
||||
|
@ -163,14 +167,35 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
|||
delayedHide(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_emulation, menu);
|
||||
menu.findItem(R.id.show_controller).setChecked(mTouchscreenControllerVisible);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == android.R.id.home) {
|
||||
// This ID represents the Home or Up button.
|
||||
NavUtils.navigateUpFromSameTask(this);
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
} else if (id == R.id.show_controller) {
|
||||
setTouchscreenControllerVisibility(!mTouchscreenControllerVisible);
|
||||
item.setChecked(mTouchscreenControllerVisible);
|
||||
return true;
|
||||
} else if (id == R.id.quit) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
@ -217,4 +242,9 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
|||
mHideHandler.removeCallbacks(mHideRunnable);
|
||||
mHideHandler.postDelayed(mHideRunnable, delayMillis);
|
||||
}
|
||||
|
||||
private void setTouchscreenControllerVisibility(boolean visible) {
|
||||
mTouchscreenControllerVisible = visible;
|
||||
mTouchscreenController.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<group android:id="@+id/quick_load_save">
|
||||
<item android:title="Quick Load" />
|
||||
<item android:title="Quick Save" />
|
||||
</group>
|
||||
<group android:id="@+id/quick_settings">
|
||||
<item
|
||||
android:id="@+id/change_disc"
|
||||
android:title="Change Disc" />
|
||||
<item
|
||||
android:id="@+id/show_controller"
|
||||
android:checkable="true"
|
||||
android:title="Show Controller" />
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:title="Settings" />
|
||||
<item
|
||||
android:id="@+id/quit"
|
||||
android:title="Quit" />
|
||||
</group>
|
||||
</menu>
|
Loading…
Reference in New Issue