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 if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
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());
// Go back to immersive fullscreen mode in 3s handler.postDelayed(this::enableFullscreenImmersive, 3000 /* 3s */);
Handler handler = new Handler(getMainLooper());
handler.postDelayed(new Runnable()
{
@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,35 +310,27 @@ public final class EmulationActivity extends AppCompatActivity
} }
} }
public void exitWithAnimation() public void exitWithAnimation() {
{ runOnUiThread(() ->
runOnUiThread(new Runnable()
{ {
@Override Picasso.with(EmulationActivity.this)
public void run() .invalidate(mScreenPath);
{
Picasso.with(EmulationActivity.this)
.invalidate(mScreenPath);
Picasso.with(EmulationActivity.this) Picasso.with(EmulationActivity.this)
.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) {
{ editor.apply();
mEmulationFragment.toggleInputOverlayVisibility();
}
});
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
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 mFileList = fileList;
public void run() notifyDataSetChanged();
{ mListener.updateSubtitle(path);
mFileList = fileList;
notifyDataSetChanged();
mListener.updateSubtitle(path);
}
}, 200); }, 200);
} }
} }

View file

@ -68,19 +68,15 @@ 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 // Start the emulation activity and send the path of the clicked ROM to it.
public void onClick(View view) EmulationActivity.launch(getActivity(),
{ getArguments().getString(ARG_GAME_PATH),
// Start the emulation activity and send the path of the clicked ROM to it. getArguments().getString(ARG_GAME_TITLE),
EmulationActivity.launch(getActivity(), getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
getArguments().getString(ARG_GAME_PATH), -1,
getArguments().getString(ARG_GAME_TITLE), imageGameScreen);
getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
-1,
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 NativeLibrary.SurfaceChanged(mSurface);
public void run() NativeLibrary.Run(mGamePath);
{ }, "NativeEmulation");
NativeLibrary.SurfaceChanged(mSurface);
NativeLibrary.Run(mGamePath);
}},
"NativeEmulation");
mEmulationThread.start(); mEmulationThread.start();
} }

View file

@ -262,32 +262,28 @@ 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 Log.info("[GameDatabase] Reading games list...");
public void call(Subscriber<? super Cursor> subscriber)
{
Log.info("[GameDatabase] Reading games list...");
String[] whereArgs = new String[]{Integer.toString(platform.toInt())}; String[] whereArgs = new String[]{Integer.toString(platform.toInt())};
SQLiteDatabase database = getReadableDatabase(); SQLiteDatabase database = getReadableDatabase();
Cursor resultCursor = database.query( Cursor resultCursor = database.query(
TABLE_NAME_GAMES, TABLE_NAME_GAMES,
null, null,
KEY_GAME_PLATFORM + " = ?", KEY_GAME_PLATFORM + " = ?",
whereArgs, whereArgs,
null, null,
null, null,
KEY_GAME_TITLE + " ASC" KEY_GAME_TITLE + " ASC"
); );
// Pass the result cursor to the consumer. // Pass the result cursor to the consumer.
subscriber.onNext(resultCursor); subscriber.onNext(resultCursor);
// 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,31 +71,27 @@ public final class TvMainActivity extends FragmentActivity implements MainView
buildRowsAdapter(); buildRowsAdapter();
mBrowseFragment.setOnItemViewClickedListener( mBrowseFragment.setOnItemViewClickedListener(
new OnItemViewClickedListener() (itemViewHolder, item, rowViewHolder, row) ->
{ {
@Override // Special case: user clicked on a settings row item.
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) if (item instanceof TvSettingsItem)
{ {
// Special case: user clicked on a settings row item. TvSettingsItem settingsItem = (TvSettingsItem) item;
if (item instanceof TvSettingsItem) mPresenter.handleOptionSelection(settingsItem.getItemId());
{ }
TvSettingsItem settingsItem = (TvSettingsItem) item; else
mPresenter.handleOptionSelection(settingsItem.getItemId()); {
} TvGameViewHolder holder = (TvGameViewHolder) itemViewHolder;
else
{
TvGameViewHolder holder = (TvGameViewHolder) itemViewHolder;
// Start the emulation activity and send the path of the clicked ISO to it. // Start the emulation activity and send the path of the clicked ISO to it.
EmulationActivity.launch(TvMainActivity.this, EmulationActivity.launch(TvMainActivity.this,
holder.path, holder.path,
holder.title, holder.title,
holder.screenshotPath, holder.screenshotPath,
-1, -1,
holder.imageScreenshot); holder.imageScreenshot);
} }
} });
});
} }
/** /**
* MainView * MainView

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 Log.debug("[PlatformGamesPresenter] " + mPlatform + ": Load finished, swapping cursor...");
public void call(Cursor games)
{
Log.debug("[PlatformGamesPresenter] " + mPlatform + ": Load finished, swapping cursor...");
mView.showGames(games); mView.showGames(games);
}
}); });
} }
} }

View file

@ -201,34 +201,26 @@ 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 item.setValue("");
public void onClick(DialogInterface dialogInterface, int i)
{
item.setValue("");
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
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 StringSetting setting = new StringSetting(item.getKey(), item.getSection(), item.getFile(), item.getValue());
public void onDismiss(DialogInterface dialog) notifyItemChanged(position);
if (setting != null)
{ {
StringSetting setting = new StringSetting(item.getKey(), item.getSection(), item.getFile(), item.getValue()); mView.putSetting(setting);
notifyItemChanged(position);
if (setting != null)
{
mView.putSetting(setting);
}
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();
} }