mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 14:46:49 +01:00
[Android] Reduce code redundancy
This commit is contained in:
parent
937caea1c9
commit
a5b72abf2c
@ -479,7 +479,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
return super.dispatchKeyEvent(event);
|
return super.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
int action = 0;
|
int action;
|
||||||
|
|
||||||
switch (event.getAction())
|
switch (event.getAction())
|
||||||
{
|
{
|
||||||
@ -501,8 +501,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
InputDevice input = event.getDevice();
|
InputDevice input = event.getDevice();
|
||||||
boolean handled = NativeLibrary.onGamePadEvent(input.getDescriptor(), event.getKeyCode(), action);
|
return NativeLibrary.onGamePadEvent(input.getDescriptor(), event.getKeyCode(), action);
|
||||||
return handled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,7 @@ public final class MotionAlertDialog extends AlertDialog
|
|||||||
private final Preference inputPref;
|
private final Preference inputPref;
|
||||||
|
|
||||||
private boolean firstEvent = true;
|
private boolean firstEvent = true;
|
||||||
private final ArrayList<Float> m_values = new ArrayList<Float>();
|
private final ArrayList<Float> m_values = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -105,19 +105,13 @@ public final class MotionAlertDialog extends AlertDialog
|
|||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event)
|
public boolean dispatchKeyEvent(KeyEvent event)
|
||||||
{
|
{
|
||||||
if (onKeyDown(event.getKeyCode(), event))
|
return onKeyDown(event.getKeyCode(), event) || super.dispatchKeyEvent(event);
|
||||||
return true;
|
|
||||||
|
|
||||||
return super.dispatchKeyEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent event)
|
public boolean dispatchGenericMotionEvent(MotionEvent event)
|
||||||
{
|
{
|
||||||
if (onMotionEvent(event))
|
return onMotionEvent(event) || super.dispatchGenericMotionEvent(event);
|
||||||
return true;
|
|
||||||
|
|
||||||
return super.dispatchGenericMotionEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,15 +26,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
|
|
||||||
private SharedPreferences mPreferences;
|
private SharedPreferences mPreferences;
|
||||||
|
|
||||||
private SurfaceView mSurfaceView;
|
|
||||||
private Surface mSurface;
|
private Surface mSurface;
|
||||||
|
|
||||||
private InputOverlay mInputOverlay;
|
private InputOverlay mInputOverlay;
|
||||||
|
|
||||||
private Thread mEmulationThread;
|
private Thread mEmulationThread;
|
||||||
|
|
||||||
private String mPath;
|
|
||||||
|
|
||||||
private boolean mEmulationStarted;
|
private boolean mEmulationStarted;
|
||||||
private boolean mEmulationRunning;
|
private boolean mEmulationRunning;
|
||||||
|
|
||||||
@ -70,15 +67,15 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
mPath = getArguments().getString(ARGUMENT_GAME_PATH);
|
String path = getArguments().getString(ARGUMENT_GAME_PATH);
|
||||||
NativeLibrary.SetFilename(mPath);
|
NativeLibrary.SetFilename(path);
|
||||||
|
|
||||||
View contents = inflater.inflate(R.layout.fragment_emulation, container, false);
|
View contents = inflater.inflate(R.layout.fragment_emulation, container, false);
|
||||||
|
|
||||||
mSurfaceView = (SurfaceView) contents.findViewById(R.id.surface_emulation);
|
SurfaceView surfaceView = (SurfaceView) contents.findViewById(R.id.surface_emulation);
|
||||||
mInputOverlay = (InputOverlay) contents.findViewById(R.id.surface_input_overlay);
|
mInputOverlay = (InputOverlay) contents.findViewById(R.id.surface_input_overlay);
|
||||||
|
|
||||||
mSurfaceView.getHolder().addCallback(this);
|
surfaceView.getHolder().addCallback(this);
|
||||||
|
|
||||||
// If the input overlay was previously disabled, then don't show it.
|
// If the input overlay was previously disabled, then don't show it.
|
||||||
if (mInputOverlay != null)
|
if (mInputOverlay != null)
|
||||||
|
@ -5,6 +5,7 @@ import android.content.ContentValues;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import org.dolphinemu.dolphinemu.BuildConfig;
|
import org.dolphinemu.dolphinemu.BuildConfig;
|
||||||
import org.dolphinemu.dolphinemu.utils.Log;
|
import org.dolphinemu.dolphinemu.utils.Log;
|
||||||
@ -39,7 +40,7 @@ public final class GameProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
|
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
|
||||||
{
|
{
|
||||||
Log.info("[GameProvider] Querying URI: " + uri);
|
Log.info("[GameProvider] Querying URI: " + uri);
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ public final class GameProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri)
|
public String getType(@NonNull Uri uri)
|
||||||
{
|
{
|
||||||
Log.verbose("[GameProvider] Getting MIME type for URI: " + uri);
|
Log.verbose("[GameProvider] Getting MIME type for URI: " + uri);
|
||||||
String lastSegment = uri.getLastPathSegment();
|
String lastSegment = uri.getLastPathSegment();
|
||||||
@ -85,7 +86,7 @@ public final class GameProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri insert(Uri uri, ContentValues values)
|
public Uri insert(@NonNull Uri uri, ContentValues values)
|
||||||
{
|
{
|
||||||
Log.info("[GameProvider] Inserting row at URI: " + uri);
|
Log.info("[GameProvider] Inserting row at URI: " + uri);
|
||||||
|
|
||||||
@ -134,14 +135,14 @@ public final class GameProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String selection, String[] selectionArgs)
|
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs)
|
||||||
{
|
{
|
||||||
Log.error("[GameProvider] Delete operations unsupported. URI: " + uri);
|
Log.error("[GameProvider] Delete operations unsupported. URI: " + uri);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs)
|
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs)
|
||||||
{
|
{
|
||||||
Log.error("[GameProvider] Update operations unsupported. URI: " + uri);
|
Log.error("[GameProvider] Update operations unsupported. URI: " + uri);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -36,8 +36,8 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public final class InputOverlay extends SurfaceView implements OnTouchListener
|
public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
{
|
{
|
||||||
private final Set<InputOverlayDrawableButton> overlayButtons = new HashSet<InputOverlayDrawableButton>();
|
private final Set<InputOverlayDrawableButton> overlayButtons = new HashSet<>();
|
||||||
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<InputOverlayDrawableJoystick>();
|
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes a {@link Bitmap} by a given scale factor
|
* Resizes a {@link Bitmap} by a given scale factor
|
||||||
@ -53,11 +53,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
// Retrieve screen dimensions.
|
// Retrieve screen dimensions.
|
||||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||||
|
|
||||||
Bitmap bitmapResized = Bitmap.createScaledBitmap(bitmap,
|
return Bitmap.createScaledBitmap(bitmap,
|
||||||
(int)(dm.heightPixels * scale),
|
(int)(dm.heightPixels * scale),
|
||||||
(int)(dm.heightPixels * scale),
|
(int)(dm.heightPixels * scale),
|
||||||
true);
|
true);
|
||||||
return bitmapResized;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,8 +60,8 @@ public final class AssetCopyService extends IntentService
|
|||||||
private void copyAsset(String asset, String output, Boolean overwrite)
|
private void copyAsset(String asset, String output, Boolean overwrite)
|
||||||
{
|
{
|
||||||
Log.verbose("[AssetCopyService] Copying File " + asset + " to " + output);
|
Log.verbose("[AssetCopyService] Copying File " + asset + " to " + output);
|
||||||
InputStream in = null;
|
InputStream in;
|
||||||
OutputStream out = null;
|
OutputStream out;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -120,14 +120,12 @@ public final class EGLHelper
|
|||||||
*/
|
*/
|
||||||
public String[] getEGLInfo()
|
public String[] getEGLInfo()
|
||||||
{
|
{
|
||||||
String[] info = {
|
return new String[] {
|
||||||
mGL.glGetString(GL10.GL_VENDOR),
|
mGL.glGetString(GL10.GL_VENDOR),
|
||||||
mGL.glGetString(GL10.GL_VERSION),
|
mGL.glGetString(GL10.GL_VERSION),
|
||||||
mGL.glGetString(GL10.GL_RENDERER),
|
mGL.glGetString(GL10.GL_RENDERER),
|
||||||
mGL.glGetString(GL10.GL_EXTENSIONS),
|
mGL.glGetString(GL10.GL_EXTENSIONS),
|
||||||
};
|
};
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,10 +241,10 @@ public final class EGLHelper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < mEGLConfigs.length; i++)
|
for (EGLConfig mEGLConfig : mEGLConfigs)
|
||||||
{
|
{
|
||||||
int[] attribVal = new int[1];
|
int[] attribVal = new int[1];
|
||||||
boolean ret = mEGL.eglGetConfigAttrib(mDisplay, mEGLConfigs[i], EGL10.EGL_RENDERABLE_TYPE, attribVal);
|
boolean ret = mEGL.eglGetConfigAttrib(mDisplay, mEGLConfig, EGL10.EGL_RENDERABLE_TYPE, attribVal);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
if ((attribVal[0] & EGL_OPENGL_BIT) != 0)
|
if ((attribVal[0] & EGL_OPENGL_BIT) != 0)
|
||||||
|
@ -32,7 +32,7 @@ public class Java_GCAdapter {
|
|||||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||||
{
|
{
|
||||||
UsbDevice dev = (UsbDevice) pair.getValue();
|
UsbDevice dev = pair.getValue();
|
||||||
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
|
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
|
||||||
{
|
{
|
||||||
if (!manager.hasPermission(dev))
|
if (!manager.hasPermission(dev))
|
||||||
@ -58,7 +58,7 @@ public class Java_GCAdapter {
|
|||||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||||
{
|
{
|
||||||
UsbDevice dev = (UsbDevice) pair.getValue();
|
UsbDevice dev = pair.getValue();
|
||||||
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
|
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
|
||||||
{
|
{
|
||||||
if (manager.hasPermission(dev))
|
if (manager.hasPermission(dev))
|
||||||
@ -77,24 +77,21 @@ public class Java_GCAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int Input() {
|
public static int Input() {
|
||||||
int read = usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16);
|
return usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16);
|
||||||
return read;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Output(byte[] rumble) {
|
public static int Output(byte[] rumble) {
|
||||||
int size = usb_con.bulkTransfer(usb_out, rumble, 5, 16);
|
return usb_con.bulkTransfer(usb_out, rumble, 5, 16);
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean OpenAdapter()
|
public static boolean OpenAdapter()
|
||||||
{
|
{
|
||||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||||
Iterator it = devices.entrySet().iterator();
|
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||||
while (it.hasNext())
|
{
|
||||||
|
UsbDevice dev = pair.getValue();
|
||||||
|
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
|
||||||
{
|
{
|
||||||
HashMap.Entry pair = (HashMap.Entry)it.next();
|
|
||||||
UsbDevice dev = (UsbDevice)pair.getValue();
|
|
||||||
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e) {
|
|
||||||
if (manager.hasPermission(dev))
|
if (manager.hasPermission(dev))
|
||||||
{
|
{
|
||||||
usb_con = manager.openDevice(dev);
|
usb_con = manager.openDevice(dev);
|
||||||
|
@ -38,7 +38,7 @@ public class Java_WiimoteAdapter
|
|||||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||||
{
|
{
|
||||||
UsbDevice dev = (UsbDevice) pair.getValue();
|
UsbDevice dev = pair.getValue();
|
||||||
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
||||||
{
|
{
|
||||||
if (!manager.hasPermission(dev))
|
if (!manager.hasPermission(dev))
|
||||||
@ -59,7 +59,7 @@ public class Java_WiimoteAdapter
|
|||||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||||
{
|
{
|
||||||
UsbDevice dev = (UsbDevice) pair.getValue();
|
UsbDevice dev = pair.getValue();
|
||||||
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
||||||
{
|
{
|
||||||
if (manager.hasPermission(dev))
|
if (manager.hasPermission(dev))
|
||||||
@ -114,7 +114,7 @@ public class Java_WiimoteAdapter
|
|||||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||||
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
|
||||||
{
|
{
|
||||||
UsbDevice dev = (UsbDevice) pair.getValue();
|
UsbDevice dev = pair.getValue();
|
||||||
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID)
|
||||||
{
|
{
|
||||||
if (manager.hasPermission(dev))
|
if (manager.hasPermission(dev))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user