Skip to content
Permalink
Browse files
Merge pull request #6259 from mahdihijazi/java8
[Android] Enable Java 8 features in Dolphin Java code base
  • Loading branch information
degasus committed Dec 18, 2017
2 parents 4733bbd + e61e4d4 commit 9f9b4bc
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 278 deletions.
@@ -4,6 +4,11 @@ android {
compileSdkVersion 26
buildToolsVersion '26.0.2'

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
// This is important as it will run lint but not abort on error
// Lint has some overly obnoxious "errors" that should really be warnings
@@ -384,14 +384,7 @@ public static void displayAlertMsg(final String alert)
final EmulationActivity emulationActivity = sEmulationActivity.get();
if (emulationActivity != null)
{
emulationActivity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
Toast.makeText(emulationActivity, "Panic Alert: " + alert, Toast.LENGTH_LONG).show();
}
});
emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity, "Panic Alert: " + alert, Toast.LENGTH_LONG).show());
}
else
{
@@ -175,24 +175,13 @@ protected void onCreate(Bundle savedInstanceState)

// Get a handle to the Window containing the UI.
mDecorView = getWindow().getDecorView();
mDecorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{
// Go back to immersive fullscreen mode in 3s
Handler handler = new Handler(getMainLooper());
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
enableFullscreenImmersive();
}
},
3000 /* 3s */);
}
mDecorView.setOnSystemUiVisibilityChangeListener(visibility ->
{
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{
// Go back to immersive fullscreen mode in 3s
Handler handler = new Handler(getMainLooper());
handler.postDelayed(this::enableFullscreenImmersive, 3000 /* 3s */);
}
});
// Set these options now so that the SurfaceView the game renders into is the right size.
@@ -251,14 +240,7 @@ public void onError()

Animations.fadeViewOut(mImageView)
.setStartDelay(2000)
.withEndAction(new Runnable()
{
@Override
public void run()
{
mImageView.setVisibility(View.GONE);
}
});
.withEndAction(() -> mImageView.setVisibility(View.GONE));
}
else
{
@@ -328,35 +310,27 @@ private void toggleMenu()
}
}

public void exitWithAnimation()
{
runOnUiThread(new Runnable()
public void exitWithAnimation() {
runOnUiThread(() ->
{
@Override
public void run()
{
Picasso.with(EmulationActivity.this)
.invalidate(mScreenPath);

Picasso.with(EmulationActivity.this)
.load(mScreenPath)
.noFade()
.noPlaceholder()
.into(mImageView, new Callback()
{
@Override
public void onSuccess()
{
showScreenshot();
}

@Override
public void onError()
{
finish();
}
});
}
Picasso.with(EmulationActivity.this)
.invalidate(mScreenPath);

Picasso.with(EmulationActivity.this)
.load(mScreenPath)
.noFade()
.noPlaceholder()
.into(mImageView, new Callback() {
@Override
public void onSuccess() {
showScreenshot();
}

@Override
public void onError() {
finish();
}
});
});
}

@@ -575,60 +549,31 @@ private void toggleControls() {
enabledButtons[i] = mPreferences.getBoolean("buttonToggleGc" + i, true);
}
builder.setMultiChoiceItems(R.array.gcpadButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleGc" + indexSelected, isChecked);
}
});
(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleGc" + indexSelected, isChecked));
} else if (mPreferences.getInt("wiiController", 3) == 4) {
for (int i = 0; i < enabledButtons.length; i++) {
enabledButtons[i] = mPreferences.getBoolean("buttonToggleClassic" + i, true);
}
builder.setMultiChoiceItems(R.array.classicButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleClassic" + indexSelected, isChecked);
}
});
(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleClassic" + indexSelected, isChecked));
} else {
for (int i = 0; i < enabledButtons.length; i++) {
enabledButtons[i] = mPreferences.getBoolean("buttonToggleWii" + i, true);
}
if (mPreferences.getInt("wiiController", 3) == 3) {
builder.setMultiChoiceItems(R.array.nunchukButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleWii" + indexSelected, isChecked);
}
});
(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleWii" + indexSelected, isChecked));
} else {
builder.setMultiChoiceItems(R.array.wiimoteButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleWii" + indexSelected, isChecked);
}
});
(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleWii" + indexSelected, isChecked));
}
}
builder.setNeutralButton(getString(R.string.emulation_toggle_all), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
mEmulationFragment.toggleInputOverlayVisibility();
}
});
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
editor.apply();
builder.setNeutralButton(getString(R.string.emulation_toggle_all), (dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility());
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
{
editor.apply();

mEmulationFragment.refreshInputOverlay();
}
mEmulationFragment.refreshInputOverlay();
});

AlertDialog alertDialog = builder.create();
@@ -665,15 +610,13 @@ public void onStopTrackingTouch(SeekBar seekBar) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_control_scale);
builder.setView(view);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt("controlScale", seekbar.getProgress());
editor.apply();

