android: remove enter and exit transition

Originally done by weihuoya for Dolphin-emu.
This commit is contained in:
FearlessTobi 2020-03-28 20:05:02 +01:00 committed by bunnei
parent 68eb56d83b
commit a0c7666afa
5 changed files with 35 additions and 130 deletions

View File

@ -477,8 +477,8 @@ public final class NativeLibrary {
AlertDialog.Builder builder = new AlertDialog.Builder(emulationActivity) AlertDialog.Builder builder = new AlertDialog.Builder(emulationActivity)
.setTitle(captionId) .setTitle(captionId)
.setMessage(Html.fromHtml("Please follow the guides to redump your <a href=\"https://citra-emu.org/wiki/dumping-game-cartridges/\">game cartidges</a> or <a href=\"https://citra-emu.org/wiki/dumping-installed-titles/\">installed titles</a>.")) .setMessage(Html.fromHtml("Please follow the guides to redump your <a href=\"https://citra-emu.org/wiki/dumping-game-cartridges/\">game cartidges</a> or <a href=\"https://citra-emu.org/wiki/dumping-installed-titles/\">installed titles</a>."))
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> emulationActivity.exitWithAnimation()) .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> emulationActivity.finish())
.setOnDismissListener(dialogInterface -> emulationActivity.exitWithAnimation()); .setOnDismissListener(dialogInterface -> emulationActivity.finish());
emulationActivity.runOnUiThread(() -> { emulationActivity.runOnUiThread(() -> {
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();

View File

@ -10,7 +10,6 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
@ -25,13 +24,9 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import org.citra.citra_emu.NativeLibrary; import org.citra.citra_emu.NativeLibrary;
import org.citra.citra_emu.R; import org.citra.citra_emu.R;
import org.citra.citra_emu.fragments.EmulationFragment; import org.citra.citra_emu.fragments.EmulationFragment;
@ -39,7 +34,6 @@ import org.citra.citra_emu.fragments.MenuFragment;
import org.citra.citra_emu.model.settings.view.InputBindingSetting; import org.citra.citra_emu.model.settings.view.InputBindingSetting;
import org.citra.citra_emu.ui.main.MainPresenter; import org.citra.citra_emu.ui.main.MainPresenter;
import org.citra.citra_emu.ui.settings.SettingsActivity; import org.citra.citra_emu.ui.settings.SettingsActivity;
import org.citra.citra_emu.utils.Animations;
import org.citra.citra_emu.utils.ControllerMappingHelper; import org.citra.citra_emu.utils.ControllerMappingHelper;
import org.citra.citra_emu.utils.EmulationMenuSettings; import org.citra.citra_emu.utils.EmulationMenuSettings;
import org.citra.citra_emu.utils.SettingsFile; import org.citra.citra_emu.utils.SettingsFile;
@ -52,8 +46,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;
public final class EmulationActivity extends AppCompatActivity { public final class EmulationActivity extends AppCompatActivity {
public static final String EXTRA_SELECTED_GAME = "SelectedGame"; public static final String EXTRA_SELECTED_GAME = "SelectedGame";
public static final String EXTRA_SELECTED_TITLE = "SelectedTitle"; public static final String EXTRA_SELECTED_TITLE = "SelectedTitle";
public static final String EXTRA_SCREEN_PATH = "ScreenPath";
public static final String EXTRA_GRID_POSITION = "GridPosition";
public static final int MENU_ACTION_EDIT_CONTROLS_PLACEMENT = 0; public static final int MENU_ACTION_EDIT_CONTROLS_PLACEMENT = 0;
public static final int MENU_ACTION_TOGGLE_CONTROLS = 1; public static final int MENU_ACTION_TOGGLE_CONTROLS = 1;
public static final int MENU_ACTION_ADJUST_SCALE = 2; public static final int MENU_ACTION_ADJUST_SCALE = 2;
@ -100,44 +92,31 @@ public final class EmulationActivity extends AppCompatActivity {
} }
private View mDecorView; private View mDecorView;
private ImageView mImageView;
private EmulationFragment mEmulationFragment; private EmulationFragment mEmulationFragment;
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private ControllerMappingHelper mControllerMappingHelper; private ControllerMappingHelper mControllerMappingHelper;
// So that MainActivity knows which view to invalidate before the return animation.
private int mPosition;
private boolean mDeviceHasTouchScreen; private boolean mDeviceHasTouchScreen;
private boolean mMenuVisible; private boolean mMenuVisible;
private boolean activityRecreated; private boolean activityRecreated;
private String mScreenPath;
private String mSelectedTitle; private String mSelectedTitle;
private String mPath; private String mPath;
private Runnable afterShowingScreenshot = new Runnable() { private Runnable afterShowingScreenshot = new Runnable() {
@Override @Override
public void run() { public void run() {
setResult(mPosition);
supportFinishAfterTransition(); supportFinishAfterTransition();
} }
}; };
public static void launch(FragmentActivity activity, String path, String title, public static void launch(FragmentActivity activity, String path, String title) {
String screenshotPath, int position, View sharedView) {
Intent launcher = new Intent(activity, EmulationActivity.class); Intent launcher = new Intent(activity, EmulationActivity.class);
launcher.putExtra(EXTRA_SELECTED_GAME, path); launcher.putExtra(EXTRA_SELECTED_GAME, path);
launcher.putExtra(EXTRA_SELECTED_TITLE, title); launcher.putExtra(EXTRA_SELECTED_TITLE, title);
launcher.putExtra(EXTRA_SCREEN_PATH, screenshotPath); Bundle options = new Bundle();
launcher.putExtra(EXTRA_GRID_POSITION, position);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
activity,
sharedView,
"image_game_screenshot");
// I believe this warning is a bug. Activities are FragmentActivity from the support lib // I believe this warning is a bug. Activities are FragmentActivity from the support lib
//noinspection RestrictedApi //noinspection RestrictedApi
activity.startActivityForResult(launcher, MainPresenter.REQUEST_EMULATE_GAME, activity.startActivityForResult(launcher, MainPresenter.REQUEST_EMULATE_GAME, options);
options.toBundle());
} }
private void showRunningNotification() { private void showRunningNotification() {
@ -176,8 +155,6 @@ public final class EmulationActivity extends AppCompatActivity {
Intent gameToEmulate = getIntent(); Intent gameToEmulate = getIntent();
mPath = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAME); mPath = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAME);
mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE); mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE);
mScreenPath = gameToEmulate.getStringExtra(EXTRA_SCREEN_PATH);
mPosition = gameToEmulate.getIntExtra(EXTRA_GRID_POSITION, -1);
activityRecreated = false; activityRecreated = false;
} else { } else {
activityRecreated = true; activityRecreated = true;
@ -211,8 +188,6 @@ public final class EmulationActivity extends AppCompatActivity {
setContentView(R.layout.activity_emulation); setContentView(R.layout.activity_emulation);
mImageView = findViewById(R.id.image_screenshot);
// Find or create the EmulationFragment // Find or create the EmulationFragment
mEmulationFragment = (EmulationFragment) getSupportFragmentManager() mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
.findFragmentById(R.id.frame_emulation_fragment); .findFragmentById(R.id.frame_emulation_fragment);
@ -223,34 +198,6 @@ public final class EmulationActivity extends AppCompatActivity {
.commit(); .commit();
} }
if (savedInstanceState == null) {
// Picasso will take a while to load these big-ass screenshots. So don't run
// the animation until we say so.
postponeEnterTransition();
Picasso.get()
.load(mScreenPath)
.noFade()
.noPlaceholder()
.into(mImageView, new Callback() {
@Override
public void onSuccess() {
supportStartPostponedEnterTransition();
}
@Override
public void onError(Exception ex) {
// Still have to do this, or else the app will crash.
supportStartPostponedEnterTransition();
}
});
Animations.fadeViewOut(mImageView)
.setStartDelay(2000)
.withEndAction(() -> mImageView.setVisibility(View.GONE));
} else {
mImageView.setVisibility(View.GONE);
}
if (mDeviceHasTouchScreen) { if (mDeviceHasTouchScreen) {
setTitle(mSelectedTitle); setTitle(mSelectedTitle);
} }
@ -268,16 +215,12 @@ public final class EmulationActivity extends AppCompatActivity {
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
outState.putString(EXTRA_SELECTED_GAME, mPath); outState.putString(EXTRA_SELECTED_GAME, mPath);
outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle); outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle);
outState.putString(EXTRA_SCREEN_PATH, mScreenPath);
outState.putInt(EXTRA_GRID_POSITION, mPosition);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
protected void restoreState(Bundle savedInstanceState) { protected void restoreState(Bundle savedInstanceState) {
mPath = savedInstanceState.getString(EXTRA_SELECTED_GAME); mPath = savedInstanceState.getString(EXTRA_SELECTED_GAME);
mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE); mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE);
mScreenPath = savedInstanceState.getString(EXTRA_SCREEN_PATH);
mPosition = savedInstanceState.getInt(EXTRA_GRID_POSITION);
// If an alert prompt was in progress when state was restored, retry displaying it // If an alert prompt was in progress when state was restored, retry displaying it
NativeLibrary.retryDisplayAlertPrompt(); NativeLibrary.retryDisplayAlertPrompt();
@ -299,7 +242,7 @@ public final class EmulationActivity extends AppCompatActivity {
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> .setPositiveButton(android.R.string.yes, (dialogInterface, i) ->
{ {
mEmulationFragment.stopEmulation(); mEmulationFragment.stopEmulation();
exitWithAnimation(); finish();
}) })
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> .setNegativeButton(android.R.string.cancel, (dialogInterface, i) ->
{ {
@ -348,37 +291,6 @@ public final class EmulationActivity extends AppCompatActivity {
} }
} }
public void exitWithAnimation() {
tryDismissRunningNotification(this);
runOnUiThread(() ->
{
Picasso.get()
.invalidate(mScreenPath);
Picasso.get()
.load(mScreenPath)
.noFade()
.noPlaceholder()
.into(mImageView, new Callback() {
@Override
public void onSuccess() {
showScreenshot();
}
@Override
public void onError(Exception ex) {
finish();
}
});
});
}
private void showScreenshot() {
Animations.fadeViewIn(mImageView)
.withEndAction(afterShowingScreenshot);
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
@ -484,7 +396,7 @@ public final class EmulationActivity extends AppCompatActivity {
case MENU_ACTION_EXIT: case MENU_ACTION_EXIT:
toggleMenu(); // Hide the menu (it will be showing since we just clicked it) toggleMenu(); // Hide the menu (it will be showing since we just clicked it)
mEmulationFragment.stopEmulation(); mEmulationFragment.stopEmulation();
exitWithAnimation(); finish();
break; break;
case MENU_ACTION_OPEN_SETTINGS: case MENU_ACTION_OPEN_SETTINGS:
@ -585,13 +497,15 @@ public final class EmulationActivity extends AppCompatActivity {
seekbar.setMax(150); seekbar.setMax(150);
seekbar.setProgress(mPreferences.getInt("controlScale", 50)); seekbar.setProgress(mPreferences.getInt("controlScale", 50));
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStartTrackingTouch(SeekBar seekBar) { } public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
value.setText(String.valueOf(progress + 50)); value.setText(String.valueOf(progress + 50));
} }
public void onStopTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) {
}
}); });
value.setText(String.valueOf(seekbar.getProgress() + 50)); value.setText(String.valueOf(seekbar.getProgress() + 50));
@ -600,7 +514,8 @@ 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.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> { }); builder.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> {
});
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) ->
{ {
SharedPreferences.Editor editor = mPreferences.edit(); SharedPreferences.Editor editor = mPreferences.edit();
@ -623,7 +538,8 @@ public final class EmulationActivity extends AppCompatActivity {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setTitle(getString(R.string.emulation_touch_overlay_reset)) .setTitle(getString(R.string.emulation_touch_overlay_reset))
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> mEmulationFragment.resetInputOverlay()) .setPositiveButton(android.R.string.yes, (dialogInterface, i) -> mEmulationFragment.resetInputOverlay())
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> { }) .setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> {
})
.create() .create()
.show(); .show();
} }
@ -702,20 +618,24 @@ public final class EmulationActivity extends AppCompatActivity {
if (axisValuesDPad[0] == 0.f) { if (axisValuesDPad[0] == 0.f) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_LEFT, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_LEFT, NativeLibrary.ButtonState.RELEASED);
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_RIGHT, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_RIGHT, NativeLibrary.ButtonState.RELEASED);
} if (axisValuesDPad[0] < 0.f) { }
if (axisValuesDPad[0] < 0.f) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_LEFT, NativeLibrary.ButtonState.PRESSED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_LEFT, NativeLibrary.ButtonState.PRESSED);
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_RIGHT, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_RIGHT, NativeLibrary.ButtonState.RELEASED);
} if (axisValuesDPad[0] > 0.f) { }
if (axisValuesDPad[0] > 0.f) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_LEFT, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_LEFT, NativeLibrary.ButtonState.RELEASED);
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_RIGHT, NativeLibrary.ButtonState.PRESSED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_RIGHT, NativeLibrary.ButtonState.PRESSED);
} }
if (axisValuesDPad[1] == 0.f) { if (axisValuesDPad[1] == 0.f) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_UP, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_UP, NativeLibrary.ButtonState.RELEASED);
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_DOWN, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_DOWN, NativeLibrary.ButtonState.RELEASED);
} if (axisValuesDPad[1] < 0.f) { }
if (axisValuesDPad[1] < 0.f) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_UP, NativeLibrary.ButtonState.PRESSED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_UP, NativeLibrary.ButtonState.PRESSED);
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_DOWN, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_DOWN, NativeLibrary.ButtonState.RELEASED);
} if (axisValuesDPad[1] > 0.f) { }
if (axisValuesDPad[1] > 0.f) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_UP, NativeLibrary.ButtonState.RELEASED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_UP, NativeLibrary.ButtonState.RELEASED);
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_DOWN, NativeLibrary.ButtonState.PRESSED); NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, NativeLibrary.ButtonType.DPAD_DOWN, NativeLibrary.ButtonState.PRESSED);
} }

