Android: Format Java code

This commit is contained in:
Connor McLaughlin 2020-10-24 16:04:27 +10:00
parent 076d3d3479
commit 9a7999f158
11 changed files with 71 additions and 104 deletions

View File

@ -6,8 +6,6 @@ import android.util.Log;
import android.view.Surface;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
public class AndroidHostInterface {
public final static int DISPLAY_ALIGNMENT_TOP_OR_LEFT = 0;
public final static int DISPLAY_ALIGNMENT_CENTER = 1;
@ -72,11 +70,13 @@ public class AndroidHostInterface {
public native void setDisplayAlignment(int alignment);
public native CheatCode[] getCheatList();
public native void setCheatEnabled(int index, boolean enabled);
public native void addOSDMessage(String message, float duration);
public native boolean hasAnyBIOSImages();
public native String importBIOSImage(byte[] data);
static {

View File

@ -2,8 +2,6 @@ package com.github.stenzek.duckstation;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
@ -31,6 +29,7 @@ public class AndroidProgressCallback {
mDialog.setTitle(text);
});
}
public void setStatusText(String text) {
mContext.runOnUiThread(() -> {
mDialog.setMessage(text);

View File

@ -11,7 +11,15 @@ public class CheatCode {
mEnabled = enabled;
}
public int getIndex() { return mIndex; }
public String getName() { return mName; }
public boolean isEnabled() { return mEnabled; }
public int getIndex() {
return mIndex;
}
public String getName() {
return mName;
}
public boolean isEnabled() {
return mEnabled;
}
}

View File

@ -1,31 +1,21 @@
package com.github.stenzek.duckstation;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.hardware.input.InputManager;
import android.os.Bundle;
import android.os.Handler;
import android.util.AndroidException;
import android.util.Log;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.MenuItem;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.appcompat.widget.PopupMenu;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;
/**
@ -253,8 +243,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
AndroidHostInterface.getInstance().setDisplayAlignment(AndroidHostInterface.DISPLAY_ALIGNMENT_CENTER);
}
private void enableFullscreenImmersive()
{
private void enableFullscreenImmersive() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
@ -271,8 +260,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
private void showMenu() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(R.array.emulation_menu, (dialogInterface, i) -> {
switch (i)
{
switch (i) {
case 0: // Quick Load
{
AndroidHostInterface.getInstance().loadState(false, mSaveStateSlot);
@ -333,8 +321,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
builder.setTitle(mGameTitle);
builder.setItems(R.array.emulation_more_menu, (dialogInterface, i) -> {
switch (i)
{
switch (i) {
case 0: // Reset
{
AndroidHostInterface.getInstance().resetSystem();
@ -434,6 +421,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
}
private InputManager.InputDeviceListener mInputDeviceListener;
private void registerInputDeviceListener() {
if (mInputDeviceListener != null)
return;
@ -458,18 +446,19 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
}
};
InputManager inputManager = ((InputManager)getSystemService(Context.INPUT_SERVICE));
InputManager inputManager = ((InputManager) getSystemService(Context.INPUT_SERVICE));
if (inputManager != null)
inputManager.registerInputDeviceListener(mInputDeviceListener, null);
}
private void unregisterInputDeviceListener() {
if (mInputDeviceListener == null)
return;
InputManager inputManager = ((InputManager)getSystemService(Context.INPUT_SERVICE));
InputManager inputManager = ((InputManager) getSystemService(Context.INPUT_SERVICE));
if (inputManager != null)
inputManager.unregisterInputDeviceListener(mInputDeviceListener);
mInputDeviceListener = null;
}
}

View File

@ -1,11 +1,8 @@
package com.github.stenzek.duckstation;
import android.content.Context;
import android.hardware.input.InputManager;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
@ -194,10 +191,7 @@ public class EmulationSurfaceView extends SurfaceView {
if ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
return true;
if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD)
return true;
return false;
return (sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD;
}
public boolean initControllerMapping(String controllerType) {

View File

@ -1,21 +1,14 @@
package com.github.stenzek.duckstation;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.ArraySet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import androidx.preference.PreferenceManager;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
public class GameList {
private Activity mContext;

View File

@ -1,49 +1,34 @@
package com.github.stenzek.duckstation;
import android.Manifest;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.documentfile.provider.DocumentFile;
import androidx.preference.PreferenceManager;
import android.content.Intent;
import androidx.collection.ArraySet;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
import java.util.prefs.Preferences;
import static com.google.android.material.snackbar.Snackbar.make;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_EXTERNAL_STORAGE_PERMISSIONS = 1;
@ -188,7 +173,8 @@ public class MainActivity extends AppCompatActivity {
.setMessage("Failed to get path for the selected file. Please make sure the file is in internal/external storage.\n\n" +
"Tap the overflow button in the directory selector.\nSelect \"Show Internal Storage\".\n" +
"Tap the menu button and select your device name or SD card.")
.setPositiveButton("OK", (dialog, button) -> {})
.setPositiveButton("OK", (dialog, button) -> {
})
.create()
.show();
return null;
@ -205,7 +191,8 @@ public class MainActivity extends AppCompatActivity {
.setMessage("Failed to get path for the selected directory. Please make sure the directory is in internal/external storage.\n\n" +
"Tap the overflow button in the directory selector.\nSelect \"Show Internal Storage\".\n" +
"Tap the menu button and select your device name or SD card.")
.setPositiveButton("OK", (dialog, button) -> {})
.setPositiveButton("OK", (dialog, button) -> {
})
.create()
.show();
return null;
@ -323,7 +310,8 @@ public class MainActivity extends AppCompatActivity {
.setTitle("Missing BIOS Image")
.setMessage("No BIOS image was found in DuckStation's bios directory. Do you with to locate and import a BIOS image now?")
.setPositiveButton("Yes", (dialog, button) -> importBIOSImage())
.setNegativeButton("No", (dialog, button) -> {})
.setNegativeButton("No", (dialog, button) -> {
})
.create()
.show();
@ -362,7 +350,8 @@ public class MainActivity extends AppCompatActivity {
} catch (IOException e) {
new AlertDialog.Builder(this)
.setMessage("Failed to read BIOS image: " + e.getMessage())
.setPositiveButton("OK", (dialog, button) -> {})
.setPositiveButton("OK", (dialog, button) -> {
})
.create()
.show();
return;
@ -372,9 +361,10 @@ public class MainActivity extends AppCompatActivity {
String message = (importResult == null) ? "This BIOS image is invalid, or has already been imported." : ("BIOS '" + importResult + "' imported.");
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("OK", (dialog, button) -> {})
.create()
.show();
.setMessage(message)
.setPositiveButton("OK", (dialog, button) -> {
})
.create()
.show();
}
}

View File

@ -46,6 +46,7 @@ public class SettingsActivity extends AppCompatActivity {
public static class SettingsFragment extends PreferenceFragmentCompat {
private int resourceId;
public SettingsFragment(int resourceId) {
this.resourceId = resourceId;
}

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class TouchscreenControllerAxisView extends View {
@ -84,21 +83,21 @@ public class TouchscreenControllerAxisView extends View {
}
public void setPressed(int pointerId, float pointerX, float pointerY) {
final float dx = pointerX - (float)(getX() + (float)(getWidth() / 2));
final float dy = pointerY - (float)(getY() + (float)(getHeight() / 2));
final float dx = pointerX - (float) (getX() + (float) (getWidth() / 2));
final float dy = pointerY - (float) (getY() + (float) (getHeight() / 2));
// Log.i("SetPressed", String.format("px=%f,py=%f dx=%f,dy=%f", pointerX, pointerY, dx, dy));
final float pointerDistance = Math.max(Math.abs(dx), Math.abs(dy));
final float angle = (float)Math.atan2((double)dy, (double)dx);
final float angle = (float) Math.atan2((double) dy, (double) dx);
final float maxDistance = (float)Math.min((getWidth() - getPaddingLeft() - getPaddingRight()) / 2, (getHeight() - getPaddingTop() - getPaddingBottom()) / 2);
final float maxDistance = (float) Math.min((getWidth() - getPaddingLeft() - getPaddingRight()) / 2, (getHeight() - getPaddingTop() - getPaddingBottom()) / 2);
final float length = Math.min(pointerDistance / maxDistance, 1.0f);
// Log.i("SetPressed", String.format("pointerDist=%f,angle=%f,w=%d,h=%d,maxDist=%f,length=%f", pointerDistance, angle, getWidth(), getHeight(), maxDistance, length));
final float xValue = (float)Math.cos((double)angle) * length;
final float yValue = (float)Math.sin((double)angle) * length;
mDrawXPos = (int)(xValue * maxDistance);
mDrawYPos = (int)(yValue * maxDistance);
final float xValue = (float) Math.cos((double) angle) * length;
final float yValue = (float) Math.sin((double) angle) * length;
mDrawXPos = (int) (xValue * maxDistance);
mDrawYPos = (int) (yValue * maxDistance);
boolean doUpdate = (pointerId != mPointerId || !mPressed || (xValue != mXValue || yValue != mYValue));
mPointerId = pointerId;
@ -128,7 +127,7 @@ public class TouchscreenControllerAxisView extends View {
hostInterface.setControllerButtonState(mControllerIndex, mRightButtonCode, (mXValue >= BUTTON_THRESHOLD));
if (mUpButtonCode >= 0)
hostInterface.setControllerButtonState(mControllerIndex, mUpButtonCode, (mYValue <= -BUTTON_THRESHOLD));
if (mDownButtonCode >= 0)
if (mDownButtonCode >= 0)
hostInterface.setControllerButtonState(mControllerIndex, mDownButtonCode, (mYValue >= BUTTON_THRESHOLD));
}

View File

@ -5,8 +5,6 @@ import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
/**

View File

@ -42,8 +42,7 @@ public class TouchscreenControllerView extends FrameLayout {
removeAllViews();
LayoutInflater inflater = LayoutInflater.from(getContext());
switch (viewType)
{
switch (viewType) {
case "digital":
mMainView = inflater.inflate(R.layout.layout_touchscreen_controller_digital, this, true);
break;
@ -95,7 +94,7 @@ public class TouchscreenControllerView extends FrameLayout {
if (buttonView == null)
return;
int code = AndroidHostInterface.getInstance().getControllerButtonCode(mControllerType, buttonName);
int code = AndroidHostInterface.getControllerButtonCode(mControllerType, buttonName);
Log.i("TouchscreenController", String.format("%s -> %d", buttonName, code));
if (code >= 0) {
@ -112,8 +111,8 @@ public class TouchscreenControllerView extends FrameLayout {
if (axisView == null)
return false;
int xCode = AndroidHostInterface.getInstance().getControllerAxisCode(mControllerType, axisName + "X");
int yCode = AndroidHostInterface.getInstance().getControllerAxisCode(mControllerType, axisName + "Y");
int xCode = AndroidHostInterface.getControllerAxisCode(mControllerType, axisName + "X");
int yCode = AndroidHostInterface.getControllerAxisCode(mControllerType, axisName + "Y");
Log.i("TouchscreenController", String.format("%s -> %d/%d", axisName, xCode, yCode));
if (xCode < 0 && yCode < 0)
return false;
@ -128,10 +127,10 @@ public class TouchscreenControllerView extends FrameLayout {
if (axisView == null)
return false;
int leftCode = AndroidHostInterface.getInstance().getControllerButtonCode(mControllerType, buttonPrefix + "Left");
int rightCode = AndroidHostInterface.getInstance().getControllerButtonCode(mControllerType, buttonPrefix + "Right");
int upCode = AndroidHostInterface.getInstance().getControllerButtonCode(mControllerType, buttonPrefix + "Up");
int downCode = AndroidHostInterface.getInstance().getControllerButtonCode(mControllerType, buttonPrefix + "Down");
int leftCode = AndroidHostInterface.getControllerButtonCode(mControllerType, buttonPrefix + "Left");
int rightCode = AndroidHostInterface.getControllerButtonCode(mControllerType, buttonPrefix + "Right");
int upCode = AndroidHostInterface.getControllerButtonCode(mControllerType, buttonPrefix + "Up");
int downCode = AndroidHostInterface.getControllerButtonCode(mControllerType, buttonPrefix + "Down");
Log.i("TouchscreenController", String.format("%s(ButtonAxis) -> %d,%d,%d,%d", buttonPrefix, leftCode, rightCode, upCode, downCode));
if (leftCode < 0 && rightCode < 0 && upCode < 0 && downCode < 0)
return false;
@ -142,10 +141,8 @@ public class TouchscreenControllerView extends FrameLayout {
}
private boolean handleTouchEvent(MotionEvent event) {
switch (event.getActionMasked())
{
case MotionEvent.ACTION_UP:
{
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP: {
for (TouchscreenControllerButtonView buttonView : mButtonViews) {
buttonView.setPressed(false);
}
@ -160,8 +157,7 @@ public class TouchscreenControllerView extends FrameLayout {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_MOVE:
{
case MotionEvent.ACTION_MOVE: {
Rect rect = new Rect();
final int pointerCount = event.getPointerCount();
final int liftedPointerIndex = (event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) ? event.getActionIndex() : -1;