Replace all Anonymouse class with lambdas or method refernce where applicable

This commit is contained in:
mahdihijazi
2017-12-17 17:45:24 +01:00
parent c6bc25a189
commit e61e4d4b3c
13 changed files with 130 additions and 269 deletions

View File

@ -384,14 +384,7 @@ public final class NativeLibrary
final EmulationActivity emulationActivity = sEmulationActivity.get(); final EmulationActivity emulationActivity = sEmulationActivity.get();
if (emulationActivity != null) if (emulationActivity != null)
{ {
emulationActivity.runOnUiThread(new Runnable() emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity, "Panic Alert: " + alert, Toast.LENGTH_LONG).show());
{
@Override
public void run()
{
Toast.makeText(emulationActivity, "Panic Alert: " + alert, Toast.LENGTH_LONG).show();
}
});
} }
else else
{ {

View File

@ -175,24 +175,13 @@ public final class EmulationActivity extends AppCompatActivity
// Get a handle to the Window containing the UI. // Get a handle to the Window containing the UI.
mDecorView = getWindow().getDecorView(); mDecorView = getWindow().getDecorView();
mDecorView.setOnSystemUiVisibilityChangeListener mDecorView.setOnSystemUiVisibilityChangeListener(visibility ->
(new View.OnSystemUiVisibilityChangeListener() { {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{ {
// Go back to immersive fullscreen mode in 3s // Go back to immersive fullscreen mode in 3s
Handler handler = new Handler(getMainLooper()); Handler handler = new Handler(getMainLooper());
handler.postDelayed(new Runnable() handler.postDelayed(this::enableFullscreenImmersive, 3000 /* 3s */);
{
@Override
public void run()
{
enableFullscreenImmersive();
}
},
3000 /* 3s */);
}
} }
}); });
// Set these options now so that the SurfaceView the game renders into is the right size. // Set these options now so that the SurfaceView the game renders into is the right size.
@ -251,14 +240,7 @@ public final class EmulationActivity extends AppCompatActivity
Animations.fadeViewOut(mImageView) Animations.fadeViewOut(mImageView)
.setStartDelay(2000) .setStartDelay(2000)
.withEndAction(new Runnable() .withEndAction(() -> mImageView.setVisibility(View.GONE));
{
@Override
public void run()
{
mImageView.setVisibility(View.GONE);
}
});
} }
else else
{ {
@ -328,12 +310,8 @@ public final class EmulationActivity extends AppCompatActivity
} }
} }
public void exitWithAnimation() public void exitWithAnimation() {
{ runOnUiThread(() ->
runOnUiThread(new Runnable()
{
@Override
public void run()
{ {
Picasso.with(EmulationActivity.this) Picasso.with(EmulationActivity.this)
.invalidate(mScreenPath); .invalidate(mScreenPath);
@ -342,21 +320,17 @@ public final class EmulationActivity extends AppCompatActivity
.load(mScreenPath) .load(mScreenPath)
.noFade() .noFade()
.noPlaceholder() .noPlaceholder()
.into(mImageView, new Callback() .into(mImageView, new Callback() {
{
@Override @Override
public void onSuccess() public void onSuccess() {
{
showScreenshot(); showScreenshot();
} }
@Override @Override
public void onError() public void onError() {
{
finish(); finish();
} }
}); });
}
}); });
} }
@ -575,60 +549,31 @@ public final class EmulationActivity extends AppCompatActivity
enabledButtons[i] = mPreferences.getBoolean("buttonToggleGc" + i, true); enabledButtons[i] = mPreferences.getBoolean("buttonToggleGc" + i, true);
} }
builder.setMultiChoiceItems(R.array.gcpadButtons, enabledButtons, builder.setMultiChoiceItems(R.array.gcpadButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() { (dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleGc" + indexSelected, isChecked));
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleGc" + indexSelected, isChecked);
}
});
} else if (mPreferences.getInt("wiiController", 3) == 4) { } else if (mPreferences.getInt("wiiController", 3) == 4) {
for (int i = 0; i < enabledButtons.length; i++) { for (int i = 0; i < enabledButtons.length; i++) {
enabledButtons[i] = mPreferences.getBoolean("buttonToggleClassic" + i, true); enabledButtons[i] = mPreferences.getBoolean("buttonToggleClassic" + i, true);
} }
builder.setMultiChoiceItems(R.array.classicButtons, enabledButtons, builder.setMultiChoiceItems(R.array.classicButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() { (dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleClassic" + indexSelected, isChecked));
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleClassic" + indexSelected, isChecked);
}
});
} else { } else {
for (int i = 0; i < enabledButtons.length; i++) { for (int i = 0; i < enabledButtons.length; i++) {
enabledButtons[i] = mPreferences.getBoolean("buttonToggleWii" + i, true); enabledButtons[i] = mPreferences.getBoolean("buttonToggleWii" + i, true);
} }
if (mPreferences.getInt("wiiController", 3) == 3) { if (mPreferences.getInt("wiiController", 3) == 3) {
builder.setMultiChoiceItems(R.array.nunchukButtons, enabledButtons, builder.setMultiChoiceItems(R.array.nunchukButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() { (dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleWii" + indexSelected, isChecked));
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleWii" + indexSelected, isChecked);
}
});
} else { } else {
builder.setMultiChoiceItems(R.array.wiimoteButtons, enabledButtons, builder.setMultiChoiceItems(R.array.wiimoteButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener() { (dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleWii" + indexSelected, isChecked));
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
editor.putBoolean("buttonToggleWii" + indexSelected, isChecked);
}
});
} }
} }
builder.setNeutralButton(getString(R.string.emulation_toggle_all), new DialogInterface.OnClickListener() { builder.setNeutralButton(getString(R.string.emulation_toggle_all), (dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility());
@Override builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
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(); editor.apply();
mEmulationFragment.refreshInputOverlay(); mEmulationFragment.refreshInputOverlay();
}
}); });
AlertDialog alertDialog = builder.create(); AlertDialog alertDialog = builder.create();
@ -665,15 +610,13 @@ public final class EmulationActivity extends AppCompatActivity
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_control_scale); builder.setTitle(R.string.emulation_control_scale);
builder.setView(view); builder.setView(view);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
@Override {
public void onClick(DialogInterface dialogInterface, int i) {
SharedPreferences.Editor editor = mPreferences.edit(); SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt("controlScale", seekbar.getProgress()); editor.putInt("controlScale", seekbar.getProgress());
editor.apply(); editor.apply();
mEmulationFragment.refreshInputOverlay(); mEmulationFragment.refreshInputOverlay();
}
}); });
AlertDialog alertDialog = builder.create(); AlertDialog alertDialog = builder.create();
@ -685,24 +628,20 @@ public final class EmulationActivity extends AppCompatActivity
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_choose_controller); builder.setTitle(R.string.emulation_choose_controller);
builder.setSingleChoiceItems(R.array.controllersEntries, mPreferences.getInt("wiiController", 3), builder.setSingleChoiceItems(R.array.controllersEntries, mPreferences.getInt("wiiController", 3),
new DialogInterface.OnClickListener() { (dialog, indexSelected) ->
@Override {
public void onClick(DialogInterface dialog, int indexSelected) {
editor.putInt("wiiController", indexSelected); editor.putInt("wiiController", indexSelected);
NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension", NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension",
getResources().getStringArray(R.array.controllersValues)[indexSelected]); getResources().getStringArray(R.array.controllersValues)[indexSelected]);
}
}); });
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
@Override {
public void onClick(DialogInterface dialogInterface, int i) {
editor.apply(); 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(); AlertDialog alertDialog = builder.create();

View File

@ -132,15 +132,11 @@ public final class FileAdapter extends RecyclerView.Adapter<FileViewHolder> impl
// Delay the loading of the new directory to give a little bit of time for UI feedback // 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 // 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. // the RecyclerView's contents, rather than constructing a new one.
view.getHandler().postDelayed(new Runnable() view.getHandler().postDelayed(() ->
{
@Override
public void run()
{ {
mFileList = fileList; mFileList = fileList;
notifyDataSetChanged(); notifyDataSetChanged();
mListener.updateSubtitle(path); mListener.updateSubtitle(path);
}
}, 200); }, 200);
} }
} }

