Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09229546c6 | ||
|
|
03582eb9da | ||
|
|
e2e794b85c | ||
|
|
ab949d5567 | ||
|
|
f340279e57 | ||
|
|
ddb1edb7d1 | ||
|
|
a7f29a3cd5 | ||
|
|
d09e4a9215 | ||
|
|
07335ba49c | ||
|
|
b55d5a1538 | ||
|
|
97fc40a69c | ||
|
|
cc73666475 | ||
|
|
0ed34f2eca | ||
|
|
a7a3d56c91 | ||
|
|
748c5cb812 | ||
|
|
f5318cf6d3 | ||
|
|
082dc2e3f5 | ||
|
|
c4ed7a034a | ||
|
|
28f548e565 | ||
|
|
20927eea63 | ||
|
|
1a302e5157 | ||
|
|
92417cb7b4 | ||
|
|
1dab2722dd | ||
|
|
3a59e3eaae | ||
|
|
d56c4e5386 | ||
|
|
0c3a7301cc | ||
|
|
6878de9175 | ||
|
|
97956b98df | ||
|
|
52bf4ac74d | ||
|
|
b53e8b49e0 | ||
|
|
51d648ac6b | ||
|
|
03a5b75648 | ||
|
|
bea31278a7 | ||
|
|
3bec2e47e3 | ||
|
|
13eb3d291d | ||
|
|
23225bdb56 | ||
|
|
8ba3d11c11 | ||
|
|
d519179ae2 | ||
|
|
e8aa39d66d | ||
|
|
ee231382f5 | ||
|
|
0324b87ad6 | ||
|
|
855e4cc61c | ||
|
|
b759ee0997 | ||
|
|
f2a1ad7df4 | ||
|
|
33999a317e | ||
|
|
2d9a54bc0e | ||
|
|
8d1ad9697b | ||
|
|
39d9701c75 | ||
|
|
d886cbe391 | ||
|
|
5afb351fcc | ||
|
|
7f5569a8d9 | ||
|
|
9df26b94c7 | ||
|
|
103cfe1749 | ||
|
|
006a8684ff | ||
|
|
645f0df208 | ||
|
|
60dc0a7f72 | ||
|
|
4c7c06e8dc | ||
|
|
d361eaf63d | ||
|
|
b44fdcfeec | ||
|
|
51f050ae7e | ||
|
|
d59685588b | ||
|
|
2e188a2cc3 | ||
|
|
b562ec2b50 | ||
|
|
dab0b0cbfb | ||
|
|
68aea866e1 | ||
|
|
82c0208ac8 | ||
|
|
0285f82f52 | ||
|
|
3d88928ed3 | ||
|
|
f05d123da7 | ||
|
|
dcc45c5d81 | ||
|
|
d25caafc8b | ||
|
|
290c60adab | ||
|
|
3c7a61a863 | ||
|
|
5a3b152110 | ||
|
|
446e0aadd1 | ||
|
|
62675a3dd2 | ||
|
|
6e97c23dda | ||
|
|
d08598ab71 | ||
|
|
007330112e | ||
|
|
eb33529980 | ||
|
|
22ff864844 | ||
|
|
51f2ea5bf8 | ||
|
|
8f611c5a27 | ||
|
|
5413b8e40e | ||
|
|
b1cf11e2bc | ||
|
|
fb8bc2c364 | ||
|
|
570796a610 | ||
|
|
3a1fe8da1d | ||
|
|
5259f2173d | ||
|
|
5b6f458c60 | ||
|
|
1998af3d0b | ||
|
|
e3b5ed840e | ||
|
|
e96d91184f | ||
|
|
5822e58984 | ||
|
|
da90150233 | ||
|
|
62d6609b15 | ||
|
|
e451db6032 | ||
|
|
a2bbe855e8 | ||
|
|
374ed3a515 | ||
|
|
6f0af8b6ec | ||
|
|
a98cd0bc79 | ||
|
|
0e125738e2 | ||
|
|
055fd5e8ae | ||
|
|
10ba81f5cc | ||
|
|
08d79aa204 | ||
|
|
d0e1b4cfee | ||
|
|
90d95c6552 | ||
|
|
53a7cc84a2 | ||
|
|
129b70e15c | ||
|
|
80282ffd04 | ||
|
|
e3209cd2c0 | ||
|
|
3681bd1dd4 | ||
|
|
a6fea77b15 | ||
|
|
e08a9bfdfa | ||
|
|
ee229b11da | ||
|
|
dfa5998483 | ||
|
|
b743bdb581 | ||
|
|
fa5d8380c9 | ||
|
|
79ffce2f3e | ||
|
|
d89db7754f | ||
|
|
ef154867a6 | ||
|
|
8abe21c536 | ||
|
|
333c783a0d | ||
|
|
eae2375560 | ||
|
|
0a3adfb06b | ||
|
|
5fda8b792c | ||
|
|
0ea49f593b | ||
|
|
6331c3c86d | ||
|
|
99df5be760 | ||
|
|
53f8f6defc | ||
|
|
c1d39de57c | ||
|
|
f0c8c14918 | ||
|
|
5b0b1b1614 | ||
|
|
8ffa54dc25 | ||
|
|
ae4714aa48 | ||
|
|
802c11bed1 | ||
|
|
ff2ed3205d | ||
|
|
ba7f1a5aed | ||
|
|
43903adcc4 | ||
|
|
703fc5f44d | ||
|
|
485f4ba9f2 | ||
|
|
1d6e6277d8 | ||
|
|
2ed2c08183 | ||
|
|
eaae310f05 | ||
|
|
ab9b7e59d9 | ||
|
|
07614fecef | ||
|
|
fae86c1782 | ||
|
|
b0fc8f4c58 | ||
|
|
5cdc004829 | ||
|
|
7efed23ddf | ||
|
|
251ed9b687 | ||
|
|
1b017250a5 | ||
|
|
5e9097b1bf | ||
|
|
62858aa5d2 | ||
|
|
8ceb7ca912 | ||
|
|
4ce0a60397 | ||
|
|
75731d5600 | ||
|
|
7ddeef682a | ||
|
|
da076be7fb | ||
|
|
7235e3abd5 | ||
|
|
05cfabae10 | ||
|
|
32e345f9f0 | ||
|
|
6b7f314e9f | ||
|
|
db3fe7e446 | ||
|
|
d7e42a760c | ||
|
|
f90588e79e | ||
|
|
deefd9b9e3 | ||
|
|
e01ef1abff | ||
|
|
facb17eac2 | ||
|
|
151c16ad83 | ||
|
|
07d1cc6bf6 | ||
|
|
e9bb78ebfc | ||
|
|
c154f9b73a | ||
|
|
51266d4c3b | ||
|
|
f02998b917 | ||
|
|
b6f89741ee | ||
|
|
2498be6850 | ||
|
|
ce2907610a | ||
|
|
4e266c160c | ||
|
|
3e76680aeb | ||
|
|
8ad331af60 | ||
|
|
90a41a1d6b | ||
|
|
ce786f4e41 | ||
|
|
3f099969d1 | ||
|
|
e0acfa55eb | ||
|
|
f4472005b5 | ||
|
|
1c2263c001 | ||
|
|
6f93bb5b88 | ||
|
|
1d2978952b | ||
|
|
937fc619dd | ||
|
|
30c46bd0a2 | ||
|
|
ae90c1b2b1 | ||
|
|
e6e85dc8d4 | ||
|
|
1a1242cc47 | ||
|
|
9b34b561d8 | ||
|
|
ee5cc24a4d | ||
|
|
6ebc172783 | ||
|
|
a6237f0dc5 | ||
|
|
66e2727acb | ||
|
|
78bcb037ac | ||
|
|
9aecbf9e66 | ||
|
|
bcba2f556b | ||
|
|
148f03a175 | ||
|
|
f39cfc7875 | ||
|
|
5bc166d3da | ||
|
|
7e5a844246 | ||
|
|
8cecf200eb | ||
|
|
535a6297af | ||
|
|
5ea2fdb651 | ||
|
|
bfe9044fda | ||
|
|
d277066d34 | ||
|
|
cbbe1478ae | ||
|
|
8848e712cc | ||
|
|
ed693d1742 | ||
|
|
626def198c | ||
|
|
b9fc9b054b | ||
|
|
602f68e88b | ||
|
|
dfa00b7605 | ||
|
|
27cb0aa260 | ||
|
|
416d080eb4 | ||
|
|
386c98575d | ||
|
|
84f9aef856 | ||
|
|
13cbb7507e | ||
|
|
4a1594f982 | ||
|
|
761ce507f1 | ||
|
|
67884ed9d3 | ||
|
|
12412d67fb | ||
|
|
2c58f6c9ae | ||
|
|
65e908546b | ||
|
|
ea18b8c090 | ||
|
|
6c182f3bba | ||
|
|
807c49eea1 | ||
|
|
50dd19222e | ||
|
|
b5bbf19a65 | ||
|
|
9ed06be68b | ||
|
|
9da0c76da6 | ||
|
|
1b06d19059 | ||
|
|
e258617c23 | ||
|
|
839a7227ab | ||
|
|
f49b111e15 | ||
|
|
d5d6b6fb4c | ||
|
|
7cc794d614 | ||
|
|
f209f5f157 | ||
|
|
ca4be438c5 | ||
|
|
d9411b190c | ||
|
|
ec2cb356c1 | ||
|
|
15a2db978c | ||
|
|
a9506b1f53 | ||
|
|
1a8f6752c7 | ||
|
|
637579db5c | ||
|
|
534c5506e6 | ||
|
|
a2182e0f05 | ||
|
|
0d0153c6e8 | ||
|
|
ca6281bf72 | ||
|
|
a50df7308f | ||
|
|
d31a51ab9a | ||
|
|
91aa31503b | ||
|
|
a5e07a0ebe | ||
|
|
cfa51276bd | ||
|
|
148470e4be | ||
|
|
fd72fbf9bd | ||
|
|
b37087a69d | ||
|
|
ec1694347a | ||
|
|
a89b001370 | ||
|
|
867a0f4ef7 | ||
|
|
fee7d87a21 | ||
|
|
ffd0ca0cec | ||
|
|
7d819d4ac6 | ||
|
|
e08ee26991 | ||
|
|
599649200c | ||
|
|
4e4c670c97 | ||
|
|
1def607a80 | ||
|
|
5bee5d6663 | ||
|
|
834b9b7a2a | ||
|
|
4e7bb7aec3 | ||
|
|
f4c73e3b32 | ||
|
|
bb6f8ded7f | ||
|
|
e7753fddec | ||
|
|
29e77faec9 | ||
|
|
e0cc198d96 | ||
|
|
cc9d194ddd | ||
|
|
0735fa2425 | ||
|
|
d8fc3f0a51 | ||
|
|
c47f124854 | ||
|
|
7dba58b1aa | ||
|
|
5f34b5aeb0 | ||
|
|
7470a25cbe | ||
|
|
28b31d3439 | ||
|
|
97d855b546 | ||
|
|
711564a0ab | ||
|
|
f20bc2c954 | ||
|
|
ed0702068c | ||
|
|
b568082c2d | ||
|
|
f89ae0d1b1 | ||
|
|
d2c4cf598a | ||
|
|
f9ceddfabf | ||
|
|
cec40a8f89 | ||
|
|
4a4ec2312a | ||
|
|
5417918382 | ||
|
|
f8b2b46172 | ||
|
|
d0f07ae62b | ||
|
|
5d7b99e328 | ||
|
|
ae563a7950 | ||
|
|
1f6668cd8c | ||
|
|
24a384eed7 | ||
|
|
b5eeee9b73 | ||
|
|
1bd32d97de | ||
|
|
5e6d771dad | ||
|
|
9b80be453c | ||
|
|
7d0bfc1aa7 | ||
|
|
3d31c32d40 | ||
|
|
087a6ee305 | ||
|
|
9056d7ced0 | ||
|
|
4a8e01caec | ||
|
|
1088729269 | ||
|
|
21ac176f5f | ||
|
|
b3cc1dec4b | ||
|
|
3da180beb0 | ||
|
|
acec30ae5a | ||
|
|
8229007710 | ||
|
|
80e0432c73 | ||
|
|
c97dccaf04 | ||
|
|
f4bdbe1ed1 | ||
|
|
75a67ae54e | ||
|
|
61c3144a48 | ||
|
|
8158bae9d5 | ||
|
|
9615aa0b7c | ||
|
|
870153ef88 | ||
|
|
741203ab81 | ||
|
|
0b74bf3fc3 | ||
|
|
f5f7489093 | ||
|
|
05dae37a28 | ||
|
|
1384a05830 | ||
|
|
256b4896cb | ||
|
|
c44011402f | ||
|
|
eff24ca4b3 | ||
|
|
8f16044c6b | ||
|
|
7c46027bd6 | ||
|
|
5f7b677db7 | ||
|
|
b27e02fed1 | ||
|
|
abe2189acd | ||
|
|
721659d959 | ||
|
|
d2e083922e | ||
|
|
34181ce370 | ||
|
|
a939c505f9 | ||
|
|
5de9fc8134 | ||
|
|
0c45ddf04d | ||
|
|
74e37ea72d | ||
|
|
c6c060b5e2 | ||
|
|
def283de08 | ||
|
|
be3d3189ec | ||
|
|
0581b7cc53 | ||
|
|
79b75e5de1 | ||
|
|
f7be9dec18 | ||
|
|
566226958f | ||
|
|
e45db97a54 | ||
|
|
ea58ffed74 | ||
|
|
eb1e49e7c7 | ||
|
|
b69c71a54b | ||
|
|
3aff219639 | ||
|
|
e1edd00fb0 | ||
|
|
70e0aada25 | ||
|
|
1c11ac38ea | ||
|
|
7ac8878f83 | ||
|
|
a48a18ba84 | ||
|
|
8a2a2061a9 | ||
|
|
b1f772eb2f | ||
|
|
37043c1284 | ||
|
|
7f693f4e1d | ||
|
|
529ed71ebe | ||
|
|
644d3d6402 | ||
|
|
83395619e7 | ||
|
|
cde6904e3f | ||
|
|
74dcbae3dd | ||
|
|
70f6a2fa78 | ||
|
|
567b0a2c19 | ||
|
|
5e28481684 | ||
|
|
90ed3d40f3 | ||
|
|
366285f625 | ||
|
|
7945b0facd | ||
|
|
556429a4d6 | ||
|
|
601d426721 | ||
|
|
aa3d3ca57c | ||
|
|
471cf5df85 | ||
|
|
177920a1eb | ||
|
|
ab4b4ad598 | ||
|
|
626f7141e9 | ||
|
|
30c7ac5100 | ||
|
|
b30489785f | ||
|
|
22e042d11d | ||
|
|
6137e851cd | ||
|
|
57419fd8d1 | ||
|
|
471962e664 | ||
|
|
7254d9d7a7 | ||
|
|
ea2418b981 | ||
|
|
5c4009e435 | ||
|
|
89c7beda26 | ||
|
|
c6109bd0d4 | ||
|
|
15d6e4f87c | ||
|
|
7cfd910122 | ||
|
|
c67619d54c | ||
|
|
38ec446130 | ||
|
|
60a5fd2443 | ||
|
|
f8907c6e8f | ||
|
|
61e318fb6e | ||
|
|
1382a83648 |
No files matched your search
@@ -0,0 +1,9 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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>
|
||||
@@ -1,6 +0,0 @@
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
@@ -1 +0,0 @@
|
||||
EhViewer
|
||||
@@ -1,23 +0,0 @@
|
||||
<?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>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?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>
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<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>
|
||||
@@ -1,7 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?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>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?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>
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<component name="DependencyValidationManager">
|
||||
<state>
|
||||
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
<?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>
|
||||
<dictionary>
|
||||
<key>?children?</key>
|
||||
<value>?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\|?name?=outputEntries\||</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value>NDK_DEBUG=0</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>ndk-build</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
|
||||
<value>clean</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
</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>
|
||||
@@ -14,9 +14,14 @@
|
||||
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">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hippo.ehviewer"
|
||||
android:versionCode="28"
|
||||
android:versionName="0.6.7" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
android:targetSdkVersion="19" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
@@ -28,17 +33,15 @@
|
||||
android:allowBackup="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:largeHeap="true"
|
||||
android:supportsRtl="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:icon="@drawable/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.Translucent" >
|
||||
android:theme="@style/AppTheme.NoActionBar.Transparent" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
@@ -60,15 +63,6 @@
|
||||
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|uiMode"
|
||||
@@ -90,12 +84,13 @@
|
||||
android:name=".ui.GalleryActivity"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@style/AppTheme.Dark.NoActionBar" >
|
||||
android:theme="@style/AppTheme.NoActionBar" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.SettingsActivity"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:icon="@drawable/ic_action_settings"
|
||||
android:label="@string/preference_settings_title"
|
||||
android:screenOrientation="behind" >
|
||||
</activity>
|
||||
@@ -103,22 +98,16 @@
|
||||
<activity
|
||||
android:name=".ui.FavouriteActivity"
|
||||
android:configChanges="orientation|screenSize|uiMode"
|
||||
android:icon="@drawable/ic_action_favorite"
|
||||
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|uiMode"
|
||||
android:icon="@drawable/ic_setting_download"
|
||||
android:label="@string/download"
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="behind"
|
||||
@@ -128,13 +117,6 @@
|
||||
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" />
|
||||
@@ -146,4 +128,4 @@
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?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>
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,13 @@
|
||||
# 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)).
|
||||
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,95 +0,0 @@
|
||||
<?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>
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
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'
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
# 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*();
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,695 +0,0 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,423 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,285 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -1,579 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.gallery.ui;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
|
||||
public class SynchronizedHandler extends Handler {
|
||||
|
||||
private final GLRoot mRoot;
|
||||
|
||||
public SynchronizedHandler(GLRoot root) {
|
||||
mRoot = Utils.checkNotNull(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchMessage(Message message) {
|
||||
mRoot.lockRenderThread();
|
||||
try {
|
||||
super.dispatchMessage(message);
|
||||
} finally {
|
||||
mRoot.unlockRenderThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
public final class Network {
|
||||
|
||||
public static final int NETWORK_STATE_NONE = 0x0;
|
||||
public static final int NETWORK_STATE_MOBILE = 0x1;
|
||||
public static final int NETWORK_STATE_WIFI = 0x2;
|
||||
|
||||
public static int getNetworkState(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo mWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
NetworkInfo mMobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
|
||||
if (mWifi != null && mWifi.isConnected())
|
||||
return NETWORK_STATE_WIFI;
|
||||
else if (mMobile != null && mMobile.isConnected())
|
||||
return NETWORK_STATE_MOBILE;
|
||||
else
|
||||
return NETWORK_STATE_NONE;
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* 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.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.app.MaterialAlertDialog;
|
||||
import com.hippo.ehviewer.widget.MaterialToast;
|
||||
|
||||
public class EditTextPreference extends DialogPreference {
|
||||
|
||||
private EditText mEditText;
|
||||
|
||||
private int mMax;
|
||||
private int mMin;
|
||||
|
||||
public EditTextPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0);
|
||||
}
|
||||
|
||||
public EditTextPreference(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyle) {
|
||||
mEditText = new EditText(context, attrs);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.EditTextPreference, defStyle, 0);
|
||||
mMax = a.getInt(R.styleable.EditTextPreference_etpMax, Integer.MAX_VALUE);
|
||||
mMin = a.getInt(R.styleable.EditTextPreference_etpMin, Integer.MIN_VALUE);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean inScrollView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
// Make sure mEditText is an orphan
|
||||
ViewParent oldParent = mEditText.getParent();
|
||||
if (oldParent != null)
|
||||
((ViewGroup) oldParent).removeView(mEditText);
|
||||
|
||||
mEditText.setTextColor(getContext().getResources().getColor(
|
||||
R.color.secondary_text_dark));
|
||||
return mEditText;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
mEditText.setText(getPersistedString(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(MaterialAlertDialog.Builder builder) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
return a.getString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restorePersistedValue,
|
||||
Object defaultValue) {
|
||||
setSummary(restorePersistedValue ? getPersistedString((String) defaultValue)
|
||||
: (String) defaultValue);
|
||||
if (!restorePersistedValue)
|
||||
persistString((String) defaultValue);
|
||||
}
|
||||
|
||||
// Return true for close and save
|
||||
private boolean checkBorder(String value) {
|
||||
boolean re;
|
||||
if (mMax == Integer.MAX_VALUE && mMin == Integer.MIN_VALUE) {
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
int intValue = Integer.parseInt(value);
|
||||
if (intValue > mMax || intValue < mMin)
|
||||
re = false;
|
||||
else
|
||||
re = true;
|
||||
} catch (Throwable e) {
|
||||
re = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Show Toast
|
||||
if (!re)
|
||||
MaterialToast.showToast(R.string.invalid_input);
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
super.onClick(dialog, which);
|
||||
if (which == MaterialAlertDialog.POSITIVE) {
|
||||
String value = mEditText.getText().toString();
|
||||
if (checkBorder(value) && callChangeListener(value)) {
|
||||
persistString(value);
|
||||
setSummary(value);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import com.hippo.ehviewer.cache.ImageCache;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
|
||||
public abstract class AbsActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Ui.adjustOrientation(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (Config.getAllowAnalyics())
|
||||
EasyTracker.getInstance(this).activityStart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if (Config.getAllowAnalyics())
|
||||
EasyTracker.getInstance(this).activityStop(this);
|
||||
|
||||
ImageCache.getInstance(this).flush();
|
||||
}
|
||||
}
|
||||
@@ -1,551 +0,0 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.AppHandler;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.app.DirSelectDialog;
|
||||
import com.hippo.ehviewer.app.MaterialAlertDialog;
|
||||
import com.hippo.ehviewer.data.Data;
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.ehclient.ExDownloader;
|
||||
import com.hippo.ehviewer.gallery.GalleryView;
|
||||
import com.hippo.ehviewer.gallery.data.ImageSet;
|
||||
import com.hippo.ehviewer.gallery.ui.GLRootView;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.FullScreenHelper;
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
import com.hippo.ehviewer.util.Utils;
|
||||
import com.hippo.ehviewer.widget.ColorView;
|
||||
import com.hippo.ehviewer.widget.MaterialToast;
|
||||
import com.hippo.ehviewer.widget.SlidingLayout;
|
||||
|
||||
public class GalleryActivity extends AbsActivity
|
||||
implements GalleryView.GalleryViewListener, SeekBar.OnSeekBarChangeListener,
|
||||
FullScreenHelper.OnFullScreenBrokenListener, CompoundButton.OnCheckedChangeListener,
|
||||
SlidingLayout.OnChildHideListener, AdapterView.OnItemSelectedListener,
|
||||
View.OnClickListener, Utils.OnCopyOverListener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final static String TAG = GalleryActivity.class.getSimpleName();
|
||||
|
||||
public final static String KEY_GALLERY_INFO = "gallery_info";
|
||||
public final static String KEY_START_INDEX = "start_index";
|
||||
|
||||
public final static String KEY_LIGHTNESS = "lightness";
|
||||
public final static float DEFAULT_LIGHTNESS = 0.5f;
|
||||
|
||||
public final static String KEY_FIRST_READ_CONFIG_V1 = "first_read_config_v1";
|
||||
public final static boolean DEFAULT_FIRST_READ_CONFIG_V1 = true;
|
||||
|
||||
public final static String KEY_LAST_SAVE_IMAGE_FILE_PATH = "last_save_image_file_path";
|
||||
public final static String DEFAULT_LAST_SAVE_IMAGE_FILE_PATH = null;
|
||||
|
||||
private View mClock;
|
||||
private View mBattery;
|
||||
|
||||
private SlidingLayout mConfigSliding;
|
||||
/** It store index, start from 0, so max is samller than size **/
|
||||
private TextView mCurrentPage;
|
||||
private TextView mPageSum;
|
||||
private SeekBar mPageSeeker;
|
||||
private TextView mRefresh;
|
||||
private TextView mSend;
|
||||
private TextView mMoreSettings;
|
||||
private Spinner mReadingDirection;
|
||||
private Spinner mPageScaling;
|
||||
private Spinner mStartPosition;
|
||||
private CheckBox mKeepScreenOn;
|
||||
private CheckBox mShowClock;
|
||||
private CheckBox mShowBattery;
|
||||
private CheckBox mCustomLightness;
|
||||
private SeekBar mCustomLightnessValue;
|
||||
private CheckBox mCustomCodec;
|
||||
private Spinner mDecodeFormat;
|
||||
|
||||
private ImageSet mImageSet;
|
||||
|
||||
private GalleryView mGalleryView;
|
||||
|
||||
private ColorView mMaskView;
|
||||
|
||||
private GalleryInfo mGi;
|
||||
|
||||
private FullScreenHelper mFullScreenHelper;
|
||||
|
||||
private File mCurImageFile;
|
||||
|
||||
private Dialog mSendDialog;
|
||||
|
||||
private final Runnable mFullScreenTask = new Runnable() {
|
||||
@Override public void run() {
|
||||
mFullScreenHelper.setFullScreen(true);
|
||||
}
|
||||
};
|
||||
|
||||
private void startFullScreenTask() {
|
||||
AppHandler.getInstance().postDelayed(mFullScreenTask, 2000);
|
||||
}
|
||||
|
||||
private void cancelFullScreenTask() {
|
||||
AppHandler.getInstance().removeCallbacks(mFullScreenTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCopyOver(boolean success, File src, File dst) {
|
||||
MaterialToast.showToast(success ? String.format(getString(R.string.save_successful), dst.getPath())
|
||||
: getString(R.string.save_failed));
|
||||
if (success)
|
||||
Config.setString(KEY_LAST_SAVE_IMAGE_FILE_PATH, dst.getParent());
|
||||
}
|
||||
|
||||
private Dialog createSaveImageDialog() {
|
||||
return DirSelectDialog.create(
|
||||
new MaterialAlertDialog.Builder(GalleryActivity.this)
|
||||
.setDrakTheme(true).setTitle(R.string.select_save_dir)
|
||||
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
|
||||
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
if (which == MaterialAlertDialog.POSITIVE) {
|
||||
String targetPath = ((DirSelectDialog) dialog).getCurrentPath();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(mImageSet.getTitle()).append("-").append(mGalleryView.getCurIndex() + 1)
|
||||
.append(".").append(Utils.getExtension(mCurImageFile.getName(), "jpg"));
|
||||
Utils.copyInNewThread(mCurImageFile, new File(targetPath, Utils.standardizeFilename(sb.toString())),
|
||||
GalleryActivity.this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}),
|
||||
Config.getString(KEY_LAST_SAVE_IMAGE_FILE_PATH, null));
|
||||
}
|
||||
|
||||
private Dialog createSendDialog() {
|
||||
return new MaterialAlertDialog.Builder(this).setDrakTheme(true).setTitle(R.string.send)
|
||||
.setItems(R.array.send_entries, new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
// Check current image file again
|
||||
if (mCurImageFile == null || !mCurImageFile.exists()) {
|
||||
MaterialToast.showToast(R.string.current_image_not_downloaded);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (which) {
|
||||
case 0:
|
||||
createSaveImageDialog().show();
|
||||
break;
|
||||
case 1:
|
||||
Uri uri = Uri.fromFile(mCurImageFile);
|
||||
Intent shareIntent = new Intent();
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
shareIntent.setType(Utils.getMimeType(uri.toString()));
|
||||
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_image)));
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel).create();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFullScreenBroken(boolean fullScreen) {
|
||||
// TODO For some MIUI system, onSystemUiVisibilityChange() do not work fine
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
updateState();
|
||||
mFullScreenHelper.setFullScreen(!mConfigSliding.isShowing());
|
||||
}
|
||||
|
||||
private void setScreenLightness(boolean enable, int lightness) {
|
||||
Window w = getWindow();
|
||||
WindowManager.LayoutParams lp = w.getAttributes();
|
||||
if (enable) {
|
||||
lightness = MathUtils.clamp(lightness, 0, 200);
|
||||
if (lightness > 100) {
|
||||
mMaskView.setColor(0);
|
||||
// Avoid BRIGHTNESS_OVERRIDE_OFF,
|
||||
// screen may be off when lp.screenBrightness is 0.0f
|
||||
lp.screenBrightness = Math.max((lightness - 100) / 100.0f, 0.05f);
|
||||
} else {
|
||||
mMaskView.setColor(MathUtils.lerp(0xde, 0x00, lightness / 100.0f) << 24);
|
||||
lp.screenBrightness = 0.05f;
|
||||
}
|
||||
} else {
|
||||
mMaskView.setColor(0);
|
||||
lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
|
||||
}
|
||||
w.setAttributes(lp);
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
mReadingDirection.setSelection(Config.getReadingDirection());
|
||||
mPageScaling.setSelection(Config.getPageScaling());
|
||||
mStartPosition.setSelection(Config.getStartPosition());
|
||||
mGalleryView.setReadingDirection(Config.getReadingDirection());
|
||||
mGalleryView.setPageScaling(Config.getPageScaling());
|
||||
mGalleryView.setStartPosition(Config.getStartPosition());
|
||||
|
||||
mKeepScreenOn.setChecked(Config.getKeepSreenOn());
|
||||
if (Config.getKeepSreenOn())
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
mShowClock.setChecked(Config.getShowClock());
|
||||
mShowBattery.setChecked(Config.getShowBattery());
|
||||
mClock.setVisibility(Config.getShowClock() ? View.VISIBLE : View.GONE);
|
||||
mBattery.setVisibility(Config.getShowBattery() ? View.VISIBLE : View.GONE);
|
||||
|
||||
mCustomLightness.setChecked(Config.getCustomLightness());
|
||||
if (mCustomLightness.isChecked())
|
||||
mCustomLightnessValue.setEnabled(true);
|
||||
else
|
||||
mCustomLightnessValue.setEnabled(false);
|
||||
mCustomLightnessValue.setProgress(Config.getCustomLightnessValue());
|
||||
setScreenLightness(mCustomLightness.isChecked(), mCustomLightnessValue.getProgress());
|
||||
|
||||
if (Utils.SUPPORT_IMAGE)
|
||||
mCustomCodec.setEnabled(true);
|
||||
else
|
||||
mCustomCodec.setEnabled(false);
|
||||
mCustomCodec.setChecked(Config.getCustomCodec());
|
||||
if (Utils.SUPPORT_IMAGE && mCustomCodec.isChecked())
|
||||
mDecodeFormat.setEnabled(true);
|
||||
else
|
||||
mDecodeFormat.setEnabled(false);
|
||||
mDecodeFormat.setSelection(Config.getDecodeFormatIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.gl_root_group);
|
||||
|
||||
mFullScreenHelper = new FullScreenHelper(this);
|
||||
mFullScreenHelper.setOnFullScreenBrokenListener(this);
|
||||
mFullScreenHelper.setFullScreen(true);
|
||||
|
||||
mMaskView = (ColorView)findViewById(R.id.mask);
|
||||
mClock = findViewById(R.id.clock);
|
||||
mBattery = findViewById(R.id.battery);
|
||||
|
||||
mConfigSliding = (SlidingLayout) findViewById(R.id.config_sliding);
|
||||
mCurrentPage = (TextView) mConfigSliding.findViewById(R.id.current_page);
|
||||
mPageSum = (TextView) mConfigSliding.findViewById(R.id.page_sum);
|
||||
mPageSeeker = (SeekBar) mConfigSliding.findViewById(R.id.page_seeker);
|
||||
mRefresh = (TextView) mConfigSliding.findViewById(R.id.refresh);
|
||||
mSend = (TextView) mConfigSliding.findViewById(R.id.send);
|
||||
mMoreSettings = (TextView) mConfigSliding.findViewById(R.id.more_settings);
|
||||
mReadingDirection = (Spinner) mConfigSliding.findViewById(R.id.reading_direction);
|
||||
mPageScaling = (Spinner) mConfigSliding.findViewById(R.id.page_scaling);
|
||||
mStartPosition = (Spinner) mConfigSliding.findViewById(R.id.start_position);
|
||||
mKeepScreenOn = (CheckBox) mConfigSliding.findViewById(R.id.keep_screen_on);
|
||||
mShowClock = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_clock);
|
||||
mShowBattery = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_battery);
|
||||
mCustomLightness = (CheckBox) mConfigSliding.findViewById(R.id.custom_lightness);
|
||||
mCustomLightnessValue = (SeekBar) mConfigSliding.findViewById(R.id.custom_lightness_value);
|
||||
mCustomCodec = (CheckBox) mConfigSliding.findViewById(R.id.custom_codec);
|
||||
mDecodeFormat = (Spinner) mConfigSliding.findViewById(R.id.decode_format);
|
||||
|
||||
mConfigSliding.hide();
|
||||
|
||||
mSendDialog = createSendDialog();
|
||||
|
||||
Intent intent = getIntent();
|
||||
mGi = (GalleryInfo) intent.getParcelableExtra(KEY_GALLERY_INFO);
|
||||
|
||||
if (mGi == null) {
|
||||
// Get error force finish
|
||||
new MaterialAlertDialog.Builder(this).setTitle(R.string.error)
|
||||
.setMessage(R.string.ga_data_error)
|
||||
.setPositiveButton(R.string.close)
|
||||
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
}).show();
|
||||
} else {
|
||||
|
||||
Data.getInstance().addHistory(mGi, Data.READ);
|
||||
|
||||
int startIndex = intent.getIntExtra(KEY_START_INDEX, 0);
|
||||
if (startIndex == -1)
|
||||
startIndex = ExDownloader.readCurReadIndex(mGi.gid, mGi.title);
|
||||
|
||||
mImageSet = new ImageSet(mGi.gid, mGi.token, mGi.title, startIndex);
|
||||
mGalleryView = new GalleryView(getApplicationContext(), mImageSet, startIndex);
|
||||
|
||||
GLRootView glrv= (GLRootView)findViewById(R.id.gl_root_view);
|
||||
glrv.setContentPane(mGalleryView);
|
||||
|
||||
// Set listener
|
||||
mConfigSliding.setOnChildHideListener(this);
|
||||
mGalleryView.setGalleryViewListener(this);
|
||||
mPageSeeker.setOnSeekBarChangeListener(this);
|
||||
mRefresh.setOnClickListener(this);
|
||||
mSend.setOnClickListener(this);
|
||||
mMoreSettings.setOnClickListener(this);
|
||||
mReadingDirection.setOnItemSelectedListener(this);
|
||||
mPageScaling.setOnItemSelectedListener(this);
|
||||
mStartPosition.setOnItemSelectedListener(this);
|
||||
mDecodeFormat.setOnItemSelectedListener(this);
|
||||
mKeepScreenOn.setOnCheckedChangeListener(this);
|
||||
mShowClock.setOnCheckedChangeListener(this);
|
||||
mShowBattery.setOnCheckedChangeListener(this);
|
||||
mCustomLightness.setOnCheckedChangeListener(this);
|
||||
mCustomLightnessValue.setOnSeekBarChangeListener(this);
|
||||
mCustomCodec.setOnCheckedChangeListener(this);
|
||||
|
||||
mKeepScreenOn = (CheckBox) mConfigSliding.findViewById(R.id.keep_screen_on);
|
||||
mShowClock = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_clock);
|
||||
mShowBattery = (CheckBox) mConfigSliding.findViewById(R.id.gallery_show_battery);
|
||||
mCustomCodec = (CheckBox) mConfigSliding.findViewById(R.id.custom_codec);
|
||||
|
||||
mPageSeeker.setMax(mGalleryView.getSize() - 1);
|
||||
mPageSeeker.setProgress(startIndex);
|
||||
|
||||
mCurrentPage.setText(Integer.toString(startIndex + 1));
|
||||
mPageSum.setText(Integer.toString(mGalleryView.getSize()));
|
||||
|
||||
onRightToLeftChanged(mGalleryView.isRightToLeft());
|
||||
|
||||
// Show first tip
|
||||
String keyGalleryFirst = "gallery_first";
|
||||
if (Config.getBoolean(keyGalleryFirst, true)) {
|
||||
Config.setBoolean(keyGalleryFirst, false);
|
||||
new MaterialAlertDialog.Builder(this).setDrakTheme(true).setTitle(R.string.tip)
|
||||
.setMessage(R.string.gallery_tip)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setButtonListener(new MaterialAlertDialog.OnClickListener() {
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
mFullScreenHelper.setFullScreen(true);
|
||||
return true;
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
// Update state
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mImageSet != null)
|
||||
mImageSet.free();
|
||||
if (mGalleryView != null)
|
||||
mGalleryView.free();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mConfigSliding.isInHideAnimate())
|
||||
return;
|
||||
|
||||
if (mConfigSliding.isShowing())
|
||||
mConfigSliding.toBaseLevel();
|
||||
else
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mRefresh) {
|
||||
mImageSet.redownload(mGalleryView.getCurIndex());
|
||||
} else if (v == mSend) {
|
||||
mCurImageFile = mImageSet.getImageFile(mGalleryView.getCurIndex());
|
||||
if (mCurImageFile == null || !mCurImageFile.exists())
|
||||
MaterialToast.showToast(R.string.current_image_not_downloaded);
|
||||
else
|
||||
mSendDialog.show();
|
||||
|
||||
} else if (v == mMoreSettings) {
|
||||
Intent intent = new Intent(GalleryActivity.this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTapCenter() {
|
||||
if (!mConfigSliding.isShowing()) {
|
||||
if (mFullScreenHelper.willHideNavBar())
|
||||
cancelFullScreenTask();
|
||||
mFullScreenHelper.setFullScreen(false);
|
||||
|
||||
boolean firstTime = Config.getBoolean(KEY_FIRST_READ_CONFIG_V1, DEFAULT_FIRST_READ_CONFIG_V1);
|
||||
mConfigSliding.toReservedLevel(firstTime);
|
||||
if (firstTime)
|
||||
Config.setBoolean(KEY_FIRST_READ_CONFIG_V1, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageChanged(int index) {
|
||||
mPageSeeker.setProgress(index);
|
||||
mCurrentPage.setText(Integer.toString(index + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeUpdate(int size) {
|
||||
mPageSeeker.setMax(size - 1);
|
||||
mPageSeeker.setProgress(mGalleryView.getCurIndex() + 1);
|
||||
mCurrentPage.setText(Integer.toString(mGalleryView.getCurIndex() + 1));
|
||||
mPageSum.setText(Integer.toString(size));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideBottom(float dx) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideBottomOver() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
public void onRightToLeftChanged(boolean value) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
int nevLd = value ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
|
||||
if (mPageSeeker.getLayoutDirection() != nevLd) {
|
||||
mPageSeeker.setLayoutDirection(nevLd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress,
|
||||
boolean fromUser) {
|
||||
if (seekBar == mPageSeeker) {
|
||||
mCurrentPage.setText(Integer.toString(progress + 1));
|
||||
} else if (seekBar == mCustomLightnessValue) {
|
||||
setScreenLightness(mCustomLightness.isChecked(), progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
if (seekBar == mPageSeeker) {
|
||||
mGalleryView.goToPage(seekBar.getProgress());
|
||||
} else if (seekBar == mCustomLightnessValue) {
|
||||
Config.setCustomLightnessValue(seekBar.getProgress());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildHide() {
|
||||
if (mFullScreenHelper.willHideNavBar())
|
||||
startFullScreenTask();
|
||||
else
|
||||
mFullScreenHelper.setFullScreen(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
if (parent == mReadingDirection) {
|
||||
Config.setReadingDirection(mReadingDirection.getSelectedItemPosition());
|
||||
mGalleryView.setReadingDirection(position);
|
||||
} else if (parent == mPageScaling) {
|
||||
Config.setPageScaling(mPageScaling.getSelectedItemPosition());
|
||||
mGalleryView.setPageScaling(position);
|
||||
} else if (parent == mStartPosition) {
|
||||
Config.setStartPosition(mStartPosition.getSelectedItemPosition());
|
||||
mGalleryView.setStartPosition(position);
|
||||
} else if (parent == mDecodeFormat) {
|
||||
Config.setDecodeFormatFromIndex(mDecodeFormat.getSelectedItemPosition());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (buttonView == mShowClock) {
|
||||
Config.setShowClock(isChecked);
|
||||
mClock.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
} else if (buttonView == mShowBattery) {
|
||||
Config.setShowBattery(isChecked);
|
||||
mBattery.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
} else if (buttonView == mKeepScreenOn) {
|
||||
Config.setKeepSreenOn(isChecked);
|
||||
if (isChecked)
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
} else if (buttonView == mCustomLightness) {
|
||||
Config.setCustomLightness(isChecked);
|
||||
if (isChecked)
|
||||
mCustomLightnessValue.setEnabled(true);
|
||||
else
|
||||
mCustomLightnessValue.setEnabled(false);
|
||||
setScreenLightness(isChecked, mCustomLightnessValue.getProgress());
|
||||
} else if (buttonView == mCustomCodec) {
|
||||
Config.setCustomCodec(isChecked);
|
||||
if (Utils.SUPPORT_IMAGE && mCustomCodec.isChecked())
|
||||
mDecodeFormat.setEnabled(true);
|
||||
else
|
||||
mDecodeFormat.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.app.MaterialAlertDialog;
|
||||
import com.hippo.ehviewer.data.Data;
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.drawable.MaterialIndicatorDrawable;
|
||||
import com.hippo.ehviewer.drawable.MaterialIndicatorDrawable.Stroke;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
import com.hippo.ehviewer.widget.FitWindowView;
|
||||
import com.hippo.ehviewer.widget.GalleryListView;
|
||||
import com.hippo.ehviewer.widget.GalleryListView.OnGetListListener;
|
||||
import com.hippo.ehviewer.widget.recyclerview.EasyRecyclerView;
|
||||
|
||||
public class HistoryActivity extends AbsTranslucentActivity
|
||||
implements EasyRecyclerView.OnItemClickListener, MaterialAlertDialog.OnClickListener,
|
||||
GalleryListView.GalleryListViewHelper, FitWindowView.OnFitSystemWindowsListener {
|
||||
|
||||
private static final String TAG = HistoryActivity.class.getSimpleName();
|
||||
|
||||
public static final int LIST_MODE_DETAIL = 0;
|
||||
public static final int LIST_MODE_THUMB = 1;
|
||||
|
||||
private Data mData;
|
||||
private int mThemeColor;
|
||||
|
||||
private FitWindowView mStandard;
|
||||
private GalleryListView mGalleryListView;
|
||||
|
||||
private int mFilterMode;
|
||||
|
||||
private Dialog mFilterDialog;
|
||||
private CheckBox mJustBrowse;
|
||||
private CheckBox mHaveRead;
|
||||
|
||||
private Dialog mClearDialog;
|
||||
|
||||
private static final String HISTORY_URL = "ehviewer://history";
|
||||
private static final String KEY_HISTORY_FILTER = "history_filter";
|
||||
|
||||
private void setFilterDialogMode(int filterMode) {
|
||||
if ((filterMode & Data.BROWSE) == 0)
|
||||
mJustBrowse.setChecked(false);
|
||||
else
|
||||
mJustBrowse.setChecked(true);
|
||||
if ((filterMode & Data.READ) == 0)
|
||||
mHaveRead.setChecked(false);
|
||||
else
|
||||
mHaveRead.setChecked(true);
|
||||
}
|
||||
|
||||
private int getFilterDialogMode() {
|
||||
int filterMode = 0;
|
||||
filterMode |= mJustBrowse.isChecked() ? Data.BROWSE : 0;
|
||||
filterMode |= mHaveRead.isChecked() ? Data.READ : 0;
|
||||
return filterMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(MaterialAlertDialog dialog, int which) {
|
||||
if (dialog == mFilterDialog) {
|
||||
switch (which) {
|
||||
case MaterialAlertDialog.POSITIVE:
|
||||
int newFilterMode = getFilterDialogMode();
|
||||
if (newFilterMode != mFilterMode) {
|
||||
mFilterMode = newFilterMode;
|
||||
Config.setInt(KEY_HISTORY_FILTER, mFilterMode);
|
||||
mGalleryListView.refresh();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (dialog == mClearDialog) {
|
||||
switch (which) {
|
||||
case MaterialAlertDialog.POSITIVE:
|
||||
Data.getInstance().clearHistory();
|
||||
mGalleryListView.refresh();
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private void createFilterDialog() {
|
||||
View view = ViewUtils.inflateDialogView(R.layout.history_filter, false);
|
||||
mJustBrowse = (CheckBox) view.findViewById(R.id.just_browse);
|
||||
mHaveRead = (CheckBox) view.findViewById(R.id.have_read);
|
||||
|
||||
mFilterDialog = new MaterialAlertDialog.Builder(this).setTitle(R.string.filter)
|
||||
.setView(view, true)
|
||||
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
|
||||
.setButtonListener(this).create();
|
||||
}
|
||||
|
||||
private void createClearDialog() {
|
||||
mClearDialog = new MaterialAlertDialog.Builder(this).setTitle(R.string.attention)
|
||||
.setMessage(R.string.clear_history_message)
|
||||
.setDefaultButton(MaterialAlertDialog.POSITIVE | MaterialAlertDialog.NEGATIVE)
|
||||
.setButtonListener(this).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFitSystemWindows(int l, int t, int r, int b) {
|
||||
mGalleryListView.setPaddingTopAndBottom(t, b);
|
||||
Ui.colorStatusBarKK(this, mThemeColor, t - Ui.ACTION_BAR_HEIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
mGalleryListView.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.history);
|
||||
|
||||
mData = Data.getInstance();
|
||||
mFilterMode = Config.getInt(KEY_HISTORY_FILTER, Data.BROWSE | Data.READ);
|
||||
|
||||
// Menu
|
||||
MaterialIndicatorDrawable materialIndicator = new MaterialIndicatorDrawable(this, Color.WHITE, Stroke.THIN);
|
||||
materialIndicator.setIconState(MaterialIndicatorDrawable.IconState.ARROW);
|
||||
Ui.setMaterialIndicator(getActionBar(), materialIndicator);
|
||||
|
||||
// Theme
|
||||
mThemeColor = Config.getCustomThemeColor() ? Config.getThemeColor() : Ui.THEME_COLOR;
|
||||
getActionBar().setBackgroundDrawable(new ColorDrawable(mThemeColor));
|
||||
Ui.colorStatusBarL(this, mThemeColor);
|
||||
|
||||
mStandard = (FitWindowView) findViewById(R.id.standard);
|
||||
mGalleryListView = (GalleryListView) findViewById(R.id.gallery_list);
|
||||
|
||||
mGalleryListView.setGalleryListViewHelper(this);
|
||||
mStandard.addOnFitSystemWindowsListener(this);
|
||||
|
||||
// Do not need header an footer
|
||||
mGalleryListView.setEnabledHeader(false);
|
||||
mGalleryListView.setEnabledFooter(false);
|
||||
mGalleryListView.setOnItemClickListener(this);
|
||||
|
||||
createFilterDialog();
|
||||
createClearDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.history, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
|
||||
case R.id.action_filter:
|
||||
if (!mFilterDialog.isShowing()) {
|
||||
setFilterDialogMode(mFilterMode);
|
||||
mFilterDialog.show();
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.action_clear:
|
||||
if (!mClearDialog.isShowing())
|
||||
mClearDialog.show();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetUrl(int targetPage) {
|
||||
return HISTORY_URL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGetGallerys(String url, long taskStamp,
|
||||
OnGetListListener listener) {
|
||||
if (url.equals(HISTORY_URL)) {
|
||||
List<GalleryInfo> giList = new ArrayList<GalleryInfo>(mData.getHistory(mFilterMode, true));
|
||||
if (giList == null || giList.size() == 0)
|
||||
listener.onSuccess(taskStamp, giList, 0);
|
||||
else
|
||||
listener.onSuccess(taskStamp, giList, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view,
|
||||
int position, long id) {
|
||||
Intent intent = new Intent(this, GalleryDetailActivity.class);
|
||||
GalleryInfo gi = mGalleryListView.getGalleryInfo(position);
|
||||
intent.putExtra(GalleryDetailActivity.KEY_G_INFO, gi);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.effect.DrawableTransition;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Secret;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.widget.MaterialToast;
|
||||
|
||||
public class SecretActivity extends AbsActivity implements View.OnClickListener {
|
||||
|
||||
private final long[] mHits = new long[3];
|
||||
private Bitmap mBmp;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mBmp = Secret.getSecretImage(this);
|
||||
if (mBmp == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
int themeColor = Config.getCustomThemeColor() ? Config.getThemeColor() : Ui.THEME_COLOR;
|
||||
Ui.colorStatusBarL(this, themeColor);
|
||||
|
||||
ImageView iv = new ImageView(this);
|
||||
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
iv.setImageBitmap(mBmp);
|
||||
iv.setOnClickListener(this);
|
||||
iv.setSoundEffectsEnabled(false);
|
||||
setContentView(iv);
|
||||
DrawableTransition.transit(iv.getDrawable(), false, 3000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mBmp != null) {
|
||||
mBmp.recycle();
|
||||
mBmp = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
|
||||
mHits[mHits.length-1] = SystemClock.uptimeMillis();
|
||||
if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
|
||||
Arrays.fill(mHits, 0);
|
||||
MaterialToast.showToast(R.string.photo_footnotes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import com.hippo.ehviewer.ehclient.EhClient;
|
||||
import com.hippo.ehviewer.ehclient.EhInfo;
|
||||
|
||||
public class WebViewLoginActivity extends AbsActivity {
|
||||
|
||||
private static final String TITLE_LOGIN_SUCCESS = "Please stand by...";
|
||||
|
||||
public static final String KEY_ERROR = "error";
|
||||
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
CookieManager.getInstance().removeAllCookie();
|
||||
WebView wv = new WebView(this);
|
||||
wv.setWebViewClient(new LoginWebViewClient());
|
||||
wv.loadUrl(EhClient.LOGIN_URL);
|
||||
setContentView(wv);
|
||||
}
|
||||
|
||||
private class LoginWebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
if (TITLE_LOGIN_SUCCESS.equals(view.getTitle())) {
|
||||
// Login OK
|
||||
String cookies = CookieManager.getInstance().getCookie(url);
|
||||
if (cookies != null) {
|
||||
// Store cookie
|
||||
EhInfo ehInfo = EhInfo.getInstance(WebViewLoginActivity.this);
|
||||
ehInfo.setCookie(cookies);
|
||||
ehInfo.login("User", "User");
|
||||
setResult(RESULT_OK);
|
||||
} else {
|
||||
setResult(RESULT_CANCELED);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.app.MaterialAlertDialog;
|
||||
|
||||
public class DialogUtils {
|
||||
|
||||
public static MaterialAlertDialog.Builder createUpdateDialog(Context context, String version, String size,
|
||||
String info, MaterialAlertDialog.OnClickListener l) {
|
||||
|
||||
return new MaterialAlertDialog.Builder(context).setTitle(R.string.update).setCancelable(false)
|
||||
.setMessage(String.format(context.getString(R.string.update_message), version, size, info))
|
||||
.setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel).setButtonListener(l);
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
public final class FullScreenHelper implements View.OnSystemUiVisibilityChangeListener {
|
||||
|
||||
private static final String TAG = FullScreenHelper.class.getSimpleName();
|
||||
|
||||
private final int NOT_FULL_SCREEN_JELLY_BEAN =
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
||||
|
||||
private final int FULL_SCREEN_JELLY_BEAN =
|
||||
NOT_FULL_SCREEN_JELLY_BEAN |
|
||||
View.SYSTEM_UI_FLAG_LOW_PROFILE |
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
|
||||
private final int FULL_SCREEN_FLAG_JELLY_BEAN =
|
||||
View.SYSTEM_UI_FLAG_LOW_PROFILE |
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
|
||||
private final int NOT_FULL_SCREEN_KITKAT =
|
||||
NOT_FULL_SCREEN_JELLY_BEAN |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
|
||||
|
||||
private final int FULL_SCREEN_KITKAT =
|
||||
NOT_FULL_SCREEN_KITKAT |
|
||||
View.SYSTEM_UI_FLAG_LOW_PROFILE |
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
|
||||
private boolean mFullScreen;
|
||||
private final Activity mActivity;
|
||||
private final Window mWindow;
|
||||
private final View mDecorView;
|
||||
|
||||
private boolean mHasNavBar;
|
||||
|
||||
private OnFullScreenBrokenListener mListener;
|
||||
|
||||
private final int TEST_SDK = Build.VERSION.SDK_INT;
|
||||
|
||||
public interface OnFullScreenBrokenListener {
|
||||
/**
|
||||
* FullScreen state should be fullScreen or not,
|
||||
* but user or system broke it
|
||||
*
|
||||
* @param fullScreen support to be
|
||||
*/
|
||||
public void onFullScreenBroken(boolean fullScreen);
|
||||
}
|
||||
|
||||
public FullScreenHelper(Activity activity) {
|
||||
mFullScreen = false;
|
||||
mActivity = activity;
|
||||
mWindow = mActivity.getWindow();
|
||||
mDecorView = mWindow.getDecorView();
|
||||
mDecorView.setOnSystemUiVisibilityChangeListener(this);
|
||||
|
||||
String mainKey = Utils.getSystemProperties("qemu.hw.mainkeys");
|
||||
int resourceId = activity.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
|
||||
if (resourceId != 0) {
|
||||
mHasNavBar = activity.getResources().getBoolean(resourceId);
|
||||
// check override flag (see static block)
|
||||
if ("1".equals(mainKey)) {
|
||||
mHasNavBar = false;
|
||||
} else if ("0".equals(mainKey)) {
|
||||
mHasNavBar = true;
|
||||
}
|
||||
} else {
|
||||
mHasNavBar = !ViewConfiguration.get(activity).hasPermanentMenuKey();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean willHideNavBar() {
|
||||
if (TEST_SDK >= Build.VERSION_CODES.KITKAT && mHasNavBar)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility) {
|
||||
if (TEST_SDK >= Build.VERSION_CODES.JELLY_BEAN &&
|
||||
TEST_SDK < Build.VERSION_CODES.KITKAT) {
|
||||
if ((mFullScreen && visibility != FULL_SCREEN_FLAG_JELLY_BEAN) ||
|
||||
(!mFullScreen && visibility != 0)) {
|
||||
// User or system change visibility
|
||||
if (mListener != null)
|
||||
mListener.onFullScreenBroken(mFullScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnFullScreenBrokenListener(OnFullScreenBrokenListener l) {
|
||||
mListener = l;
|
||||
}
|
||||
|
||||
public boolean getFullScreen() {
|
||||
return mFullScreen;
|
||||
}
|
||||
|
||||
public void setFullScreen(boolean fullScreen) {
|
||||
mFullScreen = fullScreen;
|
||||
if (fullScreen) {
|
||||
if (TEST_SDK < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
// Empty
|
||||
} else if (TEST_SDK < Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
} else if (TEST_SDK < Build.VERSION_CODES.KITKAT) {
|
||||
mDecorView.setSystemUiVisibility(FULL_SCREEN_JELLY_BEAN);
|
||||
|
||||
} else {
|
||||
mDecorView.setSystemUiVisibility(FULL_SCREEN_KITKAT);
|
||||
}
|
||||
} else {
|
||||
if (TEST_SDK < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
// Empty
|
||||
} else if (TEST_SDK < Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
} else if (TEST_SDK < Build.VERSION_CODES.KITKAT) {
|
||||
mDecorView.setSystemUiVisibility(NOT_FULL_SCREEN_JELLY_BEAN);
|
||||
|
||||
} else {
|
||||
mDecorView.setSystemUiVisibility(NOT_FULL_SCREEN_KITKAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.hippo.ehviewer.network.HttpHelper;
|
||||
|
||||
public final class Secret {
|
||||
|
||||
private static final String DIR_NAME = "images";
|
||||
private static final String IMAGE_NAME = "sercet.jpg";
|
||||
private static final String SERCET_IMAGE_URL = "http://www.ehviewer.com/static/images/pandas.jpg";
|
||||
|
||||
private static volatile boolean sIsGetSecretImage = false;
|
||||
|
||||
public static void updateSecretImage(Context context) {
|
||||
if (sIsGetSecretImage)
|
||||
return;
|
||||
sIsGetSecretImage = true;
|
||||
|
||||
new UpdateSercetImageThread(context).start();
|
||||
}
|
||||
|
||||
public static boolean hasSecretImage(Context context) {
|
||||
if (sIsGetSecretImage)
|
||||
return false;
|
||||
|
||||
File dir = context.getExternalFilesDir(DIR_NAME);
|
||||
File image = new File(dir, IMAGE_NAME);
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||
opts.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(image.getAbsolutePath(), opts);
|
||||
return opts.outWidth > 0 && opts.outHeight > 0;
|
||||
}
|
||||
|
||||
public static Bitmap getSecretImage(Context context) {
|
||||
if (sIsGetSecretImage)
|
||||
return null;
|
||||
|
||||
File dir = context.getExternalFilesDir(DIR_NAME);
|
||||
File image = new File(dir, IMAGE_NAME);
|
||||
return BitmapFactory.decodeFile(image.getAbsolutePath(), null);
|
||||
}
|
||||
|
||||
private static class UpdateSercetImageThread extends BgThread {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public UpdateSercetImageThread(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO check usable space
|
||||
File dir = mContext.getExternalFilesDir(DIR_NAME);
|
||||
File image = new File(dir, IMAGE_NAME);
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||
opts.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(image.getAbsolutePath(), opts);
|
||||
if (opts.outWidth <= 0 || opts.outHeight <= 0) {
|
||||
// Get image error, try to get image from internet
|
||||
HttpHelper hh = new HttpHelper(mContext);
|
||||
hh.download(SERCET_IMAGE_URL, mContext.getExternalFilesDir(DIR_NAME),
|
||||
IMAGE_NAME, false, null, null);
|
||||
}
|
||||
sIsGetSecretImage = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class ColorView extends View {
|
||||
|
||||
private int mColor;
|
||||
|
||||
public ColorView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ColorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ColorView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public ColorView(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
if (mColor != color) {
|
||||
mColor = color;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
canvas.drawColor(mColor);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
|
||||
public class DrawerListView extends ListView {
|
||||
|
||||
private Context mContext;
|
||||
private DrawerListAdapter mAdapter;
|
||||
|
||||
private static final int DRAWABLE_SIDE = Ui.dp2pix(24);
|
||||
|
||||
public DrawerListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public DrawerListView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public DrawerListView(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mContext = context;
|
||||
mAdapter = new DrawerListAdapter();
|
||||
setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
public void setData(Drawable[] drawableArray, CharSequence[] titleArray) {
|
||||
mAdapter.setData(drawableArray, titleArray);
|
||||
}
|
||||
|
||||
private class DrawerListAdapter extends BaseAdapter {
|
||||
|
||||
private Drawable[] mDrawableArray;
|
||||
private CharSequence[] mTitleArray;
|
||||
|
||||
private void setData(Drawable[] drawableArray, CharSequence[] titleArray) {
|
||||
if (drawableArray != null && titleArray != null) {
|
||||
if (drawableArray.length != titleArray.length)
|
||||
throw new java.lang.IllegalStateException("drawableArray.length != titleArray.length");
|
||||
} else if (drawableArray == null && titleArray == null) {
|
||||
throw new java.lang.IllegalStateException("drawableArray and titleArray should be all null or not null");
|
||||
}
|
||||
mDrawableArray = drawableArray;
|
||||
mTitleArray = titleArray;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mTitleArray == null ? 0 : mTitleArray.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null)
|
||||
convertView = LayoutInflater.from(mContext).inflate(R.layout.drawer_list_item, parent, false);
|
||||
|
||||
TextView tv = (TextView) convertView;
|
||||
Drawable d = mDrawableArray[position];
|
||||
CharSequence t = mTitleArray[position];
|
||||
tv.setText(t);
|
||||
d.setBounds(0, 0, DRAWABLE_SIDE, DRAWABLE_SIDE);
|
||||
tv.setCompoundDrawables(d, null, null, null);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class FloatingActionButton extends View {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = FloatingActionButton.class.getSimpleName();
|
||||
|
||||
private final Paint mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private final Paint mDrawablePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private Bitmap mBitmap;
|
||||
private int mColor;
|
||||
private final int mDrawableSide;
|
||||
private final float mShadowRadius;
|
||||
private final float mShadowDx;
|
||||
private final float mShadowDy;
|
||||
|
||||
private int mCircleX;
|
||||
private int mCircleY;
|
||||
private int mCircleRadius;
|
||||
private final Rect mSrc = new Rect();
|
||||
private final RectF mDst = new RectF();
|
||||
|
||||
|
||||
public FloatingActionButton(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public FloatingActionButton(Context context, AttributeSet attributeSet) {
|
||||
this(context, attributeSet, 0);
|
||||
}
|
||||
|
||||
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton);
|
||||
mDrawableSide = a.getDimensionPixelSize(R.styleable.FloatingActionButton_fabDrawableSide, 72);
|
||||
mColor = a.getColor(R.styleable.FloatingActionButton_fabColor, Color.WHITE);
|
||||
mButtonPaint.setStyle(Paint.Style.FILL);
|
||||
mButtonPaint.setColor(mColor);
|
||||
mShadowRadius = a.getDimension(R.styleable.FloatingActionButton_fabShadowRadius, 10.0f);
|
||||
mShadowDx = a.getDimension(R.styleable.FloatingActionButton_fabShadowDx, 0.0f);
|
||||
mShadowDy = a.getDimension(R.styleable.FloatingActionButton_fabShadowDy, 3.0f);
|
||||
int shadowColor = a.getColor(R.styleable.FloatingActionButton_fabShadowColor, 0x8a000000);
|
||||
mButtonPaint.setShadowLayer(mShadowRadius, mShadowDx, mShadowDy, shadowColor);
|
||||
Drawable drawable = a.getDrawable(R.styleable.FloatingActionButton_fabDrawable);
|
||||
if (drawable != null && drawable instanceof BitmapDrawable)
|
||||
mBitmap = ((BitmapDrawable) drawable).getBitmap();
|
||||
a.recycle();
|
||||
|
||||
setWillNotDraw(false);
|
||||
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
mColor = color;
|
||||
mButtonPaint.setColor(mColor);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setDrawable(Drawable drawable) {
|
||||
mBitmap = ((BitmapDrawable) drawable).getBitmap();
|
||||
updateValue();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public static int getDefaultSize(int size, int measureSpec) {
|
||||
int result = size;
|
||||
int specMode = MeasureSpec.getMode(measureSpec);
|
||||
int specSize = MeasureSpec.getSize(measureSpec);
|
||||
|
||||
switch (specMode) {
|
||||
case MeasureSpec.UNSPECIFIED:
|
||||
case MeasureSpec.AT_MOST:
|
||||
result = size;
|
||||
break;
|
||||
case MeasureSpec.EXACTLY:
|
||||
result = specSize;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
float half = Math.min(getWidth(), getHeight()) / 2;
|
||||
mCircleX = (int) (half - mShadowDx);
|
||||
mCircleY = (int) (half - mShadowDy);
|
||||
mCircleRadius = (int) (half - mShadowRadius);
|
||||
float halfDrawableSide = mDrawableSide / 2.0f;
|
||||
if (mBitmap != null) {
|
||||
mSrc.set(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
|
||||
mDst.set(mCircleX - halfDrawableSide, mCircleY - halfDrawableSide, mCircleX + halfDrawableSide, mCircleY + halfDrawableSide);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
|
||||
getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
updateValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
canvas.drawCircle(mCircleX, mCircleY, mCircleRadius, mButtonPaint);
|
||||
if (null != mBitmap)
|
||||
canvas.drawBitmap(mBitmap, mSrc, mDst, mDrawablePaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
int color;
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
color = mColor;
|
||||
} else {
|
||||
color = darkenColor(mColor);
|
||||
}
|
||||
mButtonPaint.setColor(color);
|
||||
invalidate();
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public static int darkenColor(int color) {
|
||||
float[] hsv = new float[3];
|
||||
Color.colorToHSV(color, hsv);
|
||||
hsv[2] *= 0.8f;
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
}
|
||||
@@ -1,795 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.AppHandler;
|
||||
import com.hippo.ehviewer.ImageLoader;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.cache.ImageCache;
|
||||
import com.hippo.ehviewer.cardview.CardViewSalon;
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.ehclient.ListParser;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
import com.hippo.ehviewer.widget.recyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.widget.recyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.widget.recyclerview.EasyRecyclerView.FooterAdapter;
|
||||
|
||||
public class GalleryListView extends FrameLayout implements RefreshLayout.OnFooterRefreshListener,
|
||||
RefreshLayout.OnRefreshListener {
|
||||
|
||||
private static final String TAG = GalleryListView.class.getSimpleName();
|
||||
|
||||
public static final int LIST_MODE_DETAIL = 0;
|
||||
public static final int LIST_MODE_THUMB = 1;
|
||||
|
||||
private static final int MODE_REFRESH = 0;
|
||||
private static final int MODE_NEXT_PAGE = 1;
|
||||
private static final int MODE_PRE_PAGE = 2;
|
||||
private static final int MODE_SOMEWHERE = 3;
|
||||
|
||||
private Context mContext;
|
||||
private GalleryListViewHelper mHelper;
|
||||
|
||||
private List<GalleryInfo> mGiList;
|
||||
|
||||
private RefreshLayout mRefreshLayout;
|
||||
private EasyRecyclerView mEasyRecyclerView;
|
||||
private RefreshTextView mRefreshTextView;
|
||||
|
||||
private int mListMode = LIST_MODE_DETAIL;
|
||||
|
||||
private GalleryAdapter mAdapter;
|
||||
private StaggeredGridLayoutManager mLayoutManager;
|
||||
private MarginItemDecoration mItemDecoration;
|
||||
private final int[] mFirstPositionTemp = new int[50]; // TODO
|
||||
|
||||
private long mTaskStamp;
|
||||
|
||||
/**
|
||||
* First index of current page
|
||||
*/
|
||||
private int mFirstIndex;
|
||||
/**
|
||||
* Last index of current page
|
||||
*/
|
||||
private int mLastIndex;
|
||||
private int mCurPage;
|
||||
private int mFirstPage = 0;
|
||||
private int mLastPage = 0;
|
||||
/**
|
||||
* The number of page in sum
|
||||
*/
|
||||
private int mPageNum;
|
||||
private int mItemPerPage;
|
||||
private int mGetMode;
|
||||
|
||||
private OnGetListListener mListener;
|
||||
|
||||
/**
|
||||
* If true, list will make showed item not changed after get
|
||||
*/
|
||||
private boolean mIsKeepPosition;
|
||||
|
||||
private int mTargetPage;
|
||||
private String mTargetUrl;
|
||||
private boolean isFootRefresh = false;
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
private int mListDetailThumbWidth;
|
||||
private int mListDetailThumbHeight;
|
||||
|
||||
public GalleryListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0, 0);
|
||||
}
|
||||
|
||||
public GalleryListView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public GalleryListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
mContext = context;
|
||||
mGiList = new ArrayList<GalleryInfo>();
|
||||
mListener = new OnGetGalleryListListener();
|
||||
|
||||
LayoutInflater.from(mContext).inflate(R.layout.gallery_list_view, this);
|
||||
|
||||
mRefreshLayout = (RefreshLayout) findViewById(R.id.refresh_layout);
|
||||
mEasyRecyclerView = mRefreshLayout.getEasyRecyclerView();
|
||||
mRefreshTextView = (RefreshTextView) findViewById(R.id.refresh_text);
|
||||
|
||||
mAdapter = new GalleryAdapter(mContext, mGiList);
|
||||
mLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
|
||||
mItemDecoration = new MarginItemDecoration();
|
||||
mEasyRecyclerView.setOnScrollListener(new OnScrollListener());
|
||||
mEasyRecyclerView.setClipToPadding(false);
|
||||
mEasyRecyclerView.setAdapter(mAdapter);
|
||||
mEasyRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mEasyRecyclerView.addItemDecoration(mItemDecoration);
|
||||
mEasyRecyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
mEasyRecyclerView.setHasFixedSize(true);
|
||||
setItemMargin(Ui.dp2pix(8)); // TODO for tablet margin should be greater
|
||||
|
||||
mRefreshTextView.setDefaultRefresh(R.string.click_retry, new RefreshTextView.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
retry();
|
||||
}
|
||||
});
|
||||
|
||||
mRefreshLayout.setColorSchemeResources(
|
||||
R.color.refresh_color_1,
|
||||
R.color.refresh_color_2,
|
||||
R.color.refresh_color_3,
|
||||
R.color.refresh_color_4);
|
||||
mRefreshLayout.setOnHeaderRefreshListener(this);
|
||||
mRefreshLayout.setOnFooterRefreshListener(this);
|
||||
mRefreshLayout.setFooterString(
|
||||
mContext.getString(R.string.footer_loading),
|
||||
mContext.getString(R.string.footer_loaded),
|
||||
mContext.getString(R.string.footer_fail));
|
||||
mRefreshLayout.addFooterView();
|
||||
|
||||
// Caculate gallery detail height
|
||||
mInflater = LayoutInflater.from(mContext);
|
||||
View v = mInflater.inflate(R.layout.test_gallery_list_detail_thumb, null);
|
||||
((TextView) v.findViewById(R.id.title)).setText("haha\nhaha");
|
||||
((TextView) v.findViewById(R.id.uploader)).setText("haha");
|
||||
((RatingView) v.findViewById(R.id.rate)).setRating(2.3f);
|
||||
((TextView) v.findViewById(R.id.category)).setText("haha");
|
||||
ViewUtils.measureView(v, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mListDetailThumbHeight = Math.max(v.getMeasuredHeight(), Ui.dp2pix(120));
|
||||
mListDetailThumbWidth = mListDetailThumbHeight * 2 / 3;
|
||||
}
|
||||
|
||||
public int getListMode() {
|
||||
return mListMode;
|
||||
}
|
||||
|
||||
public void setListMode(int listMode) {
|
||||
if (mListMode != listMode) {
|
||||
mListMode = listMode;
|
||||
// Update span
|
||||
updateSpanCount();
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLandscape() {
|
||||
return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
private static final String[] KEY_SPAN_COUNT_ARRAY = {
|
||||
"list_detail_columns_portrait", "list_detail_columns_landscape",
|
||||
"list_thumb_columns_portrait", "list_thumb_columns_landscape"
|
||||
};
|
||||
|
||||
private static final int[] DEFAULT_SPAN_COUNT_ARRAY = {
|
||||
1, 2, 3, 5
|
||||
};
|
||||
|
||||
public void updateSpanCount() {
|
||||
int index = mListMode * 2 + (isLandscape() ? 1 : 0);
|
||||
try {
|
||||
mLayoutManager.setSpanCount(Config.getInt(KEY_SPAN_COUNT_ARRAY[index],
|
||||
DEFAULT_SPAN_COUNT_ARRAY[index]));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setGalleryListViewHelper(GalleryListViewHelper h) {
|
||||
mHelper = h;
|
||||
}
|
||||
|
||||
public void setPaddingTopAndBottom(int top, int bottom) {
|
||||
setPadding(getPaddingLeft(), top, getPaddingRight(), getPaddingBottom());
|
||||
mEasyRecyclerView.setPadding(mEasyRecyclerView.getPaddingLeft(), mEasyRecyclerView.getPaddingTop(),
|
||||
mEasyRecyclerView.getPaddingRight(), mEasyRecyclerView.getPaddingBottom() + bottom);
|
||||
}
|
||||
|
||||
private void setItemMargin(int margin) {
|
||||
int halfMargin = margin / 2;
|
||||
mItemDecoration.setMargin(margin);
|
||||
mEasyRecyclerView.setPadding(halfMargin, halfMargin,
|
||||
halfMargin, halfMargin);
|
||||
}
|
||||
|
||||
public void setEnabledHeader(boolean enabled) {
|
||||
mRefreshLayout.setEnabledHeader(enabled);
|
||||
}
|
||||
|
||||
public void setEnabledFooter(boolean enabled) {
|
||||
mRefreshLayout.setEnabledFooter(enabled);
|
||||
}
|
||||
|
||||
public void setHeaderRefreshing(boolean refreshing) {
|
||||
mRefreshLayout.setRefreshing(refreshing);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(EasyRecyclerView.OnItemClickListener l) {
|
||||
mEasyRecyclerView.setOnItemClickListener(l);
|
||||
}
|
||||
|
||||
public void setOnItemLongClickListener(EasyRecyclerView.OnItemLongClickListener l) {
|
||||
mEasyRecyclerView.setOnItemLongClickListener(l);
|
||||
}
|
||||
|
||||
public void setChoiceMode(int choiceMode) {
|
||||
mEasyRecyclerView.setChoiceMode(choiceMode);
|
||||
}
|
||||
|
||||
public void setMultiChoiceModeListener(EasyRecyclerView.MultiChoiceModeListener listener) {
|
||||
mEasyRecyclerView.setMultiChoiceModeListener(listener);
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
public void setNoneText(CharSequence text) {
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setEmesg(text, false);
|
||||
}
|
||||
|
||||
public void onlyShowList() {
|
||||
mRefreshLayout.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setRefreshing(false);
|
||||
mRefreshTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void onlyShowNone() {
|
||||
mRefreshLayout.setVisibility(View.GONE);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setEmesg(R.string.none, false);
|
||||
}
|
||||
|
||||
private void getGallerys() {
|
||||
setGallerysLayout();
|
||||
|
||||
mTaskStamp = System.currentTimeMillis();
|
||||
mHelper.doGetGallerys(mTargetUrl, mTaskStamp, mListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
// It is invokened by user pull, so no need to
|
||||
if (mFirstPage > 0) {
|
||||
getPrePage(true);
|
||||
} else {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onFooterRefresh() {
|
||||
if (!isRefreshing() && mLastPage < mPageNum - 1) {
|
||||
isFootRefresh = true;
|
||||
getNextPage(true);
|
||||
isFootRefresh = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void firstTimeRefresh() {
|
||||
// set mPullViewGroup gone, make wait view show
|
||||
mRefreshLayout.setVisibility(View.GONE);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setRefreshing(true);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void setGallerysLayout() {
|
||||
if (mRefreshLayout.getVisibility() == View.VISIBLE) {
|
||||
if (!isFootRefresh)
|
||||
mRefreshLayout.setRefreshing(true);
|
||||
mRefreshTextView.setVisibility(View.GONE);
|
||||
} else {
|
||||
mRefreshLayout.setVisibility(View.GONE);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setRefreshing(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean retry() {
|
||||
// Need to update url, because mode may be changed
|
||||
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
|
||||
getGallerys();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Go to page 0.<br>
|
||||
* You should know you can refresh or not.
|
||||
*/
|
||||
public void refresh() {
|
||||
mGetMode = MODE_REFRESH;
|
||||
mTargetPage = 0;
|
||||
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
|
||||
mIsKeepPosition = false;
|
||||
getGallerys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get previous page.<br>
|
||||
* You should know you can get previous page or not
|
||||
*
|
||||
* @param isKeepPosition
|
||||
*/
|
||||
protected void getPrePage(boolean isKeepPosition) {
|
||||
mGetMode = MODE_PRE_PAGE;
|
||||
mTargetPage = mFirstPage - 1;
|
||||
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
|
||||
mIsKeepPosition = isKeepPosition;
|
||||
getGallerys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next page.<br>
|
||||
* You should know you can get next page or not
|
||||
*
|
||||
* @param isKeepPosition
|
||||
*/
|
||||
protected void getNextPage(boolean isKeepPosition) {
|
||||
mGetMode = MODE_NEXT_PAGE;
|
||||
mTargetPage = mLastPage + 1;
|
||||
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
|
||||
mIsKeepPosition = isKeepPosition;
|
||||
getGallerys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get some page.<br>
|
||||
* You should know you can get that page or not
|
||||
*
|
||||
* @param page
|
||||
*/
|
||||
protected void getSomewhere(int page) {
|
||||
mGetMode = MODE_SOMEWHERE;
|
||||
mTargetPage = page;
|
||||
mTargetUrl = mHelper.getTargetUrl(mTargetPage);
|
||||
mIsKeepPosition = false;
|
||||
getGallerys();
|
||||
}
|
||||
|
||||
public void jumpTo(int page) {
|
||||
if (page >= mFirstPage && page <= mLastPage) {
|
||||
int position = (page - mFirstPage) * mItemPerPage;
|
||||
mLayoutManager.scrollToPosition(position);
|
||||
} else if (page == mFirstPage - 1) {
|
||||
getPrePage(false);
|
||||
} else if (page == mLastPage + 1) {
|
||||
getNextPage(false);
|
||||
} else {
|
||||
getSomewhere(page);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if actionbar or footer is refreshing
|
||||
*/
|
||||
public boolean isRefreshing() {
|
||||
return mRefreshLayout.isRefreshing();
|
||||
}
|
||||
|
||||
public boolean isGetGalleryOk() {
|
||||
return mRefreshLayout.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
public int getPageNum() {
|
||||
return mPageNum;
|
||||
}
|
||||
|
||||
public int getCurPage() {
|
||||
return mCurPage;
|
||||
}
|
||||
|
||||
public List<GalleryInfo> getGalleryList() {
|
||||
return mGiList;
|
||||
}
|
||||
|
||||
public GalleryInfo getGalleryInfo(int position) {
|
||||
return mGiList.get(position);
|
||||
}
|
||||
|
||||
public static interface OnGetListListener {
|
||||
public void onSuccess(long taskStamp, List<GalleryInfo> gis, int maxPage);
|
||||
public void onFailure(long taskStamp, String eMsg);
|
||||
}
|
||||
|
||||
private class OnGetGalleryListListener implements OnGetListListener, Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int preIndex = mLayoutManager.findFirstVisibleItemPositions(mFirstPositionTemp)[0] - 1;
|
||||
if (preIndex >= 0)
|
||||
mEasyRecyclerView.smoothScrollToPosition(preIndex);
|
||||
}
|
||||
|
||||
public void smoothScrollToPrePosition() {
|
||||
AppHandler.getInstance().post(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(long taskStamp, List<GalleryInfo> gis, int pageNum) {
|
||||
if (mTaskStamp != taskStamp)
|
||||
return;
|
||||
|
||||
if (pageNum == ListParser.TARGET_PAGE_IS_LAST)
|
||||
mPageNum = mTargetPage + 1;
|
||||
else
|
||||
mPageNum = pageNum;
|
||||
|
||||
int itemPerPage = gis == null ? 0 : gis.size();
|
||||
if (mItemPerPage < itemPerPage)
|
||||
mItemPerPage = itemPerPage;
|
||||
|
||||
if (mPageNum == 0) { // Get none
|
||||
onlyShowNone();
|
||||
|
||||
mFirstPage = 0;
|
||||
mLastPage = 0;
|
||||
mGiList.clear();
|
||||
mAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
onlyShowList();
|
||||
|
||||
int start;
|
||||
switch (mGetMode) {
|
||||
case MODE_REFRESH:
|
||||
mFirstPage = 0;
|
||||
mLastPage = 0;
|
||||
mGiList.clear();
|
||||
mGiList.addAll(gis);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
// For current page
|
||||
mFirstIndex = 0;
|
||||
mLastIndex = gis.size() - 1;
|
||||
mCurPage = 0;
|
||||
|
||||
mLayoutManager.scrollToPosition(0);
|
||||
break;
|
||||
|
||||
case MODE_PRE_PAGE:
|
||||
mFirstPage--;
|
||||
mGiList.addAll(0, gis);
|
||||
mAdapter.notifyItemRangeInserted(0, gis.size());
|
||||
|
||||
if (mIsKeepPosition) {
|
||||
mFirstIndex += gis.size();
|
||||
mLastIndex += gis.size();
|
||||
smoothScrollToPrePosition();
|
||||
} else {
|
||||
mFirstIndex = 0;
|
||||
mLastIndex = gis.size()-1;
|
||||
mCurPage = mTargetPage;
|
||||
mLayoutManager.scrollToPosition(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_NEXT_PAGE:
|
||||
mLastPage++;
|
||||
start = mGiList.size();
|
||||
mGiList.addAll(gis);
|
||||
mAdapter.notifyItemRangeInserted(start, gis.size());
|
||||
|
||||
if (!mIsKeepPosition) {
|
||||
mFirstIndex = mGiList.size() - gis.size();
|
||||
mLastIndex = mGiList.size() - 1;
|
||||
mCurPage = mTargetPage;
|
||||
mLayoutManager.scrollToPosition(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_SOMEWHERE:
|
||||
mFirstPage = mTargetPage;
|
||||
mLastPage = mTargetPage;
|
||||
mGiList.clear();
|
||||
mGiList.addAll(gis);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
// For current page
|
||||
mFirstIndex = 0;
|
||||
mLastIndex = gis.size() - 1;
|
||||
mCurPage = mTargetPage;
|
||||
|
||||
mLayoutManager.scrollToPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
mRefreshLayout.setAnyRefreshComplete(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(long taskStamp, String eMsg) {
|
||||
if (mTaskStamp != taskStamp)
|
||||
return;
|
||||
|
||||
switch (mGetMode) {
|
||||
case MODE_REFRESH:
|
||||
case MODE_SOMEWHERE:
|
||||
mRefreshLayout.setVisibility(View.GONE);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
if (eMsg.equals(mContext.getString(R.string.em_index_error))) {
|
||||
mRefreshTextView.setEmesg(eMsg, mContext.getString(R.string.click_first_page),
|
||||
new RefreshTextView.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mRefreshTextView.setRefreshing(true);
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mRefreshTextView.setEmesg(eMsg, true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
mRefreshTextView.setRefreshing(false);
|
||||
mRefreshTextView.setVisibility(View.GONE);
|
||||
MaterialToast.showToast(eMsg);
|
||||
}
|
||||
mRefreshLayout.setAnyRefreshComplete(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static interface GalleryListViewHelper {
|
||||
/**
|
||||
* Get url string for very page
|
||||
*
|
||||
* @param targetPage
|
||||
* @return
|
||||
*/
|
||||
public String getTargetUrl(int targetPage);
|
||||
|
||||
/**
|
||||
* Do get gallarys here, you shuold invoke the onSuccess or onFailure of
|
||||
* listener when over
|
||||
*
|
||||
* @param url
|
||||
* @param taskStamp
|
||||
* @param listener
|
||||
*/
|
||||
public void doGetGallerys(String url, long taskStamp, OnGetListListener listener);
|
||||
}
|
||||
|
||||
public class OnScrollListener extends RecyclerView.OnScrollListener {
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
switch (newState) {
|
||||
case RecyclerView.SCROLL_STATE_DRAGGING:
|
||||
ImageCache.getInstance(mContext).setPauseDiskCache(true);
|
||||
break;
|
||||
case RecyclerView.SCROLL_STATE_IDLE:
|
||||
ImageCache.getInstance(mContext).setPauseDiskCache(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
mRefreshLayout.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int itemCount = mLayoutManager.getChildCount();
|
||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPositions(mFirstPositionTemp)[0];
|
||||
|
||||
// itemCount might include some view can't be seen
|
||||
// Just check top line child and bottom line child
|
||||
int visibleItemCount = itemCount;
|
||||
int height = mEasyRecyclerView.getHeight();
|
||||
int span = mLayoutManager.getSpanCount();
|
||||
// Top line
|
||||
int start = 0;
|
||||
int end = Math.min(span, itemCount);
|
||||
for (int i = start; i < end; i++) {
|
||||
View view = mLayoutManager.getChildAt(i);
|
||||
if (view.getBottom() <= 0 || view.getTop() > height)
|
||||
visibleItemCount--;
|
||||
}
|
||||
// Bottom line
|
||||
start = Math.max(itemCount - 1 - span, 0);
|
||||
end = itemCount;
|
||||
for (int i = start; i < end; i++) {
|
||||
View view = mLayoutManager.getChildAt(i);
|
||||
if (view.getBottom() <= 0 || view.getTop() > height)
|
||||
visibleItemCount--;
|
||||
}
|
||||
|
||||
if (mItemPerPage == 0)
|
||||
return;
|
||||
if (mLastIndex == 0)
|
||||
mLastIndex = mItemPerPage - 1;
|
||||
int pageChanged = (firstVisibleItem - mFirstIndex) / mItemPerPage;
|
||||
if (pageChanged == 0)
|
||||
pageChanged = (firstVisibleItem + visibleItemCount - mLastIndex - 1) / mItemPerPage;
|
||||
|
||||
if (pageChanged != 0) {
|
||||
mCurPage = mCurPage + pageChanged;
|
||||
mFirstIndex += pageChanged * mItemPerPage;
|
||||
mLastIndex += pageChanged * mItemPerPage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class GalleryViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public int viewType;
|
||||
public LoadImageView thumb;
|
||||
public TextView title;
|
||||
public TextView uploader;
|
||||
public TextView category;
|
||||
public RatingView rate;
|
||||
public TextView posted;
|
||||
public TextView simpleLanguage;
|
||||
|
||||
public GalleryViewHolder(View itemView, int viewType) {
|
||||
super(itemView);
|
||||
|
||||
this.viewType = viewType;
|
||||
switch (viewType) {
|
||||
case LIST_MODE_DETAIL:
|
||||
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
category = (TextView) itemView.findViewById(R.id.category);
|
||||
uploader = (TextView) itemView.findViewById(R.id.uploader);
|
||||
rate = (RatingView) itemView.findViewById(R.id.rate);
|
||||
posted = (TextView) itemView.findViewById(R.id.posted);
|
||||
simpleLanguage = (TextView) itemView.findViewById(R.id.simple_language);
|
||||
|
||||
ViewGroup.LayoutParams lp = thumb.getLayoutParams();
|
||||
lp.width = mListDetailThumbWidth;
|
||||
lp.height = mListDetailThumbHeight;
|
||||
break;
|
||||
case LIST_MODE_THUMB:
|
||||
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
|
||||
category = (TextView) itemView.findViewById(R.id.category);
|
||||
simpleLanguage = (TextView) itemView.findViewById(R.id.simple_language);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GalleryAdapter extends EasyRecyclerView.FooterAdapter<GalleryViewHolder> {
|
||||
|
||||
private final Context mContext;
|
||||
private final List<GalleryInfo> mGiList;
|
||||
private final ImageLoader mImageLoader;
|
||||
|
||||
|
||||
public GalleryAdapter(Context context, List<GalleryInfo> gilist) {
|
||||
mContext = context;
|
||||
mGiList = gilist;
|
||||
mImageLoader = ImageLoader.getInstance(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryViewHolder onCreateAndBindFooterViewHolder(
|
||||
ViewGroup parent, View footerView) {
|
||||
return new GalleryViewHolder(footerView, FooterAdapter.TYPE_FOOTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryViewHolder onCreateViewHolderActual(ViewGroup parent,
|
||||
int viewType) {
|
||||
int resId;
|
||||
if (viewType == LIST_MODE_DETAIL)
|
||||
resId = R.layout.gallery_list_detail_item;
|
||||
else
|
||||
resId = R.layout.gallery_list_thumb_item;
|
||||
View view = mInflater.inflate(resId, parent, false);
|
||||
CardViewSalon.reformWithShadow(view, new int[][]{
|
||||
new int[]{android.R.attr.state_pressed},
|
||||
new int[]{android.R.attr.state_activated},
|
||||
new int[]{}},
|
||||
new int[]{0xff84cae4, 0xff33b5e5, 0xFFFAFAFA}, null, false);
|
||||
return new GalleryViewHolder(view, viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolderActual(GalleryViewHolder holder,
|
||||
int position) {
|
||||
GalleryInfo gi = mGiList.get(position);
|
||||
final LoadImageView thumb = holder.thumb;
|
||||
if (!String.valueOf(gi.gid).equals(thumb.getKey())) {
|
||||
// Set new thumb
|
||||
thumb.setImageDrawable(null);
|
||||
thumb.setLoadInfo(gi.thumb, String.valueOf(gi.gid));
|
||||
mImageLoader.add(gi.thumb, String.valueOf(gi.gid),
|
||||
new LoadImageView.SimpleImageGetListener(thumb).setFixScaleType(true));
|
||||
}
|
||||
// Set simple language
|
||||
TextView simpleLanguage = holder.simpleLanguage;
|
||||
if (gi.simpleLanguage == null) {
|
||||
simpleLanguage.setVisibility(View.GONE);
|
||||
} else {
|
||||
simpleLanguage.setVisibility(View.VISIBLE);
|
||||
simpleLanguage.setText(gi.simpleLanguage);
|
||||
}
|
||||
|
||||
// For detail mode
|
||||
if (holder.viewType == LIST_MODE_DETAIL) {
|
||||
// Set category
|
||||
TextView category = holder.category;
|
||||
String newText = Ui.getCategoryText(gi.category);
|
||||
if (!newText.equals(category.getText())) {
|
||||
category.setText(newText);
|
||||
category.setBackgroundColor(Ui.getCategoryColor(gi.category));
|
||||
}
|
||||
// Set manga title
|
||||
TextView title = holder.title;
|
||||
title.setText(gi.title);
|
||||
// Set uploder
|
||||
TextView uploader = holder.uploader;
|
||||
uploader.setText(gi.uploader);
|
||||
// Set star
|
||||
RatingView rate = holder.rate;
|
||||
rate.setRating(gi.rating);
|
||||
// set posted
|
||||
TextView posted = holder.posted;
|
||||
posted.setText(gi.posted);
|
||||
} else {
|
||||
// Set category
|
||||
TextView category = holder.category;
|
||||
String newText = Ui.getCategoryText(gi.category);
|
||||
if (!newText.equals(category.getText())) {
|
||||
category.setText(newText);
|
||||
category.setBackgroundColor(Ui.getCategoryColor(gi.category)
|
||||
& 0x00ffffff | 0xca000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewTypeActual(int position) {
|
||||
return mListMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCountActual() {
|
||||
return mGiList.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.TouchDelegate;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
public class HotspotTouchHelper implements View.OnTouchListener {
|
||||
|
||||
private final Hotspotable mOwner;
|
||||
|
||||
private boolean mPrePressed = false;
|
||||
private boolean mHasPerformedLongPress = false;
|
||||
|
||||
private CheckForLongPress mPendingCheckForLongPress = null;
|
||||
private CheckForTap mPendingCheckForTap = null;
|
||||
private PerformClick mPerformClick = null;
|
||||
private UnsetPressedState mUnsetPressedState = null;
|
||||
|
||||
/**
|
||||
* Cache the touch slop from the context that created the view.
|
||||
*/
|
||||
private int mTouchSlop = -1;
|
||||
|
||||
public HotspotTouchHelper(Hotspotable owner){
|
||||
mOwner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
final float x = event.getX();
|
||||
final float y = event.getY();
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN ||
|
||||
event.getAction() == MotionEvent.ACTION_MOVE)
|
||||
mOwner.setHotspot(x, y);
|
||||
|
||||
if (!v.isEnabled()) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP && v.isPressed()) {
|
||||
v.setPressed(false);
|
||||
}
|
||||
// A disabled view that is clickable still consumes the touch
|
||||
// events, it just doesn't respond to them.
|
||||
return (v.isClickable() || v.isLongClickable());
|
||||
}
|
||||
|
||||
TouchDelegate touchDelegate = v.getTouchDelegate();
|
||||
if (touchDelegate != null) {
|
||||
if (touchDelegate.onTouchEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (v.isClickable() || v.isLongClickable()) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (v.isPressed() || mPrePressed) {
|
||||
// take focus if we don't have it already and we should in
|
||||
// touch mode.
|
||||
boolean focusTaken = false;
|
||||
if (v.isFocusable() && v.isFocusableInTouchMode() && !v.isFocused()) {
|
||||
focusTaken = v.requestFocus();
|
||||
}
|
||||
|
||||
if (mPrePressed) {
|
||||
// The button is being released before we actually
|
||||
// showed it as pressed. Make it show the pressed
|
||||
// state now (before scheduling the click) to ensure
|
||||
// the user sees it.
|
||||
setPressed(v, true, x, y);
|
||||
}
|
||||
|
||||
if (!mHasPerformedLongPress) {
|
||||
// This is a tap, so remove the longpress check
|
||||
removeLongPressCallback(v);
|
||||
|
||||
// Only perform take click actions if we were in the pressed state
|
||||
if (!focusTaken) {
|
||||
// Use a Runnable and post this rather than calling
|
||||
// performClick directly. This lets other visual state
|
||||
// of the view update before click actions start.
|
||||
if (mPerformClick == null) {
|
||||
mPerformClick = new PerformClick(v);
|
||||
}
|
||||
if (!v.post(mPerformClick)) {
|
||||
v.performClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mUnsetPressedState == null) {
|
||||
mUnsetPressedState = new UnsetPressedState(v);
|
||||
}
|
||||
|
||||
if (mPrePressed) {
|
||||
v.postDelayed(mUnsetPressedState,
|
||||
ViewConfiguration.getPressedStateDuration());
|
||||
} else if (!v.post(mUnsetPressedState)) {
|
||||
// If the post failed, unpress right now
|
||||
mUnsetPressedState.run();
|
||||
}
|
||||
|
||||
removeTapCallback(v);
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mHasPerformedLongPress = false;
|
||||
|
||||
if (performButtonActionOnTouchDown(v, event)) {
|
||||
break;
|
||||
}
|
||||
|
||||
mPrePressed = true;
|
||||
if (mPendingCheckForTap == null) {
|
||||
mPendingCheckForTap = new CheckForTap(v);
|
||||
}
|
||||
mPendingCheckForTap.x = event.getX();
|
||||
mPendingCheckForTap.y = event.getY();
|
||||
v.postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
v.setPressed(false);
|
||||
removeTapCallback(v);
|
||||
removeLongPressCallback(v);
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
mOwner.setHotspot(x, y);
|
||||
|
||||
if (mTouchSlop == -1)
|
||||
mTouchSlop = ViewConfiguration.get(v.getContext()).getScaledTouchSlop();
|
||||
|
||||
// Be lenient about moving outside of buttons
|
||||
if (!pointInView(v, x, y, mTouchSlop)) {
|
||||
// Outside button
|
||||
removeTapCallback(v);
|
||||
if (v.isPressed()) {
|
||||
// Remove any future long press/tap checks
|
||||
removeLongPressCallback(v);
|
||||
|
||||
v.setPressed(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void setPressed(View v, boolean pressed, float x, float y){
|
||||
v.setPressed(pressed);
|
||||
mOwner.setHotspot(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to determine whether the given point, in local coordinates,
|
||||
* is inside the view, where the area of the view is expanded by the slop factor.
|
||||
* This method is called while processing touch-move events to determine if the event
|
||||
* is still within the view.
|
||||
*/
|
||||
public boolean pointInView(View v, float localX, float localY, float slop) {
|
||||
return localX >= -slop && localY >= -slop && localX < ((v.getRight() - v.getLeft()) + slop) &&
|
||||
localY < ((v.getBottom() - v.getTop()) + slop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs button-related actions during a touch down event.
|
||||
*
|
||||
* @param event The event.
|
||||
* @return True if the down was consumed.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
protected boolean performButtonActionOnTouchDown(View v, MotionEvent event) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
|
||||
if (v.showContextMenu()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the longpress detection timer.
|
||||
*/
|
||||
private void removeLongPressCallback(View v) {
|
||||
if (mPendingCheckForLongPress != null) {
|
||||
v.removeCallbacks(mPendingCheckForLongPress);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the tap detection timer.
|
||||
*/
|
||||
private void removeTapCallback(View v) {
|
||||
if (mPendingCheckForTap != null) {
|
||||
mPrePressed = false;
|
||||
v.removeCallbacks(mPendingCheckForTap);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForLongClick(View v, int delayOffset) {
|
||||
if (v.isLongClickable()) {
|
||||
mHasPerformedLongPress = false;
|
||||
|
||||
if (mPendingCheckForLongPress == null) {
|
||||
mPendingCheckForLongPress = new CheckForLongPress(v);
|
||||
}
|
||||
v.postDelayed(mPendingCheckForLongPress,
|
||||
ViewConfiguration.getLongPressTimeout() - delayOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private final class CheckForLongPress implements Runnable {
|
||||
|
||||
private final View mView;
|
||||
|
||||
public CheckForLongPress(View v) {
|
||||
mView = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (mView.isPressed() && (mView.getParent() != null)) {
|
||||
if (mView.performLongClick()) {
|
||||
mHasPerformedLongPress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class CheckForTap implements Runnable {
|
||||
public float x;
|
||||
public float y;
|
||||
private final View mView;
|
||||
|
||||
public CheckForTap(View v) {
|
||||
mView = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mPrePressed = false;
|
||||
setPressed(mView, true, x, y);
|
||||
checkForLongClick(mView, ViewConfiguration.getTapTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
private final class PerformClick implements Runnable {
|
||||
private final View mView;
|
||||
|
||||
public PerformClick(View v) {
|
||||
mView = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mView.performClick();
|
||||
}
|
||||
}
|
||||
|
||||
private final class UnsetPressedState implements Runnable {
|
||||
private final View mView;
|
||||
|
||||
public UnsetPressedState(View v) {
|
||||
mView = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mView.setPressed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
public interface Hotspotable {
|
||||
|
||||
public void setHotspot(float x, float y);
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
|
||||
public class RatingView extends TextView {
|
||||
|
||||
private static final char START_EMPTY = '\uFA73';
|
||||
private static final char START_HALF = '\uFA74';
|
||||
private static final char START_FULL = '\uFA75';
|
||||
|
||||
private int mRating = -1;
|
||||
|
||||
public RatingView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
public RatingView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
public RatingView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
setTypeface(((AppContext)context.getApplicationContext()).getFaceTypeface());
|
||||
}
|
||||
|
||||
public void setRating(float rating) {
|
||||
mRating = Math.min(10, Math.round(rating * 2));
|
||||
int fullNum = mRating / 2;
|
||||
int halfNum = mRating % 2;
|
||||
int emptyNum = 5 - fullNum - halfNum;
|
||||
StringBuilder sb = new StringBuilder(5);
|
||||
for (int i = 0; i < fullNum; i++)
|
||||
sb.append(START_FULL);
|
||||
if (halfNum == 1)
|
||||
sb.append(START_HALF);
|
||||
for (int i = 0; i < emptyNum; i++)
|
||||
sb.append(START_EMPTY);
|
||||
setText(sb.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class SearchView extends android.widget.SearchView {
|
||||
|
||||
private static final String TAG = SearchView.class.getSimpleName();
|
||||
|
||||
private OnActionViewExpandedListener mListener;
|
||||
|
||||
public SearchView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SearchView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public SearchView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public SearchView(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionViewExpanded() {
|
||||
super.onActionViewExpanded();
|
||||
|
||||
if (mListener != null)
|
||||
mListener.onActionViewExpanded();
|
||||
}
|
||||
|
||||
public void setOnActionViewExpandedListener(OnActionViewExpandedListener l) {
|
||||
mListener = l;
|
||||
}
|
||||
|
||||
public interface OnActionViewExpandedListener {
|
||||
public void onActionViewExpanded();
|
||||
}
|
||||
}
|
||||
@@ -1,598 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.CycleInterpolator;
|
||||
|
||||
import com.hippo.ehviewer.util.AnimatorUtils;
|
||||
import com.hippo.ehviewer.util.MathUtils;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
import com.hippo.ehviewer.util.ZInterpolator;
|
||||
|
||||
public class SlidingLayout extends ViewGroup {
|
||||
|
||||
private static final String TAG = SlidingLayout.class.getSimpleName();
|
||||
|
||||
/*
|
||||
* There are three level, first is base level, second is reserved level, third is full screen level.
|
||||
*/
|
||||
|
||||
private static final int LEVEL_BASE = 0;
|
||||
private static final int LEVEL_RESERVED = 1;
|
||||
private static final int LEVEL_FULL_SCREEN = 2;
|
||||
|
||||
private int mLevel = LEVEL_BASE;
|
||||
|
||||
private View mChild;
|
||||
private int mMaxWidth;
|
||||
private int mSlop;
|
||||
private float mShowPercent = 0.0f;
|
||||
private boolean isBottom = true;
|
||||
|
||||
private int mPaddingLeft;
|
||||
private int mPaddingTop;
|
||||
private int mPaddingRight;
|
||||
private int mPaddingBottom;
|
||||
|
||||
private ValueAnimator mToBaseLevelAnimate;
|
||||
private ValueAnimator mToReservedLevelAnimate;
|
||||
private ValueAnimator mToFullScreenLevelAnimate;
|
||||
private SetYListener mToBaseLevelListener;
|
||||
private SetYListener mToReservedLevelListener;
|
||||
private SetYListener mToFullScreenLevelListener;
|
||||
|
||||
private float mInitialMotionX;
|
||||
private float mInitialMotionY;
|
||||
private float mLastMotionY;
|
||||
|
||||
private int mMinTop;
|
||||
private int mMaxTop;
|
||||
|
||||
/*
|
||||
* ---------------------- mFullScreenTop
|
||||
*
|
||||
* ---------------------- m5Top
|
||||
*
|
||||
*
|
||||
* ---------------------- m4Top
|
||||
*
|
||||
* ---------------------- mReservedTop
|
||||
*
|
||||
* ---------------------- m2Top
|
||||
*
|
||||
*
|
||||
* ---------------------- m1Top
|
||||
*
|
||||
* ---------------------- mBaseTop
|
||||
*/
|
||||
|
||||
private int mBaseTop;
|
||||
private int m1Top;
|
||||
private int m2Top;
|
||||
private int mReservedTop;
|
||||
private int m4Top;
|
||||
private int m5Top;
|
||||
private int mFullScreenTop;
|
||||
|
||||
private boolean mInHideAnimate = false;
|
||||
|
||||
private OnChildHideListener mOnChildHideListener;
|
||||
|
||||
private static final ZInterpolator ZINTERPOLATOR = new ZInterpolator();
|
||||
|
||||
public interface OnChildHideListener {
|
||||
public void onChildHide();
|
||||
}
|
||||
|
||||
|
||||
public SlidingLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public SlidingLayout(Context context, AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public SlidingLayout(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mMaxWidth = Ui.dp2pix(480);
|
||||
mSlop = Ui.dp2pix(0);
|
||||
|
||||
mToBaseLevelAnimate = new ValueAnimator();
|
||||
mToBaseLevelListener = new SetYListener();
|
||||
mToBaseLevelAnimate.addUpdateListener(mToBaseLevelListener);
|
||||
mToBaseLevelAnimate.setDuration(300);
|
||||
mToBaseLevelAnimate.setInterpolator(ZINTERPOLATOR);
|
||||
mToBaseLevelAnimate.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mInHideAnimate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLevel = LEVEL_BASE;
|
||||
if (mChild.getVisibility() != View.INVISIBLE)
|
||||
mChild.setVisibility(View.INVISIBLE);
|
||||
|
||||
if (mOnChildHideListener != null)
|
||||
mOnChildHideListener.onChildHide();
|
||||
|
||||
mInHideAnimate = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
mInHideAnimate = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
});
|
||||
|
||||
mToReservedLevelAnimate = new ValueAnimator();
|
||||
mToReservedLevelListener = new SetYListener();
|
||||
mToReservedLevelAnimate.addUpdateListener(mToReservedLevelListener);
|
||||
mToReservedLevelAnimate.setDuration(300);
|
||||
mToReservedLevelAnimate.setInterpolator(ZINTERPOLATOR);
|
||||
mToReservedLevelAnimate.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLevel = LEVEL_RESERVED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
});
|
||||
|
||||
mToFullScreenLevelAnimate = new ValueAnimator();
|
||||
mToFullScreenLevelListener = new SetYListener();
|
||||
mToFullScreenLevelAnimate.addUpdateListener(mToFullScreenLevelListener);
|
||||
mToFullScreenLevelAnimate.setDuration(300);
|
||||
mToFullScreenLevelAnimate.setInterpolator(ZINTERPOLATOR);
|
||||
mToFullScreenLevelAnimate.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLevel = LEVEL_FULL_SCREEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class SetYListener implements ValueAnimator.AnimatorUpdateListener {
|
||||
|
||||
private boolean mFirstShow = false;
|
||||
private int mStartTop;
|
||||
|
||||
public void reset() {
|
||||
mFirstShow = true;
|
||||
mStartTop = mChild.getTop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
int offsetY = (int) (float) (Float) animation.getAnimatedValue() - mChild.getTop();
|
||||
mChild.offsetTopAndBottom(offsetY);
|
||||
updateShowPercent();
|
||||
|
||||
if (mFirstShow && Math.abs(mStartTop - mChild.getTop()) > 5) {
|
||||
mFirstShow = false;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnChildHideListener(OnChildHideListener l) {
|
||||
mOnChildHideListener = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
final int childCount = getChildCount();
|
||||
if (childCount != 1)
|
||||
throw new IllegalStateException("There must be only one child");
|
||||
|
||||
mChild = getChildAt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY)
|
||||
throw new IllegalArgumentException(
|
||||
"SlidingDrawerLayout must be measured with MeasureSpec.EXACTLY.");
|
||||
|
||||
setMeasuredDimension(widthSize, heightSize);
|
||||
|
||||
final View child = mChild;
|
||||
if (child.getVisibility() != GONE) {
|
||||
final int childWidthSpec = MeasureSpec.makeMeasureSpec(
|
||||
Math.min(widthSize - getPaddingLeft() - getPaddingRight(), mMaxWidth), MeasureSpec.EXACTLY);
|
||||
final int childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||
child.measure(childWidthSpec, childHeightSpec);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
final View child = mChild;
|
||||
final int width = r - l;
|
||||
final int height = b - t;
|
||||
final int childWidth = child.getMeasuredWidth();
|
||||
final int childHeight = child.getMeasuredHeight();
|
||||
mPaddingLeft = getPaddingLeft();
|
||||
mPaddingTop = getPaddingTop();
|
||||
mPaddingRight = getPaddingRight();
|
||||
mPaddingBottom = getPaddingBottom();
|
||||
|
||||
// Set mReservedLength and mFullScreenLength
|
||||
int heightWithoutPadding = height - mPaddingTop - mPaddingBottom;
|
||||
int defaultReservedLength = Math.min(heightWithoutPadding - Ui.dp2pix(48), Ui.dp2pix(248));
|
||||
int defaultFullScreenLength = Math.max(heightWithoutPadding, defaultReservedLength);
|
||||
int reservedLength = Math.min(defaultReservedLength, childHeight);
|
||||
int fullScreenLength = Math.min(defaultFullScreenLength, childHeight);
|
||||
|
||||
int showHeight = MathUtils.lerp(0, childHeight, mShowPercent);
|
||||
|
||||
int childLeft = mPaddingLeft + (width - mPaddingLeft - mPaddingRight - childWidth) / 2;
|
||||
|
||||
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
||||
final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
||||
final int maxGap = Ui.dp2pix(32);
|
||||
final int brGap = Math.min(Math.abs((mBaseTop - mReservedTop) / 3), maxGap);
|
||||
final int rfGap = Math.min(Math.abs((mReservedTop - mFullScreenTop) / 3), maxGap);
|
||||
switch (vgrav) {
|
||||
case Gravity.TOP: {
|
||||
isBottom = false;
|
||||
mMinTop = mPaddingTop;
|
||||
mMaxTop = mMinTop + childHeight;
|
||||
mBaseTop = mMinTop;
|
||||
mReservedTop = mMinTop + reservedLength;
|
||||
mFullScreenTop = mMinTop + fullScreenLength;
|
||||
|
||||
m1Top = mBaseTop + brGap;
|
||||
m2Top = mReservedTop - brGap;
|
||||
m4Top = mReservedTop + rfGap;
|
||||
m5Top = mFullScreenTop - rfGap;
|
||||
|
||||
int childBottom = mMinTop + showHeight;
|
||||
child.layout(childLeft, childBottom - childHeight, childLeft + childWidth, childBottom);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case Gravity.BOTTOM: {
|
||||
isBottom = true;
|
||||
mMaxTop = height - mPaddingBottom;
|
||||
mMinTop = mMaxTop - childHeight;
|
||||
mBaseTop = mMaxTop;
|
||||
mReservedTop = mMaxTop - reservedLength;
|
||||
mFullScreenTop = mMaxTop - fullScreenLength;
|
||||
|
||||
m1Top = mBaseTop - brGap;
|
||||
m2Top = mReservedTop + brGap;
|
||||
m4Top = mReservedTop - rfGap;
|
||||
m5Top = mFullScreenTop + rfGap;
|
||||
|
||||
int childTop = mMaxTop - showHeight;
|
||||
child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
boolean getTouchEvent = false;
|
||||
final int action = MotionEventCompat.getActionMasked(ev);
|
||||
final float x = ev.getX();
|
||||
final float y = ev.getY();
|
||||
final boolean isChildUnder = ViewUtils.isViewUnder(mChild, (int) x, (int) y);
|
||||
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mInitialMotionX = x;
|
||||
mInitialMotionY = y;
|
||||
mLastMotionY = mInitialMotionY;
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
final float adx = Math.abs(x - mInitialMotionX);
|
||||
final float ady = Math.abs(y - mInitialMotionY);
|
||||
if (isChildUnder && adx > mSlop && ady > adx)
|
||||
getTouchEvent = true;
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
break;
|
||||
}
|
||||
|
||||
return getTouchEvent;
|
||||
}
|
||||
|
||||
private void updateShowPercent() {
|
||||
int top = mChild.getTop();
|
||||
mShowPercent = (isBottom ? (mMaxTop - top) : (top - mMinTop)) /
|
||||
(float) mChild.getHeight();
|
||||
}
|
||||
|
||||
private void cancelAnimator() {
|
||||
if (mToBaseLevelAnimate.isRunning())
|
||||
mToBaseLevelAnimate.cancel();
|
||||
if (mToReservedLevelAnimate.isRunning())
|
||||
mToReservedLevelAnimate.cancel();
|
||||
if (mToFullScreenLevelAnimate.isRunning())
|
||||
mToFullScreenLevelAnimate.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
final int action = MotionEventCompat.getActionMasked(ev);
|
||||
final float x = ev.getX();
|
||||
final float y = ev.getY();
|
||||
boolean getTouchEvent = false;
|
||||
|
||||
cancelAnimator();
|
||||
|
||||
int top;
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mInitialMotionX = x;
|
||||
mInitialMotionY = y;
|
||||
mLastMotionY = mInitialMotionY;
|
||||
if (isShowing())
|
||||
getTouchEvent = true;
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
final float dy = y - mLastMotionY;
|
||||
mLastMotionY = y;
|
||||
getTouchEvent = true;
|
||||
|
||||
top = mChild.getTop();
|
||||
int newTop = top + (int) dy;
|
||||
newTop = MathUtils.clamp(newTop, mMinTop, mMaxTop);
|
||||
mChild.offsetTopAndBottom(newTop - top);
|
||||
updateShowPercent();
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
getTouchEvent = true;
|
||||
|
||||
top = mChild.getTop();
|
||||
if (isBottom) {
|
||||
switch (mLevel) {
|
||||
default:
|
||||
case LEVEL_BASE:
|
||||
if (top < mFullScreenTop)
|
||||
;
|
||||
else if (top < m4Top)
|
||||
toFullScreenLevel();
|
||||
else if (top < m1Top)
|
||||
toReservedLevel(false);
|
||||
else
|
||||
toBaseLevel();
|
||||
break;
|
||||
case LEVEL_RESERVED:
|
||||
if (top < mFullScreenTop)
|
||||
;
|
||||
else if (top < m4Top)
|
||||
toFullScreenLevel();
|
||||
else if (top < m2Top)
|
||||
toReservedLevel(false);
|
||||
else
|
||||
toBaseLevel();
|
||||
break;
|
||||
case LEVEL_FULL_SCREEN:
|
||||
if (top < mFullScreenTop)
|
||||
;
|
||||
else if (top < m5Top)
|
||||
toFullScreenLevel();
|
||||
else if (top < m2Top)
|
||||
toReservedLevel(false);
|
||||
else
|
||||
toBaseLevel();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
break;
|
||||
}
|
||||
return getTouchEvent;
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
if (mChild.getVisibility() != View.INVISIBLE)
|
||||
mChild.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mChild.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
public boolean isInHideAnimate() {
|
||||
return mInHideAnimate;
|
||||
}
|
||||
|
||||
public void toReservedLevel(boolean withShake) {
|
||||
cancelAnimator();
|
||||
// Show child
|
||||
if (mChild.getVisibility() != View.VISIBLE)
|
||||
mChild.setVisibility(View.VISIBLE);
|
||||
|
||||
mToReservedLevelListener.reset();
|
||||
mToReservedLevelAnimate.setFloatValues(mChild.getTop(), mReservedTop);
|
||||
|
||||
if (withShake) {
|
||||
AnimatorSet bouncer = new AnimatorSet();
|
||||
Animator delayAnimator = AnimatorUtils.createDelayAnimator(200);
|
||||
ValueAnimator shakeAnimator = ValueAnimator.ofFloat(mReservedTop,
|
||||
isBottom ? mReservedTop - Ui.dp2pix(8) : mReservedTop + Ui.dp2pix(8));
|
||||
shakeAnimator.setDuration(500);
|
||||
shakeAnimator.setInterpolator(new CycleInterpolator(1));
|
||||
shakeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
int offsetY = (int) (float) (Float) animation.getAnimatedValue() - mChild.getTop();
|
||||
mChild.offsetTopAndBottom(offsetY);
|
||||
updateShowPercent();
|
||||
}
|
||||
});
|
||||
bouncer.play(mToReservedLevelAnimate).before(delayAnimator);
|
||||
bouncer.play(delayAnimator).before(shakeAnimator);
|
||||
bouncer.start();
|
||||
|
||||
} else {
|
||||
mToReservedLevelAnimate.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void toBaseLevel() {
|
||||
cancelAnimator();
|
||||
// Show child
|
||||
if (mChild.getVisibility() != View.VISIBLE)
|
||||
mChild.setVisibility(View.VISIBLE);
|
||||
|
||||
mToBaseLevelListener.reset();
|
||||
mToBaseLevelAnimate.setFloatValues(mChild.getTop(), mBaseTop);
|
||||
mToBaseLevelAnimate.start();
|
||||
}
|
||||
|
||||
public void toFullScreenLevel() {
|
||||
cancelAnimator();
|
||||
// Show child
|
||||
if (mChild.getVisibility() != View.VISIBLE)
|
||||
mChild.setVisibility(View.VISIBLE);
|
||||
|
||||
mToFullScreenLevelListener.reset();
|
||||
mToFullScreenLevelAnimate.setFloatValues(mChild.getTop(), mFullScreenTop);
|
||||
mToFullScreenLevelAnimate.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
|
||||
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
|
||||
return p instanceof LayoutParams
|
||||
? new LayoutParams((LayoutParams) p)
|
||||
: new LayoutParams(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
|
||||
return p instanceof LayoutParams && super.checkLayoutParams(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
|
||||
return new LayoutParams(getContext(), attrs);
|
||||
}
|
||||
|
||||
public static class LayoutParams extends ViewGroup.LayoutParams {
|
||||
|
||||
private static final int[] LAYOUT_ATTRS = new int[] {
|
||||
android.R.attr.layout_gravity
|
||||
};
|
||||
|
||||
public int gravity = Gravity.BOTTOM;
|
||||
|
||||
public LayoutParams(Context c, AttributeSet attrs) {
|
||||
super(c, attrs);
|
||||
|
||||
final TypedArray a = c.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
|
||||
this.gravity = a.getInt(0, Gravity.BOTTOM);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public LayoutParams(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
public LayoutParams(int width, int height, int gravity) {
|
||||
this(width, height);
|
||||
this.gravity = gravity;
|
||||
}
|
||||
|
||||
public LayoutParams(LayoutParams source) {
|
||||
super(source);
|
||||
gravity = source.gravity;
|
||||
}
|
||||
|
||||
public LayoutParams(ViewGroup.LayoutParams source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.hippo.ehviewer.effect.DrawableTransition;
|
||||
|
||||
public class TransitionLayout extends LinearLayout {
|
||||
|
||||
private Bitmap mBmp;
|
||||
private int mOldWidth;
|
||||
private int mOldHeight;
|
||||
|
||||
private static final String TAG = TransitionLayout.class.getSimpleName();
|
||||
|
||||
public TransitionLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public TransitionLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public TransitionLayout(Context context, AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public TransitionLayout(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
if (mOldWidth != width || mOldHeight != height || mBmp == null) {
|
||||
mOldWidth = width;
|
||||
mOldHeight = height;
|
||||
|
||||
if (mBmp != null && !mBmp.isRecycled())
|
||||
mBmp.recycle();
|
||||
|
||||
mBmp = Bitmap.createBitmap(getWidth(), getHeight(),
|
||||
Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(mBmp);
|
||||
c.translate(-getScrollX(), -getScrollY());
|
||||
super.dispatchDraw(c);
|
||||
BitmapDrawable b = new BitmapDrawable(getResources(), mBmp);
|
||||
DrawableTransition.transit(b, false, 3000);
|
||||
setBackgroundDrawable(b);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
setBackgroundDrawable(null);
|
||||
if (mBmp != null && !mBmp.isRecycled())
|
||||
mBmp.recycle();
|
||||
}
|
||||
}
|
||||
@@ -1,889 +0,0 @@
|
||||
/*
|
||||
* 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.widget.recyclerview;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ActionMode;
|
||||
import android.view.InputDevice;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.ListAdapter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Get some code from twoway-view and AbsListView
|
||||
*
|
||||
* @author Hippo
|
||||
*
|
||||
*/
|
||||
public class EasyRecyclerView extends RecyclerView implements View.OnClickListener,
|
||||
View.OnLongClickListener {
|
||||
|
||||
private static final String TAG = EasyRecyclerView.class.getSimpleName();
|
||||
|
||||
private static final String STATE_KEY_CHOICE_MODE = "choiceMode";
|
||||
private static final String STATE_KEY_CHECKED_STATES = "checkedStates";
|
||||
private static final String STATE_KEY_CHECKED_ID_STATES = "checkedIdStates";
|
||||
private static final String STATE_KEY_CHECKED_COUNT = "checkedCount";
|
||||
|
||||
/**
|
||||
* Represents an invalid position. All valid positions are in the range 0 to 1 less than the
|
||||
* number of items in the current adapter.
|
||||
*/
|
||||
public static final int INVALID_POSITION = -1;
|
||||
|
||||
/**
|
||||
* Normal list that does not indicate choices
|
||||
*/
|
||||
public static final int CHOICE_MODE_NONE = 0;
|
||||
|
||||
/**
|
||||
* The list allows up to one choice
|
||||
*/
|
||||
public static final int CHOICE_MODE_SINGLE = 1;
|
||||
|
||||
/**
|
||||
* The list allows multiple choices
|
||||
*/
|
||||
public static final int CHOICE_MODE_MULTIPLE = 2;
|
||||
|
||||
/**
|
||||
* The list allows multiple choices in a modal selection mode
|
||||
*/
|
||||
public static final int CHOICE_MODE_MULTIPLE_MODAL = 3;
|
||||
|
||||
/**
|
||||
* Controls if/how the user may choose/check items in the list
|
||||
*/
|
||||
private int mChoiceMode = CHOICE_MODE_NONE;
|
||||
|
||||
/**
|
||||
* Controls CHOICE_MODE_MULTIPLE_MODAL. null when inactive.
|
||||
*/
|
||||
private ActionMode mChoiceActionMode;
|
||||
|
||||
/**
|
||||
* Wrapper for the multiple choice mode callback; AbsListView needs to perform
|
||||
* a few extra actions around what application code does.
|
||||
*/
|
||||
MultiChoiceModeWrapper mMultiChoiceModeCallback;
|
||||
|
||||
/**
|
||||
* Running count of how many items are currently checked
|
||||
*/
|
||||
private int mCheckedItemCount;
|
||||
|
||||
/**
|
||||
* Running state of which positions are currently checked
|
||||
*/
|
||||
private SparseBooleanArray mCheckStates;
|
||||
|
||||
/**
|
||||
* Running state of which IDs are currently checked.
|
||||
* If there is a value for a given key, the checked state for that ID is true
|
||||
* and the value holds the last known position in the adapter for that id.
|
||||
*/
|
||||
private LongSparseArray<Integer> mCheckedIdStates;
|
||||
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
private OnItemLongClickListener mOnItemLongClickListener;
|
||||
private boolean mNeedOnClickListener = false;
|
||||
private boolean mNeedOnLongClickListener = false;
|
||||
|
||||
private FooterAdapter mAdapter;
|
||||
|
||||
private float mVerticalScrollFactor = 0;
|
||||
|
||||
public EasyRecyclerView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public EasyRecyclerView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public EasyRecyclerView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public View getFootView() {
|
||||
if (mAdapter != null)
|
||||
return mAdapter.getFooterView();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isNeedOnClickListener() {
|
||||
if (mOnItemClickListener == null && mChoiceMode == CHOICE_MODE_NONE)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isNeedOnLongClickListener() {
|
||||
if (mOnItemLongClickListener != null || mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setAllOnClickListener() {
|
||||
final int count = getChildCount();
|
||||
final View footView = getFootView();
|
||||
for (int i = 0; i < count; i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child != footView) {
|
||||
child.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAllOnClickListener() {
|
||||
final int count = getChildCount();
|
||||
final View footView = getFootView();
|
||||
for (int i = 0; i < count; i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child != footView) {
|
||||
child.setOnClickListener(null);
|
||||
child.setClickable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setAllOnLongClickListener() {
|
||||
final int count = getChildCount();
|
||||
final View footView = getFootView();
|
||||
for (int i = 0; i < count; i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child != footView) {
|
||||
child.setOnLongClickListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAllOnLongClickListener() {
|
||||
final int count = getChildCount();
|
||||
final View footView = getFootView();
|
||||
for (int i = 0; i < count; i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child != footView) {
|
||||
child.setOnLongClickListener(null);
|
||||
child.setLongClickable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateOnClickState() {
|
||||
boolean newNeedOnClickListener = isNeedOnClickListener();
|
||||
if (mNeedOnClickListener != newNeedOnClickListener) {
|
||||
mNeedOnClickListener = newNeedOnClickListener;
|
||||
if (mNeedOnClickListener)
|
||||
setAllOnClickListener();
|
||||
else
|
||||
resetAllOnClickListener();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateOnLongClickState() {
|
||||
boolean newNeedOnLongClickListener = isNeedOnLongClickListener();
|
||||
if (mNeedOnLongClickListener != newNeedOnLongClickListener) {
|
||||
mNeedOnLongClickListener = newNeedOnLongClickListener;
|
||||
if (mNeedOnLongClickListener)
|
||||
setAllOnLongClickListener();
|
||||
else
|
||||
resetAllOnLongClickListener();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be invoked when an item in the
|
||||
* RecyclerView has been clicked.
|
||||
*
|
||||
* @param listener The callback that will be invoked.
|
||||
*/
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
mOnItemClickListener = listener;
|
||||
updateOnClickState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be invoked when an item in the
|
||||
* RecyclerView has been clicked and held.
|
||||
*
|
||||
* @param listener The callback that will be invoked.
|
||||
*/
|
||||
public void setOnItemLongClickListener(OnItemLongClickListener listener) {
|
||||
mOnItemLongClickListener = listener;
|
||||
updateOnLongClickState();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* adapter must be {@link com.hippo.ehviewer.widget.recyclerview.EasyRecyclerView.FooterAdapter}
|
||||
*/
|
||||
@Override
|
||||
public void setAdapter(RecyclerView.Adapter adapter) {
|
||||
super.setAdapter(adapter);
|
||||
|
||||
mAdapter = (FooterAdapter) adapter;
|
||||
mAdapter.mHolder = this;
|
||||
if (adapter != null) {
|
||||
if (mChoiceMode != CHOICE_MODE_NONE && adapter.hasStableIds() &&
|
||||
mCheckedIdStates == null) {
|
||||
mCheckedIdStates = new LongSparseArray<Integer>();
|
||||
}
|
||||
}
|
||||
|
||||
if (mCheckStates != null) {
|
||||
mCheckStates.clear();
|
||||
}
|
||||
|
||||
if (mCheckedIdStates != null) {
|
||||
mCheckedIdStates.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items currently selected. This will only be valid
|
||||
* if the choice mode is not {@link #CHOICE_MODE_NONE} (default).
|
||||
*
|
||||
* <p>To determine the specific items that are currently selected, use one of
|
||||
* the <code>getChecked*</code> methods.
|
||||
*
|
||||
* @return The number of items currently selected
|
||||
*
|
||||
* @see #getCheckedItemPosition()
|
||||
* @see #getCheckedItemPositions()
|
||||
* @see #getCheckedItemIds()
|
||||
*/
|
||||
public int getCheckedItemCount() {
|
||||
return mCheckedItemCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the checked state of the specified position. The result is only
|
||||
* valid if the choice mode has been set to {@link #CHOICE_MODE_SINGLE}
|
||||
* or {@link #CHOICE_MODE_MULTIPLE}.
|
||||
*
|
||||
* @param position The item whose checked state to return
|
||||
* @return The item's checked state or <code>false</code> if choice mode
|
||||
* is invalid
|
||||
*
|
||||
* @see #setChoiceMode(int)
|
||||
*/
|
||||
public boolean isItemChecked(int position) {
|
||||
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
|
||||
return mCheckStates.get(position);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently checked item. The result is only valid if the choice
|
||||
* mode has been set to {@link #CHOICE_MODE_SINGLE}.
|
||||
*
|
||||
* @return The position of the currently checked item or
|
||||
* {@link #INVALID_POSITION} if nothing is selected
|
||||
*
|
||||
* @see #setChoiceMode(int)
|
||||
*/
|
||||
public int getCheckedItemPosition() {
|
||||
if (mChoiceMode == CHOICE_MODE_SINGLE && mCheckStates != null && mCheckStates.size() == 1) {
|
||||
return mCheckStates.keyAt(0);
|
||||
}
|
||||
|
||||
return INVALID_POSITION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of checked items in the list. The result is only valid if
|
||||
* the choice mode has not been set to {@link #CHOICE_MODE_NONE}.
|
||||
*
|
||||
* @return A SparseBooleanArray which will return true for each call to
|
||||
* get(int position) where position is a checked position in the
|
||||
* list and false otherwise, or <code>null</code> if the choice
|
||||
* mode is set to {@link #CHOICE_MODE_NONE}.
|
||||
*/
|
||||
public SparseBooleanArray getCheckedItemPositions() {
|
||||
if (mChoiceMode != CHOICE_MODE_NONE) {
|
||||
return mCheckStates;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of checked items ids. The result is only valid if the
|
||||
* choice mode has not been set to {@link #CHOICE_MODE_NONE} and the adapter
|
||||
* has stable IDs. ({@link ListAdapter#hasStableIds()} == {@code true})
|
||||
*
|
||||
* @return A new array which contains the id of each checked item in the
|
||||
* list.
|
||||
*/
|
||||
public long[] getCheckedItemIds() {
|
||||
if (mChoiceMode == CHOICE_MODE_NONE || mCheckedIdStates == null || mAdapter == null) {
|
||||
return new long[0];
|
||||
}
|
||||
|
||||
final LongSparseArray<Integer> idStates = mCheckedIdStates;
|
||||
final int count = idStates.size();
|
||||
final long[] ids = new long[count];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ids[i] = idStates.keyAt(i);
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear any choices previously set
|
||||
*/
|
||||
public void clearChoices() {
|
||||
if (mCheckStates != null) {
|
||||
mCheckStates.clear();
|
||||
}
|
||||
if (mCheckedIdStates != null) {
|
||||
mCheckedIdStates.clear();
|
||||
}
|
||||
mCheckedItemCount = 0;
|
||||
updateOnScreenCheckedViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the checked state of the specified position. The is only valid if
|
||||
* the choice mode has been set to {@link #CHOICE_MODE_SINGLE} or
|
||||
* {@link #CHOICE_MODE_MULTIPLE}.
|
||||
*
|
||||
* @param position The item whose checked state is to be checked
|
||||
* @param value The new checked state for the item
|
||||
*/
|
||||
public void setItemChecked(int position, boolean value) {
|
||||
if (mChoiceMode == CHOICE_MODE_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start selection mode if needed. We don't need to if we're unchecking something.
|
||||
if (value && mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null) {
|
||||
if (mMultiChoiceModeCallback == null ||
|
||||
!mMultiChoiceModeCallback.hasWrappedCallback()) {
|
||||
throw new IllegalStateException("AbsListView: attempted to start selection mode " +
|
||||
"for CHOICE_MODE_MULTIPLE_MODAL but no choice mode callback was " +
|
||||
"supplied. Call setMultiChoiceModeListener to set a callback.");
|
||||
}
|
||||
mChoiceActionMode = startActionMode(mMultiChoiceModeCallback);
|
||||
}
|
||||
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE || mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
|
||||
boolean oldValue = mCheckStates.get(position);
|
||||
mCheckStates.put(position, value);
|
||||
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
|
||||
if (value) {
|
||||
mCheckedIdStates.put(mAdapter.getItemId(position), position);
|
||||
} else {
|
||||
mCheckedIdStates.delete(mAdapter.getItemId(position));
|
||||
}
|
||||
}
|
||||
if (oldValue != value) {
|
||||
if (value) {
|
||||
mCheckedItemCount++;
|
||||
} else {
|
||||
mCheckedItemCount--;
|
||||
}
|
||||
}
|
||||
if (mChoiceActionMode != null) {
|
||||
final long id = mAdapter.getItemId(position);
|
||||
mMultiChoiceModeCallback.onItemCheckedStateChanged(mChoiceActionMode,
|
||||
position, id, value);
|
||||
}
|
||||
} else {
|
||||
boolean updateIds = mCheckedIdStates != null && mAdapter.hasStableIds();
|
||||
// Clear all values if we're checking something, or unchecking the currently
|
||||
// selected item
|
||||
if (value || isItemChecked(position)) {
|
||||
mCheckStates.clear();
|
||||
if (updateIds) {
|
||||
mCheckedIdStates.clear();
|
||||
}
|
||||
}
|
||||
// this may end up selecting the value we just cleared but this way
|
||||
// we ensure length of mCheckStates is 1, a fact getCheckedItemPosition relies on
|
||||
if (value) {
|
||||
mCheckStates.put(position, true);
|
||||
if (updateIds) {
|
||||
mCheckedIdStates.put(mAdapter.getItemId(position), position);
|
||||
}
|
||||
mCheckedItemCount = 1;
|
||||
} else if (mCheckStates.size() == 0 || !mCheckStates.valueAt(0)) {
|
||||
mCheckedItemCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
updateOnScreenCheckedViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #setChoiceMode(int)
|
||||
*
|
||||
* @return The current choice mode
|
||||
*/
|
||||
public int getChoiceMode() {
|
||||
return mChoiceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the choice behavior for the List. By default, Lists do not have any choice behavior
|
||||
* ({@link #CHOICE_MODE_NONE}). By setting the choiceMode to {@link #CHOICE_MODE_SINGLE}, the
|
||||
* List allows up to one item to be in a chosen state. By setting the choiceMode to
|
||||
* {@link #CHOICE_MODE_MULTIPLE}, the list allows any number of items to be chosen.
|
||||
*
|
||||
* @param choiceMode One of {@link #CHOICE_MODE_NONE}, {@link #CHOICE_MODE_SINGLE}, or
|
||||
* {@link #CHOICE_MODE_MULTIPLE}
|
||||
*/
|
||||
public void setChoiceMode(int choiceMode) {
|
||||
mChoiceMode = choiceMode;
|
||||
if (mChoiceActionMode != null) {
|
||||
mChoiceActionMode.finish();
|
||||
mChoiceActionMode = null;
|
||||
}
|
||||
if (mChoiceMode != CHOICE_MODE_NONE) {
|
||||
if (mCheckStates == null) {
|
||||
mCheckStates = new SparseBooleanArray(0);
|
||||
}
|
||||
if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
|
||||
mCheckedIdStates = new LongSparseArray<Integer>(0);
|
||||
}
|
||||
// Modal multi-choice mode only has choices when the mode is active. Clear them.
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
|
||||
clearChoices();
|
||||
}
|
||||
}
|
||||
|
||||
updateOnClickState();
|
||||
updateOnLongClickState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a {@link MultiChoiceModeListener} that will manage the lifecycle of the
|
||||
* selection {@link ActionMode}. Only used when the choice mode is set to
|
||||
* {@link #CHOICE_MODE_MULTIPLE_MODAL}.
|
||||
*
|
||||
* @param listener Listener that will manage the selection mode
|
||||
*
|
||||
* @see #setChoiceMode(int)
|
||||
*/
|
||||
public void setMultiChoiceModeListener(MultiChoiceModeListener listener) {
|
||||
if (mMultiChoiceModeCallback == null) {
|
||||
mMultiChoiceModeCallback = new MultiChoiceModeWrapper();
|
||||
}
|
||||
mMultiChoiceModeCallback.setWrapped(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a quick, in-place update of the checked or activated state
|
||||
* on all visible item views. This should only be called when a valid
|
||||
* choice mode is active.
|
||||
*/
|
||||
private void updateOnScreenCheckedViews() {
|
||||
final int count = getChildCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final View child = getChildAt(i);
|
||||
final int position = getChildPosition(child);
|
||||
setViewChecked(child, mCheckStates.get(position));
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static void setViewChecked(View view, boolean checked) {
|
||||
final boolean useActivated = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
|
||||
if (view instanceof Checkable) {
|
||||
((Checkable) view).setChecked(checked);
|
||||
} else if (useActivated) {
|
||||
view.setActivated(checked);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_SCROLL: {
|
||||
if (getScrollState() != SCROLL_STATE_DRAGGING) {
|
||||
final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
|
||||
if (vscroll != 0) {
|
||||
final int delta = (int) (vscroll * getVerticalScrollFactor());
|
||||
scrollBy(0, -delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a scale factor that determines the distance the view should scroll
|
||||
* vertically in response to {@link MotionEvent#ACTION_SCROLL}.
|
||||
* @return The vertical scroll scale factor.
|
||||
*/
|
||||
protected float getVerticalScrollFactor() {
|
||||
if (mVerticalScrollFactor == 0) {
|
||||
TypedValue outValue = new TypedValue();
|
||||
if (!getContext().getTheme().resolveAttribute(
|
||||
0x0101004d, outValue, true)) {//com.android.internal.R.attr.listPreferredItemHeight
|
||||
throw new IllegalStateException(
|
||||
"Expected theme to define listPreferredItemHeight.");
|
||||
}
|
||||
mVerticalScrollFactor = outValue.getDimension(
|
||||
getContext().getResources().getDisplayMetrics());
|
||||
}
|
||||
return mVerticalScrollFactor;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
final Parcelable state = new Bundle(super.onSaveInstanceState());
|
||||
|
||||
state.putInt(STATE_KEY_CHOICE_MODE, mChoiceMode);
|
||||
state.putParcelable(STATE_KEY_CHECKED_STATES, mCheckStates);
|
||||
state.putParcelable(STATE_KEY_CHECKED_ID_STATES, mCheckedIdStates);
|
||||
state.putInt(STATE_KEY_CHECKED_COUNT, mCheckedItemCount);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
public void onRestoreInstanceState(Bundle state) {
|
||||
mChoiceMode = ChoiceMode.values()[state.getInt(STATE_KEY_CHOICE_MODE)];
|
||||
mCheckedStates = state.getParcelable(STATE_KEY_CHECKED_STATES);
|
||||
mCheckedIdStates = state.getParcelable(STATE_KEY_CHECKED_ID_STATES);
|
||||
mCheckedCount = state.getInt(STATE_KEY_CHECKED_COUNT);
|
||||
|
||||
// TODO confirm ids here
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when an item in the
|
||||
* EasyRecyclerView has been clicked.
|
||||
*/
|
||||
public interface OnItemClickListener {
|
||||
/**
|
||||
* Callback method to be invoked when an item in the EasyRecyclerView
|
||||
* has been clicked.
|
||||
*
|
||||
* @param parent The EasyRecyclerView where the click happened.
|
||||
* @param view The view within the EasyRecyclerView that was clicked
|
||||
* @param position The position of the view in the adapter.
|
||||
* @param id The row id of the item that was clicked.
|
||||
*
|
||||
* @return true if the callback consumed the click, false otherwise
|
||||
*/
|
||||
boolean onItemClick(EasyRecyclerView parent, View view, int position, long id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when an item in the
|
||||
* EasyRecyclerView has been clicked and held.
|
||||
*/
|
||||
public interface OnItemLongClickListener {
|
||||
/**
|
||||
* Callback method to be invoked when an item in the EasyRecyclerView
|
||||
* has been clicked and held.
|
||||
*
|
||||
* @param parent The EasyRecyclerView where the click happened
|
||||
* @param view The view within the EasyRecyclerView that was clicked
|
||||
* @param position The position of the view in the list
|
||||
* @param id The row id of the item that was clicked
|
||||
*
|
||||
* @return true if the callback consumed the long click, false otherwise
|
||||
*/
|
||||
boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* EasyRecyclerView.OnItemTouchListener will not work fine
|
||||
* when item view's child need click action, because they make
|
||||
* touch event deliver different
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final int position = getChildPosition(view);
|
||||
final long id = mAdapter.getItemId(position);
|
||||
|
||||
boolean dispatchItemClick = true;
|
||||
|
||||
if (mChoiceMode != CHOICE_MODE_NONE) {
|
||||
boolean checkedStateChanged = false;
|
||||
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE ||
|
||||
(mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode != null)) {
|
||||
boolean checked = !mCheckStates.get(position, false);
|
||||
mCheckStates.put(position, checked);
|
||||
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
|
||||
if (checked) {
|
||||
mCheckedIdStates.put(mAdapter.getItemId(position), position);
|
||||
} else {
|
||||
mCheckedIdStates.delete(mAdapter.getItemId(position));
|
||||
}
|
||||
}
|
||||
if (checked) {
|
||||
mCheckedItemCount++;
|
||||
} else {
|
||||
mCheckedItemCount--;
|
||||
}
|
||||
if (mChoiceActionMode != null) {
|
||||
mMultiChoiceModeCallback.onItemCheckedStateChanged(mChoiceActionMode,
|
||||
position, id, checked);
|
||||
dispatchItemClick = false;
|
||||
}
|
||||
checkedStateChanged = true;
|
||||
} else if (mChoiceMode == CHOICE_MODE_SINGLE) {
|
||||
boolean checked = !mCheckStates.get(position, false);
|
||||
if (checked) {
|
||||
mCheckStates.clear();
|
||||
mCheckStates.put(position, true);
|
||||
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
|
||||
mCheckedIdStates.clear();
|
||||
mCheckedIdStates.put(mAdapter.getItemId(position), position);
|
||||
}
|
||||
mCheckedItemCount = 1;
|
||||
} else if (mCheckStates.size() == 0 || !mCheckStates.valueAt(0)) {
|
||||
mCheckedItemCount = 0;
|
||||
}
|
||||
checkedStateChanged = true;
|
||||
}
|
||||
|
||||
if (checkedStateChanged) {
|
||||
updateOnScreenCheckedViews();
|
||||
}
|
||||
}
|
||||
|
||||
if (dispatchItemClick && mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onItemClick(this, view, position, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
final int position = getChildPosition(view);
|
||||
final long id = mAdapter.getItemId(position);
|
||||
|
||||
// CHOICE_MODE_MULTIPLE_MODAL takes over long press.
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
|
||||
if (mChoiceActionMode == null &&
|
||||
(mChoiceActionMode = startActionMode(mMultiChoiceModeCallback)) != null) {
|
||||
setItemChecked(position, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean handled = false;
|
||||
if (mOnItemLongClickListener != null) {
|
||||
handled = mOnItemLongClickListener.onItemLongClick(this, view,
|
||||
position, id);
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* A MultiChoiceModeListener receives events for {@link AbsListView#CHOICE_MODE_MULTIPLE_MODAL}.
|
||||
* It acts as the {@link ActionMode.Callback} for the selection mode and also receives
|
||||
* {@link #onItemCheckedStateChanged(ActionMode, int, long, boolean)} events when the user
|
||||
* selects and deselects list items.
|
||||
*/
|
||||
public interface MultiChoiceModeListener extends ActionMode.Callback {
|
||||
/**
|
||||
* Called when an item is checked or unchecked during selection mode.
|
||||
*
|
||||
* @param mode The {@link ActionMode} providing the selection mode
|
||||
* @param position Adapter position of the item that was checked or unchecked
|
||||
* @param id Adapter ID of the item that was checked or unchecked
|
||||
* @param checked <code>true</code> if the item is now checked, <code>false</code>
|
||||
* if the item is now unchecked.
|
||||
*/
|
||||
public void onItemCheckedStateChanged(ActionMode mode,
|
||||
int position, long id, boolean checked);
|
||||
}
|
||||
|
||||
class MultiChoiceModeWrapper implements MultiChoiceModeListener {
|
||||
private MultiChoiceModeListener mWrapped;
|
||||
|
||||
public void setWrapped(MultiChoiceModeListener wrapped) {
|
||||
mWrapped = wrapped;
|
||||
}
|
||||
|
||||
public boolean hasWrappedCallback() {
|
||||
return mWrapped != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
if (mWrapped.onCreateActionMode(mode, menu)) {
|
||||
// Initialize checked graphic state?
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
return mWrapped.onPrepareActionMode(mode, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
return mWrapped.onActionItemClicked(mode, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
mWrapped.onDestroyActionMode(mode);
|
||||
mChoiceActionMode = null;
|
||||
|
||||
// Ending selection mode means deselecting everything.
|
||||
clearChoices();
|
||||
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemCheckedStateChanged(ActionMode mode,
|
||||
int position, long id, boolean checked) {
|
||||
mWrapped.onItemCheckedStateChanged(mode, position, id, checked);
|
||||
|
||||
// If there are no items selected we no longer need the selection mode.
|
||||
if (getCheckedItemCount() == 0) {
|
||||
mode.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class FooterAdapter<VH extends ViewHolder> extends RecyclerView.Adapter<VH> {
|
||||
|
||||
public static final int TYPE_FOOTER = Integer.MAX_VALUE;
|
||||
|
||||
private EasyRecyclerView mHolder;
|
||||
private View mFooterView;
|
||||
|
||||
public boolean hasFootView() {
|
||||
return mFooterView != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* footerView == null to remove foot view
|
||||
* @param footerView
|
||||
*/
|
||||
public void setFooterView(View footerView) {
|
||||
if (mFooterView == footerView)
|
||||
return;
|
||||
|
||||
int itemCountActual = getItemCountActual();
|
||||
View originView = mFooterView;
|
||||
mFooterView = footerView;
|
||||
if (originView != null) {
|
||||
if (mFooterView != null)
|
||||
notifyItemChanged(itemCountActual);
|
||||
else
|
||||
notifyItemRemoved(itemCountActual);
|
||||
} else {
|
||||
notifyItemInserted(itemCountActual);
|
||||
}
|
||||
}
|
||||
|
||||
public View getFooterView() {
|
||||
return mFooterView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final VH onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (mFooterView != null && viewType == TYPE_FOOTER) {
|
||||
StaggeredGridLayoutManager.LayoutParams lp = new StaggeredGridLayoutManager.LayoutParams(
|
||||
StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT,
|
||||
StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT);
|
||||
lp.setFullSpan(true);
|
||||
mFooterView.setLayoutParams(lp);
|
||||
return onCreateAndBindFooterViewHolder(parent, mFooterView);
|
||||
} else {
|
||||
return onCreateViewHolderActual(parent, viewType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onBindViewHolder(VH holder, int position) {
|
||||
if (mFooterView == null || position != getItemCountActual()) {
|
||||
onBindViewHolderActual(holder, position);
|
||||
if (mHolder.mNeedOnClickListener)
|
||||
holder.itemView.setOnClickListener(mHolder);
|
||||
if (mHolder.mNeedOnLongClickListener)
|
||||
holder.itemView.setOnLongClickListener(mHolder);
|
||||
EasyRecyclerView.setViewChecked(holder.itemView,
|
||||
mHolder.isItemChecked(position));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getItemViewType(int position) {
|
||||
if (mFooterView != null && position == getItemCountActual())
|
||||
return TYPE_FOOTER;
|
||||
else
|
||||
return getItemViewTypeActual(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getItemCount() {
|
||||
int itemCount = getItemCountActual();
|
||||
if (mFooterView != null)
|
||||
itemCount++;
|
||||
return itemCount;
|
||||
}
|
||||
|
||||
public abstract VH onCreateAndBindFooterViewHolder(ViewGroup parent, View footerView);
|
||||
|
||||
public abstract VH onCreateViewHolderActual(ViewGroup parent, int viewType);
|
||||
|
||||
public abstract void onBindViewHolderActual(VH holder, int position);
|
||||
|
||||
/**
|
||||
* Foot view type is Integer.MAX_VALUE, do not be the same
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
public int getItemViewTypeActual(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public abstract int getItemCountActual();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* 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.widget.recyclerview;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
public class LinearDividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||
public static final int HORIZONTAL = LinearLayoutManager.HORIZONTAL;
|
||||
public static final int VERTICAL = LinearLayoutManager.VERTICAL;
|
||||
|
||||
private boolean mShowFirstDivider = false;
|
||||
private boolean mShowLastDivider = false;
|
||||
|
||||
private final Rect mRect;
|
||||
private final Paint mPaint;
|
||||
|
||||
private int mOrientation;
|
||||
private int mThickness;
|
||||
private int mPaddingStart = 0;
|
||||
private int mPaddingEnd = 0;
|
||||
|
||||
public LinearDividerItemDecoration(int orientation, int color, int thickness) {
|
||||
mRect = new Rect();
|
||||
mPaint = new Paint();
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
setOrientation(orientation);
|
||||
setColor(color);
|
||||
setThickness(thickness);
|
||||
}
|
||||
|
||||
public void setOrientation(int orientation) {
|
||||
if (orientation != HORIZONTAL && orientation != VERTICAL) {
|
||||
throw new IllegalArgumentException("invalid orientation");
|
||||
}
|
||||
mOrientation = orientation;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
mPaint.setColor(color);
|
||||
}
|
||||
|
||||
public void setThickness(int thickness) {
|
||||
mThickness = thickness;
|
||||
}
|
||||
|
||||
public void setShowFirstDivider(boolean showFirstDivider) {
|
||||
mShowFirstDivider = showFirstDivider;
|
||||
}
|
||||
|
||||
public void setShowLastDivider(boolean showLastDivider) {
|
||||
mShowLastDivider = showLastDivider;
|
||||
}
|
||||
|
||||
public void setPadding(int padding) {
|
||||
setPaddingStart(padding);
|
||||
setPaddingEnd(padding);
|
||||
}
|
||||
|
||||
public void setPaddingStart(int paddingStart) {
|
||||
mPaddingStart = paddingStart;
|
||||
}
|
||||
|
||||
public void setPaddingEnd(int paddingEnd) {
|
||||
mPaddingEnd = paddingEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view,
|
||||
RecyclerView parent, RecyclerView.State state) {
|
||||
final int position = parent.getChildPosition(view);
|
||||
final int itemCount = parent.getAdapter().getItemCount();
|
||||
if (mOrientation == VERTICAL) {
|
||||
if (position == 0 && mShowFirstDivider)
|
||||
outRect.top = mThickness;
|
||||
outRect.bottom = mThickness;
|
||||
if (position == itemCount - 1 && !mShowLastDivider)
|
||||
outRect.bottom = 0;
|
||||
} else {
|
||||
if (position == 0 && mShowFirstDivider)
|
||||
outRect.left = mThickness;
|
||||
outRect.right = mThickness;
|
||||
if (position == itemCount - 1 && !mShowLastDivider)
|
||||
outRect.left = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
int itemCount = parent.getAdapter().getItemCount();
|
||||
|
||||
if (mOrientation == VERTICAL) {
|
||||
final int left = parent.getPaddingLeft() + mPaddingStart;
|
||||
final int right = parent.getWidth() - parent.getPaddingRight() - mPaddingEnd;
|
||||
final int childCount = parent.getChildCount();
|
||||
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
if (i != childCount - 1 || mShowLastDivider
|
||||
|| parent.getChildPosition(child) != itemCount - 1) {
|
||||
final int top = child.getBottom() + lp.bottomMargin;
|
||||
final int bottom = top + mThickness;
|
||||
mRect.set(left, top, right, bottom);
|
||||
c.drawRect(mRect, mPaint);
|
||||
}
|
||||
|
||||
if (i == 0 && mShowFirstDivider && parent.getChildPosition(child) == 0) {
|
||||
final int bottom = child.getTop() + lp.topMargin;
|
||||
final int top = bottom - mThickness;
|
||||
mRect.set(left, top, right, bottom);
|
||||
c.drawRect(mRect, mPaint);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final int top = parent.getPaddingTop() + mPaddingStart;
|
||||
final int bottom = parent.getHeight() - parent.getPaddingBottom() - mPaddingEnd;
|
||||
final int childCount = parent.getChildCount();
|
||||
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
if (i != childCount - 1 || mShowLastDivider
|
||||
|| parent.getChildPosition(child) != itemCount - 1) {
|
||||
final int left = child.getRight() + lp.rightMargin;
|
||||
final int right = left + mThickness;
|
||||
mRect.set(left, top, right, bottom);
|
||||
c.drawRect(mRect, mPaint);
|
||||
}
|
||||
|
||||
if (i == 0 && mShowFirstDivider && parent.getChildPosition(child) == 0) {
|
||||
final int right = child.getLeft() + lp.leftMargin;
|
||||
final int left = right - mThickness;
|
||||
mRect.set(left, top, right, bottom);
|
||||
c.drawRect(mRect, mPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.widget.recyclerview;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Only work for StaggeredGridLayoutManager, FooterAdapter
|
||||
*
|
||||
* @author Hippo
|
||||
*
|
||||
*/
|
||||
public class MarginItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private int mHalfMargin;
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view,
|
||||
RecyclerView parent, RecyclerView.State state) {
|
||||
outRect.set(mHalfMargin, mHalfMargin, mHalfMargin, mHalfMargin);
|
||||
}
|
||||
|
||||
public void setMargin(int margin) {
|
||||
mHalfMargin = margin / 2;
|
||||
}
|
||||
|
||||
public int getMargin() {
|
||||
return mHalfMargin * 2;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 292 B |
|
Before Width: | Height: | Size: 291 B |
|
Before Width: | Height: | Size: 295 B |
|
Before Width: | Height: | Size: 285 B |
|
Before Width: | Height: | Size: 427 B |
|
Before Width: | Height: | Size: 420 B |
|
Before Width: | Height: | Size: 411 B |
|
Before Width: | Height: | Size: 407 B |
|
Before Width: | Height: | Size: 627 B |
|
Before Width: | Height: | Size: 606 B |
|
Before Width: | Height: | Size: 579 B |
|
Before Width: | Height: | Size: 621 B |
|
Before Width: | Height: | Size: 692 B |
|
Before Width: | Height: | Size: 689 B |
|
Before Width: | Height: | Size: 675 B |
|
Before Width: | Height: | Size: 723 B |
|
Before Width: | Height: | Size: 188 B |
|
Before Width: | Height: | Size: 175 B |
|
Before Width: | Height: | Size: 262 B |
|
Before Width: | Height: | Size: 280 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 176 B |
|
Before Width: | Height: | Size: 339 B |
|
Before Width: | Height: | Size: 412 B |
|
Before Width: | Height: | Size: 436 B |
|
Before Width: | Height: | Size: 344 B |
|
Before Width: | Height: | Size: 211 B |
|
Before Width: | Height: | Size: 374 B |
|
Before Width: | Height: | Size: 320 B |
|
Before Width: | Height: | Size: 485 B |
|
Before Width: | Height: | Size: 652 B |
|
Before Width: | Height: | Size: 383 B |
|
Before Width: | Height: | Size: 730 B |