-Added back button press check to destroy rather than minimize main video player.

This commit is contained in:
John Zhen Mo 2018-06-05 23:37:20 -07:00
parent e1df4757e4
commit 3b603b0637
2 changed files with 18 additions and 5 deletions

View File

@ -104,6 +104,7 @@ public final class MainVideoPlayer extends AppCompatActivity
@Nullable private PlayerState playerState; @Nullable private PlayerState playerState;
private boolean isInMultiWindow; private boolean isInMultiWindow;
private boolean isBackPressed;
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Activity LifeCycle // Activity LifeCycle
@ -191,6 +192,12 @@ public final class MainVideoPlayer extends AppCompatActivity
} }
} }
@Override
public void onBackPressed() {
super.onBackPressed();
isBackPressed = true;
}
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
if (DEBUG) Log.d(TAG, "onSaveInstanceState() called"); if (DEBUG) Log.d(TAG, "onSaveInstanceState() called");
@ -211,9 +218,15 @@ public final class MainVideoPlayer extends AppCompatActivity
PlayerHelper.setScreenBrightness(getApplicationContext(), PlayerHelper.setScreenBrightness(getApplicationContext(),
getWindow().getAttributes().screenBrightness); getWindow().getAttributes().screenBrightness);
isInMultiWindow = false; if (playerImpl == null) return;
if (isBackPressed) {
playerImpl.destroy();
} else {
playerImpl.minimize();
}
if (playerImpl != null) playerImpl.terminate(); isInMultiWindow = false;
isBackPressed = false;
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -443,7 +456,7 @@ public final class MainVideoPlayer extends AppCompatActivity
switchPopupButton.setOnClickListener(this); switchPopupButton.setOnClickListener(this);
} }
public void terminate() { public void minimize() {
switch (PlayerHelper.getMinimizeOnExitAction(context)) { switch (PlayerHelper.getMinimizeOnExitAction(context)) {
case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND: case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND:
onPlayBackgroundButtonClicked(); onPlayBackgroundButtonClicked();

View File

@ -505,8 +505,8 @@
</string-array> </string-array>
<!-- Minimize to exit action --> <!-- Minimize to exit action -->
<string name="minimize_on_exit_title">Minimize on exit</string> <string name="minimize_on_exit_title">Minimize on application switch</string>
<string name="minimize_on_exit_summary">Action when exiting main video player — %s</string> <string name="minimize_on_exit_summary">Action when switching to other application from main video player — %s</string>
<string name="minimize_on_exit_none_description">None</string> <string name="minimize_on_exit_none_description">None</string>
<string name="minimize_on_exit_background_description">Minimize to background player</string> <string name="minimize_on_exit_background_description">Minimize to background player</string>
<string name="minimize_on_exit_popup_description">Minimize to popup player</string> <string name="minimize_on_exit_popup_description">Minimize to popup player</string>