mirror of
https://github.com/seven332/EhViewer
synced 2026-12-05 21:39:01 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ee2dfc581 | ||
|
|
1c2aff9bbb | ||
|
|
fd5d07b2f2 |
No files matched your search
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
@@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="com.android.toolchain.gcc.1322280913">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.android.toolchain.gcc.1322280913" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="com.android.toolchain.gcc.1322280913" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<folderInfo id="com.android.toolchain.gcc.1322280913.1369823253" name="/" resourcePath="">
|
||||
<toolChain id="com.android.toolchain.gcc.803500692" name="Android GCC" superClass="com.android.toolchain.gcc">
|
||||
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="com.android.targetPlatform.1260474165" isAbstract="false" superClass="com.android.targetPlatform"/>
|
||||
<builder arguments="NDK_DEBUG=0" command="ndk-build" enableCleanBuild="false" id="com.android.builder.2127875218" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Android Builder" superClass="com.android.builder">
|
||||
<outputEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="obj"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="libs"/>
|
||||
</outputEntries>
|
||||
</builder>
|
||||
<tool id="com.android.gcc.compiler.877935514" name="Android GCC Compiler" superClass="com.android.gcc.compiler">
|
||||
<inputType id="com.android.gcc.inputType.68370901" superClass="com.android.gcc.inputType"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="jni"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="EhViewer.null.1834465747" name="EhViewer"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.1322280913;com.android.toolchain.gcc.1322280913.1369823253;com.android.gcc.compiler.877935514;com.android.gcc.inputType.68370901">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.android.AndroidPerProjectProfile"/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||
<configuration configurationName="Default">
|
||||
<resource resourceType="PROJECT" workspacePath="/EhViewer"/>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
||||
</cproject>
|
||||
@@ -0,0 +1,6 @@
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
Generated
+1
@@ -0,0 +1 @@
|
||||
EhViewer
|
||||
Generated
+23
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
||||
Generated
+18
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
|
||||
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/EhViewer.iml" filepath="$PROJECT_DIR$/EhViewer.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<component name="DependencyValidationManager">
|
||||
<state>
|
||||
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>EhViewer</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
-202
@@ -1,202 +0,0 @@
|
||||
|
||||
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.
|
||||
@@ -1,13 +0,0 @@
|
||||
# EhViewer
|
||||
|
||||
这是一个 Android 平台上的 E-Hentai 阅读应用。<br>
|
||||
E-Hentai Application for Android.
|
||||
|
||||
# License
|
||||
|
||||
本项目内容采用 [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) 授权,
|
||||
部分文件采用 [Creative Commons Attribution 3.0 Unported License](http://creativecommons.org/licenses/by/3.0/) 授权([列表](rc/list1)),
|
||||
部分文件可随意使用([列表](rc/list2))。<br>
|
||||
The content of this project itself is licensed under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0),
|
||||
some files are licensed under the [Creative Commons Attribution 3.0 Unported License](http://creativecommons.org/licenses/by/3.0/) ([list](rc/list1)),
|
||||
some files are free to use ([list](rc/list2)).
|
||||
@@ -0,0 +1 @@
|
||||
/build
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="EhViewer" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
|
||||
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
||||
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="svg-android-2.0.6" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="libGoogleAnalyticsServices" level="project" />
|
||||
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion "21.1.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hippo.ehviewer"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 21
|
||||
versionCode 36
|
||||
versionName "0.6.12"
|
||||
}
|
||||
buildTypes {
|
||||
debug {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
release {
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
compile 'com.android.support:recyclerview-v7:21.0.3'
|
||||
compile 'com.github.japgolly.android:svg-android:2.0.6'
|
||||
}
|
||||
Binary file not shown.
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in E:\Android\android-sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
-keep class com.hippo.ehviewer.widget.SearchView {*;}
|
||||
|
||||
-keep class com.hippo.ehviewer.gallery.image.Image {*;}
|
||||
|
||||
-keep class com.hippo.ehviewer.gallery.image.GifImage {*;}
|
||||
|
||||
-keepclassmembers class com.hippo.ehviewer.drawable.MaterialProgressDrawable$Ring {
|
||||
void set*(***);
|
||||
*** get*();
|
||||
}
|
||||
|
||||
-keepclassmembers class * extends com.hippo.ehviewer.windowsanimate.Sprite {
|
||||
void set*(***);
|
||||
*** get*();
|
||||
}
|
||||
|
||||
-keepclassmembers class * extends android.graphics.drawable.Drawable {
|
||||
void set*(***);
|
||||
*** get*();
|
||||
}
|
||||
|
||||
-keepclassmembers class com.hippo.ehviewer.effect.ripple.Ripple {
|
||||
void set*(***);
|
||||
*** get*();
|
||||
}
|
||||
|
||||
-keepclassmembers class com.hippo.ehviewer.effect.ripple.RippleBackground {
|
||||
void set*(***);
|
||||
*** get*();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,9 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hippo.ehviewer"
|
||||
android:versionCode="24"
|
||||
android:versionName="0.6.3" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
android:targetSdkVersion="19" />
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hippo.ehviewer">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
@@ -33,15 +28,17 @@
|
||||
android:allowBackup="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:largeHeap="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:supportsRtl="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.Normal" >
|
||||
android:theme="@style/AppTheme.Normal">
|
||||
|
||||
<activity
|
||||
android:name=".StartActivity"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.NoActionBar.Transparent" >
|
||||
android:theme="@style/AppTheme.NoActionBar.Transparent.Translucent" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
@@ -50,7 +47,7 @@
|
||||
|
||||
<activity
|
||||
android:name=".ui.GalleryListActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="behind"
|
||||
@@ -63,9 +60,18 @@
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.WebViewLoginActivity"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:label="@string/login"
|
||||
android:screenOrientation="behind"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.GalleryDetailActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:screenOrientation="behind"
|
||||
android:windowSoftInputMode="adjustPan|adjustUnspecified|stateHidden" >
|
||||
<intent-filter>
|
||||
@@ -82,32 +88,37 @@
|
||||
|
||||
<activity
|
||||
android:name=".ui.GalleryActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@style/AppTheme.NoActionBar" >
|
||||
android:theme="@style/AppTheme.Dark.NoActionBar" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.SettingsActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:icon="@drawable/ic_action_settings"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:label="@string/preference_settings_title"
|
||||
android:screenOrientation="behind" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.FavouriteActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:icon="@drawable/ic_action_favorite"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:label="@string/favourite"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@style/AppTheme.ListActivity" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.HistoryActivity"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:label="@string/history"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@style/AppTheme.ListActivity" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.DownloadActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:icon="@drawable/ic_setting_download"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:label="@string/download"
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="behind"
|
||||
@@ -117,9 +128,22 @@
|
||||
android:value=".ui.GalleryListActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.SecretActivity"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@style/AppTheme.NoActionBar.Transparent" >
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".service.DownloadService"
|
||||
android:label="DownloadService" />
|
||||
|
||||
<provider
|
||||
android:name=".SimpleSuggestionProvider"
|
||||
android:authorities="com.hippo.ehviewer.SimpleSuggestionProvider"
|
||||
android:exported="false" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
Binary file not shown.
Binary file not shown.
+9
-10
@@ -16,27 +16,26 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import com.google.analytics.tracking.android.MapBuilder;
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
|
||||
import android.content.Context;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Analytics {
|
||||
|
||||
|
||||
private static final String KEY_GALLERY = "gallery";
|
||||
private static final String KEY_OPEN = "open";
|
||||
private static final String KEY_READ = "read";
|
||||
private static final String KEY_DOWNLOAD = "download";
|
||||
private static final String KEY_ADD_TO_FAVORITE = "add_to_favorite";
|
||||
|
||||
|
||||
private static void doGallery(Context context, int gid, String token, String method) {
|
||||
if (!Config.getAllowAnalyics())
|
||||
return;
|
||||
|
||||
|
||||
try {
|
||||
JSONObject js = new JSONObject();
|
||||
js.put("gid", gid).put("token", token);
|
||||
@@ -44,19 +43,19 @@ public class Analytics {
|
||||
easyTracker.send(MapBuilder.createEvent(KEY_GALLERY, method, js.toString(), null).build());
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
|
||||
public static void openGallery(Context context, int gid, String token) {
|
||||
doGallery(context, gid, token, KEY_OPEN);
|
||||
}
|
||||
|
||||
|
||||
public static void readGallery(Context context, int gid, String token) {
|
||||
doGallery(context, gid, token, KEY_READ);
|
||||
}
|
||||
|
||||
|
||||
public static void downloadGallery(Context context, int gid, String token) {
|
||||
doGallery(context, gid, token, KEY_DOWNLOAD);
|
||||
}
|
||||
|
||||
|
||||
public static void addToFavoriteGallery(Context context, int gid, String token) {
|
||||
doGallery(context, gid, token, KEY_ADD_TO_FAVORITE);
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
import com.hippo.ehviewer.cache.ImageCache;
|
||||
import com.hippo.ehviewer.data.Data;
|
||||
import com.hippo.ehviewer.ehclient.EhClient;
|
||||
import com.hippo.ehviewer.ehclient.EhInfo;
|
||||
import com.hippo.ehviewer.ehclient.ExDownloaderManager;
|
||||
import com.hippo.ehviewer.network.HttpHelper;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Crash;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.util.Favorite;
|
||||
import com.hippo.ehviewer.util.Log;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
import com.hippo.ehviewer.widget.MaterialToast;
|
||||
import com.hippo.ehviewer.widget.SlidingDrawerLayout;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
||||
public class AppContext extends Application implements UncaughtExceptionHandler {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = AppContext.class.getSimpleName();
|
||||
|
||||
private Thread.UncaughtExceptionHandler mDefaultHandler;
|
||||
|
||||
private Typeface mFaceTypeface;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
// Do catch error prepare
|
||||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
|
||||
Context mContextThemeWrapper = new ContextThemeWrapper(this, R.style.AppTheme);
|
||||
ViewUtils.initDialogViewInflater(this);
|
||||
|
||||
// Init everything
|
||||
Ui.init(mContextThemeWrapper);
|
||||
Config.init(mContextThemeWrapper);
|
||||
Log.init(mContextThemeWrapper);
|
||||
Crash.init(mContextThemeWrapper);
|
||||
EhClient.createInstance(mContextThemeWrapper);
|
||||
Favorite.init(mContextThemeWrapper);
|
||||
Data.createInstance(mContextThemeWrapper);
|
||||
ExDownloaderManager.createInstance(mContextThemeWrapper);
|
||||
MaterialToast.setContext(mContextThemeWrapper);
|
||||
|
||||
mFaceTypeface = Typeface.createFromAsset(getAssets(),"fonts/face.ttf");
|
||||
|
||||
// Set drawer margin
|
||||
SlidingDrawerLayout.setDefaultMinDrawerMargin(Ui.ACTION_BAR_HEIGHT * 2);
|
||||
|
||||
// Add .nomedia or delete it
|
||||
File nomedia = new File(Config.getDownloadPath(), ".nomedia");
|
||||
if (Config.getMediaScan()) {
|
||||
nomedia.delete();
|
||||
} else {
|
||||
try {
|
||||
new FileOutputStream(nomedia).close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
// Update proxy urls
|
||||
HttpHelper.updateProxyUrls(mContextThemeWrapper);
|
||||
|
||||
String keyVersionCode = "version_code";
|
||||
int oldVersion = Config.getInt(keyVersionCode, Integer.MAX_VALUE);
|
||||
// Fix <=22 login error
|
||||
if (oldVersion <= 22)
|
||||
EhInfo.getInstance(mContextThemeWrapper).logout();
|
||||
|
||||
// Fix <=25 Update
|
||||
if (oldVersion <= 25) {
|
||||
File downloadDir = new File(Config.getDownloadPath());
|
||||
String cachePath = getExternalCacheDir() != null
|
||||
? getExternalCacheDir().getPath()
|
||||
: getCacheDir().getPath();
|
||||
File oldEdInfoDir = new File(cachePath, "ExDownloaderManager");
|
||||
String[] list = downloadDir.list();
|
||||
if (list != null && list.length != 0) {
|
||||
for (String str : list) {
|
||||
int index = str.indexOf('-');
|
||||
if (index == -1)
|
||||
continue;
|
||||
String gid = str.substring(0, index);
|
||||
File gDir = new File(downloadDir, str);
|
||||
// Move download info file
|
||||
File oldInfoFile = new File(oldEdInfoDir, gid);
|
||||
File newInfoFile = new File(gDir, EhUtils.EH_DOWNLOAD_FILENAME);
|
||||
if (!oldInfoFile.exists())
|
||||
continue;
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(newInfoFile);
|
||||
// Add last page
|
||||
byte[] bs = {'0', '0', '0', '0', '0', '0', '0', '0', '\n'};
|
||||
fos.write(bs);
|
||||
Utils.copy(new FileInputStream(oldInfoFile), fos);
|
||||
} catch (Throwable e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Delete old exdownload info dir
|
||||
Utils.deleteDirInThread(oldEdInfoDir);
|
||||
}
|
||||
|
||||
// Update version code
|
||||
try {
|
||||
PackageInfo pi= getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
Config.setInt(keyVersionCode, pi.versionCode);
|
||||
} catch (NameNotFoundException e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
ImageCache.getInstance(this).evictAll();
|
||||
super.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable ex) {
|
||||
if (!handleException(ex) && mDefaultHandler != null) {
|
||||
mDefaultHandler.uncaughtException(thread, ex);
|
||||
}
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private boolean handleException(Throwable ex) {
|
||||
if (ex == null)
|
||||
return false;
|
||||
Crash.saveCrashInfo2File(ex);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Typeface getFaceTypeface() {
|
||||
return mFaceTypeface;
|
||||
}
|
||||
}
|
||||
-5
@@ -25,7 +25,6 @@ import com.hippo.ehviewer.util.Constants;
|
||||
|
||||
public class AppHandler extends Handler {
|
||||
|
||||
public static final int IMAGE_LOADER_TAG = 0x0;
|
||||
public static final int HTTP_HELPER_TAG = 0x1;
|
||||
|
||||
private static Handler sInstance;
|
||||
@@ -43,10 +42,6 @@ public class AppHandler extends Handler {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch(msg.what) {
|
||||
case IMAGE_LOADER_TAG:
|
||||
ImageLoader.LoadTask task = (ImageLoader.LoadTask)msg.obj;
|
||||
task.listener.onGetImage(task.key, task.bitmap);
|
||||
break;
|
||||
|
||||
case HTTP_HELPER_TAG:
|
||||
HttpHelper.Package p = (HttpHelper.Package)msg.obj;
|
||||
+38
-17
@@ -16,19 +16,24 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Message;
|
||||
|
||||
import com.hippo.ehviewer.cache.ImageCache;
|
||||
import com.hippo.ehviewer.network.HttpHelper;
|
||||
import com.hippo.ehviewer.util.BgThread;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
public class ImageLoader {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = ImageLoader.class.getSimpleName();
|
||||
|
||||
public static final int STATE_NONE = 0;
|
||||
public static final int STATE_FROM_MEMORY = 1;
|
||||
public static final int STATE_FROM_DISK = 2;
|
||||
public static final int STATE_FROM_NETWORK = 3;
|
||||
|
||||
private static ImageLoader sInstance;
|
||||
|
||||
class LoadTask {
|
||||
@@ -36,6 +41,7 @@ public class ImageLoader {
|
||||
public String key;
|
||||
public OnGetImageListener listener;
|
||||
public Bitmap bitmap;
|
||||
public int state;
|
||||
|
||||
public LoadTask(String url, String key, OnGetImageListener listener) {
|
||||
this.url = url;
|
||||
@@ -49,16 +55,14 @@ public class ImageLoader {
|
||||
private final ImageCache mImageCache;
|
||||
private final ImageDownloader mImageDownloader;
|
||||
|
||||
public ImageLoader(Context context) {
|
||||
private ImageLoader(Context context) {
|
||||
mLoadTasks = new Stack<LoadTask>();
|
||||
mImageDownloader = new ImageDownloader();
|
||||
|
||||
mContext = context;
|
||||
mImageCache = ImageCache.getInstance(mContext);
|
||||
|
||||
Thread thread = new Thread(new LoadFromCacheTask());
|
||||
thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
|
||||
thread.start();
|
||||
new BgThread(new LoadFromCacheTask()).start();
|
||||
}
|
||||
|
||||
public final static ImageLoader getInstance(final Context context) {
|
||||
@@ -75,6 +79,20 @@ public class ImageLoader {
|
||||
}
|
||||
}
|
||||
|
||||
private class LoadImageCallback implements Runnable {
|
||||
|
||||
private final LoadTask mLoadTask;
|
||||
|
||||
private LoadImageCallback(LoadTask task) {
|
||||
mLoadTask = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mLoadTask.listener.onGetImage(mLoadTask.key, mLoadTask.bitmap, mLoadTask.state);
|
||||
}
|
||||
}
|
||||
|
||||
private class LoadFromCacheTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -90,12 +108,13 @@ public class ImageLoader {
|
||||
loadTask = mLoadTasks.pop();
|
||||
}
|
||||
|
||||
int[] state = new int[1];
|
||||
String key = loadTask.key;
|
||||
loadTask.bitmap = mImageCache.getCachedBitmap(key);
|
||||
loadTask.bitmap = mImageCache.getCachedBitmap(key, state);
|
||||
loadTask.state = state[0];
|
||||
|
||||
if (loadTask.bitmap != null)
|
||||
AppHandler.getInstance().sendMessage(
|
||||
Message.obtain(null, AppHandler.IMAGE_LOADER_TAG, loadTask));
|
||||
AppHandler.getInstance().post(new LoadImageCallback(loadTask));
|
||||
else
|
||||
mImageDownloader.add(loadTask);
|
||||
}
|
||||
@@ -115,9 +134,7 @@ public class ImageLoader {
|
||||
synchronized (mDownloadTasks) {
|
||||
mDownloadTasks.push(loadTask);
|
||||
if (mWorkingThreadNum < MAX_DOWNLOAD_THREADS) {
|
||||
Thread thread = new Thread(new DownloadImageTask());
|
||||
thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
|
||||
thread.start();
|
||||
new BgThread(new DownloadImageTask()).start();
|
||||
mWorkingThreadNum++;
|
||||
}
|
||||
}
|
||||
@@ -140,10 +157,14 @@ public class ImageLoader {
|
||||
|
||||
// TODO use proxy to get image
|
||||
loadTask.bitmap = httpHelper.getImage(loadTask.url);
|
||||
mImageCache.addBitmapToCache(loadTask.key, loadTask.bitmap);
|
||||
if (loadTask.bitmap != null) {
|
||||
mImageCache.addBitmapToCache(loadTask.key, loadTask.bitmap);
|
||||
loadTask.state = STATE_FROM_NETWORK;
|
||||
} else {
|
||||
loadTask.state = STATE_NONE;
|
||||
}
|
||||
|
||||
AppHandler.getInstance().sendMessage(
|
||||
Message.obtain(null, AppHandler.IMAGE_LOADER_TAG, loadTask));
|
||||
AppHandler.getInstance().post(new LoadImageCallback(loadTask));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,6 +176,6 @@ public class ImageLoader {
|
||||
* @param key
|
||||
* @param bmp
|
||||
*/
|
||||
void onGetImage(String key, Bitmap bmp);
|
||||
void onGetImage(String key, Bitmap bmp, int state);
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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;
|
||||
|
||||
import android.content.SearchRecentSuggestionsProvider;
|
||||
|
||||
public class SimpleSuggestionProvider extends SearchRecentSuggestionsProvider {
|
||||
public final static String AUTHORITY = "com.hippo.ehviewer.SimpleSuggestionProvider";
|
||||
public final static int MODE = DATABASE_MODE_QUERIES;
|
||||
|
||||
public SimpleSuggestionProvider() {
|
||||
setupSuggestions(AUTHORITY, MODE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.app.MaterialAlertDialog;
|
||||
import com.hippo.ehviewer.network.Network;
|
||||
import com.hippo.ehviewer.ui.AbsActivity;
|
||||
import com.hippo.ehviewer.ui.GalleryListActivity;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Crash;
|
||||
import com.hippo.ehviewer.util.Secret;
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
import com.larvalabs.svgandroid.SVGBuilder;
|
||||
|
||||
public class StartActivity extends AbsActivity {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = StartActivity.class.getSimpleName();
|
||||
|
||||
private static final int CHECK_WARING = 0;
|
||||
private static final int CHECK_ANALYTICS = 1;
|
||||
private static final int CHECK_NETWORK = 2;
|
||||
private static final int CHECK_CRASH = 3;
|
||||
|
||||
private static final String KEY_ALLOWED = "allowed";
|
||||
private static final String KEY_SET_ANALYTICS = "set_analyics";
|
||||
|
||||
private String lastCrash;
|
||||
private boolean isAnimationOver = false;
|
||||
private boolean isCheckOver = false;
|
||||
|
||||
private MaterialAlertDialog createWarningDialog() {
|
||||
return new MaterialAlertDialog.Builder(this).setCancelable(false)
|
||||
.setTitle(R.string.dailog_waring_title)
|
||||
.setMessage(R.string.dailog_waring_plain)
|
||||
.setPositiveButton(android.R.string.ok)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
switch (which) {
|
||||
case MaterialAlertDialog.POSITIVE:
|
||||
Config.setBoolean(KEY_ALLOWED, true);
|
||||
check(CHECK_ANALYTICS);
|
||||
break;
|
||||
case MaterialAlertDialog.NEGATIVE:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).create();
|
||||
}
|
||||
|
||||
private AlertDialog createAllowAnalyicsDialog() {
|
||||
return new MaterialAlertDialog.Builder(this).setCancelable(false)
|
||||
.setTitle(R.string.dailog_analyics_title)
|
||||
.setMessageAutoLink(Linkify.WEB_URLS)
|
||||
.setMessage(R.string.dailog_analyics_plain)
|
||||
.setPositiveButton(android.R.string.ok)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
switch (which) {
|
||||
case MaterialAlertDialog.POSITIVE:
|
||||
Config.setAllowAnalyics(true);
|
||||
check(CHECK_NETWORK);
|
||||
break;
|
||||
case MaterialAlertDialog.NEGATIVE:
|
||||
Config.setAllowAnalyics(false);
|
||||
check(CHECK_NETWORK);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).create();
|
||||
}
|
||||
|
||||
private AlertDialog createNetworkDialog(int state) {
|
||||
int mesgId;
|
||||
switch (state) {
|
||||
case Network.NETWORK_STATE_MOBILE:
|
||||
mesgId = R.string.dailog_network_mobile_title;
|
||||
break;
|
||||
case Network.NETWORK_STATE_NONE:
|
||||
default:
|
||||
mesgId = R.string.dailog_network_none_title;
|
||||
break;
|
||||
}
|
||||
|
||||
return new MaterialAlertDialog.Builder(this).setCancelable(false)
|
||||
.setTitle(R.string.warning).setMessage(mesgId)
|
||||
.setPositiveButton(android.R.string.ok)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
switch (which) {
|
||||
case MaterialAlertDialog.POSITIVE:
|
||||
check(CHECK_CRASH);
|
||||
break;
|
||||
case MaterialAlertDialog.NEGATIVE:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).create();
|
||||
}
|
||||
|
||||
private AlertDialog createSendCrashDialog() {
|
||||
View view = ViewUtils.inflateDialogView(R.layout.send_crash, false);
|
||||
final EditText et = (EditText) view.findViewById(R.id.description_of_user);
|
||||
return new MaterialAlertDialog.Builder(this).setCancelable(false)
|
||||
.setTitle(R.string.dialog_send_crash_title)
|
||||
.setView(view, true)
|
||||
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
|
||||
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
switch (which) {
|
||||
case MaterialAlertDialog.POSITIVE:
|
||||
// A wait dialog
|
||||
new MaterialAlertDialog.Builder(StartActivity.this)
|
||||
.setCancelable(false)
|
||||
.setTitle(R.string.wait)
|
||||
.setMessage(R.string.dialog_wait_send_crash_msg)
|
||||
.setPositiveButton(android.R.string.ok)
|
||||
.setButtonListener(
|
||||
new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
checkOver();
|
||||
return true;
|
||||
}
|
||||
}).show();
|
||||
Intent i = new Intent(Intent.ACTION_SENDTO);
|
||||
i.setData(Uri.parse("mailto:ehviewersu@gmail.com"));
|
||||
i.putExtra(Intent.EXTRA_SUBJECT, "I found a bug in EhViewer !");
|
||||
i.putExtra(Intent.EXTRA_TEXT, lastCrash + "======== Description ========\n" + et.getText().toString());
|
||||
startActivity(i);
|
||||
lastCrash = null;
|
||||
break;
|
||||
case MaterialAlertDialog.NEGATIVE:
|
||||
lastCrash = null;
|
||||
checkOver();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
// Disable animate
|
||||
overridePendingTransition(0, 0);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.start_activity);
|
||||
|
||||
TextView text = (TextView) findViewById(R.id.text);
|
||||
text.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/GloriaHallelujah.ttf"));
|
||||
ImageView image = (ImageView) findViewById(R.id.image);
|
||||
image.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
image.setImageDrawable(new SVGBuilder().readFromResource(getResources(), R.raw.sad_pandroid).build().getDrawable());
|
||||
|
||||
// Update secret image here
|
||||
int state = Network.getNetworkState(this);
|
||||
if (state == Network.NETWORK_STATE_WIFI) {
|
||||
Secret.updateSecretImage(this);
|
||||
}
|
||||
|
||||
AppHandler.getInstance().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isCheckOver)
|
||||
redirectTo();
|
||||
isAnimationOver = true;
|
||||
}
|
||||
}, 3000);
|
||||
check(CHECK_WARING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Order is 1. check waring 2. check analyics 3. check network 4. check
|
||||
* crash 5. check external storage
|
||||
*
|
||||
* @param order
|
||||
*/
|
||||
private void check(int order) {
|
||||
switch (order) {
|
||||
case CHECK_WARING:
|
||||
if (!Config.getBoolean(KEY_ALLOWED, false)) {
|
||||
createWarningDialog().show();
|
||||
return;
|
||||
}
|
||||
case CHECK_ANALYTICS:
|
||||
if (!Config.getBoolean(KEY_SET_ANALYTICS, false)) {
|
||||
Config.setBoolean(KEY_SET_ANALYTICS, true);
|
||||
createAllowAnalyicsDialog().show();
|
||||
return;
|
||||
}
|
||||
case CHECK_NETWORK:
|
||||
int state = Network.getNetworkState(this);
|
||||
if (state != Network.NETWORK_STATE_WIFI) {
|
||||
createNetworkDialog(state).show();
|
||||
return;
|
||||
}
|
||||
case CHECK_CRASH:
|
||||
if ((lastCrash = Crash.getLastCrash()) != null) {
|
||||
createSendCrashDialog().show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
checkOver();
|
||||
}
|
||||
|
||||
private void checkOver() {
|
||||
if (isAnimationOver)
|
||||
redirectTo();
|
||||
isCheckOver = true;
|
||||
}
|
||||
|
||||
private void redirectTo() {
|
||||
Intent intent = new Intent(this, GalleryListActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -28,10 +28,11 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.net.Uri;
|
||||
import android.os.Process;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.hippo.ehviewer.ehclient.EhClient;
|
||||
import com.hippo.ehviewer.network.HttpHelper;
|
||||
import com.hippo.ehviewer.util.BgThread;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
@@ -42,7 +43,6 @@ public class UpdateHelper implements Runnable {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = "UpdateHelper";
|
||||
|
||||
private static final String UPDATE_API = "http://www.ehviewer.com/API";
|
||||
private static final String HEADER = "Ehviewer-";
|
||||
private static final String FOOTER = ".apk";
|
||||
|
||||
@@ -114,7 +114,7 @@ public class UpdateHelper implements Runnable {
|
||||
|
||||
jo.put("detail", detailJO);
|
||||
|
||||
_package.body = hp.postJson(UPDATE_API, jo);
|
||||
_package.body = hp.postJson(EhClient.API_EHVIEWER, jo);
|
||||
_package.emesg = hp.getEMsg();
|
||||
send(_package);
|
||||
} catch (NameNotFoundException e) {
|
||||
@@ -129,9 +129,7 @@ public class UpdateHelper implements Runnable {
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
Thread thread = new Thread(this);
|
||||
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
thread.start();
|
||||
new BgThread(this).start();
|
||||
}
|
||||
|
||||
private class Respond implements Runnable {
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.app;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
import com.hippo.ehviewer.widget.FileExplorerView;
|
||||
|
||||
public class DirSelectDialog extends MaterialAlertDialog {
|
||||
|
||||
private final FileExplorerView mFileExplorerView;
|
||||
|
||||
protected DirSelectDialog(Builder builder, FileExplorerView fileExplorerView) {
|
||||
super(builder);
|
||||
|
||||
mFileExplorerView = fileExplorerView;
|
||||
}
|
||||
|
||||
public static DirSelectDialog create(Builder builder, String path) {
|
||||
View view = ViewUtils.inflateDialogView(R.layout.dir_selection, builder.mDarkTheme);
|
||||
final FileExplorerView fileExplorerView = (FileExplorerView) view.findViewById(R.id.file_list);
|
||||
final TextView warningTextView = (TextView) view.findViewById(R.id.warning);
|
||||
final TextView pathTextView = (TextView) view.findViewById(R.id.path);
|
||||
|
||||
if (path != null)
|
||||
fileExplorerView.setPath(path);
|
||||
fileExplorerView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
fileExplorerView.onItemClick(parent, view, position, id);
|
||||
pathTextView.setText(fileExplorerView.getCurPath());
|
||||
if (fileExplorerView.canWrite())
|
||||
warningTextView.setVisibility(View.GONE);
|
||||
else
|
||||
warningTextView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
pathTextView.setText(fileExplorerView.getCurPath());
|
||||
if (fileExplorerView.canWrite())
|
||||
warningTextView.setVisibility(View.GONE);
|
||||
else
|
||||
warningTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
builder.setView(view, false,
|
||||
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, Ui.dp2pix(360)));
|
||||
|
||||
return new DirSelectDialog(builder, fileExplorerView);
|
||||
}
|
||||
|
||||
public String getCurrentPath() {
|
||||
return mFileExplorerView.getCurPath();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
mFileExplorerView.refresh();
|
||||
}
|
||||
|
||||
public boolean canWrite() {
|
||||
return mFileExplorerView.canWrite();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,504 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
|
||||
public class MaterialAlertDialog extends AlertDialog implements
|
||||
View.OnClickListener, AdapterView.OnItemClickListener {
|
||||
|
||||
public final static int ACTION = 0x1;
|
||||
public final static int POSITIVE = 0x2;
|
||||
public final static int NEGATIVE = 0x4;
|
||||
public final static int NEUTRAL = 0x8;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private final Builder mBuilder;
|
||||
|
||||
private View mRootView;
|
||||
private TextView mTitle;
|
||||
private Button mActionButton;
|
||||
private Button mPositiveButton;
|
||||
private Button mNegativeButton;
|
||||
private Button mNeutralButton;
|
||||
|
||||
protected MaterialAlertDialog(Builder builder) {
|
||||
super(builder.mContext);
|
||||
mContext = builder.mContext;
|
||||
mBuilder = builder;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private void init() {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mRootView = inflater.inflate(R.layout.alert_dialog_material, null);
|
||||
|
||||
// Check in scroll view or not
|
||||
boolean inScrollView;
|
||||
if (mBuilder.mCustomView != null)
|
||||
inScrollView = mBuilder.mInScrollView;
|
||||
else if (mBuilder.mAdapter != null)
|
||||
inScrollView = false;
|
||||
else
|
||||
inScrollView = true;
|
||||
// Get widget
|
||||
LinearLayout topPanel;
|
||||
TextView message = null;
|
||||
ListView list = null;
|
||||
if (inScrollView) {
|
||||
mRootView.findViewById(R.id.top_panel_noscroll).setVisibility(
|
||||
View.GONE);
|
||||
mTitle = (TextView) mRootView.findViewById(R.id.title);
|
||||
topPanel = (LinearLayout) mRootView.findViewById(R.id.top_panel);
|
||||
message = (TextView) mRootView.findViewById(R.id.message);
|
||||
} else {
|
||||
mRootView.findViewById(R.id.scroll_view).setVisibility(View.GONE);
|
||||
mTitle = (TextView) mRootView.findViewById(R.id.title2);
|
||||
topPanel = (LinearLayout) mRootView
|
||||
.findViewById(R.id.top_panel_noscroll);
|
||||
list = (ListView) mRootView.findViewById(R.id.list);
|
||||
}
|
||||
// Title
|
||||
if (mBuilder.mTitle == null)
|
||||
mTitle.setVisibility(View.GONE);
|
||||
else
|
||||
mTitle.setText(mBuilder.mTitle);
|
||||
// Content
|
||||
if (mBuilder.mCustomView != null) {
|
||||
// CustomView
|
||||
if (message != null)
|
||||
message.setVisibility(View.GONE);
|
||||
if (list != null)
|
||||
list.setVisibility(View.GONE);
|
||||
LinearLayout.LayoutParams lp = mBuilder.mCustomLp;
|
||||
if (lp == null)
|
||||
lp = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
mBuilder.mCustomView.setId(R.id.custom);
|
||||
topPanel.addView(mBuilder.mCustomView, lp);
|
||||
} else if (mBuilder.mAdapter != null) {
|
||||
// List
|
||||
if (message != null)
|
||||
message.setVisibility(View.GONE);
|
||||
list.setAdapter(mBuilder.mAdapter);
|
||||
list.setOnItemClickListener(this);
|
||||
if (mBuilder.mIsSingleChoice) {
|
||||
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
if (mBuilder.mCheckedItem > -1) {
|
||||
list.setItemChecked(mBuilder.mCheckedItem, true);
|
||||
list.setSelection(mBuilder.mCheckedItem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Message
|
||||
if (list != null)
|
||||
list.setVisibility(View.GONE);
|
||||
if (mBuilder.mAutoLinkMask != -1)
|
||||
message.setAutoLinkMask(mBuilder.mAutoLinkMask);
|
||||
message.setText(mBuilder.mMessage);
|
||||
}
|
||||
|
||||
// Buttons
|
||||
View buttonPanel = mRootView.findViewById(R.id.button_panel);
|
||||
View nonActionPanel = mRootView.findViewById(R.id.non_action_panel);
|
||||
mActionButton = (Button) mRootView.findViewById(R.id.button_action);
|
||||
mPositiveButton = (Button) mRootView.findViewById(R.id.button_positive);
|
||||
mNegativeButton = (Button) mRootView.findViewById(R.id.button_negative);
|
||||
mNeutralButton = (Button) mRootView.findViewById(R.id.button_neutral);
|
||||
boolean hasAction = mBuilder.mActionButtonText != null;
|
||||
boolean hasNonAction = mBuilder.mPositiveButtonText != null
|
||||
|| mBuilder.mNegativeButtonText != null
|
||||
|| mBuilder.mNeutralButtonText != null;
|
||||
boolean hasButton = hasAction || hasNonAction;
|
||||
if (hasButton) {
|
||||
if (hasAction) {
|
||||
mActionButton.setText(mBuilder.mActionButtonText);
|
||||
mActionButton.setOnClickListener(this);
|
||||
} else {
|
||||
mActionButton.setVisibility(View.GONE);
|
||||
}
|
||||
if (hasNonAction) {
|
||||
// Positive
|
||||
if (mBuilder.mPositiveButtonText != null) {
|
||||
mPositiveButton.setText(mBuilder.mPositiveButtonText);
|
||||
mPositiveButton.setOnClickListener(this);
|
||||
} else {
|
||||
mPositiveButton.setVisibility(View.GONE);
|
||||
}
|
||||
// Negative
|
||||
if (mBuilder.mNegativeButtonText != null) {
|
||||
mNegativeButton.setText(mBuilder.mNegativeButtonText);
|
||||
mNegativeButton.setOnClickListener(this);
|
||||
} else {
|
||||
mNegativeButton.setVisibility(View.GONE);
|
||||
}
|
||||
// Neutral
|
||||
if (mBuilder.mNeutralButtonText != null) {
|
||||
mNeutralButton.setText(mBuilder.mNeutralButtonText);
|
||||
mNeutralButton.setOnClickListener(this);
|
||||
} else {
|
||||
mNeutralButton.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
nonActionPanel.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
buttonPanel.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
setView(mRootView);
|
||||
|
||||
setCancelable(mBuilder.mCancelable);
|
||||
if (mBuilder.mOnCancelListener != null)
|
||||
setOnCancelListener(mBuilder.mOnCancelListener);
|
||||
if (mBuilder.mOnDismissListener != null)
|
||||
setOnDismissListener(mBuilder.mOnDismissListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
mTitle.setText(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(int resId) {
|
||||
setTitle(getContext().getString(resId));
|
||||
}
|
||||
|
||||
public void setView(View view, boolean inScrollView) {
|
||||
setView(view, inScrollView, new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
|
||||
public void setView(View view, boolean inScrollView,
|
||||
LinearLayout.LayoutParams lp) {
|
||||
mRootView.findViewById(inScrollView ? R.id.top_panel_noscroll : R.id.scroll_view).setVisibility(View.GONE);
|
||||
mRootView.findViewById(inScrollView ? R.id.scroll_view : R.id.top_panel_noscroll).setVisibility(View.VISIBLE);
|
||||
mRootView.findViewById(R.id.message).setVisibility(View.GONE);
|
||||
mRootView.findViewById(R.id.list).setVisibility(View.GONE);
|
||||
LinearLayout topPanel = (LinearLayout) mRootView.findViewById(inScrollView ? R.id.top_panel : R.id.top_panel_noscroll);
|
||||
topPanel.addView(view, lp);
|
||||
// Title
|
||||
TextView oldTitle = mTitle;
|
||||
mTitle = (TextView) mRootView.findViewById(inScrollView ? R.id.title : R.id.title2);
|
||||
if (mTitle != oldTitle && oldTitle != null)
|
||||
mTitle.setText(oldTitle.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean close = true;
|
||||
|
||||
if (mBuilder.mButtonListener != null) {
|
||||
if (v == mActionButton)
|
||||
close = mBuilder.mButtonListener.onClick(this, ACTION);
|
||||
else if (v == mPositiveButton)
|
||||
close = mBuilder.mButtonListener.onClick(this, POSITIVE);
|
||||
else if (v == mNegativeButton)
|
||||
close = mBuilder.mButtonListener.onClick(this, NEGATIVE);
|
||||
else if (v == mNeutralButton)
|
||||
close = mBuilder.mButtonListener.onClick(this, NEUTRAL);
|
||||
}
|
||||
|
||||
if (close)
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
|
||||
boolean close = false;
|
||||
|
||||
if (mBuilder.mOnClickListener != null)
|
||||
close = mBuilder.mOnClickListener.onClick(this, position);
|
||||
|
||||
if (close)
|
||||
dismiss();
|
||||
}
|
||||
|
||||
public static interface OnClickListener {
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
protected Context mContext;
|
||||
|
||||
protected boolean mDarkTheme = false;
|
||||
protected CharSequence mTitle;
|
||||
protected CharSequence mMessage;
|
||||
protected CharSequence mActionButtonText;
|
||||
protected CharSequence mPositiveButtonText;
|
||||
protected CharSequence mNegativeButtonText;
|
||||
protected CharSequence mNeutralButtonText;
|
||||
protected OnClickListener mButtonListener;
|
||||
protected View mCustomView;
|
||||
protected LinearLayout.LayoutParams mCustomLp;
|
||||
protected boolean mInScrollView = true;
|
||||
protected boolean mCancelable = true;
|
||||
protected int mAutoLinkMask = -1;
|
||||
|
||||
protected OnCancelListener mOnCancelListener;
|
||||
|
||||
protected ListAdapter mAdapter;
|
||||
protected OnClickListener mOnClickListener;
|
||||
protected int mCheckedItem;
|
||||
protected boolean mIsSingleChoice;
|
||||
|
||||
protected DialogInterface.OnDismissListener mOnDismissListener;
|
||||
|
||||
public Builder(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public Builder setDrakTheme(boolean darkTheme) {
|
||||
mDarkTheme = darkTheme;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTitle(CharSequence title) {
|
||||
mTitle = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTitle(int resId) {
|
||||
return setTitle(mContext.getString(resId));
|
||||
}
|
||||
|
||||
public Builder setMessage(CharSequence message) {
|
||||
mMessage = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMessage(int resId) {
|
||||
return setMessage(mContext.getString(resId));
|
||||
}
|
||||
|
||||
public Builder setActionButton(CharSequence text) {
|
||||
mActionButtonText = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setActionButton(int resId) {
|
||||
return setActionButton(mContext.getString(resId));
|
||||
}
|
||||
|
||||
public Builder setPositiveButton(CharSequence text) {
|
||||
mPositiveButtonText = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPositiveButton(int resId) {
|
||||
return setPositiveButton(mContext.getString(resId));
|
||||
}
|
||||
|
||||
public Builder setNegativeButton(CharSequence text) {
|
||||
mNegativeButtonText = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setNegativeButton(int resId) {
|
||||
return setNegativeButton(mContext.getString(resId));
|
||||
}
|
||||
|
||||
public Builder setNeutralButton(CharSequence text) {
|
||||
mNeutralButtonText = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setNeutralButton(int resId) {
|
||||
return setNeutralButton(mContext.getString(resId));
|
||||
}
|
||||
|
||||
public Builder setDefaultButton(int b) {
|
||||
if ((b & POSITIVE) == POSITIVE)
|
||||
mPositiveButtonText = mContext.getString(android.R.string.ok);
|
||||
if ((b & NEGATIVE) == NEGATIVE)
|
||||
mNegativeButtonText = mContext.getString(android.R.string.cancel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setButtonListener(OnClickListener l) {
|
||||
mButtonListener = l;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom view id will be R.id.custom
|
||||
*
|
||||
* @param view
|
||||
* @param inScrollView
|
||||
* @return
|
||||
*/
|
||||
public Builder setView(View view, boolean inScrollView) {
|
||||
mCustomView = view;
|
||||
mInScrollView = inScrollView;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom view id will be R.id.custom
|
||||
*
|
||||
* @param view
|
||||
* @param inScrollView
|
||||
* @param lp
|
||||
* @return
|
||||
*/
|
||||
public Builder setView(View view, boolean inScrollView,
|
||||
LinearLayout.LayoutParams lp) {
|
||||
mCustomView = view;
|
||||
mInScrollView = inScrollView;
|
||||
mCustomLp = lp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setView(int resId, boolean inScrollView, ViewHolder vh) {
|
||||
mCustomView = ViewUtils.inflateDialogView(resId, mDarkTheme);
|
||||
mInScrollView = inScrollView;
|
||||
if (vh != null)
|
||||
vh.setView(mCustomView);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCancelable(boolean cancelable) {
|
||||
mCancelable = cancelable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOnCancelListener(OnCancelListener onCancelListener) {
|
||||
mOnCancelListener = onCancelListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMessageAutoLink(int mask) {
|
||||
mAutoLinkMask = mask;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setItems(int itemsId, final OnClickListener listener) {
|
||||
mAdapter = new ArrayAdapter<CharSequence>(
|
||||
mDarkTheme ? ViewUtils.sDarkContextThemeWrapper : ViewUtils.sContextThemeWrapper,
|
||||
R.layout.select_dialog_item, android.R.id.text1, mContext
|
||||
.getResources().getTextArray(itemsId));
|
||||
mOnClickListener = listener;
|
||||
mIsSingleChoice = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setItems(CharSequence[] items,
|
||||
final OnClickListener listener) {
|
||||
mAdapter = new ArrayAdapter<CharSequence>(
|
||||
mDarkTheme ? ViewUtils.sDarkContextThemeWrapper : ViewUtils.sContextThemeWrapper,
|
||||
R.layout.select_dialog_item, android.R.id.text1, items);
|
||||
mOnClickListener = listener;
|
||||
mIsSingleChoice = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAdapter(final ListAdapter adapter,
|
||||
final OnClickListener listener) {
|
||||
mAdapter = adapter;
|
||||
mOnClickListener = listener;
|
||||
mIsSingleChoice = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSingleChoiceItems(int itemsId, int checkedItem,
|
||||
final OnClickListener listener) {
|
||||
mAdapter = new ArrayAdapter<CharSequence>(
|
||||
mDarkTheme ? ViewUtils.sDarkContextThemeWrapper : ViewUtils.sContextThemeWrapper,
|
||||
R.layout.select_dialog_singlechoice, android.R.id.text1,
|
||||
mContext.getResources().getTextArray(itemsId));
|
||||
mOnClickListener = listener;
|
||||
mCheckedItem = checkedItem;
|
||||
mIsSingleChoice = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSingleChoiceItems(CharSequence[] items,
|
||||
int checkedItem, final OnClickListener listener) {
|
||||
mAdapter = new ArrayAdapter<CharSequence>(
|
||||
mDarkTheme ? ViewUtils.sDarkContextThemeWrapper : ViewUtils.sContextThemeWrapper,
|
||||
R.layout.select_dialog_singlechoice, android.R.id.text1,
|
||||
items);
|
||||
mOnClickListener = listener;
|
||||
mCheckedItem = checkedItem;
|
||||
mIsSingleChoice = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSingleChoiceItems(ListAdapter adapter,
|
||||
int checkedItem, final OnClickListener listener) {
|
||||
mAdapter = adapter;
|
||||
mOnClickListener = listener;
|
||||
mCheckedItem = checkedItem;
|
||||
mIsSingleChoice = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOnDismissListener(DialogInterface.OnDismissListener l) {
|
||||
mOnDismissListener = l;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MaterialAlertDialog create() {
|
||||
mContext = new ContextThemeWrapper(mContext, mDarkTheme ?
|
||||
R.style.AppTheme_Dark_Dialog : R.style.AppTheme_Dialog);
|
||||
return new MaterialAlertDialog(this);
|
||||
}
|
||||
|
||||
public MaterialAlertDialog show() {
|
||||
MaterialAlertDialog dialog = create();
|
||||
dialog.show();
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ViewHolder {
|
||||
private View mView;
|
||||
|
||||
private void setView(View v) {
|
||||
mView = v;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mView;
|
||||
}
|
||||
}
|
||||
}
|
||||
+71
-92
@@ -14,12 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
package com.hippo.ehviewer.app;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
@@ -32,53 +31,46 @@ import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ProgressDialogBulider extends DialogBuilder{
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class MaterialProgressDialog extends MaterialAlertDialog {
|
||||
|
||||
|
||||
/** Creates a ProgressDialog with a circular, spinning progress
|
||||
* bar. This is not the default.
|
||||
* bar. This is the default.
|
||||
*/
|
||||
public static final int STYLE_SPINNER = 0;
|
||||
|
||||
|
||||
/** Creates a ProgressDialog with a horizontal progress bar.
|
||||
*/
|
||||
public static final int STYLE_HORIZONTAL = 1;
|
||||
|
||||
|
||||
private ProgressBar mProgress;
|
||||
private TextView mMessageView;
|
||||
|
||||
|
||||
private int mProgressStyle = STYLE_HORIZONTAL;
|
||||
private TextView mProgressNumber;
|
||||
private String mProgressNumberFormat;
|
||||
private TextView mProgressPercent;
|
||||
private NumberFormat mProgressPercentFormat;
|
||||
|
||||
|
||||
private int mMax;
|
||||
private int mProgressVal;
|
||||
private int mSecondaryProgressVal;
|
||||
private int mIncrementBy;
|
||||
private int mIncrementSecondaryBy;
|
||||
private Drawable mProgressDrawable;
|
||||
private Drawable mIndeterminateDrawable;
|
||||
private CharSequence mMessage;
|
||||
private boolean mIndeterminate;
|
||||
|
||||
private boolean mHasStarted = true;
|
||||
|
||||
private boolean mHasStarted;
|
||||
private Handler mViewUpdateHandler;
|
||||
|
||||
private void initFormats() {
|
||||
mProgressNumberFormat = "%1d/%2d";
|
||||
mProgressPercentFormat = NumberFormat.getPercentInstance();
|
||||
mProgressPercentFormat.setMaximumFractionDigits(0);
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
public ProgressDialogBulider(Context context) {
|
||||
super(context);
|
||||
|
||||
|
||||
|
||||
@SuppressLint({ "InflateParams", "HandlerLeak" })
|
||||
protected MaterialProgressDialog(Builder builder) {
|
||||
super(builder);
|
||||
initFormats();
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(builder.mContext);
|
||||
if (mProgressStyle == STYLE_HORIZONTAL) {
|
||||
|
||||
|
||||
/* Use a separate handler to update the text views as they
|
||||
* must be updated on the same thread that created them.
|
||||
*/
|
||||
@@ -86,7 +78,7 @@ public class ProgressDialogBulider extends DialogBuilder{
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
|
||||
|
||||
/* Update the number and percent */
|
||||
int progress = mProgress.getProgress();
|
||||
int max = mProgress.getMax();
|
||||
@@ -118,59 +110,62 @@ public class ProgressDialogBulider extends DialogBuilder{
|
||||
mMessageView = (TextView) view.findViewById(R.id.message);
|
||||
setView(view, false);
|
||||
}
|
||||
if (mMax > 0) {
|
||||
setMax(mMax);
|
||||
}
|
||||
if (mProgressVal > 0) {
|
||||
setProgress(mProgressVal);
|
||||
}
|
||||
if (mSecondaryProgressVal > 0) {
|
||||
setSecondaryProgress(mSecondaryProgressVal);
|
||||
}
|
||||
if (mIncrementBy > 0) {
|
||||
incrementProgressBy(mIncrementBy);
|
||||
}
|
||||
if (mIncrementSecondaryBy > 0) {
|
||||
incrementSecondaryProgressBy(mIncrementSecondaryBy);
|
||||
}
|
||||
if (mProgressDrawable != null) {
|
||||
setProgressDrawable(mProgressDrawable);
|
||||
}
|
||||
if (mIndeterminateDrawable != null) {
|
||||
setIndeterminateDrawable(mIndeterminateDrawable);
|
||||
}
|
||||
if (mMessage != null) {
|
||||
setMessage(mMessage);
|
||||
}
|
||||
setIndeterminate(mIndeterminate);
|
||||
onProgressChanged();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
private void initFormats() {
|
||||
mProgressNumberFormat = "%1d/%2d";
|
||||
mProgressPercentFormat = NumberFormat.getPercentInstance();
|
||||
mProgressPercentFormat.setMaximumFractionDigits(0);
|
||||
}
|
||||
|
||||
|
||||
public static MaterialProgressDialog create(Context context, CharSequence title) {
|
||||
return create(context, title, false, null);
|
||||
}
|
||||
|
||||
public static MaterialProgressDialog create(Context context, CharSequence title,
|
||||
boolean cancelable) {
|
||||
return create(context, title, cancelable, null);
|
||||
}
|
||||
|
||||
public static MaterialProgressDialog create(Context context, CharSequence title,
|
||||
boolean cancelable, OnCancelListener cancelListener) {
|
||||
|
||||
MaterialProgressDialog.Builder builder = new MaterialProgressDialog.Builder(context);
|
||||
builder.setTitle(title);
|
||||
builder.setCancelable(cancelable);
|
||||
builder.setOnCancelListener(cancelListener);
|
||||
return new MaterialProgressDialog(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog create() {
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mHasStarted = true;
|
||||
return super.create();
|
||||
}*/
|
||||
|
||||
public ProgressDialogBulider setProgress(int value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mHasStarted = false;
|
||||
}
|
||||
|
||||
public void setProgress(int value) {
|
||||
if (mHasStarted) {
|
||||
mProgress.setProgress(value);
|
||||
onProgressChanged();
|
||||
} else {
|
||||
mProgressVal = value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProgressDialogBulider setSecondaryProgress(int secondaryProgress) {
|
||||
public void setSecondaryProgress(int secondaryProgress) {
|
||||
if (mProgress != null) {
|
||||
mProgress.setSecondaryProgress(secondaryProgress);
|
||||
onProgressChanged();
|
||||
} else {
|
||||
mSecondaryProgressVal = secondaryProgress;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
@@ -194,22 +189,19 @@ public class ProgressDialogBulider extends DialogBuilder{
|
||||
return mMax;
|
||||
}
|
||||
|
||||
public ProgressDialogBulider setMax(int max) {
|
||||
public void setMax(int max) {
|
||||
if (mProgress != null) {
|
||||
mProgress.setMax(max);
|
||||
onProgressChanged();
|
||||
} else {
|
||||
mMax = max;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void incrementProgressBy(int diff) {
|
||||
if (mProgress != null) {
|
||||
mProgress.incrementProgressBy(diff);
|
||||
onProgressChanged();
|
||||
} else {
|
||||
mIncrementBy += diff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,36 +209,25 @@ public class ProgressDialogBulider extends DialogBuilder{
|
||||
if (mProgress != null) {
|
||||
mProgress.incrementSecondaryProgressBy(diff);
|
||||
onProgressChanged();
|
||||
} else {
|
||||
mIncrementSecondaryBy += diff;
|
||||
}
|
||||
}
|
||||
|
||||
public ProgressDialogBulider setProgressDrawable(Drawable d) {
|
||||
public void setProgressDrawable(Drawable d) {
|
||||
if (mProgress != null) {
|
||||
mProgress.setProgressDrawable(d);
|
||||
} else {
|
||||
mProgressDrawable = d;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProgressDialogBulider setIndeterminateDrawable(Drawable d) {
|
||||
public void setIndeterminateDrawable(Drawable d) {
|
||||
if (mProgress != null) {
|
||||
mProgress.setIndeterminateDrawable(d);
|
||||
} else {
|
||||
mIndeterminateDrawable = d;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProgressDialogBulider setIndeterminate(boolean indeterminate) {
|
||||
public void setIndeterminate(boolean indeterminate) {
|
||||
if (mProgress != null) {
|
||||
mProgress.setIndeterminate(indeterminate);
|
||||
} else {
|
||||
mIndeterminate = indeterminate;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isIndeterminate() {
|
||||
@@ -255,21 +236,18 @@ public class ProgressDialogBulider extends DialogBuilder{
|
||||
}
|
||||
return mIndeterminate;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ProgressDialogBulider setMessage(CharSequence message) {
|
||||
public void setMessage(CharSequence message) {
|
||||
if (mProgress != null) {
|
||||
if (mProgressStyle == STYLE_HORIZONTAL) {
|
||||
super.setMessage(message);
|
||||
} else {
|
||||
mMessageView.setText(message);
|
||||
}
|
||||
} else {
|
||||
mMessage = message;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void setProgressStyle(int style) {
|
||||
mProgressStyle = style;
|
||||
}
|
||||
@@ -299,7 +277,7 @@ public class ProgressDialogBulider extends DialogBuilder{
|
||||
mProgressPercentFormat = format;
|
||||
onProgressChanged();
|
||||
}
|
||||
|
||||
|
||||
private void onProgressChanged() {
|
||||
if (mProgressStyle == STYLE_HORIZONTAL) {
|
||||
if (mViewUpdateHandler != null && !mViewUpdateHandler.hasMessages(0)) {
|
||||
@@ -307,4 +285,5 @@ public class ProgressDialogBulider extends DialogBuilder{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File renamed without changes.
+30
-22
@@ -11,35 +11,31 @@
|
||||
|
||||
package com.hippo.ehviewer.cache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
/**
|
||||
@@ -48,7 +44,7 @@ import com.hippo.ehviewer.util.Utils;
|
||||
public final class ImageCache {
|
||||
|
||||
private static final String TAG = ImageCache.class.getSimpleName();
|
||||
|
||||
|
||||
/**
|
||||
* Default memory cache size as a percent of device memory class
|
||||
*/
|
||||
@@ -90,8 +86,8 @@ public final class ImageCache {
|
||||
* Used to temporarily pause the disk cache while scrolling
|
||||
*/
|
||||
public boolean mPauseDiskAccess = false;
|
||||
private Object mPauseLock = new Object();
|
||||
|
||||
private final Object mPauseLock = new Object();
|
||||
|
||||
/**
|
||||
* Constructor of <code>ImageCache</code>
|
||||
*
|
||||
@@ -383,6 +379,11 @@ public final class ImageCache {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final int STATE_NONE = 0;
|
||||
public static final int STATE_FROM_MEMORY = 1;
|
||||
public static final int STATE_FROM_DISK = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Tries to return a cached image from memory cache before fetching from the
|
||||
* disk cache
|
||||
@@ -390,21 +391,28 @@ public final class ImageCache {
|
||||
* @param data Unique identifier for which item to get
|
||||
* @return The {@link Bitmap} if found in cache, null otherwise
|
||||
*/
|
||||
public final Bitmap getCachedBitmap(final String data) {
|
||||
public final Bitmap getCachedBitmap(final String data, int[] state) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
Bitmap cachedImage = getBitmapFromMemCache(data);
|
||||
if (cachedImage == null) {
|
||||
cachedImage = getBitmapFromDiskCache(data);
|
||||
if (cachedImage != null) {
|
||||
addBitmapToMemCache(data, cachedImage);
|
||||
if (state != null)
|
||||
state[0] = STATE_FROM_DISK;
|
||||
} else {
|
||||
if (state != null)
|
||||
state[0] = STATE_NONE;
|
||||
}
|
||||
} else {
|
||||
if (state != null)
|
||||
state[0] = STATE_FROM_MEMORY;
|
||||
}
|
||||
if (cachedImage != null) {
|
||||
addBitmapToMemCache(data, cachedImage);
|
||||
return cachedImage;
|
||||
}
|
||||
return null;
|
||||
return cachedImage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* flush() is called to synchronize up other methods that are accessing the
|
||||
* cache first
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+5
@@ -98,4 +98,9 @@ public class ApiGalleryDetail extends ApiGalleryInfo
|
||||
public String[] getTags() {
|
||||
return apiTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryInfo toGalleryInfo() {
|
||||
return new GalleryInfo(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
|
||||
public class ApiGalleryInfo extends GalleryInfo{
|
||||
public String archiver_key;
|
||||
public String title_jpn;
|
||||
public String filecount;
|
||||
public long filesize;
|
||||
public boolean expunged;
|
||||
public String torrentcount;
|
||||
public String[] apiTags;
|
||||
|
||||
public static final Parcelable.Creator<ApiGalleryInfo> CREATOR =
|
||||
new Parcelable.Creator<ApiGalleryInfo>() {
|
||||
@Override
|
||||
public ApiGalleryInfo createFromParcel(Parcel source) {
|
||||
ApiGalleryInfo p = new ApiGalleryInfo();
|
||||
p.gid = source.readInt();
|
||||
p.token = source.readString();
|
||||
p.title = source.readString();
|
||||
p.posted = source.readString();
|
||||
p.category = source.readInt();
|
||||
p.thumb = source.readString();
|
||||
p.uploader = source.readString();
|
||||
p.rating = source.readFloat();
|
||||
p.simpleLanguage = source.readString();
|
||||
p.archiver_key = source.readString();
|
||||
p.title_jpn = source.readString();
|
||||
p.filecount = source.readString();
|
||||
p.filesize = source.readLong();
|
||||
p.expunged = Utils.int2boolean(source.readInt());
|
||||
p.torrentcount = source.readString();
|
||||
int apiTagsLength = source.readInt();
|
||||
p.apiTags = new String[apiTagsLength];
|
||||
for (int i = 0; i < apiTagsLength; i++)
|
||||
p.apiTags[i] = source.readString();
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiGalleryInfo[] newArray(int size) {
|
||||
return new ApiGalleryInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(archiver_key);
|
||||
dest.writeString(title_jpn);
|
||||
dest.writeString(filecount);
|
||||
dest.writeLong(filesize);
|
||||
dest.writeInt(Utils.boolean2int(expunged));
|
||||
dest.writeString(torrentcount);
|
||||
dest.writeInt(apiTags.length);
|
||||
for (String str : apiTags)
|
||||
dest.writeString(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File renamed without changes.
+281
-18
@@ -21,26 +21,41 @@ import java.util.List;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.service.DownloadService;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Log;
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
import com.hippo.ehviewer.util.SqlUtils;
|
||||
|
||||
// TODO
|
||||
// what a mess
|
||||
// refactoring
|
||||
|
||||
/**
|
||||
* @author Hippo
|
||||
*
|
||||
* Ver 2: 移除 read 表,添加 Download 表
|
||||
* Ver 3: Download 表添加下载时间项
|
||||
* Ver 4: 添历史记录
|
||||
*/
|
||||
public class Data {
|
||||
private static final String TAG = "Data";
|
||||
|
||||
private static final int VERSION = 2;
|
||||
private static final int VERSION = 4;
|
||||
private static final String DB_NAME = "data";
|
||||
|
||||
private static final String TABLE_GALLERY = "gallery";
|
||||
private static final String TABLE_LOCAL_FAVOURITE = "local_favourite";
|
||||
private static final String TABLE_TAG = "tag";
|
||||
private static final String TABLE_DOWNLOAD = "download";
|
||||
private static final String TABLE_HISTORY = "history";
|
||||
|
||||
private static final String COLUMN_GID = "gid";
|
||||
private static final String COLUMN_TOKEN = "token";
|
||||
@@ -63,6 +78,8 @@ public class Data {
|
||||
private static final String COLUMN_STATE = "state";
|
||||
private static final String COLUMN_LEGACY = "legacy";
|
||||
|
||||
private static final String COLUMN_DATE = "date";
|
||||
|
||||
private final SparseArray<GalleryInfo> mGallerys;
|
||||
|
||||
private long mTagRowNum;
|
||||
@@ -87,11 +104,11 @@ public class Data {
|
||||
|
||||
public Data(Context context) {
|
||||
mContext = context;
|
||||
mGallerys = new SparseArray<GalleryInfo>();
|
||||
|
||||
mDBHelper = new DBHelper(mContext);
|
||||
mDatabase = mDBHelper.getWritableDatabase();
|
||||
|
||||
mGallerys = new SparseArray<GalleryInfo>();
|
||||
|
||||
getTags();
|
||||
getLocalFavourites();
|
||||
getDownloads();
|
||||
@@ -110,10 +127,10 @@ public class Data {
|
||||
* @param gid
|
||||
* @return
|
||||
*/
|
||||
public GalleryInfo getGallery(int gid) {
|
||||
public GalleryInfo getGallery(SQLiteDatabase db, int gid) {
|
||||
GalleryInfo galleryInfo = mGallerys.get(gid);
|
||||
if (galleryInfo == null) {
|
||||
Cursor cursor = mDatabase.rawQuery("select * from " + TABLE_GALLERY + " where " + COLUMN_GID + "=?",
|
||||
Cursor cursor = db.rawQuery("select * from " + TABLE_GALLERY + " where " + COLUMN_GID + "=?",
|
||||
new String[]{String.valueOf(gid)});
|
||||
if (cursor.moveToFirst()) {
|
||||
galleryInfo = new GalleryInfo();
|
||||
@@ -200,7 +217,7 @@ public class Data {
|
||||
values.put(COLUMN_REFERENCE, reference);
|
||||
|
||||
if (isInsert) { // Set
|
||||
long id = mDatabase.insert(TABLE_GALLERY, null, values);
|
||||
mDatabase.insert(TABLE_GALLERY, null, values);
|
||||
} else { // Update
|
||||
mDatabase.update(TABLE_GALLERY, values, COLUMN_GID + "=?", new String[]{String.valueOf(gid)});
|
||||
}
|
||||
@@ -253,15 +270,18 @@ public class Data {
|
||||
|
||||
/****** download ******/
|
||||
private synchronized void getDownloads() {
|
||||
boolean startService = false;
|
||||
boolean keepDownloadService = Config.getKeepDownloadService();
|
||||
mDownloads = new ArrayList<DownloadInfo>();
|
||||
|
||||
Cursor cursor = mDatabase.rawQuery("select * from "
|
||||
+ TABLE_DOWNLOAD, null);
|
||||
Cursor cursor = mDatabase.rawQuery("select * from " + TABLE_DOWNLOAD
|
||||
+ " order by " + COLUMN_DATE + " asc", null);
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
while (!cursor.isAfterLast()) {
|
||||
|
||||
int gid = cursor.getInt(0);
|
||||
GalleryInfo galleryInfo = getGallery(gid);
|
||||
GalleryInfo galleryInfo = getGallery(mDatabase, gid);
|
||||
if (galleryInfo == null) {
|
||||
cursor.moveToNext();
|
||||
continue;
|
||||
@@ -269,8 +289,14 @@ public class Data {
|
||||
int mode = cursor.getInt(1);
|
||||
int state = cursor.getInt(2);
|
||||
int legacy = cursor.getInt(3);
|
||||
if (state == DownloadInfo.STATE_WAIT || state == DownloadInfo.STATE_DOWNLOAD)
|
||||
state = DownloadInfo.STATE_NONE;
|
||||
if (state == DownloadInfo.STATE_WAIT || state == DownloadInfo.STATE_DOWNLOAD) {
|
||||
if (keepDownloadService) {
|
||||
state = DownloadInfo.STATE_WAIT;
|
||||
startService = true;
|
||||
} else {
|
||||
state = DownloadInfo.STATE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
DownloadInfo downloadInfo = new DownloadInfo(
|
||||
galleryInfo, mode, state, legacy);
|
||||
@@ -280,6 +306,11 @@ public class Data {
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
if (startService) {
|
||||
Intent it = new Intent(mContext, DownloadService.class);
|
||||
mContext.startService(it);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,6 +342,12 @@ public class Data {
|
||||
return re;
|
||||
}
|
||||
|
||||
/**
|
||||
* If exits, just update
|
||||
*
|
||||
* @param downloadInfo
|
||||
* @return
|
||||
*/
|
||||
public synchronized boolean addDownload(DownloadInfo downloadInfo) {
|
||||
GalleryInfo galleryInfo = downloadInfo.galleryInfo;
|
||||
int gid = galleryInfo.gid;
|
||||
@@ -335,6 +372,9 @@ public class Data {
|
||||
COLUMN_GID + "=?", new String[]{String.valueOf(galleryInfo.gid)});
|
||||
return false;
|
||||
} else {
|
||||
// If not update, set date
|
||||
values.put(COLUMN_DATE, System.currentTimeMillis());
|
||||
|
||||
if (mDatabase.insert(TABLE_DOWNLOAD, null,
|
||||
values) != -1) { // If add ok
|
||||
mDownloads.add(downloadInfo);
|
||||
@@ -386,6 +426,48 @@ public class Data {
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized void setDownloadState(int gid, int state) {
|
||||
setDownloadState(getDownload(gid), state);
|
||||
}
|
||||
|
||||
public synchronized void setDownloadState(DownloadInfo di, int state) {
|
||||
if (di == null || di.state == state)
|
||||
return;
|
||||
|
||||
di.state = state;
|
||||
// Update in db
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_STATE, state);
|
||||
mDatabase.update(TABLE_DOWNLOAD, values,
|
||||
COLUMN_GID + "=?", new String[]{String.valueOf(di.galleryInfo.gid)});
|
||||
}
|
||||
|
||||
/**
|
||||
* If state is STATE_NONE or state is STATE_FINISH and legacy is not 0,
|
||||
* make state STATE_WAIT
|
||||
*/
|
||||
public synchronized void startAllDownload() {
|
||||
for (DownloadInfo di : mDownloads) {
|
||||
if (di.state == DownloadInfo.STATE_NONE ||
|
||||
(di.state == DownloadInfo.STATE_FINISH && di.legacy != 0)) {
|
||||
setDownloadState(di, DownloadInfo.STATE_WAIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If state is STATE_WAIT or STATE_DOWNLOAD,
|
||||
* make state STATE_NONE
|
||||
*/
|
||||
public synchronized void stopAllDownload() {
|
||||
for (DownloadInfo di : mDownloads) {
|
||||
if (di.state == DownloadInfo.STATE_WAIT ||
|
||||
di.state == DownloadInfo.STATE_DOWNLOAD) {
|
||||
setDownloadState(di, DownloadInfo.STATE_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****** local favourite ******/
|
||||
private synchronized void getLocalFavourites() {
|
||||
mLocalFavourites = new ArrayList<GalleryInfo>();
|
||||
@@ -395,7 +477,7 @@ public class Data {
|
||||
if (cursor.moveToFirst()) {
|
||||
while (!cursor.isAfterLast()) {
|
||||
int gid = cursor.getInt(0);
|
||||
GalleryInfo galleryInfo = getGallery(gid);
|
||||
GalleryInfo galleryInfo = getGallery(mDatabase, gid);
|
||||
if (galleryInfo != null)
|
||||
mLocalFavourites.add(galleryInfo);
|
||||
cursor.moveToNext();
|
||||
@@ -594,6 +676,108 @@ public class Data {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final int NONE = 0x0;
|
||||
public static final int BROWSE = 0x1;
|
||||
public static final int READ = 0x2;
|
||||
|
||||
public synchronized List<HistoryItem> getHistory(int mode, boolean desc) {
|
||||
List<HistoryItem> history = new ArrayList<HistoryItem>();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("select * from ").append(TABLE_HISTORY);
|
||||
boolean first = true;
|
||||
if (mode != 0) {
|
||||
sb.append(" where " + COLUMN_MODE + " in (");
|
||||
for (int b = 1; b <= READ; b <<= 1) {
|
||||
if ((mode & b) != 0) {
|
||||
sb.append(first ? "" : ", ").append(b);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
}
|
||||
sb.append(" order by ").append(COLUMN_DATE).append(desc ? " desc" : " asc");
|
||||
|
||||
Log.d(TAG, sb.toString());
|
||||
|
||||
Cursor cursor = mDatabase.rawQuery(sb.toString(), null);
|
||||
if (cursor.moveToFirst()) {
|
||||
while (!cursor.isAfterLast()) {
|
||||
int gid = cursor.getInt(0);
|
||||
GalleryInfo gi = getGallery(mDatabase, gid);
|
||||
if (gi != null) {
|
||||
history.add(new HistoryItem(gi, cursor.getInt(1), cursor.getLong(2)));
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
public synchronized int containsHistory(int gid) {
|
||||
int re;
|
||||
Cursor cursor = mDatabase.rawQuery("select * from "
|
||||
+ TABLE_HISTORY + " where " + COLUMN_GID + "=?",
|
||||
new String[]{String.valueOf(gid)});
|
||||
if (cursor.moveToFirst())
|
||||
re = cursor.getInt(1);
|
||||
else
|
||||
re = NONE;
|
||||
cursor.close();
|
||||
return re;
|
||||
}
|
||||
|
||||
private int checkMode(int mode) {
|
||||
return MathUtils.clamp(mode, NONE, READ);
|
||||
}
|
||||
|
||||
public synchronized void addHistory(GalleryInfo gi, int mode) {
|
||||
mode = checkMode(mode);
|
||||
|
||||
long curDate = System.currentTimeMillis();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_GID, gi.gid);
|
||||
values.put(COLUMN_DATE, curDate);
|
||||
|
||||
int curMode = checkMode(containsHistory(gi.gid));
|
||||
if (curMode == NONE) {
|
||||
// Add new record
|
||||
values.put(COLUMN_MODE, mode);
|
||||
mDatabase.insert(TABLE_HISTORY, null, values);
|
||||
addGallery(gi);
|
||||
|
||||
truncateHistory(Config.getMaxHistoryCount());
|
||||
} else {
|
||||
// Update record
|
||||
int newMode = Math.max(curMode, mode);
|
||||
values.put(COLUMN_MODE, newMode);
|
||||
mDatabase.update(TABLE_HISTORY, values,
|
||||
COLUMN_GID + "=?", new String[]{String.valueOf(gi.gid)});
|
||||
updateGallery(gi);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearHistory() {
|
||||
truncateHistory(0);
|
||||
}
|
||||
|
||||
protected synchronized void truncateHistory(int maxEntries) {
|
||||
if (maxEntries < 0) {
|
||||
return;
|
||||
} else if (maxEntries == 0) {
|
||||
mDatabase.delete(TABLE_HISTORY, null, null);
|
||||
} else {
|
||||
try {
|
||||
mDatabase.execSQL("delete from " + TABLE_HISTORY + " where " + COLUMN_GID
|
||||
+ " in " + "(select " + COLUMN_GID + " from " + TABLE_HISTORY
|
||||
+ " order by " + COLUMN_DATE + " desc limit " + maxEntries
|
||||
+ ", -1);");
|
||||
} catch(Throwable e){}
|
||||
}
|
||||
}
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper {
|
||||
|
||||
public DBHelper(Context context) {
|
||||
@@ -636,11 +820,14 @@ public class Data {
|
||||
db.execSQL(CreateTag);
|
||||
|
||||
// download
|
||||
createDownloadTable(db);
|
||||
createDownloadTableVer3(db);
|
||||
|
||||
// History
|
||||
createHistoryTable(db);
|
||||
}
|
||||
|
||||
private void createDownloadTable(SQLiteDatabase db) {
|
||||
String CreateDownload = "create table "
|
||||
private void createDownloadTableVer2(SQLiteDatabase db) {
|
||||
String createDownload = "create table "
|
||||
+ TABLE_DOWNLOAD + "("
|
||||
+ COLUMN_GID + " integer primary key,"
|
||||
+ COLUMN_MODE + " integer,"
|
||||
@@ -648,7 +835,77 @@ public class Data {
|
||||
+ COLUMN_LEGACY + " integer,"
|
||||
+ "foreign key(" + COLUMN_GID + ") references " + TABLE_GALLERY + "(" + COLUMN_GID + "));";
|
||||
|
||||
SqlUtils.exeSQLSafely(db, CreateDownload);
|
||||
SqlUtils.exeSQLSafely(db, createDownload);
|
||||
}
|
||||
|
||||
private synchronized List<DownloadInfo> getDownloadsVer2(SQLiteDatabase db) {
|
||||
List<DownloadInfo> list = new ArrayList<DownloadInfo>();
|
||||
|
||||
Cursor cursor = db.rawQuery("select * from " + TABLE_DOWNLOAD,
|
||||
null);
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
while (!cursor.isAfterLast()) {
|
||||
|
||||
int gid = cursor.getInt(0);
|
||||
GalleryInfo galleryInfo = getGallery(db, gid);
|
||||
if (galleryInfo == null) {
|
||||
cursor.moveToNext();
|
||||
continue;
|
||||
}
|
||||
int mode = cursor.getInt(1);
|
||||
int state = cursor.getInt(2);
|
||||
int legacy = cursor.getInt(3);
|
||||
if (state == DownloadInfo.STATE_WAIT || state == DownloadInfo.STATE_DOWNLOAD)
|
||||
state = DownloadInfo.STATE_NONE;
|
||||
|
||||
DownloadInfo downloadInfo = new DownloadInfo(
|
||||
galleryInfo, mode, state, legacy);
|
||||
list.add(downloadInfo);
|
||||
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private void createDownloadTableVer3(SQLiteDatabase db) {
|
||||
String createDownload = "create table "
|
||||
+ TABLE_DOWNLOAD + "("
|
||||
+ COLUMN_GID + " integer primary key,"
|
||||
+ COLUMN_MODE + " integer,"
|
||||
+ COLUMN_STATE + " integer,"
|
||||
+ COLUMN_LEGACY + " integer,"
|
||||
+ COLUMN_DATE + " long,"
|
||||
+ "foreign key(" + COLUMN_GID + ") references " + TABLE_GALLERY + "(" + COLUMN_GID + "));";
|
||||
|
||||
SqlUtils.exeSQLSafely(db, createDownload);
|
||||
}
|
||||
|
||||
public void addDownloadInfoVer3(SQLiteDatabase db, List<DownloadInfo> l) {
|
||||
for (int i = 0; i < l.size(); i++) {
|
||||
DownloadInfo di = l.get(i);
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_GID, di.galleryInfo.gid);
|
||||
values.put(COLUMN_MODE, di.mode);
|
||||
values.put(COLUMN_STATE, di.state);
|
||||
values.put(COLUMN_LEGACY, di.legacy);
|
||||
values.put(COLUMN_DATE, (long) i);
|
||||
db.insert(TABLE_DOWNLOAD, null, values);
|
||||
}
|
||||
}
|
||||
|
||||
private void createHistoryTable(SQLiteDatabase db) {
|
||||
String createDownload = "create table "
|
||||
+ TABLE_HISTORY + "("
|
||||
+ COLUMN_GID + " integer primary key,"
|
||||
+ COLUMN_MODE + " integer,"
|
||||
+ COLUMN_DATE + " long,"
|
||||
+ "foreign key(" + COLUMN_GID + ") references " + TABLE_GALLERY + "(" + COLUMN_GID + "));";
|
||||
|
||||
SqlUtils.exeSQLSafely(db, createDownload);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -657,8 +914,14 @@ public class Data {
|
||||
case 1:
|
||||
SqlUtils.dropTable(db, TABLE_DOWNLOAD);
|
||||
SqlUtils.dropTable(db, "read");
|
||||
createDownloadTable(db);
|
||||
break;
|
||||
createDownloadTableVer2(db);
|
||||
case 2:
|
||||
List<DownloadInfo> l = getDownloadsVer2(db);
|
||||
SqlUtils.dropTable(db, TABLE_DOWNLOAD);
|
||||
createDownloadTableVer3(db);
|
||||
addDownloadInfoVer3(db, l);
|
||||
case 3:
|
||||
createHistoryTable(db);
|
||||
case VERSION:
|
||||
break;
|
||||
default:
|
||||
+14
-2
@@ -16,8 +16,10 @@
|
||||
|
||||
package com.hippo.ehviewer.data;
|
||||
|
||||
import com.hippo.ehviewer.widget.ExpandableListItem;
|
||||
|
||||
public class DownloadInfo {
|
||||
|
||||
public class DownloadInfo implements ExpandableListItem {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = DownloadInfo.class.getSimpleName();
|
||||
|
||||
@@ -35,7 +37,7 @@ public class DownloadInfo {
|
||||
public volatile int total = -1;
|
||||
public volatile int legacy;
|
||||
|
||||
public boolean selected = false;
|
||||
private boolean mExpanded = false;
|
||||
|
||||
public DownloadInfo(GalleryInfo gi, int mode) {
|
||||
this.galleryInfo = gi;
|
||||
@@ -48,4 +50,14 @@ public class DownloadInfo {
|
||||
this.state = state;
|
||||
this.legacy = legacy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpanded(boolean expanded) {
|
||||
mExpanded = expanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getExpanded() {
|
||||
return mExpanded;
|
||||
}
|
||||
}
|
||||
+5
@@ -98,4 +98,9 @@ public class GalleryDetail extends GalleryInfo
|
||||
if (page >= 0 && previewLists != null && page < previewLists.length)
|
||||
previewLists[page] = previewList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryInfo toGalleryInfo() {
|
||||
return new GalleryInfo(this);
|
||||
}
|
||||
}
|
||||
+34
-3
@@ -61,9 +61,9 @@ public class GalleryInfo implements Parcelable {
|
||||
|
||||
public static final String[] S_LANG_PATTERNS = {
|
||||
"[(\\[]eng(?:lish)?[)\\]]",
|
||||
"[((\\[]chinese[))\\]]|[汉漢]化",
|
||||
"[((\\[]chinese[))\\]]|[汉漢]化|中[国國][语語]|中文|[(\\[]CN[)\\]]",
|
||||
"[(\\[]spanish[)\\]]|[(\\[]Español[)\\]]",
|
||||
"[(\\[]korean[)\\]]",
|
||||
"[(\\[]korean?[)\\]]",
|
||||
"[(\\[]rus(?:sian)?[)\\]]",
|
||||
"[(\\[]fr(?:ench)?[)\\]]",
|
||||
"[(\\[]portuguese",
|
||||
@@ -76,7 +76,6 @@ public class GalleryInfo implements Parcelable {
|
||||
"[(\\[]dutch[)\\]]",
|
||||
};
|
||||
|
||||
|
||||
public int gid;
|
||||
public String token;
|
||||
public String title;
|
||||
@@ -85,6 +84,14 @@ public class GalleryInfo implements Parcelable {
|
||||
public String thumb;
|
||||
public String uploader;
|
||||
public float rating;
|
||||
/**
|
||||
* Will not be recond
|
||||
*/
|
||||
public int thumbWidth;
|
||||
/**
|
||||
* Will not be recond
|
||||
*/
|
||||
public int thumbHeight;
|
||||
/**
|
||||
* language get from title
|
||||
*/
|
||||
@@ -131,6 +138,30 @@ public class GalleryInfo implements Parcelable {
|
||||
dest.writeString(simpleLanguage);
|
||||
}
|
||||
|
||||
public GalleryInfo() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public GalleryInfo(GalleryInfo gi) {
|
||||
gid = gi.gid;
|
||||
token = gi.token;
|
||||
title = gi.title;
|
||||
posted = gi.posted;
|
||||
category = gi.category;
|
||||
thumb = gi.thumb;
|
||||
uploader = gi.uploader;
|
||||
rating = gi.rating;
|
||||
simpleLanguage = gi.simpleLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof GalleryInfo && ((GalleryInfo) o).gid == gid)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void generateSLang() {
|
||||
for (int i = 0; i < S_LANGS.length; i++) {
|
||||
if (Pattern.compile(S_LANG_PATTERNS[i], Pattern.CASE_INSENSITIVE).matcher(title).find()) {
|
||||
-5
@@ -46,11 +46,6 @@ public class GalleryPopular extends GalleryInfo {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class HistoryItem extends GalleryInfo {
|
||||
public int mode;
|
||||
public long date;
|
||||
|
||||
public static final Parcelable.Creator<HistoryItem> CREATOR =
|
||||
new Parcelable.Creator<HistoryItem>() {
|
||||
@Override
|
||||
public HistoryItem createFromParcel(Parcel source) {
|
||||
HistoryItem p = new HistoryItem();
|
||||
p.gid = source.readInt();
|
||||
p.token = source.readString();
|
||||
p.title = source.readString();
|
||||
p.posted = source.readString();
|
||||
p.category = source.readInt();
|
||||
p.thumb = source.readString();
|
||||
p.uploader = source.readString();
|
||||
p.rating = source.readFloat();
|
||||
p.simpleLanguage = source.readString();
|
||||
p.mode = source.readInt();
|
||||
p.date = source.readLong();
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryItem[] newArray(int size) {
|
||||
return new HistoryItem[size];
|
||||
}
|
||||
};
|
||||
|
||||
public HistoryItem() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public HistoryItem(GalleryInfo gi, int m, long d) {
|
||||
super(gi);
|
||||
mode = m;
|
||||
date = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeInt(mode);
|
||||
dest.writeLong(date);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-4
@@ -83,9 +83,7 @@ public class LargePreviewList extends PreviewList {
|
||||
// Add to read in Data
|
||||
Intent intent = new Intent(mActivity,
|
||||
GalleryActivity.class);
|
||||
intent.putExtra(GalleryActivity.KEY_GID, mPi.getGid());
|
||||
intent.putExtra(GalleryActivity.KEY_TOKEN, mPi.getToken());
|
||||
intent.putExtra(GalleryActivity.KEY_TITLE, mPi.getTitle());
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mPi.toGalleryInfo());
|
||||
intent.putExtra(GalleryActivity.KEY_START_INDEX, _index);
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
@@ -115,7 +113,7 @@ public class LargePreviewList extends PreviewList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetImage(String key, Bitmap bmp) {
|
||||
public void onGetImage(String key, Bitmap bmp, int state) {
|
||||
if (mTargetPage != mHolder.getCurPreviewPage())
|
||||
return;
|
||||
|
||||
+16
@@ -315,4 +315,20 @@ public class ListUrls {
|
||||
return ub.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (mMode) {
|
||||
case MODE_NORMAL:
|
||||
case MODE_UPLOADER:
|
||||
return search;
|
||||
case MODE_TAG:
|
||||
return mTag;
|
||||
case MODE_POPULAR:
|
||||
case MODE_IMAGE_SEARCH:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+5
@@ -96,4 +96,9 @@ public class LofiGalleryDetail extends LofiGalleryInfo
|
||||
public String[] getTags() {
|
||||
return lofiTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryInfo toGalleryInfo() {
|
||||
return new GalleryInfo(this);
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+3
-5
@@ -113,7 +113,7 @@ public class NormalPreviewList extends PreviewList{
|
||||
int index = mTargetPage * mPi.getPreviewPerPage(); // it is display index
|
||||
int rowIndex = 0;
|
||||
for (NormalPreviewList.Row row : rowArray) {
|
||||
for (NormalPreviewList.Item item : row.itemArray) {
|
||||
for (int i = 0; i < row.itemArray.size(); i++) {
|
||||
View view = inflater.inflate(R.layout.preview_item, null);
|
||||
|
||||
((TextView)view.findViewById(R.id.text)).setText(String.valueOf(index + 1));
|
||||
@@ -125,9 +125,7 @@ public class NormalPreviewList extends PreviewList{
|
||||
// Add to read in Data
|
||||
Intent intent = new Intent(mActivity,
|
||||
GalleryActivity.class);
|
||||
intent.putExtra(GalleryActivity.KEY_GID, mPi.getGid());
|
||||
intent.putExtra(GalleryActivity.KEY_TOKEN, mPi.getToken());
|
||||
intent.putExtra(GalleryActivity.KEY_TITLE, mPi.getTitle());
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mPi.toGalleryInfo());
|
||||
intent.putExtra(GalleryActivity.KEY_START_INDEX, _index);
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
@@ -154,7 +152,7 @@ public class NormalPreviewList extends PreviewList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetImage(String key, Bitmap bmp) {
|
||||
public void onGetImage(String key, Bitmap bmp, int state) {
|
||||
if (mTargetPage != mHolder.getCurPreviewPage())
|
||||
return;
|
||||
|
||||
+2
@@ -47,4 +47,6 @@ public interface PreviewImpl {
|
||||
*/
|
||||
public void setPreview(int page, PreviewList previewList);
|
||||
|
||||
public GalleryInfo toGalleryInfo();
|
||||
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+54
-22
@@ -24,6 +24,8 @@ import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
|
||||
public class BatteryDrawable extends Drawable {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -34,39 +36,69 @@ public class BatteryDrawable extends Drawable {
|
||||
private int mColor = Color.WHITE;
|
||||
private int mWarnColor = Color.RED;
|
||||
private int mElect = -1;
|
||||
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
|
||||
private final Paint mPaint;
|
||||
|
||||
private final Rect mTopRect;
|
||||
private final Rect mBottomRect;
|
||||
private final Rect mRightRect;
|
||||
private final Rect mHeadRect;
|
||||
private final Rect mElectRect;
|
||||
private int mStart;
|
||||
private int mStop;
|
||||
|
||||
public BatteryDrawable() {
|
||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
mTopRect = new Rect();
|
||||
mBottomRect = new Rect();
|
||||
mRightRect = new Rect();
|
||||
mHeadRect = new Rect();
|
||||
mElectRect = new Rect();
|
||||
updatePaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
int width = bounds.width();
|
||||
int height = bounds.height();
|
||||
int strokeWidth = (int) (Math.sqrt(width * width + height * height) * 0.06f);
|
||||
int turn1 = width * 6 / 7;
|
||||
int turn2 = height / 3;
|
||||
int secBottom = height - strokeWidth;
|
||||
mStart = strokeWidth;
|
||||
mStop = turn1 - strokeWidth;
|
||||
|
||||
mTopRect.set(0, 0, turn1, strokeWidth);
|
||||
mBottomRect.set(0, secBottom, turn1, height);
|
||||
mRightRect.set(turn1 - strokeWidth, strokeWidth, turn1, secBottom);
|
||||
mHeadRect.set(turn1, turn2, width, height - turn2);
|
||||
mElectRect.set(0, strokeWidth, mStop, secBottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* How to draw:<br>
|
||||
* |------------------------------|<br>
|
||||
* |\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|<br>
|
||||
* |------------------------------|---|<br>
|
||||
* |/////////////////| |//|\\\|<br>
|
||||
* |/////////////////| |//|\\\|<br>
|
||||
* |------------------------------|---|<br>
|
||||
* |\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|<br>
|
||||
* |------------------------------|
|
||||
*/
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
if (mElect == -1)
|
||||
return;
|
||||
|
||||
Rect bounds = getBounds();
|
||||
int width = bounds.width();
|
||||
int height = bounds.height();
|
||||
int strokeWidth = (int)(Math.sqrt(width * width + height * height) * 0.06f);
|
||||
int halfStrokeWidth = strokeWidth / 2;
|
||||
int turn1 = width * 6 / 7;
|
||||
int turn2 = height / 3;
|
||||
int start = strokeWidth;
|
||||
int stop = turn1 - halfStrokeWidth;
|
||||
int levelEnd = start + (stop - start) * mElect / 100;
|
||||
mElectRect.right = MathUtils.lerp(mStart, mStop, mElect / 100.0f);
|
||||
|
||||
float[] drawPoints = {
|
||||
halfStrokeWidth, 0 + strokeWidth, halfStrokeWidth, height - strokeWidth,
|
||||
0, halfStrokeWidth, turn1 - halfStrokeWidth, halfStrokeWidth,
|
||||
0, height - halfStrokeWidth, turn1 - halfStrokeWidth, height - halfStrokeWidth,
|
||||
turn1, 0, turn1, turn2,
|
||||
turn1, height, turn1, height - turn2};
|
||||
|
||||
mPaint.setStrokeWidth(strokeWidth);
|
||||
canvas.drawLines(drawPoints, mPaint);
|
||||
canvas.drawRect(turn1 - halfStrokeWidth, turn2, width, height - turn2, mPaint);
|
||||
canvas.drawRect(start, 0 + strokeWidth, levelEnd, height - strokeWidth, mPaint);
|
||||
canvas.drawRect(mTopRect, mPaint);
|
||||
canvas.drawRect(mBottomRect, mPaint);
|
||||
canvas.drawRect(mRightRect, mPaint);
|
||||
canvas.drawRect(mHeadRect, mPaint);
|
||||
canvas.drawRect(mElectRect, mPaint);
|
||||
}
|
||||
|
||||
private boolean isWarn() {
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.drawable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
|
||||
public class FreeMaterialDrawable extends Drawable {
|
||||
|
||||
private static final String TAG = FreeMaterialDrawable.class.getSimpleName();
|
||||
|
||||
private static final int MAX_SPRITE_NUM = 6;
|
||||
|
||||
private static final int SPRITE_SHAPE_RECTANGLE = 0;
|
||||
private static final int SPRITE_SHAPE_ROUND = 1;
|
||||
private static final int SPRITE_SHAPE_MAX = 2;
|
||||
|
||||
private boolean mKeepTop;
|
||||
private int mBgIndex;
|
||||
private int mBgColor;
|
||||
private final Paint mPaint;
|
||||
private int mSpriteNum;
|
||||
private final Sprite[] mSpriteArray = new Sprite[MAX_SPRITE_NUM];
|
||||
|
||||
private static final int[] sColorArray = new int[] {
|
||||
0xff9c27b0, 0xff673ab7,
|
||||
0xff3f51b5, 0xff2196f3, 0xff03a9f4, 0xff00bcd4,
|
||||
0xff4caf50
|
||||
};
|
||||
|
||||
public FreeMaterialDrawable () {
|
||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
mPaint.setShadowLayer(Ui.dp2pix(3), 0, 0, 0x8a000000);
|
||||
}
|
||||
|
||||
public FreeMaterialDrawable setBgIndex(int bgIndex) {
|
||||
mBgIndex = bgIndex;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FreeMaterialDrawable setKeepTop(boolean keepTop) {
|
||||
mKeepTop = keepTop;
|
||||
return this;
|
||||
}
|
||||
|
||||
private int getColor(int[] copyOfColorArray) {
|
||||
int index = MathUtils.random(0, copyOfColorArray.length);
|
||||
int color = copyOfColorArray[index];
|
||||
while (color == -1)
|
||||
color = copyOfColorArray[++index < copyOfColorArray.length ? index : (index = 0)];
|
||||
copyOfColorArray[index] = -1;
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
int w = bounds.width();
|
||||
int h = bounds.height();
|
||||
Sprite s;
|
||||
int[] copyOfColorArray = Arrays.copyOf(sColorArray, sColorArray.length);
|
||||
if (mBgIndex >= 0) {
|
||||
mBgColor = copyOfColorArray[mBgIndex];
|
||||
copyOfColorArray[mBgIndex] = -1;
|
||||
} else {
|
||||
mBgColor = getColor(copyOfColorArray);
|
||||
}
|
||||
mSpriteNum = MathUtils.random(4, MAX_SPRITE_NUM + 1);
|
||||
for (int i = 0; i < mSpriteNum; i++) {
|
||||
switch (SPRITE_SHAPE_ROUND) {//MathUtils.random(0, SPRITE_SHAPE_MAX)) {
|
||||
case SPRITE_SHAPE_RECTANGLE:
|
||||
s = new Rectangle(w, h, getColor(copyOfColorArray));
|
||||
break;
|
||||
default:
|
||||
case SPRITE_SHAPE_ROUND:
|
||||
s = new Round(w, h, getColor(copyOfColorArray));
|
||||
break;
|
||||
}
|
||||
mSpriteArray[i] = s;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
canvas.drawColor(mBgColor);
|
||||
|
||||
for (int i = 0; i < mSpriteNum; i++)
|
||||
mSpriteArray[i].draw(canvas, mPaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return PixelFormat.OPAQUE;
|
||||
}
|
||||
|
||||
private abstract class Sprite {
|
||||
|
||||
private final int mColor;
|
||||
|
||||
public Sprite(int w, int h, int color) {
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
public void draw(Canvas canvas, Paint paint) {
|
||||
paint.setColor(mColor);
|
||||
doDraw(canvas, paint);
|
||||
}
|
||||
|
||||
public abstract void doDraw(Canvas canvas, Paint paint);
|
||||
}
|
||||
|
||||
private class Rectangle extends Sprite {
|
||||
|
||||
private final int left;
|
||||
private final int top;
|
||||
private final int right;
|
||||
private final int bottom;
|
||||
|
||||
public Rectangle(int w, int h, int color) {
|
||||
super(w, h, color);
|
||||
|
||||
int width = MathUtils.random(w / 4, w / 2);
|
||||
int height = MathUtils.random(h / 4, h / 2);
|
||||
left = MathUtils.random(w - width / 2);
|
||||
top = MathUtils.random(h - height / 2);
|
||||
right = left + width;
|
||||
bottom = top + height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDraw(Canvas canvas, Paint paint) {
|
||||
canvas.drawRect(left, top, right, bottom, paint);
|
||||
}
|
||||
}
|
||||
|
||||
private class Round extends Sprite {
|
||||
|
||||
int mX, mY, mRadius;
|
||||
|
||||
public Round(int w, int h, int color) {
|
||||
super(w, h, color);
|
||||
|
||||
int t = (w + h) / 2;
|
||||
mRadius = MathUtils.random(t / 8, t / 4);
|
||||
mX = MathUtils.random(w);
|
||||
mY = MathUtils.random(mKeepTop ? mRadius + 10 : 0, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDraw(Canvas canvas, Paint paint) {
|
||||
canvas.drawCircle(mX, mY, mRadius, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,695 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Balys Valentukevicius
|
||||
*
|
||||
* 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.drawable;
|
||||
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Property;
|
||||
import android.util.TypedValue;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
|
||||
public class MaterialIndicatorDrawable extends Drawable implements Animatable {
|
||||
|
||||
private static final String STATE_KEY = "material_menu_icon_state";
|
||||
|
||||
public enum IconState {
|
||||
BURGER, ARROW
|
||||
}
|
||||
|
||||
public enum AnimationState {
|
||||
BURGER_ARROW;
|
||||
|
||||
public IconState getFirstState() {
|
||||
switch (this) {
|
||||
case BURGER_ARROW:
|
||||
return IconState.BURGER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IconState getSecondState() {
|
||||
switch (this) {
|
||||
case BURGER_ARROW:
|
||||
return IconState.ARROW;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Stroke {
|
||||
/**
|
||||
* 3 dip
|
||||
*/
|
||||
REGULAR(3),
|
||||
/**
|
||||
* 2 dip
|
||||
*/
|
||||
THIN(2),
|
||||
/**
|
||||
* 1 dip
|
||||
*/
|
||||
EXTRA_THIN(1);
|
||||
|
||||
private final int strokeWidth;
|
||||
|
||||
Stroke(int strokeWidth) {
|
||||
this.strokeWidth = strokeWidth;
|
||||
}
|
||||
|
||||
protected static Stroke valueOf(int strokeWidth) {
|
||||
switch (strokeWidth) {
|
||||
case 3:
|
||||
return REGULAR;
|
||||
case 2:
|
||||
return THIN;
|
||||
case 1:
|
||||
return EXTRA_THIN;
|
||||
default:
|
||||
return THIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final int DEFAULT_COLOR = Color.WHITE;
|
||||
public static final int DEFAULT_SCALE = 1;
|
||||
public static final int DEFAULT_TRANSFORM_DURATION = 800;
|
||||
public static final int DEFAULT_PRESSED_DURATION = 400;
|
||||
|
||||
private static final int BASE_DRAWABLE_WIDTH = 40;
|
||||
private static final int BASE_DRAWABLE_HEIGHT = 40;
|
||||
private static final int BASE_ICON_WIDTH = 20;
|
||||
private static final int BASE_CIRCLE_RADIUS = 18;
|
||||
|
||||
private static final float ARROW_MID_LINE_ANGLE = 180;
|
||||
private static final float ARROW_TOP_LINE_ANGLE = 135;
|
||||
private static final float ARROW_BOT_LINE_ANGLE = 225;
|
||||
|
||||
private static final float TRANSFORMATION_START = 0;
|
||||
private static final float TRANSFORMATION_MID = 1.0f;
|
||||
private static final float TRANSFORMATION_END = 2.0f;
|
||||
|
||||
private static final int DEFAULT_CIRCLE_ALPHA = 200;
|
||||
|
||||
private final float diph;
|
||||
private final float dip1;
|
||||
private final float dip2;
|
||||
private final float dip3;
|
||||
private final float dip4;
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final float strokeWidth;
|
||||
private final float iconWidth;
|
||||
private final float topPadding;
|
||||
private final float sidePadding;
|
||||
private final float circleRadius;
|
||||
|
||||
private final Stroke stroke;
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private final Paint gridPaint = new Paint();
|
||||
private final Paint iconPaint = new Paint();
|
||||
private final Paint circlePaint = new Paint();
|
||||
|
||||
private float transformationValue = 0f;
|
||||
private float pressedProgressValue = 0f;
|
||||
private boolean transformationRunning = false;
|
||||
|
||||
private IconState currentIconState = IconState.BURGER;
|
||||
private AnimationState animationState = AnimationState.BURGER_ARROW;
|
||||
|
||||
private IconState animatingIconState;
|
||||
private boolean drawTouchCircle;
|
||||
private boolean neverDrawTouch;
|
||||
private boolean rtlEnabled;
|
||||
|
||||
private ObjectAnimator transformation;
|
||||
private ObjectAnimator pressedCircle;
|
||||
|
||||
private MaterialMenuState materialMenuState;
|
||||
|
||||
public MaterialIndicatorDrawable(Context context, int color, Stroke stroke) {
|
||||
this(context, color, stroke, DEFAULT_SCALE, DEFAULT_TRANSFORM_DURATION, DEFAULT_PRESSED_DURATION);
|
||||
}
|
||||
|
||||
public MaterialIndicatorDrawable(Context context, int color, Stroke stroke, int transformDuration, int pressedDuration) {
|
||||
this(context, color, stroke, DEFAULT_SCALE, transformDuration, pressedDuration);
|
||||
}
|
||||
|
||||
public MaterialIndicatorDrawable(Context context, int color, Stroke stroke, int scale, int transformDuration, int pressedDuration) {
|
||||
Resources resources = context.getResources();
|
||||
// convert each separately due to various densities
|
||||
this.dip1 = dpToPx(resources, 1) * scale;
|
||||
this.dip2 = dpToPx(resources, 2) * scale;
|
||||
this.dip3 = dpToPx(resources, 3) * scale;
|
||||
this.dip4 = dpToPx(resources, 4) * scale;
|
||||
this.diph = dip1 / 2;
|
||||
|
||||
this.stroke = stroke;
|
||||
this.width = (int) (dpToPx(resources, BASE_DRAWABLE_WIDTH) * scale);
|
||||
this.height = (int) (dpToPx(resources, BASE_DRAWABLE_HEIGHT) * scale);
|
||||
this.iconWidth = dpToPx(resources, BASE_ICON_WIDTH) * scale;
|
||||
this.circleRadius = dpToPx(resources, BASE_CIRCLE_RADIUS) * scale;
|
||||
this.strokeWidth = dpToPx(resources, stroke.strokeWidth) * scale;
|
||||
|
||||
this.sidePadding = (width - iconWidth) / 2;
|
||||
this.topPadding = (height - 5 * dip3) / 2;
|
||||
|
||||
initPaint(color);
|
||||
initAnimations(transformDuration, pressedDuration);
|
||||
|
||||
materialMenuState = new MaterialMenuState();
|
||||
}
|
||||
|
||||
private MaterialIndicatorDrawable(int color, Stroke stroke, long transformDuration, long pressedDuration,
|
||||
int width, int height, float iconWidth, float circleRadius, float strokeWidth, float dip1
|
||||
) {
|
||||
this.dip1 = dip1;
|
||||
this.dip2 = dip1 * 2;
|
||||
this.dip3 = dip1 * 3;
|
||||
this.dip4 = dip1 * 4;
|
||||
this.diph = dip1 / 2;
|
||||
this.stroke = stroke;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.iconWidth = iconWidth;
|
||||
this.circleRadius = circleRadius;
|
||||
this.strokeWidth = strokeWidth;
|
||||
this.sidePadding = (width - iconWidth) / 2;
|
||||
this.topPadding = (height - 5 * dip3) / 2;
|
||||
|
||||
initPaint(color);
|
||||
initAnimations((int) transformDuration, (int) pressedDuration);
|
||||
|
||||
materialMenuState = new MaterialMenuState();
|
||||
}
|
||||
|
||||
private void initPaint(int color) {
|
||||
gridPaint.setAntiAlias(false);
|
||||
gridPaint.setColor(Color.GREEN);
|
||||
gridPaint.setStrokeWidth(1);
|
||||
|
||||
iconPaint.setAntiAlias(true);
|
||||
iconPaint.setStyle(Style.STROKE);
|
||||
iconPaint.setStrokeWidth(strokeWidth);
|
||||
iconPaint.setColor(color);
|
||||
|
||||
circlePaint.setAntiAlias(true);
|
||||
circlePaint.setStyle(Style.FILL);
|
||||
circlePaint.setColor(color);
|
||||
circlePaint.setAlpha(DEFAULT_CIRCLE_ALPHA);
|
||||
|
||||
setBounds(0, 0, width, height);
|
||||
}
|
||||
|
||||
/*
|
||||
* Drawing
|
||||
*/
|
||||
|
||||
@Override public void draw(Canvas canvas) {
|
||||
final float ratio = transformationValue <= 1 ? transformationValue : 2 - transformationValue;
|
||||
|
||||
if (rtlEnabled) {
|
||||
canvas.save();
|
||||
canvas.scale(-1, 1, 0, 0);
|
||||
canvas.translate(-getIntrinsicWidth(), 0);
|
||||
}
|
||||
|
||||
drawTopLine(canvas, ratio);
|
||||
drawMiddleLine(canvas, ratio);
|
||||
drawBottomLine(canvas, ratio);
|
||||
|
||||
if (rtlEnabled) {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
if (drawTouchCircle) drawTouchCircle(canvas);
|
||||
}
|
||||
|
||||
private void drawTouchCircle(Canvas canvas) {
|
||||
canvas.restore();
|
||||
canvas.drawCircle(width / 2, height / 2, pressedProgressValue, circlePaint);
|
||||
}
|
||||
|
||||
private void drawMiddleLine(Canvas canvas, float ratio) {
|
||||
canvas.restore();
|
||||
canvas.save();
|
||||
|
||||
float rotation = 0;
|
||||
float pivotX = width / 2;
|
||||
float pivotY = width / 2;
|
||||
float startX = sidePadding;
|
||||
float startY = topPadding + dip3 / 2 * 5;
|
||||
float stopX = width - sidePadding;
|
||||
float stopY = topPadding + dip3 / 2 * 5;
|
||||
int alpha = 255;
|
||||
|
||||
switch (animationState) {
|
||||
case BURGER_ARROW:
|
||||
// rotate by 180
|
||||
if (isMorphingForward()) {
|
||||
rotation = ratio * ARROW_MID_LINE_ANGLE;
|
||||
} else {
|
||||
rotation = ARROW_MID_LINE_ANGLE + (1 - ratio) * ARROW_MID_LINE_ANGLE;
|
||||
}
|
||||
// shorten one end
|
||||
stopX -= ratio * resolveStrokeModifier(ratio) / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
iconPaint.setAlpha(alpha);
|
||||
canvas.rotate(rotation, pivotX, pivotY);
|
||||
canvas.drawLine(startX, startY, stopX, stopY, iconPaint);
|
||||
iconPaint.setAlpha(255);
|
||||
}
|
||||
|
||||
private void drawTopLine(Canvas canvas, float ratio) {
|
||||
canvas.save();
|
||||
|
||||
float rotation = 0, pivotX = 0, pivotY = 0;
|
||||
float rotation2 = 0;
|
||||
// pivot at center of line
|
||||
float pivotX2 = width / 2 + dip3 / 2;
|
||||
float pivotY2 = topPadding + dip2;
|
||||
|
||||
float startX = sidePadding;
|
||||
float startY = topPadding + dip2;
|
||||
float stopX = width - sidePadding;
|
||||
float stopY = topPadding + dip2;
|
||||
int alpha = 255;
|
||||
|
||||
switch (animationState) {
|
||||
case BURGER_ARROW:
|
||||
if (isMorphingForward()) {
|
||||
// rotate until required angle
|
||||
rotation = ratio * ARROW_BOT_LINE_ANGLE;
|
||||
} else {
|
||||
// rotate back to start doing a 360
|
||||
rotation = ARROW_BOT_LINE_ANGLE + (1 - ratio) * ARROW_TOP_LINE_ANGLE;
|
||||
}
|
||||
// rotate by middle
|
||||
pivotX = width / 2;
|
||||
pivotY = height / 2;
|
||||
|
||||
// shorten both ends
|
||||
stopX -= resolveStrokeModifier(ratio);
|
||||
startX += dip3 * ratio;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
iconPaint.setAlpha(alpha);
|
||||
canvas.rotate(rotation, pivotX, pivotY);
|
||||
canvas.rotate(rotation2, pivotX2, pivotY2);
|
||||
canvas.drawLine(startX, startY, stopX, stopY, iconPaint);
|
||||
iconPaint.setAlpha(255);
|
||||
}
|
||||
|
||||
private void drawBottomLine(Canvas canvas, float ratio) {
|
||||
canvas.restore();
|
||||
canvas.save();
|
||||
|
||||
float rotation = 0, pivotX = 0, pivotY = 0;
|
||||
float rotation2 = 0;
|
||||
// pivot at center of line
|
||||
float pivotX2 = width / 2 + dip3 / 2;
|
||||
float pivotY2 = height - topPadding - dip2;
|
||||
|
||||
float startX = sidePadding;
|
||||
float startY = height - topPadding - dip2;
|
||||
float stopX = width - sidePadding;
|
||||
float stopY = height - topPadding - dip2;
|
||||
|
||||
switch (animationState) {
|
||||
case BURGER_ARROW:
|
||||
if (isMorphingForward()) {
|
||||
// rotate to required angle
|
||||
rotation = ARROW_TOP_LINE_ANGLE * ratio;
|
||||
} else {
|
||||
// rotate back to start doing a 360
|
||||
rotation = ARROW_TOP_LINE_ANGLE + (1 - ratio) * ARROW_BOT_LINE_ANGLE;
|
||||
}
|
||||
// pivot center of canvas
|
||||
pivotX = width / 2;
|
||||
pivotY = height / 2;
|
||||
|
||||
// shorten both ends
|
||||
stopX = width - sidePadding - resolveStrokeModifier(ratio);
|
||||
startX = sidePadding + dip3 * ratio;
|
||||
break;
|
||||
}
|
||||
|
||||
canvas.rotate(rotation, pivotX, pivotY);
|
||||
canvas.rotate(rotation2, pivotX2, pivotY2);
|
||||
canvas.drawLine(startX, startY, stopX, stopY, iconPaint);
|
||||
}
|
||||
|
||||
private boolean isMorphingForward() {
|
||||
return transformationValue <= TRANSFORMATION_MID;
|
||||
}
|
||||
|
||||
private float resolveStrokeModifier(float ratio) {
|
||||
switch (stroke) {
|
||||
case REGULAR:
|
||||
return ratio * dip3;
|
||||
case THIN:
|
||||
return ratio * (dip3 + diph);
|
||||
case EXTRA_THIN:
|
||||
return ratio * dip4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override public void setAlpha(int alpha) {
|
||||
iconPaint.setAlpha(alpha);
|
||||
}
|
||||
|
||||
@Override public void setColorFilter(ColorFilter cf) {
|
||||
iconPaint.setColorFilter(cf);
|
||||
}
|
||||
|
||||
@Override public int getOpacity() {
|
||||
return PixelFormat.TRANSPARENT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Accessor methods
|
||||
*/
|
||||
|
||||
public void setColor(int color) {
|
||||
iconPaint.setColor(color);
|
||||
circlePaint.setColor(color);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public void setTransformationDuration(int duration) {
|
||||
transformation.setDuration(duration);
|
||||
}
|
||||
|
||||
public void setPressedDuration(int duration) {
|
||||
pressedCircle.setDuration(duration);
|
||||
}
|
||||
|
||||
public void setInterpolator(Interpolator interpolator) {
|
||||
transformation.setInterpolator(interpolator);
|
||||
}
|
||||
|
||||
public void setNeverDrawTouch(boolean neverDrawTouch) {
|
||||
this.neverDrawTouch = neverDrawTouch;
|
||||
}
|
||||
|
||||
public void setIconState(IconState iconState) {
|
||||
synchronized (lock) {
|
||||
if (transformationRunning) {
|
||||
transformation.cancel();
|
||||
transformationRunning = false;
|
||||
}
|
||||
|
||||
if (currentIconState == iconState) return;
|
||||
|
||||
switch (iconState) {
|
||||
case BURGER:
|
||||
animationState = AnimationState.BURGER_ARROW;
|
||||
transformationValue = TRANSFORMATION_START;
|
||||
break;
|
||||
case ARROW:
|
||||
animationState = AnimationState.BURGER_ARROW;
|
||||
transformationValue = TRANSFORMATION_MID;
|
||||
break;
|
||||
}
|
||||
currentIconState = iconState;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
public void animateIconState(IconState state, boolean drawTouch) {
|
||||
synchronized (lock) {
|
||||
if (transformationRunning) {
|
||||
transformation.end();
|
||||
pressedCircle.end();
|
||||
}
|
||||
drawTouchCircle = drawTouch;
|
||||
animatingIconState = state;
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
public IconState setTransformationOffset(AnimationState animationState, float offset) {
|
||||
if (offset < TRANSFORMATION_START || offset > TRANSFORMATION_END) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Value must be between %s and %s", TRANSFORMATION_START, TRANSFORMATION_END)
|
||||
);
|
||||
}
|
||||
|
||||
this.animationState = animationState;
|
||||
|
||||
final boolean isFirstIcon = offset < TRANSFORMATION_MID || offset == TRANSFORMATION_END;
|
||||
|
||||
currentIconState = isFirstIcon ? animationState.getFirstState() : animationState.getSecondState();
|
||||
animatingIconState = isFirstIcon ? animationState.getSecondState() : animationState.getFirstState();
|
||||
|
||||
setTransformationValue(offset);
|
||||
|
||||
return currentIconState;
|
||||
}
|
||||
|
||||
public void setRTLEnabled(boolean rtlEnabled) {
|
||||
this.rtlEnabled = rtlEnabled;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public IconState getIconState() {
|
||||
return currentIconState;
|
||||
}
|
||||
|
||||
/*
|
||||
* Animations
|
||||
*/
|
||||
private final Property<MaterialIndicatorDrawable, Float> transformationProperty
|
||||
= new Property<MaterialIndicatorDrawable, Float>(Float.class, "transformation") {
|
||||
@Override
|
||||
public Float get(MaterialIndicatorDrawable object) {
|
||||
return object.getTransformationValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(MaterialIndicatorDrawable object, Float value) {
|
||||
object.setTransformationValue(value);
|
||||
}
|
||||
};
|
||||
|
||||
private final Property<MaterialIndicatorDrawable, Float> pressedProgressProperty
|
||||
= new Property<MaterialIndicatorDrawable, Float>(Float.class, "pressedProgress") {
|
||||
@Override
|
||||
public Float get(MaterialIndicatorDrawable object) {
|
||||
return object.getPressedProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(MaterialIndicatorDrawable object, Float value) {
|
||||
object.setPressedProgress(value);
|
||||
}
|
||||
};
|
||||
|
||||
public Float getTransformationValue() {
|
||||
return transformationValue;
|
||||
}
|
||||
|
||||
public void setTransformationValue(Float value) {
|
||||
this.transformationValue = value;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public Float getPressedProgress() {
|
||||
return pressedProgressValue;
|
||||
}
|
||||
|
||||
public void setPressedProgress(Float value) {
|
||||
this.pressedProgressValue = value;
|
||||
circlePaint.setAlpha((int) (DEFAULT_CIRCLE_ALPHA * (1 - value / (circleRadius * 1.22f))));
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
private void initAnimations(int transformDuration, int pressedDuration) {
|
||||
transformation = ObjectAnimator.ofFloat(this, transformationProperty, 0);
|
||||
transformation.setInterpolator(new DecelerateInterpolator(3));
|
||||
transformation.setDuration(transformDuration);
|
||||
transformation.addListener(new AnimatorListenerAdapter() {
|
||||
@Override public void onAnimationEnd(Animator animation) {
|
||||
transformationRunning = false;
|
||||
setIconState(animatingIconState);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
pressedCircle = ObjectAnimator.ofFloat(this, pressedProgressProperty, 0, 0);
|
||||
pressedCircle.setDuration(pressedDuration);
|
||||
pressedCircle.setInterpolator(new DecelerateInterpolator());
|
||||
pressedCircle.addListener(new AnimatorListenerAdapter() {
|
||||
@Override public void onAnimationEnd(Animator animation) {
|
||||
pressedProgressValue = 0;
|
||||
}
|
||||
|
||||
@Override public void onAnimationCancel(Animator animation) {
|
||||
pressedProgressValue = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean resolveTransformation() {
|
||||
boolean isCurrentBurger = currentIconState == IconState.BURGER;
|
||||
boolean isCurrentArrow = currentIconState == IconState.ARROW;
|
||||
boolean isAnimatingBurger = animatingIconState == IconState.BURGER;
|
||||
boolean isAnimatingArrow = animatingIconState == IconState.ARROW;
|
||||
|
||||
if ((isCurrentBurger && isAnimatingArrow) || (isCurrentArrow && isAnimatingBurger)) {
|
||||
animationState = AnimationState.BURGER_ARROW;
|
||||
return isCurrentBurger;
|
||||
}
|
||||
|
||||
throw new IllegalStateException(
|
||||
String.format("Animating from %s to %s is not supported", currentIconState, animatingIconState)
|
||||
);
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
if (transformationRunning || animatingIconState == null || animatingIconState == currentIconState) return;
|
||||
transformationRunning = true;
|
||||
|
||||
final boolean direction = resolveTransformation();
|
||||
transformation.setFloatValues(
|
||||
direction ? TRANSFORMATION_START : TRANSFORMATION_MID,
|
||||
direction ? TRANSFORMATION_MID : TRANSFORMATION_END
|
||||
);
|
||||
transformation.start();
|
||||
|
||||
if (pressedCircle.isRunning()) {
|
||||
pressedCircle.cancel();
|
||||
}
|
||||
if (drawTouchCircle && !neverDrawTouch) {
|
||||
pressedCircle.setFloatValues(0, circleRadius * 1.22f);
|
||||
pressedCircle.start();
|
||||
}
|
||||
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override public void stop() {
|
||||
if (isRunning() && transformation.isRunning()) {
|
||||
transformation.end();
|
||||
} else {
|
||||
transformationRunning = false;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean isRunning() {
|
||||
return transformationRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConstantState getConstantState() {
|
||||
materialMenuState.changingConfigurations = getChangingConfigurations();
|
||||
return materialMenuState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable mutate() {
|
||||
materialMenuState = new MaterialMenuState();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call from {@link android.app.Activity#onSaveInstanceState(android.os.Bundle)} to store current icon state
|
||||
*
|
||||
* @param outState outState
|
||||
*/
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString(STATE_KEY, currentIconState.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Call from {@link android.app.Activity#onPostCreate(android.os.Bundle)} to restore icon state
|
||||
*
|
||||
* @param state state
|
||||
*/
|
||||
public void syncState(Bundle state) {
|
||||
if (state != null) {
|
||||
String iconStateName = state.getString(STATE_KEY);
|
||||
if (iconStateName == null) {
|
||||
iconStateName = MaterialIndicatorDrawable.IconState.BURGER.name();
|
||||
}
|
||||
setIconState(MaterialIndicatorDrawable.IconState.valueOf(iconStateName));
|
||||
}
|
||||
}
|
||||
|
||||
private final class MaterialMenuState extends ConstantState {
|
||||
private int changingConfigurations;
|
||||
|
||||
private MaterialMenuState() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable newDrawable() {
|
||||
MaterialIndicatorDrawable drawable = new MaterialIndicatorDrawable(
|
||||
circlePaint.getColor(), stroke, transformation.getDuration(),
|
||||
pressedCircle.getDuration(), width, height, iconWidth, circleRadius, strokeWidth, dip1
|
||||
);
|
||||
drawable.setIconState(animatingIconState != null ? animatingIconState : currentIconState);
|
||||
drawable.setRTLEnabled(rtlEnabled);
|
||||
return drawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChangingConfigurations() {
|
||||
return changingConfigurations;
|
||||
}
|
||||
}
|
||||
|
||||
static float dpToPx(Resources resources, float dp) {
|
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,5 @@
|
||||
package com.hippo.ehviewer.drawable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.TimeInterpolator;
|
||||
@@ -18,6 +16,8 @@ import android.os.Build;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
// Get from android.graphics.drawable.MaterialProgressDrawable
|
||||
public class MaterialProgressDrawable extends Drawable implements Animatable {
|
||||
private static final TimeInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
||||
+9
-1
@@ -20,21 +20,29 @@ import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class OvalDrawable extends Drawable {
|
||||
|
||||
private final Paint mPaint;
|
||||
private final RectF mRectF;
|
||||
|
||||
public OvalDrawable(int color) {
|
||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
|
||||
mPaint.setColor(color);
|
||||
mRectF = new RectF();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
mRectF.set(bounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
canvas.drawOval(new RectF(this.getBounds()), mPaint);
|
||||
canvas.drawOval(mRectF, mPaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.effect;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class DrawableTransition {
|
||||
|
||||
public static void transit(final Drawable drawable, boolean fromDark, long duration) {
|
||||
final AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator(fromDark);
|
||||
evaluator.setFraction(0.0f);
|
||||
drawable.setColorFilter(new ColorMatrixColorFilter(evaluator.getColorMatrix()));
|
||||
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 1.0f);
|
||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
float f = (Float) animation.getAnimatedValue();
|
||||
evaluator.setFraction(f);
|
||||
drawable.setColorFilter(new ColorMatrixColorFilter(evaluator.getColorMatrix()));
|
||||
}
|
||||
});
|
||||
animator.setDuration(duration);
|
||||
animator.start();
|
||||
}
|
||||
|
||||
// From rnr.tests.imageloadingpattern.AlphaSatColorMatrixEvaluator
|
||||
// with modification
|
||||
private static class AlphaSatColorMatrixEvaluator {
|
||||
private final ColorMatrix colorMatrix;
|
||||
private final float[] elements = new float[20];
|
||||
private final boolean mFromDark;
|
||||
|
||||
public AlphaSatColorMatrixEvaluator(boolean fromDark) {
|
||||
colorMatrix = new ColorMatrix ();
|
||||
mFromDark = fromDark;
|
||||
}
|
||||
|
||||
public ColorMatrix getColorMatrix() {
|
||||
return colorMatrix;
|
||||
}
|
||||
|
||||
public void setFraction(float fraction) {
|
||||
// There are 4 phases so we multiply fraction by that amount
|
||||
float phase = fraction * 4;
|
||||
|
||||
// Compute the alpha change over period [0, 2]
|
||||
float alpha = Math.min(phase, 2.0f) / 2.0f;
|
||||
elements [19] = Math.round(alpha * 255);
|
||||
|
||||
// We substract to make the picture look darker, it will automatically clamp
|
||||
// This is spread over period [0, 3]
|
||||
final int MaxBlacker = 50;
|
||||
float blackening = Math.round((1 - Math.min(phase, 3.0f) / 3.0f) * MaxBlacker);
|
||||
elements [4] = elements [9] = elements [14] = mFromDark ? -blackening : blackening;
|
||||
|
||||
// Finally we desaturate over [0, 4], taken from ColorMatrix.SetSaturation
|
||||
float invSat = 1 - Math.max(0.2f, fraction);
|
||||
float R = 0.213f * invSat;
|
||||
float G = 0.715f * invSat;
|
||||
float B = 0.072f * invSat;
|
||||
|
||||
elements[0] = R + fraction; elements[1] = G; elements[2] = B;
|
||||
elements[5] = R; elements[6] = G + fraction; elements[7] = B;
|
||||
elements[10] = R; elements[11] = G; elements[12] = B + fraction;
|
||||
|
||||
colorMatrix.set(elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* 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.effect.ripple;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
|
||||
/**
|
||||
* Draws a Material ripple.
|
||||
*/
|
||||
class Ripple {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = Ripple.class.getSimpleName();
|
||||
|
||||
private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
||||
private static final Interpolator DECEL_INTERPOLATOR = new LogInterpolator();
|
||||
|
||||
private static final float GLOBAL_SPEED = 1.0f;
|
||||
private static final float WAVE_TOUCH_DOWN_ACCELERATION = 1024.0f * GLOBAL_SPEED;
|
||||
private static final float WAVE_TOUCH_UP_ACCELERATION = 3400.0f * GLOBAL_SPEED;
|
||||
private static final float WAVE_OPACITY_DECAY_VELOCITY = 3.0f / GLOBAL_SPEED;
|
||||
|
||||
private static final long RIPPLE_ENTER_DELAY = 80;
|
||||
|
||||
private final RippleOwner mOwner;
|
||||
|
||||
/** Bounds used for computing max radius. */
|
||||
private final Rect mBounds;
|
||||
|
||||
/** Full-opacity color for drawing this ripple. */
|
||||
private int mColorOpaque;
|
||||
|
||||
/** Maximum ripple radius. */
|
||||
private float mOuterRadius;
|
||||
|
||||
/** Screen density used to adjust pixel-based velocities. */
|
||||
private float mDensity;
|
||||
|
||||
private float mStartingX;
|
||||
private float mStartingY;
|
||||
private float mClampedStartingX;
|
||||
private float mClampedStartingY;
|
||||
|
||||
// Software animators.
|
||||
private ObjectAnimator mAnimRadius;
|
||||
private ObjectAnimator mAnimOpacity;
|
||||
private ObjectAnimator mAnimX;
|
||||
private ObjectAnimator mAnimY;
|
||||
|
||||
// Software rendering properties.
|
||||
private float mOpacity = 1;
|
||||
private float mOuterX;
|
||||
private float mOuterY;
|
||||
|
||||
// Values used to tween between the start and end positions.
|
||||
private float mTweenRadius = 0;
|
||||
private float mTweenX = 0;
|
||||
private float mTweenY = 0;
|
||||
|
||||
/** Whether we have an explicit maximum radius. */
|
||||
private boolean mHasMaxRadius;
|
||||
|
||||
/** Whether we were canceled externally and should avoid self-removal. */
|
||||
private boolean mCanceled;
|
||||
|
||||
/**
|
||||
* Creates a new ripple.
|
||||
*/
|
||||
public Ripple(RippleOwner owner, Rect bounds, float startingX, float startingY) {
|
||||
mOwner = owner;
|
||||
mBounds = bounds;
|
||||
|
||||
mStartingX = startingX;
|
||||
mStartingY = startingY;
|
||||
}
|
||||
|
||||
public void setup(int maxRadius, int color, float density) {
|
||||
mColorOpaque = color | 0xFF000000;
|
||||
mOpacity = Color.alpha(color) / 2 / 255.0f;
|
||||
|
||||
if (maxRadius != RippleOwner.RADIUS_AUTO) {
|
||||
mHasMaxRadius = true;
|
||||
mOuterRadius = maxRadius;
|
||||
} else {
|
||||
final float halfWidth = mBounds.width() / 2.0f;
|
||||
final float halfHeight = mBounds.height() / 2.0f;
|
||||
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
|
||||
}
|
||||
|
||||
mOuterX = 0;
|
||||
mOuterY = 0;
|
||||
mDensity = density;
|
||||
|
||||
clampStartingPosition();
|
||||
}
|
||||
|
||||
private void clampStartingPosition() {
|
||||
final float cX = mBounds.exactCenterX();
|
||||
final float cY = mBounds.exactCenterY();
|
||||
final float dX = mStartingX - cX;
|
||||
final float dY = mStartingY - cY;
|
||||
final float r = mOuterRadius;
|
||||
if (dX * dX + dY * dY > r * r) {
|
||||
// Point is outside the circle, clamp to the circumference.
|
||||
final double angle = Math.atan2(dY, dX);
|
||||
mClampedStartingX = cX + (float) (Math.cos(angle) * r);
|
||||
mClampedStartingY = cY + (float) (Math.sin(angle) * r);
|
||||
} else {
|
||||
mClampedStartingX = mStartingX;
|
||||
mClampedStartingY = mStartingY;
|
||||
}
|
||||
}
|
||||
|
||||
public void onHotspotBoundsChanged() {
|
||||
if (!mHasMaxRadius) {
|
||||
final float halfWidth = mBounds.width() / 2.0f;
|
||||
final float halfHeight = mBounds.height() / 2.0f;
|
||||
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
|
||||
|
||||
clampStartingPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public void setOpacity(float a) {
|
||||
mOpacity = a;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public float getOpacity() {
|
||||
return mOpacity;
|
||||
}
|
||||
|
||||
public void setRadiusGravity(float r) {
|
||||
mTweenRadius = r;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public float getRadiusGravity() {
|
||||
return mTweenRadius;
|
||||
}
|
||||
|
||||
public void setXGravity(float x) {
|
||||
mTweenX = x;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public float getXGravity() {
|
||||
return mTweenX;
|
||||
}
|
||||
|
||||
public void setYGravity(float y) {
|
||||
mTweenY = y;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public float getYGravity() {
|
||||
return mTweenY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the ripple centered at (0,0) using the specified paint.
|
||||
*/
|
||||
public boolean draw(Canvas c, Paint p) {
|
||||
return drawSoftware(c, p);
|
||||
}
|
||||
|
||||
private boolean drawSoftware(Canvas c, Paint p) {
|
||||
boolean hasContent = false;
|
||||
|
||||
p.setColor(mColorOpaque);
|
||||
final int alpha = MathUtils.clamp((int) (255 * mOpacity + 0.5f), 0, 255);
|
||||
final float radius = MathUtils.lerp(0, mOuterRadius, mTweenRadius);
|
||||
if (alpha > 0 && radius > 0) {
|
||||
final float x = MathUtils.lerp(
|
||||
mClampedStartingX - mBounds.exactCenterX(), mOuterX, mTweenX);
|
||||
final float y = MathUtils.lerp(
|
||||
mClampedStartingY - mBounds.exactCenterY(), mOuterY, mTweenY);
|
||||
p.setAlpha(alpha);
|
||||
p.setStyle(Style.FILL);
|
||||
c.drawCircle(x, y, radius, p);
|
||||
hasContent = true;
|
||||
}
|
||||
|
||||
return hasContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum bounds of the ripple relative to the ripple center.
|
||||
*/
|
||||
public void getBounds(Rect bounds) {
|
||||
final int outerX = (int) mOuterX;
|
||||
final int outerY = (int) mOuterY;
|
||||
final int r = (int) mOuterRadius + 1;
|
||||
bounds.set(outerX - r, outerY - r, outerX + r, outerY + r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the starting position relative to the drawable bounds. No-op if
|
||||
* the ripple has already entered.
|
||||
*/
|
||||
public void move(float x, float y) {
|
||||
mStartingX = x;
|
||||
mStartingY = y;
|
||||
|
||||
clampStartingPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the enter animation.
|
||||
*/
|
||||
public void enter() {
|
||||
cancel();
|
||||
|
||||
final int radiusDuration = (int)
|
||||
(1000 * Math.sqrt(mOuterRadius / WAVE_TOUCH_DOWN_ACCELERATION * mDensity) + 0.5);
|
||||
|
||||
final ObjectAnimator radius = ObjectAnimator.ofFloat(this, "radiusGravity", 1);
|
||||
radius.setDuration(radiusDuration);
|
||||
radius.setInterpolator(LINEAR_INTERPOLATOR);
|
||||
radius.setStartDelay(RIPPLE_ENTER_DELAY);
|
||||
|
||||
final ObjectAnimator cX = ObjectAnimator.ofFloat(this, "xGravity", 1);
|
||||
cX.setDuration(radiusDuration);
|
||||
cX.setInterpolator(LINEAR_INTERPOLATOR);
|
||||
cX.setStartDelay(RIPPLE_ENTER_DELAY);
|
||||
|
||||
final ObjectAnimator cY = ObjectAnimator.ofFloat(this, "yGravity", 1);
|
||||
cY.setDuration(radiusDuration);
|
||||
cY.setInterpolator(LINEAR_INTERPOLATOR);
|
||||
cY.setStartDelay(RIPPLE_ENTER_DELAY);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
radius.setAutoCancel(true);
|
||||
cX.setAutoCancel(true);
|
||||
cY.setAutoCancel(true);
|
||||
}
|
||||
|
||||
mAnimRadius = radius;
|
||||
mAnimX = cX;
|
||||
mAnimY = cY;
|
||||
|
||||
// Enter animations always run on the UI thread, since it's unlikely
|
||||
// that anything interesting is happening until the user lifts their
|
||||
// finger.
|
||||
radius.start();
|
||||
cX.start();
|
||||
cY.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the exit animation.
|
||||
*/
|
||||
public void exit() {
|
||||
cancel();
|
||||
|
||||
final float radius = MathUtils.lerp(0, mOuterRadius, mTweenRadius);
|
||||
final float remaining;
|
||||
if (mAnimRadius != null && mAnimRadius.isRunning()) {
|
||||
remaining = mOuterRadius - radius;
|
||||
} else {
|
||||
remaining = mOuterRadius;
|
||||
}
|
||||
|
||||
final int radiusDuration = (int) (1000 * Math.sqrt(remaining / (WAVE_TOUCH_UP_ACCELERATION
|
||||
+ WAVE_TOUCH_DOWN_ACCELERATION) * mDensity) + 0.5);
|
||||
final int opacityDuration = (int) (1000 * 1 / WAVE_OPACITY_DECAY_VELOCITY + 0.5f);
|
||||
|
||||
exitSoftware(radiusDuration, opacityDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jump all animations to their end state. The caller is responsible for
|
||||
* removing the ripple from the list of animating ripples.
|
||||
*/
|
||||
public void jump() {
|
||||
mCanceled = true;
|
||||
endSoftwareAnimations();
|
||||
mCanceled = false;
|
||||
}
|
||||
|
||||
private void endSoftwareAnimations() {
|
||||
if (mAnimRadius != null) {
|
||||
mAnimRadius.end();
|
||||
mAnimRadius = null;
|
||||
}
|
||||
|
||||
if (mAnimOpacity != null) {
|
||||
mAnimOpacity.end();
|
||||
mAnimOpacity = null;
|
||||
}
|
||||
|
||||
if (mAnimX != null) {
|
||||
mAnimX.end();
|
||||
mAnimX = null;
|
||||
}
|
||||
|
||||
if (mAnimY != null) {
|
||||
mAnimY.end();
|
||||
mAnimY = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void exitSoftware(int radiusDuration, int opacityDuration) {
|
||||
final ObjectAnimator radiusAnim = ObjectAnimator.ofFloat(this, "radiusGravity", 1);
|
||||
radiusAnim.setDuration(radiusDuration);
|
||||
radiusAnim.setInterpolator(DECEL_INTERPOLATOR);
|
||||
|
||||
final ObjectAnimator xAnim = ObjectAnimator.ofFloat(this, "xGravity", 1);
|
||||
xAnim.setDuration(radiusDuration);
|
||||
xAnim.setInterpolator(DECEL_INTERPOLATOR);
|
||||
|
||||
final ObjectAnimator yAnim = ObjectAnimator.ofFloat(this, "yGravity", 1);
|
||||
yAnim.setDuration(radiusDuration);
|
||||
yAnim.setInterpolator(DECEL_INTERPOLATOR);
|
||||
|
||||
final ObjectAnimator opacityAnim = ObjectAnimator.ofFloat(this, "opacity", 0);
|
||||
opacityAnim.setDuration(opacityDuration);
|
||||
opacityAnim.setInterpolator(LINEAR_INTERPOLATOR);
|
||||
opacityAnim.addListener(mAnimationListener);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
radiusAnim.setAutoCancel(true);
|
||||
xAnim.setAutoCancel(true);
|
||||
yAnim.setAutoCancel(true);
|
||||
opacityAnim.setAutoCancel(true);
|
||||
}
|
||||
|
||||
mAnimRadius = radiusAnim;
|
||||
mAnimOpacity = opacityAnim;
|
||||
mAnimX = xAnim;
|
||||
mAnimY = yAnim;
|
||||
|
||||
radiusAnim.start();
|
||||
opacityAnim.start();
|
||||
xAnim.start();
|
||||
yAnim.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all animations. The caller is responsible for removing
|
||||
* the ripple from the list of animating ripples.
|
||||
*/
|
||||
public void cancel() {
|
||||
mCanceled = true;
|
||||
cancelSoftwareAnimations();
|
||||
mCanceled = false;
|
||||
}
|
||||
|
||||
private void cancelSoftwareAnimations() {
|
||||
if (mAnimRadius != null) {
|
||||
mAnimRadius.cancel();
|
||||
mAnimRadius = null;
|
||||
}
|
||||
|
||||
if (mAnimOpacity != null) {
|
||||
mAnimOpacity.cancel();
|
||||
mAnimOpacity = null;
|
||||
}
|
||||
|
||||
if (mAnimX != null) {
|
||||
mAnimX.cancel();
|
||||
mAnimX = null;
|
||||
}
|
||||
|
||||
if (mAnimY != null) {
|
||||
mAnimY.cancel();
|
||||
mAnimY = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void removeSelf() {
|
||||
// The owner will invalidate itself.
|
||||
if (!mCanceled) {
|
||||
mOwner.removeRipple(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidateSelf() {
|
||||
mOwner.invalidateSelf();
|
||||
}
|
||||
|
||||
private final AnimatorListenerAdapter mAnimationListener = new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
removeSelf();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Interpolator with a smooth log deceleration
|
||||
*/
|
||||
private static final class LogInterpolator implements Interpolator {
|
||||
@Override
|
||||
public float getInterpolation(float input) {
|
||||
return 1 - (float) Math.pow(400, -input * 1.4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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
|
||||
* 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.effect.ripple;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
|
||||
/**
|
||||
* Draws a Material ripple.
|
||||
*/
|
||||
class RippleBackground {
|
||||
private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
||||
|
||||
private static final float GLOBAL_SPEED = 1.0f;
|
||||
private static final float WAVE_OPACITY_DECAY_VELOCITY = 3.0f / GLOBAL_SPEED;
|
||||
private static final float WAVE_OUTER_OPACITY_EXIT_VELOCITY_MAX = 4.5f * GLOBAL_SPEED;
|
||||
private static final float WAVE_OUTER_OPACITY_EXIT_VELOCITY_MIN = 1.5f * GLOBAL_SPEED;
|
||||
private static final float WAVE_OUTER_OPACITY_ENTER_VELOCITY = 10.0f * GLOBAL_SPEED;
|
||||
private static final float WAVE_OUTER_SIZE_INFLUENCE_MAX = 200f;
|
||||
private static final float WAVE_OUTER_SIZE_INFLUENCE_MIN = 40f;
|
||||
|
||||
private final RippleOwner mOwner;
|
||||
|
||||
/** Bounds used for computing max radius. */
|
||||
private final Rect mBounds;
|
||||
|
||||
/** Full-opacity color for drawing this ripple. */
|
||||
private int mColorOpaque;
|
||||
|
||||
/** Maximum alpha value for drawing this ripple. */
|
||||
private int mColorAlpha;
|
||||
|
||||
/** Maximum ripple radius. */
|
||||
private float mOuterRadius;
|
||||
|
||||
/** Screen density used to adjust pixel-based velocities. */
|
||||
private float mDensity;
|
||||
|
||||
// Software animators.
|
||||
private ObjectAnimator mAnimOuterOpacity;
|
||||
|
||||
// Software rendering properties.
|
||||
private float mOuterOpacity = 0;
|
||||
private float mOuterX;
|
||||
private float mOuterY;
|
||||
|
||||
/** Whether we have an explicit maximum radius. */
|
||||
private boolean mHasMaxRadius;
|
||||
|
||||
/**
|
||||
* Creates a new ripple.
|
||||
*/
|
||||
public RippleBackground(RippleOwner owner, Rect bounds) {
|
||||
mOwner = owner;
|
||||
mBounds = bounds;
|
||||
}
|
||||
|
||||
public void setup(int maxRadius, int color, float density) {
|
||||
mColorOpaque = color | 0xFF000000;
|
||||
mColorAlpha = Color.alpha(color) / 2;
|
||||
|
||||
if (maxRadius != RippleOwner.RADIUS_AUTO) {
|
||||
mHasMaxRadius = true;
|
||||
mOuterRadius = maxRadius;
|
||||
} else {
|
||||
final float halfWidth = mBounds.width() / 2.0f;
|
||||
final float halfHeight = mBounds.height() / 2.0f;
|
||||
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
|
||||
}
|
||||
|
||||
mOuterX = 0;
|
||||
mOuterY = 0;
|
||||
mDensity = density;
|
||||
}
|
||||
|
||||
public void onHotspotBoundsChanged() {
|
||||
if (!mHasMaxRadius) {
|
||||
final float halfWidth = mBounds.width() / 2.0f;
|
||||
final float halfHeight = mBounds.height() / 2.0f;
|
||||
mOuterRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOuterOpacity(float a) {
|
||||
mOuterOpacity = a;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public float getOuterOpacity() {
|
||||
return mOuterOpacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the ripple centered at (0,0) using the specified paint.
|
||||
*/
|
||||
public boolean draw(Canvas c, Paint p) {
|
||||
return drawSoftware(c, p);
|
||||
}
|
||||
|
||||
public boolean shouldDraw() {
|
||||
final int outerAlpha = (int) (mColorAlpha * mOuterOpacity + 0.5f);
|
||||
return outerAlpha > 0 && mOuterRadius > 0;
|
||||
}
|
||||
|
||||
private boolean drawSoftware(Canvas c, Paint p) {
|
||||
boolean hasContent = false;
|
||||
|
||||
p.setColor(mColorOpaque);
|
||||
final int outerAlpha = (int) (mColorAlpha * mOuterOpacity + 0.5f);
|
||||
if (outerAlpha > 0 && mOuterRadius > 0) {
|
||||
p.setAlpha(outerAlpha);
|
||||
p.setStyle(Style.FILL);
|
||||
c.drawCircle(mOuterX, mOuterY, mOuterRadius, p);
|
||||
hasContent = true;
|
||||
}
|
||||
|
||||
return hasContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum bounds of the ripple relative to the ripple center.
|
||||
*/
|
||||
public void getBounds(Rect bounds) {
|
||||
final int outerX = (int) mOuterX;
|
||||
final int outerY = (int) mOuterY;
|
||||
final int r = (int) mOuterRadius + 1;
|
||||
bounds.set(outerX - r, outerY - r, outerX + r, outerY + r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the enter animation.
|
||||
*/
|
||||
public void enter() {
|
||||
cancel();
|
||||
|
||||
final int outerDuration = (int) (1000 * 1.0f / WAVE_OUTER_OPACITY_ENTER_VELOCITY);
|
||||
final ObjectAnimator outer = ObjectAnimator.ofFloat(this, "outerOpacity", 0, 1);
|
||||
outer.setDuration(outerDuration);
|
||||
outer.setInterpolator(LINEAR_INTERPOLATOR);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
outer.setAutoCancel(true);
|
||||
}
|
||||
|
||||
mAnimOuterOpacity = outer;
|
||||
|
||||
// Enter animations always run on the UI thread, since it's unlikely
|
||||
// that anything interesting is happening until the user lifts their
|
||||
// finger.
|
||||
outer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the exit animation.
|
||||
*/
|
||||
public void exit() {
|
||||
cancel();
|
||||
|
||||
// Scale the outer max opacity and opacity velocity based
|
||||
// on the size of the outer radius.
|
||||
final int opacityDuration = (int) (1000 / WAVE_OPACITY_DECAY_VELOCITY + 0.5f);
|
||||
final float outerSizeInfluence = MathUtils.clamp(
|
||||
(mOuterRadius - WAVE_OUTER_SIZE_INFLUENCE_MIN * mDensity)
|
||||
/ (WAVE_OUTER_SIZE_INFLUENCE_MAX * mDensity), 0, 1);
|
||||
final float outerOpacityVelocity = MathUtils.lerp(WAVE_OUTER_OPACITY_EXIT_VELOCITY_MIN,
|
||||
WAVE_OUTER_OPACITY_EXIT_VELOCITY_MAX, outerSizeInfluence);
|
||||
|
||||
// Determine at what time the inner and outer opacity intersect.
|
||||
// inner(t) = mOpacity - t * WAVE_OPACITY_DECAY_VELOCITY / 1000
|
||||
// outer(t) = mOuterOpacity + t * WAVE_OUTER_OPACITY_VELOCITY / 1000
|
||||
final int inflectionDuration = Math.max(0, (int) (1000 * (1 - mOuterOpacity)
|
||||
/ (WAVE_OPACITY_DECAY_VELOCITY + outerOpacityVelocity) + 0.5f));
|
||||
final int inflectionOpacity = (int) (mColorAlpha * (mOuterOpacity
|
||||
+ inflectionDuration * outerOpacityVelocity * outerSizeInfluence / 1000) + 0.5f);
|
||||
|
||||
exitSoftware(opacityDuration, inflectionDuration, inflectionOpacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jump all animations to their end state. The caller is responsible for
|
||||
* removing the ripple from the list of animating ripples.
|
||||
*/
|
||||
public void jump() {
|
||||
endSoftwareAnimations();
|
||||
}
|
||||
|
||||
private void endSoftwareAnimations() {
|
||||
if (mAnimOuterOpacity != null) {
|
||||
mAnimOuterOpacity.end();
|
||||
mAnimOuterOpacity = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void exitSoftware(int opacityDuration, int inflectionDuration, int inflectionOpacity) {
|
||||
final ObjectAnimator outerOpacityAnim;
|
||||
if (inflectionDuration > 0) {
|
||||
// Outer opacity continues to increase for a bit.
|
||||
outerOpacityAnim = ObjectAnimator.ofFloat(this,
|
||||
"outerOpacity", inflectionOpacity / 255.0f);
|
||||
outerOpacityAnim.setDuration(inflectionDuration);
|
||||
outerOpacityAnim.setInterpolator(LINEAR_INTERPOLATOR);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
outerOpacityAnim.setAutoCancel(true);
|
||||
}
|
||||
|
||||
// Chain the outer opacity exit animation.
|
||||
final int outerDuration = opacityDuration - inflectionDuration;
|
||||
if (outerDuration > 0) {
|
||||
outerOpacityAnim.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
final ObjectAnimator outerFadeOutAnim = ObjectAnimator.ofFloat(
|
||||
RippleBackground.this, "outerOpacity", 0);
|
||||
outerFadeOutAnim.setDuration(outerDuration);
|
||||
outerFadeOutAnim.setInterpolator(LINEAR_INTERPOLATOR);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
outerFadeOutAnim.setAutoCancel(true);
|
||||
}
|
||||
|
||||
mAnimOuterOpacity = outerFadeOutAnim;
|
||||
|
||||
outerFadeOutAnim.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
animation.removeListener(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
outerOpacityAnim = ObjectAnimator.ofFloat(this, "outerOpacity", 0);
|
||||
outerOpacityAnim.setDuration(opacityDuration);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
outerOpacityAnim.setAutoCancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
mAnimOuterOpacity = outerOpacityAnim;
|
||||
|
||||
outerOpacityAnim.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel all animations. The caller is responsible for removing
|
||||
* the ripple from the list of animating ripples.
|
||||
*/
|
||||
public void cancel() {
|
||||
cancelSoftwareAnimations();
|
||||
}
|
||||
|
||||
private void cancelSoftwareAnimations() {
|
||||
if (mAnimOuterOpacity != null) {
|
||||
mAnimOuterOpacity.cancel();
|
||||
mAnimOuterOpacity = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidateSelf() {
|
||||
mOwner.invalidateSelf();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,579 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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
|
||||
* 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.effect.ripple;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.hippo.ehviewer.widget.Hotspotable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Drawable that shows a ripple effect in response to state changes. The
|
||||
* anchoring position of the ripple for a given state may be specified by
|
||||
* calling {@link #setHotspot(float, float)} with the corresponding state
|
||||
* attribute identifier.
|
||||
* <p>
|
||||
* A touch feedback drawable may contain multiple child layers, including a
|
||||
* special mask layer that is not drawn to the screen. A single layer may be set
|
||||
* as the mask by specifying its android:id value as {@link android.R.id#mask}.
|
||||
* <pre>
|
||||
* <code><!-- A red ripple masked against an opaque rectangle. --/>
|
||||
* <ripple android:color="#ffff0000">
|
||||
* <item android:id="@android:id/mask"
|
||||
* android:drawable="@android:color/white" />
|
||||
* <ripple /></code>
|
||||
* </pre>
|
||||
* <p>
|
||||
* If a mask layer is set, the ripple effect will be masked against that layer
|
||||
* before it is drawn over the composite of the remaining child layers.
|
||||
* <p>
|
||||
* If no mask layer is set, the ripple effect is masked against the composite
|
||||
* of the child layers.
|
||||
* <pre>
|
||||
* <code><!-- A blue ripple drawn atop a black rectangle. --/>
|
||||
* <ripple android:color="#ff00ff00">
|
||||
* <item android:drawable="@android:color/black" />
|
||||
* <ripple />
|
||||
*
|
||||
* <!-- A red ripple drawn atop a drawable resource. --/>
|
||||
* <ripple android:color="#ff00ff00">
|
||||
* <item android:drawable="@drawable/my_drawable" />
|
||||
* <ripple /></code>
|
||||
* </pre>
|
||||
* <p>
|
||||
* If no child layers or mask is specified and the ripple is set as a View
|
||||
* background, the ripple will be drawn atop the first available parent
|
||||
* background within the View's hierarchy. In this case, the drawing region
|
||||
* may extend outside of the Drawable bounds.
|
||||
* <pre>
|
||||
* <code><!-- An unbounded green ripple. --/>
|
||||
* <ripple android:color="#ff0000ff" /></code>
|
||||
* </pre>
|
||||
*
|
||||
* @attr ref android.R.styleable#RippleDrawable_color
|
||||
*/
|
||||
public class RippleDrawable extends Drawable implements RippleOwner, Hotspotable {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = RippleDrawable.class.getSimpleName();
|
||||
|
||||
/** The maximum number of ripples supported. */
|
||||
private static final int MAX_RIPPLES = 10;
|
||||
|
||||
/** Current ripple effect bounds, used to constrain ripple effects. */
|
||||
private final Rect mHotspotBounds = new Rect();
|
||||
|
||||
/** The current background. May be actively animating or pending entry. */
|
||||
private RippleBackground mBackground;
|
||||
|
||||
/** Whether we expect to draw a background when visible. */
|
||||
private boolean mBackgroundActive;
|
||||
|
||||
/** The current ripple. May be actively animating or pending entry. */
|
||||
private Ripple mRipple;
|
||||
|
||||
/** Whether we expect to draw a ripple when visible. */
|
||||
private boolean mRippleActive;
|
||||
|
||||
// Hotspot coordinates that are awaiting activation.
|
||||
private float mPendingX;
|
||||
private float mPendingY;
|
||||
private boolean mHasPending;
|
||||
|
||||
/**
|
||||
* Lazily-created array of actively animating ripples. Inactive ripples are
|
||||
* pruned during draw(). The locations of these will not change.
|
||||
*/
|
||||
private Ripple[] mExitingRipples;
|
||||
private int mExitingRipplesCount = 0;
|
||||
|
||||
/** Paint used to control appearance of ripples. */
|
||||
private Paint mRipplePaint;
|
||||
|
||||
/** Target density of the display into which ripples are drawn. */
|
||||
private final float mDensity = 1.0f;
|
||||
|
||||
/** Whether bounds are being overridden. */
|
||||
private boolean mOverrideBounds;
|
||||
|
||||
/**
|
||||
* Whether the next draw MUST draw something to canvas. Used to work around
|
||||
* a bug in hardware invalidation following a render thread-accelerated
|
||||
* animation.
|
||||
*/
|
||||
private boolean mNeedsDraw;
|
||||
|
||||
private ColorStateList mColor = ColorStateList.valueOf(Color.MAGENTA);
|
||||
|
||||
private int mMaxRadius = RADIUS_AUTO;
|
||||
|
||||
private final Drawable mContent;
|
||||
|
||||
RippleDrawable(ColorStateList color, Drawable content) {
|
||||
setColor(color);
|
||||
|
||||
mContent = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public void jumpToCurrentState() {
|
||||
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
|
||||
super.jumpToCurrentState();
|
||||
}
|
||||
|
||||
boolean needsDraw = false;
|
||||
|
||||
if (mRipple != null) {
|
||||
mRipple.jump();
|
||||
}
|
||||
|
||||
if (mBackground != null) {
|
||||
mBackground.jump();
|
||||
}
|
||||
|
||||
needsDraw |= cancelExitingRipples();
|
||||
|
||||
mNeedsDraw = needsDraw;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
private boolean cancelExitingRipples() {
|
||||
final int count = mExitingRipplesCount;
|
||||
final Ripple[] ripples = mExitingRipples;
|
||||
for (int i = 0; i < count; i++) {
|
||||
ripples[i].cancel();
|
||||
}
|
||||
|
||||
if (ripples != null) {
|
||||
Arrays.fill(ripples, 0, count, null);
|
||||
}
|
||||
mExitingRipplesCount = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
mColor.withAlpha(alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAlpha() {
|
||||
return Color.alpha(mColor.getDefaultColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
//TODO Paint.setColorFilter(filter) ?
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
// Worst-case scenario.
|
||||
return PixelFormat.TRANSLUCENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onStateChange(int[] stateSet) {
|
||||
boolean changed = false;
|
||||
if (mContent != null)
|
||||
changed |= mContent.setState(stateSet);
|
||||
|
||||
boolean enabled = false;
|
||||
boolean pressed = false;
|
||||
boolean focused = false;
|
||||
|
||||
for (int state : stateSet) {
|
||||
if (state == android.R.attr.state_enabled) {
|
||||
enabled = true;
|
||||
}
|
||||
if (state == android.R.attr.state_focused) {
|
||||
focused = true;
|
||||
}
|
||||
if (state == android.R.attr.state_pressed) {
|
||||
pressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
setRippleActive(enabled && pressed);
|
||||
setBackgroundActive(focused || (enabled && pressed));
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void setRippleActive(boolean active) {
|
||||
if (mRippleActive != active) {
|
||||
mRippleActive = active;
|
||||
if (active) {
|
||||
tryRippleEnter();
|
||||
} else {
|
||||
tryRippleExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setBackgroundActive(boolean active) {
|
||||
if (mBackgroundActive != active) {
|
||||
mBackgroundActive = active;
|
||||
if (active) {
|
||||
tryBackgroundEnter();
|
||||
} else {
|
||||
tryBackgroundExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
super.onBoundsChange(bounds);
|
||||
|
||||
if (!mOverrideBounds) {
|
||||
mHotspotBounds.set(bounds);
|
||||
onHotspotBoundsChanged();
|
||||
}
|
||||
|
||||
if (mContent != null)
|
||||
mContent.setBounds(bounds);
|
||||
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setVisible(boolean visible, boolean restart) {
|
||||
final boolean changed = super.setVisible(visible, restart);
|
||||
|
||||
if (!visible) {
|
||||
clearHotspots();
|
||||
} else if (changed) {
|
||||
// If we just became visible, ensure the background and ripple
|
||||
// visibilities are consistent with their internal states.
|
||||
if (mRippleActive) {
|
||||
tryRippleEnter();
|
||||
}
|
||||
|
||||
if (mBackgroundActive) {
|
||||
tryBackgroundEnter();
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateful() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setColor(ColorStateList color) {
|
||||
int alpha = Color.alpha(color.getDefaultColor());
|
||||
mColor = color.withAlpha((int) (alpha * (1 - 0.001f * alpha)));
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHotspot(float x, float y) {
|
||||
if (mRipple == null || mBackground == null) {
|
||||
mPendingX = x;
|
||||
mPendingY = y;
|
||||
mHasPending = true;
|
||||
}
|
||||
|
||||
if (mRipple != null) {
|
||||
mRipple.move(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an active hotspot at the specified location.
|
||||
*/
|
||||
private void tryBackgroundEnter() {
|
||||
if (mBackground == null) {
|
||||
mBackground = new RippleBackground(this, mHotspotBounds);
|
||||
}
|
||||
|
||||
final int color = mColor.getColorForState(getState(), Color.TRANSPARENT);
|
||||
mBackground.setup(mMaxRadius, color, mDensity);
|
||||
mBackground.enter();
|
||||
}
|
||||
|
||||
private void tryBackgroundExit() {
|
||||
if (mBackground != null) {
|
||||
// Don't null out the background, we need it to draw!
|
||||
mBackground.exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to start an enter animation for the active hotspot. Fails if
|
||||
* there are too many animating ripples.
|
||||
*/
|
||||
private void tryRippleEnter() {
|
||||
if (mExitingRipplesCount >= MAX_RIPPLES) {
|
||||
// This should never happen unless the user is tapping like a maniac
|
||||
// or there is a bug that's preventing ripples from being removed.
|
||||
return;
|
||||
}
|
||||
|
||||
if (mRipple == null) {
|
||||
final float x;
|
||||
final float y;
|
||||
if (mHasPending) {
|
||||
mHasPending = false;
|
||||
x = mPendingX;
|
||||
y = mPendingY;
|
||||
} else {
|
||||
x = mHotspotBounds.exactCenterX();
|
||||
y = mHotspotBounds.exactCenterY();
|
||||
}
|
||||
mRipple = new Ripple(this, mHotspotBounds, x, y);
|
||||
}
|
||||
|
||||
final int color = mColor.getColorForState(getState(), Color.TRANSPARENT);
|
||||
mRipple.setup(mMaxRadius, color, mDensity);
|
||||
mRipple.enter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to start an exit animation for the active hotspot. Fails if
|
||||
* there is no active hotspot.
|
||||
*/
|
||||
private void tryRippleExit() {
|
||||
if (mRipple != null) {
|
||||
if (mExitingRipples == null) {
|
||||
mExitingRipples = new Ripple[MAX_RIPPLES];
|
||||
}
|
||||
mExitingRipples[mExitingRipplesCount++] = mRipple;
|
||||
mRipple.exit();
|
||||
mRipple = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels and removes the active ripple, all exiting ripples, and the
|
||||
* background. Nothing will be drawn after this method is called.
|
||||
*/
|
||||
private void clearHotspots() {
|
||||
boolean needsDraw = false;
|
||||
|
||||
if (mRipple != null) {
|
||||
mRipple.cancel();
|
||||
mRipple = null;
|
||||
}
|
||||
|
||||
if (mBackground != null) {
|
||||
mBackground.cancel();
|
||||
mBackground = null;
|
||||
}
|
||||
|
||||
needsDraw |= cancelExitingRipples();
|
||||
|
||||
mNeedsDraw = needsDraw;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHotspotBounds(int left, int top, int right, int bottom) {
|
||||
mOverrideBounds = true;
|
||||
mHotspotBounds.set(left, top, right, bottom);
|
||||
|
||||
onHotspotBoundsChanged();
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void getHotspotBounds(Rect outRect) {
|
||||
outRect.set(mHotspotBounds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all the animating ripples that the hotspot bounds have changed.
|
||||
*/
|
||||
private void onHotspotBoundsChanged() {
|
||||
final int count = mExitingRipplesCount;
|
||||
final Ripple[] ripples = mExitingRipples;
|
||||
for (int i = 0; i < count; i++) {
|
||||
ripples[i].onHotspotBoundsChanged();
|
||||
}
|
||||
|
||||
if (mRipple != null) {
|
||||
mRipple.onHotspotBoundsChanged();
|
||||
}
|
||||
|
||||
if (mBackground != null) {
|
||||
mBackground.onHotspotBoundsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
final boolean drawNonMaskContent = mContent != null;
|
||||
final Rect bounds = getDirtyBounds();
|
||||
final int saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
|
||||
canvas.clipRect(bounds);
|
||||
|
||||
// If we have content, draw it into a layer first.
|
||||
if (drawNonMaskContent) {
|
||||
drawContentLayer(canvas, bounds);
|
||||
}
|
||||
|
||||
// If we have a background and a non-opaque mask, draw the masking layer.
|
||||
drawBackgroundLayer(canvas, bounds);
|
||||
|
||||
// If we have ripples and a non-opaque mask, draw the masking layer.
|
||||
drawRippleLayer(canvas, bounds);
|
||||
|
||||
// If we failed to draw anything and we just canceled animations, at
|
||||
// least draw a color so that hardware invalidation works correctly.
|
||||
if (mNeedsDraw) {
|
||||
canvas.drawColor(Color.TRANSPARENT);
|
||||
|
||||
// Request another draw so we can avoid adding a transparent layer
|
||||
// during the next display list refresh.
|
||||
invalidateSelf();
|
||||
}
|
||||
mNeedsDraw = false;
|
||||
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a ripple from the exiting ripple list.
|
||||
*
|
||||
* @param ripple the ripple to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeRipple(Ripple ripple) {
|
||||
// Ripple ripple ripple ripple. Ripple ripple.
|
||||
final Ripple[] ripples = mExitingRipples;
|
||||
final int count = mExitingRipplesCount;
|
||||
final int index = getRippleIndex(ripple);
|
||||
if (index >= 0) {
|
||||
System.arraycopy(ripples, index + 1, ripples, index, count - (index + 1));
|
||||
ripples[count - 1] = null;
|
||||
mExitingRipplesCount--;
|
||||
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
private int getRippleIndex(Ripple ripple) {
|
||||
final Ripple[] ripples = mExitingRipples;
|
||||
final int count = mExitingRipplesCount;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (ripples[i] == ripple) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void drawContentLayer(Canvas canvas, Rect bounds) {
|
||||
mContent.draw(canvas);
|
||||
}
|
||||
|
||||
private void drawBackgroundLayer(
|
||||
Canvas canvas, Rect bounds) {
|
||||
if (mBackground != null && mBackground.shouldDraw()) {
|
||||
final float x = mHotspotBounds.exactCenterX();
|
||||
final float y = mHotspotBounds.exactCenterY();
|
||||
canvas.translate(x, y);
|
||||
mBackground.draw(canvas, getRipplePaint());
|
||||
canvas.translate(-x, -y);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawRippleLayer(Canvas canvas, Rect bounds) {
|
||||
int restoreTranslate = -1;
|
||||
|
||||
// Translate the canvas to the current hotspot bounds.
|
||||
restoreTranslate = canvas.save();
|
||||
canvas.translate(mHotspotBounds.exactCenterX(), mHotspotBounds.exactCenterY());
|
||||
|
||||
// Draw ripples and update the animating ripples array.
|
||||
final int count = mExitingRipplesCount;
|
||||
final Ripple[] ripples = mExitingRipples;
|
||||
for (int i = 0; i <= count; i++) {
|
||||
final Ripple ripple;
|
||||
if (i < count) {
|
||||
ripple = ripples[i];
|
||||
} else if (mRipple != null) {
|
||||
ripple = mRipple;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
ripple.draw(canvas, getRipplePaint());
|
||||
}
|
||||
|
||||
// Always restore the translation.
|
||||
if (restoreTranslate >= 0) {
|
||||
canvas.restoreToCount(restoreTranslate);
|
||||
}
|
||||
}
|
||||
|
||||
private Paint getRipplePaint() {
|
||||
if (mRipplePaint == null) {
|
||||
mRipplePaint = new Paint();
|
||||
mRipplePaint.setAntiAlias(true);
|
||||
}
|
||||
return mRipplePaint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getDirtyBounds() {
|
||||
return getBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum ripple radius in pixels. The default value of
|
||||
* {@link #RADIUS_AUTO} defines the radius as the distance from the center
|
||||
* of the drawable bounds (or hotspot bounds, if specified) to a corner.
|
||||
*
|
||||
* @param maxRadius the maximum ripple radius in pixels or
|
||||
* {@link #RADIUS_AUTO} to automatically determine the maximum
|
||||
* radius based on the bounds
|
||||
* @see #getMaxRadius()
|
||||
* @see #setHotspotBounds(int, int, int, int)
|
||||
* @hide
|
||||
*/
|
||||
public void setMaxRadius(int maxRadius) {
|
||||
if (maxRadius != RADIUS_AUTO && maxRadius < 0) {
|
||||
throw new IllegalArgumentException("maxRadius must be RADIUS_AUTO or >= 0");
|
||||
}
|
||||
|
||||
mMaxRadius = maxRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum ripple radius in pixels, or {@link #RADIUS_AUTO} if
|
||||
* the radius is determined automatically
|
||||
* @see #setMaxRadius(int)
|
||||
* @hide
|
||||
*/
|
||||
public int getMaxRadius() {
|
||||
return mMaxRadius;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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
|
||||
* 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.effect.ripple;
|
||||
|
||||
|
||||
public interface RippleOwner {
|
||||
/**
|
||||
* Constant for automatically determining the maximum ripple radius.
|
||||
*/
|
||||
public static final int RADIUS_AUTO = -1;
|
||||
|
||||
public void removeRipple(Ripple ripple);
|
||||
|
||||
public void invalidateSelf();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.effect.ripple;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.widget.HotspotTouchHelper;
|
||||
|
||||
|
||||
public final class RippleSalon {
|
||||
|
||||
private static final boolean USE_OLD_RIPPLE =
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
|
||||
|
||||
private static final Drawable MASK = new ColorDrawable(Color.BLACK);
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static void addRipple(View v, ColorStateList color) {
|
||||
addRipple(v, color, v.getBackground());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static void addRipple(View v, ColorStateList color, Drawable content) {
|
||||
if (USE_OLD_RIPPLE) {
|
||||
RippleDrawable rippleDrawable = new RippleDrawable(color, content);
|
||||
v.setOnTouchListener(new HotspotTouchHelper(rippleDrawable));
|
||||
v.setBackgroundDrawable(rippleDrawable);
|
||||
} else {
|
||||
android.graphics.drawable.RippleDrawable rippleDrawable = new android.graphics.drawable.RippleDrawable(color, content, MASK);
|
||||
v.setBackgroundDrawable(rippleDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File renamed without changes.
+9
-1
@@ -27,6 +27,7 @@ import com.hippo.ehviewer.data.Comment;
|
||||
import com.hippo.ehviewer.data.LargePreviewList;
|
||||
import com.hippo.ehviewer.data.NormalPreviewList;
|
||||
import com.hippo.ehviewer.data.PreviewList;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
public class DetailParser {
|
||||
@@ -114,6 +115,13 @@ public class DetailParser {
|
||||
return PINING;
|
||||
}
|
||||
|
||||
p = Pattern.compile("<div class=\"d\">\n<p>([^<]+)</p>");
|
||||
m = p.matcher(body);
|
||||
if (m.find()) {
|
||||
eMesg = m.group(1);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
// Get detail
|
||||
if ((mode & DETAIL) != 0) {
|
||||
p = Pattern
|
||||
@@ -146,7 +154,7 @@ public class DetailParser {
|
||||
thumb = Utils.unescapeXml(m.group(1));
|
||||
title = Utils.unescapeXml(m.group(2));
|
||||
title_jpn = Utils.unescapeXml(m.group(3));
|
||||
category = EhClient.getType(m.group(4));
|
||||
category = EhUtils.getCategory(m.group(4));
|
||||
uploader = m.group(5);
|
||||
posted = m.group(6);
|
||||
pages = Integer.parseInt(m.group(7));
|
||||
File renamed without changes.
File renamed without changes.
+196
-244
@@ -16,6 +16,33 @@
|
||||
|
||||
package com.hippo.ehviewer.ehclient;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.AppHandler;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.ApiGalleryInfo;
|
||||
import com.hippo.ehviewer.data.Comment;
|
||||
import com.hippo.ehviewer.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.data.GalleryPopular;
|
||||
import com.hippo.ehviewer.data.LofiGalleryDetail;
|
||||
import com.hippo.ehviewer.data.PreviewList;
|
||||
import com.hippo.ehviewer.network.HttpHelper;
|
||||
import com.hippo.ehviewer.util.BgThread;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@@ -24,29 +51,6 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.AppHandler;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.Comment;
|
||||
import com.hippo.ehviewer.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.data.GalleryPopular;
|
||||
import com.hippo.ehviewer.data.ListUrls;
|
||||
import com.hippo.ehviewer.data.LofiGalleryDetail;
|
||||
import com.hippo.ehviewer.data.PreviewList;
|
||||
import com.hippo.ehviewer.network.HttpHelper;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
public class EhClient {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = EhClient.class.getSimpleName();
|
||||
@@ -62,14 +66,14 @@ public class EhClient {
|
||||
public static final long APIUID = 1363542;
|
||||
public static final String APIKEY = "f4b5407ab1727b9d08d7";
|
||||
|
||||
private static final String LOGIN_URL = "http://forums.e-hentai.org/index.php?act=Login&CODE=01";
|
||||
public static final String LOGIN_URL = "http://forums.e-hentai.org/index.php?act=Login&CODE=01";
|
||||
private static final String FORUMS_URL = "http://forums.e-hentai.org/index.php";
|
||||
|
||||
public static final String HEADER_G = "http://g.e-hentai.org/";
|
||||
public static final String HEADER_EX = "http://exhentai.org/";
|
||||
public static final String HEADER_LOFI = "http://lofi.e-hentai.org/";
|
||||
|
||||
private static final String API_EHVIEWER = "http://www.ehviewer.com/API";
|
||||
public static final String API_EHVIEWER = "http://www.ehviewer.com/API";
|
||||
|
||||
/* Avatar get code */
|
||||
public static final int GET_AVATAR_OK = 0x0;
|
||||
@@ -192,11 +196,29 @@ public class EhClient {
|
||||
}
|
||||
}
|
||||
|
||||
public String getFavoriteUrl(int index, int page) {
|
||||
return getFavoriteUrl(Config.getApiMode(), index, page);
|
||||
public String getFavoriteUrl(int page) {
|
||||
return getFavoriteUrl(Config.getApiMode(), page);
|
||||
}
|
||||
|
||||
public static String getFavoriteUrl(int mode, int index, int page) {
|
||||
public static String getFavoriteUrl(int mode, int page) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (mode) {
|
||||
case MODE_EX:
|
||||
sb.append(HEADER_EX);
|
||||
break;
|
||||
case MODE_G:
|
||||
default:
|
||||
sb.append(HEADER_G);
|
||||
break;
|
||||
}
|
||||
return sb.append("favorites.php?page=").append(page).toString();
|
||||
}
|
||||
|
||||
public String getFavoriteUrlWithCat(int index, int page) {
|
||||
return getFavoriteUrlWithCat(Config.getApiMode(), index, page);
|
||||
}
|
||||
|
||||
public static String getFavoriteUrlWithCat(int mode, int index, int page) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (mode) {
|
||||
case MODE_EX:
|
||||
@@ -263,7 +285,7 @@ public class EhClient {
|
||||
/**
|
||||
* Return avatar, if not return default avatar
|
||||
*/
|
||||
public Bitmap getAvatar() {
|
||||
public Drawable getAvatar() {
|
||||
return mInfo.getAvatar();
|
||||
}
|
||||
|
||||
@@ -374,7 +396,7 @@ public class EhClient {
|
||||
Bitmap avatar = hp.getImage(avatarUrl);
|
||||
// Set avatar if not null
|
||||
if (avatar != null)
|
||||
mInfo.setAvatar(avatar);
|
||||
mInfo.setAvatar(new BitmapDrawable(EhClient.this.mContext.getResources(), avatar));
|
||||
// notification
|
||||
listener.onGetAvatar(GET_AVATAR_OK);
|
||||
}
|
||||
@@ -885,7 +907,7 @@ public class EhClient {
|
||||
|
||||
public void comment(final String detailUrl, final String comment,
|
||||
final OnCommentListener listener) {
|
||||
new Thread(new Runnable() {
|
||||
new BgThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
@@ -1090,56 +1112,6 @@ public class EhClient {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private static final int[] CATEGORY_VALUES = {
|
||||
ListUrls.MISC,
|
||||
ListUrls.DOUJINSHI,
|
||||
ListUrls.MANGA,
|
||||
ListUrls.ARTIST_CG,
|
||||
ListUrls.GAME_CG,
|
||||
ListUrls.IMAGE_SET,
|
||||
ListUrls.COSPLAY,
|
||||
ListUrls.ASIAN_PORN,
|
||||
ListUrls.NON_H,
|
||||
ListUrls.WESTERN,
|
||||
ListUrls.UNKNOWN
|
||||
};
|
||||
|
||||
// TODO How about "Private"
|
||||
private static final String[][] CATEGORY_STRINGS = {
|
||||
new String[]{"misc"},
|
||||
new String[]{"doujinshi"},
|
||||
new String[]{"manga"},
|
||||
new String[]{"artistcg", "Artist CG Sets"},
|
||||
new String[]{"gamecg", "Game CG Sets"},
|
||||
new String[]{"imageset", "Image Sets"},
|
||||
new String[]{"cosplay"},
|
||||
new String[]{"asianporn", "Asian Porn"},
|
||||
new String[]{"non-h"},
|
||||
new String[]{"western"},
|
||||
new String[]{"unknown"}
|
||||
};
|
||||
|
||||
public static int getType(String type) {
|
||||
int i;
|
||||
for (i = 0; i < CATEGORY_STRINGS.length - 1; i++) {
|
||||
for (String str : CATEGORY_STRINGS[i])
|
||||
if (str.equalsIgnoreCase(type))
|
||||
return CATEGORY_VALUES[i];
|
||||
}
|
||||
|
||||
return CATEGORY_VALUES[i];
|
||||
}
|
||||
|
||||
public static String getType(int type) {
|
||||
int i;
|
||||
for (i = 0; i < CATEGORY_VALUES.length - 1; i++) {
|
||||
if (CATEGORY_VALUES[i] == type)
|
||||
break;
|
||||
}
|
||||
return CATEGORY_STRINGS[i][0];
|
||||
}
|
||||
|
||||
|
||||
// modifyFavorite
|
||||
public interface OnModifyFavoriteListener {
|
||||
void onSuccess(List<GalleryInfo> gis, int pageNum);
|
||||
@@ -1173,7 +1145,7 @@ public class EhClient {
|
||||
*/
|
||||
public void modifyFavorite(final int[] gids, final int dstCat, final int srcCat,
|
||||
final OnModifyFavoriteListener listener) {
|
||||
new Thread(new Runnable() {
|
||||
new BgThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int i;
|
||||
@@ -1213,7 +1185,7 @@ public class EhClient {
|
||||
args[i] = new String[]{"modifygids[]", String.valueOf(gids[i-1])};
|
||||
args[i] = new String[]{"apply", "Apply"};
|
||||
|
||||
hp.postForm(getFavoriteUrl(srcCat, 0), args);
|
||||
hp.postForm(getFavoriteUrlWithCat(srcCat, 0), args);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@@ -1231,7 +1203,7 @@ public class EhClient {
|
||||
listener.onFailure(e.getMessage());
|
||||
return;
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
new BgThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
@@ -1262,7 +1234,7 @@ public class EhClient {
|
||||
gi.title = Utils.unescapeXml(j.getString("title"));
|
||||
gi.posted = Utils.sDate.format(Long.parseLong(j.getString("posted")) * 1000);
|
||||
gi.thumb = j.getString("thumb");
|
||||
gi.category = getType(j.getString("category"));
|
||||
gi.category = EhUtils.getCategory(j.getString("category"));
|
||||
gi.uploader = j.getString("uploader");
|
||||
gi.rating = Float.parseFloat(j.getString("rating"));
|
||||
gi.generateSLang();
|
||||
@@ -1290,183 +1262,163 @@ public class EhClient {
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private static class GetGalleryMetadataPackage {
|
||||
public Map<String, ListMangaDetail> lmds;
|
||||
public OnGetGalleryMetadataListener listener;
|
||||
|
||||
public GetGalleryMetadataPackage(Map<String, ListMangaDetail> lmds,
|
||||
OnGetGalleryMetadataListener listener) {
|
||||
this.lmds = lmds;
|
||||
this.listener = listener;
|
||||
}
|
||||
public interface OnGetApiGalleryInfoListener {
|
||||
public void onSuccess(Object checkFlag, ApiGalleryInfo[] agiArray);
|
||||
public void onFailure(Object checkFlag, String eMsg);
|
||||
}
|
||||
|
||||
private static Handler getGalleryMetadataHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
OnGetGalleryMetadataListener listener =
|
||||
((GetGalleryMetadataPackage) msg.obj).listener;
|
||||
Map<String, ListMangaDetail> lmds =
|
||||
((GetGalleryMetadataPackage) msg.obj).lmds;
|
||||
if (lmds == null || lmds.size() == 0)
|
||||
listener.onFailure(msg.what);
|
||||
else
|
||||
listener.onSuccess(lmds);
|
||||
};
|
||||
};
|
||||
private class GetApiGalleryInfoResponder implements Runnable {
|
||||
private final boolean isOk;
|
||||
private final OnGetApiGalleryInfoListener listener;
|
||||
private final Object checkFlag;
|
||||
private final ApiGalleryInfo[] agiArray;
|
||||
private final String eMesg;
|
||||
|
||||
private static class GetGalleryMetadataRunnable implements Runnable {
|
||||
private String[][] gidTokens;
|
||||
private OnGetGalleryMetadataListener listener;
|
||||
|
||||
public GetGalleryMetadataRunnable(String[][] gidTokens,
|
||||
OnGetGalleryMetadataListener listener) {
|
||||
this.gidTokens = gidTokens;
|
||||
public GetApiGalleryInfoResponder(OnGetApiGalleryInfoListener listener,
|
||||
Object checkFlag, ApiGalleryInfo[] agiArray) {
|
||||
this.isOk = true;
|
||||
this.listener = listener;
|
||||
this.checkFlag = checkFlag;
|
||||
this.agiArray = agiArray;
|
||||
this.eMesg = null;
|
||||
}
|
||||
|
||||
public GetApiGalleryInfoResponder(OnGetApiGalleryInfoListener listener,
|
||||
Object checkFlag, String eMsg) {
|
||||
this.isOk = false;
|
||||
this.listener = listener;
|
||||
this.checkFlag = checkFlag;
|
||||
this.agiArray = null;
|
||||
this.eMesg = eMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int errorMessageId = R.string.em_unknown_error;
|
||||
Map<String, ListMangaDetail> lmds = new HashMap<String, ListMangaDetail>();
|
||||
if (isOk)
|
||||
listener.onSuccess(checkFlag, agiArray);
|
||||
else
|
||||
listener.onFailure(checkFlag, eMesg);
|
||||
}
|
||||
}
|
||||
|
||||
// Create post string
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
strBuf.append("{\"method\": \"gdata\",\"gidlist\": [");
|
||||
for (String[] item: gidTokens)
|
||||
strBuf.append("[" + item[0] + ",\"" + item[1] + "\"],");
|
||||
strBuf.delete(strBuf.length()-1, strBuf.length());
|
||||
strBuf.append("]}");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
errorMessageId = postJson(API_URL, strBuf.toString(),sb);
|
||||
if (sb.length() != 0) {
|
||||
String pageContent = sb.toString();
|
||||
private ApiGalleryInfo Json2Agi(JSONObject js) throws JSONException {
|
||||
ApiGalleryInfo agi = new ApiGalleryInfo();
|
||||
agi.gid = js.getInt("gid");
|
||||
agi.token = js.getString("token");
|
||||
agi.archiver_key = js.getString("archiver_key");
|
||||
agi.title = js.getString("title");
|
||||
agi.title_jpn = js.getString("title_jpn");
|
||||
agi.category = EhUtils.getCategory(js.getString("category"));
|
||||
agi.thumb = js.getString("thumb");
|
||||
agi.uploader = js.getString("uploader");
|
||||
agi.posted = Utils.sDate.format(Long.parseLong(js.getString("posted")) * 1000);
|
||||
agi.filecount = js.getString("filecount");
|
||||
agi.filesize = js.getLong("filesize");
|
||||
agi.expunged = js.getBoolean("expunged");
|
||||
agi.rating = Float.parseFloat(js.getString("rating"));
|
||||
agi.torrentcount = js.getString("torrentcount");
|
||||
JSONArray tags = js.getJSONArray("tags");
|
||||
agi.apiTags = new String[tags.length()];
|
||||
for (int j = 0; j < tags.length(); j++)
|
||||
agi.apiTags[j] = tags.getString(j);
|
||||
return agi;
|
||||
}
|
||||
|
||||
public void getApiGalleryInfo(final Object checkFlag, final int[] gids, final String[] tokens, final OnGetApiGalleryInfoListener l) {
|
||||
new BgThread() {
|
||||
@Override
|
||||
public void run() {
|
||||
GetApiGalleryInfoResponder responder;
|
||||
ApiGalleryInfo[] agiArray;
|
||||
int requstLen;
|
||||
// Create json
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd hh:mm");
|
||||
JSONObject jsonObject = new JSONObject(pageContent);
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("gmetadata");
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject jo = jsonArray.getJSONObject(i);
|
||||
if (jo.getString("error") != null)
|
||||
continue;
|
||||
ListMangaDetail lmd = new ListMangaDetail();
|
||||
lmd.gid = Long.toString(jo.getLong("gid"));
|
||||
lmd.token = jo.getString("token");
|
||||
lmd.archiver_key = jo.getString("archiver_key");
|
||||
lmd.title = jo.getString("title");
|
||||
lmd.title_jpn = jo.getString("title_jpn");
|
||||
lmd.category = getType(jo.getString("category"));
|
||||
lmd.thumb = jo.getString("thumb");
|
||||
lmd.uploader = jo.getString("uploader");
|
||||
lmd.posted = fm.format(Long.parseLong(jo.getString("posted")) * 1000);
|
||||
lmd.filecount = jo.getString("filecount");
|
||||
lmd.filesize = jo.getLong("filesize");
|
||||
lmd.expunged = jo.getBoolean("expunged");
|
||||
lmd.rating = jo.getString("rating");
|
||||
lmd.torrentcount = jo.getString("torrentcount");
|
||||
JSONArray ja = jo.getJSONArray("tags");
|
||||
int length = ja.length();
|
||||
lmd.tags = new String[1][length+1];
|
||||
lmd.tags[0][0] = "all";
|
||||
for (int j = 1; j < length+1; j++)
|
||||
lmd.tags[0][j] = ja.getString(j);
|
||||
|
||||
lmds.put(lmd.gid, lmd);
|
||||
json.put("method", "gdata");
|
||||
JSONArray jsonA = new JSONArray();
|
||||
requstLen = Math.min(gids.length, tokens.length);
|
||||
agiArray = new ApiGalleryInfo[requstLen];
|
||||
for (int i = 0; i < requstLen; i++) {
|
||||
JSONArray ja = new JSONArray();
|
||||
ja.put(gids[i]);
|
||||
ja.put(tokens[i]);
|
||||
jsonA.put(ja);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
errorMessageId = R.string.em_parser_error;
|
||||
json.put("gidlist", jsonA);
|
||||
} catch (Throwable e) {
|
||||
responder = new GetApiGalleryInfoResponder(l, null, "Create json error");
|
||||
mHandler.post(responder);
|
||||
return;
|
||||
}
|
||||
// Post
|
||||
HttpHelper hh = new HttpHelper(mContext);
|
||||
String body = hh.postJson(getApiUrl(), json);
|
||||
if (body != null) {
|
||||
try {
|
||||
json = new JSONObject(body);
|
||||
JSONArray jsonA = (JSONArray) json.get("gmetadata");
|
||||
for (int i = 0; i < jsonA.length(); i++) {
|
||||
ApiGalleryInfo agi = Json2Agi(jsonA.getJSONObject(i));
|
||||
// Add to agiArray
|
||||
for (int j = 0; j < requstLen; j++) {
|
||||
if (agi.gid == gids[j])
|
||||
agiArray[j] = agi;
|
||||
}
|
||||
}
|
||||
responder = new GetApiGalleryInfoResponder(l, checkFlag, agiArray);
|
||||
} catch (Throwable e) {
|
||||
responder = new GetApiGalleryInfoResponder(l, checkFlag, "Json error");
|
||||
}
|
||||
} else {
|
||||
responder = new GetApiGalleryInfoResponder(l, checkFlag, hh.getEMsg());
|
||||
}
|
||||
mHandler.post(responder);
|
||||
}
|
||||
Message msg = new Message();
|
||||
msg.what = errorMessageId;
|
||||
msg.obj = new GetGalleryMetadataPackage(lmds, listener);
|
||||
getGalleryMetadataHandler.sendMessage(msg);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public static void getGalleryMetadata(String[][] gidTokens,
|
||||
OnGetGalleryMetadataListener listener) {
|
||||
new Thread(new GetGalleryMetadataRunnable(gidTokens,
|
||||
listener)).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class GetGalleryTokensPackage {
|
||||
public Map<String, String> tokens;
|
||||
public OnGetGalleryTokensListener listener;
|
||||
|
||||
public GetGalleryTokensPackage(Map<String, String> tokens,
|
||||
OnGetGalleryTokensListener listener) {
|
||||
this.tokens = tokens;
|
||||
this.listener = listener;
|
||||
public ApiGalleryInfo[] getApiGalleryInfo(int[] gids, String[] tokens) {
|
||||
ApiGalleryInfo[] agiArray;
|
||||
int requstLen;
|
||||
// Create json
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("method", "gdata");
|
||||
JSONArray jsonA = new JSONArray();
|
||||
requstLen = Math.min(gids.length, tokens.length);
|
||||
agiArray = new ApiGalleryInfo[requstLen];
|
||||
for (int i = 0; i < requstLen; i++) {
|
||||
JSONArray ja = new JSONArray();
|
||||
ja.put(gids[i]);
|
||||
ja.put(tokens[i]);
|
||||
jsonA.put(ja);
|
||||
}
|
||||
json.put("gidlist", jsonA);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Handler getGalleryTokensHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
OnGetGalleryTokensListener listener =
|
||||
((GetGalleryTokensPackage) msg.obj).listener;
|
||||
Map<String, String> tokens =
|
||||
((GetGalleryTokensPackage) msg.obj).tokens;
|
||||
if (tokens == null || tokens.size() == 0)
|
||||
listener.onFailure(msg.what);
|
||||
else
|
||||
listener.onSuccess(tokens);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
private static class GetGalleryTokensRunnable implements Runnable {
|
||||
private String gid;
|
||||
private String token;
|
||||
private String[] pages;
|
||||
private OnGetGalleryMetadataListener listener;
|
||||
|
||||
public GetGalleryTokensRunnable(String gid, String token, String[] pages,
|
||||
OnGetGalleryMetadataListener listener) {
|
||||
this.gid = gid;
|
||||
this.token = token;
|
||||
this.pages = pages;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int errorMessageId = R.string.em_unknown_error;
|
||||
Map<String, String> tokens = new HashMap<String, String>();
|
||||
|
||||
// Create post string
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
strBuf.append("{\"method\": \"gtoken\",\"pagelist\": [");
|
||||
for (String item: pages)
|
||||
strBuf.append("[" + gid + ",\"" + token + "\"," + item + "],");
|
||||
strBuf.delete(strBuf.length()-1, strBuf.length());
|
||||
strBuf.append("]}");
|
||||
|
||||
Log.i(TAG, strBuf.toString());
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
errorMessageId = postJson(API_URL, strBuf.toString(),sb);
|
||||
if (sb.length() != 0) {
|
||||
String pageContent = sb.toString();
|
||||
Log.d(TAG, pageContent);
|
||||
// Post api
|
||||
HttpHelper hh = new HttpHelper(mContext);
|
||||
String body = hh.postJson(getApiUrl(), json);
|
||||
if (body == null) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
json = new JSONObject(body);
|
||||
JSONArray jsonA = (JSONArray) json.get("gmetadata");
|
||||
for (int i = 0; i < jsonA.length(); i++) {
|
||||
ApiGalleryInfo agi = Json2Agi(jsonA.getJSONObject(i));
|
||||
// Add to agiArray
|
||||
for (int j = 0; j < requstLen; j++) {
|
||||
if (agi.gid == gids[j])
|
||||
agiArray[j] = agi;
|
||||
}
|
||||
}
|
||||
return agiArray;
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
private static void getGalleryTokens(String gid, String token, String[] pages,
|
||||
OnGetGalleryMetadataListener listener) {
|
||||
new Thread(new GetGalleryTokensRunnable(gid, token, pages,
|
||||
listener)).start();
|
||||
}*/
|
||||
|
||||
}
|
||||
+36
-30
@@ -16,6 +16,17 @@
|
||||
|
||||
package com.hippo.ehviewer.ehclient;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
import com.larvalabs.svgandroid.SVGBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -25,15 +36,6 @@ import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Hippo
|
||||
@@ -46,7 +48,7 @@ public class EhInfo {
|
||||
private static final String DIR_NAME = "file";
|
||||
private static final String AVATAR_NAME = "avatar.png";
|
||||
private static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.PNG;
|
||||
private static Bitmap DEFAULT_AVATAR;
|
||||
private static Drawable DEFAULT_AVATAR;
|
||||
|
||||
public static final String EX_HOST = "exhentai.org";
|
||||
public static final String[] COOKIABLE_HOSTS = {"exhentai.org",
|
||||
@@ -69,14 +71,14 @@ public class EhInfo {
|
||||
private boolean mIsLogin;
|
||||
private String mUsername;
|
||||
private String mDisplayname;
|
||||
private Bitmap mAvatar;
|
||||
private BitmapDrawable mAvatar;
|
||||
private int mDefaultCat;
|
||||
private String mPreviewMode;
|
||||
private int mExculdeTagGroup;
|
||||
private String mExculdeLanguage;
|
||||
private static EhInfo sInstance;
|
||||
|
||||
private Bitmap getAvatarFromFile() {
|
||||
private BitmapDrawable getAvatarFromFile() {
|
||||
File dir = mContext.getDir(DIR_NAME, 0);
|
||||
File avatarFile = new File(dir, AVATAR_NAME);
|
||||
if (!avatarFile.exists())
|
||||
@@ -85,7 +87,7 @@ public class EhInfo {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(avatarFile);
|
||||
return BitmapFactory.decodeStream(is);
|
||||
return (BitmapDrawable) BitmapDrawable.createFromStream(is, null);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
} finally {
|
||||
@@ -97,8 +99,7 @@ public class EhInfo {
|
||||
mContext = context;
|
||||
mInfoPref = mContext.getSharedPreferences(PREF_NAME, 0);
|
||||
if (DEFAULT_AVATAR == null)
|
||||
DEFAULT_AVATAR = BitmapFactory.decodeStream(
|
||||
context.getResources().openRawResource(R.drawable.default_avatar));
|
||||
DEFAULT_AVATAR = new SVGBuilder().readFromResource(context.getResources(), R.raw.default_avatar).build().getDrawable();
|
||||
|
||||
mIsLogin = mInfoPref.getBoolean(KEY_LOGIN, DEFAULT_LOGIN);
|
||||
mUsername = mInfoPref.getString(KEY_USERNAME, DEFAULT_NAME);
|
||||
@@ -147,22 +148,24 @@ public class EhInfo {
|
||||
}
|
||||
|
||||
public void storeCookie(HttpURLConnection conn) {
|
||||
String ipb_member_id;
|
||||
String ipb_pass_hash;
|
||||
|
||||
List<String> cookieList = conn.getHeaderFields().get("Set-Cookie");
|
||||
if (cookieList == null)
|
||||
return;
|
||||
SharedPreferences.Editor editor = mInfoPref.edit();
|
||||
for (String str : cookieList) {
|
||||
ipb_member_id = getCookie(str, KEY_MEMBER_ID);
|
||||
ipb_pass_hash = getCookie(str, KEY_PASS_HASH);
|
||||
|
||||
if (ipb_member_id != null)
|
||||
editor.putString(KEY_MEMBER_ID, ipb_member_id);
|
||||
if (ipb_pass_hash != null)
|
||||
editor.putString(KEY_PASS_HASH, ipb_pass_hash);
|
||||
for (String str : cookieList) {
|
||||
setCookie(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCookie(String cookie) {
|
||||
SharedPreferences.Editor editor = mInfoPref.edit();
|
||||
String ipb_member_id = getCookie(cookie, KEY_MEMBER_ID);
|
||||
String ipb_pass_hash = getCookie(cookie, KEY_PASS_HASH);
|
||||
|
||||
if (ipb_member_id != null)
|
||||
editor.putString(KEY_MEMBER_ID, ipb_member_id);
|
||||
if (ipb_pass_hash != null)
|
||||
editor.putString(KEY_PASS_HASH, ipb_pass_hash);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@@ -180,6 +183,9 @@ public class EhInfo {
|
||||
sb.append("; ipb_member_id=").append(id);
|
||||
if (hash != null)
|
||||
sb.append("; ipb_pass_hash=").append(hash);
|
||||
// Fake
|
||||
sb.append("; igneous=");
|
||||
sb.append("; lv=");
|
||||
conn.setRequestProperty("Cookie", sb.toString());
|
||||
}
|
||||
|
||||
@@ -201,7 +207,7 @@ public class EhInfo {
|
||||
mIsLogin = false;
|
||||
// Remove avatar
|
||||
if (mAvatar != null) {
|
||||
mAvatar.recycle();
|
||||
mAvatar.getBitmap().recycle();
|
||||
mAvatar = null;
|
||||
File dir = mContext.getDir(DIR_NAME, 0);
|
||||
File avatarFile = new File(dir, AVATAR_NAME);
|
||||
@@ -221,11 +227,11 @@ public class EhInfo {
|
||||
return mDisplayname;
|
||||
}
|
||||
|
||||
public Bitmap getAvatar() {
|
||||
public Drawable getAvatar() {
|
||||
return isLogin() && mAvatar != null ? mAvatar : DEFAULT_AVATAR;
|
||||
}
|
||||
|
||||
public void setAvatar(Bitmap avatar) {
|
||||
public void setAvatar(BitmapDrawable avatar) {
|
||||
mAvatar = avatar;
|
||||
|
||||
File dir = mContext.getDir(DIR_NAME, 0);
|
||||
@@ -233,7 +239,7 @@ public class EhInfo {
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(avatarFile);
|
||||
avatar.compress(AVATAR_FORMAT, 100, os);
|
||||
avatar.getBitmap().compress(AVATAR_FORMAT, 100, os);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
+160
-36
@@ -20,33 +20,44 @@ import java.io.BufferedInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.Process;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.network.HttpHelper;
|
||||
import com.hippo.ehviewer.util.AutoExpandArray;
|
||||
import com.hippo.ehviewer.util.BgThread;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.util.Log;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
public class ExDownloader implements Runnable {
|
||||
// TODO what a mess
|
||||
public final class ExDownloader implements Runnable {
|
||||
|
||||
private static final String TAG = ExDownloader.class.getSimpleName();
|
||||
|
||||
private static final int IO_BUFFER_SIZE = 8 * 1024;
|
||||
|
||||
private static final String[] URL_ARRAY_509 = new String[] {
|
||||
"http://ehgt.org/g/509.gif",
|
||||
"http://ehgt.org/g/509s.gif",
|
||||
"http://st.exhentai.net/img/509.gif",
|
||||
"http://st.exhentai.net/img/509s.gif"
|
||||
};
|
||||
|
||||
private final Context mContext;
|
||||
private final ExDownloaderManager mManager;
|
||||
|
||||
@@ -97,6 +108,8 @@ public class ExDownloader implements Runnable {
|
||||
private volatile HashSet<Integer> mDownloadIndexSet;
|
||||
private volatile Object mDownloadLock = new Object();
|
||||
|
||||
private int mCurReadIndex = 0;
|
||||
|
||||
/**
|
||||
* Do no work in UI thread
|
||||
* @author Hippo
|
||||
@@ -114,13 +127,14 @@ public class ExDownloader implements Runnable {
|
||||
*/
|
||||
public interface ListenerForDownload {
|
||||
public void onStart(int gid);
|
||||
public void onGetSum(int gid, int sum);
|
||||
public void onDownload(int gid, int downloadSize, int totalSize);
|
||||
public void onUpdateSpeed(int gid, int speed);
|
||||
public void onDownloadOver(int gid, int legacy);
|
||||
}
|
||||
|
||||
ExDownloader(int gid, String token, String title, int mode) {
|
||||
mContext = AppContext.getInstance();
|
||||
ExDownloader(Context context, int gid, String token, String title, int mode) {
|
||||
mContext = context;
|
||||
mManager = ExDownloaderManager.getInstance();
|
||||
mGid = gid;
|
||||
mToken = token;
|
||||
@@ -134,11 +148,6 @@ public class ExDownloader implements Runnable {
|
||||
// Make sure dir
|
||||
mDir = EhUtils.getGalleryDir(mGid, mTitle);
|
||||
Utils.ensureDir(mDir, true);
|
||||
// Create mark file
|
||||
File makeFile = new File(mDir, EhUtils.EH_DOWNLOAD_FILENAME);
|
||||
try {
|
||||
new FileOutputStream(makeFile).close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public void setListenerForImageSet(ListenerForImageSet l) {
|
||||
@@ -206,13 +215,17 @@ public class ExDownloader implements Runnable {
|
||||
return mToken;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public void setDownloadMode(boolean downloadMode) {
|
||||
synchronized (mDownloadLock) {
|
||||
if (downloadMode) {
|
||||
setStartIndex(0);
|
||||
if (mDownloadIndexSet == null)
|
||||
mDownloadIndexSet = new HashSet<Integer>();
|
||||
if (mLfd != null)
|
||||
if (mDownloadMode && mLfd != null)
|
||||
mLfd.onStart(mGid);
|
||||
} else {
|
||||
mDownloadIndexSet = null;
|
||||
@@ -223,7 +236,7 @@ public class ExDownloader implements Runnable {
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
if (mDownloadMode) {
|
||||
setTargetIndex(startIndex);
|
||||
addTargetIndex(startIndex);
|
||||
} else {
|
||||
if (mImageNum != -1 && startIndex >= mImageNum)
|
||||
mStartIndex = 0;
|
||||
@@ -235,7 +248,7 @@ public class ExDownloader implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void setTargetIndex(int index) {
|
||||
public void addTargetIndex(int index) {
|
||||
if (mImageNum != -1 && index >= mImageNum)
|
||||
return;
|
||||
|
||||
@@ -244,11 +257,20 @@ public class ExDownloader implements Runnable {
|
||||
ensureWorkers();
|
||||
}
|
||||
|
||||
public void setCurReadIndex(final int index) {
|
||||
new BgThread() {
|
||||
@Override
|
||||
public void run() {
|
||||
writeCurReadIndex(index);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public int getMaxEnsureIndex() {
|
||||
if (mImageNum != -1) {
|
||||
return mImageNum - 1;
|
||||
} else {
|
||||
return Math.max(Math.max(Math.max(mStartIndex - 1,
|
||||
return Math.max(Math.max(Math.max(mStartIndex,
|
||||
Math.max(mCurMaxPreviewPage, mPreviewPageNum - 1) * mPreviewPerPage),
|
||||
mPageTokeArray.maxValidIndex()), 0);
|
||||
}
|
||||
@@ -282,13 +304,13 @@ public class ExDownloader implements Runnable {
|
||||
if (mMainThread != null)
|
||||
return;
|
||||
|
||||
mMainThread = new Thread(this);
|
||||
mMainThread = new BgThread(this);
|
||||
mMainThread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mMainThread.start();
|
||||
}
|
||||
|
||||
private File getExDownloadInfoFile() {
|
||||
return new File(mManager.getExDownloadInfoDir(), String.valueOf(mGid));
|
||||
return new File(mDir, EhUtils.EH_DOWNLOAD_FILENAME);
|
||||
}
|
||||
|
||||
private boolean checkMode(int samlpe, int target) {
|
||||
@@ -300,6 +322,7 @@ public class ExDownloader implements Runnable {
|
||||
* This function parser the download info file.<br>
|
||||
* The file look like this:<br>
|
||||
* <code>
|
||||
* 00000000<br>
|
||||
* 728874<br>
|
||||
* 306429c222<br>
|
||||
* 1<br>
|
||||
@@ -317,7 +340,7 @@ public class ExDownloader implements Runnable {
|
||||
* @param ediFile
|
||||
* @return
|
||||
*/
|
||||
private boolean parserEdiFile(File ediFile) {
|
||||
private synchronized boolean parserEdiFile(File ediFile) {
|
||||
if (!ediFile.exists() || !ediFile.isFile() || !ediFile.canRead()
|
||||
|| !ediFile.canWrite())
|
||||
return false;
|
||||
@@ -326,6 +349,8 @@ public class ExDownloader implements Runnable {
|
||||
try {
|
||||
is = new BufferedInputStream(new FileInputStream(ediFile),
|
||||
IO_BUFFER_SIZE);
|
||||
// skip read index
|
||||
Utils.readAsciiLine(is);
|
||||
if (mGid != Integer.valueOf(Utils.readAsciiLine(is)) ||
|
||||
!mToken.equals(Utils.readAsciiLine(is)))
|
||||
return false;
|
||||
@@ -377,9 +402,11 @@ public class ExDownloader implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeEdiFile(File ediFile) {
|
||||
private synchronized void writeEdiFile(File ediFile) {
|
||||
try {
|
||||
FileWriter writer = new FileWriter(ediFile);
|
||||
writer.write(String.format("%08x", mCurReadIndex));
|
||||
writer.write("\n");
|
||||
writer.write(String.valueOf(mGid));
|
||||
writer.write("\n");
|
||||
writer.write(mToken);
|
||||
@@ -406,6 +433,27 @@ public class ExDownloader implements Runnable {
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
private synchronized void writeCurReadIndex(int index) {
|
||||
mCurReadIndex = index;
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(getExDownloadInfoFile(), "rw");
|
||||
raf.write(String.format("%08x", mCurReadIndex).getBytes());
|
||||
raf.close();
|
||||
} catch (Throwable e) {}
|
||||
}
|
||||
|
||||
public static int readCurReadIndex(int gid, String title) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(new File(EhUtils.getGalleryDir(gid, title),
|
||||
EhUtils.EH_DOWNLOAD_FILENAME), "r");
|
||||
int index = Integer.parseInt(raf.readLine(), 16);
|
||||
raf.close();
|
||||
return index;
|
||||
} catch (Throwable e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void getDetailInfo(int pageIndex, File ediFile, boolean needPreviewInfo) throws Exception {
|
||||
HttpHelper hh = new HttpHelper(mContext);
|
||||
EdDetailParser edp = new EdDetailParser();
|
||||
@@ -471,6 +519,18 @@ public class ExDownloader implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int BE_NOTIFY_ID = -3;
|
||||
|
||||
private static final void show509Notification(Context context) {
|
||||
NotificationManager notifyManager = (NotificationManager) context
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
|
||||
mBuilder.setSmallIcon(R.drawable.ic_stat_eh).setContentTitle(context.getString(R.string.notification_be_title))
|
||||
.setContentText(context.getString(R.string.notification_be_mesg))
|
||||
.setOngoing(false).setAutoCancel(true);
|
||||
notifyManager.notify(BE_NOTIFY_ID, mBuilder.build());
|
||||
}
|
||||
|
||||
// TODO for download , when to claim download completed
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -478,10 +538,13 @@ public class ExDownloader implements Runnable {
|
||||
try {
|
||||
File ediFile = getExDownloadInfoFile();
|
||||
if (!parserEdiFile(ediFile) || mPreviewPerPage == -1 ||
|
||||
(mMode == EhClient.MODE_EX && mImageNum == -1)) {
|
||||
((mMode == EhClient.MODE_EX || mMode == EhClient.MODE_G) && mImageNum == -1)) {
|
||||
getDetailInfo(0, ediFile, true);
|
||||
}
|
||||
|
||||
if (mLfd != null)
|
||||
mLfd.onGetSum(mGid, mImageNum);
|
||||
|
||||
ensureWorkers();
|
||||
|
||||
// A loop to get page token
|
||||
@@ -544,7 +607,7 @@ public class ExDownloader implements Runnable {
|
||||
Log.d(TAG, "ExDownloader over");
|
||||
}
|
||||
|
||||
private class Worker extends Thread {
|
||||
private class Worker extends BgThread {
|
||||
|
||||
private final int mIndex;
|
||||
|
||||
@@ -599,6 +662,7 @@ public class ExDownloader implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO what if download failed ? what to do ?
|
||||
@Override
|
||||
public void run() {
|
||||
HttpDownloadListener listener = new HttpDownloadListener();
|
||||
@@ -672,31 +736,91 @@ public class ExDownloader implements Runnable {
|
||||
hh.reset();
|
||||
ipp.reset();
|
||||
String body = hh.get(EhClient.getPageUrl(mGid, pageToken, targetIndex + 1, mMode)
|
||||
+ (i == 1 ? "?nl=48" : ""));
|
||||
+ ((i == 1) ? "?nl=48" : ""));
|
||||
if (ipp.parser(body, mMode)) {
|
||||
// Download image
|
||||
HttpHelper.DownloadControlor c = mControlorArray[mIndex];
|
||||
String imageUrl = ipp.imageUrl;
|
||||
String filename = EhUtils.getImageFilename(targetIndex, Utils.getExtension(imageUrl, "jpg"));
|
||||
// Just put filename to mImageFilenameArray
|
||||
mImageFilenameArray.set(targetIndex, filename);
|
||||
hh.reset();
|
||||
if (hh.download(imageUrl, mDir, filename, false, c, listener) == null) {
|
||||
|
||||
if (Config.getDownloadOriginImage() && ipp.originalImageUrl != null) {
|
||||
|
||||
Log.d(TAG, "Download origin image");
|
||||
|
||||
// Download orgin image
|
||||
String imageUrl = ipp.originalImageUrl;
|
||||
// Guess filename
|
||||
String filename = EhUtils.getImageFilename(targetIndex, "jpg");
|
||||
// Download
|
||||
hh.reset();
|
||||
if (hh.download(imageUrl, mDir, filename, true, c, listener) == null) {
|
||||
if (i == 1) {
|
||||
// TODO download error
|
||||
Log.d(TAG, "download error");
|
||||
if (hh.downloadOriginEhImage(imageUrl, mDir, filename, false, c, listener) == null) {
|
||||
if (hh.getException() instanceof HttpHelper.BandwidthExceededException) {
|
||||
// Get 509
|
||||
show509Notification(mContext);
|
||||
break;
|
||||
} else {
|
||||
String newImageUrl = hh.getLastUrl();
|
||||
if (newImageUrl != null) {
|
||||
// Try download from proxy
|
||||
hh.reset();
|
||||
if (hh.downloadEhImage(newImageUrl, mDir, filename, true, c, listener) == null) {
|
||||
// Download failed
|
||||
Log.d(TAG, "Download failed");
|
||||
} else {
|
||||
// Download successful
|
||||
Log.d(TAG, "Download successful");
|
||||
}
|
||||
} else {
|
||||
// Download failed
|
||||
Log.d(TAG, "Download failed");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Download successful
|
||||
Log.d(TAG, "Download successful");
|
||||
}
|
||||
|
||||
// No need to refresh image url
|
||||
break;
|
||||
} else {
|
||||
// Download scale image
|
||||
String imageUrl = ipp.imageUrl;
|
||||
|
||||
//Check 509 gif
|
||||
boolean get509 = false;
|
||||
int length = URL_ARRAY_509.length;
|
||||
for (int j = 0; j < length; j++) {
|
||||
if (URL_ARRAY_509[j].equals(imageUrl)) {
|
||||
// Get 509 gif here
|
||||
get509 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (get509) {
|
||||
show509Notification(mContext);
|
||||
break;
|
||||
}
|
||||
|
||||
// Guess filename
|
||||
String filename = EhUtils.getImageFilename(targetIndex, Utils.getExtension(imageUrl, "jpg"));
|
||||
// Don't put into mImageFilenameArray, because extension maybe be wrong
|
||||
// mImageFilenameArray.set(targetIndex, filename);
|
||||
hh.reset();
|
||||
if (hh.downloadEhImage(imageUrl, mDir, filename, false, c, listener) == null) {
|
||||
hh.reset();
|
||||
if (hh.downloadEhImage(imageUrl, mDir, filename, true, c, listener) == null) {
|
||||
if (i == 1) {
|
||||
// TODO download error
|
||||
Log.d(TAG, "download error");
|
||||
}
|
||||
} else {
|
||||
// download ok
|
||||
Log.d(TAG, "download ok proxy");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// download ok
|
||||
Log.d(TAG, "download ok proxy");
|
||||
Log.d(TAG, "download ok");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// download ok
|
||||
Log.d(TAG, "download ok");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// TODO parser error, Do somthing
|
||||
+5
-22
@@ -16,52 +16,35 @@
|
||||
|
||||
package com.hippo.ehviewer.ehclient;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
|
||||
public class ExDownloaderManager {
|
||||
|
||||
private static final String TAG = ExDownloaderManager.class.getSimpleName();
|
||||
|
||||
private final Context mContext;
|
||||
private final SparseArray<ExDownloader> mExDownloadList;
|
||||
private final File mExDownloadInfoDir;
|
||||
|
||||
private static ExDownloaderManager sInstance;
|
||||
|
||||
public static void createInstance() {
|
||||
sInstance = new ExDownloaderManager();
|
||||
public static void createInstance(Context context) {
|
||||
sInstance = new ExDownloaderManager(context.getApplicationContext());
|
||||
}
|
||||
|
||||
public static ExDownloaderManager getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private ExDownloaderManager() {
|
||||
mContext = AppContext.getInstance();
|
||||
private ExDownloaderManager(Context context) {
|
||||
mContext = context;
|
||||
mExDownloadList = new SparseArray<ExDownloader>();
|
||||
// Init download info dir
|
||||
String cachePath = mContext.getExternalCacheDir() != null
|
||||
? mContext.getExternalCacheDir().getPath()
|
||||
: mContext.getCacheDir().getPath();
|
||||
mExDownloadInfoDir = new File(cachePath, TAG);
|
||||
if (!mExDownloadInfoDir.exists()) {
|
||||
mExDownloadInfoDir.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
File getExDownloadInfoDir() {
|
||||
return mExDownloadInfoDir;
|
||||
}
|
||||
|
||||
public synchronized ExDownloader getExDownloader(int gid, String token, String title, int mode) {
|
||||
ExDownloader exDownloader = mExDownloadList.get(gid);
|
||||
if (exDownloader == null) {
|
||||
exDownloader = new ExDownloader(gid, token, title, mode);
|
||||
exDownloader = new ExDownloader(mContext, gid, token, title, mode);
|
||||
mExDownloadList.append(gid, exDownloader);
|
||||
}
|
||||
exDownloader.occupy();
|
||||
+9
-1
@@ -24,11 +24,13 @@ import com.hippo.ehviewer.util.Utils;
|
||||
public class ImagePageParser {
|
||||
|
||||
public String imageUrl;
|
||||
public String originalImageUrl;
|
||||
public int gid;
|
||||
public String token;
|
||||
|
||||
public void reset() {
|
||||
imageUrl = null;
|
||||
originalImageUrl = null;
|
||||
gid = 0;
|
||||
token = null;
|
||||
}
|
||||
@@ -63,11 +65,17 @@ public class ImagePageParser {
|
||||
+ ".+?"
|
||||
+ "<div id=\"i5\"><div class=\"sb\"><a href=\"(?:http|https)://.+?/g/(\\d+)/(\\w+)");
|
||||
m = p.matcher(body);
|
||||
|
||||
if (m.find()) {
|
||||
imageUrl = Utils.unescapeXml(m.group(1));
|
||||
gid = Integer.parseInt(m.group(2));
|
||||
token = m.group(3);
|
||||
|
||||
p = Pattern.compile("<a href=\"([^\"]+)fullimg.php([^\"]+)\">");
|
||||
m = p.matcher(body);
|
||||
if (m.find()) {
|
||||
originalImageUrl = Utils.unescapeXml(
|
||||
new StringBuilder(m.group(1)).append("fullimg.php").append(m.group(2)).toString());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
+15
-11
@@ -22,6 +22,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.data.LofiGalleryInfo;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
public class ListParser {
|
||||
@@ -84,7 +85,7 @@ public class ListParser {
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
lgi.category = EhClient.getType(m.group(5));
|
||||
lgi.category = EhUtils.getCategory(m.group(5));
|
||||
String tags = m.group(6);
|
||||
if (tags.equals("-"))
|
||||
lgi.lofiTags = null;
|
||||
@@ -133,7 +134,7 @@ public class ListParser {
|
||||
|
||||
p = Pattern.compile("<td class=\"itdc\">(?:<a.+?>)?<img.+?alt=\"(.+?)\".+?/>(?:</a>)?</td>" // category
|
||||
+ "<td.+?>(.+?)</td>" // posted
|
||||
+ "<td.+?><div.+?><div.+?>"
|
||||
+ "<td.+?><div.+?><div.+?height:(\\d+)px; width:(\\d+)px\">"
|
||||
+ "(?:<img.+?src=\"(.+?)\".+?alt=\"(.+?)\" style.+?/>"
|
||||
+ "|init~([^<>\"~]+~[^<>\"~]+)~([^<>]+))" // thumb and title
|
||||
+ "</div>"
|
||||
@@ -147,28 +148,31 @@ public class ListParser {
|
||||
while (m.find()) {
|
||||
GalleryInfo gi = new GalleryInfo();
|
||||
|
||||
gi.category = EhClient.getType(m.group(1));
|
||||
gi.category = EhUtils.getCategory(m.group(1));
|
||||
gi.posted = m.group(2);
|
||||
if (m.group(3) == null) {
|
||||
gi.thumbHeight = Integer.parseInt(m.group(3));
|
||||
gi.thumbWidth = Integer.parseInt(m.group(4));
|
||||
|
||||
if (m.group(5) == null) {
|
||||
gi.thumb = Utils.unescapeXml("http://"
|
||||
+ m.group(5).replace('~', '/'));
|
||||
gi.title = Utils.unescapeXml(m.group(6));
|
||||
+ m.group(7).replace('~', '/'));
|
||||
gi.title = Utils.unescapeXml(m.group(8));
|
||||
} else {
|
||||
gi.thumb = Utils.unescapeXml(m.group(3));
|
||||
gi.title = Utils.unescapeXml(m.group(4));
|
||||
gi.thumb = Utils.unescapeXml(m.group(5));
|
||||
gi.title = Utils.unescapeXml(m.group(6));
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern
|
||||
.compile("/(\\d+)/(\\w+)");
|
||||
Matcher matcher = pattern.matcher(m.group(7));
|
||||
Matcher matcher = pattern.matcher(m.group(9));
|
||||
if (matcher.find()) {
|
||||
gi.gid = Integer.parseInt(matcher.group(1));
|
||||
gi.token = matcher.group(2);
|
||||
} else
|
||||
continue;
|
||||
|
||||
gi.rating = Float.parseFloat(getRate(m.group(9)));
|
||||
gi.uploader = m.group(10);
|
||||
gi.rating = Float.parseFloat(getRate(m.group(11)));
|
||||
gi.uploader = m.group(12);
|
||||
gi.generateSLang();
|
||||
|
||||
giList.add(gi);
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+730
-399
File diff suppressed because it is too large.
Load diff
File renamed without changes.
File renamed without changes.
File renamed without changes.
+39
-12
@@ -20,8 +20,6 @@ import java.io.File;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import javax.microedition.khronos.opengles.GL11;
|
||||
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Movie;
|
||||
import android.util.SparseArray;
|
||||
@@ -31,6 +29,7 @@ import com.hippo.ehviewer.ehclient.ExDownloader;
|
||||
import com.hippo.ehviewer.ehclient.ExDownloaderManager;
|
||||
import com.hippo.ehviewer.gallery.image.Image;
|
||||
import com.hippo.ehviewer.util.AutoExpandArray;
|
||||
import com.hippo.ehviewer.util.BgThread;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.util.Log;
|
||||
@@ -38,7 +37,6 @@ import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
public class ImageSet implements ExDownloader.ListenerForImageSet {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = ImageSet.class.getSimpleName();
|
||||
|
||||
/**
|
||||
@@ -97,8 +95,8 @@ public class ImageSet implements ExDownloader.ListenerForImageSet {
|
||||
// Init ExDownloader
|
||||
mEdManager = ExDownloaderManager.getInstance();
|
||||
mExDownloader = mEdManager.getExDownloader(gid, token, title, Config.getMode());
|
||||
mExDownloader.setStartIndex(startIndex);
|
||||
mExDownloader.setListenerForImageSet(this);
|
||||
mExDownloader.setStartIndex(startIndex);
|
||||
|
||||
mImageFilenameArray = mExDownloader.getImageFilenameArray();
|
||||
|
||||
@@ -123,22 +121,36 @@ public class ImageSet implements ExDownloader.ListenerForImageSet {
|
||||
mListener = l;
|
||||
}
|
||||
|
||||
public void setTargetIndex(int index) {
|
||||
mExDownloader.setTargetIndex(index);
|
||||
public void addTargetIndex(int index) {
|
||||
mExDownloader.addTargetIndex(index);
|
||||
}
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
mExDownloader.setStartIndex(startIndex);
|
||||
}
|
||||
|
||||
public Object getImage(int index) {
|
||||
// Try to get file name
|
||||
public void setCurReadIndex(int index) {
|
||||
mExDownloader.setCurReadIndex(index);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mExDownloader.getTitle();
|
||||
}
|
||||
|
||||
public File getImageFile(int index) {
|
||||
File file = null;
|
||||
String name = getImageFilename(index);
|
||||
if (name != null)
|
||||
file = new File(mDir, name);
|
||||
return file;
|
||||
}
|
||||
|
||||
private String getImageFilename(int index) {
|
||||
String filename = mImageFilenameArray.get(index);
|
||||
if (filename == null) {
|
||||
// Just guess filename
|
||||
for (String possibleFilename : EhUtils.getPossibleImageFilenames(index)) {
|
||||
File file = new File(mDir, possibleFilename);
|
||||
if (file.exists()) {
|
||||
if (new File(mDir, possibleFilename).exists()) {
|
||||
// Get filename
|
||||
filename = possibleFilename;
|
||||
mImageFilenameArray.set(index, filename);
|
||||
@@ -146,8 +158,23 @@ public class ImageSet implements ExDownloader.ListenerForImageSet {
|
||||
}
|
||||
}
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void redownload(int index) {
|
||||
String filename = getImageFilename(index);
|
||||
if (filename != null) {
|
||||
// Delete file
|
||||
new File(mDir, filename).delete();
|
||||
}
|
||||
mExDownloader.addTargetIndex(index);
|
||||
mListener.onGetImage(index);
|
||||
}
|
||||
|
||||
public Object getImage(int index) {
|
||||
String filename = getImageFilename(index);
|
||||
Float percent;
|
||||
|
||||
if ((percent = mPercentMap.get(index)) != null) {
|
||||
return percent;
|
||||
} else if (mExDownloader.isDownloading(index)) {
|
||||
@@ -178,7 +205,7 @@ public class ImageSet implements ExDownloader.ListenerForImageSet {
|
||||
mEdManager.freeExDownloader(mExDownloader);
|
||||
}
|
||||
|
||||
private class DecodeWorker extends Thread {
|
||||
private class DecodeWorker extends BgThread {
|
||||
@Override
|
||||
public void run() {
|
||||
DecodeInfo decodeInfo;
|
||||
@@ -204,7 +231,7 @@ public class ImageSet implements ExDownloader.ListenerForImageSet {
|
||||
Object res = null;
|
||||
|
||||
if (Utils.SUPPORT_IMAGE && Config.getCustomCodec()) {
|
||||
res = Image.decodeFile(pathName, GL11.GL_RGB);
|
||||
res = Image.decodeFile(pathName, Config.getDecodeFormat());
|
||||
} else {
|
||||
if (Utils.getExtension(pathName, "jpg").equals("gif"))
|
||||
res = Movie.decodeFile(pathName);
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 1070 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user