|
1 | 1 | package org.schabi.newpipe; |
2 | 2 |
|
| 3 | +import android.content.Context; |
3 | 4 | import android.content.Intent; |
| 5 | +import android.content.SharedPreferences; |
4 | 6 | import android.content.pm.ActivityInfo; |
5 | 7 | import android.content.res.Configuration; |
6 | 8 | import android.content.res.Resources; |
@@ -72,6 +74,9 @@ public class PlayVideoActivity extends AppCompatActivity { |
72 | 74 | private boolean isLandscape = true; |
73 | 75 | private boolean hasSoftKeys = false; |
74 | 76 |
|
| 77 | + private SharedPreferences prefs; |
| 78 | + private static final String PREF_IS_LANDSCAPE = "is_landscape"; |
| 79 | + |
75 | 80 | @Override |
76 | 81 | protected void onCreate(Bundle savedInstanceState) { |
77 | 82 | super.onCreate(savedInstanceState); |
@@ -136,12 +141,16 @@ public void onSystemUiVisibilityChange(int visibility) { |
136 | 141 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
137 | 142 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
138 | 143 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
| 144 | + |
| 145 | + prefs = getPreferences(Context.MODE_PRIVATE); |
| 146 | + if(prefs.getBoolean(PREF_IS_LANDSCAPE, false) && !isLandscape) { |
| 147 | + toggleOrientation(); |
| 148 | + } |
139 | 149 | } |
140 | 150 |
|
141 | 151 | @Override |
142 | 152 | protected void onPostCreate(Bundle savedInstanceState) { |
143 | 153 | super.onPostCreate(savedInstanceState); |
144 | | - |
145 | 154 | } |
146 | 155 |
|
147 | 156 | @Override |
@@ -179,14 +188,7 @@ public boolean onOptionsItemSelected(MenuItem item) { |
179 | 188 | startActivity(Intent.createChooser(intent, getString(R.string.shareDialogTitle))); |
180 | 189 | break; |
181 | 190 | case R.id.menu_item_screen_rotation: |
182 | | - Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); |
183 | | - if(display.getRotation() == Surface.ROTATION_0 |
184 | | - || display.getRotation() == Surface.ROTATION_180) { |
185 | | - setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
186 | | - } else if(display.getRotation() == Surface.ROTATION_90 |
187 | | - || display.getRotation() == Surface.ROTATION_270) { |
188 | | - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
189 | | - } |
| 191 | + toggleOrientation(); |
190 | 192 | break; |
191 | 193 | default: |
192 | 194 | Log.e(TAG, "Error: MenuItem not known"); |
@@ -319,4 +321,17 @@ public boolean checkIfLandscape() { |
319 | 321 | getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); |
320 | 322 | return displayMetrics.heightPixels < displayMetrics.widthPixels; |
321 | 323 | } |
| 324 | + |
| 325 | + private void toggleOrientation() { |
| 326 | + if(isLandscape) { |
| 327 | + isLandscape = false; |
| 328 | + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 329 | + } else { |
| 330 | + isLandscape = true; |
| 331 | + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); |
| 332 | + } |
| 333 | + SharedPreferences.Editor editor = prefs.edit(); |
| 334 | + editor.putBoolean(PREF_IS_LANDSCAPE, isLandscape); |
| 335 | + editor.commit(); |
| 336 | + } |
322 | 337 | } |
0 commit comments