mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 16:09:16 +01:00
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);
|
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() {
|
public Preference<Boolean> enableTransitions() {
|
||||||
return rxPrefs.getBoolean(getKey(R.string.pref_enable_transitions_key), true);
|
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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -13,7 +14,6 @@ import android.support.v7.widget.Toolbar;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.Surface;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -277,9 +277,9 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
|||||||
.asObservable()
|
.asObservable()
|
||||||
.subscribe(this::setPageNumberVisibility));
|
.subscribe(this::setPageNumberVisibility));
|
||||||
|
|
||||||
subscriptions.add(preferences.lockOrientation()
|
subscriptions.add(preferences.rotation()
|
||||||
.asObservable()
|
.asObservable()
|
||||||
.subscribe(this::setOrientation));
|
.subscribe(this::setRotation));
|
||||||
|
|
||||||
subscriptions.add(preferences.hideStatusBar()
|
subscriptions.add(preferences.hideStatusBar()
|
||||||
.asObservable()
|
.asObservable()
|
||||||
@ -299,28 +299,25 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
|||||||
.subscribe(this::applyTheme));
|
.subscribe(this::applyTheme));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOrientation(boolean locked) {
|
private void setRotation(int rotation) {
|
||||||
if (locked) {
|
switch (rotation) {
|
||||||
int orientation;
|
// Rotation free
|
||||||
int rotation = ((WindowManager) getSystemService(
|
case 1:
|
||||||
Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||||
switch (rotation) {
|
break;
|
||||||
case Surface.ROTATION_0:
|
// Lock in current rotation
|
||||||
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
case 2:
|
||||||
break;
|
int currentOrientation = getResources().getConfiguration().orientation;
|
||||||
case Surface.ROTATION_90:
|
setRotation(currentOrientation == Configuration.ORIENTATION_PORTRAIT ? 3 : 4);
|
||||||
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
break;
|
||||||
break;
|
// Lock in portrait
|
||||||
case Surface.ROTATION_180:
|
case 3:
|
||||||
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
||||||
break;
|
break;
|
||||||
default:
|
// Lock in landscape
|
||||||
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
case 4:
|
||||||
break;
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
||||||
}
|
break;
|
||||||
setRequestedOrientation(orientation);
|
|
||||||
} else {
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.reader;
|
|||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -178,20 +179,31 @@ public class ReaderMenu {
|
|||||||
if (nextChapterBtn != null) nextChapterBtn.setVisible(nextChapter != null);
|
if (nextChapterBtn != null) nextChapterBtn.setVisible(nextChapter != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
private void initializeMenu() {
|
private void initializeMenu() {
|
||||||
// Orientation changes
|
// Orientation selector
|
||||||
add(preferences.lockOrientation().asObservable()
|
add(preferences.lockOrientation().asObservable()
|
||||||
.subscribe(locked -> {
|
.subscribe(locked -> {
|
||||||
int resourceId = !locked ? R.drawable.ic_screen_rotation :
|
boolean isPortrait = activity.getResources().getConfiguration()
|
||||||
activity.getResources().getConfiguration().orientation == 1 ?
|
.orientation == Configuration.ORIENTATION_PORTRAIT;
|
||||||
|
int resourceId = !locked ? R.drawable.ic_screen_rotation : isPortrait ?
|
||||||
R.drawable.ic_screen_lock_portrait :
|
R.drawable.ic_screen_lock_portrait :
|
||||||
R.drawable.ic_screen_lock_landscape;
|
R.drawable.ic_screen_lock_landscape;
|
||||||
|
|
||||||
lockOrientation.setImageResource(resourceId);
|
lockOrientation.setImageResource(resourceId);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
lockOrientation.setOnClickListener(v ->
|
lockOrientation.setOnClickListener(v -> {
|
||||||
preferences.lockOrientation().set(!preferences.lockOrientation().get()));
|
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
|
// Zoom selector
|
||||||
zoomSelector.setOnClickListener(v -> {
|
zoomSelector.setOnClickListener(v -> {
|
||||||
@ -279,6 +291,7 @@ public class ReaderMenu {
|
|||||||
initializePopupMenu();
|
initializePopupMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
private void initializePopupMenu() {
|
private void initializePopupMenu() {
|
||||||
// Load values from preferences
|
// Load values from preferences
|
||||||
enableTransitions.setChecked(preferences.enableTransitions().get());
|
enableTransitions.setChecked(preferences.enableTransitions().get());
|
||||||
|
@ -80,6 +80,20 @@
|
|||||||
<item>4</item>
|
<item>4</item>
|
||||||
</string-array>
|
</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">
|
<string-array name="library_update_interval">
|
||||||
<item>@string/update_never</item>
|
<item>@string/update_never</item>
|
||||||
<item>@string/update_1hour</item>
|
<item>@string/update_1hour</item>
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
<string name="pref_zoom_start_key">pref_zoom_start_key</string>
|
<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_hide_status_bar_key">pref_hide_status_bar_key</string>
|
||||||
<string name="pref_lock_orientation_key">pref_lock_orientation_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_enable_transitions_key">pref_enable_transitions_key</string>
|
||||||
<string name="pref_show_page_number_key">pref_show_page_number_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>
|
<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_left">Left</string>
|
||||||
<string name="zoom_start_right">Right</string>
|
<string name="zoom_start_right">Right</string>
|
||||||
<string name="zoom_start_center">Center</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 -->
|
<!-- Downloads section -->
|
||||||
<string name="pref_download_directory">Downloads directory</string>
|
<string name="pref_download_directory">Downloads directory</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user