diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index a5c473dc8..4c9c6de1a 100644 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -136,16 +136,35 @@ public class Settings { private static final String KEY_READING_DIRECTION = "reading_direction"; private static final int DEFAULT_READING_DIRECTION = GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT; - @SuppressWarnings("WrongConstant") @GalleryView.LayoutMode public static int getReadingDirection() { - int value = getIntFromStr(KEY_READING_DIRECTION, DEFAULT_READING_DIRECTION); - if (value != GalleryView.LAYOUT_MODE_LEFT_TO_RIGHT && - value != GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT && - value != GalleryView.LAYOUT_MODE_TOP_TO_BOTTOM) { - value = GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT; - } - return value; + return GalleryView.sanitizeLayoutMode(getIntFromStr(KEY_READING_DIRECTION, DEFAULT_READING_DIRECTION)); + } + + public static void putReadingDirection(int value) { + putIntToStr(KEY_READING_DIRECTION, value); + } + + private static final String KEY_SHOW_CLOCK = "gallery_show_clock"; + private static final boolean DEFAULT_SHOW_CLOCK = true; + + public static boolean getShowClock() { + return getBoolean(KEY_SHOW_CLOCK, DEFAULT_SHOW_CLOCK); + } + + public static void putShowClock(boolean value) { + putBoolean(KEY_SHOW_CLOCK, value); + } + + private static final String KEY_SHOW_BATTERY = "gallery_show_battery"; + private static final boolean DEFAULT_SHOW_BATTERY = true; + + public static boolean getShowBattery() { + return getBoolean(KEY_SHOW_BATTERY, DEFAULT_SHOW_BATTERY); + } + + public static void putShowBattery(boolean value) { + putBoolean(KEY_SHOW_BATTERY, value); } private static final String KEY_VOLUME_PAGE = "volume_page"; @@ -155,6 +174,10 @@ public class Settings { return getBoolean(KEY_VOLUME_PAGE, DEFAULT_VOLUME_PAGE); } + public static void putVolumePage(boolean value) { + putBoolean(KEY_VOLUME_PAGE, value); + } + public static final String KEY_DOWNLOAD_SAVE_SCHEME = "image_scheme"; public static final String KEY_DOWNLOAD_SAVE_AUTHORITY = "image_authority"; public static final String KEY_DOWNLOAD_SAVE_PATH = "image_path"; diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java b/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java index 553541102..6f136d490 100644 --- a/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java +++ b/app/src/main/java/com/hippo/ehviewer/gallery/gl/GalleryView.java @@ -247,6 +247,17 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener { mPageTextTexture = null; } + @LayoutMode + public static int sanitizeLayoutMode(int layoutMode) { + if (layoutMode != GalleryView.LAYOUT_MODE_LEFT_TO_RIGHT && + layoutMode != GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT && + layoutMode != GalleryView.LAYOUT_MODE_TOP_TO_BOTTOM) { + return GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT; + } else { + return layoutMode; + } + } + public int getLayoutMode() { return mLayoutMode; } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java index c9e44279f..85e3d65df 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java @@ -26,8 +26,10 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.SwitchCompat; import android.view.KeyEvent; import android.view.View; +import android.widget.Spinner; import android.widget.TextView; import com.hippo.anani.AnimationUtils; @@ -81,6 +83,10 @@ public class GalleryActivity extends AppCompatActivity private SystemUiHelper mSystemUiHelper; private boolean mSystemUiShowing = false; + @Nullable + private View mClock; + @Nullable + private View mBattery; @Nullable private View mSliderPanel; @Nullable @@ -201,6 +207,16 @@ public class GalleryActivity extends AppCompatActivity mSystemUiShowing = true; } + mClock = findViewById(R.id.clock); + mBattery = findViewById(R.id.battery); + + if (mClock != null && !Settings.getShowClock()) { + mClock.setVisibility(View.GONE); + } + if (mBattery != null && !Settings.getShowBattery()) { + mBattery.setVisibility(View.GONE); + } + mSliderPanel = findViewById(R.id.slider_panel); mLeftText = (TextView) mSliderPanel.findViewById(R.id.left); mRightText = (TextView) mSliderPanel.findViewById(R.id.right); @@ -481,6 +497,56 @@ public class GalleryActivity extends AppCompatActivity SimpleHandler.getInstance().post(task); } + private class GalleryMenuHelper implements DialogInterface.OnClickListener { + + private final View mView; + private final Spinner mReadingDirection; + private final SwitchCompat mShowClock; + private final SwitchCompat mShowBattery; + private final SwitchCompat mVolumePage; + + @SuppressLint("InflateParams") + public GalleryMenuHelper() { + mView = getLayoutInflater().inflate(R.layout.dialog_gallery_menu, null); + mReadingDirection = (Spinner) mView.findViewById(R.id.reading_direction); + mShowClock = (SwitchCompat) mView.findViewById(R.id.show_clock); + mShowBattery = (SwitchCompat) mView.findViewById(R.id.show_battery); + mVolumePage = (SwitchCompat) mView.findViewById(R.id.volume_page); + + mReadingDirection.setSelection(Settings.getReadingDirection()); + mShowClock.setChecked(Settings.getShowClock()); + mShowBattery.setChecked(Settings.getShowBattery()); + mVolumePage.setChecked(Settings.getVolumePage()); + } + + public View getView() { + return mView; + } + + @Override + public void onClick(DialogInterface dialog, int which) { + int layoutMode = GalleryView.sanitizeLayoutMode(mReadingDirection.getSelectedItemPosition()); + boolean showClock = mShowClock.isChecked(); + boolean showBattery = mShowBattery.isChecked(); + boolean volumePage = mVolumePage.isChecked(); + + Settings.putReadingDirection(layoutMode); + Settings.putShowClock(showClock); + Settings.putShowBattery(showBattery); + Settings.putVolumePage(volumePage); + + if (mGalleryView != null) { + mGalleryView.setLayoutMode(layoutMode); + } + if (mClock != null) { + mClock.setVisibility(showClock ? View.VISIBLE : View.GONE); + } + if (mBattery != null) { + mBattery.setVisibility(showBattery ? View.VISIBLE : View.GONE); + } + } + } + private class NotifyTask implements Runnable { public static final int KEY_LAYOUT_MODE = 0; @@ -499,8 +565,11 @@ public class GalleryActivity extends AppCompatActivity } private void onTapMenuArea() { + GalleryMenuHelper helper = new GalleryMenuHelper(); new AlertDialog.Builder(GalleryActivity.this) - .setTitle(R.string.gallery_menu_title).show(); + .setTitle(R.string.gallery_menu_title) + .setView(helper.getView()) + .setPositiveButton(android.R.string.ok, helper).show(); } private void onTapSliderArea() { diff --git a/app/src/main/res/layout/dialog_gallery_menu.xml b/app/src/main/res/layout/dialog_gallery_menu.xml index 521e39abd..2ecb9a477 100644 --- a/app/src/main/res/layout/dialog_gallery_menu.xml +++ b/app/src/main/res/layout/dialog_gallery_menu.xml @@ -19,6 +19,50 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:padding="@dimen/keyline_margin" + android:divider="@drawable/spacer_keyline" + android:showDividers="middle"> + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 85291b167..5ef45141c 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -191,6 +191,8 @@ 从左至右 从右至左 从上至下 + 显示时钟 + 显示电量 使用音量键翻页 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c303df33e..1fde2f94e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -230,6 +230,8 @@ Left to right Right to left Top to bottom + Show clock + Show battery Use volume key to turn pages diff --git a/app/src/main/res/xml/read_settings.xml b/app/src/main/res/xml/read_settings.xml index 3af79229b..21f7417c3 100644 --- a/app/src/main/res/xml/read_settings.xml +++ b/app/src/main/res/xml/read_settings.xml @@ -26,6 +26,20 @@ android:entryValues="@array/reading_direction_entry_values" android:defaultValue="1"/> + + + +