Fix and simplify the new subclassing of the popup menus

This commit is contained in:
TwistedUmbrella 2014-02-09 15:01:05 -05:00
parent e70b71828c
commit ae6d694c52
3 changed files with 35 additions and 46 deletions

View File

@ -2,11 +2,9 @@ package com.reicast.emulator;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
@ -15,7 +13,6 @@ import android.view.ViewGroup.LayoutParams;
import android.view.Window; import android.view.Window;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView.ScaleType; import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.Toast; import android.widget.Toast;
@ -45,7 +42,7 @@ public class EditVJoyActivity extends Activity {
menu = new OnScreenMenu(this); menu = new OnScreenMenu(this);
menu.setGLView(mView, mView6); menu.setGLView(mView, mView6);
popUp = menu.createPopup(); popUp = menu.createVjoyPopup();
// Call parent onCreate() // Call parent onCreate()
super.onCreate(icicle); super.onCreate(icicle);

View File

@ -496,6 +496,26 @@ public class GL2JNIActivity extends Activity {
return true; return true;
} }
} }
public void displayPopUp(PopupWindow popUp) {
if (MainActivity.force_gpu) {
popUp.showAtLocation(mView6, Gravity.BOTTOM, 0, 0);
} else {
popUp.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
}
popUp.update(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
}
public void displayConfig(PopupWindow popUpConfig) {
if (MainActivity.force_gpu) {
popUpConfig.showAtLocation(mView6, Gravity.BOTTOM, 0, 0);
} else {
popUpConfig.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
}
popUpConfig.update(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
}
public boolean onKeyUp(int keyCode, KeyEvent event) { public boolean onKeyUp(int keyCode, KeyEvent event) {
Integer playerNum = Arrays.asList(name).indexOf(event.getDeviceId()); Integer playerNum = Arrays.asList(name).indexOf(event.getDeviceId());
@ -556,14 +576,7 @@ public class GL2JNIActivity extends Activity {
private boolean showMenu() { private boolean showMenu() {
if (!popUp.isShowing()) { if (!popUp.isShowing()) {
if (MainActivity.force_gpu) { displayPopUp(popUp);
popUp.showAtLocation(mView6, Gravity.BOTTOM, 0, 0);
} else {
popUp.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
}
popUp.update(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
} else { } else {
popUp.dismiss(); popUp.dismiss();
} }

View File

@ -18,7 +18,8 @@ import android.widget.ImageView.ScaleType;
public class OnScreenMenu { public class OnScreenMenu {
private Context mContext; private GL2JNIActivity mContext;
private EditVJoyActivity vContext;
private SharedPreferences prefs; private SharedPreferences prefs;
LayoutParams params; LayoutParams params;
private int frameskip; private int frameskip;
@ -31,7 +32,7 @@ public class OnScreenMenu {
private File sdcard = Environment.getExternalStorageDirectory(); private File sdcard = Environment.getExternalStorageDirectory();
private String home_directory = sdcard + "/dc"; private String home_directory = sdcard + "/dc";
public OnScreenMenu(Context mContext, SharedPreferences prefs) { public OnScreenMenu(GL2JNIActivity mContext, SharedPreferences prefs) {
this.mContext = mContext; this.mContext = mContext;
this.prefs = prefs; this.prefs = prefs;
home_directory = prefs.getString("home_directory", home_directory); home_directory = prefs.getString("home_directory", home_directory);
@ -40,8 +41,8 @@ public class OnScreenMenu {
frameskip = ConfigureFragment.frameskip; frameskip = ConfigureFragment.frameskip;
} }
public OnScreenMenu(Context mContext) { public OnScreenMenu(EditVJoyActivity vContext) {
this.mContext = mContext; this.vContext = vContext;
} }
public void setGLView(GL2JNIView mView, GL2JNIViewV6 mView6) { public void setGLView(GL2JNIView mView, GL2JNIViewV6 mView6) {
@ -125,19 +126,19 @@ public class OnScreenMenu {
} }
PopupWindow createVjoyPopup() { PopupWindow createVjoyPopup() {
final PopupWindow popUp = new PopupWindow(mContext); final PopupWindow popUp = new PopupWindow(vContext);
int p = getPixelsFromDp(60, mContext); int p = getPixelsFromDp(60, vContext);
params = new LayoutParams(p, p); params = new LayoutParams(p, p);
LinearLayout hlay = new LinearLayout(mContext); LinearLayout hlay = new LinearLayout(vContext);
hlay.setOrientation(LinearLayout.HORIZONTAL); hlay.setOrientation(LinearLayout.HORIZONTAL);
hlay.addView(addbut(R.drawable.apply, new OnClickListener() { hlay.addView(addbut(R.drawable.apply, new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
Intent inte = new Intent(mContext, MainActivity.class); Intent inte = new Intent(vContext, MainActivity.class);
mContext.startActivity(inte); vContext.startActivity(inte);
((Activity) mContext).finish(); ((Activity) vContext).finish();
} }
}), params); }), params);
@ -170,16 +171,10 @@ public class OnScreenMenu {
void displayConfigPopup(final PopupWindow popUp) { void displayConfigPopup(final PopupWindow popUp) {
final PopupWindow popUpConfig = new PopupWindow(mContext); final PopupWindow popUpConfig = new PopupWindow(mContext);
// LinearLayout layout = new LinearLayout(this);
// tv = new TextView(this);
int p = getPixelsFromDp(60, mContext); int p = getPixelsFromDp(60, mContext);
LayoutParams configParams = new LayoutParams(p, p); LayoutParams configParams = new LayoutParams(p, p);
// layout.setOrientation(LinearLayout.VERTICAL);
// tv.setText("Hi this is a sample text for popup window");
// layout.addView(tv, params);
LinearLayout hlay = new LinearLayout(mContext); LinearLayout hlay = new LinearLayout(mContext);
hlay.setOrientation(LinearLayout.HORIZONTAL); hlay.setOrientation(LinearLayout.HORIZONTAL);
@ -255,28 +250,12 @@ public class OnScreenMenu {
hlay.addView(addbut(R.drawable.up, new OnClickListener() { hlay.addView(addbut(R.drawable.up, new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
popUpConfig.dismiss(); popUpConfig.dismiss();
if (MainActivity.force_gpu) { mContext.displayPopUp(popUp);
popUp.showAtLocation(mView6, Gravity.BOTTOM, 0, 0);
} else {
popUp.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
}
popUp.update(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
} }
}), configParams); }), configParams);
// layout.addView(hlay,params);
popUpConfig.setContentView(hlay); popUpConfig.setContentView(hlay);
if (popUp.isShowing()) { mContext.displayConfig(popUpConfig);
popUp.dismiss();
}
if (MainActivity.force_gpu) {
popUpConfig.showAtLocation(mView6, Gravity.BOTTOM, 0, 0);
} else {
popUpConfig.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
}
popUpConfig.update(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
} }
public static int getPixelsFromDp(float dps, Context context) { public static int getPixelsFromDp(float dps, Context context) {