mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 01:20:34 +00:00
Merge pull request #1354 from karyogamy/minimize-on-exit
Minimize main player on exit
This commit is contained in:
commit
adb6943420
@ -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");
|
||||||
@ -208,10 +215,18 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
if (DEBUG) Log.d(TAG, "onStop() called");
|
if (DEBUG) Log.d(TAG, "onStop() called");
|
||||||
super.onStop();
|
super.onStop();
|
||||||
playerImpl.destroy();
|
|
||||||
|
|
||||||
PlayerHelper.setScreenBrightness(getApplicationContext(),
|
PlayerHelper.setScreenBrightness(getApplicationContext(),
|
||||||
getWindow().getAttributes().screenBrightness);
|
getWindow().getAttributes().screenBrightness);
|
||||||
|
|
||||||
|
if (playerImpl == null) return;
|
||||||
|
if (isBackPressed) {
|
||||||
|
playerImpl.destroy();
|
||||||
|
} else {
|
||||||
|
playerImpl.minimize();
|
||||||
|
}
|
||||||
|
|
||||||
|
isInMultiWindow = false;
|
||||||
|
isBackPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
@ -441,6 +456,20 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||||||
switchPopupButton.setOnClickListener(this);
|
switchPopupButton.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void minimize() {
|
||||||
|
switch (PlayerHelper.getMinimizeOnExitAction(context)) {
|
||||||
|
case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND:
|
||||||
|
onPlayBackgroundButtonClicked();
|
||||||
|
break;
|
||||||
|
case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP:
|
||||||
|
onFullScreenButtonClicked();
|
||||||
|
break;
|
||||||
|
case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE:
|
||||||
|
destroy();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// ExoPlayer Video Listener
|
// ExoPlayer Video Listener
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.IntDef;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.view.accessibility.CaptioningManager;
|
import android.view.accessibility.CaptioningManager;
|
||||||
@ -28,6 +29,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueue;
|
|||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
||||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -42,6 +44,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FILL;
|
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FILL;
|
||||||
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIT;
|
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIT;
|
||||||
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM;
|
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.*;
|
||||||
|
|
||||||
public class PlayerHelper {
|
public class PlayerHelper {
|
||||||
private PlayerHelper() {}
|
private PlayerHelper() {}
|
||||||
@ -51,6 +55,14 @@ public class PlayerHelper {
|
|||||||
private static final NumberFormat speedFormatter = new DecimalFormat("0.##x");
|
private static final NumberFormat speedFormatter = new DecimalFormat("0.##x");
|
||||||
private static final NumberFormat pitchFormatter = new DecimalFormat("##%");
|
private static final NumberFormat pitchFormatter = new DecimalFormat("##%");
|
||||||
|
|
||||||
|
@Retention(SOURCE)
|
||||||
|
@IntDef({MINIMIZE_ON_EXIT_MODE_NONE, MINIMIZE_ON_EXIT_MODE_BACKGROUND,
|
||||||
|
MINIMIZE_ON_EXIT_MODE_POPUP})
|
||||||
|
public @interface MinimizeMode {
|
||||||
|
int MINIMIZE_ON_EXIT_MODE_NONE = 0;
|
||||||
|
int MINIMIZE_ON_EXIT_MODE_BACKGROUND = 1;
|
||||||
|
int MINIMIZE_ON_EXIT_MODE_POPUP = 2;
|
||||||
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// Exposed helpers
|
// Exposed helpers
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
@ -173,6 +185,22 @@ public class PlayerHelper {
|
|||||||
return isAutoQueueEnabled(context, false);
|
return isAutoQueueEnabled(context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MinimizeMode
|
||||||
|
public static int getMinimizeOnExitAction(@NonNull final Context context) {
|
||||||
|
final String defaultAction = context.getString(R.string.minimize_on_exit_none_key);
|
||||||
|
final String popupAction = context.getString(R.string.minimize_on_exit_popup_key);
|
||||||
|
final String backgroundAction = context.getString(R.string.minimize_on_exit_background_key);
|
||||||
|
|
||||||
|
final String action = getMinimizeOnExitAction(context, defaultAction);
|
||||||
|
if (action.equals(popupAction)) {
|
||||||
|
return MINIMIZE_ON_EXIT_MODE_POPUP;
|
||||||
|
} else if (action.equals(backgroundAction)) {
|
||||||
|
return MINIMIZE_ON_EXIT_MODE_BACKGROUND;
|
||||||
|
} else {
|
||||||
|
return MINIMIZE_ON_EXIT_MODE_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static SeekParameters getSeekParameters(@NonNull final Context context) {
|
public static SeekParameters getSeekParameters(@NonNull final Context context) {
|
||||||
return isUsingInexactSeek(context, false) ?
|
return isUsingInexactSeek(context, false) ?
|
||||||
@ -249,7 +277,6 @@ public class PlayerHelper {
|
|||||||
* System font scaling:
|
* System font scaling:
|
||||||
* Very small - 0.25f, Small - 0.5f, Normal - 1.0f, Large - 1.5f, Very Large - 2.0f
|
* Very small - 0.25f, Small - 0.5f, Normal - 1.0f, Large - 1.5f, Very Large - 2.0f
|
||||||
* */
|
* */
|
||||||
@NonNull
|
|
||||||
public static float getCaptionScale(@NonNull final Context context) {
|
public static float getCaptionScale(@NonNull final Context context) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return 1f;
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return 1f;
|
||||||
|
|
||||||
@ -322,4 +349,10 @@ public class PlayerHelper {
|
|||||||
return sp.getFloat(context.getString(R.string.screen_brightness_key), screenBrightness);
|
return sp.getFloat(context.getString(R.string.screen_brightness_key), screenBrightness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getMinimizeOnExitAction(@NonNull final Context context,
|
||||||
|
final String key) {
|
||||||
|
return getPreferences(context).getString(context.getString(R.string.minimize_on_exit_key),
|
||||||
|
key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,22 @@
|
|||||||
<string name="screen_brightness_key" translatable="false">screen_brightness_key</string>
|
<string name="screen_brightness_key" translatable="false">screen_brightness_key</string>
|
||||||
<string name="screen_brightness_timestamp_key" translatable="false">screen_brightness_timestamp_key</string>
|
<string name="screen_brightness_timestamp_key" translatable="false">screen_brightness_timestamp_key</string>
|
||||||
|
|
||||||
|
<string name="minimize_on_exit_key" translatable="false">minimize_on_exit_key</string>
|
||||||
|
<string name="minimize_on_exit_value" translatable="false">@string/minimize_on_exit_none_key</string>
|
||||||
|
<string name="minimize_on_exit_none_key" translatable="false">minimize_on_exit_none_key</string>
|
||||||
|
<string name="minimize_on_exit_background_key" translatable="false">minimize_on_exit_background_key</string>
|
||||||
|
<string name="minimize_on_exit_popup_key" translatable="false">minimize_on_exit_popup_key</string>
|
||||||
|
<string-array name="minimize_on_exit_action_key" translatable="false">
|
||||||
|
<item>@string/minimize_on_exit_none_key</item>
|
||||||
|
<item>@string/minimize_on_exit_background_key</item>
|
||||||
|
<item>@string/minimize_on_exit_popup_key</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="minimize_on_exit_action_description" translatable="false">
|
||||||
|
<item>@string/minimize_on_exit_none_description</item>
|
||||||
|
<item>@string/minimize_on_exit_background_description</item>
|
||||||
|
<item>@string/minimize_on_exit_popup_description</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="default_resolution_key" translatable="false">default_resolution</string>
|
<string name="default_resolution_key" translatable="false">default_resolution</string>
|
||||||
<string name="default_resolution_value" translatable="false">360p</string>
|
<string name="default_resolution_value" translatable="false">360p</string>
|
||||||
<string name="show_higher_resolutions_key" translatable="false">show_higher_resolutions</string>
|
<string name="show_higher_resolutions_key" translatable="false">show_higher_resolutions</string>
|
||||||
|
@ -504,4 +504,11 @@
|
|||||||
<item>144p</item>
|
<item>144p</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- Minimize to exit action -->
|
||||||
|
<string name="minimize_on_exit_title">Minimize on application switch</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_background_description">Minimize to background player</string>
|
||||||
|
<string name="minimize_on_exit_popup_description">Minimize to popup player</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -90,6 +90,14 @@
|
|||||||
android:summary="@string/preferred_open_action_settings_summary"
|
android:summary="@string/preferred_open_action_settings_summary"
|
||||||
android:title="@string/preferred_open_action_settings_title"/>
|
android:title="@string/preferred_open_action_settings_title"/>
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/minimize_on_exit_value"
|
||||||
|
android:entries="@array/minimize_on_exit_action_description"
|
||||||
|
android:entryValues="@array/minimize_on_exit_action_key"
|
||||||
|
android:key="@string/minimize_on_exit_key"
|
||||||
|
android:summary="@string/minimize_on_exit_summary"
|
||||||
|
android:title="@string/minimize_on_exit_title"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="@string/resume_on_audio_focus_gain_key"
|
android:key="@string/resume_on_audio_focus_gain_key"
|
||||||
|
Loading…
Reference in New Issue
Block a user