View File

@ -68,10 +68,7 @@ public final class GameDetailsDialog extends DialogFragment
textCountry.setText(country); textCountry.setText(country);
textDate.setText(getArguments().getString(ARG_GAME_DATE)); 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. // Start the emulation activity and send the path of the clicked ROM to it.
EmulationActivity.launch(getActivity(), EmulationActivity.launch(getActivity(),
@ -80,7 +77,6 @@ public final class GameDetailsDialog extends DialogFragment
getArguments().getString(ARG_GAME_SCREENSHOT_PATH), getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
-1, -1,
imageGameScreen); imageGameScreen);
}
}); });
// Fill in the view contents. // Fill in the view contents.

View File

@ -96,14 +96,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
Button doneButton = contents.findViewById(R.id.done_control_config); Button doneButton = contents.findViewById(R.id.done_control_config);
if (doneButton != null) if (doneButton != null)
{ {
doneButton.setOnClickListener(new View.OnClickListener() doneButton.setOnClickListener(v -> stopConfiguringControls());
{
@Override
public void onClick(View v)
{
stopConfiguringControls();
}
});
} }
// The new Surface created here will get passed to the native code via onSurfaceChanged. // The new Surface created here will get passed to the native code via onSurfaceChanged.
@ -327,15 +320,11 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
{ {
Log.debug("[EmulationFragment] Starting emulation thread."); Log.debug("[EmulationFragment] Starting emulation thread.");
mEmulationThread = new Thread(new Runnable() mEmulationThread = new Thread(() ->
{
@Override
public void run()
{ {
NativeLibrary.SurfaceChanged(mSurface); NativeLibrary.SurfaceChanged(mSurface);
NativeLibrary.Run(mGamePath); NativeLibrary.Run(mGamePath);
}}, }, "NativeEmulation");
"NativeEmulation");
mEmulationThread.start(); mEmulationThread.start();
} }

