Permalink
Browse files

front: Removed reliance on the actionbar in the touch screen profile

editor.
  • Loading branch information...
fzurita committed Dec 18, 2015
1 parent cf6cf04 commit 3b21f54633514c3f27acfbf2b34ee9831d390d40
@@ -9,7 +9,9 @@
android:id="@+id/menuItem_buttons"
android:title="@string/touchscreenProfileActivity_buttons">
<menu>
<group android:checkableBehavior="all" >
<group
android:id="@+id/menuGroup_buttons"
android:checkableBehavior="all" >
<item
android:id="@+id/menuItem_analog"
android:title="@string/controller_analog"/>
View
@@ -513,6 +513,7 @@
<string name="playerMapPreference_reminder">Remind me whenever players are not mapped</string>
<!-- Touchscreen Profile Activity -->
<string name="touchscreenProfileActivity_menuTitle">Choose an option</string>
<string name="touchscreenProfileActivity_buttons">Buttons</string>
<string name="touchscreenProfileActivity_remove">Remove</string>
<string name="touchscreenProfileActivity_horizontalSlider">Horizontal: %1$d %%</string>
@@ -26,7 +26,10 @@
import org.mupen64plusae.v3.alpha.R;
import paulscode.android.mupen64plusae.ActivityHelper;
import paulscode.android.mupen64plusae.MenuListView;
import paulscode.android.mupen64plusae.dialog.MenuDialogFragment;
import paulscode.android.mupen64plusae.dialog.Prompt;
import paulscode.android.mupen64plusae.dialog.MenuDialogFragment.OnDialogMenuItemSelectedListener;
import paulscode.android.mupen64plusae.dialog.Prompt.PromptFileListener;
import paulscode.android.mupen64plusae.dialog.SeekBarGroup;
import paulscode.android.mupen64plusae.game.GameOverlay;
@@ -41,13 +44,10 @@
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.OnMenuVisibilityListener;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.SparseArray;
@@ -65,10 +65,11 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
public class TouchscreenProfileActivity extends AppCompatActivity implements OnTouchListener
public class TouchscreenProfileActivity extends AppCompatActivity implements OnTouchListener, OnDialogMenuItemSelectedListener
{
private static final String TOUCHSCREEN_AUTOHOLDABLES = "touchscreenAutoHoldables";
private static final String AUTOHOLDABLES_DELIMITER = "~";
private static final String STATE_MENU_DIALOG_FRAGMENT = "STATE_MENU_DIALOG_FRAGMENT";
private static final String ANALOG = "analog";
private static final String DPAD = "dpad";
@@ -113,9 +114,6 @@
private int dragY;
private Rect dragFrame;
// Don't enter immersive mode until the ActionBar menus are closed
private boolean actionBarMenuOpen = false;
// The directory of the selected touchscreen skin.
private String touchscreenSkin;
@@ -177,26 +175,6 @@ protected void onCreate( Bundle savedInstanceState )
mSurface = (ImageView) findViewById( R.id.gameSurface );
mOverlay = (GameOverlay) findViewById( R.id.gameOverlay );
// Configure the action bar
{
getSupportActionBar().hide();
ColorDrawable color = new ColorDrawable( Color.parseColor( "#303030" ) );
color.setAlpha( mGlobalPrefs.displayActionBarTransparency );
getSupportActionBar().setBackgroundDrawable( color );
// onOptionsMenuClosed is not called due to a bug in Android:
// http://stackoverflow.com/questions/3688077/android-onoptionsmenuclosed-not-being-called-for-submenu
// so add a menu visibility listener instead
getSupportActionBar().addOnMenuVisibilityListener( new OnMenuVisibilityListener()
{
@Override
public void onMenuVisibilityChanged( boolean isVisible )
{
actionBarMenuOpen = isVisible;
}
});
}
String layout = mProfile.get( "touchscreenSkin", "Outline" );
if( layout.equals( "Custom" ) )
touchscreenSkin = mProfile.get( "touchscreenCustomSkinPath", "" );
@@ -248,8 +226,10 @@ protected void onResume()
public void onWindowFocusChanged( boolean hasFocus )
{
super.onWindowFocusChanged( hasFocus );
if( hasFocus && !actionBarMenuOpen )
if( hasFocus )
{
hideSystemBars();
}
}
@Override
@@ -270,14 +250,22 @@ public boolean onCreateOptionsMenu( Menu menu )
}
@Override
public boolean onPrepareOptionsMenu( Menu menu )
public void onPrepareMenuList(MenuListView listView)
{
Menu menu = listView.getMenu();
setCheckState( menu, R.id.menuItem_analog, ANALOG );
setCheckState( menu, R.id.menuItem_dpad, DPAD );
setVisibleState( menu, R.id.menuItem_groupAB, !mTouchscreenMap.isABSplit() );
setVisibleState( menu, R.id.menuItem_buttonA, mTouchscreenMap.isABSplit() );
setVisibleState( menu, R.id.menuItem_buttonB, mTouchscreenMap.isABSplit() );
if(mTouchscreenMap.isABSplit())
{
UpdateButtonMenu(listView, R.id.menuItem_groupAB);
}
else
{
UpdateButtonMenu(listView, R.id.menuItem_buttonA);
UpdateButtonMenu(listView, R.id.menuItem_buttonB);
}
setCheckState( menu, R.id.menuItem_buttonA, BUTTON_A );
setCheckState( menu, R.id.menuItem_buttonB, BUTTON_B );
setCheckState( menu, R.id.menuItem_groupAB, GROUP_AB );
@@ -286,90 +274,92 @@ public boolean onPrepareOptionsMenu( Menu menu )
setCheckState( menu, R.id.menuItem_buttonR, BUTTON_R );
setCheckState( menu, R.id.menuItem_buttonZ, BUTTON_Z );
setCheckState( menu, R.id.menuItem_buttonS, BUTTON_S );
return super.onPrepareOptionsMenu( menu );
}
private void setCheckState( Menu menu, int id, String assetName )
{
MenuItem item = menu.findItem( id );
if( item != null )
item.setChecked( hasAsset( assetName ) );
}
private void setVisibleState( Menu menu, int id, boolean state )
{
MenuItem item = menu.findItem( id );
if( item != null )
item.setVisible(state);
}
private boolean hasAsset( String assetName )
private void UpdateButtonMenu(MenuListView listView, int menuItemId)
{
// Get the asset position from the profile and see if it's valid
int x = mProfile.getInt( assetName + TAG_X, DISABLED_ASSET_POS );
int y = mProfile.getInt( assetName + TAG_Y, DISABLED_ASSET_POS );
return ( x > DISABLED_ASSET_POS ) && ( y > DISABLED_ASSET_POS );
MenuItem buttonGroupItem = listView.getMenu().findItem(R.id.menuItem_buttons);
if(buttonGroupItem != null && listView.getMenu().findItem(menuItemId) != null)
{
buttonGroupItem.getSubMenu().removeItem(menuItemId);
}
}
@Override
public boolean onOptionsItemSelected( MenuItem item )
{
public void onDialogMenuItemSelected( int dialogId, MenuItem item)
{
switch( item.getItemId() )
{
case R.id.menuItem_globalSettings:
ActivityHelper.startGlobalPrefsActivity( this, 1 );
return true;
return;
case R.id.menuItem_exit:
finish();
return true;
return;
case R.id.menuItem_analog:
toggleAsset( ANALOG );
return true;
return;
case R.id.menuItem_dpad:
toggleAsset( DPAD );
return true;
return;
case R.id.menuItem_groupAB:
toggleAsset( GROUP_AB );
return true;
return;
case R.id.menuItem_buttonA:
toggleAsset( BUTTON_A );
return true;
return;
case R.id.menuItem_buttonB:
toggleAsset( BUTTON_B );
return true;
return;
case R.id.menuItem_groupC:
toggleAsset( GROUP_C );
return true;
return;
case R.id.menuItem_buttonL:
toggleAsset( BUTTON_L );
return true;
return;
case R.id.menuItem_buttonR:
toggleAsset( BUTTON_R );
return true;
return;
case R.id.menuItem_buttonZ:
toggleAsset( BUTTON_Z );
return true;
return;
case R.id.menuItem_buttonS:
toggleAsset( BUTTON_S );
return true;
return;
case R.id.menuItem_outline:
touchscreenSkin = mAppData.touchscreenSkinsDir + "Outline";
mProfile.put( "touchscreenSkin", "Outline" );
refresh();
return true;
return;
case R.id.menuItem_shaded:
touchscreenSkin = mAppData.touchscreenSkinsDir + "Shaded";
mProfile.put( "touchscreenSkin", "Shaded" );
refresh();
return true;
return;
case R.id.menuItem_custom:
loadCustomSkinFromPrompt();
return true;
return;
default:
return super.onOptionsItemSelected( item );
return;
}
}
private void setCheckState( Menu menu, int id, String assetName )
{
MenuItem item = menu.findItem( id );
if( item != null )
item.setChecked( hasAsset( assetName ) );
}
private boolean hasAsset( String assetName )
{
// Get the asset position from the profile and see if it's valid
int x = mProfile.getInt( assetName + TAG_X, DISABLED_ASSET_POS );
int y = mProfile.getInt( assetName + TAG_Y, DISABLED_ASSET_POS );
return ( x > DISABLED_ASSET_POS ) && ( y > DISABLED_ASSET_POS );
}
private void toggleAsset( String assetName )
{
// Change the position of the asset to show/hide
@@ -429,21 +419,6 @@ private boolean getHoldable( int n64Index )
return ArrayUtils.contains( holdables, String.valueOf( n64Index ) );
}
@Override
public void onBackPressed()
{
// Toggle the action bar
ActionBar actionBar = getSupportActionBar();
if( actionBar.isShowing() )
{
hideSystemBars();
}
else
{
actionBar.show();
}
}
@SuppressLint( "InlinedApi" )
private void hideSystemBars()
{
@@ -509,6 +484,17 @@ public boolean onTouch( View v, MotionEvent event )
dragAsset = ANALOG;
dragFrame = mTouchscreenMap.getAnalogFrame();
}
else
{
int resId = R.menu.touchscreen_profile_activity;
int stringId = R.string.touchscreenProfileActivity_menuTitle;
MenuDialogFragment menuDialogFragment = MenuDialogFragment.newInstance(0,
getString(stringId), resId);
FragmentManager fm = getSupportFragmentManager();
menuDialogFragment.show(fm, STATE_MENU_DIALOG_FRAGMENT);
}
}
dragX = mProfile.getInt( dragAsset + TAG_X, INITIAL_ASSET_POS );

0 comments on commit 3b21f54

Please sign in to comment.