Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] The back button now toggles the visibility of the action ba…
…r in the emulation window. This can be used in the future to implement the overlay for save states and other things.
  • Loading branch information
lioncash committed Aug 29, 2013
1 parent aeec249 commit 5a749cc
Showing 1 changed file with 41 additions and 4 deletions.
Expand Up @@ -11,9 +11,11 @@
import android.util.DisplayMetrics;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;

/**
* This is the activity where all of the emulation handling happens.
Expand All @@ -22,6 +24,7 @@
public final class EmulationActivity extends Activity
{
private boolean Running;
private boolean IsActionBarHidden = false;
private float screenWidth;
private float screenHeight;

Expand All @@ -38,8 +41,8 @@ public void onCreate(Bundle savedInstanceState)
this.screenWidth = displayMetrics.widthPixels;

// Request window features for the emulation view.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

// Set the native rendering screen width/height.
Expand All @@ -51,10 +54,13 @@ public void onCreate(Bundle savedInstanceState)
NativeLibrary.SetDimensions((int)screenWidth, (int)screenHeight);
NativeLibrary.SetFilename(gameToEmulate.getStringExtra("SelectedGame"));
Running = true;

// Set the emulation window.
setContentView(R.layout.emulation_view);


// Hide the action bar by default so it doesn't get in the way.
getActionBar().hide();
IsActionBarHidden = true;
}

@Override
Expand Down Expand Up @@ -96,6 +102,29 @@ public boolean onTouchEvent(MotionEvent event)

return false;
}

@Override
public void onBackPressed()
{
// The back button in the emulation
// window is the toggle for the action bar.
if (IsActionBarHidden)
{
IsActionBarHidden = false;
getActionBar().show();
}
else
{
IsActionBarHidden = true;
getActionBar().hide();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
return true;
}

// Gets button presses
@Override
Expand Down Expand Up @@ -124,6 +153,14 @@ public boolean dispatchKeyEvent(KeyEvent event)
switch (event.getAction())
{
case KeyEvent.ACTION_DOWN:
// Handling the case where the back button is pressed.
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
{
onBackPressed();
return true;
}

// Normal key events.
action = 0;
break;
case KeyEvent.ACTION_UP:
Expand Down

0 comments on commit 5a749cc

Please sign in to comment.