From 391550f49af5fea980d46dc5df79daf7714f78ba Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 4 Feb 2016 17:16:47 +0100 Subject: [PATCH] Implement zoom start position. Closes #92. Rapid decoder properly throws an error when it fails to decode. --- .../data/preference/PreferencesHelper.java | 4 ++ .../tachiyomi/ui/reader/ReaderMenu.java | 18 ++++++++- .../ui/reader/viewer/pager/PagerReader.java | 36 ++++++++++++++++-- .../viewer/pager/PagerReaderFragment.java | 19 +++++++++ .../ic_crop_original_white_24dp.png | Bin 0 -> 271 bytes .../ic_crop_original_white_24dp.png | Bin 0 -> 237 bytes .../ic_crop_original_white_24dp.png | Bin 0 -> 179 bytes .../ic_crop_original_white_24dp.png | Bin 0 -> 304 bytes .../ic_crop_original_white_24dp.png | Bin 0 -> 441 bytes .../ic_crop_original_white_24dp.png | Bin 0 -> 580 bytes app/src/main/res/layout/reader_menu.xml | 11 ++++++ app/src/main/res/values/arrays.xml | 14 +++++++ app/src/main/res/values/keys.xml | 1 + app/src/main/res/values/strings.xml | 8 +++- app/src/main/res/xml/pref_reader.xml | 8 ++++ .../decoder/RapidImageRegionDecoder.java | 12 +++--- 16 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_crop_original_white_24dp.png create mode 100644 app/src/main/res/drawable-ldpi/ic_crop_original_white_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_crop_original_white_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_crop_original_white_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_crop_original_white_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_crop_original_white_24dp.png diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java index ba8668658b..eacead9252 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.java @@ -116,6 +116,10 @@ public class PreferencesHelper { return rxPrefs.getInteger(getKey(R.string.pref_image_decoder_key), 0); } + public Preference zoomStart() { + return rxPrefs.getInteger(getKey(R.string.pref_zoom_start_key), 1); + } + public Preference readerTheme() { return rxPrefs.getInteger(getKey(R.string.pref_reader_theme_key), 0); } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java index 76a1c1e383..2645405ac1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderMenu.java @@ -43,9 +43,10 @@ public class ReaderMenu { @Bind(R.id.page_seeker) SeekBar seekBar; @Bind(R.id.total_pages) TextView totalPages; @Bind(R.id.lock_orientation) ImageButton lockOrientation; + @Bind(R.id.reader_zoom_selector) ImageButton zoomSelector; + @Bind(R.id.reader_scale_type_selector) ImageButton scaleTypeSelector; @Bind(R.id.reader_selector) ImageButton readerSelector; @Bind(R.id.reader_extra_settings) ImageButton extraSettings; - @Bind(R.id.reader_scale_type_selector) ImageButton scaleTypeSelector; private MenuItem nextChapterBtn; private MenuItem prevChapterBtn; @@ -189,9 +190,23 @@ public class ReaderMenu { lockOrientation.setOnClickListener(v -> preferences.lockOrientation().set(!preferences.lockOrientation().get())); + // Zoom selector + zoomSelector.setOnClickListener(v -> { + showImmersiveDialog(new MaterialDialog.Builder(activity) + .title(R.string.pref_zoom_start) + .items(R.array.zoom_start) + .itemsCallbackSingleChoice(preferences.zoomStart().get() - 1, + (d, itemView, which, text) -> { + preferences.zoomStart().set(which + 1); + return true; + }) + .build()); + }); + // Scale type selector scaleTypeSelector.setOnClickListener(v -> { showImmersiveDialog(new MaterialDialog.Builder(activity) + .title(R.string.pref_image_scale_type) .items(R.array.image_scale_type) .itemsCallbackSingleChoice(preferences.imageScaleType().get() - 1, (d, itemView, which, text) -> { @@ -205,6 +220,7 @@ public class ReaderMenu { readerSelector.setOnClickListener(v -> { final Manga manga = activity.getPresenter().getManga(); showImmersiveDialog(new MaterialDialog.Builder(activity) + .title(R.string.pref_viewer_type) .items(R.array.viewers_selector) .itemsCallbackSingleChoice(manga.viewer, (d, itemView, which, text) -> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.java index 7f6bd146f7..0bc5562709 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.java @@ -6,10 +6,13 @@ import android.view.ViewGroup; import java.util.List; import eu.kanade.tachiyomi.R; +import eu.kanade.tachiyomi.data.preference.PreferencesHelper; import eu.kanade.tachiyomi.data.source.model.Page; import eu.kanade.tachiyomi.ui.reader.viewer.base.BaseReader; import eu.kanade.tachiyomi.ui.reader.viewer.base.OnChapterBoundariesOutListener; import eu.kanade.tachiyomi.ui.reader.viewer.base.OnChapterSingleTapListener; +import eu.kanade.tachiyomi.ui.reader.viewer.pager.horizontal.LeftToRightReader; +import eu.kanade.tachiyomi.ui.reader.viewer.pager.horizontal.RightToLeftReader; import rx.subscriptions.CompositeSubscription; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; @@ -24,6 +27,12 @@ public abstract class PagerReader extends BaseReader { protected CompositeSubscription subscriptions; protected int scaleType = 1; + protected int zoomStart = 1; + + public static final int ALIGN_AUTO = 1; + public static final int ALIGN_LEFT = 2; + public static final int ALIGN_RIGHT = 3; + public static final int ALIGN_CENTER = 4; protected void initializePager(Pager pager) { this.pager = pager; @@ -61,22 +70,30 @@ public abstract class PagerReader extends BaseReader { adapter = new PagerReaderAdapter(getChildFragmentManager()); pager.setAdapter(adapter); + PreferencesHelper preferences = getReaderActivity().getPreferences(); subscriptions = new CompositeSubscription(); - subscriptions.add(getReaderActivity().getPreferences().imageDecoder() + subscriptions.add(preferences.imageDecoder() .asObservable() .doOnNext(this::setDecoderClass) .skip(1) .distinctUntilChanged() .subscribe(v -> adapter.notifyDataSetChanged())); - subscriptions.add(getReaderActivity().getPreferences().imageScaleType() + subscriptions.add(preferences.imageScaleType() .asObservable() .doOnNext(this::setImageScaleType) .skip(1) .distinctUntilChanged() .subscribe(v -> adapter.notifyDataSetChanged())); - subscriptions.add(getReaderActivity().getPreferences().enableTransitions() + subscriptions.add(preferences.zoomStart() + .asObservable() + .doOnNext(this::setZoomStart) + .skip(1) + .distinctUntilChanged() + .subscribe(v -> adapter.notifyDataSetChanged())); + + subscriptions.add(preferences.enableTransitions() .asObservable() .subscribe(value -> transitions = value)); @@ -125,6 +142,19 @@ public abstract class PagerReader extends BaseReader { this.scaleType = scaleType; } + private void setZoomStart(int zoomStart) { + if (zoomStart == ALIGN_AUTO) { + if (this instanceof LeftToRightReader) + setZoomStart(ALIGN_LEFT); + else if (this instanceof RightToLeftReader) + setZoomStart(ALIGN_RIGHT); + else + setZoomStart(ALIGN_CENTER); + } else { + this.zoomStart = zoomStart; + } + } + public abstract void onFirstPageOut(); public abstract void onLastPageOut(); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.java index a0279d91ce..26892364d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.java @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager; +import android.graphics.PointF; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; @@ -70,6 +71,23 @@ public class PagerReaderFragment extends BaseFragment { imageView.setVerticalScrollingParent(parentFragment instanceof VerticalReader); imageView.setOnTouchListener((v, motionEvent) -> parentFragment.onImageTouch(motionEvent)); imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() { + @Override + public void onReady() { + switch (parentFragment.zoomStart) { + case PagerReader.ALIGN_LEFT: + imageView.setScaleAndCenter(imageView.getScale(), new PointF(0, 0)); + break; + case PagerReader.ALIGN_RIGHT: + imageView.setScaleAndCenter(imageView.getScale(), new PointF(99999f, 0)); + break; + case PagerReader.ALIGN_CENTER: + PointF center = imageView.getCenter(); + center.y = 0; + imageView.setScaleAndCenter(imageView.getScale(), center); + break; + } + } + @Override public void onImageLoadError(Exception e) { showImageLoadError(); @@ -93,6 +111,7 @@ public class PagerReaderFragment extends BaseFragment { public void onDestroyView() { unsubscribeProgress(); unsubscribeStatus(); + imageView.setOnImageEventListener(null); ButterKnife.unbind(this); super.onDestroyView(); } diff --git a/app/src/main/res/drawable-hdpi/ic_crop_original_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_crop_original_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..78ad3222d1ea218691c84c0c1c39b6f2a057a5f7 GIT binary patch literal 271 zcmV+q0r38bP)Fft5c{O|X__J0GBunwr25t~7b|JVN~6|6@Xg)qqPKRLh`)1X?g!~vqcb^xrt z7So^xutWpV!HcGT)Syv=hNwZB|HY|c5bysR|M&c7BF~_(|2lB?8nA3VIR@$e|N8&l ze-SXd1X^hP{qIPsLHz%3gZYR4v;DXK{|8?FJcoxAQ3f&o-vHOT^8X8zq6`*NL>W|x zw^Xbr)*!C`HF(R$TA+#{m9p!oRrr%v9r;kFf?SQQf&>}mOG1@h3v>|FEU|Xo9joD6*1iAn(r)h68IJ>u%n ze~;yo_<|&1LlXwkGpv_d9jf>Q&a*uF>0l$RWhNfWY!R`rE4@*~>1AYqVZes6huu3m k4bmM7#RGapB3CjognVO9vbprfALxDtPgg&ebxsLQ01~rSO8@`> literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_crop_original_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_crop_original_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..a3e55bdc35b9ac43ac1ec8b8da64ddc9052b648c GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+iDo+>3kcwN$Kh8Tyr7W1;cHqDM z|HsVh|NUN^bzr>=OWdL?2F4n{#?$>-3qqQ|*83)zZ1`i&dRgfI{J;A@&F|jOw(q}u zquS;__8elf-94N&W|aQ^Us5rtI$9rJ e^*nQtA_ITdY|811|cLAjqc>Vte7p(xs z1!lV=ff5T8|Gz^r>fishSlSTCF+rjQ9RJS|)l5Oe1c?^RCAuZFV6-e6Iu?APb>nvv zRV-Lf+YZRP|7!TVP#b|>BtLN0qZ&WjjUBas8V~?$S5Hm$WvF}r0000@5W=6+62n`v5k+fKTA16yLzwMskrDFAt!Nokcdv zg5d8&7RhcldSY^hQ~a}4=5R6}dx71V0t#*&1%e17h#*Hn9s-mR!A8WWA%x!#Xdbt) z9d}a25acOv+R>0oMxX#%Q8ELS)j(A}|0jqbf(RmrAc6=Yh#-R8 z1C6={I>WY0pncgDVbK-PD&nM-Frf=t&n-BOr=Ok2nxG{#ao&|3!DVXijuvPNkKbzt znfzhq%e^IV70^Yp_KD4o?1uc##(nOE9Wp3Por9GmyMWi+{>F)I&>B8c>(7{x>^N?E zwp?~?f@bm3Rqz_VJW;))g`zFc7_M?l*8gZrJz&xf=;+^_vQrzNt$~_%d&3452kbn) zVVUnk1QFyeD0XeMP*Vd{%s`+P+*eun}?*gteJ zubACgXza(QrFg`(hS^QtVezIJKZJbh&UhsxI6PwBu~S0zotl~(hYsJdg9jzpLu7t! z7gFJP`-=a_HWj`xD%FATMGDl8JIW}8bCzClm->9j0LPWFFMIqsyIM- z7yLKfryTw*?7+atB7luBs5+qcD3NW=Lupf=R#AiQ=ihvu7BC$vygOHWv64a(PvE~5 z>FfA)RN|E<0oelqWIm>JFzt3Axp>>P%62r_!?em7$&aS(4Www7a+nNWL zQzF^tzTugd<9*|{Bh#{v85`I1e!E!uask`@BS8TT9C|Ek88zQn=O`Q8=M-Xye7Nb} zE%oNj8mx>SyCW9V=A2~vBO6=iD%@?vxYvDp{KtejH!d+Oez{EhqrD--+y5Ay?*E7i z=L#t0KcUTPQO57_<5zLzjc>nqR5y6>{!qWLhaqW&#>PL|E_)g4I9nUyRqj^&3cM)w zcK>nCCjrKG$)D`!geJefb*r3Mj>Jce})f9Kl#Qx3@e0ZbhXp00i_>zopr07sGM A$N&HU literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/reader_menu.xml b/app/src/main/res/layout/reader_menu.xml index 0017425573..8d4f8a50ea 100644 --- a/app/src/main/res/layout/reader_menu.xml +++ b/app/src/main/res/layout/reader_menu.xml @@ -78,6 +78,16 @@ android:src="@drawable/ic_screen_rotation" android:layout_gravity="center_vertical" android:background="?android:selectableItemBackground" /> + + + + 6 + + @string/zoom_start_automatic + @string/zoom_start_left + @string/zoom_start_right + @string/zoom_start_center + + + + 1 + 2 + 3 + 4 + + @string/update_never @string/update_1hour diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 4eac520ce5..1967a589f7 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -17,6 +17,7 @@ pref_default_viewer_key pref_image_scale_type_key + pref_zoom_start_key pref_hide_status_bar_key pref_lock_orientation_key pref_enable_transitions_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7532f1ef0d..b3ee4d1917 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -93,7 +93,7 @@ Left to right Right to left Vertical - Webtoon (experimental) + Webtoon Image decoder Rapid Skia @@ -104,7 +104,11 @@ Fit height Original size Smart fit - + Zoom start position + Automatic + Left + Right + Center Downloads directory diff --git a/app/src/main/res/xml/pref_reader.xml b/app/src/main/res/xml/pref_reader.xml index 5587253d8c..35fe58f3b2 100644 --- a/app/src/main/res/xml/pref_reader.xml +++ b/app/src/main/res/xml/pref_reader.xml @@ -37,6 +37,14 @@ android:defaultValue="1" android:summary="%s"/> + +