mEmulationFragment.refreshInputOverlay();
}
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
{
SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt("controlScale", seekbar.getProgress());
editor.apply();

mEmulationFragment.refreshInputOverlay();
});

AlertDialog alertDialog = builder.create();
@@ -685,24 +628,20 @@ private void chooseController() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_choose_controller);
builder.setSingleChoiceItems(R.array.controllersEntries, mPreferences.getInt("wiiController", 3),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected) {
editor.putInt("wiiController", indexSelected);

NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension",
getResources().getStringArray(R.array.controllersValues)[indexSelected]);
}
(dialog, indexSelected) ->
{
editor.putInt("wiiController", indexSelected);

NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension",
getResources().getStringArray(R.array.controllersValues)[indexSelected]);
});
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
editor.apply();
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
{
editor.apply();

mEmulationFragment.refreshInputOverlay();
mEmulationFragment.refreshInputOverlay();

Toast.makeText(getApplication(), R.string.emulation_controller_changed, Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplication(), R.string.emulation_controller_changed, Toast.LENGTH_SHORT).show();
});

AlertDialog alertDialog = builder.create();
@@ -132,15 +132,11 @@ public void onClick(final View view)
// Delay the loading of the new directory to give a little bit of time for UI feedback
// to happen. Hacky, but good enough for now; this is necessary because we're modifying
// the RecyclerView's contents, rather than constructing a new one.
view.getHandler().postDelayed(new Runnable()
view.getHandler().postDelayed(() ->
{
@Override
public void run()
{
mFileList = fileList;
notifyDataSetChanged();
mListener.updateSubtitle(path);
}
mFileList = fileList;
notifyDataSetChanged();
mListener.updateSubtitle(path);
}, 200);
}
}
@@ -68,19 +68,15 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
textCountry.setText(country);
textDate.setText(getArguments().getString(ARG_GAME_DATE));

buttonLaunch.setOnClickListener(new View.OnClickListener()
buttonLaunch.setOnClickListener(view ->
{
@Override
public void onClick(View view)
{
// Start the emulation activity and send the path of the clicked ROM to it.
EmulationActivity.launch(getActivity(),
getArguments().getString(ARG_GAME_PATH),
getArguments().getString(ARG_GAME_TITLE),
getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
-1,
imageGameScreen);
}
// Start the emulation activity and send the path of the clicked ROM to it.
EmulationActivity.launch(getActivity(),
getArguments().getString(ARG_GAME_PATH),
getArguments().getString(ARG_GAME_TITLE),
getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
-1,
imageGameScreen);
});

// Fill in the view contents.
@@ -96,14 +96,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
Button doneButton = contents.findViewById(R.id.done_control_config);
if (doneButton != null)
{
doneButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
stopConfiguringControls();
}
});
doneButton.setOnClickListener(v -> stopConfiguringControls());
}

// The new Surface created here will get passed to the native code via onSurfaceChanged.
@@ -327,15 +320,11 @@ private void runWithValidSurface()
{
Log.debug("[EmulationFragment] Starting emulation thread.");

mEmulationThread = new Thread(new Runnable()
mEmulationThread = new Thread(() ->
{
@Override
public void run()
{
NativeLibrary.SurfaceChanged(mSurface);
NativeLibrary.Run(mGamePath);
}},
"NativeEmulation");
NativeLibrary.SurfaceChanged(mSurface);
NativeLibrary.Run(mGamePath);
}, "NativeEmulation");
mEmulationThread.start();

}
@@ -262,32 +262,28 @@ else if (!folder.exists())

public Observable<Cursor> getGamesForPlatform(final Platform platform)
{
return Observable.create(new Observable.OnSubscribe<Cursor>()
return Observable.create(subscriber ->
{
@Override
public void call(Subscriber<? super Cursor> subscriber)
{
Log.info("[GameDatabase] Reading games list...");

String[] whereArgs = new String[]{Integer.toString(platform.toInt())};

SQLiteDatabase database = getReadableDatabase();
Cursor resultCursor = database.query(
TABLE_NAME_GAMES,
null,
KEY_GAME_PLATFORM + " = ?",
whereArgs,
null,
null,
KEY_GAME_TITLE + " ASC"
);

// Pass the result cursor to the consumer.
subscriber.onNext(resultCursor);

// Tell the consumer we're done; it will unsubscribe implicitly.
subscriber.onCompleted();
}
Log.info("[GameDatabase] Reading games list...");

String[] whereArgs = new String[]{Integer.toString(platform.toInt())};

SQLiteDatabase database = getReadableDatabase();
Cursor resultCursor = database.query(
TABLE_NAME_GAMES,
null,
KEY_GAME_PLATFORM + " = ?",
whereArgs,
null,
null,
KEY_GAME_TITLE + " ASC"
);

// Pass the result cursor to the consumer.
subscriber.onNext(resultCursor);

// Tell the consumer we're done; it will unsubscribe implicitly.
subscriber.onCompleted();
});
}

0 comments on commit 9f9b4bc

Please sign in to comment.