View File

@ -262,10 +262,7 @@ public final class GameDatabase extends SQLiteOpenHelper
public Observable<Cursor> getGamesForPlatform(final Platform platform) 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..."); Log.info("[GameDatabase] Reading games list...");
@ -287,7 +284,6 @@ public final class GameDatabase extends SQLiteOpenHelper
// Tell the consumer we're done; it will unsubscribe implicitly. // Tell the consumer we're done; it will unsubscribe implicitly.
subscriber.onCompleted(); subscriber.onCompleted();
}
}); });
} }

View File

@ -52,14 +52,7 @@ public final class MainActivity extends AppCompatActivity implements MainView
mTabLayout.setupWithViewPager(mViewPager); mTabLayout.setupWithViewPager(mViewPager);
// Set up the FAB. // Set up the FAB.
mFab.setOnClickListener(new View.OnClickListener() mFab.setOnClickListener(view -> mPresenter.onFabClick());
{
@Override
public void onClick(View view)
{
mPresenter.onFabClick();
}
});
mPresenter.onCreate(); mPresenter.onCreate();

View File

@ -96,14 +96,6 @@ public final class MainPresenter
databaseHelper.getGamesForPlatform(platform) databaseHelper.getGamesForPlatform(platform)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Cursor>() .subscribe(games -> mView.showGames(platform, games));
{
@Override
public void call(Cursor games)
{
mView.showGames(platform, games);
}
}
);
} }
} }

View File

