Compare commits

...
106 Commits
Author SHA1 Message Date
seven332 fad9e3ccc0 1.0.8 2016-05-02 19:38:21 +08:00
seven332 5aa56e0237 Add detail size options
Large for 480dp width
Small for 320dp width
2016-05-02 19:36:41 +08:00
seven332 d4d4ba8c75 Use TuXiang library
Make GLRootView extends com.hippo.tuxiang.GLSurfaceView
2016-05-02 18:56:56 +08:00
seven332 2a324c4d89 Call GLRootView onPause and onResume 2016-05-02 13:20:35 +08:00
seven332 e6638b6f56 Remove ANRWatchDog 2016-05-01 23:20:00 +08:00
seven332 5d956b43fb 1.0.7 2016-05-01 17:11:17 +08:00
seven332 9e19b16735 Close #142, save thumb to download dir 2016-05-01 17:08:03 +08:00
seven332 af8cc34048 Bump image library version 2016-05-01 15:53:18 +08:00
seven332 430e748490 Remove TODO list 2016-05-01 15:23:46 +08:00
seven332 297c35b14d Use custom GLSurfaceView
Ensure GLRootView's mContentView.detachFromRoot() called in render thread
2016-05-01 15:21:26 +08:00
seven332 b973e0244e Add gallery image cache 2016-05-01 13:26:13 +08:00
seven332 f672fe1e96 Remove 'git submodule update --init' in build instruction 2016-04-30 19:09:22 +08:00
seven332 e3113083bc Use jitpack libraries 2016-04-30 19:03:59 +08:00
seven332 d186a6ac3b Run copyNotice task automatically 2016-04-28 02:07:17 +08:00
seven332 10693c5ffc Use jack and jill 2016-04-27 22:07:42 +08:00
seven332 9b54fd09c9 Bump gradle tool version 2016-04-27 22:06:30 +08:00
seven332 7f4dc1f131 Fix regex for jack 2016-04-27 21:58:56 +08:00
seven332 5638832c05 Use image library 2016-04-27 21:15:01 +08:00
seven332 a7e8b96b4c Change gallery_list_column_width to 480dp 2016-04-26 18:04:39 +08:00
seven332 a8df181ff8 Add TODO list 2016-04-26 18:03:45 +08:00
seven332 58acaa7287 Add html-format NOTICE 2016-04-25 17:03:35 +08:00
seven332 b00ed5a360 Bump libraries version 2016-04-25 17:02:05 +08:00
seven332 42eeb4f44c Bump libraries and gradle tool version 2016-04-25 00:10:11 +08:00
seven332 2ccb5d92c9 Bump gradle tool version 2016-04-21 16:41:38 +08:00
seven332 e12a35cb52 Remove DumpBrowsableActivity to fix default app error 2016-04-21 16:41:05 +08:00
seven332 fbeaf3d5ea Add anr watch dog 2016-04-14 19:10:38 +08:00
seven332 b4d8168457 Bump gradle tool version 2016-04-14 14:50:23 +08:00
seven332 9561fcf662 requestLayout when set different-size ImageTexture in ImageView 2016-04-14 02:40:25 +08:00
seven332 453a56aa23 Use hotspot and ripple library 2016-04-14 00:58:38 +08:00
seven332 df108f9678 Adjust build instruction for Linux 2016-04-13 14:04:26 +08:00
seven332 a835ca9547 Remove some @TargetApi 2016-04-13 01:54:45 +08:00
seven332 3f4cc46bc1 Do not show animation for image has no valid rect 2016-04-12 01:09:13 +08:00
seven332 27bc38ae8b Fix gif delay calculation 2016-04-12 00:55:36 +08:00
seven332 fd1aca48d6 Update UniFile library 2016-04-12 00:22:44 +08:00
seven332 adbb1f11a5 Use SystemClock.currentThreadTimeMillis to calculate gif delay 2016-04-12 00:21:58 +08:00
seven332 4b8e46d220 Use drawerLayout library 2016-04-11 15:36:00 +08:00
seven332 1c45c4b042 Add thumb resolution option 2016-04-11 14:28:01 +08:00
seven332 d33e3c27fc Rename image_size to image_resolution 2016-04-11 13:59:35 +08:00
seven332 189a95e49c Use RefreshLayout from jitpack 2016-04-11 00:05:17 +08:00
seven332 4e3717fa69 Avoid write null in SpiderInfo 2016-04-10 15:58:41 +08:00
seven332 97d51b1fc3 Start home page when can't recognize the intent 2016-04-10 15:41:17 +08:00
seven332 ba5a554ca8 Use unifile library for jitpack 2016-04-10 15:22:48 +08:00
seven332 b4095449c1 Fix mDownloadingDelay NullPointerException 2016-04-09 22:36:20 +08:00
seven332 05f9ce59f3 Update giflib to 5.1.4 2016-04-09 21:42:50 +08:00
seven332 793dca3674 Set APP_PLATFORM to android-15 2016-04-09 21:42:23 +08:00
seven332 e10172c09c Hide ime in go to dialog 2016-04-09 20:41:52 +08:00
seven332 2d65b71fff Rename ActivityHelper to AppHelper 2016-04-09 20:35:57 +08:00
seven332 7693275967 Use card for gallery thumb 2016-04-09 18:40:31 +08:00
seven332 9d4eadffac Add up react to SnackBar 2016-04-09 16:52:27 +08:00
seven332 1bf826a923 Clean up 2016-04-09 13:44:12 +08:00
seven332 4866e963de 1.0.6 2016-04-09 02:01:02 +08:00
seven332 2b15c8f620 Use clipRect instead of clipPath in SearchBar 2016-04-09 01:54:47 +08:00
seven332 d9265610c3 Check pages in read SpiderInfo 2016-04-08 22:44:09 +08:00
seven332 81dce7d297 Remove customtabs, set minSdkVersion to 14 2016-04-08 22:40:36 +08:00
seven332 078d086362 1.0.5 2016-04-08 22:09:15 +08:00
seven332 492d483467 Request again if image missing in cache 2016-04-08 21:19:57 +08:00
seven332 d9c1b81eb3 Add support zip file support for GalleryActivity 2016-04-08 20:46:07 +08:00
seven332 a2a9dbcb02 Add media scan config 2016-04-08 20:28:05 +08:00
seven332 97c28c04c5 Fix typo 2016-04-08 19:53:08 +08:00
seven332 f4d8cbf3a4 Add back icon callback in SetSecurityActivity 2016-04-08 19:49:58 +08:00
seven332 4291493256 Fix status bar background color above NavigationView 2016-04-08 19:33:13 +08:00
seven332 ce6cb19e73 Rename SlidingDrawerLayout to DrawerLayout 2016-04-08 18:59:36 +08:00
seven332 574d09302e Bump libraries version 2016-04-08 16:36:41 +08:00
seven332 f37b479400 Adjust table layout 2016-04-08 15:30:11 +08:00
seven332 87c27b6256 Avoid showing download path warning for the first time 2016-04-08 02:02:09 +08:00
seven332 b3881f8562 Adjust layout for table 2016-04-07 20:45:20 +08:00
seven332 3f8e872d55 Apply new MarginItemDecoration 2016-04-07 19:33:09 +08:00
seven332 7e62673e5a Improve SpiderQueen 2016-04-07 02:23:52 +08:00
seven332 69be0c48fb Put save parse error to AppConfig 2016-04-07 02:23:10 +08:00
seven332 9d783fa86d Use GetText in ExceptionUtils 2016-04-07 02:22:06 +08:00
seven332 28b81a0db0 Fix parse gallery page error in e-hentai 2016-04-07 02:16:13 +08:00
seven332 3ac1964069 Adjust download thumb guide 2016-04-07 00:53:35 +08:00
seven332 a2241e62a3 Fix SwipeProgressBar finish animation 2016-04-07 00:33:50 +08:00
seven332 100a3d872e Set minSdkVersion to 15 2016-04-06 18:24:33 +08:00
seven332 413a17acf1 Update icon 2016-04-06 18:05:49 +08:00
seven332 79bc2bcd22 Apply thumb size settings to preview size 2016-04-06 14:53:33 +08:00
seven332 c6e45cc080 Update EasyRecyclerView 2016-04-06 01:53:05 +08:00
seven332 7a215acd18 Add progress in GalleryActivity 2016-04-05 20:38:26 +08:00
seven332 3ca6b69984 Add image size option 2016-04-05 02:07:08 +08:00
seven332 084f352d71 Add favorites sort, image size, gallery title, popular for EhConfig 2016-04-05 00:47:11 +08:00
seven332 f4a16b3edd Only show error when no cookie saved 2016-04-04 22:20:58 +08:00
seven332 e8d8ee8501 1.0.4 2016-04-04 21:08:53 +08:00
seven332 9a87701ad6 Fix memory leak which due to GalleryView.onDetachFromRootInternal not called 2016-04-04 15:20:26 +08:00
seven332 cdc8a7aea6 Adjust GLView attachToRoot detachFromRoot 2016-04-04 15:12:33 +08:00
seven332 90bfd445d1 Do not show warning after get profile error 2016-04-04 13:24:20 +08:00
seven332 7493bd57f4 Fix not showing click-thumb-detail guide 2016-04-04 13:15:52 +08:00
seven332 629c2bb80d Fix add to favorites failed 2016-04-03 23:59:17 +08:00
seven332 4d45d717e2 1.0.3 2016-04-03 20:18:38 +08:00
seven332 b8e80c6c8c Make identity live long 2016-04-03 20:15:58 +08:00
seven332 efed7776d3 Remove cancel button in sign in failed dialog 2016-04-03 19:24:57 +08:00
seven332 56cfc0669b Add set read cache max size 2016-04-03 19:19:20 +08:00
seven332 6d9ed41382 Don't scroll vertically unloaded page when scaling for ScrollLayoutManager 2016-04-03 18:20:46 +08:00
seven332 505efbdef6 Avoid unnecessary invalidate in GalleryView 2016-04-03 17:18:41 +08:00
seven332 52ab8cebb0 Improve ScrollLayoutManager 2016-04-03 17:12:13 +08:00
seven332 e8251ee521 Improve PageLayoutManager scale 2016-04-03 02:37:28 +08:00
seven332 d4195c6e5b Add scale for ScrollLayoutManager 2016-04-03 02:36:51 +08:00
seven332 f50975d767 Adjust search bar size 2016-04-02 23:11:56 +08:00
seven332 4d9452c791 Add thumb size option 2016-04-02 21:12:17 +08:00
seven332 474eea094d Add remove download redundancy 2016-04-02 19:14:42 +08:00
seven332 bbb6b634ff Remove unused resources 2016-04-02 16:59:32 +08:00
seven332 d5da97141f Remove unsupported language 2016-04-02 16:59:03 +08:00
seven332 a12f9ba595 Add fullscreen option 2016-04-02 16:36:37 +08:00
seven332 75944e5a8b Improve EhGalleryProvider 2016-04-02 16:03:49 +08:00
seven332 1aa51a5934 Bump gradle version 2016-04-02 15:49:35 +08:00
seven332 092fd6779c Bump build tools version 2016-04-02 15:42:14 +08:00
seven332 618dc2b180 Adjust SlidingDrawerLayout min margin 2016-04-02 14:05:21 +08:00
458 changed files with 4762 additions and 135108 deletions

No files matched your search

