Add screen orientation configure for reading
This commit is contained in:
1 parent
125fe0e691
commit
87e714aff6
9 files changed
+112
-6
No files matched your search
@@ -368,6 +368,17 @@ public class Settings {
|
||||
/********************
|
||||
****** Read
|
||||
********************/
|
||||
private static final String KEY_SCREEN_ROTATION = "screen_rotation";
|
||||
private static final int DEFAULT_SCREEN_ROTATION = 0;
|
||||
|
||||
public static int getScreenRotation() {
|
||||
return getIntFromStr(KEY_SCREEN_ROTATION, DEFAULT_SCREEN_ROTATION);
|
||||
}
|
||||
|
||||
public static void putScreenRotation(int value) {
|
||||
putIntToStr(KEY_SCREEN_ROTATION, value);
|
||||
}
|
||||
|
||||
private static final String KEY_READING_DIRECTION = "reading_direction";
|
||||
private static final int DEFAULT_READING_DIRECTION = GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
@@ -283,6 +284,22 @@ public class GalleryActivity extends EhActivity
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
// Orientation
|
||||
int orientation;
|
||||
switch (Settings.getScreenRotation()) {
|
||||
default:
|
||||
case 0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
break;
|
||||
case 1:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
|
||||
break;
|
||||
case 2:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
||||
break;
|
||||
}
|
||||
setRequestedOrientation(orientation);
|
||||
|
||||
if (Settings.getGuideGallery()) {
|
||||
FrameLayout mainLayout = (FrameLayout) ViewUtils.$$(this, R.id.main);
|
||||
mainLayout.addView(new GalleryGuideView(this));
|
||||
@@ -653,6 +670,7 @@ public class GalleryActivity extends EhActivity
|
||||
private class GalleryMenuHelper implements DialogInterface.OnClickListener {
|
||||
|
||||
private final View mView;
|
||||
private final Spinner mScreenRotation;
|
||||
private final Spinner mReadingDirection;
|
||||
private final Spinner mScaleMode;
|
||||
private final Spinner mStartPosition;
|
||||
@@ -664,6 +682,7 @@ public class GalleryActivity extends EhActivity
|
||||
@SuppressLint("InflateParams")
|
||||
public GalleryMenuHelper(Context context) {
|
||||
mView = LayoutInflater.from(context).inflate(R.layout.dialog_gallery_menu, null);
|
||||
mScreenRotation = (Spinner) mView.findViewById(R.id.screen_rotation);
|
||||
mReadingDirection = (Spinner) mView.findViewById(R.id.reading_direction);
|
||||
mScaleMode = (Spinner) mView.findViewById(R.id.page_scaling);
|
||||
mStartPosition = (Spinner) mView.findViewById(R.id.start_position);
|
||||
@@ -672,6 +691,7 @@ public class GalleryActivity extends EhActivity
|
||||
mShowBattery = (SwitchCompat) mView.findViewById(R.id.show_battery);
|
||||
mVolumePage = (SwitchCompat) mView.findViewById(R.id.volume_page);
|
||||
|
||||
mScreenRotation.setSelection(Settings.getScreenRotation());
|
||||
mReadingDirection.setSelection(Settings.getReadingDirection());
|
||||
mScaleMode.setSelection(Settings.getPageScaling());
|
||||
mStartPosition.setSelection(Settings.getStartPosition());
|
||||
@@ -687,6 +707,7 @@ public class GalleryActivity extends EhActivity
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int screenRotation = mScreenRotation.getSelectedItemPosition();
|
||||
int layoutMode = GalleryView.sanitizeLayoutMode(mReadingDirection.getSelectedItemPosition());
|
||||
int scaleMode = ImageView.sanitizeScaleMode(mScaleMode.getSelectedItemPosition());
|
||||
int startPosition = ImageView.sanitizeStartPosition(mStartPosition.getSelectedItemPosition());
|
||||
@@ -695,6 +716,7 @@ public class GalleryActivity extends EhActivity
|
||||
boolean showBattery = mShowBattery.isChecked();
|
||||
boolean volumePage = mVolumePage.isChecked();
|
||||
|
||||
Settings.putScreenRotation(screenRotation);
|
||||
Settings.putReadingDirection(layoutMode);
|
||||
Settings.putPageScaling(scaleMode);
|
||||
Settings.putStartPosition(startPosition);
|
||||
@@ -703,6 +725,20 @@ public class GalleryActivity extends EhActivity
|
||||
Settings.putShowBattery(showBattery);
|
||||
Settings.putVolumePage(volumePage);
|
||||
|
||||
int orientation;
|
||||
switch (screenRotation) {
|
||||
default:
|
||||
case 0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
break;
|
||||
case 1:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
|
||||
break;
|
||||
case 2:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
||||
break;
|
||||
}
|
||||
setRequestedOrientation(orientation);
|
||||
if (mGalleryView != null) {
|
||||
mGalleryView.setLayoutMode(layoutMode);
|
||||
mGalleryView.setScaleMode(scaleMode);
|
||||
|
||||
Reference in new issue
Block a user