Merge pull request #895 from TeamNewPipe/remember
remember last screen orientation
This commit is contained in:
commit
3a85187111
|
@ -22,12 +22,15 @@ package org.schabi.newpipe.player;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
@ -81,6 +84,8 @@ public final class MainVideoPlayer extends Activity {
|
||||||
private boolean activityPaused;
|
private boolean activityPaused;
|
||||||
private VideoPlayerImpl playerImpl;
|
private VideoPlayerImpl playerImpl;
|
||||||
|
|
||||||
|
private SharedPreferences defaultPreferences;
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Activity LifeCycle
|
// Activity LifeCycle
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -89,6 +94,7 @@ public final class MainVideoPlayer extends Activity {
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
||||||
|
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
ThemeHelper.setTheme(this);
|
ThemeHelper.setTheme(this);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.BLACK);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.BLACK);
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
|
@ -99,6 +105,8 @@ public final class MainVideoPlayer extends Activity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
showSystemUi();
|
showSystemUi();
|
||||||
setContentView(R.layout.activity_main_player);
|
setContentView(R.layout.activity_main_player);
|
||||||
playerImpl = new VideoPlayerImpl(this);
|
playerImpl = new VideoPlayerImpl(this);
|
||||||
|
@ -146,6 +154,11 @@ public final class MainVideoPlayer extends Activity {
|
||||||
|
|
||||||
activityPaused = false;
|
activityPaused = false;
|
||||||
}
|
}
|
||||||
|
if(globalScreenOrientationLocked()) {
|
||||||
|
boolean lastOrientationWasLandscape
|
||||||
|
= defaultPreferences.getBoolean(getString(R.string.last_orientation_landscape_key), false);
|
||||||
|
setLandScape(lastOrientationWasLandscape);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -198,11 +211,28 @@ public final class MainVideoPlayer extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleOrientation() {
|
private void toggleOrientation() {
|
||||||
setRequestedOrientation(getResources().getDisplayMetrics().heightPixels > getResources().getDisplayMetrics().widthPixels
|
setLandScape(!isLandScape());
|
||||||
|
defaultPreferences.edit()
|
||||||
|
.putBoolean(getString(R.string.last_orientation_landscape_key), !isLandScape())
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLandScape() {
|
||||||
|
return getResources().getDisplayMetrics().heightPixels < getResources().getDisplayMetrics().widthPixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setLandScape(boolean v) {
|
||||||
|
setRequestedOrientation(v
|
||||||
? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||||
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean globalScreenOrientationLocked() {
|
||||||
|
// 1: Screen orientation changes using acelerometer
|
||||||
|
// 0: Screen orientatino is locked
|
||||||
|
return !(android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
protected void setRepeatModeButton(final ImageButton imageButton, final int repeatMode) {
|
protected void setRepeatModeButton(final ImageButton imageButton, final int repeatMode) {
|
||||||
switch (repeatMode) {
|
switch (repeatMode) {
|
||||||
case Player.REPEAT_MODE_OFF:
|
case Player.REPEAT_MODE_OFF:
|
||||||
|
|
|
@ -75,6 +75,8 @@
|
||||||
<item>@string/audio_webm_key</item>
|
<item>@string/audio_webm_key</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string name="last_orientation_landscape_key" translatable="false">last_orientation_landscape_key</string>
|
||||||
|
|
||||||
<!-- THEMES -->
|
<!-- THEMES -->
|
||||||
<string name="theme_key" translatable="false">theme</string>
|
<string name="theme_key" translatable="false">theme</string>
|
||||||
<string name="light_theme_key" translatable="false">light_theme</string>
|
<string name="light_theme_key" translatable="false">light_theme</string>
|
||||||
|
|
Loading…
Reference in New Issue