@ -71,10 +71,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView
buildRowsAdapter(); buildRowsAdapter();
mBrowseFragment.setOnItemViewClickedListener( mBrowseFragment.setOnItemViewClickedListener(
new OnItemViewClickedListener() (itemViewHolder, item, rowViewHolder, row) ->
{
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row)
{ {
// Special case: user clicked on a settings row item. // Special case: user clicked on a settings row item.
if (item instanceof TvSettingsItem) if (item instanceof TvSettingsItem)
@ -94,7 +91,6 @@ public final class TvMainActivity extends FragmentActivity implements MainView
-1, -1,
holder.imageScreenshot); holder.imageScreenshot);
} }
}
}); });
} }
/** /**

View File

@ -47,15 +47,11 @@ public final class PlatformGamesPresenter
databaseHelper.getGamesForPlatform(mPlatform) databaseHelper.getGamesForPlatform(mPlatform)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Cursor>() .subscribe(games ->
{
@Override
public void call(Cursor games)
{ {
Log.debug("[PlatformGamesPresenter] " + mPlatform + ": Load finished, swapping cursor..."); Log.debug("[PlatformGamesPresenter] " + mPlatform + ": Load finished, swapping cursor...");
mView.showGames(games); mView.showGames(games);
}
}); });
} }
} }

View File

@ -201,10 +201,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
dialog.setTitle(R.string.input_binding); dialog.setTitle(R.string.input_binding);
dialog.setMessage(String.format(mContext.getString(R.string.input_binding_descrip), mContext.getString(item.getNameId()))); dialog.setMessage(String.format(mContext.getString(R.string.input_binding_descrip), mContext.getString(item.getNameId())));
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, mContext.getString(R.string.cancel), this); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, mContext.getString(R.string.cancel), this);
dialog.setButton(AlertDialog.BUTTON_NEUTRAL, mContext.getString(R.string.clear), new AlertDialog.OnClickListener() dialog.setButton(AlertDialog.BUTTON_NEUTRAL, mContext.getString(R.string.clear), (dialogInterface, i) ->
{
@Override
public void onClick(DialogInterface dialogInterface, int i)
{ {
item.setValue(""); item.setValue("");
@ -212,12 +209,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(item.getKey()); editor.remove(item.getKey());
editor.apply(); editor.apply();
}
}); });
dialog.setOnDismissListener(new AlertDialog.OnDismissListener() dialog.setOnDismissListener(dialog1 ->
{
@Override
public void onDismiss(DialogInterface dialog)
{ {
StringSetting setting = new StringSetting(item.getKey(), item.getSection(), item.getFile(), item.getValue()); StringSetting setting = new StringSetting(item.getKey(), item.getSection(), item.getFile(), item.getValue());
notifyItemChanged(position); notifyItemChanged(position);
@ -228,7 +221,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
} }
mView.onSettingChanged(); mView.onSettingChanged();
}
}); });
dialog.setCanceledOnTouchOutside(false); dialog.setCanceledOnTouchOutside(false);
dialog.show(); dialog.show();

View File

@ -137,14 +137,7 @@ public class Java_GCAdapter {
final Activity emulationActivity = NativeLibrary.sEmulationActivity.get(); final Activity emulationActivity = NativeLibrary.sEmulationActivity.get();
if (emulationActivity != null) if (emulationActivity != null)
{ {
emulationActivity.runOnUiThread(new Runnable() emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity, "GameCube Adapter couldn't be opened. Please re-plug the device.", Toast.LENGTH_LONG).show());
{
@Override
public void run()
{
Toast.makeText(emulationActivity, "GameCube Adapter couldn't be opened. Please re-plug the device.", Toast.LENGTH_LONG).show();
}
});
} }
else else
{ {

View File

@ -27,13 +27,8 @@ public class PermissionsHandler {
if (hasWritePermission != PackageManager.PERMISSION_GRANTED) { if (hasWritePermission != PackageManager.PERMISSION_GRANTED) {
if (activity.shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) { if (activity.shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) {
showMessageOKCancel(activity, activity.getString(R.string.write_permission_needed), showMessageOKCancel(activity, activity.getString(R.string.write_permission_needed),
new DialogInterface.OnClickListener() { (dialog, which) -> activity.requestPermissions(new String[] {WRITE_EXTERNAL_STORAGE},
@Override REQUEST_CODE_WRITE_PERMISSION));
public void onClick(DialogInterface dialog, int which) {
activity.requestPermissions(new String[] {WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_WRITE_PERMISSION);
}
});
return false; return false;
} }
@ -58,13 +53,8 @@ public class PermissionsHandler {
new AlertDialog.Builder(activity) new AlertDialog.Builder(activity)
.setMessage(message) .setMessage(message)
.setPositiveButton(android.R.string.ok, okListener) .setPositiveButton(android.R.string.ok, okListener)
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(android.R.string.cancel, (dialogInterface, i) ->
@Override Toast.makeText(activity, R.string.write_permission_needed, Toast.LENGTH_SHORT).show())
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(activity, R.string.write_permission_needed, Toast.LENGTH_SHORT)
.show();
}
})
.create() .create()
.show(); .show();
} }