Allow to force a rotation
This commit is contained in:
parent
56a45f263e
commit
140bf8caee
@ -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());
|
||||
|
@ -80,6 +80,20 @@
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="rotation_type">
|
||||
<item>@string/rotation_free</item>
|
||||
<item>@string/rotation_lock</item>
|
||||
<item>@string/rotation_force_portrait</item>
|
||||
<item>@string/rotation_force_landscape</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="rotation_type_values">
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="library_update_interval">
|
||||
<item>@string/update_never</item>
|
||||
<item>@string/update_1hour</item>
|
||||
|
@ -20,6 +20,7 @@
|
||||
<string name="pref_zoom_start_key">pref_zoom_start_key</string>
|
||||
<string name="pref_hide_status_bar_key">pref_hide_status_bar_key</string>
|
||||
<string name="pref_lock_orientation_key">pref_lock_orientation_key</string>
|
||||
<string name="pref_rotation_type_key">pref_rotation_type_key</string>
|
||||
<string name="pref_enable_transitions_key">pref_enable_transitions_key</string>
|
||||
<string name="pref_show_page_number_key">pref_show_page_number_key</string>
|
||||
<string name="pref_keep_screen_on_key">pref_keep_screen_on_key</string>
|
||||
|
@ -111,6 +111,12 @@
|
||||
<string name="zoom_start_left">Left</string>
|
||||
<string name="zoom_start_right">Right</string>
|
||||
<string name="zoom_start_center">Center</string>
|
||||
<string name="pref_rotation_type">Rotation</string>
|
||||
<string name="rotation_free">Free</string>
|
||||
<string name="rotation_lock">Lock</string>
|
||||
<string name="rotation_force_portrait">Force portrait</string>
|
||||
<string name="rotation_force_landscape">Force landscape</string>
|
||||
|
||||
|
||||
<!-- Downloads section -->
|
||||
<string name="pref_download_directory">Downloads directory</string>
|
||||
|
Loading…
Reference in New Issue
Block a user