View File

@ -192,12 +192,7 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
GameViewHolder holder = (GameViewHolder) view.getTag(); GameViewHolder holder = (GameViewHolder) view.getTag();
EmulationActivity.launch((FragmentActivity) view.getContext(), EmulationActivity.launch((FragmentActivity) view.getContext(), holder.path, holder.title);
holder.path,
holder.title,
holder.screenshotPath,
holder.getAdapterPosition(),
holder.imageScreenshot);
} }
public static class SpacesItemDecoration extends RecyclerView.ItemDecoration { public static class SpacesItemDecoration extends RecyclerView.ItemDecoration {

View File

@ -69,12 +69,7 @@ public final class GameDetailsDialog extends DialogFragment {
buttonLaunch.setOnClickListener(view -> buttonLaunch.setOnClickListener(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(), getArguments().getString(ARG_GAME_PATH), getArguments().getString(ARG_GAME_TITLE));
getArguments().getString(ARG_GAME_PATH),
getArguments().getString(ARG_GAME_TITLE),
getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
-1,
imageGameScreen);
}); });
// Fill in the view contents. // Fill in the view contents.

View File

@ -82,12 +82,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView {
TvGameViewHolder holder = (TvGameViewHolder) itemViewHolder; 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.title);
holder.path,
holder.title,
holder.screenshotPath,
-1,
holder.imageScreenshot);
} }
}); });
} }