mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Allow to force a rotation
This commit is contained in:
		| @@ -60,6 +60,10 @@ public class PreferencesHelper { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_lock_orientation_key), true); | ||||
|     } | ||||
|  | ||||
|     public Preference<Integer> rotation() { | ||||
|         return rxPrefs.getInteger(getKey(R.string.pref_rotation_type_key), 1); | ||||
|     } | ||||
|  | ||||
|     public Preference<Boolean> enableTransitions() { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_enable_transitions_key), true); | ||||
|     } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.reader; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.pm.ActivityInfo; | ||||
| import android.content.res.Configuration; | ||||
| import android.graphics.Color; | ||||
| import android.os.Build; | ||||
| import android.os.Bundle; | ||||
| @@ -13,7 +14,6 @@ import android.support.v7.widget.Toolbar; | ||||
| import android.view.KeyEvent; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuItem; | ||||
| import android.view.Surface; | ||||
| import android.view.View; | ||||
| import android.view.WindowManager; | ||||
| import android.widget.TextView; | ||||
| @@ -277,9 +277,9 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|                 .asObservable() | ||||
|                 .subscribe(this::setPageNumberVisibility)); | ||||
|  | ||||
|         subscriptions.add(preferences.lockOrientation() | ||||
|         subscriptions.add(preferences.rotation() | ||||
|                 .asObservable() | ||||
|                 .subscribe(this::setOrientation)); | ||||
|                 .subscribe(this::setRotation)); | ||||
|  | ||||
|         subscriptions.add(preferences.hideStatusBar() | ||||
|                 .asObservable() | ||||
| @@ -299,28 +299,25 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|                 .subscribe(this::applyTheme)); | ||||
|     } | ||||
|  | ||||
|     private void setOrientation(boolean locked) { | ||||
|         if (locked) { | ||||
|             int orientation; | ||||
|             int rotation = ((WindowManager) getSystemService( | ||||
|                     Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); | ||||
|             switch (rotation) { | ||||
|                 case Surface.ROTATION_0: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; | ||||
|                     break; | ||||
|                 case Surface.ROTATION_90: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; | ||||
|                     break; | ||||
|                 case Surface.ROTATION_180: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; | ||||
|                     break; | ||||
|                 default: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; | ||||
|                     break; | ||||
|             } | ||||
|             setRequestedOrientation(orientation); | ||||
|         } else { | ||||
|             setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); | ||||
|     private void setRotation(int rotation) { | ||||
|         switch (rotation) { | ||||
|             // Rotation free | ||||
|             case 1: | ||||
|                 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); | ||||
|                 break; | ||||
|             // Lock in current rotation | ||||
|             case 2: | ||||
|                 int currentOrientation = getResources().getConfiguration().orientation; | ||||
|                 setRotation(currentOrientation == Configuration.ORIENTATION_PORTRAIT ? 3 : 4); | ||||
|                 break; | ||||
|             // Lock in portrait | ||||
|             case 3: | ||||
|                 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); | ||||
|                 break; | ||||
|             // Lock in landscape | ||||
|             case 4: | ||||
|                 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.reader; | ||||
|  | ||||
| import android.app.Dialog; | ||||
| import android.content.Context; | ||||
| import android.content.res.Configuration; | ||||
| import android.support.v7.widget.Toolbar; | ||||
| import android.view.Gravity; | ||||
| import android.view.Menu; | ||||
| @@ -178,20 +179,31 @@ public class ReaderMenu { | ||||
|         if (nextChapterBtn != null) nextChapterBtn.setVisible(nextChapter != null); | ||||
|     } | ||||
|  | ||||
|     @SuppressWarnings("ConstantConditions") | ||||
|     private void initializeMenu() { | ||||
|         // Orientation changes | ||||
|         // Orientation selector | ||||
|         add(preferences.lockOrientation().asObservable() | ||||
|                 .subscribe(locked -> { | ||||
|                     int resourceId = !locked ? R.drawable.ic_screen_rotation : | ||||
|                             activity.getResources().getConfiguration().orientation == 1 ? | ||||
|                     boolean isPortrait = activity.getResources().getConfiguration() | ||||
|                             .orientation == Configuration.ORIENTATION_PORTRAIT; | ||||
|                     int resourceId = !locked ? R.drawable.ic_screen_rotation : isPortrait ? | ||||
|                                     R.drawable.ic_screen_lock_portrait : | ||||
|                                     R.drawable.ic_screen_lock_landscape; | ||||
|  | ||||
|                     lockOrientation.setImageResource(resourceId); | ||||
|                 })); | ||||
|  | ||||
|         lockOrientation.setOnClickListener(v -> | ||||
|                 preferences.lockOrientation().set(!preferences.lockOrientation().get())); | ||||
|         lockOrientation.setOnClickListener(v -> { | ||||
|             showImmersiveDialog(new MaterialDialog.Builder(activity) | ||||
|                     .title(R.string.pref_rotation_type) | ||||
|                     .items(R.array.rotation_type) | ||||
|                     .itemsCallbackSingleChoice(preferences.rotation().get() - 1, | ||||
|                             (d, itemView, which, text) -> { | ||||
|                                 preferences.rotation().set(which + 1); | ||||
|                                 return true; | ||||
|                             }) | ||||
|                     .build()); | ||||
|         }); | ||||
|  | ||||
|         // Zoom selector | ||||
|         zoomSelector.setOnClickListener(v -> { | ||||
| @@ -279,6 +291,7 @@ public class ReaderMenu { | ||||
|             initializePopupMenu(); | ||||
|         } | ||||
|  | ||||
|         @SuppressWarnings("ConstantConditions") | ||||
|         private void initializePopupMenu() { | ||||
|             // Load values from preferences | ||||
|             enableTransitions.setChecked(preferences.enableTransitions().get()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user