-21
View File
@@ -1,21 +0,0 @@
[submodule "yorozuya"]
path = yorozuya
url = https://github.com/seven332/Yorozuya
[submodule "hotspot"]
path = hotspot
url = https://github.com/seven332/Hotspot
[submodule "easyrecyclerview"]
path = easyrecyclerview
url = https://github.com/seven332/EasyRecyclerView
[submodule "beerbelly"]
path = beerbelly
url = https://github.com/seven332/BeerBelly
[submodule "conaco"]
path = conaco
url = https://github.com/seven332/Conaco
[submodule "rippleold"]
path = rippleold
url = https://github.com/seven332/RippleOld
[submodule "unifile"]
path = unifile
url = https://github.com/seven332/UniFile
+4 -843
View File
@@ -1,846 +1,7 @@
======================================================================
EhViewer
======================================================================
Copyright 2014-2016 Hippo Seven
Copyright (C) 2014-2016 Hippo Seven
An Unofficial E-Hentai Application for Android.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
======================================================================
Library ("Advanced RecyclerView")
======================================================================
Copyright (C) 2015 Haruki Hasegawa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
======================================================================
Library ("giflib")
======================================================================
The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
======================================================================
Library ("greenDAO")
======================================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
======================================================================
Library ("jsoup")
======================================================================
The MIT License
© 2009-2015, Jonathan Hedley <jonathan@hedley.net>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
======================================================================
Library ("libjpeg-turbo")
======================================================================
libjpeg-turbo Licenses
----------------------
libjpeg-turbo is covered by three compatible BSD-style open source licenses:
-- The IJG (Independent JPEG Group) License, which is listed in README
This license applies to the libjpeg API library and associated programs
(any code inherited from libjpeg, and any modifications to that code.)
-- The Modified (3-clause) BSD License, which is listed in turbojpeg.c
This license covers the TurboJPEG API library and associated programs.
-- The zlib License, which is listed in simd/jsimdext.inc
This license is a subset of the other two, and it covers the libjpeg-turbo
SIMD extensions.
Complying with the libjpeg-turbo Licenses
-----------------------------------------
This section provides a roll-up of the libjpeg-turbo licensing terms, to the
best of our understanding.
1. If you are distributing a modified version of the libjpeg-turbo source,
then:
a. You cannot alter or remove any existing copyright or license notices
from the source.
Origin: Clause 1 of the IJG License
Clause 1 of the Modified BSD License
Clauses 1 and 3 of the zlib License
b. You must add your own copyright notice to the header of each source
file you modified, so others can tell that you modified that file (if
there is not an existing copyright header in that file, then you can
simply add a notice stating that you modified the file.)
Origin: Clause 1 of the IJG License
Clause 2 of the zlib License
c. You must include the IJG README file, and you must not alter any of the
copyright or license text in that file.
Origin: Clause 1 of the IJG License
2. If you are distributing only libjpeg-turbo binaries without the source, or
if you are distributing an application that statically links with
libjpeg-turbo, then:
a. Your product documentation must include a message stating:
This software is based in part on the work of the Independent JPEG
Group.
Origin: Clause 2 of the IJG license
b. If your binary distribution includes or uses the TurboJPEG API, then
your product documentation must include the text of the Modified BSD
License.
Origin: Clause 2 of the Modified BSD License
3. You cannot use the name of the IJG or The libjpeg-turbo Project or the
contributors thereof in advertising, publicity, etc.
Origin: IJG License
Clause 3 of the Modified BSD License
4. The IJG and The libjpeg-turbo Project do not warrant libjpeg-turbo to be
free of defects, nor do we accept any liability for undesirable
consequences resulting from your use of the software.
Origin: IJG License
Modified BSD License
zlib License
======================================================================
Library ("libpng" + "apng")
======================================================================
This copy of the libpng notices is provided for your convenience. In case of
any discrepancy between this copy and the notices in the file png.h that is
included in the libpng distribution, the latter shall prevail.
COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
If you modify libpng you may insert additional notices immediately following
this sentence.
This modified version of libpng code adds animated PNG support and is
released under the libpng license described below. The modifications are
Copyright (c) 2006-2007 Andrew Smith, Copyright (c) 2008-2015 Max Stepin,
and are delimited by "#ifdef PNG_APNG_SUPPORTED / #endif" directives
surrounding them in the modified libpng source files.
This code is released under the libpng license.
libpng versions 1.0.7, July 1, 2000, through 1.6.20, December 3, 2015, are
Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, are
derived from libpng-1.0.6, and are distributed according to the same
disclaimer and license as libpng-1.0.6 with the following individuals
added to the list of Contributing Authors:
Simon-Pierre Cadieux
Eric S. Raymond
Mans Rullgard
Cosmin Truta
Gilles Vollant
James Yu
and with the following additions to the disclaimer:
There is no warranty against interference with your enjoyment of the
library or against infringement. There is no warranty that our
efforts or the library will fulfill any of your particular purposes
or needs. This library is provided with all faults, and the entire
risk of satisfactory quality, performance, accuracy, and effort is with
the user.
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
libpng-0.96, and are distributed according to the same disclaimer and
license as libpng-0.96, with the following individuals added to the list
of Contributing Authors:
Tom Lane
Glenn Randers-Pehrson
Willem van Schaik
libpng versions 0.89, June 1996, through 0.96, May 1997, are
Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
and are distributed according to the same disclaimer and license as
libpng-0.88, with the following individuals added to the list of
Contributing Authors:
John Bowler
Kevin Bracey
Sam Bushell
Magnus Holmgren
Greg Roelofs
Tom Tanner
libpng versions 0.5, May 1995, through 0.88, January 1996, are
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:
Andreas Dilger
Dave Martindale
Guy Eric Schalnat
Paul Schmidt
Tim Wegner
The PNG Reference Library is supplied "AS IS". The Contributing Authors
and Group 42, Inc. disclaim all warranties, expressed or implied,
including, without limitation, the warranties of merchantability and of
fitness for any purpose. The Contributing Authors and Group 42, Inc.
assume no liability for direct, indirect, incidental, special, exemplary,
or consequential damages, which may result from the use of the PNG
Reference Library, even if advised of the possibility of such damage.
Permission is hereby granted to use, copy, modify, and distribute this
source code, or portions hereof, for any purpose, without fee, subject
to the following restrictions:
1. The origin of this source code must not be misrepresented.
2. Altered versions must be plainly marked as such and must not
be misrepresented as being the original source.
3. This Copyright notice may not be removed or altered from any
source or altered source distribution.
The Contributing Authors and Group 42, Inc. specifically permit, without
fee, and encourage the use of this source code as a component to
supporting the PNG file format in commercial products. If you use this
source code in a product, acknowledgment is not required but would be
appreciated.
END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
A "png_get_copyright" function is available, for convenient use in "about"
boxes and the like:
printf("%s", png_get_copyright(NULL));
Also, the PNG logo (in PNG format, of course) is supplied in the
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
a certification mark of the Open Source Initiative. OSI has not addressed
the additional disclaimers inserted at version 1.0.7.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
December 3, 2015
======================================================================
Library ("OkHttp")
======================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
======================================================================
Library ("roaster")
======================================================================
Forge Roaster
Copyright 2011-2015 Red Hat Inc. and/or its affiliates.
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
======================================================================
Library ("ShowcaseView")
======================================================================
Copyright Alex Curran (@amlcurran) © 2012-2014. All rights reserved.
This library is distributed under an Apache 2.0 License.
======================================================================
Font ("Slabo")
======================================================================
Copyright (c) 2013, Tiro Typeworks Ltd (www.tiro.com).
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
======================================================================
Library ("TagSoup")
======================================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
香风智乃是最可爱的女孩子。
chino kafuu is the cutest girl.
+1840
View File
File diff suppressed because it is too large. Load diff
+12 -14
View File
@@ -14,27 +14,24 @@ An E-Hentai Application for Android.
# Build
Windows
> git clone https://github.com/seven332/EhViewer
> cd EhViewer
> gradlew daogenerator:executeDaoGenerator
> gradlew app:assembleDebug
Linux
$ git clone https://github.com/seven332/EhViewer
$ cd EhViewer
$ git submodule update --init
$ gradlew app:copyNotice
$ gradlew daogenerator:executeDaoGenerator
$ gradlew app:assembleDebug
$ ./gradlew daogenerator:executeDaoGenerator
$ ./gradlew app:assembleDebug
生成的 apk 文件在 app\build\outputs\apk 目录下
The apk is in app\build\outputs\apk
**注意**:如果你遇到了下面这样的错误,需要添加系统变量 NDK_HOME 为 android NDK 路径
**Note**: If you get the error below, set NDK_HOME environment variable
* What went wrong:
A problem occurred evaluating project ':app'.
> assert ndkDir != null
| |
null false
# Thanks
@@ -44,6 +41,7 @@ Here is the libraries
- [AOSP](http://source.android.com/)
- [android-advancedrecyclerview](https://github.com/h6ah4i/android-advancedrecyclerview)
- [Apache Commons Lang](https://commons.apache.org/proper/commons-lang/)
- [apng](http://apng.sourceforge.net/)
- [giflib](http://giflib.sourceforge.net)
- [greenDAO](https://github.com/greenrobot/greenDAO)
+1 -1
View File
@@ -1,4 +1,4 @@
/src/main/assets/NOTICE
/src/main/assets/NOTICE.html
/build
/src/main/java-gen
manifest-merger-release-report.txt
+47 -52
View File
@@ -1,18 +1,30 @@
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "24.0.0 rc3"
defaultConfig {
applicationId "com.hippo.ehviewer"
minSdkVersion 16
minSdkVersion 14
targetSdkVersion 23
versionCode 55
versionName "1.0.2"
versionCode 61
versionName "1.0.8"
vectorDrawables.useSupportLibrary = true
resConfigs "zh", "zh-rCN", "zh-rHK", "zh-rTW"
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError true
}
buildTypes {
@@ -25,62 +37,45 @@ android {
sourceSets {
main {
java.srcDirs += 'src/main/java-gen'
// Disable default NdkCompile task
jni.srcDirs = []
// Set new jni lib dir
jniLibs.srcDir 'src/main/libs'
}
}
// noinspection GroovyAssignabilityCheck
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
if (ndkDir == null) {
ndkDir = System.getenv('NDK_HOME')
}
assert ndkDir != null
def ndkBuilder
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkBuilder = 'ndk-build.cmd'
} else {
ndkBuilder = 'ndk-build'
}
commandLine "$ndkDir\\$ndkBuilder",
'-C', file('src/main/jni').absolutePath,
'-j', Runtime.runtime.availableProcessors()
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
clean {
delete file('src/main/obj').absolutePath
delete file('src/main/libs').absolutePath
}
task copyNotice(type: Copy) {
from '../NOTICE'
from '../NOTICE.html'
into './src/main/assets'
}
tasks.withType(AbstractCompile) {
compileTask -> compileTask.dependsOn copyNotice
}
clean {
delete file('src/main/assets/NOTICE.html').absolutePath
}
dependencies {
compile project(':beerbelly')
compile project(':conaco')
compile project(':easyrecyclerview')
compile project(':hotspot')
compile project(':okhttp3')
compile project(':rippleold')
compile project(':unifile')
compile project(':yorozuya')
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:customtabs:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.github.amlcurran.showcaseview:library:5.4.1'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.github.amlcurran.showcaseview:library:5.4.3'
compile 'com.github.seven332:beerbelly:0.1.2'
compile 'com.github.seven332:conaco:0.1.3-eh'
compile 'com.github.seven332:easyrecyclerview:0.1.0'
compile 'com.github.seven332:drawerLayout:0.1.0'
compile 'com.github.seven332:image:0.1.3'
compile 'com.github.seven332:okhttp:3.2.0-eh'
compile 'com.github.seven332:refreshlayout:0.1.0'
compile 'com.github.seven332:ripple:0.1.1'
compile 'com.github.seven332:streampipe:0.1.0'
compile 'com.github.seven332:tuxiang:0.1.0'
compile 'com.github.seven332:unifile:0.1.3'
compile 'com.github.seven332:yorozuya-collect:0.1.2'
compile 'com.github.seven332:yorozuya-thread:0.1.0'
compile 'com.github.seven332:yorozuya:0.1.0'
compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.7'
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
compile 'org.jsoup:jsoup:1.8.3'
compile 'org.greenrobot:greendao:2.2.0'
compile 'org.jsoup:jsoup:1.9.1'
testCompile 'junit:junit:4.12'
}
Binary file not shown.
+19 -37
View File
@@ -67,49 +67,31 @@
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
<activity
android:name="com.hippo.ehviewer.ui.DumpBrowsableActivity"
android:configChanges="screenSize|uiMode"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter android:priority="-10">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"/>
<data android:host="exhentai.org"/>
<data android:host="g.e-hentai.org"/>
<data android:host="lofi.e-hentai.org"/>
<data android:pathPrefix="/g/"/>
</intent-filter>
</activity>
<activity-alias
android:name="com.hippo.ehviewer.ui.DumpBrowsableActivity2"
android:targetActivity="com.hippo.ehviewer.ui.DumpBrowsableActivity"
android:configChanges="screenSize|uiMode"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter android:priority="-10">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"/>
<data android:host="exhentai.org"/>
<data android:host="g.e-hentai.org"/>
<data android:host="lofi.e-hentai.org"/>
<data android:pathPrefix="/s/"/>
</intent-filter>
</activity-alias>
<activity
android:name="com.hippo.ehviewer.ui.GalleryActivity"
android:configChanges="screenSize|uiMode"
android:theme="@style/AppTheme.Gallery"
android:launchMode="singleTask"/>
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.zip"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="file"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.zip"/>
</intent-filter>
</activity>
<activity
android:name="com.hippo.ehviewer.ui.SettingsActivity"
@@ -59,6 +59,7 @@ public class BatteryDrawable extends Drawable {
}
@Override
@SuppressWarnings("SuspiciousNameCombination")
protected void onBoundsChange(Rect bounds) {
int width = bounds.width();
int height = bounds.height();
@@ -89,8 +90,9 @@ public class BatteryDrawable extends Drawable {
*/
@Override
public void draw(Canvas canvas) {
if (mElect == -1)
if (mElect == -1) {
return;
}
mElectRect.right = MathUtils.lerp(mStart, mStop, mElect / 100.0f);
@@ -152,21 +154,22 @@ public class BatteryDrawable extends Drawable {
}
private void updatePaint(boolean warn) {
if (warn)
if (warn) {
mPaint.setColor(mWarningColor);
else
} else {
mPaint.setColor(mColor);
}
invalidateSelf();
}
@Override
public void setAlpha(int alpha) {
// Empty
mPaint.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
// Empty
mPaint.setColorFilter(cf);
}
@Override
@@ -38,7 +38,7 @@ public class DrawerArrowDrawable extends Drawable {
private final Paint mPaint = new Paint();
// The angle in degress that the arrow head is inclined at.
// The angle in degrees that the arrow head is inclined at.
private static final float ARROW_HEAD_ANGLE = (float) Math.toRadians(45);
private final float mBarThickness;
// The length of top and bottom bars when they merge into an arrow
@@ -61,7 +61,7 @@ public class DrawerArrowDrawable extends Drawable {
// The interpolated version of the original progress
private float mProgress;
// the amount that overlaps w/ bar size when rotation is max
private float mMaxCutForBarSize;
private final float mMaxCutForBarSize;
/**
* @param context used to get the configuration for the drawable from
@@ -24,6 +24,9 @@ import android.support.v7.graphics.drawable.DrawableWrapper;
import com.hippo.yorozuya.MathUtils;
/**
* Show a part of the original drawable
*/
public class PreciselyClipDrawable extends DrawableWrapper {
private final boolean mClip;
@@ -16,26 +16,59 @@
package com.hippo.drawable;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.widget.TextView;
import android.util.Log;
import com.hippo.conaco.Conaco;
import com.hippo.conaco.ConacoTask;
import com.hippo.conaco.Unikery;
import com.hippo.conaco.ValueHolder;
import com.hippo.image.ImageBitmap;
import com.hippo.image.ImageDrawable;
import com.hippo.image.RecycledException;
import com.hippo.widget.ObservedTextView;
public class UnikeryDrawable extends WrapDrawable implements Unikery<Bitmap> {
public class UnikeryDrawable extends WrapDrawable implements Unikery<ImageBitmap>,
ObservedTextView.OnWindowAttachListener {
private static final String TAG = UnikeryDrawable.class.getSimpleName();
private int mTaskId = Unikery.INVALID_ID;
private final TextView mTextView;
private final ObservedTextView mTextView;
private final Conaco<ImageBitmap> mConaco;
private String mUrl;
private ValueHolder<Bitmap> mHolder;
public UnikeryDrawable(TextView textView) {
public UnikeryDrawable(ObservedTextView textView, Conaco<ImageBitmap> conaco) {
mTextView = textView;
mTextView.setOnWindowAttachListener(this);
mConaco = conaco;
}
@Override
public void onAttachedToWindow() {
load(mUrl);
}
@Override
public void onDetachedFromWindow() {
mConaco.cancel(this);
clearDrawable();
}
public void load(String url) {
if (url != null) {
mUrl = url;
mConaco.load(new ConacoTask.Builder<ImageBitmap>().setUnikery(this).setUrl(url).setKey(url));
}
}
private void clearDrawable() {
Drawable drawable = getDrawable();
if (drawable instanceof ImageDrawable) {
((ImageDrawable) drawable).recycle();
}
setDrawable(null);
}
@Override
@@ -54,9 +87,7 @@ public class UnikeryDrawable extends WrapDrawable implements Unikery<Bitmap> {
updateBounds();
if (drawable != null) {
// mTextView.requestLayout() not work!
CharSequence cs = mTextView.getText();
mTextView.setText(cs);
invalidateSelf();
}
}
@@ -71,49 +102,41 @@ public class UnikeryDrawable extends WrapDrawable implements Unikery<Bitmap> {
}
@Override
public void onMiss(Conaco.Source source) {
public void invalidateSelf() {
CharSequence cs = mTextView.getText();
mTextView.setText(cs);
}
@Override
public void onRequest() {
}
public void onMiss(int source) {}
@Override
public void onProgress(long singleReceivedSize, long receivedSize, long totalSize) {
}
public void onRequest() {}
private void removeDrawableAndHolder() {
// Remove drawable
setDrawable(null);
@Override
public void onProgress(long singleReceivedSize, long receivedSize, long totalSize) {}
// Remove holder
if (mHolder != null) {
mHolder.release(this);
mHolder = null;
@Override
public void onWait() {}
@Override
public boolean onGetValue(@NonNull ImageBitmap value, int source) {
ImageDrawable drawable;
try {
drawable = new ImageDrawable(value);
} catch (RecycledException e) {
Log.d(TAG, "The ImageBitmap is recycled", e);
return false;
}
}
@Override
public boolean onGetObject(@NonNull ValueHolder<Bitmap> holder, Conaco.Source source) {
holder.obtain(this);
removeDrawableAndHolder();
mHolder = holder;
Drawable drawable = new BitmapDrawable(mTextView.getResources(), holder.getValue());
clearDrawable();
setDrawable(drawable);
drawable.start();
return true;
}
@Override
public void onSetDrawable(Drawable drawable) {
removeDrawableAndHolder();
setDrawable(drawable);
}
@Override
public void onFailure() {
// Empty
@@ -20,9 +20,15 @@ import android.content.Context;
import android.os.Environment;
import android.support.annotation.Nullable;
import com.hippo.ehviewer.client.exception.ParseException;
import com.hippo.util.ReadableTime;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class AppConfig {
@@ -129,4 +135,31 @@ public class AppConfig {
public static File createTempFile() {
return FileUtils.createTempFile(getTempDir(), null);
}
public static void saveParseErrorBody(ParseException e) {
File dir = getExternalParseErrorDir();
if (null == dir) {
return;
}
File file = new File(dir, ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt");
OutputStream os = null;
try {
os = new FileOutputStream(file);
String message = e.getMessage();
String body = e.getBody();
if (null != message) {
os.write(message.getBytes("utf-8"));
os.write('\n');
}
if (null != body) {
os.write(body.getBytes("utf-8"));
}
os.flush();
} catch (IOException e1) {
// Ignore
} finally {
IOUtils.closeQuietly(os);
}
}
}
@@ -22,7 +22,6 @@ import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Debug;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -34,14 +33,17 @@ import com.hippo.conaco.Conaco;
import com.hippo.ehviewer.client.EhClient;
import com.hippo.ehviewer.client.EhCookieStore;
import com.hippo.ehviewer.client.EhEngine;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.data.GalleryDetail;
import com.hippo.ehviewer.download.DownloadManager;
import com.hippo.ehviewer.spider.SpiderDen;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.image.ImageBitmap;
import com.hippo.network.StatusCodeException;
import com.hippo.okhttp.CookieDB;
import com.hippo.scene.SceneApplication;
import com.hippo.text.Html;
import com.hippo.unifile.UniFile;
import com.hippo.util.BitmapUtils;
import com.hippo.util.ReadableTime;
import com.hippo.yorozuya.FileUtils;
@@ -55,6 +57,8 @@ import java.util.List;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import okhttp3.Cookie;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
public class EhApplication extends SceneApplication implements Thread.UncaughtExceptionHandler {
@@ -73,8 +77,8 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
private EhCookieStore mEhCookieStore;
private EhClient mEhClient;
private OkHttpClient mOkHttpClient;
private BitmapHelper mBitmapHelper;
private Conaco<Bitmap> mConaco;
private ImageBitmapHelper mImageBitmapHelper;
private Conaco<ImageBitmap> mConaco;
private LruCache<Long, GalleryDetail> mGalleryDetailCache;
private SimpleDiskCache mSpiderInfoCache;
private DownloadManager mDownloadManager;
@@ -109,8 +113,18 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
Analytics.start(this);
}
CommonOperations.ensureNoMediaFile(Settings.getDownloadLocation());
// Check no media file
UniFile downloadLocation = Settings.getDownloadLocation();
if (Settings.getMediaScan()) {
CommonOperations.removeNoMediaFile(downloadLocation);
} else {
CommonOperations.ensureNoMediaFile(downloadLocation);
}
// Clear temp dir
clearTempDir();
// Check app update
update();
// Update version code
@@ -142,11 +156,34 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
if (version < 52) {
Settings.putGuideGallery(true);
}
if (version < 56) { // Make cookie long live
HttpUrl eUrl = HttpUrl.parse(EhUrl.HOST_E);
HttpUrl exUrl = HttpUrl.parse(EhUrl.HOST_EX);
EhCookieStore cookieStore = getEhCookieStore(this);
Cookie c;
c = cookieStore.get(eUrl, EhCookieStore.KEY_IPD_MEMBER_ID);
if (null != c) {
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
}
c = cookieStore.get(eUrl, EhCookieStore.KEY_IPD_PASS_HASH);
if (null != c) {
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
}
c = cookieStore.get(exUrl, EhCookieStore.KEY_IPD_MEMBER_ID);
if (null != c) {
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
}
c = cookieStore.get(exUrl, EhCookieStore.KEY_IPD_PASS_HASH);
if (null != c) {
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
}
}
}
public void clearMemoryCache() {
if (null != mConaco) {
mConaco.clearMemoryCache();
mConaco.getBeerBelly().clearMemory();
}
if (null != mGalleryDetailCache) {
mGalleryDetailCache.evictAll();
@@ -217,9 +254,9 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mOkHttpClient == null) {
application.mOkHttpClient = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.cookieJar(getEhCookieStore(application))
.build();
}
@@ -227,12 +264,12 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
}
@NonNull
public static BitmapHelper getBitmapHelper(@NonNull Context context) {
public static ImageBitmapHelper getImageBitmapHelper(@NonNull Context context) {
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mBitmapHelper == null) {
application.mBitmapHelper = new BitmapHelper();
if (application.mImageBitmapHelper == null) {
application.mImageBitmapHelper = new ImageBitmapHelper();
}
return application.mBitmapHelper;
return application.mImageBitmapHelper;
}
private static int getMemoryCacheMaxSize(Context context) {
@@ -243,17 +280,17 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
}
@NonNull
public static Conaco<Bitmap> getConaco(@NonNull Context context) {
public static Conaco<ImageBitmap> getConaco(@NonNull Context context) {
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mConaco == null) {
Conaco.Builder<Bitmap> builder = new Conaco.Builder<>();
Conaco.Builder<ImageBitmap> builder = new Conaco.Builder<>();
builder.hasMemoryCache = true;
builder.memoryCacheMaxSize = getMemoryCacheMaxSize(context);
builder.hasDiskCache = true;
builder.diskCacheDir = new File(context.getCacheDir(), "thumb");
builder.diskCacheMaxSize = 80 * 1024 * 1024; // 80MB
builder.okHttpClient = getOkHttpClient(context);
builder.objectHelper = getBitmapHelper(context);
builder.objectHelper = getImageBitmapHelper(context);
builder.debug = DEBUG_CONACO;
application.mConaco = builder.build();
}
@@ -307,6 +344,12 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
if (!handleException(ex) && mDefaultHandler != null) {
mDefaultHandler.uncaughtException(thread, ex);
}
Activity activity = getTopActivity();
if (activity != null) {
activity.finish();
}
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
@@ -47,7 +47,7 @@ import com.hippo.util.SqlUtils;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import java.io.File;
import java.io.FileInputStream;
@@ -16,25 +16,31 @@
package com.hippo.ehviewer;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.hippo.conaco.ValueHelper;
import com.hippo.conaco.ValueHolder;
import com.hippo.yorozuya.io.InputStreamPipe;
import com.hippo.image.Image;
import com.hippo.image.ImageBitmap;
import com.hippo.streampipe.InputStreamPipe;
import java.io.IOException;
public class BitmapHelper implements ValueHelper<Bitmap> {
public class ImageBitmapHelper implements ValueHelper<ImageBitmap> {
private static final int MAX_CACHE_SIZE = 512 * 512;
@Nullable
@Override
public Bitmap decode(@NonNull InputStreamPipe isPipe) {
public ImageBitmap decode(@NonNull InputStreamPipe isPipe) {
try {
isPipe.obtain();
return BitmapFactory.decodeStream(isPipe.open());
Image image = Image.decode(isPipe.open(), false);
if (image != null) {
return new ImageBitmap(image);
} else {
return null;
}
} catch (OutOfMemoryError e) {
return null;
} catch (IOException e) {
@@ -46,15 +52,26 @@ public class BitmapHelper implements ValueHelper<Bitmap> {
}
@Override
public int sizeOf(@NonNull String key, @NonNull Bitmap value) {
return value.getByteCount();
public int sizeOf(@NonNull String key, @NonNull ImageBitmap value) {
return value.getWidth() * value.getHeight() * 4;
}
@Override
public void onRemove(@NonNull String key, @NonNull ValueHolder<Bitmap> oldValue) {}
public void onAddToMemoryCache(@NonNull ImageBitmap oldValue) {
oldValue.obtain();
}
@Override
public boolean useMemoryCache(@NonNull String key, ValueHolder<Bitmap> holder) {
return true;
public void onRemoveFromMemoryCache(@NonNull String key, @NonNull ImageBitmap oldValue) {
oldValue.release();
}
@Override
public boolean useMemoryCache(@NonNull String key, ImageBitmap value) {
if (value != null) {
return value.getWidth() * value.getHeight() <= MAX_CACHE_SIZE;
} else {
return true;
}
}
}
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.annotation.DimenRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
@@ -55,6 +56,7 @@ public class Settings {
private static EhConfig loadEhConfig() {
EhConfig ehConfig= new EhConfig();
ehConfig.imageSize = getImageResolution();
ehConfig.excludedLanguages = getExcludedLanguages();
ehConfig.defaultCategories = getDefaultCategories();
ehConfig.excludedNamespaces = getExcludedTagNamespaces();
@@ -253,6 +255,51 @@ public class Settings {
return getIntFromStr(KEY_LIST_MODE, DEFAULT_LIST_MODE);
}
public static final String KEY_DETAIL_SIZE = "detail_size";
private static final int DEFAULT_DETAIL_SIZE = 0;
public static int getDetailSize() {
return getIntFromStr(KEY_DETAIL_SIZE, DEFAULT_DETAIL_SIZE);
}
@DimenRes
public static int getDetailSizeResId() {
switch (getDetailSize()) {
default:
case 0:
return R.dimen.gallery_list_column_width_long;
case 1:
return R.dimen.gallery_list_column_width_short;
}
}
public static final String KEY_THUMB_SIZE = "thumb_size";
private static final int DEFAULT_THUMB_SIZE = 1;
public static int getThumbSize() {
return getIntFromStr(KEY_THUMB_SIZE, DEFAULT_THUMB_SIZE);
}
@DimenRes
public static int getThumbSizeResId() {
switch (getThumbSize()) {
case 0:
return R.dimen.gallery_grid_column_width_large;
default:
case 1:
return R.dimen.gallery_grid_column_width_middle;
case 2:
return R.dimen.gallery_grid_column_width_small;
}
}
public static final String KEY_THUMB_RESOLUTION = "thumb_resolution";
private static final int DEFAULT_THUMB_RESOLUTION = 0;
public static int getThumbResolution() {
return getIntFromStr(KEY_THUMB_RESOLUTION, DEFAULT_THUMB_RESOLUTION);
}
private static final String KEY_SHOW_JPN_TITLE = "show_jpn_title";
private static final boolean DEFAULT_SHOW_JPN_TITLE = false;
@@ -437,6 +484,17 @@ public class Settings {
putBoolean(KEY_SHOW_CLOCK, value);
}
private static final String KEY_SHOW_PROGRESS = "gallery_show_progress";
private static final boolean DEFAULT_SHOW_PROGRESS = true;
public static boolean getShowProgress() {
return getBoolean(KEY_SHOW_PROGRESS, DEFAULT_SHOW_PROGRESS);
}
public static void putShowProgress(boolean value) {
putBoolean(KEY_SHOW_PROGRESS, value);
}
private static final String KEY_SHOW_BATTERY = "gallery_show_battery";
private static final boolean DEFAULT_SHOW_BATTERY = true;
@@ -459,6 +517,17 @@ public class Settings {
putBoolean(KEY_VOLUME_PAGE, value);
}
private static final String KEY_READING_FULLSCREEN = "reading_fullscreen";
private static final boolean VALUE_READING_FULLSCREEN = true;
public static boolean getReadingFullscreen() {
return getBoolean(KEY_READING_FULLSCREEN, VALUE_READING_FULLSCREEN);
}
public static void putReadingFullscreen(boolean value) {
putBoolean(KEY_READING_FULLSCREEN, value);
}
private static final String KEY_CUSTOM_SCREEN_LIGHTNESS = "custom_screen_lightness";
private static final boolean DEFAULT_CUSTOM_SCREEN_LIGHTNESS = false;
@@ -515,7 +584,18 @@ public class Settings {
putString(KEY_DOWNLOAD_SAVE_QUERY, uri.getEncodedQuery());
putString(KEY_DOWNLOAD_SAVE_FRAGMENT, uri.getEncodedFragment());
CommonOperations.ensureNoMediaFile(location);
if (getMediaScan()) {
CommonOperations.removeNoMediaFile(location);
} else {
CommonOperations.ensureNoMediaFile(location);
}
}
public static final String KEY_MEDIA_SCAN = "media_scan";
private static final boolean DEFAULT_MEDIA_SCAN = false;
public static boolean getMediaScan() {
return getBoolean(KEY_MEDIA_SCAN, DEFAULT_MEDIA_SCAN);
}
private static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label";
@@ -573,6 +653,19 @@ public class Settings {
putIntToStr(KEY_PRELOAD_IMAGE, value);
}
public static final String KEY_IMAGE_RESOLUTION = "image_size";
public static final String DEFAULT_IMAGE_RESOLUTION = EhConfig.IMAGE_SIZE_AUTO;
public static String getImageResolution() {
return getString(KEY_IMAGE_RESOLUTION, DEFAULT_IMAGE_RESOLUTION);
}
public static void putImageResolution(String value) {
sEhConfig.imageSize = value;
sEhConfig.setDirty();
putString(KEY_IMAGE_RESOLUTION, value);
}
private static final String KEY_DOWNLOAD_ORIGIN_IMAGE = "download_origin_image";
private static final boolean DEFAULT_DOWNLOAD_ORIGIN_IMAGE = false;
@@ -804,6 +897,13 @@ public class Settings {
putString(KEY_SECURITY, value);
}
public static final String KEY_READ_CACHE_SIZE = "read_cache_size";
public static final int DEFAULT_READ_CACHE_SIZE = 160;
public static int getReadCacheSize() {
return getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE);
}
/********************
****** Guide
********************/
@@ -16,14 +16,12 @@
package com.hippo.ehviewer;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Browser;
import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent;
import android.text.TextUtils;
import android.widget.Toast;
@@ -31,14 +29,13 @@ import com.hippo.ehviewer.client.EhUrlOpener;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.scene.Announcer;
import com.hippo.scene.StageActivity;
import com.hippo.util.CustomTabsHelper;
public final class UrlOpener {
private UrlOpener() {
}
public static void openUrl(@NonNull Context context, String url, boolean ehUrl, boolean customTabs) {
public static void openUrl(@NonNull Context context, String url, boolean ehUrl) {
if (TextUtils.isEmpty(url)) {
return;
}
@@ -59,20 +56,6 @@ public final class UrlOpener {
}
}
// CustomTabs
if (customTabs && context instanceof Activity) {
Activity activity = (Activity) context;
String packageName = CustomTabsHelper.getPackageNameToUseFixed(activity);
if (packageName != null) {
new CustomTabsIntent.Builder()
.setToolbarColor(activity.getResources().getColor(R.color.colorPrimary))
.setShowTitle(true)
.build()
.launchUrl(activity, uri);
return;
}
}
// Intent.ACTION_VIEW
intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
@@ -22,8 +22,8 @@ import android.os.AsyncTask;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.client.exception.CancelledException;
import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.thread.PriorityThreadFactory;
import java.io.File;
import java.util.List;
@@ -30,8 +30,20 @@ public class EhConfig implements Cloneable {
/**
* The key of load images through the Hentai@Home Network
* @see #LOAD_FROM_HAH_YES
* @see #LOAD_FROM_HAH_NO
*/
private static final String KEY_LOAD_FROM_HAH = "uh";
/**
* The key of Image Size Settings
* @see #IMAGE_SIZE_AUTO
* @see #IMAGE_SIZE_780X
* @see #IMAGE_SIZE_980X
* @see #IMAGE_SIZE_1280X
* @see #IMAGE_SIZE_1600X
* @see #IMAGE_SIZE_2400X
*/
private static final String KEY_IMAGE_SIZE = "xr";
/**
* The key of scale images width
*/
@@ -40,18 +52,42 @@ public class EhConfig implements Cloneable {
* The key of scale images height
*/
private static final String KEY_SCALE_HEIGHT = "ry";
/**
* The key of Gallery Name Display
* @see #GALLERY_TITLE_DEFAULT
* @see #GALLERY_TITLE_JAPANESE
*/
private static final String KEY_GALLERY_TITLE = "tl";
/**
* The key of the behavior for downloading archiver
* @see #ARCHIVER_DOWNLOAD_MAMS
* @see #ARCHIVER_DOWNLOAD_MAAS
* @see #ARCHIVER_DOWNLOAD_AAMS
* @see #ARCHIVER_DOWNLOAD_AAAS
*/
private static final String KEY_ARCHIVER_DOWNLOAD = "ar";
/**
* The key of display mode would you like to use on the front and search pages
* @see #LAYOUT_MODE_LIST
* @see #LAYOUT_MODE_THUMB
*/
private static final String KEY_LAYOUT_MODE = "dm";
/**
* The key for show popular
* @see #POPULAR_YES
* @see #POPULAR_NO
*/
private static final String KEY_POPULAR = "prn";
/**
* The key of categories would you like to view as default on the front page
*/
private static final String KEY_DEFAULT_CATEGORIES = "cats";
/**
* The key for favorites sort
* @see #FAVORITES_SORT_GALLERY_UPDATE_TIME
* @see #FAVORITES_SORT_FAVORITED_TIME
*/
private static final String KEY_FAVORITES_SORT = "fs";
/**
* The key of exclude certain namespaces from a default tag search
*/
@@ -62,34 +98,55 @@ public class EhConfig implements Cloneable {
private static final String KEY_EXCLUDED_LANGUAGES = "xl";
/**
* The key of how many results would you like per page for the index/search page and torrent search pages
* @see #RESULT_COUNT_25
* @see #RESULT_COUNT_50
* @see #RESULT_COUNT_100
* @see #RESULT_COUNT_200
*/
private static final String KEY_RESULT_COUNT = "rc";
/**
* The key of mouse-over thumb
* @see #MOUSE_OVER_YES
* @see #MOUSE_OVER_NO
*/
private static final String KEY_MOUSE_OVER = "tl";
private static final String KEY_MOUSE_OVER = "lt";
/**
* The key of preview size
* @see #PREVIEW_SIZE_NORMAL
* @see #PREVIEW_SIZE_LARGE
*/
private static final String KEY_PREVIEW_SIZE = "ts";
/**
* The key of preview row per page
* @see #PREVIEW_ROW_4
* @see #PREVIEW_ROW_10
* @see #PREVIEW_ROW_20
* @see #PREVIEW_ROW_40
*/
private static final String KEY_PREVIEW_ROW = "tr";
/**
* The key of sort order for gallery comments
* @see #COMMENTS_SORT_OLDEST_FIRST
* @see #COMMENTS_SORT_RECENT_FIRST
* @see #COMMENTS_SORT_HIGHEST_SCORE_FIRST
*/
private static final String KEY_COMMENTS_SORT = "cs";
/**
* The key of show gallery comment votes
* @see #COMMENTS_VOTES_POP
* @see #COMMENTS_VOTES_ALWAYS
*/
private static final String KEY_COMMENTS_VOTES = "sc";
/**
* The key of sort order for gallery tags
* @see #TAGS_SORT_ALPHABETICAL
* @see #TAGS_SORT_POWER
*/
private static final String KEY_TAGS_SORT = "to";
/**
* The key of show gallery page numbers
* @see #SHOW_GALLERY_INDEX_NO
* @see #SHOW_GALLERY_INDEX_YES
*/
private static final String KEY_SHOW_GALLERY_INDEX = "pn";
/**
@@ -104,22 +161,33 @@ public class EhConfig implements Cloneable {
private static final String KEY_HAH_CLIENT_PASSKEY = "hk";
/**
* The key of enable Tag Flagging
* @see #ENABLE_TAG_FLAGGING_NO
* @see #ENABLE_TAG_FLAGGING_YES
*/
private static final String KEY_ENABLE_TAG_FLAGGING = "tf";
/**
* The key of always display the original images instead of the resampled versions
* @see #ALWAYS_ORIGINAL_NO
* @see #ALWAYS_ORIGINAL_YES
*/
private static final String KEY_ALWAYS_ORIGINAL = "oi";
/**
* The key of enable the multi-Page Viewer
* @see #MULTI_PAGE_NO
* @see #MULTI_PAGE_YES
*/
private static final String KEY_MULTI_PAGE = "qb";
/**
* The key of multi-Page Viewer Display Style
* @see #MULTI_PAGE_STYLE_C
* @see #MULTI_PAGE_STYLE_N
* @see #MULTI_PAGE_STYLE_Y
*/
private static final String KEY_MULTI_PAGE_STYLE = "ms";
/**
* The key of multi-Page Viewer Thumbnail Pane
* @see #MULTI_PAGE_THUMB_HIDE
* @see #MULTI_PAGE_THUMB_SHOW
*/
private static final String KEY_MULTI_PAGE_THUMB = "mt";
@@ -142,6 +210,40 @@ public class EhConfig implements Cloneable {
*/
public static final String LOAD_FROM_HAH_NO = "n";
/**
* Image Size Auto
*/
public static final String IMAGE_SIZE_AUTO = "a";
/**
* Image Size 780x
*/
public static final String IMAGE_SIZE_780X = "780";
/**
* Image Size 980x
*/
public static final String IMAGE_SIZE_980X = "980";
/**
* Image Size 1280x
*/
public static final String IMAGE_SIZE_1280X = "1280";
/**
* Image Size 1600x
*/
public static final String IMAGE_SIZE_1600X = "1600";
/**
* Image Size 2400x
*/
public static final String IMAGE_SIZE_2400X = "2400";
/**
* Default gallery title
*/
private static final String GALLERY_TITLE_DEFAULT = "r";
/**
* Japanese gallery title
*/
private static final String GALLERY_TITLE_JAPANESE = "j";
/**
* Manual Accept, Manual Start
*/
@@ -168,6 +270,15 @@ public class EhConfig implements Cloneable {
*/
public static final String LAYOUT_MODE_THUMB = "t";
/**
* Show popular
*/
private static final String POPULAR_YES = "y";
/**
* Don't show popular
*/
private static final String POPULAR_NO = "n";
public static final int MISC = 0x1;
public static final int DOUJINSHI = 0x2;
public static final int MANGA = 0x4;
@@ -239,6 +350,15 @@ public class EhConfig implements Cloneable {
public static final String OTHER_TRANSLATED = "1279";
public static final String OTHER_REWRITE = "2303";
/**
* Sort favorites by last gallery update time
*/
private static final String FAVORITES_SORT_GALLERY_UPDATE_TIME = "p";
/**
* Sort favorites by favorited time
*/
private static final String FAVORITES_SORT_FAVORITED_TIME = "f";
/**
* 25 results per page for the index/search page and torrent search pages
*/
@@ -412,6 +532,14 @@ public class EhConfig implements Cloneable {
*/
public String loadFromHAH = LOAD_FROM_HAH_YES;
/**
* Image Size<br/>
* key: {@link #KEY_IMAGE_SIZE}<br/>
* value: {@link #IMAGE_SIZE_AUTO}, {@link #IMAGE_SIZE_780X}, {@link #IMAGE_SIZE_980X},
* {@link #IMAGE_SIZE_1280X}, {@link #IMAGE_SIZE_1600X}, {@link #IMAGE_SIZE_2400X}
*/
public String imageSize = IMAGE_SIZE_AUTO;
/**
* Scale width<br/>
* key: {@link #KEY_SCALE_WIDTH}<br/>
@@ -426,6 +554,13 @@ public class EhConfig implements Cloneable {
*/
public int scaleHeight = 0;
/**
* Gallery title<br/>
* key: {@link #KEY_GALLERY_TITLE}<br/>
* value: {@link #GALLERY_TITLE_DEFAULT}, {@link #GALLERY_TITLE_JAPANESE}
*/
public String galleryTitle = GALLERY_TITLE_DEFAULT;
/**
* The default behavior for downloading an archiver<br/>
* key: {@link #KEY_ARCHIVER_DOWNLOAD}<br/>
@@ -442,6 +577,13 @@ public class EhConfig implements Cloneable {
*/
public String layoutMode = LAYOUT_MODE_LIST;
/**
* Show popular or not<br/>
* key: {@link #KEY_POPULAR}<br/>
* value: {@link #POPULAR_YES}, {@link #POPULAR_NO}
*/
public String popular = POPULAR_YES;
/**
* Default categories on the front page<br/>
* key: {@link #KEY_DEFAULT_CATEGORIES}<br/>
@@ -450,6 +592,13 @@ public class EhConfig implements Cloneable {
*/
public int defaultCategories = 0;
/**
* <br/>
* key: {@link #KEY_FAVORITES_SORT}<br/>
* value: {@link #FAVORITES_SORT_GALLERY_UPDATE_TIME}, {@link #FAVORITES_SORT_FAVORITED_TIME}
*/
public String favoritesSort = FAVORITES_SORT_FAVORITED_TIME;
/**
* Certain namespaces excluded from a default tag search<br/>
* key: {@link #KEY_EXCLUDED_NAMESPACES}<br/>
@@ -628,11 +777,15 @@ public class EhConfig implements Cloneable {
hahClientIp + "%3A" + hahClientPort : "";
String hahClientPasskey = null == this.hahClientPasskey ? "" : this.hahClientPasskey;
mUconfig = KEY_LOAD_FROM_HAH + "_" + loadFromHAH + "-" +
KEY_IMAGE_SIZE + "_" + imageSize + "-" +
KEY_SCALE_WIDTH + "_" + scaleWidth + "-" +
KEY_SCALE_HEIGHT + "_" + scaleHeight + "-" +
KEY_GALLERY_TITLE + "_" + galleryTitle + "-" +
KEY_ARCHIVER_DOWNLOAD + "_" + archiverDownload + "-" +
KEY_LAYOUT_MODE + "_" + layoutMode + "-" +
KEY_POPULAR + "_" + popular + "-" +
KEY_DEFAULT_CATEGORIES + "_" + defaultCategories + "-" +
KEY_FAVORITES_SORT + "_" + favoritesSort + "-" +
KEY_EXCLUDED_NAMESPACES + "_" + excludedNamespaces + "-" +
KEY_EXCLUDED_LANGUAGES + "_" + excludedLanguages + "-" +
KEY_RESULT_COUNT + "_" + resultCount + "-" +
@@ -49,11 +49,15 @@ public class EhCookieStore extends CookieDBStore {
contain(EhUrl.DOMAIN_EX, KEY_IPD_PASS_HASH);
}
public static Cookie newCookie(Cookie cookie, String newDomain, boolean forcePersistent, boolean forceNotHostOnly) {
public static Cookie newCookie(Cookie cookie, String newDomain, boolean forcePersistent,
boolean forceLongLive, boolean forceNotHostOnly) {
Cookie.Builder builder = new Cookie.Builder();
builder.name(cookie.name());
builder.value(cookie.value());
if (cookie.persistent()) {
if (forceLongLive) {
builder.expiresAt(Long.MAX_VALUE);
} else if (cookie.persistent()) {
builder.expiresAt(cookie.expiresAt());
} else if (forcePersistent) {
builder.expiresAt(Long.MAX_VALUE);
@@ -125,7 +129,9 @@ public class EhCookieStore extends CookieDBStore {
// Save id and hash for exhentai
if (KEY_IPD_MEMBER_ID.equals(cookie.name()) ||
KEY_IPD_PASS_HASH.equals(cookie.name())) {
result.add(newCookie(cookie, EhUrl.DOMAIN_EX, false, false));
result.add(newCookie(cookie, EhUrl.DOMAIN_E, true, true, true));
result.add(newCookie(cookie, EhUrl.DOMAIN_EX, true, true, true));
continue;
}
}
@@ -36,6 +36,7 @@ import com.hippo.ehviewer.client.parser.ForumsParser;
import com.hippo.ehviewer.client.parser.GalleryApiParser;
import com.hippo.ehviewer.client.parser.GalleryDetailParser;
import com.hippo.ehviewer.client.parser.GalleryListParser;
import com.hippo.ehviewer.client.parser.GalleryPageParser;
import com.hippo.ehviewer.client.parser.GalleryTokenApiParser;
import com.hippo.ehviewer.client.parser.ProfileParser;
import com.hippo.ehviewer.client.parser.RateGalleryParser;
@@ -44,9 +45,7 @@ import com.hippo.ehviewer.client.parser.TorrentParser;
import com.hippo.ehviewer.client.parser.VoteCommentParser;
import com.hippo.ehviewer.client.parser.WhatsHotParser;
import com.hippo.network.StatusCodeException;
import com.hippo.util.ReadableTime;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.IOUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -54,9 +53,6 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -87,33 +83,6 @@ public class EhEngine {
sEhFilter = EhFilter.getInstance();
}
private static void saveParseErrorBody(ParseException e) {
File dir = AppConfig.getExternalParseErrorDir();
if (null == dir) {
return;
}
File file = new File(dir, ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt");
OutputStream os = null;
try {
os = new FileOutputStream(file);
String message = e.getMessage();
String body = e.getBody();
if (null != message) {
os.write(message.getBytes("utf-8"));
os.write('\n');
}
if (null != body) {
os.write(body.getBytes("utf-8"));
}
os.flush();
} catch (IOException e1) {
// Ignore
} finally {
IOUtils.closeQuietly(os);
}
}
private static void throwException(Call call, int code, @Nullable Headers headers,
@Nullable String body, Exception e) throws Exception {
if (call.isCanceled()) {
@@ -132,7 +101,7 @@ public class EhEngine {
throw new EhException(body);
} else {
if (Settings.getSaveParseErrorBody()) {
saveParseErrorBody((ParseException) e);
AppConfig.saveParseErrorBody((ParseException) e);
}
throw new EhException(GetText.getString(R.string.error_parse_error));
}
@@ -500,6 +469,7 @@ public class EhEngine {
builder.add("favnote", note != null ? note : "");
// submit=Add+to+Favorites is not necessary, just use submit=Apply+Changes all the time
builder.add("submit", "Apply Changes");
builder.add("update", "1");
String url = EhUrl.getAddFavorites(gid, token);
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
@@ -833,4 +803,30 @@ public class EhEngine {
return result;
}
public static GalleryPageParser.Result getGalleryPage(@Nullable EhClient.Task task,
OkHttpClient okHttpClient, String url) throws Exception {
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
Call call = okHttpClient.newCall(request);
// Put call
if (null != task) {
task.setCall(call);
}
String body = null;
Headers headers = null;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
return GalleryPageParser.parse(body);
} catch (Exception e) {
throwException(call, code, headers, body, e);
throw e;
}
}
}
@@ -31,6 +31,7 @@ public class EhUrl {
public static final String DOMAIN_G = "g.e-hentai.org";
public static final String DOMAIN_LOFI = "lofi.e-hentai.org";
public static final String HOST_E = "http://" + DOMAIN_E + "/";
public static final String HOST_EX = "http://" + DOMAIN_EX + "/";
public static final String HOST_G = "http://" + DOMAIN_G + "/";
@@ -168,4 +168,31 @@ public class EhUtils {
return title;
}
}
public static String handleThumbUrlResolution(String url) {
if (null == url) {
return null;
}
String resolution;
switch (Settings.getThumbResolution()) {
default:
case 0: // Auto
return url;
case 1: // 250
resolution = "250";
break;
case 2: // 300
resolution = "300";
break;
}
int index1 = url.lastIndexOf('_');
int index2 = url.lastIndexOf('.');
if (index1 >= 0 && index2 >= 0 && index1 < index2) {
return url.substring(0, index1 + 1) + resolution + url.substring(index2);
} else {
return url;
}
}
}
@@ -63,7 +63,8 @@ public class GalleryInfo implements Parcelable {
public static final Pattern[] S_LANG_PATTERNS = {
Pattern.compile("[(\\[]eng(?:lish)?[)\\]]", Pattern.CASE_INSENSITIVE),
Pattern.compile("[((\\[]ch(?:inese)?[))\\]]|[汉漢]化|中[国國][语語]|中文", Pattern.CASE_INSENSITIVE),
// [((\[]ch(?:inese)?[))\]]|[汉漢]化|中[国國][语語]|中文
Pattern.compile("[(\uFF08\\[]ch(?:inese)?[)\uFF09\\]]|[汉漢]化|中[国國][语語]|中文", Pattern.CASE_INSENSITIVE),
Pattern.compile("[(\\[]spanish[)\\]]|[(\\[]Español[)\\]]", Pattern.CASE_INSENSITIVE),
Pattern.compile("[(\\[]korean?[)\\]]", Pattern.CASE_INSENSITIVE),
Pattern.compile("[(\\[]rus(?:sian)?[)\\]]", Pattern.CASE_INSENSITIVE),
@@ -21,7 +21,7 @@ import android.os.Parcelable;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.widget.LoadImageView;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.collect.IntList;
import java.util.ArrayList;
@@ -19,7 +19,7 @@ package com.hippo.ehviewer.client.data;
import android.os.Parcel;
import com.hippo.widget.LoadImageView;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.collect.IntList;
import java.util.ArrayList;
@@ -41,7 +41,7 @@ public class GalleryApiParser {
gi.title = ParserUtils.trim(g.getString("title"));
gi.titleJpn = ParserUtils.trim(g.getString("title_jpn"));
gi.category = EhUtils.getCategory(g.getString("category"));
gi.thumb = g.getString("thumb");
gi.thumb = EhUtils.handleThumbUrlResolution(g.getString("thumb"));
gi.uploader = g.getString("uploader");
gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted")) * 1000);
gi.rating = Float.parseFloat(g.getString("rating"));
@@ -130,7 +130,7 @@ public class GalleryDetailParser {
// Thumb url
Element gd1 = gm.getElementById("gd1");
try {
gd.thumb = StringUtils.trim(gd1.child(0).attr("src"));
gd.thumb = EhUtils.handleThumbUrlResolution(StringUtils.trim(gd1.child(0).attr("src")));
} catch (Exception e) {
gd.thumb = "";
}
@@ -121,13 +121,14 @@ public class GalleryListParser {
// Thumb url
Elements es = it2.children();
if (null != es && es.size() >= 1) {
gi.thumb = es.get(0).attr("src");
gi.thumb = EhUtils.handleThumbUrlResolution(es.get(0).attr("src"));
} else {
String html = it2.html();
int index1 = html.indexOf('~');
int index2 = StringUtils.ordinalIndexOf(html, '~', 2);
if (index1 < index2) {
gi.thumb = "http://" +StringUtils.replace(html.substring(index1 + 1, index2), "~", "/");
gi.thumb = EhUtils.handleThumbUrlResolution(
"http://" +StringUtils.replace(html.substring(index1 + 1, index2), "~", "/"));
} else {
Log.w(TAG, "Can't parse gallery info thumb url");
gi.thumb = "";
@@ -26,9 +26,9 @@ import java.util.regex.Pattern;
public class GalleryPageParser {
private static final Pattern PATTERN_IMAGE_URL = Pattern.compile("<div id=\"i3\"><a[^>]+><img id=\"img\" src=\"([^\"]+)\"");
private static final Pattern PATTERN_IMAGE_URL = Pattern.compile("<(?:/iframe|div id=\"i3\")[^>]*><a[^>]+><img[^>]*src=\"(.+?)\"");
private static final Pattern PATTERN_SKIP_HATH_KEY = Pattern.compile("onclick=\"return nl\\('([^\\)]+)'\\)");
private static final Pattern PATTERN_ORIGIN_IMAGE_URL = Pattern.compile("<div id=\"i7\" class=\"if\"> &nbsp; <img[^>]+/> <a href=\"([^\"]+)\">");
private static final Pattern PATTERN_ORIGIN_IMAGE_URL = Pattern.compile("<a href=\"([^\"]+)fullimg.php([^\"]+)\">");
public static Result parse(String body) throws ParseException {
Matcher m;
@@ -43,9 +43,10 @@ public class GalleryPageParser {
}
m = PATTERN_ORIGIN_IMAGE_URL.matcher(body);
if (m.find()) {
result.originImageUrl = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
result.originImageUrl = StringUtils.unescapeXml(m.group(1)) + "fullimg.php" + StringUtils.unescapeXml(m.group(2));
}
if (!TextUtils.isEmpty(result.imageUrl) && !TextUtils.isEmpty(result.skipHathKey)) {
if (!TextUtils.isEmpty(result.imageUrl)) {
return result;
} else {
throw new ParseException("Parse image url and skip hath key error", body);
@@ -16,6 +16,7 @@
package com.hippo.ehviewer.client.parser;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.client.exception.ParseException;
import com.hippo.util.JsoupUtils;
@@ -47,7 +48,7 @@ public class WhatsHotParser {
galleryInfo.gid = result.gid;
galleryInfo.token = result.token;
temp = JsoupUtils.getElementByTag(temp, "img");
galleryInfo.thumb = temp.attr("src");
galleryInfo.thumb = EhUtils.handleThumbUrlResolution(temp.attr("src"));
galleryInfo.title = temp.attr("title");
galleryInfo.generateSLang();
galleryInfoList.add(galleryInfo);
@@ -28,12 +28,12 @@ import com.hippo.ehviewer.dao.DownloadLabel;
import com.hippo.ehviewer.spider.SpiderQueen;
import com.hippo.image.Image;
import com.hippo.yorozuya.ConcurrentPool;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.sparse.SparseIJArray;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.LongList;
import com.hippo.yorozuya.collect.SparseIJArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import java.util.ArrayList;
import java.util.Collections;
@@ -40,10 +40,10 @@ import com.hippo.ehviewer.ui.scene.DownloadsScene;
import com.hippo.scene.StageActivity;
import com.hippo.util.ReadableTime;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.sparse.SparseJBArray;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.LongList;
import com.hippo.yorozuya.collect.SparseJBArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -345,7 +345,9 @@ public class DownloadService extends Service implements DownloadManager.Download
return;
}
mDownloadingDelay.cancel();
if (null != mDownloadingDelay) {
mDownloadingDelay.cancel();
}
ensureDownloadedBuilder();
@@ -443,7 +445,10 @@ public class DownloadService extends Service implements DownloadManager.Download
return;
}
mDownloadingDelay.cancel();
if (null != mDownloadingDelay) {
mDownloadingDelay.cancel();
}
checkStopSelf();
}
@@ -28,8 +28,8 @@ import com.hippo.image.Image;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.PriorityThread;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.thread.PriorityThread;
import java.io.File;
import java.io.FilenameFilter;
@@ -84,7 +84,7 @@ public class DirGalleryProvider extends GalleryProvider implements Runnable {
}
@Override
public void request(int index) {
protected void onRequest(int index) {
synchronized (mRequests) {
if (!mRequests.contains(index) && index != mDecodingIndex.get()) {
mRequests.add(index);
@@ -95,7 +95,12 @@ public class DirGalleryProvider extends GalleryProvider implements Runnable {
}
@Override
public void cancelRequest(int index) {
protected void onForceRequest(int index) {
onRequest(index);
}
@Override
public void onCancelRequest(int index) {
synchronized (mRequests) {
mRequests.remove(Integer.valueOf(index));
}
@@ -54,15 +54,9 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
if (mSpiderQueen != null) {
mSpiderQueen.removeOnSpiderListener(this);
final SpiderQueen spiderQueen = mSpiderQueen;
// Activity recreate may called, so wait 3000s
SimpleHandler.getInstance().postDelayed(new ReleaseTask(mSpiderQueen), 3000);
mSpiderQueen = null;
// Activity recreate may called
SimpleHandler.getInstance().postDelayed(new Runnable() {
@Override
public void run() {
SpiderQueen.releaseSpiderQueen(spiderQueen, SpiderQueen.MODE_READ);
}
}, 3000);
}
}
@@ -117,7 +111,7 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
}
@Override
public void request(int index) {
protected void onRequest(int index) {
if (mSpiderQueen != null) {
Object object = mSpiderQueen.request(index);
if (object instanceof Float) {
@@ -131,7 +125,7 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
}
@Override
public void forceRequest(int index) {
protected void onForceRequest(int index) {
if (mSpiderQueen != null) {
Object object = mSpiderQueen.forceRequest(index);
if (object instanceof Float) {
@@ -145,7 +139,7 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
}
@Override
public void cancelRequest(int index) {
protected void onCancelRequest(int index) {
if (mSpiderQueen != null) {
mSpiderQueen.cancelRequest(index);
}
@@ -200,4 +194,21 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
public void onGetImageFailure(int index, String error) {
notifyPageFailed(index, error);
}
private static class ReleaseTask implements Runnable {
private SpiderQueen mSpiderQueen;
public ReleaseTask(SpiderQueen spiderQueen) {
mSpiderQueen = spiderQueen;
}
@Override
public void run() {
if (null != mSpiderQueen) {
SpiderQueen.releaseSpiderQueen(mSpiderQueen, SpiderQueen.MODE_READ);
mSpiderQueen = null;
}
}
}
}
@@ -21,15 +21,25 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import com.hippo.beerbelly.LruCache;
import com.hippo.gl.glrenderer.GLCanvas;
import com.hippo.gl.view.GLRoot;
import com.hippo.image.Image;
import com.hippo.image.ImageWrapper;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.ConcurrentPool;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.NumberUtils;
import com.hippo.yorozuya.OSUtils;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class GalleryProvider {
@@ -48,6 +58,8 @@ public abstract class GalleryProvider {
private volatile GalleryProviderListener mGalleryProviderListener;
private volatile GLRoot mGLRoot;
private final ImageCache mImageCache = new ImageCache();
private boolean mStarted = false;
@UiThread
@@ -63,25 +75,40 @@ public abstract class GalleryProvider {
@UiThread
public void stop() {
OSUtils.checkMainLoop();
mImageCache.close();
}
public void setGLRoot(GLRoot glRoot) {
mGLRoot = glRoot;
}
/**
* @return {@link #STATE_WAIT} for wait, 0 for empty
*/
public abstract int size();
public abstract void request(int index);
public void forceRequest(int index) {
request(index);
public final void request(int index) {
ImageWrapper imageWrapper = mImageCache.get(index);
if (imageWrapper != null) {
notifyPageSucceed(index, imageWrapper);
} else {
onRequest(index);
}
}
public abstract void cancelRequest(int index);
public final void forceRequest(int index) {
onForceRequest(index);
}
protected abstract void onRequest(int index);
protected abstract void onForceRequest(int index);
public final void cancelRequest(int index) {
onCancelRequest(index);
}
protected abstract void onCancelRequest(int index);
public abstract String getError();
@@ -126,6 +153,12 @@ public abstract class GalleryProvider {
}
public void notifyPageSucceed(int index, Image image) {
ImageWrapper imageWrapper = new ImageWrapper(image);
mImageCache.add(index, imageWrapper);
notifyPageSucceed(index, imageWrapper);
}
public void notifyPageSucceed(int index, ImageWrapper image) {
notify(NotifyTask.TYPE_SUCCEED, index, 0.0f, image, null);
}
@@ -133,7 +166,7 @@ public abstract class GalleryProvider {
notify(NotifyTask.TYPE_FAILED, index, 0.0f, null, error);
}
private void notify(@NotifyTask.Type int type, int index, float percent, Image image, String error) {
private void notify(@NotifyTask.Type int type, int index, float percent, ImageWrapper image, String error) {
GalleryProviderListener listener = mGalleryProviderListener;
if (listener == null) {
return;
@@ -171,7 +204,7 @@ public abstract class GalleryProvider {
private int mType;
private int mIndex;
private float mPercent;
private Image mImage;
private ImageWrapper mImage;
private String mError;
public NotifyTask(GalleryProviderListener galleryProviderListener, ConcurrentPool<NotifyTask> pool) {
@@ -179,7 +212,7 @@ public abstract class GalleryProvider {
mPool = pool;
}
public void setData(@Type int type, int index, float percent, Image image, String error) {
public void setData(@Type int type, int index, float percent, ImageWrapper image, String error) {
mType = type;
mIndex = index;
mPercent = percent;
@@ -220,4 +253,67 @@ public abstract class GalleryProvider {
return false;
}
}
private static class ImageCache extends LruCache<Integer, ImageWrapper> {
private static final long MAX_CACHE_SIZE = 128 * 1024 * 1024;
private static final long MIN_CACHE_SIZE = 32 * 1024 * 1024;
private static final String PROCFS_MEMFILE = "/proc/meminfo";
private static final Pattern PROCFS_MEMFILE_FORMAT =
Pattern.compile("^([a-zA-Z]*):[ \t]*([0-9]*)[ \t]kB");
private static final String MEMTOTAL_STRING = "MemTotal";
private static long sMemTotal = -2L;
private static long getTotalMemory() {
if (sMemTotal != -2L) {
return sMemTotal;
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(PROCFS_MEMFILE), 64);
String line;
while ((line = reader.readLine()) != null) {
Matcher matcher = PROCFS_MEMFILE_FORMAT.matcher(line);
if (matcher.find() && MEMTOTAL_STRING.equals(matcher.group(1))) {
long mem = NumberUtils.parseLongSafely(matcher.group(2), -1L);
if (mem != -1L) {
mem *= 1024;
}
sMemTotal = mem;
return mem;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(reader);
}
sMemTotal = -1L;
return -1L;
}
public ImageCache() {
super((int) MathUtils.clamp(getTotalMemory() / 16, MIN_CACHE_SIZE, MAX_CACHE_SIZE));
}
public void add(Integer key, ImageWrapper value) {
if (value.obtain()) {
put(key, value);
}
}
@Override
protected int sizeOf(Integer key, ImageWrapper value) {
return value.getWidth() * value.getHeight() * 4;
}
@Override
protected void entryRemoved(boolean evicted, Integer key, ImageWrapper oldValue, ImageWrapper newValue) {
if (oldValue != null) {
oldValue.release();
}
}
}
}
@@ -16,7 +16,7 @@
package com.hippo.ehviewer.gallery;
import com.hippo.image.Image;
import com.hippo.image.ImageWrapper;
public interface GalleryProviderListener {
@@ -26,7 +26,7 @@ public interface GalleryProviderListener {
void onPagePercent(int index, float percent);
void onPageSucceed(int index, Image image);
void onPageSucceed(int index, ImageWrapper image);
void onPageFailed(int index, String error);
@@ -26,8 +26,8 @@ import com.hippo.ehviewer.R;
import com.hippo.ehviewer.gallery.gl.GalleryPageView;
import com.hippo.image.Image;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.PriorityThread;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.thread.PriorityThread;
import java.io.File;
import java.io.FileNotFoundException;
@@ -85,7 +85,7 @@ public class ZipGalleryProvider extends GalleryProvider implements Runnable {
}
@Override
public void request(int index) {
protected void onRequest(int index) {
synchronized (mRequests) {
if (!mRequests.contains(index) && index != mDecodingIndex.get()) {
mRequests.add(index);
@@ -96,7 +96,12 @@ public class ZipGalleryProvider extends GalleryProvider implements Runnable {
}
@Override
public void cancelRequest(int index) {
protected void onForceRequest(int index) {
onRequest(index);
}
@Override
protected void onCancelRequest(int index) {
synchronized (mRequests) {
mRequests.remove(Integer.valueOf(index));
}
@@ -121,7 +121,8 @@ public class GalleryPageView extends GLFrameLayout {
}
public void showInfo() {
mImage.setVisibility(GONE);
// For image valid rect
mImage.setVisibility(INVISIBLE);
mInfo.setVisibility(VISIBLE);
}
@@ -88,9 +88,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
private static final int METHOD_SET_SCALE_MODE = 18;
private static final int METHOD_SET_START_POSITION = 19;
private static final int METHOD_ON_ATTACH_TO_ROOT = 20;
private static final int METHOD_ON_DETACH_FROM_ROOT = 21;
private static final int METHOD_PAUSE = 22;
private static final int METHOD_RESUME = 23;
private final Context mContext;
private MovableTextTexture mPageTextTexture;
@@ -114,6 +111,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
private boolean mEnableRequestFill = true;
private boolean mRequestFill = false;
private boolean mWillFill = false;
private boolean mScale = false;
private boolean mScroll = false;
@@ -247,40 +245,17 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
postMethod(METHOD_ON_ATTACH_TO_ROOT);
}
private void onDetachFromRootInternal() {
@Override
public void onDetachFromRoot() {
// When detached, render() will not be called. So do it here
detachLayoutManager();
if (null != mPageTextTexture) {
mPageTextTexture.recycle();
mPageTextTexture = null;
}
}
@Override
public void onDetachFromRoot() {
super.onDetachFromRoot();
mEdgeView.onDetachFromRoot();
postMethod(METHOD_ON_DETACH_FROM_ROOT);
}
private void pauseInternal() {
mPause = true;
}
public void pause() {
postMethod(METHOD_PAUSE);
}
private void resumeInternal() {
if (mPause) {
mPause = false;
if (null != mLayoutManager) {
mLayoutManager.bindUnloadedPage();
}
}
}
public void resume() {
postMethod(METHOD_RESUME);
}
@LayoutMode
@@ -311,7 +286,9 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
public void requestFill() {
if (mEnableRequestFill) {
mRequestFill = true;
invalidate();
if (!mWillFill) {
invalidate();
}
}
}
@@ -785,15 +762,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
case METHOD_ON_ATTACH_TO_ROOT:
onAttachToRootInternal();
break;
case METHOD_ON_DETACH_FROM_ROOT:
onDetachFromRootInternal();
break;
case METHOD_PAUSE:
pauseInternal();
break;
case METHOD_RESUME:
resumeInternal();
break;
}
}
@@ -803,6 +771,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
@Override
public void render(GLCanvas canvas) {
mWillFill = true;
int oldCurrentIndex = mCurrentIndex.get();
// Dispatch method
@@ -814,6 +783,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
}
fill();
mWillFill = false;
super.render(canvas);
mEdgeView.render(canvas);
@@ -975,8 +945,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
public abstract void onDataChanged();
public abstract void bindUnloadedPage();
public abstract void onPageLeft();
public abstract void onPageRight();
@@ -208,6 +208,9 @@ public class ImageView extends GLView implements ImageTexture.Callback {
mImageTexture.setCallback(null);
}
int oldTextureWidth = mTextureWidth;
int oldTextureHeight = mTextureHeight;
mImageTexture = imageTexture;
if (imageTexture != null) {
@@ -222,8 +225,9 @@ public class ImageView extends GLView implements ImageTexture.Callback {
mTextureHeight = 1;
}
// Start alpha animation
if (isAttachedToRoot()) {
// Start alpha animation, do not show animation for image has no valid rect
getValidRect(mValidRect);
if (!mValidRect.isEmpty()) {
startAnimation(mAlphaAnimation, true);
}
} else {
@@ -233,6 +237,10 @@ public class ImageView extends GLView implements ImageTexture.Callback {
mScaleOffsetDirty = true;
mPositionInRootDirty = true;
if (oldTextureWidth != mTextureWidth || oldTextureHeight != mTextureHeight) {
requestLayout();
}
}
public ImageTexture getImageTexture() {
@@ -184,8 +184,8 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
@Override
public void onAttach(GalleryView.Adapter adapter) {
AssertUtils.assertEquals("The PagerLayoutManager is attached", mAdapter, null);
AssertUtils.assertNotEquals("The adapter is null", adapter, null);
AssertUtils.assertNull("The PagerLayoutManager is attached", mAdapter);
AssertUtils.assertNotNull("The adapter is null", adapter);
mAdapter = adapter;
// Reset parameters
resetParameters();
@@ -232,7 +232,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
@Override
public GalleryView.Adapter onDetach() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -293,7 +293,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
public void onFill() {
GalleryView.Adapter adapter = mAdapter;
GalleryView galleryView = mGalleryView;
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", adapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", adapter);
int width = galleryView.getWidth();
int height = galleryView.getHeight();
@@ -449,9 +449,8 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
image.getScaleDefault(scales);
float scale = image.getScale();
float endScale = scales[0];
for (int i = 0, size = scales.length; i < size; i++) {
float value = scales[i];
if (scale < value) {
for (float value: scales) {
if (scale < value - 0.01f) {
endScale = value;
break;
}
@@ -704,7 +703,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
@Override
public void onDataChanged() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -717,23 +716,6 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
mGalleryView.requestFill();
}
@Override
public void bindUnloadedPage() {
if (null == mAdapter) {
return;
}
if (null != mCurrent && !mCurrent.getImageView().isLoaded()) {
mAdapter.bind(mCurrent, mIndex);
}
if (null != mPrevious && !mPrevious.getImageView().isLoaded()) {
mAdapter.bind(mPrevious, mIndex - 1);
}
if (null != mNext && !mNext.getImageView().isLoaded()) {
mAdapter.bind(mNext, mIndex + 1);
}
}
@Override
public void onPageLeft() {
int size = mAdapter.size();
@@ -22,12 +22,15 @@ import android.support.annotation.NonNull;
import android.util.Log;
import com.hippo.ehviewer.gallery.GalleryProvider;
import com.hippo.gl.anim.Animation;
import com.hippo.gl.view.GLView;
import com.hippo.gl.widget.GLEdgeView;
import com.hippo.gl.widget.GLProgressView;
import com.hippo.gl.widget.GLTextureView;
import com.hippo.yorozuya.AnimationUtils;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.MathUtils;
import java.util.Iterator;
import java.util.LinkedList;
@@ -39,7 +42,13 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
private static final int INTERVAL = 24;
private static final float RESERVATIONS = 0.5f;
private static final float RESERVATION = 1f;
private static final float MAX_SCALE = 2.0f;
private static final float MIN_SCALE = 1.0f;
private static final float SCALE_ERROR = 0.01f;
private static final int INVALID_TOP = Integer.MAX_VALUE;
private GalleryView.Adapter mAdapter;
@@ -49,16 +58,22 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
private final LinkedList<GalleryPageView> mPages = new LinkedList<>();
private final LinkedList<GalleryPageView> mTempPages = new LinkedList<>();
private int mOffset;
private float mScale = 0.5f;
private int mOffsetX;
private int mOffsetY;
private int mDeltaX;
private int mDeltaY;
private int mFirstShownLoadedPageIndex = GalleryPageView.INVALID_INDEX;
private int mKeepTopPageIndex = GalleryPageView.INVALID_INDEX;
private int mKeepTop = INVALID_TOP;
private int mFirstShownPageIndex = GalleryPageView.INVALID_INDEX;
private boolean mScrollUp;
private boolean mFlingUp;
private boolean mStopAnimationFinger;
private final int mInterval;
private final PageFling mPageFling;
private final SmoothScaler mSmoothScaler;
// Current index
private int mIndex;
@@ -71,14 +86,20 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
mInterval = LayoutUtils.dp2pix(context, INTERVAL);
mPageFling = new PageFling(context);
mSmoothScaler = new SmoothScaler();
}
private void resetParameters() {
mOffset = 0;
mScale = 1.0f;
mOffsetX = 0;
mOffsetY = 0;
mDeltaX = 0;
mDeltaY = 0;
mFirstShownLoadedPageIndex = GalleryPageView.INVALID_INDEX;
mKeepTopPageIndex = GalleryPageView.INVALID_INDEX;
mKeepTop = INVALID_TOP;
mFirstShownPageIndex = GalleryPageView.INVALID_INDEX;
mScrollUp = false;
mFlingUp = false;
mStopAnimationFinger = false;
}
@@ -91,8 +112,8 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public void onAttach(GalleryView.Adapter adapter) {
AssertUtils.assertEquals("The ScrollLayoutManager is attached", mAdapter, null);
AssertUtils.assertNotEquals("The iterator is null", adapter, null);
AssertUtils.assertNull("The ScrollLayoutManager is attached", mAdapter);
AssertUtils.assertNotNull("The iterator is null", adapter);
mAdapter = adapter;
// Reset parameters
resetParameters();
@@ -130,7 +151,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public GalleryView.Adapter onDetach() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -166,6 +187,19 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
return null;
}
private boolean isInScreen(GalleryPageView page) {
int height = mGalleryView.getHeight();
Rect bound = page.bounds();
int pageTop = bound.top;
int pageBottom = bound.bottom;
return (pageTop >= 0 && pageTop < height) || (pageBottom > 0 && pageBottom <= height) ||
(pageTop < 0 && pageBottom > height);
}
private float getReservation() {
return Math.max(RESERVATION, (((1 + 2 * RESERVATION) * mScale) - 1) / 2);
}
private void fillPages(int startIndex, int startOffset) {
final GalleryView.Adapter adapter = mAdapter;
final GalleryView galleryView = mGalleryView;
@@ -173,11 +207,13 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
final LinkedList<GalleryPageView> tempPages = mTempPages;
final int width = galleryView.getWidth();
final int height = galleryView.getHeight();
final int pageWidth = (int) (width * mScale);
final int size = adapter.size();
final int interval = mInterval;
final int minY = (int) (-height * RESERVATIONS);
final int maxY = (int) (height * (1 + RESERVATIONS));
final int widthSpec = GLView.MeasureSpec.makeMeasureSpec(width, GLView.MeasureSpec.EXACTLY);
final float reservation = getReservation();
final int minY = (int) (-height * reservation);
final int maxY = (int) (height * (1 + reservation));
final int widthSpec = GLView.MeasureSpec.makeMeasureSpec(pageWidth, GLView.MeasureSpec.EXACTLY);
final int heightSpec = GLView.MeasureSpec.makeMeasureSpec(height, GLView.MeasureSpec.UNSPECIFIED);
// Fix start index and start offset
@@ -241,6 +277,14 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
tempPages.addAll(pages);
pages.clear();
// Sanitize offsetX
int margin = pageWidth - width;
if (margin >= 0) {
mOffsetX = MathUtils.clamp(mOffsetX, -margin, 0);
} else {
mOffsetX = -margin / 2;
}
// Layout start page
GalleryPageView page = getPageForIndex(tempPages, startIndex, true);
if (null == page) {
@@ -250,7 +294,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
}
pages.add(page);
page.measure(widthSpec, heightSpec);
page.layout(0, startOffset, width, startOffset + page.getMeasuredHeight());
page.layout(mOffsetX, startOffset, mOffsetX + pageWidth, startOffset + page.getMeasuredHeight());
// Prepare for check up and down
int bottomOffset = startOffset - interval;
@@ -267,7 +311,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
}
pages.addFirst(page);
page.measure(widthSpec, heightSpec);
page.layout(0, bottomOffset - page.getMeasuredHeight(), width, bottomOffset);
page.layout(mOffsetX, bottomOffset - page.getMeasuredHeight(), mOffsetX + pageWidth, bottomOffset);
// Update
bottomOffset -= page.getMeasuredHeight() + interval;
index--;
@@ -294,7 +338,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
}
pages.addLast(page);
page.measure(widthSpec, heightSpec);
page.layout(0, topOffset, width, topOffset + page.getMeasuredHeight());
page.layout(mOffsetX, topOffset, mOffsetX + pageWidth, topOffset + page.getMeasuredHeight());
// Update
topOffset += page.getMeasuredHeight() + interval;
index++;
@@ -330,7 +374,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
p.offsetTopAndBottom(offset);
}
int bottom = pagesTop - interval + offset;
page.layout(0, bottom - page.getMeasuredHeight(), width, bottom);
page.layout(mOffsetX, bottom - page.getMeasuredHeight(), mOffsetX + pageWidth, bottom);
}
}
@@ -344,7 +388,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
if (!pages.isEmpty()) {
page = pages.getFirst();
mIndex = page.getIndex();
mOffset = page.bounds().top;
mOffsetY = page.bounds().top;
}
}
@@ -352,9 +396,8 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
public void onFill() {
GalleryView.Adapter adapter = mAdapter;
GalleryView galleryView = mGalleryView;
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", adapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", adapter);
int height = galleryView.getHeight();
int size = adapter.size();
String errorStr = adapter.getError();
@@ -418,45 +461,49 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
removeAllPages();
}
// Find first shown loaded page top
GalleryPageView firstShownLoadedPage = null;
int firstShownLoadedPageTop = mOffset;
if (mFirstShownLoadedPageIndex != GalleryPageView.INVALID_INDEX) {
// Find keep index and keep top
int keepTop = INVALID_TOP;
int keepTopIndex;
if (GalleryPageView.INVALID_INDEX != mKeepTopPageIndex) {
keepTopIndex = mKeepTopPageIndex;
keepTop = mKeepTop;
} else if (GalleryPageView.INVALID_INDEX != mFirstShownPageIndex) {
keepTopIndex = mFirstShownPageIndex;
} else {
keepTopIndex = GalleryPageView.INVALID_INDEX;
}
if (GalleryPageView.INVALID_INDEX != keepTopIndex && INVALID_TOP == keepTop) {
keepTop = mOffsetY;
for (GalleryPageView page : pages) {
// Check first shown loaded page
if (mFirstShownLoadedPageIndex == page.getIndex()) {
firstShownLoadedPage = page;
// Check keep page
if (keepTopIndex == page.getIndex()) {
break;
}
firstShownLoadedPageTop += page.getHeight() + mInterval;
keepTop += page.getHeight() + mInterval;
}
}
int startIndex;
int startOffset;
if (null != firstShownLoadedPage) {
startIndex = mFirstShownLoadedPageIndex;
startOffset = firstShownLoadedPageTop;
if (GalleryPageView.INVALID_INDEX != keepTopIndex) {
startIndex = keepTopIndex;
startOffset = keepTop;
} else {
startIndex = mIndex;
startOffset = mOffset;
startOffset = mOffsetY;
}
fillPages(startIndex, startOffset);
// Get first shown loaded image
mFirstShownLoadedPageIndex = GalleryPageView.INVALID_INDEX;
// Get first shown image
mFirstShownPageIndex = GalleryPageView.INVALID_INDEX;
for (GalleryPageView page : mPages) {
// Check first shown loaded page
if (!page.isLoaded()) {
if ((mScrollUp || mFlingUp) && !page.isLoaded()) {
continue;
}
Rect bound = page.bounds();
int pageTop = bound.top;
int pageBottom = bound.bottom;
if ((pageTop >= 0 && pageTop < height) || (pageBottom > 0 && pageBottom <= height) ||
(pageTop < 0 && pageBottom > height)) {
mFirstShownLoadedPageIndex = page.getIndex();
if (isInScreen(page)) {
mFirstShownPageIndex = page.getIndex();
break;
}
}
@@ -473,12 +520,25 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public void onUp() {
mScrollUp = false;
mGalleryView.getEdgeView().onRelease();
}
@Override
public void onDoubleTapConfirmed(float x, float y) {
if (mPages.size() <= 0) {
return;
}
float startScale = mScale;
float endScale;
if (startScale < MAX_SCALE - SCALE_ERROR) {
endScale = MAX_SCALE;
} else {
endScale = MIN_SCALE;
}
mSmoothScaler.startSmoothScaler(x, y, startScale, endScale, 300);
}
@Override
@@ -492,7 +552,6 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
mDeltaX += dx;
mDeltaY += dy;
/*
if (mDeltaX < 0) {
edgeView.onPull(-mDeltaX, y, GLEdgeView.LEFT);
if (!edgeView.isFinished(GLEdgeView.RIGHT)) {
@@ -504,7 +563,6 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
edgeView.onRelease(GLEdgeView.LEFT);
}
}
*/
if (mDeltaY < 0) {
edgeView.onPull(-mDeltaY, x, GLEdgeView.TOP);
@@ -521,7 +579,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
private void getBottomState() {
List<GalleryPageView> pages = mPages;
int bottom = mOffset;
int bottom = mOffsetY;
int i = 0;
for (GalleryPageView page : pages) {
if (i != 0) {
@@ -538,49 +596,70 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
// True for get top or bottom
private boolean scrollInternal(float dx, float dy, boolean fling, float x, float y) {
if (mPages.size() == 0) {
if (mPages.size() <= 0) {
return false;
}
GalleryView galleryView = mGalleryView;
int width = galleryView.getWidth();
int height = galleryView.getHeight();
int pageWidth = (int) (width * mScale);
final float reservation = getReservation();
boolean requestFill = false;
int remainY = (int) dy;
boolean result = false;
int margin = pageWidth - width;
int dxInt = (int) dx;
if (margin > 0 && 0 != dxInt) {
int oldOffsetX = mOffsetX;
int exceptOffsetX = oldOffsetX - dxInt;
mOffsetX = MathUtils.clamp(exceptOffsetX, -margin, 0);
if (mOffsetX != oldOffsetX) {
requestFill = true;
}
// Do not show over scroll effect for left and right
/*
int extraOffsetX = mOffsetX - exceptOffsetX;
if (0 != extraOffsetX) {
overScrollEdge(extraOffsetX, 0, x, y);
}
*/
}
int remainY = (int) dy;
while (remainY != 0) {
if (remainY < 0) { // Try to show top
int limit;
if (mIndex > 0) {
limit = (int) (-height * RESERVATIONS) + mInterval;
limit = (int) (-height * reservation) + mInterval;
} else {
limit = 0;
}
if (mOffset - remainY <= limit) {
mOffset -= remainY;
if (mOffsetY - remainY <= limit) {
mOffsetY -= remainY;
remainY = 0;
requestFill = true;
mDeltaX = 0;
mDeltaY = 0;
} else {
if (mIndex > 0) {
mOffset = limit;
remainY = remainY + limit - mOffset;
mOffsetY = limit;
remainY = remainY + limit - mOffsetY;
// Offset one pixel to avoid infinite loop
++mOffset;
++mOffsetY;
++remainY;
galleryView.forceFill();
requestFill = false;
mDeltaX = 0;
mDeltaY = 0;
} else {
if (mOffset != limit) {
mOffset = limit;
if (mOffsetY != limit) {
mOffsetY = limit;
requestFill = true;
}
if (!fling) {
overScrollEdge(0, remainY + limit - mOffset, x, y);
overScrollEdge(0, remainY + limit - mOffsetY, x, y);
}
remainY = 0;
result = true;
@@ -593,7 +672,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
int limit;
if (hasNext) {
limit = (int) (height * (1 + RESERVATIONS)) - mInterval;
limit = (int) (height * (1 + reservation)) - mInterval;
} else {
limit = height;
}
@@ -601,25 +680,25 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
limit = Math.min(bottom, limit);
if (bottom - remainY >= limit) {
mOffset -= remainY;
mOffsetY -= remainY;
remainY = 0;
requestFill = true;
mDeltaX = 0;
mDeltaY = 0;
} else {
if (hasNext) {
mOffset -= bottom - limit;
mOffsetY -= bottom - limit;
remainY = remainY + limit - bottom;
// Offset one pixel to avoid infinite loop
--mOffset;
--mOffsetY;
--remainY;
galleryView.forceFill();
requestFill = false;
mDeltaX = 0;
mDeltaY = 0;
} else {
if (mOffset != limit) {
mOffset -= bottom - limit;
if (mOffsetY != limit) {
mOffsetY -= bottom - limit;
requestFill = true;
}
if (!fling) {
@@ -641,6 +720,8 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public void onScroll(float dx, float dy, float totalX, float totalY, float x, float y) {
mKeepTopPageIndex = GalleryPageView.INVALID_INDEX;
mKeepTop = INVALID_TOP;
mScrollUp = dy < 0;
scrollInternal(dx, dy, false, x, y);
}
@@ -651,13 +732,28 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
return;
}
mScrollUp = velocityY > 0;
mKeepTopPageIndex = GalleryPageView.INVALID_INDEX;
mKeepTop = INVALID_TOP;
mFlingUp = velocityY > 0;
int maxX;
int minX;
int width = mGalleryView.getWidth();
int pageWidth = (int) (width * mScale);
int margin = pageWidth - width;
if (margin > 0) {
maxX = -mOffsetX;
minX = -margin + mOffsetX;
} else {
maxX = 0;
minX = 0;
}
int maxY;
if (mIndex > 0) {
maxY = Integer.MAX_VALUE;
} else {
maxY = -mOffset;
maxY = -mOffsetY;
}
getBottomState();
@@ -670,29 +766,72 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
minY = mGalleryView.getHeight() - bottom;
}
mPageFling.startFling((int) velocityX, 0, 0,
mPageFling.startFling((int) velocityX, minX, maxX,
(int) velocityY, minY, maxY);
}
@Override
public boolean canScale() {
return false;
return mPages.size() > 0;
}
@Override
public void onScale(float focusX, float focusY, float scale) {
if (mPages.isEmpty()) {
return;
}
float oldScale = mScale;
mScale = MathUtils.clamp(oldScale * scale, MIN_SCALE, MAX_SCALE);
scale = mScale / oldScale;
if (oldScale != mScale) {
GalleryPageView page = null;
// Keep scale page origin position
for (GalleryPageView p : mPages) {
if (p.bounds().top < focusY) {
page = p;
} else {
break;
}
}
if (null != page) {
mKeepTopPageIndex = page.getIndex();
mKeepTop = page.bounds().top;
mGalleryView.forceFill();
int oldKeepTop = mKeepTop;
mKeepTop = INVALID_TOP;
// Apply scroll
int newOffsetX = (int) (focusX - ((focusX - mOffsetX) * scale));
int newKeepTop;
if (page.isLoaded()) {
newKeepTop = (int) (focusY - ((focusY - oldKeepTop) * scale));
} else {
newKeepTop = oldKeepTop;
}
scrollInternal(mOffsetX - newOffsetX, oldKeepTop - newKeepTop, false, focusX, focusY);
} else {
Log.e(TAG, "Can't find target page");
mKeepTopPageIndex = GalleryPageView.INVALID_INDEX;
mKeepTop = INVALID_TOP;
mGalleryView.forceFill();
}
}
}
@Override
public boolean onUpdateAnimation(long time) {
boolean invalidate = mPageFling.calculate(time);
invalidate |= mSmoothScaler.calculate(time);
return invalidate;
}
@Override
public void onDataChanged() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -705,21 +844,6 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
mGalleryView.requestFill();
}
@Override
public void bindUnloadedPage() {
if (null == mAdapter || 0 <= mPages.size()) {
return;
}
int index = mIndex;
for (GalleryPageView page: mPages) {
if (!page.getImageView().isLoaded()) {
mAdapter.bind(page, index);
}
index++;
}
}
@Override
public void onPageLeft() {
int size = mAdapter.size();
@@ -727,8 +851,11 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
return;
}
///////
// UP
///////
GalleryView galleryView = mGalleryView;
if (mIndex == 0 && mOffset >= 0) {
if (mIndex == 0 && mOffsetY >= 0) {
GLEdgeView edgeView = galleryView.getEdgeView();
edgeView.onPull(galleryView.getHeight(),
galleryView.getWidth() / 2, GLEdgeView.TOP);
@@ -736,13 +863,37 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
} else {
// Cancel all animations
cancelAllAnimations();
mOffset += galleryView.getHeight() / 2;
// Backup offset
int offset = mOffset;
// Reset parameters
resetParameters();
// Restore offset
mOffset = offset;
// Get first shown page
GalleryPageView previousPage = null;
GalleryPageView firstShownPage = null;
for (GalleryPageView p: mPages) {
if (isInScreen(p)) {
firstShownPage = p;
break;
}
previousPage = p;
}
int height = galleryView.getHeight();
int maxOffset = height - mInterval;
if (null == firstShownPage) {
Log.e(TAG, "Can't find first shown page when paging left");
mOffsetY += height / 2;
} else {
int firstShownTop = firstShownPage.bounds().top;
if (firstShownTop >= 0) {
if (null == previousPage) {
Log.e(TAG, "Can't find previous page when paging left and offsetY == 0");
mOffsetY += height / 2;
} else {
mOffsetY += Math.min(maxOffset, -previousPage.bounds().top);
}
} else {
mOffsetY += Math.min(maxOffset, -firstShownTop);
}
}
// Request fill
mGalleryView.requestFill();
}
@@ -755,6 +906,9 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
return;
}
/////////
// DOWN
/////////
GalleryView galleryView = mGalleryView;
getBottomState();
int bottom = mBottomStateBottom;
@@ -767,13 +921,38 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
} else {
// Cancel all animations
cancelAllAnimations();
mOffset -= galleryView.getHeight() / 2;
// Backup offset
int offset = mOffset;
// Reset parameters
resetParameters();
// Restore offset
mOffset = offset;
// Get first shown page
GalleryPageView lastShownPage = null;
GalleryPageView nextPage = null;
for (GalleryPageView p: mPages) {
if (isInScreen(p)) {
lastShownPage = p;
} else if (null != lastShownPage) {
nextPage = p;
break;
}
}
int height = galleryView.getHeight();
int maxOffset = height - mInterval;
if (null == lastShownPage) {
Log.e(TAG, "Can't find last shown page when paging left");
mOffsetY -= height / 2;
} else {
int lastShownBottom = lastShownPage.bounds().bottom;
if (lastShownBottom <= height) {
if (null == nextPage) {
Log.e(TAG, "Can't find previous page when paging left and offsetY == 0");
mOffsetY -= height / 2;
} else {
mOffsetY -= Math.min(maxOffset, nextPage.bounds().bottom - height);
}
} else {
mOffsetY -= Math.min(maxOffset, lastShownBottom - height);
}
}
// Request fill
mGalleryView.requestFill();
}
@@ -796,13 +975,8 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public int getCurrentIndex() {
int height = mGalleryView.getHeight();
for (GalleryPageView page : mPages) {
Rect bound = page.bounds();
int pageTop = bound.top;
int pageBottom = bound.bottom;
if ((pageTop >= 0 && pageTop < height) || (pageBottom > 0 && pageBottom <= height) ||
(pageTop < 0 && pageBottom > height)) {
if (isInScreen(page)) {
return page.getIndex();
}
}
@@ -816,9 +990,13 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
// Can't get size now, assume size is MAX
size = Integer.MAX_VALUE;
}
if (index == mIndex || index < 0 || index >= size) {
if (index < 0 || index >= size) {
return;
}
mKeepTopPageIndex = index;
mKeepTop = INVALID_TOP;
if (mPages.isEmpty()) {
mIndex = index;
} else {
@@ -834,25 +1012,18 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
if (targetPage != null) {
// Cancel all animations
cancelAllAnimations();
mOffset -= targetPage.bounds().top;
// Backup offset
int offset = mOffset;
// Reset parameters
resetParameters();
// Restore offset
mOffset = offset;
mOffsetY -= targetPage.bounds().top;
// Request fill
mGalleryView.requestFill();
} else {
mIndex = index;
mOffsetY = 0;
// Cancel all animations
cancelAllAnimations();
// Remove all view
removeProgress();
removeErrorView();
removeAllPages();
// Reset parameters
resetParameters();
// Request fill
mGalleryView.requestFill();
}
@@ -884,7 +1055,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
return currentIndex;
}
class PageFling extends Fling {
private class PageFling extends Fling {
private int mVelocityX;
private int mVelocityY;
@@ -950,9 +1121,11 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
protected void onFinish() {
mFlingUp = false;
int index = mIndex;
boolean topEdge = index <= 0 && mOffset >= 0;
boolean topEdge = index <= 0 && mOffsetY >= 0;
getBottomState();
int bottom = mBottomStateBottom;
@@ -971,4 +1144,40 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
}
}
}
private class SmoothScaler extends Animation {
private float mFocusX;
private float mFocusY;
private float mStartScale;
private float mEndScale;
private float mLastScale;
public SmoothScaler() {
setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
}
public void startSmoothScaler(float focusX, float focusY,
float startScale, float endScale, int duration) {
mFocusX = focusX;
mFocusY = focusY;
mStartScale = startScale;
mEndScale = endScale;
mLastScale = startScale;
setDuration(duration);
start();
mGalleryView.invalidate();
}
@Override
protected void onCalculate(float progress) {
if (mPages.size() <= 0) {
return;
}
float scale = MathUtils.lerp(mStartScale, mEndScale, progress);
onScale(mFocusX, mFocusY, scale / mLastScale);
mLastScale = scale;
}
}
}
@@ -0,0 +1,116 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.preference;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.Toast;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.download.DownloadManager;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.NumberUtils;
public class CleanRedundancyPreference extends TaskPreference {
public CleanRedundancyPreference(Context context) {
super(context);
}
public CleanRedundancyPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CleanRedundancyPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@NonNull
@Override
protected Task onCreateTask() {
return new ClearTask(getContext());
}
private static class ClearTask extends Task {
private final EhApplication mApplication;
private final DownloadManager mManager;
public ClearTask(@NonNull Context context) {
super(context);
mApplication = (EhApplication) context.getApplicationContext();
mManager = EhApplication.getDownloadManager(mApplication);
}
// True for cleared
private boolean clearFile(UniFile file) {
String name = file.getName();
int index = name.indexOf('-');
if (index >= 0) {
name = name.substring(0, index);
}
long gid = NumberUtils.parseLongSafely(name, -1L);
if (-1L == gid) {
return false;
}
if (mManager.containDownloadInfo(gid)) {
return false;
}
file.delete();
return true;
}
@Override
protected Object doInBackground(Void... params) {
UniFile dir = Settings.getDownloadLocation();
if (null == dir) {
return 0;
}
UniFile[] files = dir.listFiles();
if (null == files) {
return 0;
}
int count = 0;
for (UniFile f: files) {
if (clearFile(f)) {
++count;
}
}
return count;
}
@Override
protected void onPostExecute(Object o) {
int count;
if (o instanceof Integer) {
count = (Integer) o;
} else {
count = 0;
}
Toast.makeText(mApplication, 0 == count ?
mApplication.getString(R.string.settings_download_clean_redundancy_no_redundancy):
mApplication.getString(R.string.settings_download_clean_redundancy_done, count), Toast.LENGTH_SHORT).show();
super.onPostExecute(o);
}
}
}
@@ -42,12 +42,6 @@ public class ClearDownloadPathCachePreference extends MessagePreference {
init(context);
}
public ClearDownloadPathCachePreference(Context context,
AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
public void init(Context context) {
setDialogMessage(context.getString(R.string.settings_advanced_clear_download_path_cache_message));
}
@@ -47,11 +47,6 @@ public class DefaultCategoryPreference extends DialogPreference {
init();
}
public DefaultCategoryPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setDialogLayoutResource(R.layout.preference_dialog_default_categories);
}
@@ -69,11 +69,6 @@ public class ExcludedTagNamespacesPreference extends DialogPreference {
init();
}
public ExcludedTagNamespacesPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setDialogLayoutResource(R.layout.preference_dialog_excluded_tag_namespaces);
}
@@ -66,11 +66,6 @@ public class HatHProxyPreference extends DialogPreference implements View.OnClic
init();
}
public HatHProxyPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setDialogLayoutResource(R.layout.preference_dialog_hath_proxy);
updateSummary(Settings.getHathProxy(), Settings.getHathIp(), Settings.getHathPort());
@@ -42,11 +42,6 @@ public class SignOutPreference extends MessagePreference {
init();
}
public SignOutPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setDialogMessage(getContext().getString(R.string.settings_eh_sign_out_warning));
}
@@ -30,13 +30,14 @@ import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.gallery.GalleryProvider;
import com.hippo.io.UniFileInputStreamPipe;
import com.hippo.io.UniFileOutputStreamPipe;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.unifile.FilenameFilter;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.Utilities;
import com.hippo.yorozuya.io.InputStreamPipe;
import com.hippo.yorozuya.io.OutputStreamPipe;
import java.io.File;
import java.io.IOException;
@@ -54,7 +55,8 @@ public final class SpiderDen {
private static SimpleDiskCache sCache;
public static void initialize(Context context) {
sCache = new SimpleDiskCache(new File(context.getCacheDir(), "image"), 160 * 1024 * 1024);
sCache = new SimpleDiskCache(new File(context.getCacheDir(), "image"),
MathUtils.clamp(Settings.getReadCacheSize(), 40, 640) * 1024 * 1024);
}
private static class StartWithFilenameFilter implements FilenameFilter {
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.spider;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
@@ -102,6 +103,10 @@ public class SpiderInfo {
spiderInfo.previewPerPage = Integer.parseInt(IOUtils.readAsciiLine(is));
// Pages
spiderInfo.pages = Integer.parseInt(IOUtils.readAsciiLine(is));
// Check pages
if (spiderInfo.pages <= 0) {
return null;
}
// PToken
spiderInfo.pTokenMap = new SparseArray<>(spiderInfo.pages);
while (true) { // EOFException will raise
@@ -110,7 +115,9 @@ public class SpiderInfo {
if (pos > 0 || pos < line.length() - 1) {
int index = Integer.parseInt(line.substring(0, pos));
String pToken = line.substring(pos + 1);
spiderInfo.pTokenMap.put(index, pToken);
if (!TextUtils.isEmpty(pToken)) {
spiderInfo.pTokenMap.put(index, pToken);
}
} else {
Log.e(TAG, "Can't parse index and pToken, index = " + pos);
}
@@ -147,12 +154,14 @@ public class SpiderInfo {
writer.write(Integer.toString(pages));
writer.write("\n");
for (int i = 0; i < pTokenMap.size(); i++) {
if (TOKEN_FAILED.equals(pTokenMap.valueAt(i))) {
Integer key = pTokenMap.keyAt(i);
String value = pTokenMap.valueAt(i);
if (TOKEN_FAILED.equals(value) || TextUtils.isEmpty(value)) {
continue;
}
writer.write(Integer.toString(pTokenMap.keyAt(i)));
writer.write(Integer.toString(key));
writer.write(" ");
writer.write(pTokenMap.valueAt(i));
writer.write(value);
writer.write("\n");
}
writer.flush();
@@ -35,6 +35,7 @@ import com.hippo.ehviewer.GetText;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhConfig;
import com.hippo.ehviewer.client.EhEngine;
import com.hippo.ehviewer.client.EhRequestBuilder;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.data.GalleryInfo;
@@ -47,24 +48,24 @@ import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
import com.hippo.ehviewer.gallery.GalleryProvider;
import com.hippo.ehviewer.gallery.gl.GalleryPageView;
import com.hippo.image.Image;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.util.ExceptionUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.OSUtils;
import com.hippo.yorozuya.PriorityThread;
import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.Utilities;
import com.hippo.yorozuya.io.InputStreamPipe;
import com.hippo.yorozuya.io.OutputStreamPipe;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import com.hippo.yorozuya.thread.PriorityThread;
import com.hippo.yorozuya.thread.PriorityThreadFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -421,11 +422,11 @@ public class SpiderQueen implements Runnable {
}
public Object forceRequest(int index) {
return request(index, true);
return request(index, true, false);
}
public Object request(int index) {
return request(index, false);
return request(index, false, true);
}
private int getPageState(int index) {
@@ -471,7 +472,7 @@ public class SpiderQueen implements Runnable {
* Float for download percent<br>
* null for wait
*/
private Object request(int index, boolean force) {
private Object request(int index, boolean force, boolean addNeighbor) {
if (mQueenThread == null) {
return null;
}
@@ -494,8 +495,8 @@ public class SpiderQueen implements Runnable {
}
}
// For not force add, add next some pages to request queue
if (!force) {
// Add next some pages to request queue
if (addNeighbor) {
mRequestPageQueue2.clear();
int[] pageStateArray = mPageStateArray;
int size;
@@ -905,6 +906,55 @@ public class SpiderQueen implements Runnable {
}
}
private void updatePageState(int index, @State int state) {
updatePageState(index, state, null);
}
private boolean isStateDone(int state) {
return state == STATE_FINISHED || state == STATE_FAILED;
}
private void updatePageState(int index, @State int state, String error) {
int oldState;
synchronized (mPageStateLock) {
oldState = mPageStateArray[index];
mPageStateArray[index] = state;
if (!isStateDone(oldState) && isStateDone(state)) {
mDownloadedPages.incrementAndGet();
} else if (isStateDone(oldState) && !isStateDone(state)) {
mDownloadedPages.decrementAndGet();
}
if (oldState != STATE_FINISHED && state == STATE_FINISHED) {
mFinishedPages.incrementAndGet();
} else if (oldState == STATE_FINISHED && state != STATE_FINISHED) {
mFinishedPages.decrementAndGet();
}
// Clear
if (state == STATE_DOWNLOADING) {
mPageErrorMap.remove(index);
} else if (state == STATE_FINISHED || state == STATE_FAILED) {
mPagePercentMap.remove(index);
}
// Get default error
if (state == STATE_FAILED) {
if (error == null) {
error = GetText.getString(R.string.error_unknown);
}
mPageErrorMap.put(index, error);
}
}
// Notify listeners
if (state == STATE_FAILED) {
notifyPageFailure(index, error);
} else if (state == STATE_FINISHED) {
notifyPageSuccess(index);
}
}
private class SpiderWorker implements Runnable {
private final long mGid;
@@ -913,67 +963,14 @@ public class SpiderQueen implements Runnable {
mGid = mGalleryInfo.gid;
}
private void updatePageState(int index, @State int state) {
updatePageState(index, state, null);
}
private boolean isStateDone(int state) {
return state == STATE_FINISHED || state == STATE_FAILED;
}
private void updatePageState(int index, @State int state, String error) {
int oldState;
synchronized (mPageStateLock) {
oldState = mPageStateArray[index];
mPageStateArray[index] = state;
if (!isStateDone(oldState) && isStateDone(state)) {
mDownloadedPages.incrementAndGet();
} else if (isStateDone(oldState) && !isStateDone(state)) {
mDownloadedPages.decrementAndGet();
}
if (oldState != STATE_FINISHED && state == STATE_FINISHED) {
mFinishedPages.incrementAndGet();
} else if (oldState == STATE_FINISHED && state != STATE_FINISHED) {
mFinishedPages.decrementAndGet();
}
// Clear
if (state == STATE_DOWNLOADING) {
mPageErrorMap.remove(index);
} else if (state == STATE_FINISHED || state == STATE_FAILED) {
mPagePercentMap.remove(index);
}
// Get default error
if (state == STATE_FAILED) {
if (error == null) {
error = GetText.getString(R.string.error_unknown);
}
mPageErrorMap.put(index, error);
}
}
// Notify listeners
if (state == STATE_FAILED) {
notifyPageFailure(index, error);
} else if (state == STATE_FINISHED) {
notifyPageSuccess(index);
}
}
private GalleryPageParser.Result getImageUrl(long gid, int index, String pToken,
String skipHathKey) throws IOException, ParseException, Image509Exception {
String skipHathKey) throws Exception {
String url = EhUrl.getPageUrl(gid, index, pToken);
if (skipHathKey != null) {
url = url + "?nl=" + skipHathKey;
}
if (DEBUG_LOG) {
Log.d(TAG, url);
}
Response response = mHttpClient.newCall(new EhRequestBuilder(url).build()).execute();
String body = response.body().string();
GalleryPageParser.Result result = GalleryPageParser.parse(body);
GalleryPageParser.Result result = EhEngine.getGalleryPage(null, mHttpClient, url);
if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) {
// Get 509
// Notify listeners
@@ -993,17 +990,18 @@ public class SpiderQueen implements Runnable {
// Try twice
for (int i = 0; i < 2; i++) {
if (i > 0 && TextUtils.isEmpty(skipHathKey)) {
// No need to get image url twice without skip hath key
break;
}
GalleryPageParser.Result result = null;
try {
result = getImageUrl(gid, index, pToken, skipHathKey);
} catch (MalformedURLException e) {
error = GetText.getString(R.string.error_invalid_url);
} catch (IOException e) {
error = GetText.getString(R.string.error_socket);
} catch (ParseException e) {
error = GetText.getString(R.string.error_parse_error);
} catch (Image509Exception e) {
error = GetText.getString(R.string.error_509);
} catch (Exception e) {
error = ExceptionUtils.getReadableString(e);
}
if (result == null) {
// Get image url failed
@@ -1179,7 +1177,7 @@ public class SpiderQueen implements Runnable {
int i = mSpiderInfo.pTokenMap.indexOfKey(index);
String pToken = mSpiderInfo.pTokenMap.valueAt(i);
if (SpiderInfo.TOKEN_FAILED.equals(pToken)) {
mSpiderInfo.pTokenMap.setValueAt(i, null);
mSpiderInfo.pTokenMap.remove(i);
}
}
}
@@ -1294,7 +1292,10 @@ public class SpiderQueen implements Runnable {
InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index);
if (pipe == null) {
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
notifyGetImageFailure(index, GetText.getString(R.string.error_not_found));
// Can't find the file, it might be removed from cache,
// Reset it state and request it
updatePageState(index, STATE_NONE, null);
request(index, false, false);
continue;
}
@@ -117,7 +117,7 @@ public final class CommonOperations {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UrlOpener.openUrl(mActivity, url, false, false);
UrlOpener.openUrl(mActivity, url, false);
}
}).show();
}
@@ -309,4 +309,15 @@ public final class CommonOperations {
IOUtils.closeQuietly(is);
}
}
public static void removeNoMediaFile(UniFile file) {
if (null == file) {
return;
}
UniFile noMedia = file.subFile(".nomedia");
if (null != noMedia && noMedia.isFile()) {
noMedia.delete();
}
}
}
@@ -16,10 +16,8 @@
package com.hippo.ehviewer.ui;
import android.annotation.TargetApi;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -29,7 +27,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.hippo.ehviewer.R;
import com.hippo.rippleold.RippleSalon;
import com.hippo.ripple.Ripple;
import com.hippo.widget.DirExplorer;
import com.hippo.yorozuya.ViewUtils;
@@ -52,7 +50,6 @@ public class DirPickerActivity extends ToolbarActivity
@Nullable
private View mOk;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -73,7 +70,7 @@ public class DirPickerActivity extends ToolbarActivity
mDirExplorer.setCurrentFile(file);
mDirExplorer.setOnChangeDirListener(this);
RippleSalon.addRipple(mOk, false);
Ripple.addRipple(mOk, false);
mOk.setOnClickListener(this);
@@ -1,21 +0,0 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.ui;
// It is a dump activity to make Chrome or maybe other browser to send implicit intent when open eh url.
// Take a look at AndroidManifest to know how it works.
public class DumpBrowsableActivity extends EhActivity {}
@@ -30,7 +30,7 @@ import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhConfig;
import com.hippo.rippleold.RippleSalon;
import com.hippo.ripple.Ripple;
import com.hippo.widget.SensitiveCheckBox;
import com.hippo.yorozuya.ViewUtils;
@@ -163,11 +163,11 @@ public class ExcludedLanguagesActivity extends ToolbarActivity
mDeselectAll.setOnClickListener(this);
mInvertSelection.setOnClickListener(this);
RippleSalon.addRipple(mCancel, false);
RippleSalon.addRipple(mOk, false);
RippleSalon.addRipple(mSelectAll, false);
RippleSalon.addRipple(mDeselectAll, false);
RippleSalon.addRipple(mInvertSelection, false);
Ripple.addRipple(mCancel, false);
Ripple.addRipple(mOk, false);
Ripple.addRipple(mSelectAll, false);
Ripple.addRipple(mDeselectAll, false);
Ripple.addRipple(mInvertSelection, false);
}
private boolean isDecimal(String str) {
@@ -62,7 +62,7 @@ import com.hippo.ehviewer.widget.GalleryGuideView;
import com.hippo.ehviewer.widget.ReversibleSeekBar;
import com.hippo.gl.glrenderer.ImageTexture;
import com.hippo.gl.view.GLRootView;
import com.hippo.image.Image;
import com.hippo.image.ImageWrapper;
import com.hippo.unifile.UniFile;
import com.hippo.util.SystemUiHelper;
import com.hippo.widget.ColorView;
@@ -85,6 +85,7 @@ public class GalleryActivity extends EhActivity
public static final String KEY_ACTION = "action";
public static final String KEY_FILENAME = "filename";
public static final String KEY_URI = "uri";
public static final String KEY_GALLERY_INFO = "gallery_info";
public static final String KEY_PAGE = "page";
public static final String KEY_CURRENT_INDEX = "current_index";
@@ -94,9 +95,12 @@ public class GalleryActivity extends EhActivity
private String mAction;
private String mFilename;
private Uri mUri;
private GalleryInfo mGalleryInfo;
private int mPage;
@Nullable
private GLRootView mGLRootView;
@Nullable
private GalleryView mGalleryView;
@@ -114,6 +118,8 @@ public class GalleryActivity extends EhActivity
@Nullable
private View mClock;
@Nullable
private TextView mProgress;
@Nullable
private View mBattery;
@Nullable
private View mSeekBarPanel;
@@ -184,6 +190,11 @@ public class GalleryActivity extends EhActivity
if (mGalleryInfo != null) {
mGalleryProvider = new EhGalleryProvider(this, mGalleryInfo);
}
} else if (Intent.ACTION_VIEW.equals(mAction)) {
if (mUri != null) {
// Only support zip now
mGalleryProvider = new ZipGalleryProvider(new File(mUri.getPath()));
}
}
}
@@ -195,6 +206,7 @@ public class GalleryActivity extends EhActivity
mAction = intent.getAction();
mFilename = intent.getStringExtra(KEY_FILENAME);
mUri = intent.getData();
mGalleryInfo = intent.getParcelableExtra(KEY_GALLERY_INFO);
mPage = intent.getIntExtra(KEY_PAGE, -1);
buildProvider();
@@ -203,6 +215,7 @@ public class GalleryActivity extends EhActivity
private void onRestore(@NonNull Bundle savedInstanceState) {
mAction = savedInstanceState.getString(KEY_ACTION);
mFilename = savedInstanceState.getString(KEY_FILENAME);
mUri= savedInstanceState.getParcelable(KEY_URI);
mGalleryInfo = savedInstanceState.getParcelable(KEY_GALLERY_INFO);
mPage = savedInstanceState.getInt(KEY_PAGE, -1);
mCurrentIndex = savedInstanceState.getInt(KEY_CURRENT_INDEX);
@@ -214,6 +227,7 @@ public class GalleryActivity extends EhActivity
super.onSaveInstanceState(outState);
outState.putString(KEY_ACTION, mAction);
outState.putString(KEY_FILENAME, mFilename);
outState.putParcelable(KEY_URI, mUri);
if (mGalleryInfo != null) {
outState.putParcelable(KEY_GALLERY_INFO, mGalleryInfo);
}
@@ -223,6 +237,14 @@ public class GalleryActivity extends EhActivity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
if (Settings.getReadingFullscreen() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
@@ -239,9 +261,9 @@ public class GalleryActivity extends EhActivity
mGalleryProvider.start();
setContentView(R.layout.activity_gallery);
GLRootView glRootView = (GLRootView) ViewUtils.$$(this, R.id.gl_root_view);
mGalleryProvider.setGLRoot(glRootView);
mUploader = new ImageTexture.Uploader(glRootView);
mGLRootView = (GLRootView) ViewUtils.$$(this, R.id.gl_root_view);
mGalleryProvider.setGLRoot(mGLRootView);
mUploader = new ImageTexture.Uploader(mGLRootView);
int startPage;
if (savedInstanceState == null) {
@@ -253,24 +275,28 @@ public class GalleryActivity extends EhActivity
mGalleryView = new GalleryView(this, new GalleryAdapter(), this,
Settings.getReadingDirection(), Settings.getPageScaling(),
Settings.getStartPosition(), startPage);
glRootView.setContentPane(mGalleryView);
mGLRootView.setContentPane(mGalleryView);
// System UI helper
int systemUiLevel;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
systemUiLevel = SystemUiHelper.LEVEL_IMMERSIVE;
} else {
systemUiLevel = SystemUiHelper.LEVEL_HIDE_STATUS_BAR;
if (Settings.getReadingFullscreen()) {
int systemUiLevel;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
systemUiLevel = SystemUiHelper.LEVEL_IMMERSIVE;
} else {
systemUiLevel = SystemUiHelper.LEVEL_HIDE_STATUS_BAR;
}
mSystemUiHelper = new SystemUiHelper(this, systemUiLevel,
SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES | SystemUiHelper.FLAG_IMMERSIVE_STICKY);
mSystemUiHelper.hide();
mShowSystemUi = false;
}
mSystemUiHelper = new SystemUiHelper(this, systemUiLevel,
SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES | SystemUiHelper.FLAG_IMMERSIVE_STICKY);
mSystemUiHelper.hide();
mShowSystemUi = false;
mMaskView = (ColorView) ViewUtils.$$(this, R.id.mask);
mClock = ViewUtils.$$(this, R.id.clock);
mProgress = (TextView) ViewUtils.$$(this, R.id.progress);
mBattery = ViewUtils.$$(this, R.id.battery);
mClock.setVisibility(Settings.getShowClock() ? View.VISIBLE : View.GONE);
mProgress.setVisibility(Settings.getShowProgress() ? View.VISIBLE : View.GONE);
mBattery.setVisibility(Settings.getShowBattery() ? View.VISIBLE : View.GONE);
mSeekBarPanel = ViewUtils.$$(this, R.id.seek_bar_panel);
@@ -319,6 +345,7 @@ public class GalleryActivity extends EhActivity
@Override
protected void onDestroy() {
super.onDestroy();
mGLRootView = null;
mGalleryView = null;
if (mUploader != null) {
mUploader.clear();
@@ -332,6 +359,7 @@ public class GalleryActivity extends EhActivity
mMaskView = null;
mClock = null;
mProgress = null;
mBattery = null;
mSeekBarPanel = null;
mLeftText = null;
@@ -345,8 +373,8 @@ public class GalleryActivity extends EhActivity
protected void onPause() {
super.onPause();
if (null != mGalleryView) {
mGalleryView.pause();
if (mGLRootView != null) {
mGLRootView.onPause();
}
}
@@ -354,8 +382,8 @@ public class GalleryActivity extends EhActivity
protected void onResume() {
super.onResume();
if (null != mGalleryView) {
mGalleryView.resume();
if (mGLRootView != null) {
mGLRootView.onResume();
}
}
@@ -465,6 +493,18 @@ public class GalleryActivity extends EhActivity
}
}
@SuppressLint("SetTextI18n")
private void updateProgress() {
if (mProgress == null) {
return;
}
if (mSize <= 0 || mCurrentIndex < 0) {
mProgress.setText(null);
} else {
mProgress.setText((mCurrentIndex + 1) + "/" + mSize);
}
}
@SuppressLint("SetTextI18n")
private void updateSlider() {
if (mSeekBar == null || mRightText == null || mLeftText == null || mSize <= 0 || mCurrentIndex < 0) {
@@ -530,20 +570,26 @@ public class GalleryActivity extends EhActivity
}
@Override
public void onPageSucceed(int index, Image image) {
public void onPageSucceed(int index, ImageWrapper image) {
GalleryPageView page = findPageByIndex(index);
if (page != null) {
ImageTexture imageTexture = new ImageTexture(image);
if (mUploader != null) {
mUploader.addTexture(imageTexture);
if (image.obtain()) {
ImageTexture imageTexture = new ImageTexture(image);
if (mUploader != null) {
mUploader.addTexture(imageTexture);
}
page.showImage();
page.setImage(imageTexture);
page.setPage(index + 1);
page.setProgress(GalleryPageView.PROGRESS_GONE);
page.setError(null, null);
} else {
// The image is recycled, request again.
// TODO request loop ?
if (mGalleryProvider != null) {
mGalleryProvider.request(index);
}
}
page.showImage();
page.setImage(imageTexture);
page.setPage(index + 1);
page.setProgress(GalleryPageView.PROGRESS_GONE);
page.setError(null, null);
} else {
image.recycle();
}
}
@@ -717,8 +763,10 @@ public class GalleryActivity extends EhActivity
private final Spinner mStartPosition;
private final SwitchCompat mKeepScreenOn;
private final SwitchCompat mShowClock;
private final SwitchCompat mShowProgress;
private final SwitchCompat mShowBattery;
private final SwitchCompat mVolumePage;
private final SwitchCompat mReadingFullscreen;
private final SwitchCompat mCustomScreenLightness;
private final SeekBar mScreenLightness;
@@ -731,8 +779,10 @@ public class GalleryActivity extends EhActivity
mStartPosition = (Spinner) mView.findViewById(R.id.start_position);
mKeepScreenOn = (SwitchCompat) mView.findViewById(R.id.keep_screen_on);
mShowClock = (SwitchCompat) mView.findViewById(R.id.show_clock);
mShowProgress = (SwitchCompat) mView.findViewById(R.id.show_progress);
mShowBattery = (SwitchCompat) mView.findViewById(R.id.show_battery);
mVolumePage = (SwitchCompat) mView.findViewById(R.id.volume_page);
mReadingFullscreen = (SwitchCompat) mView.findViewById(R.id.reading_fullscreen);
mCustomScreenLightness = (SwitchCompat) mView.findViewById(R.id.custom_screen_lightness);
mScreenLightness = (SeekBar) mView.findViewById(R.id.screen_lightness);
@@ -742,8 +792,10 @@ public class GalleryActivity extends EhActivity
mStartPosition.setSelection(Settings.getStartPosition());
mKeepScreenOn.setChecked(Settings.getKeepScreenOn());
mShowClock.setChecked(Settings.getShowClock());
mShowProgress.setChecked(Settings.getShowProgress());
mShowBattery.setChecked(Settings.getShowBattery());
mVolumePage.setChecked(Settings.getVolumePage());
mReadingFullscreen.setChecked(Settings.getReadingFullscreen());
mCustomScreenLightness.setChecked(Settings.getCustomScreenLightness());
mScreenLightness.setProgress(Settings.getScreenLightness());
mScreenLightness.setEnabled(Settings.getCustomScreenLightness());
@@ -768,19 +820,25 @@ public class GalleryActivity extends EhActivity
int startPosition = ImageView.sanitizeStartPosition(mStartPosition.getSelectedItemPosition());
boolean keepScreenOn = mKeepScreenOn.isChecked();
boolean showClock = mShowClock.isChecked();
boolean showProgress = mShowProgress.isChecked();
boolean showBattery = mShowBattery.isChecked();
boolean volumePage = mVolumePage.isChecked();
boolean readingFullscreen = mReadingFullscreen.isChecked();
boolean customScreenLightness = mCustomScreenLightness.isChecked();
int screenLightness = mScreenLightness.getProgress();
boolean oldReadingFullscreen = Settings.getReadingFullscreen();
Settings.putScreenRotation(screenRotation);
Settings.putReadingDirection(layoutMode);
Settings.putPageScaling(scaleMode);
Settings.putStartPosition(startPosition);
Settings.putKeepScreenOn(keepScreenOn);
Settings.putShowClock(showClock);
Settings.putShowProgress(showProgress);
Settings.putShowBattery(showBattery);
Settings.putVolumePage(volumePage);
Settings.putReadingFullscreen(readingFullscreen);
Settings.putCustomScreenLightness(customScreenLightness);
Settings.putScreenLightness(screenLightness);
@@ -811,6 +869,9 @@ public class GalleryActivity extends EhActivity
if (mClock != null) {
mClock.setVisibility(showClock ? View.VISIBLE : View.GONE);
}
if (mProgress != null) {
mProgress.setVisibility(showProgress ? View.VISIBLE : View.GONE);
}
if (mBattery != null) {
mBattery.setVisibility(showBattery ? View.VISIBLE : View.GONE);
}
@@ -819,6 +880,10 @@ public class GalleryActivity extends EhActivity
// Update slider
mLayoutMode = layoutMode;
updateSlider();
if (oldReadingFullscreen != readingFullscreen) {
recreate();
}
}
}
@@ -953,10 +1018,12 @@ public class GalleryActivity extends EhActivity
case KEY_SIZE:
GalleryActivity.this.mSize = mValue;
updateSlider();
updateProgress();
break;
case KEY_CURRENT_INDEX:
GalleryActivity.this.mCurrentIndex = mValue;
updateSlider();
updateProgress();
break;
case KEY_TAP_MENU_AREA:
onTapMenuArea();
@@ -33,7 +33,7 @@ public class LicenseActivity extends ToolbarActivity {
super.onCreate(savedInstanceState);
mWebView = new WebView(this);
mWebView.loadUrl("file:///android_asset/NOTICE");
mWebView.loadUrl("file:///android_asset/NOTICE.html");
setContentView(mWebView);
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
@@ -30,7 +30,6 @@ import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
@@ -41,6 +40,7 @@ import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.hippo.drawerlayout.DrawerLayout;
import com.hippo.ehviewer.AppConfig;
import com.hippo.ehviewer.Crash;
import com.hippo.ehviewer.R;
@@ -68,6 +68,7 @@ import com.hippo.ehviewer.ui.scene.SelectSiteScene;
import com.hippo.ehviewer.ui.scene.SignInScene;
import com.hippo.ehviewer.ui.scene.WarningScene;
import com.hippo.ehviewer.ui.scene.WebViewSignInScene;
import com.hippo.ehviewer.widget.EhDrawerLayout;
import com.hippo.io.UniFileInputStreamPipe;
import com.hippo.scene.Announcer;
import com.hippo.scene.SceneFragment;
@@ -76,7 +77,6 @@ import com.hippo.unifile.UniFile;
import com.hippo.util.BitmapUtils;
import com.hippo.util.PermissionRequester;
import com.hippo.widget.LoadImageView;
import com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.ViewUtils;
@@ -111,7 +111,7 @@ public final class MainActivity extends StageActivity
Whole life cycle
---------------*/
@Nullable
private SlidingDrawerLayout mDrawerLayout;
private EhDrawerLayout mDrawerLayout;
@Nullable
private NavigationView mNavView;
@Nullable
@@ -340,11 +340,20 @@ public final class MainActivity extends StageActivity
@Override
protected void onUnrecognizedIntent(@Nullable Intent intent) {
if (!handleIntent(intent)) {
boolean handleUrl = false;
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
handleUrl = true;
Toast.makeText(this, R.string.error_cannot_parse_the_url, Toast.LENGTH_SHORT).show();
}
if (0 == getSceneCount()) {
finish();
if (handleUrl) {
finish();
} else {
Bundle args = new Bundle();
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
startScene(processAnnouncer(new Announcer(GalleryListScene.class).setArgs(args)));
}
}
}
}
@@ -359,7 +368,7 @@ public final class MainActivity extends StageActivity
protected void onCreate2(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
mDrawerLayout = (SlidingDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
mNavView = (NavigationView) ViewUtils.$$(this, R.id.nav_view);
mRightDrawer = (FrameLayout) ViewUtils.$$(this, R.id.right_drawer);
View headerLayout = mNavView.getHeaderView(0);
@@ -390,7 +399,8 @@ public final class MainActivity extends StageActivity
private void checkDownloadLocation() {
UniFile uniFile = Settings.getDownloadLocation();
if (null != uniFile && uniFile.ensureDir()) {
// null == uniFile for first start
if (null == uniFile || uniFile.ensureDir()) {
return;
}
new AlertDialog.Builder(this)
@@ -457,9 +467,9 @@ public final class MainActivity extends StageActivity
baseScene.getLayoutInflater2(), mRightDrawer, savedInstanceState);
if (drawerView != null) {
mRightDrawer.addView(drawerView);
mDrawerLayout.setDrawerLockMode(SlidingDrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
} else {
mDrawerLayout.setDrawerLockMode(SlidingDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
}
}
}
@@ -493,6 +503,18 @@ public final class MainActivity extends StageActivity
mDisplayName.setText(displayName);
}
public void addAboveSnackView(View view) {
if (mDrawerLayout != null) {
mDrawerLayout.addAboveSnackView(view);
}
}
public void removeAboveSnackView(View view) {
if (mDrawerLayout != null) {
mDrawerLayout.removeAboveSnackView(view);
}
}
public int getDrawerLockMode(int edgeGravity) {
if (mDrawerLayout != null) {
return mDrawerLayout.getDrawerLockMode(edgeGravity);
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.ui;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import com.hippo.ehviewer.R;
@@ -62,6 +63,17 @@ public class SetSecurityActivity extends ToolbarActivity implements View.OnClick
mPatternView = null;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onClick(View v) {
if (v == mCancel) {
@@ -26,7 +26,7 @@ import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.util.ActivityHelper;
import com.hippo.util.AppHelper;
public class AboutFragment extends PreferenceFragment
implements Preference.OnPreferenceChangeListener,
@@ -72,7 +72,7 @@ public class AboutFragment extends PreferenceFragment
public boolean onPreferenceClick(Preference preference) {
String key = preference.getKey();
if (KEY_AUTHOR.equals(key)) {
ActivityHelper.sendEmail(getActivity(), EhApplication.getDeveloperEmail(),
AppHelper.sendEmail(getActivity(), EhApplication.getDeveloperEmail(),
"About EhViewer", null);
} else if (KEY_DONATE.equals(key)) {
new AlertDialog.Builder(getActivity())
@@ -16,7 +16,6 @@
package com.hippo.ehviewer.ui.fragment;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
@@ -32,10 +31,13 @@ import android.widget.Toast;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.ehviewer.ui.DirPickerActivity;
import com.hippo.unifile.UniFile;
public class DownloadFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
public class DownloadFragment extends PreferenceFragment implements
Preference.OnPreferenceChangeListener,
Preference.OnPreferenceClickListener {
public static final int REQUEST_CODE_PICK_IMAGE_DIR = 0;
public static final int REQUEST_CODE_PICK_IMAGE_DIR_L = 1;
@@ -50,10 +52,15 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.download_settings);
Preference mediaScan = findPreference(Settings.KEY_MEDIA_SCAN);
Preference imageResolution = findPreference(Settings.KEY_IMAGE_RESOLUTION);
mDownloadLocation = findPreference(KEY_DOWNLOAD_LOCATION);
onUpdateDownloadLocation();
mediaScan.setOnPreferenceChangeListener(this);
imageResolution.setOnPreferenceChangeListener(this);
if (mDownloadLocation != null) {
mDownloadLocation.setOnPreferenceClickListener(this);
}
@@ -133,18 +140,18 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void openDirPickerL() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
try {
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
} catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
try {
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
} catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
}
}
}
@Override
@TargetApi(Build.VERSION_CODES.KITKAT)
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_PICK_IMAGE_DIR: {
@@ -161,7 +168,7 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
break;
}
case REQUEST_CODE_PICK_IMAGE_DIR_L: {
if (resultCode == Activity.RESULT_OK) {
if (resultCode == Activity.RESULT_OK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Uri treeUri = data.getData();
getActivity().getContentResolver().takePersistableUriPermission(
treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
@@ -181,4 +188,26 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
}
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (Settings.KEY_MEDIA_SCAN.equals(key)) {
if (newValue instanceof Boolean) {
UniFile downloadLocation = Settings.getDownloadLocation();
if ((Boolean) newValue) {
CommonOperations.removeNoMediaFile(downloadLocation);
} else {
CommonOperations.ensureNoMediaFile(downloadLocation);
}
}
return true;
} else if (Settings.KEY_IMAGE_RESOLUTION.equals(key)) {
if (newValue instanceof String) {
Settings.putImageResolution((String) newValue);
}
return true;
}
return false;
}
}
@@ -34,9 +34,13 @@ public class EhFragment extends PreferenceFragment
Preference gallerySite = findPreference(Settings.KEY_GALLERY_SITE);
Preference listMode = findPreference(Settings.KEY_LIST_MODE);
Preference detailSize = findPreference(Settings.KEY_DETAIL_SIZE);
Preference thumbSize = findPreference(Settings.KEY_THUMB_SIZE);
gallerySite.setOnPreferenceChangeListener(this);
listMode.setOnPreferenceChangeListener(this);
detailSize.setOnPreferenceChangeListener(this);
thumbSize.setOnPreferenceChangeListener(this);
}
@Override
@@ -48,6 +52,10 @@ public class EhFragment extends PreferenceFragment
} else if (Settings.KEY_LIST_MODE.equals(key)) {
getActivity().setResult(Activity.RESULT_OK);
return true;
} else if (Settings.KEY_DETAIL_SIZE.equals(key)) {
getActivity().setResult(Activity.RESULT_OK);
} else if (Settings.KEY_THUMB_SIZE.equals(key)) {
getActivity().setResult(Activity.RESULT_OK);
}
return true;
}
@@ -33,7 +33,7 @@ import android.view.ViewGroup;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.scene.SceneFragment;
import com.hippo.util.ActivityHelper;
import com.hippo.util.AppHelper;
public abstract class BaseScene extends SceneFragment {
@@ -49,6 +49,20 @@ public abstract class BaseScene extends SceneFragment {
}
}
public void addAboveSnackView(View view) {
FragmentActivity activity = getActivity();
if (activity instanceof MainActivity) {
((MainActivity) activity).addAboveSnackView(view);
}
}
public void removeAboveSnackView(View view) {
FragmentActivity activity = getActivity();
if (activity instanceof MainActivity) {
((MainActivity) activity).removeAboveSnackView(view);
}
}
public void setDrawerLockMode(int lockMode, int edgeGravity) {
FragmentActivity activity = getActivity();
if (activity instanceof MainActivity) {
@@ -154,7 +168,7 @@ public abstract class BaseScene extends SceneFragment {
setNavCheckedItem(getNavCheckedItem());
// Hide soft ime
ActivityHelper.hideSoftInput(getActivity());
AppHelper.hideSoftInput(getActivity());
}
public void createThemeContext(@StyleRes int style) {
@@ -198,14 +212,14 @@ public abstract class BaseScene extends SceneFragment {
public void hideSoftInput() {
FragmentActivity activity = getActivity();
if (null != activity) {
ActivityHelper.hideSoftInput(activity);
AppHelper.hideSoftInput(activity);
}
}
public void showSoftInput(@Nullable View view) {
FragmentActivity activity = getActivity();
if (null != activity && null != view) {
ActivityHelper.showSoftInput(activity, view);
AppHelper.showSoftInput(activity, view);
}
}
}
@@ -26,8 +26,8 @@ import com.hippo.ehviewer.Crash;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.rippleold.RippleSalon;
import com.hippo.util.ActivityHelper;
import com.hippo.ripple.Ripple;
import com.hippo.util.AppHelper;
import com.hippo.yorozuya.ViewUtils;
public class CrashScene extends BaseScene implements View.OnClickListener {
@@ -70,8 +70,8 @@ public class CrashScene extends BaseScene implements View.OnClickListener {
mCancel.setOnClickListener(this);
mSend.setOnClickListener(this);
RippleSalon.addRipple(mCancel, true);
RippleSalon.addRipple(mSend, true);
Ripple.addRipple(mCancel, true);
Ripple.addRipple(mSend, true);
return view;
}
@@ -81,7 +81,7 @@ public class CrashScene extends BaseScene implements View.OnClickListener {
MainActivity activity = getActivity2();
if (mSend == v && null != mCrash && null != activity) {
ActivityHelper.sendEmail(activity, EhApplication.getDeveloperEmail(),
AppHelper.sendEmail(activity, EhApplication.getDeveloperEmail(),
"I found a bug in EhViewer !", mCrash);
}
Crash.resetCrashFile();
@@ -17,7 +17,6 @@
package com.hippo.ehviewer.ui.scene;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
@@ -33,9 +32,9 @@ import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.SparseBooleanArray;
@@ -45,6 +44,7 @@ import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
@@ -56,9 +56,12 @@ import com.github.amlcurran.showcaseview.SimpleShowcaseEventListener;
import com.github.amlcurran.showcaseview.targets.PointTarget;
import com.github.amlcurran.showcaseview.targets.ViewTarget;
import com.hippo.app.CheckBoxDialogBuilder;
import com.hippo.conaco.DataContainer;
import com.hippo.conaco.ProgressNotifier;
import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.easyrecyclerview.FastScroller;
import com.hippo.easyrecyclerview.HandlerDrawable;
import com.hippo.easyrecyclerview.MarginItemDecoration;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.EhDB;
import com.hippo.ehviewer.R;
@@ -74,22 +77,28 @@ import com.hippo.ehviewer.spider.SpiderDen;
import com.hippo.ehviewer.ui.GalleryActivity;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.ehviewer.widget.SimpleRatingView;
import com.hippo.rippleold.RippleSalon;
import com.hippo.io.UniFileInputStreamPipe;
import com.hippo.ripple.Ripple;
import com.hippo.scene.Announcer;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.util.ApiHelper;
import com.hippo.util.DrawableManager;
import com.hippo.view.ViewTransition;
import com.hippo.widget.FabLayout;
import com.hippo.widget.LoadImageView;
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.ViewUtils;
import com.hippo.yorozuya.collect.LongList;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -131,7 +140,7 @@ public class DownloadsScene extends ToolbarScene
@Nullable
private DownloadAdapter mAdapter;
@Nullable
private LinearLayoutManager mLayoutManager;
private AutoStaggeredGridLayoutManager mLayoutManager;
private ShowcaseView mShowcaseView;
@@ -278,6 +287,7 @@ public class DownloadsScene extends ToolbarScene
Context context = getContext2();
AssertUtils.assertNotNull(content);
Resources resources = context.getResources();
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_download);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
@@ -286,9 +296,11 @@ public class DownloadsScene extends ToolbarScene
mAdapter = new DownloadAdapter();
mAdapter.setHasStableIds(true);
mRecyclerView.setAdapter(mAdapter);
mLayoutManager = new LinearLayoutManager(context);
mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
mRecyclerView.setDrawSelectorOnTop(true);
mRecyclerView.hasFixedSize();
mRecyclerView.setClipToPadding(false);
@@ -301,9 +313,12 @@ public class DownloadsScene extends ToolbarScene
if (itemAnimator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
}
int paddingH = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_h);
int paddingV = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_v);
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
mRecyclerView.addItemDecoration(decoration);
decoration.applyPaddings(mRecyclerView);
if (mInitPosition >= 0) {
mRecyclerView.scrollToPosition(mInitPosition);
mInitPosition = -1;
@@ -319,6 +334,7 @@ public class DownloadsScene extends ToolbarScene
mFabLayout.setHidePrimaryFab(true);
mFabLayout.setAutoCancel(false);
mFabLayout.setOnClickFabListener(this);
addAboveSnackView(mFabLayout);
updateView();
@@ -328,11 +344,16 @@ public class DownloadsScene extends ToolbarScene
}
private void guide() {
if (Settings.getGuideDownloadThumb()) {
SimpleHandler.getInstance().post(new Runnable() {
if (Settings.getGuideDownloadThumb() && null != mRecyclerView) {
mRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void run() {
guideDownloadThumb();
public void onGlobalLayout() {
if (Settings.getGuideDownloadThumb()) {
guideDownloadThumb();
}
if (null != mRecyclerView) {
ViewUtils.removeOnGlobalLayoutListener(mRecyclerView.getViewTreeObserver(), this);
}
}
});
} else {
@@ -346,7 +367,7 @@ public class DownloadsScene extends ToolbarScene
guideDownloadLabels();
return;
}
int position = mLayoutManager.findFirstCompletelyVisibleItemPosition();
int position = mLayoutManager.findFirstCompletelyVisibleItemPositions(null)[0];
if (position < 0) {
guideDownloadLabels();
return;
@@ -424,9 +445,12 @@ public class DownloadsScene extends ToolbarScene
mRecyclerView.stopScroll();
mRecyclerView = null;
}
if (null != mFabLayout) {
removeAboveSnackView(mFabLayout);
mFabLayout = null;
}
mRecyclerView = null;
mFabLayout = null;
mViewTransition = null;
mAdapter = null;
mLayoutManager = null;
@@ -1049,8 +1073,8 @@ public class DownloadsScene extends ToolbarScene
thumb.setOnClickListener(this);
start.setOnClickListener(this);
stop.setOnClickListener(this);
RippleSalon.addRipple(start, false);
RippleSalon.addRipple(stop, false);
Ripple.addRipple(start, false);
Ripple.addRipple(stop, false);
}
@Override
@@ -1115,14 +1139,23 @@ public class DownloadsScene extends ToolbarScene
return new DownloadHolder(mInflater.inflate(R.layout.item_download, parent, false));
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onBindViewHolder(DownloadHolder holder, int position) {
if (mList == null) {
return;
}
DownloadInfo info = mList.get(position);
holder.thumb.load(EhCacheKeyFactory.getThumbKey(info.gid), info.thumb);
DataContainer container = null;
UniFile dir = SpiderDen.getGalleryDownloadDir(info);
if (dir != null) {
UniFile file = dir.createFile(".thumb");
if (file != null) {
container = new ThumbDataContainer(file);
}
}
holder.thumb.load(EhCacheKeyFactory.getThumbKey(info.gid), info.thumb, container, true);
holder.title.setText(EhUtils.getSuitableTitle(info));
holder.uploader.setText(info.uploader);
holder.rating.setRating(info.rating);
@@ -1135,7 +1168,7 @@ public class DownloadsScene extends ToolbarScene
bindForState(holder, info);
// Update transition name
if (ApiHelper.SUPPORT_TRANSITION) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
long gid = info.gid;
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
}
@@ -1183,4 +1216,45 @@ public class DownloadsScene extends ToolbarScene
}
}
}
private class ThumbDataContainer implements DataContainer {
@NonNull
private final UniFile mFile;
/**
* @param file the thumb file
*/
public ThumbDataContainer(@NonNull UniFile file) {
mFile = file;
}
@Override
public void onUrlMoved(String requestUrl, String responseUrl) {}
@Override
public boolean save(InputStream is, long length, String mediaType, ProgressNotifier notify) {
OutputStream os = null;
try {
os = mFile.openOutputStream();
IOUtils.copy(is, os);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
IOUtils.closeQuietly(os);
}
}
@Override
public InputStreamPipe get() {
return new UniFileInputStreamPipe(mFile);
}
@Override
public void remove() {
mFile.delete();
}
}
}
@@ -16,7 +16,6 @@
package com.hippo.ehviewer.ui.scene;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.v4.app.Fragment;
@@ -27,7 +26,6 @@ import android.view.View;
import com.hippo.ehviewer.R;
import com.hippo.scene.TransitionHelper;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
class EnterGalleryDetailTransaction implements TransitionHelper {
private final View mThumb;
@@ -43,15 +41,17 @@ class EnterGalleryDetailTransaction implements TransitionHelper {
return false;
}
exit.setSharedElementReturnTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
exit.setExitTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
enter.setSharedElementEnterTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
enter.setEnterTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
exit.setSharedElementReturnTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
exit.setExitTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
enter.setSharedElementEnterTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
enter.setEnterTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
}
return true;
}
}
@@ -71,7 +71,8 @@ import com.hippo.ehviewer.ui.annotation.DrawerLifeCircle;
import com.hippo.ehviewer.ui.annotation.ViewLifeCircle;
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
import com.hippo.ehviewer.widget.SearchBar;
import com.hippo.rippleold.RippleSalon;
import com.hippo.refreshlayout.RefreshLayout;
import com.hippo.ripple.Ripple;
import com.hippo.scene.Announcer;
import com.hippo.scene.SceneFragment;
import com.hippo.util.ApiHelper;
@@ -79,7 +80,6 @@ import com.hippo.util.DrawableManager;
import com.hippo.widget.ContentLayout;
import com.hippo.widget.FabLayout;
import com.hippo.widget.SearchBarMover;
import com.hippo.widget.refreshlayout.RefreshLayout;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.ObjectUtils;
@@ -244,7 +244,7 @@ public class FavoritesScene extends BaseScene implements
Context context = getContext2();
AssertUtils.assertNotNull(context);
Resources resources = context.getResources();
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.list_padding_top_search_bar);
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
mHelper = new FavoritesHelper();
mHelper.setEmptyString(resources.getString(R.string.gallery_list_empty_hit));
@@ -252,7 +252,7 @@ public class FavoritesScene extends BaseScene implements
contentLayout.getFastScroller().setOnDragHandlerListener(this);
mAdapter = new FavoritesAdapter(inflater, resources, mRecyclerView, Settings.getListMode());
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
mRecyclerView.setDrawSelectorOnTop(true);
mRecyclerView.hasFixedSize();
mRecyclerView.setClipToPadding(false);
@@ -260,8 +260,6 @@ public class FavoritesScene extends BaseScene implements
mRecyclerView.setOnItemLongClickListener(this);
mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM);
mRecyclerView.setCustomCheckedListener(this);
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop() + paddingTopSB,
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
fastScroller.setPadding(fastScroller.getPaddingLeft(), fastScroller.getPaddingTop() + paddingTopSB,
fastScroller.getPaddingRight(), fastScroller.getPaddingBottom());
@@ -280,6 +278,7 @@ public class FavoritesScene extends BaseScene implements
mFabLayout.setAutoCancel(false);
mFabLayout.setHidePrimaryFab(true);
mFabLayout.setOnClickFabListener(this);
addAboveSnackView(mFabLayout);
// Restore search mode
if (mSearchMode) {
@@ -395,11 +394,14 @@ public class FavoritesScene extends BaseScene implements
mRecyclerView.stopScroll();
mRecyclerView = null;
}
if (null != mFabLayout) {
removeAboveSnackView(mFabLayout);
mFabLayout = null;
}
mAdapter = null;
mSearchBar = null;
mFabLayout = null;
mSearchBarMover = null;
mLeftDrawable = null;
@@ -484,7 +486,7 @@ public class FavoritesScene extends BaseScene implements
LayoutUtils.dp2pix(context, 1));
decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
rv.addItemDecoration(decoration);
rv.setSelector(RippleSalon.generateRippleDrawable(false));
rv.setSelector(Ripple.generateRippleDrawable(context, false));
rv.setClipToPadding(false);
builder.setView(rv).show();
}
@@ -16,7 +16,6 @@
package com.hippo.ehviewer.ui.scene;
import android.annotation.TargetApi;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
@@ -33,12 +32,11 @@ import android.widget.TextView;
import com.hippo.drawable.TriangleDrawable;
import com.hippo.easyrecyclerview.MarginItemDecoration;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.widget.TileThumb;
import com.hippo.util.ApiHelper;
import com.hippo.widget.recyclerview.AutoGridLayoutManager;
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
import java.lang.annotation.Retention;
@@ -58,7 +56,9 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
private final Resources mResources;
private final RecyclerView mRecyclerView;
private final AutoStaggeredGridLayoutManager mLayoutManager;
private RecyclerView.ItemDecoration mGirdDecoration;
private final int mPaddingTopSB;
private MarginItemDecoration mListDecoration;
private MarginItemDecoration mGirdDecoration;
private int mType = TYPE_INVALID;
public GalleryAdapter(@NonNull LayoutInflater inflater, @NonNull Resources resources,
@@ -67,16 +67,20 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
mResources = resources;
mRecyclerView = recyclerView;
mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
mPaddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
mRecyclerView.setAdapter(this);
mRecyclerView.setLayoutManager(mLayoutManager);
int paddingH = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
int paddingV = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
setType(type);
}
private void adjustPaddings() {
RecyclerView recyclerView = mRecyclerView;
recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop() + mPaddingTopSB,
recyclerView.getPaddingRight(), recyclerView.getPaddingBottom());
}
public int getType() {
return mType;
}
@@ -87,27 +91,44 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
}
mType = type;
RecyclerView recyclerView = mRecyclerView;
switch (type) {
default:
case GalleryAdapter.TYPE_LIST: {
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_list_column_width);
int columnWidth = mResources.getDimensionPixelOffset(Settings.getDetailSizeResId());
mLayoutManager.setColumnSize(columnWidth);
mLayoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_MIN_SIZE);
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
if (null != mGirdDecoration) {
mRecyclerView.removeItemDecoration(mGirdDecoration);
recyclerView.removeItemDecoration(mGirdDecoration);
}
if (null == mListDecoration) {
int interval = mResources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
int paddingH = mResources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
int paddingV = mResources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
mListDecoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
}
recyclerView.addItemDecoration(mListDecoration);
mListDecoration.applyPaddings(recyclerView);
adjustPaddings();
notifyDataSetChanged();
break;
}
case GalleryAdapter.TYPE_GRID: {
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_column_width);
int columnWidth = mResources.getDimensionPixelOffset(Settings.getThumbSizeResId());
mLayoutManager.setColumnSize(columnWidth);
mLayoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
if (null == mGirdDecoration) {
mGirdDecoration = new MarginItemDecoration(
mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin) / 2);
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_SUITABLE_SIZE);
if (null != mListDecoration) {
recyclerView.removeItemDecoration(mListDecoration);
}
mRecyclerView.addItemDecoration(mGirdDecoration);
if (null == mGirdDecoration) {
int interval = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_interval);
int paddingH = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin_h);
int paddingV = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin_v);
mGirdDecoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
}
recyclerView.addItemDecoration(mGirdDecoration);
mGirdDecoration.applyPaddings(recyclerView);
adjustPaddings();
notifyDataSetChanged();
break;
}
@@ -138,7 +159,6 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
public abstract GalleryInfo getDataAt(int position);
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void onBindViewHolder(GalleryHolder holder, int position) {
GalleryInfo gi = getDataAt(position);
if (null == gi) {
@@ -170,7 +190,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
int color = EhUtils.getCategoryColor(gi.category);
if (!(drawable instanceof TriangleDrawable)) {
drawable = new TriangleDrawable(color);
category.setBackground(drawable);
category.setBackgroundDrawable(drawable);
} else {
((TriangleDrawable) drawable).setColor(color);
}
@@ -180,7 +200,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
}
// Update transition name
if (ApiHelper.SUPPORT_TRANSITION) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
long gid = gi.gid;
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
}
@@ -64,7 +64,7 @@ import com.hippo.ehviewer.client.data.GalleryComment;
import com.hippo.ehviewer.client.parser.VoteCommentParser;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.reveal.ViewAnimationUtils;
import com.hippo.rippleold.RippleSalon;
import com.hippo.ripple.Ripple;
import com.hippo.scene.SceneFragment;
import com.hippo.text.Html;
import com.hippo.text.URLImageGetter;
@@ -72,15 +72,17 @@ import com.hippo.util.DrawableManager;
import com.hippo.util.ReadableTime;
import com.hippo.util.TextUrl;
import com.hippo.view.ViewTransition;
import com.hippo.widget.FabLayout;
import com.hippo.widget.LinkifyTextView;
import com.hippo.widget.ObservedTextView;
import com.hippo.yorozuya.AnimationUtils;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.SimpleAnimatorListener;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.ViewUtils;
import com.hippo.yorozuya.collect.IntList;
import java.util.ArrayList;
import java.util.List;
@@ -107,6 +109,8 @@ public final class GalleryCommentsScene extends ToolbarScene
@Nullable
private EasyRecyclerView mRecyclerView;
@Nullable
private FabLayout mFabLayout;
@Nullable
private FloatingActionButton mFab;
@Nullable
private View mEditPanel;
@@ -182,12 +186,13 @@ public final class GalleryCommentsScene extends ToolbarScene
mEditPanel = ViewUtils.$$(view, R.id.edit_panel);
mSendImage = (ImageView) ViewUtils.$$(mEditPanel, R.id.send);
mEditText = (EditText) ViewUtils.$$(mEditPanel, R.id.edit_text);
mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);
Context context = getContext2();
AssertUtils.assertNotNull(context);
Resources resources = context.getResources();
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.list_padding_bottom_fab);
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
@@ -202,7 +207,7 @@ public final class GalleryCommentsScene extends ToolbarScene
LayoutUtils.dp2pix(context, 1));
decoration.setShowLastDivider(true);
mRecyclerView.addItemDecoration(decoration);
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setOnItemClickListener(this);
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
@@ -216,6 +221,9 @@ public final class GalleryCommentsScene extends ToolbarScene
mSendImage.setOnClickListener(this);
mFab.setOnClickListener(this);
addAboveSnackView(mEditPanel);
addAboveSnackView(mFabLayout);
mViewTransition = new ViewTransition(mRecyclerView, tip);
updateView(false);
@@ -231,9 +239,16 @@ public final class GalleryCommentsScene extends ToolbarScene
mRecyclerView.stopScroll();
mRecyclerView = null;
}
if (null != mEditPanel) {
removeAboveSnackView(mEditPanel);
mEditPanel = null;
}
if (null != mFabLayout) {
removeAboveSnackView(mFabLayout);
mFabLayout = null;
}
mFab = null;
mEditPanel = null;
mSendImage = null;
mEditText = null;
mAdapter = null;
@@ -325,7 +340,7 @@ public final class GalleryCommentsScene extends ToolbarScene
LayoutUtils.dp2pix(context, 1));
decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
rv.addItemDecoration(decoration);
rv.setSelector(RippleSalon.generateRippleDrawable(false));
rv.setSelector(Ripple.generateRippleDrawable(context, false));
rv.setClipToPadding(false);
builder.setView(rv).show();
}
@@ -400,7 +415,7 @@ public final class GalleryCommentsScene extends ToolbarScene
commentHolder.comment.clearCurrentSpan();
if (span instanceof URLSpan) {
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true, true);
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true);
return true;
}
}
@@ -602,7 +617,7 @@ public final class GalleryCommentsScene extends ToolbarScene
return new CommentHolder(mInflater.inflate(R.layout.item_gallery_comment, parent, false));
}
public CharSequence generateComment(Context context, TextView textView, GalleryComment comment) {
public CharSequence generateComment(Context context, ObservedTextView textView, GalleryComment comment) {
SpannableStringBuilder ssb = Html.fromHtml(comment.comment, new URLImageGetter(textView,
EhApplication.getConaco(context)), null);
@@ -17,7 +17,6 @@
package com.hippo.ehviewer.ui.scene;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.app.DownloadManager;
@@ -61,6 +60,7 @@ import com.hippo.ehviewer.AppConfig;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.EhDB;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.UrlOpener;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.ehviewer.client.EhClient;
@@ -82,20 +82,21 @@ import com.hippo.ehviewer.ui.GalleryActivity;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
import com.hippo.reveal.ViewAnimationUtils;
import com.hippo.rippleold.RippleSalon;
import com.hippo.ripple.Ripple;
import com.hippo.scene.Announcer;
import com.hippo.scene.SceneFragment;
import com.hippo.scene.TransitionHelper;
import com.hippo.text.Html;
import com.hippo.text.URLImageGetter;
import com.hippo.util.ActivityHelper;
import com.hippo.util.ApiHelper;
import com.hippo.util.AppHelper;
import com.hippo.util.DrawableManager;
import com.hippo.util.ExceptionUtils;
import com.hippo.util.ReadableTime;
import com.hippo.view.ViewTransition;
import com.hippo.widget.AutoWrapLayout;
import com.hippo.widget.LoadImageView;
import com.hippo.widget.ObservedTextView;
import com.hippo.widget.ProgressView;
import com.hippo.widget.ProgressiveRatingBar;
import com.hippo.widget.SimpleGridAutoSpanLayout;
@@ -431,9 +432,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mActionGroup = (ViewGroup) ViewUtils.$$(mHeader, R.id.action_card);
mDownload = (TextView) ViewUtils.$$(mActionGroup, R.id.download);
mRead = ViewUtils.$$(mActionGroup, R.id.read);
RippleSalon.addRipple(mOtherActions, false);
RippleSalon.addRipple(mDownload, false);
RippleSalon.addRipple(mRead, false);
Ripple.addRipple(mOtherActions, false);
Ripple.addRipple(mDownload, false);
Ripple.addRipple(mRead, false);
mUploader.setOnClickListener(this);
mCategory.setOnClickListener(this);
mOtherActions.setOnClickListener(this);
@@ -452,7 +453,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mSize = (TextView) ViewUtils.$$(mInfo, R.id.size);
mPosted = (TextView) ViewUtils.$$(mInfo, R.id.posted);
mFavoredTimes = (TextView) ViewUtils.$$(mInfo, R.id.favoredTimes);
RippleSalon.addRipple(mInfo, false);
Ripple.addRipple(mInfo, false);
mInfo.setOnClickListener(this);
mActions = ViewUtils.$$(belowHeader, R.id.actions);
@@ -466,12 +467,12 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mRate = (TextView) ViewUtils.$$(mActions, R.id.rate);
mSimilar = (TextView) ViewUtils.$$(mActions, R.id.similar);
mSearchCover = (TextView) ViewUtils.$$(mActions, R.id.search_cover);
RippleSalon.addRipple(mHeartGroup, false);
RippleSalon.addRipple(mTorrent, false);
RippleSalon.addRipple(mShare, false);
RippleSalon.addRipple(mRate, false);
RippleSalon.addRipple(mSimilar, false);
RippleSalon.addRipple(mSearchCover, false);
Ripple.addRipple(mHeartGroup, false);
Ripple.addRipple(mTorrent, false);
Ripple.addRipple(mShare, false);
Ripple.addRipple(mRate, false);
Ripple.addRipple(mSimilar, false);
Ripple.addRipple(mSearchCover, false);
mHeartGroup.setOnClickListener(this);
mTorrent.setOnClickListener(this);
mShare.setOnClickListener(this);
@@ -485,13 +486,13 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mComments = (LinearLayout) ViewUtils.$$(belowHeader, R.id.comments);
mCommentsText = (TextView) ViewUtils.$$(mComments, R.id.comments_text);
RippleSalon.addRipple(mComments, false);
Ripple.addRipple(mComments, false);
mComments.setOnClickListener(this);
mPreviews = ViewUtils.$$(belowHeader, R.id.previews);
mGridLayout = (SimpleGridAutoSpanLayout) ViewUtils.$$(mPreviews, R.id.grid_layout);
mPreviewText = (TextView) ViewUtils.$$(mPreviews, R.id.preview_text);
RippleSalon.addRipple(mPreviews, false);
Ripple.addRipple(mPreviews, false);
mPreviews.setOnClickListener(this);
mProgress = ViewUtils.$$(mainView, R.id.progress);
@@ -869,7 +870,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
user.setText(comment.user);
TextView time = (TextView) v.findViewById(R.id.time);
time.setText(ReadableTime.getTimeAgo(comment.time));
TextView c = (TextView) v.findViewById(R.id.comment);
ObservedTextView c = (ObservedTextView) v.findViewById(R.id.comment);
c.setMaxLines(5);
c.setText(Html.fromHtml(comment.comment,
new URLImageGetter(c, EhApplication.getConaco(context)), null));
@@ -895,7 +896,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mPreviewText.setText(R.string.more_previews);
}
int columnWidth = resources.getDimensionPixelOffset(R.dimen.preview_grid_column_width);
int columnWidth = resources.getDimensionPixelOffset(Settings.getThumbSizeResId());
mGridLayout.setColumnSize(columnWidth);
mGridLayout.setStrategy(SimpleGridAutoSpanLayout.STRATEGY_SUITABLE_SIZE);
for (int i = 0, size = previewSet.size(); i < size; i++) {
@@ -956,12 +957,12 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
return resources.getString(R.string.rating_text, getRatingText(rating, resources), rating, ratingCount);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setTransitionName() {
long gid = getGid();
if (gid != -1 && ApiHelper.SUPPORT_TRANSITION && mThumb != null &&
mTitle != null && mUploader != null && mCategory != null) {
mTitle != null && mUploader != null && mCategory != null &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mThumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
mTitle.setTransitionName(TransitionNameFactory.getTitleTransitionName(gid));
mUploader.setTransitionName(TransitionNameFactory.getUploaderTransitionName(gid));
@@ -987,7 +988,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
String url = getGalleryDetailUrl(false);
Activity activity = getActivity2();
if (null != url && null != activity) {
UrlOpener.openUrl(activity, url, false, false);
UrlOpener.openUrl(activity, url, false);
}
break;
case R.id.action_refresh:
@@ -1159,7 +1160,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
} else if (mShare == v) {
String url = getGalleryDetailUrl(false);
if (url != null) {
ActivityHelper.share(activity, url);
AppHelper.share(activity, url);
}
} else if (mTorrent == v) {
if (mGalleryDetail != null) {
@@ -1293,7 +1294,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false, true);
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false);
break;
case 1:
addTagFilter(tag);
@@ -1454,7 +1455,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
}
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onTransition(Context context,
FragmentTransaction transaction, Fragment exit, Fragment enter) {
if (!(enter instanceof GalleryListScene) && !(enter instanceof DownloadsScene) &&
@@ -1462,15 +1462,17 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
return false;
}
exit.setSharedElementReturnTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
exit.setExitTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
enter.setSharedElementEnterTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
enter.setEnterTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
exit.setSharedElementReturnTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
exit.setExitTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
enter.setSharedElementEnterTransition(
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
enter.setEnterTransition(
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
}
return true;
}
}
@@ -1486,7 +1488,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
e.printStackTrace();
Context context = getContext2();
if (null != context && null != mTip) {
String error = ExceptionUtils.getReadableString(context, e);
String error = ExceptionUtils.getReadableString(e);
mTip.setText(error);
adjustViewVisibility(STATE_FAILED, true);
}
@@ -1658,7 +1660,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mProgressView.setVisibility(View.GONE);
mErrorText.setVisibility(View.VISIBLE);
mListView.setVisibility(View.GONE);
mErrorText.setText(ExceptionUtils.getReadableString(context, e));
mErrorText.setText(ExceptionUtils.getReadableString(e));
}
}
@@ -36,7 +36,7 @@ import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryDetail;
import com.hippo.rippleold.RippleSalon;
import com.hippo.ripple.Ripple;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.ViewUtils;
@@ -166,7 +166,7 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
LayoutUtils.dp2pix(context, 1));
decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
mRecyclerView.addItemDecoration(decoration);
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
mRecyclerView.setClipToPadding(false);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setOnItemClickListener(this);
@@ -76,16 +76,17 @@ import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.ehviewer.widget.SearchBar;
import com.hippo.ehviewer.widget.SearchLayout;
import com.hippo.rippleold.RippleSalon;
import com.hippo.refreshlayout.RefreshLayout;
import com.hippo.ripple.Ripple;
import com.hippo.scene.Announcer;
import com.hippo.scene.SceneFragment;
import com.hippo.util.ApiHelper;
import com.hippo.util.AppHelper;
import com.hippo.util.DrawableManager;
import com.hippo.view.ViewTransition;
import com.hippo.widget.ContentLayout;
import com.hippo.widget.FabLayout;
import com.hippo.widget.SearchBarMover;
import com.hippo.widget.refreshlayout.RefreshLayout;
import com.hippo.yorozuya.AnimationUtils;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.MathUtils;
@@ -400,8 +401,8 @@ public final class GalleryListScene extends BaseScene
mFabLayout = (FabLayout) ViewUtils.$$(mainLayout, R.id.fab_layout);
mSearchFab = ViewUtils.$$(mainLayout, R.id.search_fab);
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.list_padding_top_search_bar);
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.list_padding_bottom_fab);
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
mViewTransition = new ViewTransition(contentLayout, mSearchLayout);
@@ -412,14 +413,12 @@ public final class GalleryListScene extends BaseScene
mAdapter = new GalleryListAdapter(inflater, resources,
mRecyclerView, Settings.getListMode());
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
mRecyclerView.setDrawSelectorOnTop(true);
mRecyclerView.hasFixedSize();
mRecyclerView.setClipToPadding(false);
mRecyclerView.setOnItemClickListener(this);
mRecyclerView.setOnItemLongClickListener(this);
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop() + paddingTopSB,
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
mRecyclerView.addOnScrollListener(mOnScrollListener);
fastScroller.setPadding(fastScroller.getPaddingLeft(), fastScroller.getPaddingTop() + paddingTopSB,
@@ -444,6 +443,7 @@ public final class GalleryListScene extends BaseScene
mFabLayout.setHidePrimaryFab(false);
mFabLayout.setOnClickFabListener(this);
mFabLayout.setOnExpandListener(this);
addAboveSnackView(mFabLayout);
mActionFabDrawable = new AddDeleteDrawable(context);
mActionFabDrawable.setColor(resources.getColor(R.color.primary_drawable_dark));
@@ -523,11 +523,14 @@ public final class GalleryListScene extends BaseScene
mRecyclerView.stopScroll();
mRecyclerView = null;
}
if (null != mFabLayout) {
removeAboveSnackView(mFabLayout);
mFabLayout = null;
}
mAdapter = null;
mSearchLayout = null;
mSearchBar = null;
mFabLayout = null;
mSearchFab = null;
mViewTransition = null;
mLeftDrawable = null;
@@ -805,6 +808,7 @@ public final class GalleryListScene extends BaseScene
}
builder.setError(null);
mHelper.goTo(goTo);
AppHelper.hideSoftInput(dialog);
dialog.dismiss();
}
});
@@ -38,6 +38,7 @@ import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.easyrecyclerview.MarginItemDecoration;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhClient;
import com.hippo.ehviewer.client.EhRequest;
import com.hippo.ehviewer.client.EhUrl;
@@ -141,15 +142,16 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
mAdapter = new GalleryPreviewAdapter();
mRecyclerView.setAdapter(mAdapter);
int columnWidth = resources.getDimensionPixelOffset(R.dimen.preview_grid_column_width);
int columnWidth = resources.getDimensionPixelOffset(Settings.getThumbSizeResId());
AutoGridLayoutManager layoutManager = new AutoGridLayoutManager(context, columnWidth);
layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
mRecyclerView.setLayoutManager(layoutManager);
int padding = LayoutUtils.dp2pix(context, 4);
mRecyclerView.setPadding(padding, padding, padding, padding);
mRecyclerView.setClipToPadding(false);
mRecyclerView.addItemDecoration(new MarginItemDecoration(padding));
mRecyclerView.setOnItemClickListener(this);
int padding = LayoutUtils.dp2pix(context, 4);
MarginItemDecoration decoration = new MarginItemDecoration(padding, padding, padding, padding, padding);
mRecyclerView.addItemDecoration(decoration);
decoration.applyPaddings(mRecyclerView);
mHelper = new GalleryPreviewHelper();
contentLayout.setHelper(mHelper);
@@ -16,7 +16,6 @@
package com.hippo.ehviewer.ui.scene;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
@@ -25,8 +24,8 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@@ -46,8 +45,10 @@ import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractSwipeableItemView
import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.easyrecyclerview.FastScroller;
import com.hippo.easyrecyclerview.HandlerDrawable;
import com.hippo.easyrecyclerview.MarginItemDecoration;
import com.hippo.ehviewer.EhDB;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
@@ -55,13 +56,14 @@ import com.hippo.ehviewer.dao.HistoryInfo;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.ehviewer.widget.SimpleRatingView;
import com.hippo.rippleold.RippleSalon;
import com.hippo.ripple.Ripple;
import com.hippo.scene.Announcer;
import com.hippo.scene.SceneFragment;
import com.hippo.util.ApiHelper;
import com.hippo.util.DrawableManager;
import com.hippo.view.ViewTransition;
import com.hippo.widget.LoadImageView;
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.ViewUtils;
@@ -119,17 +121,23 @@ public class HistoryScene extends ToolbarScene
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
animator.setSupportsChangeAnimations(false);
mRecyclerView.setItemAnimator(animator);
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
AutoStaggeredGridLayoutManager layoutManager = new AutoStaggeredGridLayoutManager(
0, StaggeredGridLayoutManager.VERTICAL);
layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
layoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
mRecyclerView.setDrawSelectorOnTop(true);
mRecyclerView.hasFixedSize();
mRecyclerView.setClipToPadding(false);
mRecyclerView.setOnItemClickListener(this);
mRecyclerView.setOnItemLongClickListener(this);
int paddingH = resources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
int paddingV = resources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
mRecyclerView.addItemDecoration(decoration);
decoration.applyPaddings(mRecyclerView);
guardManager.attachRecyclerView(mRecyclerView);
swipeManager.attachRecyclerView(mRecyclerView);
@@ -334,7 +342,6 @@ public class HistoryScene extends ToolbarScene
}
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void onBindViewHolder(HistoryHolder holder, int position) {
if (null == mLazyList) {
return;
@@ -355,7 +362,7 @@ public class HistoryScene extends ToolbarScene
holder.simpleLanguage.setText(gi.simpleLanguage);
// Update transition name
if (ApiHelper.SUPPORT_TRANSITION) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
long gid = gi.gid;
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
}
@@ -226,7 +226,7 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
if (null != context && null != mViewTransition && null != mTip) {
// Show tip
mError = ExceptionUtils.getReadableString(context, e);
mError = ExceptionUtils.getReadableString(e);
mViewTransition.showView(1);
mTip.setText(mError);
}
@@ -29,7 +29,6 @@ import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
@@ -43,7 +42,6 @@ import com.hippo.ehviewer.client.parser.ProfileParser;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.scene.Announcer;
import com.hippo.scene.SceneFragment;
import com.hippo.util.ExceptionUtils;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.ViewUtils;
@@ -219,7 +217,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
}
if (mRegister == v) {
UrlOpener.openUrl(activity, EhUrl.URL_REGISTER, false, true);
UrlOpener.openUrl(activity, EhUrl.URL_REGISTER, false);
} else if (mSignIn == v) {
signIn();
} else if (mSignInViaWebView == v) {
@@ -329,12 +327,11 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
new AlertDialog.Builder(context)
.setTitle(R.string.sign_in_failed)
.setMessage(R.string.sign_in_failed_plain)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.get_it, null)
.show();
}
public void onSignInSuccess() {
public void onSignInEnd() {
Context context = getContext2();
if (null == context) {
return;
@@ -349,38 +346,12 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
}
}
public void onSignInFailure(Exception e) {
Context context = getContext2();
if (null == context) {
return;
}
mSigningIn = false;
Toast.makeText(context, ExceptionUtils.getReadableString(context, e),
Toast.LENGTH_SHORT).show();
hideProgress();
whetherToSkip();
}
public void onGetProfileSuccess() {
public void onGetProfileEnd() {
mSigningIn = false;
updateAvatar();
redirectTo();
}
public void onGetProfileFailure(Exception e) {
Context context = getContext2();
if (null == context) {
return;
}
mSigningIn = false;
Toast.makeText(context, ExceptionUtils.getReadableString(context, e),
Toast.LENGTH_SHORT).show();
hideProgress();
whetherToSkip();
}
private class SignInListener extends EhCallback<SignInScene, String> {
public SignInListener(Context context, int stageId, String sceneTag) {
@@ -394,7 +365,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
SignInScene scene = getScene();
if (scene != null) {
scene.onSignInSuccess();
scene.onSignInEnd();
}
}
@@ -405,7 +376,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
SignInScene scene = getScene();
if (scene != null) {
scene.onSignInFailure(e);
scene.onSignInEnd();
}
}
@@ -434,7 +405,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
SignInScene scene = getScene();
if (scene != null) {
scene.onGetProfileSuccess();
scene.onGetProfileEnd();
}
}
@@ -445,7 +416,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
SignInScene scene = getScene();
if (scene != null) {
scene.onGetProfileFailure(e);
scene.onGetProfileEnd();
}
}
@@ -121,7 +121,7 @@ public class WebViewSignInScene extends BaseScene {
}
private void addCookie(Context context, String domain, Cookie cookie) {
EhApplication.getEhCookieStore(context).add(EhCookieStore.newCookie(cookie, domain, true, true));
EhApplication.getEhCookieStore(context).add(EhCookieStore.newCookie(cookie, domain, true, true, true));
}
@Override
@@ -0,0 +1,166 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.animation.ValueAnimator;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import com.hippo.drawerlayout.DrawerLayout;
import com.hippo.ehviewer.R;
import com.hippo.yorozuya.AnimationUtils;
import java.util.ArrayList;
import java.util.List;
@CoordinatorLayout.DefaultBehavior(EhDrawerLayout.Behavior.class)
public class EhDrawerLayout extends DrawerLayout {
private List<View> mAboveSnackViewList;
public EhDrawerLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public EhDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void addAboveSnackView(View view) {
if (null == mAboveSnackViewList) {
mAboveSnackViewList = new ArrayList<>();
}
mAboveSnackViewList.add(view);
}
public void removeAboveSnackView(View view) {
if (null == mAboveSnackViewList) {
return;
}
mAboveSnackViewList.remove(view);
}
public int getAboveSnackViewCount() {
return null == mAboveSnackViewList ? 0 : mAboveSnackViewList.size();
}
@Nullable
public View getAboveSnackViewAt(int index) {
if (null == mAboveSnackViewList || index < 0 || index >= mAboveSnackViewList.size()) {
return null;
} else {
return mAboveSnackViewList.get(index);
}
}
public static class Behavior extends CoordinatorLayout.Behavior<EhDrawerLayout> {
// We only support the FAB <> Snackbar shift movement on Honeycomb and above. This is
// because we can use view translation properties which greatly simplifies the code.
private static final boolean SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
@Override
public boolean layoutDependsOn(CoordinatorLayout parent,
EhDrawerLayout child, View dependency) {
// We're dependent on all SnackbarLayouts (if enabled)
return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, EhDrawerLayout child,
View dependency) {
if (dependency instanceof Snackbar.SnackbarLayout) {
for (int i = 0, n = child.getAboveSnackViewCount(); i < n; i++) {
View view = child.getAboveSnackViewAt(i);
updateChildTranslationForSnackbar(parent, child, view);
}
}
return false;
}
private void updateChildTranslationForSnackbar(CoordinatorLayout parent,
EhDrawerLayout view, final View child) {
final float targetTransY = getChildTranslationYForSnackbar(parent, view);
float childTranslationY = 0.0f;
Object obj = child.getTag(R.id.fab_translation_y);
if (obj instanceof Float) {
childTranslationY = (Float) obj;
}
if (childTranslationY == targetTransY) {
// We're already at (or currently animating to) the target value, return...
return;
}
ValueAnimator fabTranslationYAnimator = null;
obj = child.getTag(R.id.fab_translation_y_animator);
if (obj instanceof ValueAnimator) {
fabTranslationYAnimator = (ValueAnimator) obj;
}
// Make sure that any current animation is cancelled
if (fabTranslationYAnimator != null && fabTranslationYAnimator.isRunning()) {
fabTranslationYAnimator.cancel();
}
final float currentTransY = ViewCompat.getTranslationY(child);
if (child.isShown()
&& Math.abs(currentTransY - targetTransY) > (child.getHeight() * 0.667f)) {
// If the FAB will be travelling by more than 2/3 of it's height, let's animate
// it instead
if (fabTranslationYAnimator == null) {
fabTranslationYAnimator = ValueAnimator.ofFloat();
fabTranslationYAnimator.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
fabTranslationYAnimator.addUpdateListener(
new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
ViewCompat.setTranslationY(child, (Float) animation.getAnimatedValue());
}
});
child.setTag(R.id.fab_translation_y_animator, fabTranslationYAnimator);
}
fabTranslationYAnimator.setFloatValues(currentTransY, targetTransY);
fabTranslationYAnimator.start();
} else {
// Now update the translation Y
ViewCompat.setTranslationY(child, targetTransY);
}
child.setTag(R.id.fab_translation_y, targetTransY);
}
private float getChildTranslationYForSnackbar(CoordinatorLayout parent,
EhDrawerLayout child) {
float minOffset = 0;
final List<View> dependencies = parent.getDependencies(child);
for (int i = 0, z = dependencies.size(); i < z; i++) {
final View view = dependencies.get(i);
if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(child, view)) {
minOffset = Math.min(minOffset,
ViewCompat.getTranslationY(view) - view.getHeight());
}
}
return minOffset;
}
}
}
@@ -19,10 +19,10 @@ package com.hippo.ehviewer.widget;
import android.content.Context;
import android.util.AttributeSet;
import com.hippo.drawerlayout.DrawerLayoutChild;
import com.hippo.widget.DrawerView;
import com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayoutChild;
public class EhDrawerView extends DrawerView implements SlidingDrawerLayoutChild {
public class EhDrawerView extends DrawerView implements DrawerLayoutChild {
private int mFitPaddingTop;
@@ -0,0 +1,84 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.util.AttributeSet;
import com.hippo.drawerlayout.DrawerLayoutChild;
public class EhNavigationView extends NavigationView implements DrawerLayoutChild {
private static final int SCRIM_COLOR = 0x44000000;
private static final boolean DRAW_SCRIM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
private Paint mPaint;
private int mFitPaddingTop;
public EhNavigationView(Context context) {
super(context);
init();
}
public EhNavigationView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public EhNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
if (DRAW_SCRIM) {
setWillNotDraw(false);
}
}
@Override
public void draw(@NonNull Canvas canvas) {
super.draw(canvas);
if (DRAW_SCRIM && mFitPaddingTop > 0) {
if (null == mPaint) {
mPaint = new Paint();
mPaint.setColor(SCRIM_COLOR);
}
canvas.drawRect(0, 0, getWidth(), mFitPaddingTop, mPaint);
}
}
@Override
public void setFitPadding(int top, int bottom) {
mFitPaddingTop = top;
}
@Override
public int getLayoutPaddingTop() {
return 0;
}
@Override
public int getLayoutPaddingBottom() {
return 0;
}
}
@@ -19,10 +19,10 @@ package com.hippo.ehviewer.widget;
import android.content.Context;
import android.util.AttributeSet;
import com.hippo.drawerlayout.DrawerLayoutChild;
import com.hippo.scene.StageLayout;
import com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayoutChild;
public class EhStageLayout extends StageLayout implements SlidingDrawerLayoutChild {
public class EhStageLayout extends StageLayout implements DrawerLayoutChild {
private int mFitPaddingTop;
@@ -16,12 +16,11 @@
package com.hippo.ehviewer.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -60,15 +59,8 @@ public class GalleryGuideView extends ViewGroup implements View.OnClickListener
init(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public GalleryGuideView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
@SuppressWarnings("deprecation")
private void init(Context context) {
mBgColor = context.getResources().getColor(R.color.guide_bg);
mBgColor = ContextCompat.getColor(context, R.color.guide_bg);
mPaint = new Paint();
mPaint.setColor(Color.WHITE);
mPaint.setStyle(Paint.Style.STROKE);
@@ -20,7 +20,7 @@ import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
@@ -69,7 +69,7 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
private int mState = STATE_NORMAL;
private final Path mPath = new Path();
private final Rect mRect = new Rect();
private int mWidth;
private int mHeight;
private int mBaseHeight;
@@ -425,10 +425,9 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
public void draw(@NonNull Canvas canvas) {
if (mInAnimation) {
final int state = canvas.save();
float bottom = MathUtils.lerp(mBaseHeight, mHeight, mProgress);
mPath.rewind();
mPath.addRect(0f, 0f, mWidth, bottom, Path.Direction.CW);
canvas.clipPath(mPath);
int bottom = MathUtils.lerp(mBaseHeight, mHeight, mProgress);
mRect.set(0, 0, mWidth, bottom);
canvas.clipRect(mRect);
super.draw(canvas);
canvas.restoreToCount(state);
} else {
@@ -22,14 +22,14 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import android.util.Log;
import com.hippo.util.SqlUtils;
import com.hippo.yorozuya.Say;
import java.util.LinkedList;
import java.util.List;
public class SearchDatabase {
public final class SearchDatabase {
private static final String TAG = SearchDatabase.class.getSimpleName();
@@ -41,7 +41,7 @@ public class SearchDatabase {
private static final int MAX_HISTORY = 100;
private SQLiteDatabase mDatabase;
private final SQLiteDatabase mDatabase;
private static SearchDatabase sInstance;
@@ -127,11 +127,10 @@ public class SearchDatabase {
}
mDatabase.delete(TABLE_SUGGESTIONS, selection, null);
} catch (RuntimeException e) {
Say.e(TAG, "truncateHistory", e);
Log.e(TAG, "truncateHistory", e);
}
}
/**
* Builds the database. This version has extra support for using the version field
* as a mode flags field, and configures the database columns depending on the mode bits
@@ -18,12 +18,12 @@ package com.hippo.ehviewer.widget;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.EditText;
public class SearchEditText extends EditText {
public class SearchEditText extends AppCompatEditText {
private SearchEditTextListener mListener;
@@ -39,10 +39,11 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.easyrecyclerview.MarginItemDecoration;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.data.ListUrlBuilder;
import com.hippo.ehviewer.client.exception.EhException;
import com.hippo.rippleold.RippleSalon;
import com.hippo.ripple.Ripple;
import com.hippo.widget.RadioGridGroup;
import com.hippo.yorozuya.ViewUtils;
@@ -122,9 +123,13 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
setAdapter(mAdapter);
setHasFixedSize(true);
setClipToPadding(false);
int paddingH = resources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
int paddingV = resources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
setPadding(paddingV, paddingH, paddingV, paddingH);
int interval = resources.getDimensionPixelOffset(R.dimen.search_layout_interval);
int paddingH = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_h);
int paddingV = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_v);
MarginItemDecoration decoration = new MarginItemDecoration(
interval, paddingH, paddingV, paddingH, paddingV);
addItemDecoration(decoration);
decoration.applyPaddings(this);
// Create normal view
View normalView = mInflater.inflate(R.layout.search_normal, null);
@@ -134,7 +139,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
mNormalSearchModeHelp = (ImageView) normalView.findViewById(R.id.normal_search_mode_help);
mEnableAdvanceSwitch = (SwitchCompat) normalView.findViewById(R.id.search_enable_advance);
mNormalSearchModeHelp.setOnClickListener(this);
RippleSalon.addRipple(mNormalSearchModeHelp, false);
Ripple.addRipple(mNormalSearchModeHelp, false);
mEnableAdvanceSwitch.setOnCheckedChangeListener(SearchLayout.this);
mEnableAdvanceSwitch.setSwitchPadding(resources.getDimensionPixelSize(R.dimen.switch_padding));
@@ -24,8 +24,8 @@ import android.opengl.GLUtils;
import android.opengl.Matrix;
import android.util.Log;
import com.hippo.yorozuya.IntArray;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.collect.IntList;
import java.nio.Buffer;
import java.nio.ByteBuffer;
@@ -166,7 +166,7 @@ public class GLES20Canvas implements GLCanvas {
// Keep track of restore state
private float[] mMatrices = new float[INITIAL_RESTORE_STATE_SIZE * MATRIX_SIZE];
private float[] mAlphas = new float[INITIAL_RESTORE_STATE_SIZE];
private IntArray mSaveFlags = new IntArray();
private final IntList mSaveFlags = new IntList();
private int mCurrentAlphaIndex = 0;
private int mCurrentMatrixIndex = 0;
@@ -176,20 +176,20 @@ public class GLES20Canvas implements GLCanvas {
private int mHeight;
// Projection matrix
private float[] mProjectionMatrix = new float[MATRIX_SIZE];
private final float[] mProjectionMatrix = new float[MATRIX_SIZE];
// Screen size for when we aren't bound to a texture
private int mScreenWidth;
private int mScreenHeight;
// GL programs
private int mDrawProgram;
private int mTextureProgram;
private int mOesTextureProgram;
private int mMeshProgram;
private final int mDrawProgram;
private final int mTextureProgram;
private final int mOesTextureProgram;
private final int mMeshProgram;
// GL buffer containing BOX_COORDINATES
private int mBoxCoordinates;
private final int mBoxCoordinates;
// Handle indices -- common
private static final int INDEX_POSITION = 0;
@@ -268,8 +268,8 @@ public class GLES20Canvas implements GLCanvas {
new UniformShaderParameter(ALPHA_UNIFORM), // INDEX_ALPHA
};
private final IntArray mUnboundTextures = new IntArray();
private final IntArray mDeleteBuffers = new IntArray();
private final IntList mUnboundTextures = new IntList();
private final IntList mDeleteBuffers = new IntList();
// Keep track of statistics for debugging
private int mCountDrawMesh = 0;
@@ -279,10 +279,10 @@ public class GLES20Canvas implements GLCanvas {
// Buffer for framebuffer IDs -- we keep track so we can switch the attached
// texture.
private int[] mFrameBuffer = new int[1];
private final int[] mFrameBuffer = new int[1];
// Bound textures.
private ArrayList<RawTexture> mTargetTextures = new ArrayList<RawTexture>();
private final ArrayList<RawTexture> mTargetTextures = new ArrayList<>();
// Temporary variables used within calculations
private final float[] mTempMatrix = new float[32];
@@ -492,7 +492,7 @@ public class GLES20Canvas implements GLCanvas {
@Override
public void restore() {
int restoreFlags = mSaveFlags.removeLast();
int restoreFlags = mSaveFlags.removeAt(mSaveFlags.size() - 1);
boolean restoreAlpha = (restoreFlags & SAVE_FLAG_ALPHA) == SAVE_FLAG_ALPHA;
if (restoreAlpha) {
mCurrentAlphaIndex--;
@@ -869,7 +869,7 @@ public class GLES20Canvas implements GLCanvas {
@Override
public void deleteRecycledResources() {
synchronized (mUnboundTextures) {
IntArray ids = mUnboundTextures;
IntList ids = mUnboundTextures;
if (mUnboundTextures.size() > 0) {
mGLId.glDeleteTextures(null, ids.size(), ids.getInternalArray(), 0);
ids.clear();
@@ -24,9 +24,9 @@ import android.support.annotation.NonNull;
import com.hippo.gl.annotation.RenderThread;
import com.hippo.gl.view.GLRoot;
import com.hippo.image.Image;
import com.hippo.yorozuya.PVLock;
import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.image.ImageWrapper;
import com.hippo.yorozuya.thread.PVLock;
import com.hippo.yorozuya.thread.PriorityThreadFactory;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -66,10 +66,10 @@ public class ImageTexture implements Texture, Animatable {
private static Tile sLargeFreeTileHead = null;
private static final Object sFreeTileLock = new Object();
private final Image mImage;
private final ImageWrapper mImage;
private int mUploadIndex = 0;
private final Tile[] mTiles; // Can be modified in different threads.
// Should be protected by "synchronized."
// Should be protected by "synchronized."
private final int mWidth;
private final int mHeight;
@@ -79,7 +79,8 @@ public class ImageTexture implements Texture, Animatable {
private final AtomicBoolean mFrameDirty = new AtomicBoolean();
private boolean mImageBusy = false;
private final AtomicBoolean mNeedRecycle = new AtomicBoolean();
private final AtomicBoolean mNeedRelease = new AtomicBoolean();
private final AtomicBoolean mReleased = new AtomicBoolean();
private final AtomicReference<Thread> mAnimateThread = new AtomicReference<>();
@@ -142,7 +143,7 @@ public class ImageTexture implements Texture, Animatable {
private int mTileType;
public int offsetX;
public int offsetY;
public Image image;
public ImageWrapper image;
public Tile nextFreeTile;
public int contentWidth;
public int contentHeight;
@@ -240,11 +241,12 @@ public class ImageTexture implements Texture, Animatable {
private class AnimateRunnable implements Runnable {
public void doRun() {
long lastTime = SystemClock.currentThreadTimeMillis();
long lastTime = SystemClock.elapsedRealtime();
long lastDelay = -1L;
synchronized (mImage) {
// Check recycled
if (mImage.isRecycled()) {
// Check released
if (mReleased.get()) {
return;
}
// Check image busy
@@ -252,8 +254,8 @@ public class ImageTexture implements Texture, Animatable {
// Image is busy, means it is recycling
return;
}
if (mNeedRecycle.get()) {
// Need recycle
if (mNeedRelease.get()) {
// Need release
return;
}
// Obtain image
@@ -269,7 +271,7 @@ public class ImageTexture implements Texture, Animatable {
} catch (InterruptedException e) {
interrupted = true;
}
if (!interrupted && !mNeedRecycle.get()) {
if (!interrupted && !mNeedRelease.get()) {
mImage.complete();
}
sPVLock.v();
@@ -283,15 +285,15 @@ public class ImageTexture implements Texture, Animatable {
mImageBusy = false;
}
if (interrupted || mNeedRecycle.get() || frameCount <= 1) {
if (interrupted || mNeedRelease.get() || frameCount <= 1) {
return;
}
while (!Thread.currentThread().isInterrupted()) {
// Obtain
synchronized (mImage) {
// Check recycled
if (mImage.isRecycled()) {
// Check released
if (mReleased.get()) {
return;
}
// Check image busy
@@ -299,8 +301,8 @@ public class ImageTexture implements Texture, Animatable {
// Image is busy, means it is recycling
return;
}
if (mNeedRecycle.get()) {
// Need recycle
if (mNeedRelease.get()) {
// Need release
return;
}
// Obtain image
@@ -309,9 +311,12 @@ public class ImageTexture implements Texture, Animatable {
mImage.advance();
long delay = mImage.getDelay();
long time = System.currentTimeMillis();
delay -= time - lastTime;
long time = SystemClock.elapsedRealtime();
if (-1L != lastDelay) {
delay -= (time - lastTime) - lastDelay;
}
lastTime = time;
lastDelay = delay;
mFrameDirty.lazySet(true);
invalidateSelf();
@@ -334,11 +339,11 @@ public class ImageTexture implements Texture, Animatable {
public void run() {
doRun();
while (mNeedRecycle.get()) {
while (mNeedRelease.get()) {
// Obtain
synchronized (mImage) {
// Check recycled
if (mImage.isRecycled()) {
// Check released
if (mReleased.get()) {
break;
}
// Check image busy
@@ -350,7 +355,8 @@ public class ImageTexture implements Texture, Animatable {
mImageBusy = true;
}
mImage.recycle();
mImage.release();
mReleased.lazySet(true);
synchronized (mImage) {
// Release image
@@ -362,7 +368,7 @@ public class ImageTexture implements Texture, Animatable {
}
}
public ImageTexture(@NonNull Image image) {
public ImageTexture(@NonNull ImageWrapper image) {
mImage = image;
int width = mWidth = image.getWidth();
int height = mHeight = image.getHeight();
@@ -453,7 +459,7 @@ public class ImageTexture implements Texture, Animatable {
@Override
public void start() {
if (mImage.isRecycled() || (mImage.isCompleted() && mImage.getFrameCount() <= 1)) {
if (mReleased.get() || (mImage.isCompleted() && mImage.getFrameCount() <= 1)) {
return;
}
@@ -467,7 +473,7 @@ public class ImageTexture implements Texture, Animatable {
@Override
public void stop() {
if (!mImage.isRecycled() && (mImage.isCompleted() && mImage.getFrameCount() > 1)) {
if (!mReleased.get() && (mImage.isCompleted() && mImage.getFrameCount() > 1)) {
Thread thread = mAnimateThread.getAndSet(null);
if (null != thread) {
thread.interrupt();
@@ -477,7 +483,7 @@ public class ImageTexture implements Texture, Animatable {
@Override
public boolean isRunning() {
return false;
return mAnimateThread.get() != null;
}
@@ -650,24 +656,25 @@ public class ImageTexture implements Texture, Animatable {
mTile.free();
}
boolean recycleNow;
boolean releaseNow;
synchronized (mImage) {
if (!mImageBusy) {
recycleNow = true;
releaseNow = true;
mImageBusy = true;
} else {
recycleNow = false;
releaseNow = false;
}
}
if (recycleNow) {
mImage.recycle();
if (releaseNow) {
mImage.release();
mReleased.set(true);
synchronized (mImage) {
mImageBusy = false;
}
} else {
mNeedRecycle.set(true);
mNeedRelease.set(true);
}
Thread thread = mAnimateThread.getAndSet(null);
@@ -18,7 +18,7 @@ package com.hippo.gl.util;
import android.graphics.Color;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.AssertError;
public class GalleryUtils {
@@ -51,6 +51,8 @@ public class GalleryUtils {
}
public static void assertInRenderThread() {
AssertUtils.assertEquals("Should not do this in render thread", sCurrentThread, Thread.currentThread());
if (sCurrentThread != Thread.currentThread()) {
throw new AssertError("Should not do this in render thread");
}
}
}
@@ -20,7 +20,6 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Parcelable;
import android.os.Process;
@@ -40,6 +39,9 @@ import com.hippo.gl.glrenderer.UploadedTexture;
import com.hippo.gl.util.ApiHelper;
import com.hippo.gl.util.GalleryUtils;
import com.hippo.gl.util.MotionEventHelper;
import com.hippo.tuxiang.BestConfigChooser;
import com.hippo.tuxiang.GLSurfaceView;
import com.hippo.tuxiang.Renderer;
import com.hippo.yorozuya.AssertUtils;
import java.util.ArrayDeque;
@@ -47,12 +49,11 @@ import java.util.ArrayList;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;
// TODO Call attachToRoot and detachFromRoot in render thread
// The root component of all <code>GLView</code>s. The rendering is done in GL
// thread while the event handling is done in the main thread. To synchronize
// the two threads, the entry points of this package need to synchronize on the
@@ -62,7 +63,7 @@ import javax.microedition.khronos.opengles.GL11;
// (2) The public methods of CameraHeadUpDisplay
// (3) The overridden methods in GLRootView.
public class GLRootView extends GLSurfaceView
implements GLSurfaceView.Renderer, GLRoot {
implements Renderer, GLRoot {
private static final String TAG = "GLRootView";
private static final boolean DEBUG_FPS = false;
@@ -315,6 +316,13 @@ public class GLRootView extends GLSurfaceView
mCanvas.setSize(width, height);
}
@Override
public void onSurfaceDestroyed() {
if (mContentView != null && mContentView.isAttachedToRoot()) {
mContentView.detachFromRoot();
}
}
private void outputFps() {
long now = System.nanoTime();
if (mFrameCountingStart == 0) {
@@ -591,10 +599,6 @@ public class GLRootView extends GLSurfaceView
protected void onDetachedFromWindow() {
unfreeze();
super.onDetachedFromWindow();
if (mContentView != null) {
mContentView.detachFromRoot();
}
}
/**
@@ -627,111 +631,4 @@ public class GLRootView extends GLSurfaceView
super.finalize();
}
}
private static abstract class BaseConfigChooser implements EGLConfigChooser {
public BaseConfigChooser(int[] configSpec) {
mConfigSpec = filterConfigSpec(configSpec);
}
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] num_config = new int[1];
if (!egl.eglChooseConfig(display, mConfigSpec, null, 0,
num_config)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
int numConfigs = num_config[0];
if (numConfigs <= 0) {
throw new IllegalArgumentException(
"No configs match configSpec");
}
EGLConfig[] configs = new EGLConfig[numConfigs];
if (!egl.eglChooseConfig(display, mConfigSpec, configs, numConfigs,
num_config)) {
throw new IllegalArgumentException("eglChooseConfig#2 failed");
}
EGLConfig config = chooseConfig(egl, display, configs);
if (config == null) {
throw new IllegalArgumentException("No config chosen");
}
return config;
}
abstract EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs);
protected int[] mConfigSpec;
private int[] filterConfigSpec(int[] configSpec) {
/* We know none of the subclasses define EGL_RENDERABLE_TYPE.
* And we know the configSpec is well formed.
*/
int len = configSpec.length;
int[] newConfigSpec = new int[len + 2];
System.arraycopy(configSpec, 0, newConfigSpec, 0, len-1);
newConfigSpec[len-1] = EGL10.EGL_RENDERABLE_TYPE;
newConfigSpec[len] = 4; // EGL14.EGL_OPENGL_ES2_BIT; /* EGL_OPENGL_ES2_BIT */
newConfigSpec[len+1] = EGL10.EGL_NONE;
return newConfigSpec;
}
}
private static class BestConfigChooser extends BaseConfigChooser {
private final int[] mValue = new int[1];
public BestConfigChooser() {
super(new int[] {
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE, 0,
EGL10.EGL_NONE});
}
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs) {
// Use score to avoid "No config chosen"
int configIndex = 0;
int maxScore = 0;
for (int i = 0, n = configs.length; i < n; i++) {
EGLConfig config = configs[i];
int redSize = findConfigAttrib(egl, display, config,
EGL10.EGL_RED_SIZE, 0);
int greenSize = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
int blueSize = findConfigAttrib(egl, display, config,
EGL10.EGL_BLUE_SIZE, 0);
int alphaSize = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
int sampleBuffers = findConfigAttrib(egl, display, config,
EGL10.EGL_SAMPLE_BUFFERS, 0);
int samples = findConfigAttrib(egl, display, config,
EGL10.EGL_SAMPLES, 0);
int score = redSize + greenSize + blueSize + alphaSize +
sampleBuffers + samples;
if (score > maxScore) {
maxScore = score;
configIndex = i;
}
}
return configs[configIndex];
}
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
EGLConfig config, int attribute, int defaultValue) {
if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
return mValue[0];
}
return defaultValue;
}
}
}
@@ -23,20 +23,20 @@ import com.hippo.gl.glrenderer.GLCanvas;
import com.hippo.gl.glrenderer.MovableTextTexture;
import com.hippo.gl.view.GLView;
import com.hippo.gl.view.Gravity;
import com.hippo.yorozuya.ArrayUtils;
import com.hippo.yorozuya.collect.CollectionUtils;
public class GLMovableTextView extends GLView {
MovableTextTexture mTextTexture;
private String mText = "";
private int[] mIndexes = ArrayUtils.EMPTY_INT_ARRAY;
private int[] mIndexes = CollectionUtils.EMPTY_INT_ARRAY;
private int mGravity = Gravity.NO_GRAVITY;
private void generateIndexes() {
if (mTextTexture == null || TextUtils.isEmpty(mText)) {
mIndexes = ArrayUtils.EMPTY_INT_ARRAY;
mIndexes = CollectionUtils.EMPTY_INT_ARRAY;
} else {
mIndexes = mTextTexture.getTextIndexes(mText);
}
@@ -1,142 +0,0 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.image;
import android.graphics.Bitmap;
import java.io.InputStream;
public class Image {
public static final int FORMAT_JPEG = 0x00;
public static final int FORMAT_PNG = 0x01;
public static final int FORMAT_GIF = 0x02;
private long mNativePtr;
private final int mFormat;
private final int mWidth;
private final int mHeight;
private Image(long nativePtr, int format, int width, int height) {
mNativePtr = nativePtr;
mFormat = format;
mWidth = width;
mHeight = height;
}
public int getFormat() {
return mFormat;
}
public int getWidth() {
return mWidth;
}
public int getHeight() {
return mHeight;
}
private void checkRecycled() {
if (mNativePtr == 0) {
throw new IllegalStateException("The image is recycled.");
}
}
public boolean complete() {
checkRecycled();
return nativeComplete(mNativePtr, mFormat);
}
public boolean isCompleted() {
checkRecycled();
return nativeIsCompleted(mNativePtr, mFormat);
}
public void render(int srcX, int srcY, Bitmap dst, int dstX, int dstY,
int width, int height, boolean fillBlank, int defaultColor) {
checkRecycled();
nativeRender(mNativePtr, mFormat, srcX, srcY, dst, dstX, dstY,
width, height, fillBlank, defaultColor);
}
public void texImage(boolean init, int tileType, int offsetX, int offsetY) {
checkRecycled();
nativeTexImage(mNativePtr, mFormat, init, tileType, offsetX, offsetY);
}
public void advance() {
checkRecycled();
nativeAdvance(mNativePtr, mFormat);
}
public int getDelay() {
checkRecycled();
return nativeGetDelay(mNativePtr, mFormat);
}
public int getFrameCount() {
checkRecycled();
return nativeFrameCount(mNativePtr, mFormat);
}
public boolean isOpaque() {
checkRecycled();
return nativeIsOpaque(mNativePtr, mFormat);
}
public void recycle() {
if (mNativePtr != 0) {
nativeRecycle(mNativePtr, mFormat);
mNativePtr = 0;
}
}
public boolean isRecycled() {
return mNativePtr == 0;
}
public static Image decode(InputStream is, boolean partially) {
return nativeDecode(is, partially);
}
static {
System.loadLibrary("image");
}
private static native Image nativeDecode(InputStream is, boolean partially);
private static native boolean nativeComplete(long nativePtr, int format);
private static native boolean nativeIsCompleted(long nativePtr, int format);
private static native void nativeRender(long nativePtr, int format,
int srcX, int srcY, Bitmap dst, int dstX, int dstY,
int width, int height, boolean fillBlank, int defaultColor);
private static native void nativeTexImage(long nativePtr, int format,
boolean init, int tileType, int offsetX, int offsetY);
private static native void nativeAdvance(long nativePtr, int format);
private static native int nativeGetDelay(long nativePtr, int format);
private static native int nativeFrameCount(long nativePtr, int format);
private static native boolean nativeIsOpaque(long nativePtr, int format);
private static native void nativeRecycle(long nativePtr, int format);
}
@@ -18,8 +18,8 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.InputStreamPipe;
import java.io.File;
import java.io.FileInputStream;
@@ -28,7 +28,7 @@ import java.io.InputStream;
public class FileInputStreamPipe implements InputStreamPipe {
private File mFile;
private final File mFile;
private InputStream mIs;
public FileInputStreamPipe(File file) {
@@ -18,8 +18,8 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.OutputStreamPipe;
import java.io.File;
import java.io.FileOutputStream;
@@ -28,7 +28,7 @@ import java.io.OutputStream;
public class FileOutputStreamPipe implements OutputStreamPipe {
private File mFile;
private final File mFile;
private OutputStream mOs;
public FileOutputStreamPipe(File file) {
@@ -18,16 +18,16 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.InputStreamPipe;
import java.io.IOException;
import java.io.InputStream;
public class UniFileInputStreamPipe implements InputStreamPipe {
private UniFile mFile;
private final UniFile mFile;
private InputStream mIs;
public UniFileInputStreamPipe(UniFile file) {
@@ -18,17 +18,16 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.OutputStreamPipe;
import java.io.IOException;
import java.io.OutputStream;
public class UniFileOutputStreamPipe implements OutputStreamPipe {
private UniFile mUniFile;
private final UniFile mUniFile;
private OutputStream mOs;
public UniFileOutputStreamPipe(UniFile uniFile) {
@@ -16,6 +16,8 @@
package com.hippo.okhttp;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -176,6 +178,35 @@ public class CookieDBStore implements CookieJar {
}
}
private Cookie getInternal(HttpUrl url, String name, List<CookieWithID> cookies) {
for (Iterator<CookieWithID> i = cookies.iterator(); i.hasNext();) {
CookieWithID cwi = i.next();
Cookie cookie = cwi.cookie;
// Check expired
if (hasExpired(cookie)) {
// Remove from list
i.remove();
// Remove from DB
CookieDB.removeCookie(cwi.id);
} else if (cookie.name().equals(name) && cookie.matches(url)) {
return cookie;
}
}
return null;
}
@Nullable
public synchronized Cookie get(HttpUrl url, String name) {
String host = url.host();
for (String key : map.keySet()) {
if (domainMatch(host, key)) {
List<CookieWithID> cookies = map.get(key);
return getInternal(url, name, cookies);
}
}
return null;
}
public synchronized List<Cookie> get(HttpUrl url) {
List<Cookie> result = new ArrayList<>();
@@ -185,6 +216,7 @@ public class CookieDBStore implements CookieJar {
List<CookieWithID> cookies = map.get(key);
// cookies can not be null
getInternal(url, cookies, result);
break;
}
}
@@ -16,11 +16,9 @@
package com.hippo.preference;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Build;
import android.preference.Preference;
import android.util.AttributeSet;
import android.util.Log;
@@ -48,12 +46,6 @@ public class ActivityPreference extends Preference {
init(context, attrs, defStyleAttr, 0);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ActivityPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs, defStyleAttr, defStyleRes);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActivityPreference, defStyleAttr, defStyleRes);
String clazzName = a.getString(R.styleable.ActivityPreference_activity);
Loaded 100 of 458 files, more files were not shown because too many files have changed in this diff. Show more