Android: Simplify and optimize emu UI classes

This commit is contained in:
Ender's Games 2018-09-12 12:06:56 -04:00
parent 5ef7b60134
commit ba134c8c4e
10 changed files with 190 additions and 194 deletions

View File

@ -27,6 +27,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
@ -62,21 +63,22 @@ public class AboutFragment extends Fragment {
e.printStackTrace();
}
new retrieveGitTask().execute(Config.git_api);
new retrieveGitTask(this).execute(Config.git_api);
}
private class retrieveGitTask extends
private static class retrieveGitTask extends
AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {
@Override
protected void onPreExecute() {
private WeakReference<AboutFragment> ref;
retrieveGitTask(AboutFragment context) {
ref = new WeakReference<>(context);
}
@Override
protected ArrayList<HashMap<String, String>> doInBackground(
String... paths) {
ArrayList<HashMap<String, String>> commitList = new ArrayList<HashMap<String, String>>();
ArrayList<HashMap<String, String>> commitList = new ArrayList<>();
try {
JSONArray gitObject = getContent(paths[0]);
for (int i = 0; i < gitObject.length(); i++) {
@ -89,7 +91,7 @@ public class AboutFragment extends Fragment {
String author = commitArray.getJSONObject("author").getString("name");
String committer = commitArray.getJSONObject("committer").getString("name");
String avatar = null;
String avatar;
if (!jsonObject.getString("committer").equals("null")) {
avatar = jsonObject.getJSONObject("committer").getString("avatar_url");
committer = committer + " (" + jsonObject
@ -109,7 +111,7 @@ public class AboutFragment extends Fragment {
.replace("https://api.github.com/repos", "https://github.com")
.replace("commits", "commit");
String title = "No commit heading attached";
String title;
String message = "No commit message attached";
if (commitArray.getString("message").contains("\n\n")) {
@ -121,7 +123,7 @@ public class AboutFragment extends Fragment {
title = commitArray.getString("message");
}
HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, String> map = new HashMap<>();
map.put("Date", date);
map.put("Committer", committer);
map.put("Title", title);
@ -130,7 +132,7 @@ public class AboutFragment extends Fragment {
map.put("Url", curl);
map.put("Author", author);
map.put("Avatar", avatar);
map.put("Build", buildId);
map.put("Build", ref.get().buildId);
commitList.add(map);
}
@ -146,14 +148,15 @@ public class AboutFragment extends Fragment {
protected void onPostExecute(
ArrayList<HashMap<String, String>> commitList) {
if (commitList != null && commitList.size() > 0) {
ListView list = (ListView) getView().findViewById(R.id.list);
ListView list = (ListView) ref.get().getView().findViewById(R.id.list);
list.setSelector(R.drawable.list_selector);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
GitAdapter adapter = new GitAdapter(getActivity(), commitList);
GitAdapter adapter = new GitAdapter(ref.get().getActivity(), commitList);
// Set adapter as specified collection
list.setAdapter(adapter);
} else {
showToastMessage(getActivity().getString(R.string.git_broken), Snackbar.LENGTH_SHORT);
ref.get().showToastMessage(ref.get().getActivity().getString(
R.string.git_broken), Snackbar.LENGTH_SHORT);
}
}

View File

@ -1,5 +1,6 @@
package com.reicast.emulator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@ -134,7 +135,7 @@ public class GL2JNIActivity extends Activity {
new int[][] { p1periphs, p2periphs, p3periphs, p4periphs });
int joys[] = InputDevice.getDeviceIds();
for (int joy: joys) {
String descriptor = null;
String descriptor;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
descriptor = InputDevice.getDevice(joy).getDescriptor();
} else {
@ -247,6 +248,7 @@ public class GL2JNIActivity extends Activity {
fpsPop.update(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
@SuppressLint("RtlHardcoded")
public void toggleVmu() {
boolean showFloating = !prefs.getBoolean(Config.pref_vmu, false);
if (showFloating) {
@ -305,14 +307,14 @@ public class GL2JNIActivity extends Activity {
private boolean showMenu() {
if (popUp != null) {
if (!menu.dismissPopUps()) {
if (menu.dismissPopUps()) {
popUp.dismiss();
} else {
if (!popUp.isShowing()) {
displayPopUp(popUp);
} else {
popUp.dismiss();
}
} else {
popUp.dismiss();
}
}
return true;
@ -433,7 +435,7 @@ public class GL2JNIActivity extends Activity {
boolean rav = false;
for (int i = 0; i < pad.map[playerNum].length; i += 2) {
if (pad.map[playerNum][i + 0] == kc) {
if (pad.map[playerNum][i] == kc) {
if (down)
GL2JNIView.kcode_raw[playerNum] &= ~pad.map[playerNum][i + 1];
else
@ -509,10 +511,6 @@ public class GL2JNIActivity extends Activity {
return super.onKeyDown(keyCode, event);
}
public GL2JNIView getGameView() {
return mView;
}
@Override
protected void onPause() {
super.onPause();

View File

@ -1,5 +1,6 @@
package com.reicast.emulator;
import android.annotation.SuppressLint;
import android.app.NativeActivity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@ -136,7 +137,7 @@ public class GL2JNINative extends NativeActivity {
new int[][] { p1periphs, p2periphs, p3periphs, p4periphs });
int joys[] = InputDevice.getDeviceIds();
for (int joy : joys) {
String descriptor = descriptor = InputDevice.getDevice(joy).getDescriptor();
String descriptor = InputDevice.getDevice(joy).getDescriptor();
Log.d("reicast", "InputDevice ID: " + joy);
Log.d("reicast", "InputDevice Name: " + InputDevice.getDevice(joy).getName());
Log.d("reicast", "InputDevice Descriptor: " + descriptor);
@ -242,6 +243,7 @@ public class GL2JNINative extends NativeActivity {
return pad;
}
@SuppressLint("RtlHardcoded")
public void displayFPS() {
fpsPop.showAtLocation(mView, Gravity.TOP | Gravity.LEFT, 20, 20);
fpsPop.update(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
@ -305,14 +307,14 @@ public class GL2JNINative extends NativeActivity {
private boolean showMenu() {
if (popUp != null) {
if (!menu.dismissPopUps()) {
if (menu.dismissPopUps()) {
popUp.dismiss();
} else {
if (!popUp.isShowing()) {
displayPopUp(popUp);
} else {
popUp.dismiss();
}
} else {
popUp.dismiss();
}
}
return true;
@ -436,7 +438,7 @@ public class GL2JNINative extends NativeActivity {
boolean rav = false;
for (int i = 0; i < pad.map[playerNum].length; i += 2) {
if (pad.map[playerNum][i + 0] == kc) {
if (pad.map[playerNum][i] == kc) {
if (down)
GL2JNIView.kcode_raw[playerNum] &= ~pad.map[playerNum][i + 1];
else
@ -474,7 +476,7 @@ public class GL2JNINative extends NativeActivity {
public boolean OnNativeKeyPress(int device, int keyCode, int action, int metaState) {
Integer playerNum = pad.playerNumX.get(device);
if (playerNum != null && playerNum != -1) {
if (playerNum != -1) {
String id = pad.portId[playerNum];
if (action == KeyEvent.ACTION_DOWN) {
if (keyCode == prefs.getInt(Gamepad.pref_button_l + id, KeyEvent.KEYCODE_BUTTON_L1))
@ -500,10 +502,9 @@ public class GL2JNINative extends NativeActivity {
// public boolean OnNativeMotion(int device, int source, int action, int x,
// int y, boolean newEvent) {
public boolean OnNativeMotion(int device, int source, int action, int x,
int y) {
public boolean OnNativeMotion(int device, int source, int action, int x, int y) {
Integer playerNum = pad.playerNumX.get(device);
if (playerNum != null && playerNum != -1) {
if (playerNum != -1) {
Log.d("reicast", playerNum + " - " + device + ": " + source);
// if (newEvent && source == Gamepad.Xperia_Touchpad) {
if (source == Gamepad.Xperia_Touchpad) {
@ -526,8 +527,8 @@ public class GL2JNINative extends NativeActivity {
// The y-axis is inverted from normal layout
// Imagine it as a small MacBook touch mouse
GL2JNIView.jx[playerNum] = (int) (x * 126);
GL2JNIView.jy[playerNum] = (int) (y * 126);
GL2JNIView.jx[playerNum] = x * 126;
GL2JNIView.jy[playerNum] = y * 126;
mView.pushInput();
return true;
}
@ -535,10 +536,6 @@ public class GL2JNINative extends NativeActivity {
return false;
}
public GL2JNIView getGameView() {
return mView;
}
@Override
protected void onPause() {
super.onPause();

View File

@ -14,6 +14,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
@ -64,7 +65,6 @@ public class MainActivity extends AppCompatActivity implements
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
getWindow().getDecorView().setSystemUiVisibility(
// View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
@ -152,6 +152,7 @@ public class MainActivity extends AppCompatActivity implements
}
};
//noinspection deprecation
drawer.setDrawerListener(toggle);
toggle.syncState();
@ -262,7 +263,6 @@ public class MainActivity extends AppCompatActivity implements
getSupportFragmentManager().beginTransaction().replace(
R.id.fragment_container, optsFrag, "OPTIONS_FRAG").commit();
setTitle(R.string.settings);
return;
}
/**
@ -327,8 +327,7 @@ public class MainActivity extends AppCompatActivity implements
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Fragment fragment = (FileBrowser) getSupportFragmentManager()
.findFragmentByTag("MAIN_BROWSER");
Fragment fragment = getSupportFragmentManager().findFragmentByTag("MAIN_BROWSER");
if (fragment != null && fragment.isVisible()) {
boolean readyToQuit = true;
if (fragment.getArguments() != null) {
@ -380,9 +379,8 @@ public class MainActivity extends AppCompatActivity implements
super.onPostCreate(savedInstanceState);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

View File

@ -75,7 +75,7 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
initializeDefaults();
}
public void setGameID(String id) {
private void setGameID(String id) {
this.gameId = id;
}
@ -83,7 +83,7 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
protected String doInBackground(String... params) {
String filename = game_name = params[0];
if (isNetworkAvailable() && mPrefs.getBoolean(Config.pref_gamedetails, false)) {
String xmlUrl = "";
String xmlUrl;
if (gameId != null) {
xmlUrl = "http://legacy.thegamesdb.net/api/GetGame.php?platform=sega+dreamcast&id=" + gameId;
} else {
@ -187,6 +187,7 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
game_icon = new BitmapDrawable(
mContext.get().getResources(), gameImage);
} else {
//noinspection deprecation
game_icon = new BitmapDrawable(gameImage);
}
((ImageView) childview.get().findViewById(
@ -235,18 +236,6 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
}
}
public Drawable getGameIcon() {
return game_icon;
}
public String getGameTitle() {
return game_name;
}
public String getGameDetails() {
return game_details;
}
private Document getDomElement(String xml) {
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@ -339,9 +328,7 @@ public class XMLParser extends AsyncTask<String, Integer, String> {
Bitmap bitmap = BitmapFactory.decodeStream(bis, null, options);
bis.close();
im.close();
bis = null;
im = null;
OutputStream fOut = null;
OutputStream fOut;
if (!file.getParentFile().exists()) {
file.getParentFile().mkdir();
}

View File

@ -352,9 +352,9 @@ public class GL2JNIView extends GLSurfaceView
int pre = 255;
if (y>vjoy[j][1] && y<=(vjoy[j][1]+vjoy[j][3]))
if (y > vjoy[j][1] && y <= (vjoy[j][1]+vjoy[j][3]))
{
if (vjoy[j][4]>=-2)
if (vjoy[j][4] >= -2)
{
if (vjoy[j][5]==0)
if (!editVjoyMode && touchVibrationEnabled)
@ -363,7 +363,7 @@ public class GL2JNIView extends GLSurfaceView
}
if (vjoy[j][4]==-3)
if (vjoy[j][4] == -3)
{
if (editVjoyMode) {
selectedVjoyElement = 5; // Analog
@ -375,39 +375,35 @@ public class GL2JNIView extends GLSurfaceView
JNIdc.vjoy(j+1, vjoy[j+1][0], vjoy[j+1][1] , vjoy[j+1][2], vjoy[j+1][3]);
anal_id=event.getPointerId(i);
}
}
else if (vjoy[j][4]==-4);
else if(vjoy[j][4]==-1) {
if (editVjoyMode) {
selectedVjoyElement = 3; // Left Trigger
resetEditMode();
} else if (vjoy[j][4] != -4) {
if (vjoy[j][4] == -1) {
if (editVjoyMode) {
selectedVjoyElement = 3; // Left Trigger
resetEditMode();
} else {
lt[0] = pre;
lt_id = event.getPointerId(i);
}
} else if (vjoy[j][4] == -2) {
if (editVjoyMode) {
selectedVjoyElement = 4; // Right Trigger
resetEditMode();
} else {
rt[0] = pre;
rt_id = event.getPointerId(i);
}
} else {
lt[0]=pre;
lt_id=event.getPointerId(i);
if (editVjoyMode) {
selectedVjoyElement = getElementIdFromButtonId(j);
resetEditMode();
} else
rv &= ~(int) vjoy[j][4];
}
}
else if (vjoy[j][4]==-2) {
if (editVjoyMode) {
selectedVjoyElement = 4; // Right Trigger
resetEditMode();
} else{
rt[0]=pre;
rt_id=event.getPointerId(i);
}
}
else {
if (editVjoyMode) {
selectedVjoyElement = getElementIdFromButtonId(j);
resetEditMode();
} else
rv&=~(int)vjoy[j][4];
}
}
}
}
}
else
{
} else {
if (x<vjoy[11][0])
x=vjoy[11][0];
else if (x>(vjoy[11][0]+vjoy[11][2]))

View File

@ -1,5 +1,6 @@
package com.reicast.emulator.emu;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@ -44,12 +45,12 @@ public class OnScreenMenu {
public OnScreenMenu(Activity context, SharedPreferences prefs) {
if (context instanceof GL2JNINative) {
this.mContext = (GL2JNINative) context;
this.mContext = context;
}
if (context instanceof GL2JNIActivity) {
this.mContext = (GL2JNIActivity) context;
this.mContext = context;
}
popups = new Vector<PopupWindow>();
popups = new Vector<>();
if (prefs != null) {
masteraudio = !Emulator.nosound;
audio = masteraudio;
@ -68,7 +69,7 @@ public class OnScreenMenu {
});
}
void displayDebugPopup(final PopupWindow popUp) {
private void displayDebugPopup() {
if (mContext instanceof GL2JNINative) {
((GL2JNINative) mContext).displayDebug(new DebugPopup(mContext));
}
@ -114,8 +115,9 @@ public class OnScreenMenu {
public class DebugPopup extends PopupWindow {
public DebugPopup(Context c) {
DebugPopup(Context c) {
super(c);
//noinspection deprecation
setBackgroundDrawable(new BitmapDrawable());
View shell = mContext.getLayoutInflater().inflate(R.layout.menu_popup_debug, null);
@ -171,7 +173,7 @@ public class OnScreenMenu {
}
}
void displayConfigPopup(final PopupWindow popUp) {
private void displayConfigPopup() {
if (mContext instanceof GL2JNINative) {
((GL2JNINative) mContext).displayConfig(new ConfigPopup(mContext));
}
@ -189,8 +191,9 @@ public class OnScreenMenu {
private Button fdown;
private Button fup;
public ConfigPopup(Context c) {
ConfigPopup(Context c) {
super(c);
//noinspection deprecation
setBackgroundDrawable(new BitmapDrawable());
View shell = mContext.getLayoutInflater().inflate(R.layout.menu_popup_config, null);
@ -471,7 +474,8 @@ public class OnScreenMenu {
private LinearLayout vmuIcon;
LinearLayout.LayoutParams params;
private LinearLayout.LayoutParams setVmuParams() {
@SuppressLint("RtlHardcoded")
private LinearLayout.LayoutParams setVmuParams() {
int vpX = getPixelsFromDp(72, mContext);
int vpY = getPixelsFromDp(52, mContext);
LinearLayout.LayoutParams vmuParams = new LinearLayout.LayoutParams(
@ -484,6 +488,7 @@ public class OnScreenMenu {
public MainPopup(Context c) {
super(c);
//noinspection deprecation
setBackgroundDrawable(new BitmapDrawable());
View shell = mContext.getLayoutInflater().inflate(R.layout.menu_popup_main, null);
@ -515,7 +520,7 @@ public class OnScreenMenu {
OnClickListener clickOptions = new OnClickListener() {
public void onClick(View v) {
displayConfigPopup(MainPopup.this);
displayConfigPopup();
popups.remove(MainPopup.this);
dismiss();
}
@ -525,7 +530,7 @@ public class OnScreenMenu {
OnClickListener clickDebugging = new OnClickListener() {
public void onClick(View v) {
displayDebugPopup(MainPopup.this);
displayDebugPopup();
popups.remove(MainPopup.this);
dismiss();
}
@ -552,11 +557,11 @@ public class OnScreenMenu {
OnClickListener clickExit = new OnClickListener() {
public void onClick(View v) {
if (Config.externalIntent) {
((Activity) mContext).finish();
mContext.finish();
} else {
Intent inte = new Intent(mContext, MainActivity.class);
mContext.startActivity(inte);
((Activity) mContext).finish();
mContext.finish();
}
}
};

View File

@ -20,7 +20,7 @@ public class Gamepad {
public static final String pref_player2 = "device_descriptor_player_2";
public static final String pref_player3 = "device_descriptor_player_3";
public static final String pref_player4 = "device_descriptor_player_4";
public static final String pref_pad = "controller";
private static final String pref_pad = "controller";
public static final String pref_mic = "mic_plugged_in";
@ -91,70 +91,70 @@ public class Gamepad {
public int[] getConsoleController() {
return new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_U, key_CONT_X,
OuyaController.BUTTON_Y, key_CONT_Y,
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_U, key_CONT_X,
OuyaController.BUTTON_Y, key_CONT_Y,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
getStartButtonCode(), key_CONT_START,
getSelectButtonCode(), getSelectButtonCode()
getStartButtonCode(), key_CONT_START,
getSelectButtonCode(), getSelectButtonCode()
// Redundant, but verifies it is mapped properly
};
}
public int[] getOUYAController() {
return new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_U, key_CONT_X,
OuyaController.BUTTON_Y, key_CONT_Y,
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_U, key_CONT_X,
OuyaController.BUTTON_Y, key_CONT_Y,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
getStartButtonCode(), key_CONT_START,
OuyaController.BUTTON_R3, key_CONT_START
getStartButtonCode(), key_CONT_START,
OuyaController.BUTTON_R3, key_CONT_START
};
}
public int[] getMogaController() {
return new int[] {
KeyEvent.KEYCODE_BUTTON_A, key_CONT_A,
KeyEvent.KEYCODE_BUTTON_B, key_CONT_B,
KeyEvent.KEYCODE_BUTTON_X, key_CONT_X,
KeyEvent.KEYCODE_BUTTON_Y, key_CONT_Y,
KeyEvent.KEYCODE_BUTTON_A, key_CONT_A,
KeyEvent.KEYCODE_BUTTON_B, key_CONT_B,
KeyEvent.KEYCODE_BUTTON_X, key_CONT_X,
KeyEvent.KEYCODE_BUTTON_Y, key_CONT_Y,
KeyEvent.KEYCODE_DPAD_UP, key_CONT_DPAD_UP,
KeyEvent.KEYCODE_DPAD_DOWN, key_CONT_DPAD_DOWN,
KeyEvent.KEYCODE_DPAD_LEFT, key_CONT_DPAD_LEFT,
KeyEvent.KEYCODE_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
KeyEvent.KEYCODE_DPAD_UP, key_CONT_DPAD_UP,
KeyEvent.KEYCODE_DPAD_DOWN, key_CONT_DPAD_DOWN,
KeyEvent.KEYCODE_DPAD_LEFT, key_CONT_DPAD_LEFT,
KeyEvent.KEYCODE_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
getStartButtonCode(), key_CONT_START,
getSelectButtonCode(), getSelectButtonCode()
getStartButtonCode(), key_CONT_START,
getSelectButtonCode(), getSelectButtonCode()
};
}
public int[] setModifiedKeys(String id, int playerNum, SharedPreferences mPrefs) {
private int[] setModifiedKeys(String id, SharedPreferences mPrefs) {
return new int[] {
mPrefs.getInt(pref_button_a + id, OuyaController.BUTTON_O), key_CONT_A,
mPrefs.getInt(pref_button_b + id, OuyaController.BUTTON_A), key_CONT_B,
mPrefs.getInt(pref_button_x + id, OuyaController.BUTTON_U), key_CONT_X,
mPrefs.getInt(pref_button_y + id, OuyaController.BUTTON_Y), key_CONT_Y,
mPrefs.getInt(pref_button_a + id, OuyaController.BUTTON_O), key_CONT_A,
mPrefs.getInt(pref_button_b + id, OuyaController.BUTTON_A), key_CONT_B,
mPrefs.getInt(pref_button_x + id, OuyaController.BUTTON_U), key_CONT_X,
mPrefs.getInt(pref_button_y + id, OuyaController.BUTTON_Y), key_CONT_Y,
mPrefs.getInt(pref_dpad_up + id, OuyaController.BUTTON_DPAD_UP), key_CONT_DPAD_UP,
mPrefs.getInt(pref_dpad_down + id, OuyaController.BUTTON_DPAD_DOWN), key_CONT_DPAD_DOWN,
mPrefs.getInt(pref_dpad_left + id, OuyaController.BUTTON_DPAD_LEFT), key_CONT_DPAD_LEFT,
mPrefs.getInt(pref_dpad_right + id, OuyaController.BUTTON_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
mPrefs.getInt(pref_dpad_up + id, OuyaController.BUTTON_DPAD_UP), key_CONT_DPAD_UP,
mPrefs.getInt(pref_dpad_down + id, OuyaController.BUTTON_DPAD_DOWN), key_CONT_DPAD_DOWN,
mPrefs.getInt(pref_dpad_left + id, OuyaController.BUTTON_DPAD_LEFT), key_CONT_DPAD_LEFT,
mPrefs.getInt(pref_dpad_right + id, OuyaController.BUTTON_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
mPrefs.getInt(pref_button_start + id, getStartButtonCode()), key_CONT_START,
mPrefs.getInt(pref_button_select + id, getSelectButtonCode()), getSelectButtonCode()
mPrefs.getInt(pref_button_start + id, getStartButtonCode()), key_CONT_START,
mPrefs.getInt(pref_button_select + id, getSelectButtonCode()), getSelectButtonCode()
};
}
@ -177,7 +177,7 @@ public class Gamepad {
}
}
public int getStartButtonCode() {
private int getStartButtonCode() {
return KeyEvent.KEYCODE_BUTTON_START;
}
@ -192,7 +192,7 @@ public class Gamepad {
}
public void setCustomMapping(String id, int playerNum, SharedPreferences prefs) {
map[playerNum] = setModifiedKeys(id, playerNum, prefs);
map[playerNum] = setModifiedKeys(id, prefs);
}
public void initJoyStickLayout(int playerNum) {
@ -203,14 +203,12 @@ public class Gamepad {
}
public void runCompatibilityMode(int joy, SharedPreferences prefs) {
for (int n = 0; n < 4; n++) {
if (compat[n]) {
String id = portId[n];
joystick[n] = prefs.getBoolean(Gamepad.pref_js_merged + id, false);
getCompatibilityMap(n, portId[n], prefs);
initJoyStickLayout(n);
if (compat[joy]) {
String id = portId[joy];
joystick[joy] = prefs.getBoolean(Gamepad.pref_js_merged + id, false);
getCompatibilityMap(joy, portId[joy], prefs);
initJoyStickLayout(joy);
}
}
}
public void fullCompatibilityMode(SharedPreferences prefs) {
@ -222,7 +220,7 @@ public class Gamepad {
public void getCompatibilityMap(int playerNum, String id, SharedPreferences prefs) {
name[playerNum] = prefs.getInt(Gamepad.pref_pad + id, -1);
if (name[playerNum] != -1) {
map[playerNum] = setModifiedKeys(id, playerNum, prefs);
map[playerNum] = setModifiedKeys(id, prefs);
}
}
}

View File

@ -9,14 +9,14 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class SipEmulator extends Thread {
static final String TAG = "SipEmulator";
private static final String TAG = "SipEmulator";
//one second of audio data in bytes
static final int BUFFER_SIZE = 22050;
private static final int BUFFER_SIZE = 22050;
//this needs to get set to the amount the mic normally sends per data request
//...cant be bigger than a maple packet
// 240 16 (or 14) bit samples
static final int ONE_BLIP_SIZE = 480; //ALSO DEFINED IN maple_devs.h
private static final int ONE_BLIP_SIZE = 480; //ALSO DEFINED IN maple_devs.h
private AudioRecord record;
private ConcurrentLinkedQueue<byte[]> bytesReadBuffer;
@ -48,7 +48,7 @@ public class SipEmulator extends Thread {
AudioFormat.ENCODING_PCM_16BIT,
BUFFER_SIZE);
bytesReadBuffer = new ConcurrentLinkedQueue<byte[]>();
bytesReadBuffer = new ConcurrentLinkedQueue<>();
continueRecording = false;
firstGet = true;

View File

@ -16,35 +16,32 @@ public class VJoy {
public static final int key_CONT_Y = 0x0200;
public static final int key_CONT_X = 0x0400;
public static final int LAYER_TYPE_SOFTWARE = 1;
public static final int LAYER_TYPE_HARDWARE = 2;
public static int VJoyCount = 13;
public static float[][] baseVJoy() {
return new float[][] {
new float[] { 24+0, 24+64, 64,64, VJoy.key_CONT_DPAD_LEFT, 0},
new float[] { 24+64, 24+0, 64,64, VJoy.key_CONT_DPAD_UP, 0},
new float[] { 24+128, 24+64, 64,64, VJoy.key_CONT_DPAD_RIGHT, 0},
new float[] { 24+64, 24+128, 64,64, VJoy.key_CONT_DPAD_DOWN, 0},
new float[] { 24, 24+64, 64,64, VJoy.key_CONT_DPAD_LEFT, 0},
new float[] { 24+64, 24, 64,64, VJoy.key_CONT_DPAD_UP, 0},
new float[] { 24+128, 24+64, 64,64, VJoy.key_CONT_DPAD_RIGHT, 0},
new float[] { 24+64, 24+128, 64,64, VJoy.key_CONT_DPAD_DOWN, 0},
new float[] { 440+0, 280+64, 64,64, VJoy.key_CONT_X, 0},
new float[] { 440+64, 280+0, 64,64, VJoy.key_CONT_Y, 0},
new float[] { 440+128, 280+64, 64,64, VJoy.key_CONT_B, 0},
new float[] { 440+64, 280+128, 64,64, VJoy.key_CONT_A, 0},
new float[] { 440, 280+64, 64,64, VJoy.key_CONT_X, 0},
new float[] { 440+64, 280, 64,64, VJoy.key_CONT_Y, 0},
new float[] { 440+128, 280+64, 64,64, VJoy.key_CONT_B, 0},
new float[] { 440+64, 280+128,64,64, VJoy.key_CONT_A, 0},
new float[] { 320-32, 360+32, 64,64, VJoy.key_CONT_START, 0},
new float[] { 320-32, 360+32, 64,64, VJoy.key_CONT_START, 0},
new float[] { 440, 200, 90,64, -1, 0},
new float[] { 542, 200, 90,64, -2, 0},
new float[] { 440, 200, 90,64, -1, 0},
new float[] { 542, 200, 90,64, -2, 0},
new float[] { 0, 128+224, 128,128, -3, 0},
new float[] { 96, 320, 32,32, -4, 0},
new float[] { 0, 128+224,128,128,-3, 0},
new float[] { 96, 320, 32,32, -4, 0},
new float[] { 20+0 , 288+0 , 64,64, key_CONT_DPAD_LEFT|key_CONT_DPAD_UP, 0},
new float[] { 20+128, 288+0 , 64,64, key_CONT_DPAD_RIGHT|key_CONT_DPAD_UP, 0},
new float[] { 20+0 , 288+128, 64,64, key_CONT_DPAD_LEFT|key_CONT_DPAD_DOWN, 0},
new float[] { 20+128, 288+128, 64,64, key_CONT_DPAD_RIGHT|key_CONT_DPAD_DOWN, 0},
new float[] { 20, 288, 64,64, key_CONT_DPAD_LEFT|key_CONT_DPAD_UP, 0},
new float[] { 20+128, 288, 64,64, key_CONT_DPAD_RIGHT|key_CONT_DPAD_UP, 0},
new float[] { 20, 288+128,64,64, key_CONT_DPAD_LEFT|key_CONT_DPAD_DOWN, 0},
new float[] { 20+128, 288+128,64,64, key_CONT_DPAD_RIGHT|key_CONT_DPAD_DOWN, 0},
};
}
@ -81,28 +78,45 @@ public class VJoy {
public static float[][] getVjoy_d(float[][] vjoy_d_custom) {
return new float[][] {
new float[] { 20+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT},
new float[] { 20+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_UP},
new float[] { 20+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_RIGHT},
new float[] { 20+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_DOWN},
new float[] { 20*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT},
new float[] { 20+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_UP},
new float[] { 20+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_RIGHT},
new float[] { 20+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_DOWN},
new float[] { 448+0*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_X},
new float[] { 448+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+0*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_Y},
new float[] { 448+128*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_B},
new float[] { 448+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+128*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_A},
new float[] { 448*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][1],
64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_X},
new float[] { 448+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288*vjoy_d_custom[1][2]+vjoy_d_custom[1][1],
64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_Y},
new float[] { 448+128*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][1],
64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_B},
new float[] { 448+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+128*vjoy_d_custom[1][2]+vjoy_d_custom[1][1],
64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_A},
new float[] { 320-32+vjoy_d_custom[2][0], 288+128+vjoy_d_custom[2][1], 64*vjoy_d_custom[2][2],64*vjoy_d_custom[2][2], key_CONT_START},
new float[] { 320-32+vjoy_d_custom[2][0], 288+128+vjoy_d_custom[2][1],
64*vjoy_d_custom[2][2],64*vjoy_d_custom[2][2], key_CONT_START},
new float[] { 440+vjoy_d_custom[3][0], 200+vjoy_d_custom[3][1], 90*vjoy_d_custom[3][2],64*vjoy_d_custom[3][2], -1},
new float[] { 542+vjoy_d_custom[4][0], 200+vjoy_d_custom[4][1], 90*vjoy_d_custom[4][2],64*vjoy_d_custom[4][2], -2},
new float[] { 440+vjoy_d_custom[3][0], 200+vjoy_d_custom[3][1],
90*vjoy_d_custom[3][2],64*vjoy_d_custom[3][2], -1},
new float[] { 542+vjoy_d_custom[4][0], 200+vjoy_d_custom[4][1],
90*vjoy_d_custom[4][2],64*vjoy_d_custom[4][2], -2},
new float[] { 16+vjoy_d_custom[5][0], 24+32+vjoy_d_custom[5][1], 128*vjoy_d_custom[5][2],128*vjoy_d_custom[5][2], -3},
new float[] { 96+vjoy_d_custom[5][0], 320+vjoy_d_custom[5][1], 32*vjoy_d_custom[5][2],32*vjoy_d_custom[5][2], -4},
new float[] { 16+vjoy_d_custom[5][0], 24+32+vjoy_d_custom[5][1],
128*vjoy_d_custom[5][2],128*vjoy_d_custom[5][2],-3},
new float[] { 96+vjoy_d_custom[5][0], 320+vjoy_d_custom[5][1],
32*vjoy_d_custom[5][2],32*vjoy_d_custom[5][2], -4},
new float[] { 20+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT|key_CONT_DPAD_UP},
new float[] { 20+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_RIGHT|key_CONT_DPAD_UP},
new float[] { 20+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT|key_CONT_DPAD_DOWN},
new float[] { 20+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_RIGHT|key_CONT_DPAD_DOWN},
new float[] { 20*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT|key_CONT_DPAD_UP},
new float[] { 20+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_RIGHT|key_CONT_DPAD_UP},
new float[] { 20*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT|key_CONT_DPAD_DOWN},
new float[] { 20+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][1],
64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_RIGHT|key_CONT_DPAD_DOWN},
};
}