[Android] Reduce code redundancy

This commit is contained in:
Tyler Dunn 2016-04-21 09:10:56 -04:00
parent 937caea1c9
commit a5b72abf2c
9 changed files with 34 additions and 49 deletions

View File

@ -479,7 +479,7 @@ public final class EmulationActivity extends AppCompatActivity
return super.dispatchKeyEvent(event);
}
int action = 0;
int action;
switch (event.getAction())
{
@ -501,8 +501,7 @@ public final class EmulationActivity extends AppCompatActivity
return false;
}
InputDevice input = event.getDevice();
boolean handled = NativeLibrary.onGamePadEvent(input.getDescriptor(), event.getKeyCode(), action);
return handled;
return NativeLibrary.onGamePadEvent(input.getDescriptor(), event.getKeyCode(), action);
}
@Override

View File

@ -25,7 +25,7 @@ public final class MotionAlertDialog extends AlertDialog
private final Preference inputPref;
private boolean firstEvent = true;
private final ArrayList<Float> m_values = new ArrayList<Float>();
private final ArrayList<Float> m_values = new ArrayList<>();
/**
* Constructor
@ -105,19 +105,13 @@ public final class MotionAlertDialog extends AlertDialog
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
if (onKeyDown(event.getKeyCode(), event))
return true;
return super.dispatchKeyEvent(event);
return onKeyDown(event.getKeyCode(), event) || super.dispatchKeyEvent(event);
}
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event)
{
if (onMotionEvent(event))
return true;
return super.dispatchGenericMotionEvent(event);
return onMotionEvent(event) || super.dispatchGenericMotionEvent(event);
}
/**

View File

@ -26,15 +26,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
private SharedPreferences mPreferences;
private SurfaceView mSurfaceView;
private Surface mSurface;
private InputOverlay mInputOverlay;
private Thread mEmulationThread;
private String mPath;
private boolean mEmulationStarted;
private boolean mEmulationRunning;
@ -70,15 +67,15 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
mPath = getArguments().getString(ARGUMENT_GAME_PATH);
NativeLibrary.SetFilename(mPath);
String path = getArguments().getString(ARGUMENT_GAME_PATH);
NativeLibrary.SetFilename(path);
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);
mSurfaceView.getHolder().addCallback(this);
surfaceView.getHolder().addCallback(this);
// If the input overlay was previously disabled, then don't show it.
if (mInputOverlay != null)

View File

@ -5,6 +5,7 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.support.annotation.NonNull;
import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.utils.Log;
@ -39,7 +40,7 @@ public final class GameProvider extends ContentProvider
}
@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);
@ -60,7 +61,7 @@ public final class GameProvider extends ContentProvider
}
@Override
public String getType(Uri uri)
public String getType(@NonNull Uri uri)
{
Log.verbose("[GameProvider] Getting MIME type for URI: " + uri);
String lastSegment = uri.getLastPathSegment();
@ -85,7 +86,7 @@ public final class GameProvider extends ContentProvider
}
@Override
public Uri insert(Uri uri, ContentValues values)
public Uri insert(@NonNull Uri uri, ContentValues values)
{
Log.info("[GameProvider] Inserting row at URI: " + uri);
@ -134,14 +135,14 @@ public final class GameProvider extends ContentProvider
}
@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);
return 0;
}
@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);
return 0;

View File

@ -36,8 +36,8 @@ import java.util.Set;
*/
public final class InputOverlay extends SurfaceView implements OnTouchListener
{
private final Set<InputOverlayDrawableButton> overlayButtons = new HashSet<InputOverlayDrawableButton>();
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<InputOverlayDrawableJoystick>();
private final Set<InputOverlayDrawableButton> overlayButtons = new HashSet<>();
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<>();
/**
* Resizes a {@link Bitmap} by a given scale factor
@ -53,11 +53,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// Retrieve screen dimensions.
DisplayMetrics dm = context.getResources().getDisplayMetrics();
Bitmap bitmapResized = Bitmap.createScaledBitmap(bitmap,
return Bitmap.createScaledBitmap(bitmap,
(int)(dm.heightPixels * scale),
(int)(dm.heightPixels * scale),
true);
return bitmapResized;
}
/**

View File

@ -60,8 +60,8 @@ public final class AssetCopyService extends IntentService
private void copyAsset(String asset, String output, Boolean overwrite)
{
Log.verbose("[AssetCopyService] Copying File " + asset + " to " + output);
InputStream in = null;
OutputStream out = null;
InputStream in;
OutputStream out;
try
{

View File

@ -120,14 +120,12 @@ public final class EGLHelper
*/
public String[] getEGLInfo()
{
String[] info = {
return new String[] {
mGL.glGetString(GL10.GL_VENDOR),
mGL.glGetString(GL10.GL_VERSION),
mGL.glGetString(GL10.GL_RENDERER),
mGL.glGetString(GL10.GL_EXTENSIONS),
};
return info;
}
/**
@ -243,10 +241,10 @@ public final class EGLHelper
return false;
}
for (int i = 0; i < mEGLConfigs.length; i++)
for (EGLConfig mEGLConfig : mEGLConfigs)
{
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 ((attribVal[0] & EGL_OPENGL_BIT) != 0)

View File

@ -32,7 +32,7 @@ public class Java_GCAdapter {
HashMap<String, UsbDevice> devices = manager.getDeviceList();
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 (!manager.hasPermission(dev))
@ -58,7 +58,7 @@ public class Java_GCAdapter {
HashMap<String, UsbDevice> devices = manager.getDeviceList();
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 (manager.hasPermission(dev))
@ -77,24 +77,21 @@ public class Java_GCAdapter {
}
public static int Input() {
int read = usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16);
return read;
return usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16);
}
public static int Output(byte[] rumble) {
int size = usb_con.bulkTransfer(usb_out, rumble, 5, 16);
return size;
return usb_con.bulkTransfer(usb_out, rumble, 5, 16);
}
public static boolean OpenAdapter()
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
Iterator it = devices.entrySet().iterator();
while (it.hasNext())
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
{
HashMap.Entry pair = (HashMap.Entry)it.next();
UsbDevice dev = (UsbDevice)pair.getValue();
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e) {
UsbDevice dev = pair.getValue();
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
{
if (manager.hasPermission(dev))
{
usb_con = manager.openDevice(dev);

View File

@ -38,7 +38,7 @@ public class Java_WiimoteAdapter
HashMap<String, UsbDevice> devices = manager.getDeviceList();
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 (!manager.hasPermission(dev))
@ -59,7 +59,7 @@ public class Java_WiimoteAdapter
HashMap<String, UsbDevice> devices = manager.getDeviceList();
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 (manager.hasPermission(dev))
@ -114,7 +114,7 @@ public class Java_WiimoteAdapter
HashMap<String, UsbDevice> devices = manager.getDeviceList();
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 (manager.hasPermission(dev))