base
15
.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
My Application
|
||||
6
.idea/AndroidProjectSystem.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AndroidProjectSystem">
|
||||
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
</project>
|
||||
21
.idea/deploymentTargetSelector.xml
generated
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetSelector">
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
<SelectionState runConfigName="test2">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-12-05T06:23:58.625535100Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Administrator\.android\avd\Pixel_4_API_29.avd" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
<DialogSelection />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
</project>
|
||||
13
.idea/deviceManager.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DeviceTable">
|
||||
<option name="columnSorters">
|
||||
<list>
|
||||
<ColumnSorterState>
|
||||
<option name="column" value="Name" />
|
||||
<option name="order" value="ASCENDING" />
|
||||
</ColumnSorterState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
20
.idea/gradle.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/test2" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/migrations.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectMigrations">
|
||||
<option name="MigrateToGradleLocalJavaHome">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
9
.idea/misc.xml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
17
.idea/runConfigurations.xml
generated
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
|
||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
|
||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
4
build.gradle.kts
Normal file
@ -0,0 +1,4 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
alias(libs.plugins.android.application) apply false
|
||||
}
|
||||
21
gradle.properties
Normal file
@ -0,0 +1,21 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. For more details, visit
|
||||
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Enables namespacing of each library's R class so that its R class includes only the
|
||||
# resources declared in the library itself and none from the library's dependencies,
|
||||
# thereby reducing the size of the R class for that library
|
||||
android.nonTransitiveRClass=true
|
||||
22
gradle/libs.versions.toml
Normal file
@ -0,0 +1,22 @@
|
||||
[versions]
|
||||
agp = "8.7.2"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.3.0"
|
||||
espressoCore = "3.7.0"
|
||||
appcompat = "1.7.1"
|
||||
material = "1.13.0"
|
||||
activity = "1.11.0"
|
||||
constraintlayout = "2.2.1"
|
||||
|
||||
[libraries]
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
|
||||
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
8
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
#Thu Nov 20 16:49:11 CST 2025
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
251
gradlew
vendored
Normal file
@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# https://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.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
94
gradlew.bat
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
6
keystore.properties
Normal file
@ -0,0 +1,6 @@
|
||||
app_name=Wallpaper Exquisite
|
||||
package_name=com.wall.exquisite.wallpaper
|
||||
keystoreFile=test2/WallpaperExquisite.jks
|
||||
key_alias=WallpaperExquisitekey0
|
||||
key_store_password=654321
|
||||
key_password=654321
|
||||
27
settings.gradle.kts
Normal file
@ -0,0 +1,27 @@
|
||||
// settings.gradle.kts
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google {
|
||||
content {
|
||||
includeGroupByRegex("com\\.android.*")
|
||||
includeGroupByRegex("com\\.google.*")
|
||||
includeGroupByRegex("androidx.*")
|
||||
}
|
||||
}
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google() // 用于依赖
|
||||
mavenCentral()
|
||||
maven { url = uri("https://jitpack.io") }
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "My Application"
|
||||
include(":test2")
|
||||
1
test2/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
||||
BIN
test2/WallpaperExquisite.jks
Normal file
79
test2/build.gradle.kts
Normal file
@ -0,0 +1,79 @@
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
}
|
||||
val timestamp = SimpleDateFormat("MM_dd_HH_mm").format(Date())
|
||||
|
||||
android {
|
||||
namespace = "com.wall.exquisite.wallpaper"
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.wall.exquisite.wallpaper"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
setProperty("archivesBaseName","Wallpaper Exquisite_v"+versionName+"(${versionCode})_$timestamp")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
// viewBinding = true
|
||||
dataBinding=true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.appcompat)
|
||||
implementation(libs.material)
|
||||
implementation("androidx.activity:activity:1.10.0")
|
||||
implementation(libs.constraintlayout)
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.ext.junit)
|
||||
androidTestImplementation(libs.espresso.core)
|
||||
|
||||
// 图片加载库
|
||||
implementation("com.github.bumptech.glide:glide:4.16.0")
|
||||
annotationProcessor("com.github.bumptech.glide:compiler:4.16.0")
|
||||
|
||||
// JSON解析
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
|
||||
// 其他UI组件
|
||||
implementation("androidx.viewpager2:viewpager2:1.0.0")
|
||||
implementation("androidx.recyclerview:recyclerview:1.3.2")
|
||||
// 图片缩放库(必加,否则无法缩放大图)
|
||||
implementation("com.github.chrisbanes:PhotoView:2.3.0")
|
||||
|
||||
|
||||
implementation("androidx.core:core-ktx:1.12.0")
|
||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||
|
||||
// 新增:Glide Transform扩展(用于圆角变换)
|
||||
implementation ("jp.wasabeef:glide-transformations:4.3.0")
|
||||
|
||||
implementation ("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
|
||||
implementation(files("libs/TradPlusLibrary_11_25_15_02-release.aar"))
|
||||
implementation(files("libs/UpLoadLibrary_12_03_15_13-release.aar"))
|
||||
}
|
||||
29
test2/google-services.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "629391289236",
|
||||
"project_id": "wallpaperexquisite",
|
||||
"storage_bucket": "wallpaperexquisite.firebasestorage.app"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:629391289236:android:5249f587f7a2570465bd81",
|
||||
"android_client_info": {
|
||||
"package_name": "com.wall.exquisite.wallpaper"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyBdepb0MSzNF-ZO2uIQlCKyQ0Nrl5VvU5Y"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
BIN
test2/libs/TradPlusLibrary_11_25_15_02-release.aar
Normal file
BIN
test2/libs/UpLoadLibrary_12_03_15_13-release.aar
Normal file
31
test2/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# 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 *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
-keep class com.wall.exquisite.wallpaper.Wallpaper_Item { *; }
|
||||
|
||||
-keep class com.wall.exquisite.wallpaper.Urls { *; }
|
||||
-keep class com.wall.exquisite.wallpaper.User { *; }
|
||||
-keep class com.wall.exquisite.wallpaper.Wallpaper_Item { *; }
|
||||
-keep class com.google.gson.** { *; }
|
||||
-keepattributes Signature
|
||||
-keepattributes AnnotationDefault,RuntimeVisibleAnnotations
|
||||
-keep class com.google.gson.reflect.TypeToken { *; }
|
||||
-keep class * extends com.google.gson.reflect.TypeToken
|
||||
37
test2/release/output-metadata.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.wall.exquisite.wallpaper",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0",
|
||||
"outputFile": "Wallpaper Exquisite_v1.0(1)_12_05_14_18-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File",
|
||||
"baselineProfiles": [
|
||||
{
|
||||
"minApi": 28,
|
||||
"maxApi": 30,
|
||||
"baselineProfiles": [
|
||||
"baselineProfiles/1/Wallpaper Exquisite_v1.0(1)_12_05_14_18-release.dm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"minApi": 31,
|
||||
"maxApi": 2147483647,
|
||||
"baselineProfiles": [
|
||||
"baselineProfiles/0/Wallpaper Exquisite_v1.0(1)_12_05_14_18-release.dm"
|
||||
]
|
||||
}
|
||||
],
|
||||
"minSdkVersionForDexing": 24
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.ll.zz.nn", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
42
test2/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32" />
|
||||
|
||||
<application
|
||||
android:name=".WallpaperApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/applogo"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/applogo"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.MyApplication" >
|
||||
|
||||
<activity
|
||||
android:name=".StartuppageActivity"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".FirstMainActivity"
|
||||
android:exported="false"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".FullImageActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.AppCompat.NoActionBar" />
|
||||
<activity
|
||||
android:name=".CollectionActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
20703
test2/src/main/assets/Animals.json
Normal file
20703
test2/src/main/assets/Experimental.json
Normal file
20703
test2/src/main/assets/Featured.json
Normal file
20703
test2/src/main/assets/Film.json
Normal file
20702
test2/src/main/assets/Nature.json
Normal file
20702
test2/src/main/assets/Patterns.json
Normal file
20702
test2/src/main/assets/Street.json
Normal file
20702
test2/src/main/assets/Travel.json
Normal file
BIN
test2/src/main/assets/custfont.ttf
Normal file
@ -0,0 +1,88 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AnimalsFragment extends Fragment {
|
||||
|
||||
private RecyclerView rv4dImages;
|
||||
private AnimalsImageAdapter adapter;
|
||||
private List<Wallpaper_Item> wallpaperList;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_animals, container, false);
|
||||
|
||||
rv4dImages = view.findViewById(R.id.rv_4d_images);
|
||||
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
|
||||
gridLayoutManager.setAutoMeasureEnabled(true);
|
||||
rv4dImages.setLayoutManager(gridLayoutManager);
|
||||
|
||||
// rv4dImages.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
|
||||
// rv4dImages.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.HORIZONTAL));
|
||||
rv4dImages.setHasFixedSize(true);
|
||||
|
||||
|
||||
loadWallpaperData();
|
||||
|
||||
adapter = new AnimalsImageAdapter(getContext(), wallpaperList);
|
||||
rv4dImages.setAdapter(adapter);
|
||||
|
||||
|
||||
adapter.setOnItemClickListener((position, wallpaperItem) -> {
|
||||
|
||||
if (getContext() == null || wallpaperItem == null) {
|
||||
Toast.makeText(getContext(), "Data error", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String highResImageUrl = wallpaperItem.getUrls().getRegular();
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
highResImageUrl = wallpaperItem.getUrls().getFull();
|
||||
}
|
||||
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
Toast.makeText(getContext(), "NULL", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getContext(), FullImageActivity.class);
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_URL, highResImageUrl);
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_ID, wallpaperItem.getId());
|
||||
String description = wallpaperItem.getAlt_description();
|
||||
if (description == null || description.isEmpty()) {
|
||||
description = "Beautiful wallpapers";
|
||||
}
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_DESC, description);
|
||||
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void loadWallpaperData() {
|
||||
wallpaperList = JsonUtils.loadWallpapersFromJson(getContext(), "Animals.json");
|
||||
if (wallpaperList == null) {
|
||||
wallpaperList = new ArrayList<>();
|
||||
Toast.makeText(getContext(), "Failed to load wallpaper data", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import java.util.List;
|
||||
|
||||
public class AnimalsImageAdapter extends RecyclerView.Adapter<AnimalsImageAdapter.ImageViewHolder> {
|
||||
|
||||
private final Context mContext;
|
||||
private final List<Wallpaper_Item> mWallpaperList;
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
|
||||
// 关键修改:移除Glide的圆角变换,保留尺寸和其他配置
|
||||
private final RequestOptions glideOptions = new RequestOptions()
|
||||
.centerCrop()
|
||||
.placeholder(R.drawable.load_ing)
|
||||
.error(R.drawable.load_ing)
|
||||
.override(400, 600); // 保持统一尺寸,配合布局2:3比例
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(int position, Wallpaper_Item wallpaperItem);
|
||||
}
|
||||
|
||||
public AnimalsImageAdapter(Context context, List<Wallpaper_Item> wallpaperList) {
|
||||
this.mContext = context;
|
||||
this.mWallpaperList = wallpaperList;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.mOnItemClickListener = listener;
|
||||
}
|
||||
|
||||
static class ImageViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView ivItem4d;
|
||||
|
||||
public ImageViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
ivItem4d = itemView.findViewById(R.id.iv_item_4d);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_animals_image, parent, false);
|
||||
return new ImageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
|
||||
Wallpaper_Item wallpaperItem = mWallpaperList.get(position);
|
||||
|
||||
Glide.with(mContext)
|
||||
.load(wallpaperItem.getUrls().getSmall())
|
||||
.apply(glideOptions)
|
||||
.into(holder.ivItem4d);
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onItemClick(position, wallpaperItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mWallpaperList == null ? 0 : mWallpaperList.size();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.core.view.WindowInsetsControllerCompat;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectionActivity extends AppCompatActivity {
|
||||
|
||||
private RecyclerView rvFavoriteImages;
|
||||
private TextView tvEmpty;
|
||||
private AnimalsImageAdapter adapter;
|
||||
private CollectionManager favoriteManager;
|
||||
private List<Wallpaper_Item> favoriteList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_collection);
|
||||
|
||||
setupStatusBar();
|
||||
initViews();
|
||||
setupRecyclerView();
|
||||
loadFavoriteData();
|
||||
}
|
||||
|
||||
private void setupStatusBar() {
|
||||
Window window = getWindow();
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
WindowInsetsControllerCompat insetsController = WindowCompat.getInsetsController(window, window.getDecorView());
|
||||
if (insetsController != null) {
|
||||
insetsController.setAppearanceLightStatusBars(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getStatusBarHeight() {
|
||||
int result = 0;
|
||||
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
rvFavoriteImages = findViewById(R.id.rv_favorite_images);
|
||||
tvEmpty = findViewById(R.id.tv_empty);
|
||||
|
||||
findViewById(R.id.btn_back).setOnClickListener(v -> finish());
|
||||
|
||||
favoriteManager = new CollectionManager(this);
|
||||
favoriteList = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void setupRecyclerView() {
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
|
||||
rvFavoriteImages.setLayoutManager(gridLayoutManager);
|
||||
|
||||
adapter = new AnimalsImageAdapter(this, favoriteList);
|
||||
rvFavoriteImages.setAdapter(adapter);
|
||||
|
||||
adapter.setOnItemClickListener((position, wallpaperItem) -> {
|
||||
if (wallpaperItem == null) {
|
||||
Toast.makeText(CollectionActivity.this, "Data error", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String highResImageUrl = wallpaperItem.getUrls().getRegular();
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
highResImageUrl = wallpaperItem.getUrls().getFull();
|
||||
}
|
||||
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
Toast.makeText(CollectionActivity.this, "Image URL is empty", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(CollectionActivity.this, FullImageActivity.class);
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_URL, highResImageUrl);
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_ID, wallpaperItem.getId());
|
||||
|
||||
String description = wallpaperItem.getAlt_description();
|
||||
if (description == null || description.isEmpty()) {
|
||||
description = "Favorited wallpapers";
|
||||
}
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_DESC, description);
|
||||
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
private void loadFavoriteData() {
|
||||
favoriteList.clear();
|
||||
favoriteList.addAll(favoriteManager.getFavoriteItems());
|
||||
|
||||
Log.d("FavoriteActivity", "加载收藏数据,数量: " + favoriteList.size());
|
||||
|
||||
if (favoriteList.isEmpty()) {
|
||||
tvEmpty.setVisibility(View.VISIBLE);
|
||||
rvFavoriteImages.setVisibility(View.GONE);
|
||||
|
||||
} else {
|
||||
tvEmpty.setVisibility(View.GONE);
|
||||
rvFavoriteImages.setVisibility(View.VISIBLE);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
loadFavoriteData();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectionFragment extends Fragment {
|
||||
private RecyclerView rvFavoriteImages;
|
||||
private AnimalsImageAdapter adapter;
|
||||
private CollectionManager favoriteManager;
|
||||
private List<Wallpaper_Item> favoriteList;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_animals, container, false);
|
||||
|
||||
rvFavoriteImages = view.findViewById(R.id.rv_4d_images);
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
|
||||
rvFavoriteImages.setLayoutManager(gridLayoutManager);
|
||||
|
||||
favoriteManager = new CollectionManager(getContext());
|
||||
loadFavoriteData();
|
||||
|
||||
adapter = new AnimalsImageAdapter(getContext(), favoriteList);
|
||||
rvFavoriteImages.setAdapter(adapter);
|
||||
|
||||
adapter.setOnItemClickListener((position, wallpaperItem) -> {
|
||||
if (getContext() == null || wallpaperItem == null) {
|
||||
Toast.makeText(getContext(), "Data error", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String highResImageUrl = wallpaperItem.getUrls().getRegular();
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
highResImageUrl = wallpaperItem.getUrls().getFull();
|
||||
}
|
||||
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
Toast.makeText(getContext(), "NULL", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getContext(), FullImageActivity.class);
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_URL, highResImageUrl);
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_ID, wallpaperItem.getId());
|
||||
|
||||
String description = wallpaperItem.getAlt_description();
|
||||
if (description == null || description.isEmpty()) {
|
||||
description = "Favorited wallpapers";
|
||||
}
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_DESC, description);
|
||||
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void loadFavoriteData() {
|
||||
favoriteList = favoriteManager.getFavoriteItems();
|
||||
// 移除此处的Toast提示,避免重复触发
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
loadFavoriteData();
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,122 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CollectionManager {
|
||||
private static final String TAG = "FavoriteManager";
|
||||
private static final String PREF_NAME = "favorite_wallpapers";
|
||||
private static final String KEY_FAVORITE_IDS = "favorite_ids";
|
||||
private static final String KEY_FAVORITE_ITEMS = "favorite_items";
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
private Gson gson;
|
||||
|
||||
public CollectionManager(Context context) {
|
||||
sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
||||
gson = new Gson();
|
||||
}
|
||||
|
||||
// 添加收藏
|
||||
public void addFavorite(Wallpaper_Item item) {
|
||||
try {
|
||||
String itemId = item.getId();
|
||||
Log.d(TAG, "Add to Favorites: " + itemId);
|
||||
|
||||
|
||||
Set<String> favoriteIds = getFavoriteIds();
|
||||
favoriteIds.add(itemId);
|
||||
|
||||
List<Wallpaper_Item> favorites = getFavoriteItems();
|
||||
|
||||
|
||||
for (int i = favorites.size() - 1; i >= 0; i--) {
|
||||
if (favorites.get(i).getId().equals(itemId)) {
|
||||
favorites.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
favorites.add(item);
|
||||
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putStringSet(KEY_FAVORITE_IDS, new HashSet<>(favoriteIds)); // 创建新的HashSet避免并发问题
|
||||
editor.putString(KEY_FAVORITE_ITEMS, gson.toJson(favorites));
|
||||
editor.apply();
|
||||
|
||||
Log.d(TAG, "Added to Favorites: " + favorites.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to add to favorites", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 移除收藏
|
||||
public void removeFavorite(String itemId) {
|
||||
try {
|
||||
Log.d(TAG, "Unfavorite: " + itemId);
|
||||
|
||||
|
||||
Set<String> favoriteIds = getFavoriteIds();
|
||||
favoriteIds.remove(itemId);
|
||||
|
||||
|
||||
List<Wallpaper_Item> favorites = getFavoriteItems();
|
||||
for (int i = favorites.size() - 1; i >= 0; i--) {
|
||||
if (favorites.get(i).getId().equals(itemId)) {
|
||||
favorites.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putStringSet(KEY_FAVORITE_IDS, new HashSet<>(favoriteIds));
|
||||
editor.putString(KEY_FAVORITE_ITEMS, gson.toJson(favorites));
|
||||
editor.apply();
|
||||
|
||||
Log.d(TAG, "Unfavorited successfully: " + favorites.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to unfavorite", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否已收藏
|
||||
public boolean isFavorite(String itemId) {
|
||||
Set<String> favoriteIds = getFavoriteIds();
|
||||
boolean isFav = favoriteIds.contains(itemId);
|
||||
Log.d(TAG, "检查收藏状态: " + itemId + " -> " + isFav);
|
||||
return isFav;
|
||||
}
|
||||
|
||||
// 获取所有收藏的ID
|
||||
public Set<String> getFavoriteIds() {
|
||||
Set<String> ids = sharedPreferences.getStringSet(KEY_FAVORITE_IDS, new HashSet<>());
|
||||
Log.d(TAG, "获取收藏ID数量: " + ids.size());
|
||||
return new HashSet<>(ids); // 返回新的HashSet避免并发问题
|
||||
}
|
||||
|
||||
// 获取所有收藏项
|
||||
public List<Wallpaper_Item> getFavoriteItems() {
|
||||
try {
|
||||
String json = sharedPreferences.getString(KEY_FAVORITE_ITEMS, "[]");
|
||||
Type listType = new TypeToken<List<Wallpaper_Item>>(){}.getType();
|
||||
List<Wallpaper_Item> items = gson.fromJson(json, listType);
|
||||
if (items == null) {
|
||||
items = new ArrayList<>();
|
||||
}
|
||||
Log.d(TAG, "获取收藏项数量: " + items.size());
|
||||
return items;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "获取收藏项失败", e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
|
||||
public class FirstMainActivity extends AppCompatActivity {
|
||||
|
||||
// 关键修改:颜色定义调整
|
||||
private final int SELECTED_TEXT_ICON_COLOR = Color.parseColor("#98F5F9"); // 选中:图标+文字#98F5F9
|
||||
private final int UNSELECTED_TEXT_ICON_COLOR = Color.DKGRAY; // 未选中:深灰色图标+文字
|
||||
private final int TAB_BG_COLOR = Color.TRANSPARENT; // 背景透明(不显示选中背景色)
|
||||
|
||||
// 外层Tab的文字和图标资源
|
||||
private final String[] outerTabTexts = {"Home", "Setting"};
|
||||
private final int[] outerTabIcons = {R.drawable.home2, R.drawable.setting2};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_main2);
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
int systemBarsTop = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top;
|
||||
int systemBarsBottom = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom;
|
||||
v.setPadding(0, systemBarsTop, 0, systemBarsBottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
TabLayout outerTabLayout = findViewById(R.id.outerTabLayout);
|
||||
ViewPager2 outerViewPager = findViewById(R.id.outerViewPager);
|
||||
|
||||
Outer_TabAdapter outerTabAdapter = new Outer_TabAdapter(this);
|
||||
outerViewPager.setAdapter(outerTabAdapter);
|
||||
|
||||
// 自定义布局绑定外层Tab(布局不变,只改样式逻辑)
|
||||
new TabLayoutMediator(outerTabLayout, outerViewPager, (tab, position) -> {
|
||||
View customTabView = LayoutInflater.from(this)
|
||||
.inflate(R.layout.custom_outertab, null);
|
||||
|
||||
LinearLayout tabRoot = customTabView.findViewById(R.id.tab_root);
|
||||
ImageView tabIcon = customTabView.findViewById(R.id.tab_icon);
|
||||
TextView tabText = customTabView.findViewById(R.id.tab_text);
|
||||
|
||||
// 设置文字和图标
|
||||
tabText.setText(outerTabTexts[position]);
|
||||
tabIcon.setImageResource(outerTabIcons[position]);
|
||||
|
||||
// 强制Tab均匀分布(保留原逻辑)
|
||||
ViewGroup.LayoutParams params = customTabView.getLayoutParams();
|
||||
if (params == null) {
|
||||
params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
} else {
|
||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
}
|
||||
customTabView.setLayoutParams(params);
|
||||
|
||||
// 初始化样式:默认选中第一个Tab
|
||||
tabRoot.setBackgroundColor(TAB_BG_COLOR); // 所有Tab背景都透明
|
||||
if (position == 0) {
|
||||
// 选中:图标+文字#98F5F9
|
||||
tabText.setTextColor(SELECTED_TEXT_ICON_COLOR);
|
||||
tabIcon.setColorFilter(SELECTED_TEXT_ICON_COLOR);
|
||||
} else {
|
||||
// 未选中:深灰色
|
||||
tabText.setTextColor(UNSELECTED_TEXT_ICON_COLOR);
|
||||
tabIcon.setColorFilter(UNSELECTED_TEXT_ICON_COLOR);
|
||||
}
|
||||
|
||||
tab.setCustomView(customTabView);
|
||||
}).attach();
|
||||
|
||||
// 监听Tab切换,更新图标+文字颜色(背景不变)
|
||||
outerTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
updateTabStyle(tab, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
updateTabStyle(tab, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {}
|
||||
});
|
||||
}
|
||||
|
||||
// 封装样式更新逻辑(只改文字和图标颜色,背景固定透明)
|
||||
private void updateTabStyle(TabLayout.Tab tab, boolean isSelected) {
|
||||
View customView = tab.getCustomView();
|
||||
if (customView == null) return;
|
||||
|
||||
ImageView tabIcon = customView.findViewById(R.id.tab_icon);
|
||||
TextView tabText = customView.findViewById(R.id.tab_text);
|
||||
|
||||
if (isSelected) {
|
||||
// 选中:图标+文字#98F5F9
|
||||
tabText.setTextColor(SELECTED_TEXT_ICON_COLOR);
|
||||
tabIcon.setColorFilter(SELECTED_TEXT_ICON_COLOR);
|
||||
} else {
|
||||
// 未选中:深灰色
|
||||
tabText.setTextColor(UNSELECTED_TEXT_ICON_COLOR);
|
||||
tabIcon.setColorFilter(UNSELECTED_TEXT_ICON_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,660 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.core.view.WindowInsetsControllerCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.DecodeFormat;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.wall.exquisite.wallpaper.databinding.ActivityFullImageBinding;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
// 壁纸设置类型常量
|
||||
interface WallpaperType {
|
||||
int TYPE_HOME = 1; // 桌面
|
||||
int TYPE_LOCK = 2; // 锁屏
|
||||
int TYPE_BOTH = 3; // 桌面+锁屏
|
||||
}
|
||||
|
||||
public class FullImageActivity extends AppCompatActivity implements WallpaperType {
|
||||
// 传递参数Key
|
||||
public static final String EXTRA_IMAGE_URL = "extra_image_url";
|
||||
public static final String EXTRA_IMAGE_ID = "extra_image_id";
|
||||
public static final String EXTRA_IMAGE_DESC = "extra_image_desc";
|
||||
|
||||
private ActivityFullImageBinding binding;
|
||||
private String imageUrl;
|
||||
private String imageId;
|
||||
private String imageDesc;
|
||||
private File tempFile;
|
||||
private WallpaperManager wallpaperManager;
|
||||
private CollectionManager favoriteManager;
|
||||
private int screenWidth; // 屏幕宽度
|
||||
private int screenHeight; // 屏幕高度(包含状态栏/导航栏,适配全面屏)
|
||||
private RequestManager glideRequestManager; // Glide生命周期管理
|
||||
private boolean isActivityDestroyed = false; // 标记Activity是否已销毁
|
||||
private Thread downloadThread; // 下载线程引用(用于销毁时中断)
|
||||
private Thread setWallpaperThread; // 设置壁纸线程引用(用于销毁时中断)
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityFullImageBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
// 1. 初始化Glide RequestManager,绑定Activity生命周期(避免内存泄漏)
|
||||
glideRequestManager = Glide.with(this);
|
||||
|
||||
// 沉浸式全屏
|
||||
initFullScreen();
|
||||
// 获取屏幕尺寸(用于壁纸精准缩放)
|
||||
getScreenSize();
|
||||
// 初始化管理器
|
||||
wallpaperManager = WallpaperManager.getInstance(this);
|
||||
favoriteManager = new CollectionManager(this);
|
||||
|
||||
// 获取传递的参数
|
||||
getIntentData();
|
||||
// 加载图片(使用统一的Glide管理器)
|
||||
loadImage(imageUrl);
|
||||
// 初始化点击事件
|
||||
initClick();
|
||||
// 初始化点赞状态
|
||||
initFavoriteState();
|
||||
}
|
||||
|
||||
/**
|
||||
* 沉浸式全屏配置(隐藏状态栏/导航栏,支持滑动显示)
|
||||
*/
|
||||
private void initFullScreen() {
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().hide();
|
||||
}
|
||||
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
|
||||
WindowInsetsControllerCompat insetsController = WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
|
||||
if (insetsController != null) {
|
||||
insetsController.hide(WindowInsetsCompat.Type.statusBars() | WindowInsetsCompat.Type.navigationBars());
|
||||
insetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕真实尺寸(包含状态栏/导航栏,避免壁纸缩放后被裁剪)
|
||||
*/
|
||||
private void getScreenSize() {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// Android 11+ 直接获取真实屏幕尺寸
|
||||
getDisplay().getRealMetrics(metrics);
|
||||
} else {
|
||||
// Android 11以下 通过WindowManager获取
|
||||
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
||||
}
|
||||
screenWidth = metrics.widthPixels;
|
||||
screenHeight = metrics.heightPixels;
|
||||
Log.d("ScreenSize", "宽:" + screenWidth + ",高:" + screenHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收从上个页面传递的参数(图片URL、ID、描述)
|
||||
*/
|
||||
private void getIntentData() {
|
||||
Intent intent = getIntent();
|
||||
imageUrl = intent.getStringExtra(EXTRA_IMAGE_URL);
|
||||
imageId = intent.getStringExtra(EXTRA_IMAGE_ID);
|
||||
imageDesc = intent.getStringExtra(EXTRA_IMAGE_DESC);
|
||||
|
||||
// 设置图片描述(无描述时显示应用名称)
|
||||
if (imageDesc != null && !imageDesc.isEmpty()) {
|
||||
binding.tvContent.setText(imageDesc);
|
||||
} else {
|
||||
binding.tvContent.setText(getString(R.string.app_name));
|
||||
}
|
||||
|
||||
// 初始化临时文件(应用私有目录,无需存储权限)
|
||||
if (imageId == null) {
|
||||
imageId = "wallpaper_" + System.currentTimeMillis();
|
||||
}
|
||||
tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), imageId + ".jpg");
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载图片(优先加载本地临时文件,无则从网络加载)
|
||||
*/
|
||||
private void loadImage(String imageUrl) {
|
||||
if (imageUrl == null || imageUrl.isEmpty()) {
|
||||
Toast.makeText(this, "Image URL is empty, cannot load", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// Glide加载配置(优化性能,设置占位图/错误图)
|
||||
RequestOptions options = new RequestOptions()
|
||||
.format(DecodeFormat.PREFER_RGB_565) // 节省内存
|
||||
.placeholder(R.drawable.loading) // 加载中占位图
|
||||
.error(R.drawable.load_ing); // 加载失败图
|
||||
|
||||
// 检查临时文件是否存在(存在则加载本地文件)
|
||||
if (tempFile.exists()) {
|
||||
glideRequestManager
|
||||
.load(tempFile)
|
||||
.apply(options)
|
||||
.transition(DrawableTransitionOptions.withCrossFade(500)) // 淡入动画
|
||||
.into(binding.imageviewPreview);
|
||||
} else {
|
||||
// 从网络加载图片
|
||||
glideRequestManager
|
||||
.asDrawable()
|
||||
.load(imageUrl)
|
||||
.apply(options)
|
||||
.skipMemoryCache(true) // 跳过内存缓存(避免重复图片占用内存)
|
||||
.transition(DrawableTransitionOptions.withCrossFade(500))
|
||||
.listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||
Log.e("FullImage", "Failed to load image:" + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.centerCrop() // 居中裁剪(适配ImageView)
|
||||
.into(binding.imageviewPreview);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化点赞状态(从FavoriteManager读取是否已收藏)
|
||||
*/
|
||||
private void initFavoriteState() {
|
||||
if (imageId == null) return;
|
||||
boolean isFavorited = favoriteManager.isFavorite(imageId);
|
||||
binding.imageFavorite.setSelected(isFavorited);
|
||||
binding.imageFavorite.setImageResource(isFavorited ? R.drawable.like_red : R.drawable.like);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化所有点击事件(返回、下载、设置壁纸、点赞)
|
||||
*/
|
||||
private void initClick() {
|
||||
// 返回按钮(关闭当前页面)
|
||||
binding.imageviewBack.setOnClickListener(v -> finish());
|
||||
|
||||
// 下载按钮(保存图片到相册,无需权限)
|
||||
binding.layoutDownload.setOnClickListener(v -> startDownload());
|
||||
|
||||
// 设置壁纸按钮(弹出选择弹窗)
|
||||
binding.buttonSet1.setOnClickListener(v -> showWallpaperTypeDialog());
|
||||
|
||||
// 点赞按钮(收藏/取消收藏)
|
||||
binding.imageFavorite.setOnClickListener(v -> toggleFavorite());
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换收藏状态(添加/移除收藏)
|
||||
*/
|
||||
private void toggleFavorite() {
|
||||
if (imageId == null) {
|
||||
Toast.makeText(this, "Cannot add to favorites", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建收藏实体类
|
||||
Wallpaper_Item item = new Wallpaper_Item();
|
||||
item.setId(imageId);
|
||||
item.setAlt_description(imageDesc);
|
||||
|
||||
Urls urls = new Urls();
|
||||
urls.setRegular(imageUrl);
|
||||
urls.setSmall(imageUrl);
|
||||
urls.setFull(imageUrl);
|
||||
item.setUrls(urls);
|
||||
|
||||
// 检查当前是否已收藏
|
||||
boolean isFavorited = favoriteManager.isFavorite(imageId);
|
||||
if (isFavorited) {
|
||||
// 取消收藏
|
||||
favoriteManager.removeFavorite(imageId);
|
||||
binding.imageFavorite.setSelected(false);
|
||||
binding.imageFavorite.setImageResource(R.drawable.like);
|
||||
Toast.makeText(this, "Cancel collection", Toast.LENGTH_SHORT).show();
|
||||
Log.d("FullImageActivity", "Cancel collection: " + imageId);
|
||||
} else {
|
||||
// 添加收藏
|
||||
favoriteManager.addFavorite(item);
|
||||
binding.imageFavorite.setSelected(true);
|
||||
binding.imageFavorite.setImageResource(R.drawable.like_red);
|
||||
Toast.makeText(this, "Favorited", Toast.LENGTH_SHORT).show();
|
||||
Log.d("FullImageActivity", "Favorited: " + imageId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载图片到相册(通过MediaStore,无需存储权限)
|
||||
*/
|
||||
private void startDownload() {
|
||||
// 显示加载进度条,隐藏下载按钮
|
||||
showLoading(binding.pbDownload, binding.imageDownload, true);
|
||||
|
||||
// 保存线程引用,便于销毁时中断
|
||||
downloadThread = new Thread(() -> {
|
||||
// 检查Activity是否已销毁,避免无效执行
|
||||
if (isActivityDestroyed) {
|
||||
runOnUiThread(() -> showLoading(binding.pbDownload, binding.imageDownload, false));
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bitmap = null;
|
||||
try {
|
||||
// 检查线程是否被中断(Activity销毁时触发)
|
||||
if (Thread.currentThread().isInterrupted()) throw new InterruptedException();
|
||||
|
||||
// 1. 从网络下载图片
|
||||
URL url = new URL(imageUrl);
|
||||
URLConnection conn = url.openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
bitmap = BitmapFactory.decodeStream(is);
|
||||
is.close();
|
||||
|
||||
// 检查图片是否解码成功
|
||||
if (bitmap == null) {
|
||||
throw new IOException("Failed to decode image");
|
||||
}
|
||||
|
||||
// 再次检查Activity状态和线程中断状态
|
||||
if (isActivityDestroyed || Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
// 2. 通过MediaStore写入相册(Android 10+ 适配)
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MediaStore.Images.Media.DISPLAY_NAME, imageId + ".jpg"); // 文件名
|
||||
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); // 文件类型
|
||||
values.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_DCIM + "/Wallpaper"); // 相册路径(DCIM/Wallpaper)
|
||||
values.put(MediaStore.Images.Media.WIDTH, bitmap.getWidth());
|
||||
values.put(MediaStore.Images.Media.HEIGHT, bitmap.getHeight());
|
||||
|
||||
// Android 10+ 标记为待处理(避免相册立即扫描)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
values.put(MediaStore.Images.Media.IS_PENDING, 1);
|
||||
}
|
||||
|
||||
// 插入到媒体库,获取图片Uri
|
||||
Uri imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||
if (imageUri == null) {
|
||||
throw new IOException("Failed to import to media library");
|
||||
}
|
||||
|
||||
// 写入图片数据到Uri
|
||||
try (OutputStream os = getContentResolver().openOutputStream(imageUri)) {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
|
||||
}
|
||||
|
||||
// Android 10+ 标记为完成(允许相册扫描)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
values.clear();
|
||||
values.put(MediaStore.Images.Media.IS_PENDING, 0);
|
||||
getContentResolver().update(imageUri, values, null, null);
|
||||
}
|
||||
|
||||
// 保存临时文件(用于后续设置壁纸,无需重复下载)
|
||||
saveTempFile(bitmap);
|
||||
|
||||
// 主线程更新UI(下载成功)
|
||||
if (!isActivityDestroyed && !Thread.currentThread().isInterrupted()) {
|
||||
runOnUiThread(() -> {
|
||||
showLoading(binding.pbDownload, binding.imageDownload, false);
|
||||
Toast.makeText(this, "Download successful. Saved to your photo library", Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
// 线程被中断(Activity销毁),直接退出,不提示错误
|
||||
Log.d("FullImage", "Download thread interrupted");
|
||||
runOnUiThread(() -> showLoading(binding.pbDownload, binding.imageDownload, false));
|
||||
} catch (Exception e) {
|
||||
// 其他异常(下载失败)
|
||||
e.printStackTrace();
|
||||
if (!isActivityDestroyed) {
|
||||
runOnUiThread(() -> {
|
||||
showLoading(binding.pbDownload, binding.imageDownload, false);
|
||||
Toast.makeText(FullImageActivity.this, "Download failed:" + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
// 回收Bitmap,避免内存泄漏
|
||||
if (bitmap != null && !bitmap.isRecycled()) {
|
||||
bitmap.recycle();
|
||||
}
|
||||
}
|
||||
});
|
||||
downloadThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存临时文件到应用私有目录(用于设置壁纸,无需权限)
|
||||
*/
|
||||
private void saveTempFile(Bitmap bitmap) throws IOException {
|
||||
if (!tempFile.getParentFile().exists()) {
|
||||
tempFile.getParentFile().mkdirs(); // 创建父目录(不存在则创建)
|
||||
}
|
||||
try (OutputStream os = new java.io.FileOutputStream(tempFile)) {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os); // 100表示不压缩
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示壁纸设置类型弹窗(桌面/锁屏/两者)
|
||||
*/
|
||||
private void showWallpaperTypeDialog() {
|
||||
// 加载自定义弹窗布局
|
||||
View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_wallpapertype, null);
|
||||
|
||||
// 获取弹窗中的三个选项
|
||||
LinearLayout layoutHome = dialogView.findViewById(R.id.layout_ic_home);
|
||||
LinearLayout layoutLock = dialogView.findViewById(R.id.layout_ic_lock);
|
||||
LinearLayout layoutBoth = dialogView.findViewById(R.id.layout_ic_both);
|
||||
|
||||
// 创建弹窗(设置透明背景,避免遮挡圆角)
|
||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
.setView(dialogView)
|
||||
.create();
|
||||
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
||||
|
||||
// 绑定选项点击事件
|
||||
layoutHome.setOnClickListener(v -> {
|
||||
setWallpaper(TYPE_HOME);
|
||||
dialog.dismiss();
|
||||
});
|
||||
layoutLock.setOnClickListener(v -> {
|
||||
setWallpaper(TYPE_LOCK);
|
||||
dialog.dismiss();
|
||||
});
|
||||
layoutBoth.setOnClickListener(v -> {
|
||||
setWallpaper(TYPE_BOTH);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
// 显示弹窗并设置宽度为全屏
|
||||
dialog.show();
|
||||
Window window = dialog.getWindow();
|
||||
if (window != null) {
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
window.setAttributes(params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置壁纸(根据选择的类型设置桌面/锁屏/两者)
|
||||
*/
|
||||
private void setWallpaper(int type) {
|
||||
// 显示加载进度条,隐藏设置按钮
|
||||
showLoading(binding.pbSet1, binding.buttonSet1, true);
|
||||
|
||||
final int finalType = type; // Lambda表达式中使用的变量需为final
|
||||
|
||||
// 保存线程引用,便于销毁时中断
|
||||
setWallpaperThread = new Thread(() -> {
|
||||
// 检查Activity是否已销毁
|
||||
if (isActivityDestroyed) {
|
||||
runOnUiThread(() -> showLoading(binding.pbSet1, binding.buttonSet1, false));
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap originBitmap = null;
|
||||
Bitmap scaledBitmap = null;
|
||||
try {
|
||||
// 检查线程是否被中断
|
||||
if (Thread.currentThread().isInterrupted()) throw new InterruptedException();
|
||||
|
||||
if (!tempFile.exists()) {
|
||||
// 临时文件不存在,先从网络下载
|
||||
URL url = new URL(imageUrl);
|
||||
URLConnection conn = url.openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
originBitmap = BitmapFactory.decodeStream(is);
|
||||
is.close();
|
||||
|
||||
if (originBitmap == null) {
|
||||
throw new IOException("Failed to decode image");
|
||||
}
|
||||
|
||||
// 检查Activity状态和线程中断状态
|
||||
if (isActivityDestroyed || Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
// 缩放图片到屏幕尺寸(避免系统自动裁剪)
|
||||
scaledBitmap = scaleBitmapToScreen(originBitmap);
|
||||
// 保存缩放后的临时文件
|
||||
saveTempFile(scaledBitmap);
|
||||
} else {
|
||||
// 临时文件存在,直接读取并缩放
|
||||
originBitmap = BitmapFactory.decodeFile(tempFile.getAbsolutePath());
|
||||
if (originBitmap == null) {
|
||||
throw new IOException("Failed to read temp file");
|
||||
}
|
||||
|
||||
// 检查Activity状态和线程中断状态
|
||||
if (isActivityDestroyed || Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
// 缩放图片到屏幕尺寸
|
||||
scaledBitmap = scaleBitmapToScreen(originBitmap);
|
||||
// 覆盖保存缩放后的图片
|
||||
saveTempFile(scaledBitmap);
|
||||
}
|
||||
|
||||
// 检查状态后,执行设置壁纸操作
|
||||
if (!isActivityDestroyed && !Thread.currentThread().isInterrupted()) {
|
||||
setWallpaperFromFile(tempFile, finalType);
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
// 线程被中断,直接退出
|
||||
Log.d("FullImage", "Set wallpaper thread interrupted");
|
||||
runOnUiThread(() -> showLoading(binding.pbSet1, binding.buttonSet1, false));
|
||||
} catch (Exception e) {
|
||||
// 其他异常(设置失败)
|
||||
e.printStackTrace();
|
||||
if (!isActivityDestroyed) {
|
||||
runOnUiThread(() -> {
|
||||
showLoading(binding.pbSet1, binding.buttonSet1, false);
|
||||
Toast.makeText(FullImageActivity.this, "Setup failed", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
// 回收所有Bitmap,避免内存泄漏
|
||||
if (originBitmap != null && !originBitmap.isRecycled()) {
|
||||
originBitmap.recycle();
|
||||
}
|
||||
if (scaledBitmap != null && !scaledBitmap.isRecycled()) {
|
||||
scaledBitmap.recycle();
|
||||
}
|
||||
}
|
||||
});
|
||||
setWallpaperThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片缩放适配屏幕(保持比例,避免裁剪,适配全面屏)
|
||||
*/
|
||||
private Bitmap scaleBitmapToScreen(Bitmap originBitmap) {
|
||||
if (originBitmap == null) return null;
|
||||
|
||||
// 原始图片尺寸
|
||||
int originWidth = originBitmap.getWidth();
|
||||
int originHeight = originBitmap.getHeight();
|
||||
Log.d("ScaleBitmap", "原始宽:" + originWidth + ",原始高:" + originHeight);
|
||||
|
||||
// 计算缩放比例(取最大比例,确保图片覆盖屏幕,无黑边)
|
||||
float scaleX = (float) screenWidth / originWidth;
|
||||
float scaleY = (float) screenHeight / originHeight;
|
||||
float scale = Math.max(scaleX, scaleY);
|
||||
|
||||
// 缩放后的尺寸
|
||||
int scaledWidth = (int) (originWidth * scale);
|
||||
int scaledHeight = (int) (originHeight * scale);
|
||||
Log.d("ScaleBitmap", "缩放后宽:" + scaledWidth + ",缩放后高:" + scaledHeight);
|
||||
|
||||
// 执行缩放(true表示使用双线性过滤,保持图片清晰)
|
||||
Bitmap scaledBitmap = Bitmap.createScaledBitmap(originBitmap, scaledWidth, scaledHeight, true);
|
||||
|
||||
// 裁剪超出屏幕的部分(居中裁剪,确保尺寸与屏幕一致)
|
||||
if (scaledWidth > screenWidth || scaledHeight > screenHeight) {
|
||||
int cropX = (scaledWidth - screenWidth) / 2;
|
||||
int cropY = (scaledHeight - screenHeight) / 2;
|
||||
scaledBitmap = Bitmap.createBitmap(
|
||||
scaledBitmap,
|
||||
cropX, // 裁剪起始X坐标(居中)
|
||||
cropY, // 裁剪起始Y坐标(居中)
|
||||
screenWidth, // 目标宽度(屏幕宽度)
|
||||
screenHeight // 目标高度(屏幕高度)
|
||||
);
|
||||
Log.d("ScaleBitmap", "裁剪后宽:" + scaledBitmap.getWidth() + ",裁剪后高:" + scaledBitmap.getHeight());
|
||||
}
|
||||
|
||||
return scaledBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从临时文件设置壁纸(适配Android 7.0+ 单独设置桌面/锁屏)
|
||||
*/
|
||||
private void setWallpaperFromFile(File file, int type) {
|
||||
try {
|
||||
InputStream is = new java.io.FileInputStream(file);
|
||||
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
|
||||
|
||||
switch (type) {
|
||||
case TYPE_HOME:
|
||||
// 设置桌面壁纸(Android 7.0+ 适配)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
wallpaperManager.setStream(is, null, true, WallpaperManager.FLAG_SYSTEM);
|
||||
} else {
|
||||
wallpaperManager.setStream(is);
|
||||
}
|
||||
break;
|
||||
case TYPE_LOCK:
|
||||
// 设置锁屏壁纸(Android 7.0+ 才支持)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
wallpaperManager.setStream(is, null, true, WallpaperManager.FLAG_LOCK);
|
||||
} else {
|
||||
// Android 7.0以下提示不支持
|
||||
runOnUiThread(() -> Toast.makeText(this, "Android 7.0+ supports lock screen wallpaper setting", Toast.LENGTH_SHORT).show());
|
||||
wallpaperManager.setStream(is);
|
||||
}
|
||||
break;
|
||||
case TYPE_BOTH:
|
||||
// 设置桌面+锁屏壁纸
|
||||
wallpaperManager.setStream(is);
|
||||
break;
|
||||
}
|
||||
is.close(); // 关闭输入流,释放资源
|
||||
|
||||
// 设置成功,更新UI
|
||||
runOnUiThread(() -> {
|
||||
showLoading(binding.pbSet1, binding.buttonSet1, false);
|
||||
Toast.makeText(this, "Wallpaper Updated", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 设置失败,提示用户
|
||||
runOnUiThread(() -> {
|
||||
showLoading(binding.pbSet1, binding.buttonSet1, false);
|
||||
Toast.makeText(this, "Wallpaper setup failed:" + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示/隐藏加载进度条(统一控制加载状态)
|
||||
*/
|
||||
private void showLoading(ProgressBar pb, View view, boolean show) {
|
||||
pb.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
view.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 窗口焦点变化时,重新设置全屏(避免导航栏/状态栏重新显示)
|
||||
*/
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus) {
|
||||
initFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activity销毁时,释放所有资源(避免内存泄漏和线程孤儿运行)
|
||||
*/
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// 标记Activity已销毁
|
||||
isActivityDestroyed = true;
|
||||
|
||||
// 中断所有异步线程(避免线程持有Activity引用)
|
||||
if (downloadThread != null && downloadThread.isAlive()) {
|
||||
downloadThread.interrupt();
|
||||
}
|
||||
if (setWallpaperThread != null && setWallpaperThread.isAlive()) {
|
||||
setWallpaperThread.interrupt();
|
||||
}
|
||||
|
||||
// 取消Glide所有未完成的请求(避免Glide持有ImageView引用)
|
||||
glideRequestManager.clear(binding.imageviewPreview);
|
||||
|
||||
// 回收ImageView的Drawable资源
|
||||
Drawable drawable = binding.imageviewPreview.getDrawable();
|
||||
if (drawable != null) {
|
||||
drawable.setCallback(null); // 解除Drawable与ImageView的关联
|
||||
}
|
||||
binding.imageviewPreview.setImageDrawable(null); // 清空ImageView
|
||||
|
||||
// 释放ViewBinding引用(避免内存泄漏)
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
|
||||
public class HomePageFragment extends Fragment {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_home, container, false);
|
||||
|
||||
TabLayout innerTabLayout = view.findViewById(R.id.innerTabLayout);
|
||||
ViewPager2 innerViewPager = view.findViewById(R.id.innerViewPager);
|
||||
|
||||
Inner_TabAdapter innerTabAdapter = new Inner_TabAdapter(requireActivity());
|
||||
innerViewPager.setAdapter(innerTabAdapter);
|
||||
|
||||
String[] innerTabTexts = {"Animals", "Nature", "Patterns"};
|
||||
// 定义颜色变量,方便统一管理
|
||||
int selectedColor = getResources().getColor(android.R.color.white);
|
||||
int unselectedColor = android.graphics.Color.parseColor("#98F5F9");
|
||||
|
||||
new TabLayoutMediator(innerTabLayout, innerViewPager, (tab, position) -> {
|
||||
View customTabView = LayoutInflater.from(getContext())
|
||||
.inflate(R.layout.custom_innertab, null);
|
||||
|
||||
TextView tabText = customTabView.findViewById(R.id.tab_text);
|
||||
View tabDivider = customTabView.findViewById(R.id.tab_divider);
|
||||
|
||||
tabText.setText(innerTabTexts[position]);
|
||||
// 初始化时设置颜色:第一个Tab默认选中(白色),其他未选中(#98F5F9)
|
||||
tabText.setTextColor(position == 0 ? selectedColor : unselectedColor);
|
||||
|
||||
if (position == innerTabTexts.length - 1) {
|
||||
tabDivider.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
ViewGroup.LayoutParams params = customTabView.getLayoutParams();
|
||||
if (params == null) {
|
||||
params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
} else {
|
||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
}
|
||||
customTabView.setLayoutParams(params);
|
||||
|
||||
tab.setCustomView(customTabView);
|
||||
}).attach();
|
||||
|
||||
// 选中状态监听(切换时更新颜色)
|
||||
innerTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
TextView tabText = tab.getCustomView().findViewById(R.id.tab_text);
|
||||
tabText.setTextColor(selectedColor); // 选中:白色
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
TextView tabText = tab.getCustomView().findViewById(R.id.tab_text);
|
||||
tabText.setTextColor(unselectedColor); // 未选中:#98F5F9
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {}
|
||||
});
|
||||
|
||||
// 不需要额外调用 selectTab,因为在 TabLayoutMediator 中已经初始化了第一个Tab的颜色
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
// 内层 4D/LIVE/4K 适配器
|
||||
public class Inner_TabAdapter extends FragmentStateAdapter {
|
||||
public Inner_TabAdapter(@NonNull FragmentActivity fragmentActivity) {
|
||||
super(fragmentActivity);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
return new AnimalsFragment();
|
||||
case 1:
|
||||
return new PatternsFragment();
|
||||
case 2:
|
||||
return new NatureFragment();
|
||||
default:
|
||||
return new AnimalsFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
public static List<Wallpaper_Item> loadWallpapersFromJson(Context context, String fileName) {
|
||||
try {
|
||||
String jsonString = loadJSONFromAsset(context, fileName);
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<List<Wallpaper_Item>>(){}.getType();
|
||||
List<Wallpaper_Item> items = gson.fromJson(jsonString, listType);
|
||||
|
||||
// 新增:确保每个item都有有效的ID
|
||||
if (items != null) {
|
||||
for (Wallpaper_Item item : items) {
|
||||
ensureItemHasId(item);
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
} catch (Exception e) {
|
||||
Log.e("JsonUtils", "Error loading JSON from " + fileName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String loadJSONFromAsset(Context context, String fileName) {
|
||||
String json;
|
||||
try {
|
||||
InputStream is = context.getAssets().open(fileName);
|
||||
int size = is.available();
|
||||
byte[] buffer = new byte[size];
|
||||
is.read(buffer);
|
||||
is.close();
|
||||
json = new String(buffer, "UTF-8");
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
private static void ensureItemHasId(Wallpaper_Item item) {
|
||||
if (item != null && item.getUrls() != null) {
|
||||
// 如果item没有设置id,或者id为空,则生成一个
|
||||
try {
|
||||
// 使用反射检查id字段是否为空
|
||||
java.lang.reflect.Field idField = Wallpaper_Item.class.getDeclaredField("id");
|
||||
idField.setAccessible(true);
|
||||
String currentId = (String) idField.get(item);
|
||||
|
||||
if (currentId == null || currentId.isEmpty()) {
|
||||
// 使用regular URL的hashCode作为唯一ID
|
||||
String regularUrl = item.getUrls().getRegular();
|
||||
if (regularUrl != null) {
|
||||
String generatedId = "img_" + Math.abs(regularUrl.hashCode());
|
||||
idField.set(item, generatedId);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("JsonUtils", "Error ensuring item ID", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
test2/src/main/java/com/wall/exquisite/wallpaper/MyData.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
// 移除 ObjectBox 导入
|
||||
// import io.objectbox.annotation.Entity;
|
||||
// import io.objectbox.annotation.Id;
|
||||
|
||||
public class MyData {
|
||||
// 移除 ObjectBox 注解
|
||||
// @Id
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
// 构造函数、getter、setter 方法...
|
||||
public MyData() {
|
||||
}
|
||||
|
||||
public MyData(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NatureFragment extends Fragment {
|
||||
|
||||
private RecyclerView rv4kImages;
|
||||
private NatureImageAdapter adapter;
|
||||
private List<Wallpaper_Item> wallpaperList;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_nature, container, false);
|
||||
|
||||
rv4kImages = view.findViewById(R.id.rv_4k_images);
|
||||
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
|
||||
gridLayoutManager.setAutoMeasureEnabled(true);
|
||||
rv4kImages.setLayoutManager(gridLayoutManager);
|
||||
|
||||
// rv4kImages.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
|
||||
// rv4kImages.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.HORIZONTAL));
|
||||
rv4kImages.setHasFixedSize(true);
|
||||
|
||||
|
||||
loadWallpaperData();
|
||||
|
||||
|
||||
adapter = new NatureImageAdapter(getContext(), wallpaperList);
|
||||
rv4kImages.setAdapter(adapter);
|
||||
|
||||
adapter.setOnItemClickListener((position, wallpaperItem) -> {
|
||||
// 1. 校验Context和WallpaperItem非空
|
||||
if (getContext() == null || wallpaperItem == null) {
|
||||
Toast.makeText(getContext(), "Data error", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String highResImageUrl = wallpaperItem.getUrls().getRegular();
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
highResImageUrl = wallpaperItem.getUrls().getFull();
|
||||
}
|
||||
|
||||
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
Toast.makeText(getContext(), "NULL", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Intent intent = new Intent(getContext(), FullImageActivity.class);
|
||||
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_URL, highResImageUrl);
|
||||
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_ID, wallpaperItem.getId());
|
||||
|
||||
String description = wallpaperItem.getAlt_description();
|
||||
if (description == null || description.isEmpty()) {
|
||||
description = "4K超清壁纸";
|
||||
}
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_DESC, description);
|
||||
|
||||
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void loadWallpaperData() {
|
||||
|
||||
wallpaperList = JsonUtils.loadWallpapersFromJson(getContext(), "Experimental.json");
|
||||
if (wallpaperList == null) {
|
||||
wallpaperList = new ArrayList<>();
|
||||
Toast.makeText(getContext(), "Failed to load wallpaper data", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import java.util.List;
|
||||
|
||||
public class NatureImageAdapter extends RecyclerView.Adapter<NatureImageAdapter.ImageViewHolder> {
|
||||
|
||||
private final Context mContext;
|
||||
private final List<Wallpaper_Item> mWallpaperList;
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
|
||||
// 关键修改:移除Glide圆角变换
|
||||
private final RequestOptions glideOptions = new RequestOptions()
|
||||
.centerCrop()
|
||||
.placeholder(R.drawable.load_ing)
|
||||
.error(R.drawable.load_ing)
|
||||
.override(400, 600);
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(int position, Wallpaper_Item wallpaperItem);
|
||||
}
|
||||
|
||||
public NatureImageAdapter(Context context, List<Wallpaper_Item> wallpaperList) {
|
||||
this.mContext = context;
|
||||
this.mWallpaperList = wallpaperList;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.mOnItemClickListener = listener;
|
||||
}
|
||||
|
||||
static class ImageViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView ivItem4k;
|
||||
|
||||
public ImageViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
ivItem4k = itemView.findViewById(R.id.iv_item_4k);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_nature_image, parent, false);
|
||||
return new ImageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
|
||||
Wallpaper_Item wallpaperItem = mWallpaperList.get(position);
|
||||
|
||||
Glide.with(mContext)
|
||||
.load(wallpaperItem.getUrls().getSmall())
|
||||
.apply(glideOptions)
|
||||
.into(holder.ivItem4k);
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onItemClick(position, wallpaperItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mWallpaperList == null ? 0 : mWallpaperList.size();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
public class Outer_TabAdapter extends FragmentStateAdapter {
|
||||
public Outer_TabAdapter(@NonNull FragmentActivity fragmentActivity) {
|
||||
super(fragmentActivity);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return new HomePageFragment();
|
||||
case 1:
|
||||
return new Setting_Fragment();
|
||||
default:
|
||||
return new HomePageFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PatternsFragment extends Fragment {
|
||||
|
||||
private RecyclerView rvLiveImages;
|
||||
private PatternsImageAdapter adapter;
|
||||
private List<Wallpaper_Item> wallpaperList;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_patterns, container, false);
|
||||
|
||||
rvLiveImages = view.findViewById(R.id.rv_live_images);
|
||||
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
|
||||
gridLayoutManager.setAutoMeasureEnabled(true);
|
||||
rvLiveImages.setLayoutManager(gridLayoutManager);
|
||||
|
||||
// rvLiveImages.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
|
||||
// rvLiveImages.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.HORIZONTAL));
|
||||
rvLiveImages.setHasFixedSize(true);
|
||||
|
||||
|
||||
loadWallpaperData();
|
||||
|
||||
|
||||
adapter = new PatternsImageAdapter(getContext(), wallpaperList);
|
||||
rvLiveImages.setAdapter(adapter);
|
||||
|
||||
adapter.setOnItemClickListener((position, wallpaperItem) -> {
|
||||
|
||||
if (getContext() == null || wallpaperItem == null) {
|
||||
Toast.makeText(getContext(), "Data error", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String highResImageUrl = wallpaperItem.getUrls().getRegular();
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
highResImageUrl = wallpaperItem.getUrls().getFull();
|
||||
}
|
||||
|
||||
if (highResImageUrl == null || highResImageUrl.isEmpty()) {
|
||||
Toast.makeText(getContext(), "NULL", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getContext(), FullImageActivity.class);
|
||||
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_URL, highResImageUrl);
|
||||
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_ID, wallpaperItem.getId());
|
||||
|
||||
String description = wallpaperItem.getAlt_description();
|
||||
if (description == null || description.isEmpty()) {
|
||||
description = "精美壁纸";
|
||||
}
|
||||
intent.putExtra(FullImageActivity.EXTRA_IMAGE_DESC, description);
|
||||
|
||||
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void loadWallpaperData() {
|
||||
// 从Featured.json加载壁纸数据
|
||||
wallpaperList = JsonUtils.loadWallpapersFromJson(getContext(), "Featured.json");
|
||||
if (wallpaperList == null) {
|
||||
wallpaperList = new ArrayList<>();
|
||||
Toast.makeText(getContext(), "Wallpaper data loading failed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import java.util.List;
|
||||
|
||||
public class PatternsImageAdapter extends RecyclerView.Adapter<PatternsImageAdapter.ImageViewHolder> {
|
||||
|
||||
private final Context mContext;
|
||||
private final List<Wallpaper_Item> mWallpaperList;
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
|
||||
// 关键修改:移除Glide圆角变换
|
||||
private final RequestOptions glideOptions = new RequestOptions()
|
||||
.centerCrop()
|
||||
.placeholder(R.drawable.load_ing)
|
||||
.error(R.drawable.load_ing)
|
||||
.override(400, 600);
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(int position, Wallpaper_Item wallpaperItem);
|
||||
}
|
||||
|
||||
public PatternsImageAdapter(Context context, List<Wallpaper_Item> wallpaperList) {
|
||||
this.mContext = context;
|
||||
this.mWallpaperList = wallpaperList;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.mOnItemClickListener = listener;
|
||||
}
|
||||
|
||||
static class ImageViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView ivItemLive;
|
||||
|
||||
public ImageViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
ivItemLive = itemView.findViewById(R.id.iv_item_live);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_patterns_image, parent, false);
|
||||
return new ImageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
|
||||
Wallpaper_Item wallpaperItem = mWallpaperList.get(position);
|
||||
|
||||
Glide.with(mContext)
|
||||
.load(wallpaperItem.getUrls().getSmall())
|
||||
.apply(glideOptions)
|
||||
.into(holder.ivItemLive);
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onItemClick(position, wallpaperItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mWallpaperList == null ? 0 : mWallpaperList.size();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class Setting_Fragment extends Fragment {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_setting, container, false);
|
||||
|
||||
// 1. 设置“收藏”按钮点击事件
|
||||
setupCollectionButton(view);
|
||||
// 2. 设置“Rate Us”按钮点击事件(评分弹窗)
|
||||
setupRateUsButton(view);
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
// 收藏按钮逻辑(原代码保留)
|
||||
private void setupCollectionButton(View view) {
|
||||
View collectionLayout = view.findViewById(R.id.linearLayout3);
|
||||
if (collectionLayout != null) {
|
||||
collectionLayout.setOnClickListener(v -> navigateToFavoriteActivity());
|
||||
}
|
||||
}
|
||||
|
||||
private void navigateToFavoriteActivity() {
|
||||
Intent intent = new Intent(getActivity(), CollectionActivity.class);
|
||||
startActivity(intent);
|
||||
if (getActivity() != null) {
|
||||
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupRateUsButton(View view) {
|
||||
View rateUsLayout = view.findViewById(R.id.linearLayout1);
|
||||
if (rateUsLayout != null) {
|
||||
rateUsLayout.setOnClickListener(v -> showRateUsDialog());
|
||||
}
|
||||
}
|
||||
|
||||
private void showRateUsDialog() {
|
||||
Context context = getContext();
|
||||
if (context == null) return;
|
||||
|
||||
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_rateus, null);
|
||||
RatingBar ratingBar = dialogView.findViewById(R.id.ratingBar);
|
||||
Button btnCancel = dialogView.findViewById(R.id.btn_cancel);
|
||||
Button btnRateIt = dialogView.findViewById(R.id.btn_rate_it);
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
.setView(dialogView)
|
||||
.create();
|
||||
|
||||
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
||||
|
||||
btnCancel.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
btnRateIt.setOnClickListener(v -> {
|
||||
float userRating = ratingBar.getRating();
|
||||
dialog.dismiss();
|
||||
String toastMsg;
|
||||
if (userRating == 5) {
|
||||
toastMsg = "Thank you so much for your five-star review!";
|
||||
} else if (userRating >= 3) {
|
||||
toastMsg = "Thank you" + userRating + "Star rating!";
|
||||
} else {
|
||||
toastMsg = "We apologize for not meeting your expectations, and we will continue to improve!";
|
||||
}
|
||||
Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
public class StartuppageActivity extends AppCompatActivity {
|
||||
|
||||
private ProgressBar progressBar;
|
||||
// 倒计时总时长(毫秒),这里设置1500ms=1.5秒,和你原来的逻辑一致
|
||||
private static final long TOTAL_COUNT_DOWN_TIME = 1500;
|
||||
// 倒计时间隔(毫秒),每15ms更新一次进度,和原逻辑匹配
|
||||
private static final long COUNT_DOWN_INTERVAL = 15;
|
||||
private CountDownTimer countDownTimer;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_startuppage);
|
||||
|
||||
// 初始化控件
|
||||
progressBar = findViewById(R.id.progressBar);
|
||||
|
||||
// 初始化并启动CountDownTimer倒计时
|
||||
initCountDownTimer();
|
||||
|
||||
// 适配系统状态栏(保留原有逻辑)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化CountDownTimer,实现倒计时和进度条更新
|
||||
*/
|
||||
private void initCountDownTimer() {
|
||||
// CountDownTimer参数说明:
|
||||
// 第一个参数:总倒计时时长(ms)
|
||||
// 第二个参数:倒计时间隔(ms),每隔这个时间回调一次onTick
|
||||
countDownTimer = new CountDownTimer(TOTAL_COUNT_DOWN_TIME, COUNT_DOWN_INTERVAL) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
// 计算当前进度:(总时长 - 剩余时长) / 总时长 * 100
|
||||
int progress = (int) ((TOTAL_COUNT_DOWN_TIME - millisUntilFinished) * 100 / TOTAL_COUNT_DOWN_TIME);
|
||||
// 更新进度条(CountDownTimer的回调默认在主线程,可直接更新UI)
|
||||
progressBar.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
// 倒计时结束,设置进度条为100
|
||||
progressBar.setProgress(100);
|
||||
// 跳转到MainActivity2
|
||||
Intent intent = new Intent(StartuppageActivity.this, FirstMainActivity.class);
|
||||
startActivity(intent);
|
||||
finish(); // 关闭启动页,避免返回键回到此页面
|
||||
}
|
||||
};
|
||||
|
||||
// 启动倒计时
|
||||
countDownTimer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 防止内存泄漏:页面销毁时取消倒计时
|
||||
*/
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (countDownTimer != null) {
|
||||
countDownTimer.cancel(); // 取消倒计时
|
||||
}
|
||||
}
|
||||
}
|
||||
20
test2/src/main/java/com/wall/exquisite/wallpaper/Urls.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
public class Urls {
|
||||
private String full;
|
||||
private String raw;
|
||||
private String regular;
|
||||
private String small;
|
||||
private String thumb;
|
||||
|
||||
public String getFull() { return full; }
|
||||
public void setFull(String full) { this.full = full; }
|
||||
public String getRaw() { return raw; }
|
||||
public void setRaw(String raw) { this.raw = raw; }
|
||||
public String getRegular() { return regular; }
|
||||
public void setRegular(String regular) { this.regular = regular; }
|
||||
public String getSmall() { return small; }
|
||||
public void setSmall(String small) { this.small = small; }
|
||||
public String getThumb() { return thumb; }
|
||||
public void setThumb(String thumb) { this.thumb = thumb; }
|
||||
}
|
||||
11
test2/src/main/java/com/wall/exquisite/wallpaper/User.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
public class User {
|
||||
private String name;
|
||||
private String portfolio_url;
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getPortfolio_url() { return portfolio_url; }
|
||||
public void setPortfolio_url(String portfolio_url) { this.portfolio_url = portfolio_url; }
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
// 导入你的收藏工具类
|
||||
|
||||
|
||||
/**
|
||||
* 壁纸应用的全局Application类,负责初始化全局工具、预加载数据
|
||||
*/
|
||||
public class WallpaperApplication extends Application {
|
||||
private static WallpaperApplication instance;
|
||||
private ExecutorService mExecutorService;
|
||||
private Handler mMainHandler;
|
||||
// 全局单例的收藏工具
|
||||
private static CollectionManager favoriteManager;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
instance = this;
|
||||
// 初始化基础工具(主线程)
|
||||
initBasicTools();
|
||||
// 异步执行耗时数据准备
|
||||
initDataAsync();
|
||||
}
|
||||
|
||||
private void initBasicTools() {
|
||||
mMainHandler = new Handler(Looper.getMainLooper());
|
||||
mExecutorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
Log.d("WallpaperApplication", "基础工具初始化完成");
|
||||
}
|
||||
|
||||
private void initDataAsync() {
|
||||
mExecutorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 初始化收藏工具
|
||||
initFavoriteManager();
|
||||
// 预加载收藏数据
|
||||
preloadFavoriteData();
|
||||
|
||||
// 回调主线程标记完成
|
||||
mMainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onDataInitComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化全局收藏工具
|
||||
*/
|
||||
private void initFavoriteManager() {
|
||||
Log.d("WallpaperApplication", "开始初始化收藏工具...");
|
||||
favoriteManager = new CollectionManager(getApplicationContext());
|
||||
Log.d("WallpaperApplication", "收藏工具初始化完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载收藏数据
|
||||
*/
|
||||
private void preloadFavoriteData() {
|
||||
Log.d("WallpaperApplication", "开始预加载收藏数据...");
|
||||
if (favoriteManager != null) {
|
||||
favoriteManager.getFavoriteItems();
|
||||
Log.d("WallpaperApplication", "收藏数据预加载完成,数量:" + favoriteManager.getFavoriteItems().size());
|
||||
}
|
||||
}
|
||||
|
||||
private void onDataInitComplete() {
|
||||
Log.d("WallpaperApplication", "所有数据准备工作完成!");
|
||||
}
|
||||
|
||||
// 获取全局Application实例
|
||||
public static WallpaperApplication getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
// 获取全局收藏工具实例
|
||||
public static CollectionManager getFavoriteManager() {
|
||||
return favoriteManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
if (mExecutorService != null && !mExecutorService.isShutdown()) {
|
||||
mExecutorService.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.wall.exquisite.wallpaper;
|
||||
|
||||
public class Wallpaper_Item {
|
||||
private String id; // 确保这个字段存在
|
||||
private String alt_description;
|
||||
private Urls urls;
|
||||
private User user;
|
||||
|
||||
|
||||
public String getId() {
|
||||
|
||||
if (id != null && !id.isEmpty()) {
|
||||
return id;
|
||||
}
|
||||
|
||||
if (urls != null && urls.getRegular() != null) {
|
||||
|
||||
return "wallpaper_" + Math.abs(urls.getRegular().hashCode());
|
||||
}
|
||||
|
||||
return "wallpaper_" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAlt_description() {
|
||||
return alt_description;
|
||||
}
|
||||
|
||||
public void setAlt_description(String alt_description) {
|
||||
this.alt_description = alt_description;
|
||||
}
|
||||
|
||||
public Urls getUrls() {
|
||||
return urls;
|
||||
}
|
||||
|
||||
public void setUrls(Urls urls) {
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
// public class Urls {
|
||||
//
|
||||
// }
|
||||
|
||||
// public class User {
|
||||
//
|
||||
// }
|
||||
}
|
||||
BIN
test2/src/main/res/drawable/aix.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
test2/src/main/res/drawable/beij11.jpg
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
test2/src/main/res/drawable/beij13.jpg
Normal file
|
After Width: | Height: | Size: 153 KiB |
BIN
test2/src/main/res/drawable/both1.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
7
test2/src/main/res/drawable/dialog_rounded_bg.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/Light_cyan"/> <!-- 保留原有白色背景色 -->
|
||||
<corners android:radius="15dp"/> <!-- 圆角大小(可调整,如12dp/18dp) -->
|
||||
<stroke android:width="1dp" android:color="#E0E0E0"/> <!-- 轻微边框(可选,优化视觉) -->
|
||||
</shape>
|
||||
BIN
test2/src/main/res/drawable/hert.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
test2/src/main/res/drawable/home2.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
test2/src/main/res/drawable/left.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
test2/src/main/res/drawable/like.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
test2/src/main/res/drawable/like_red.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
test2/src/main/res/drawable/load.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
test2/src/main/res/drawable/load_ing.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
test2/src/main/res/drawable/loading.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
test2/src/main/res/drawable/lock1.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
6
test2/src/main/res/drawable/oval.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/color_main_view"/>
|
||||
|
||||
</shape>
|
||||
7
test2/src/main/res/drawable/retc_16.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="16dp" />
|
||||
<solid android:color="@color/color_main_view" />
|
||||
|
||||
</shape>
|
||||
10
test2/src/main/res/drawable/retc_19.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="19dp"/>
|
||||
<gradient
|
||||
android:angle="45"
|
||||
android:endColor="@color/navy_blue"
|
||||
android:startColor="@color/navy_blue" />
|
||||
|
||||
</shape>
|
||||
BIN
test2/src/main/res/drawable/right3.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
test2/src/main/res/drawable/setting2.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
8
test2/src/main/res/drawable/shape_gray_bg.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<!-- 灰白色背景 #F5F5F5 -->
|
||||
<solid android:color="#F5F5F5" />
|
||||
<!-- 圆角(可选,让样式更柔和) -->
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
BIN
test2/src/main/res/drawable/sj.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
test2/src/main/res/drawable/xiangp.png
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
test2/src/main/res/drawable/xingxing.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
69
test2/src/main/res/layout/activity_collection.xml
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="30dp"
|
||||
android:background="@drawable/beij13">
|
||||
|
||||
<!-- 顶部栏 - 移除白色背景,仅保留文字/图标 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/top_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_back"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/left" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="Collection"
|
||||
android:textColor="#98F5F9"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_favorite_images"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/top_bar" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="No favorite wallpapers yet"
|
||||
android:textColor="@color/title_color"
|
||||
android:textSize="18sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
123
test2/src/main/res/layout/activity_full_image.xml
Normal file
@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 核心修改:添加DataBinding根标签 <layout> -->
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageview_preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageview_back"
|
||||
android:layout_width="45dp"
|
||||
android:layout_height="45dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="42dp"
|
||||
android:background="@drawable/oval"
|
||||
android:padding="13dp"
|
||||
android:src="@drawable/left"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:background="@drawable/retc_16"
|
||||
android:gravity="center"
|
||||
android:minHeight="40dp"
|
||||
android:padding="10dp"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="#000000"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent" />
|
||||
|
||||
<!-- 新增父容器:包裹 button_set1 和 image_favorite,背景统一为 oval -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/parent_set_favorite"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:background="@drawable/oval"
|
||||
android:paddingHorizontal="15dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/tv_content"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent">
|
||||
|
||||
<!-- button_set1:移除自身背景,仅保留图标相关属性 -->
|
||||
<ImageView
|
||||
android:id="@+id/button_set1"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="13dp"
|
||||
android:src="@drawable/xiangp" />
|
||||
|
||||
<!-- image_favorite:移除自身背景,靠右排列,与 button_set1 保持间距 -->
|
||||
<ImageView
|
||||
android:id="@+id/image_favorite"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_toRightOf="@id/button_set1"
|
||||
android:padding="13dp"
|
||||
android:src="@drawable/aix" />
|
||||
|
||||
<!-- 原 button_set1 的 ProgressBar:位置调整为与 button_set1 重叠 -->
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_set1"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_alignLeft="@id/button_set1"
|
||||
android:layout_alignTop="@id/button_set1"
|
||||
android:indeterminateTint="@color/white"
|
||||
android:padding="13dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<!-- 下载按钮布局:保持原有样式,仅调整约束为对齐新的父容器 -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/layout_download"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="26dp"
|
||||
android:background="@drawable/oval"
|
||||
app:layout_constraintBottom_toBottomOf="@id/parent_set_favorite"
|
||||
app:layout_constraintRight_toLeftOf="@id/parent_set_favorite"
|
||||
app:layout_constraintTop_toTopOf="@id/parent_set_favorite">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_download"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:padding="13dp"
|
||||
android:src="@drawable/load"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_download"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:indeterminateTint="@color/white"
|
||||
android:padding="13dp"
|
||||
android:visibility="gone" />
|
||||
</RelativeLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
51
test2/src/main/res/layout/activity_main2.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/beij13"
|
||||
android:id="@+id/main"
|
||||
tools:context="com.wall.exquisite.wallpaper.FirstMainActivity">
|
||||
|
||||
<!-- 内层Tab(4D/LIVE/4K)- 顶部 -->
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/innerTabLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:visibility="gone"
|
||||
app:tabGravity="fill"
|
||||
app:tabMode="fixed"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<!-- 外层ViewPager2 - 中间 -->
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/outerViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/innerTabLayout"
|
||||
app:layout_constraintBottom_toTopOf="@+id/outerTabLayout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
|
||||
<!-- 外层Tab(Home/Setting)- 底部 -->
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/outerTabLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="65dp"
|
||||
android:background="@android:color/transparent"
|
||||
app:tabGravity="fill"
|
||||
app:tabMode="fixed"
|
||||
app:tabIndicatorHeight="0dp"
|
||||
app:tabPaddingStart="0dp"
|
||||
app:tabPaddingEnd="0dp"
|
||||
app:tabMinWidth="0dp"
|
||||
app:iconSize="28dp"
|
||||
app:tabInlineLabel="false"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
40
test2/src/main/res/layout/activity_startuppage.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/beij11"
|
||||
android:orientation="vertical"
|
||||
|
||||
tools:context="com.wall.exquisite.wallpaper.StartuppageActivity">
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="#FFDE59"
|
||||
android:layout_marginTop="250dp"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold"
|
||||
/>
|
||||
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="280dp"
|
||||
android:layout_height="10dp"
|
||||
android:progress="0"
|
||||
android:progressTint="#FFDE59"
|
||||
android:backgroundTint="#E0E0E0"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginTop="100dp"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
27
test2/src/main/res/layout/custom_innertab.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- 默认颜色设为未选中色 #98F5F9,后续代码会覆盖选中态 -->
|
||||
<TextView
|
||||
android:id="@+id/tab_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:textColor="#98F5F9"
|
||||
android:textStyle="bold"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<!-- 竖线分隔符 -->
|
||||
<View
|
||||
android:id="@+id/tab_divider"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="25dp"
|
||||
android:background="#000000"/>
|
||||
|
||||
</LinearLayout>
|
||||
27
test2/src/main/res/layout/custom_outertab.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/tab_root"
|
||||
android:padding="8dp">
|
||||
|
||||
<!-- 外层Tab图标 -->
|
||||
<ImageView
|
||||
android:id="@+id/tab_icon"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp" />
|
||||
|
||||
<!-- 外层Tab文字 -->
|
||||
<TextView
|
||||
android:id="@+id/tab_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="11sp"
|
||||
android:layout_marginTop="0dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 自定义 Tab 样式:系统默认的 Tab 只能显示「单一图标」或「单一文字」,这个布局让 Tab 同时显示「图标 + 文字」,且垂直排列(符合大多数 App 的底部导航设计);-->
|
||||
58
test2/src/main/res/layout/dialog_rateus.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp"
|
||||
|
||||
android:background="@drawable/dialog_rounded_bg"
|
||||
android:gravity="center">
|
||||
|
||||
<!-- 提示文本(保留原有) -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="We hope this app is useful for you. If you like us, would you mind taking a moment to rate us on Google Play? It really helps!"
|
||||
android:textSize="16sp"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="20dp"/>
|
||||
|
||||
<!-- 星级评分条(核心修改:星星颜色) -->
|
||||
<RatingBar
|
||||
android:id="@+id/ratingBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:numStars="5"
|
||||
android:rating="2"
|
||||
android:stepSize="1"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:progressTint="#FFFFCC00"
|
||||
android:secondaryProgressTint="#E0E0E0"
|
||||
android:backgroundTint="#E0E0E0"/>
|
||||
|
||||
<!-- 按钮栏(保留原有) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="CANCEL"
|
||||
android:backgroundTint="@color/grey_300"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_rate_it"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="RATE IT"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:backgroundTint="@android:color/holo_blue_light"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
97
test2/src/main/res/layout/dialog_wallpapertype.xml
Normal file
@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:background="@drawable/retc_19"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_ic_home"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/sj" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_home"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="21dp"
|
||||
android:text="@string/type_home"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:background="@color/white" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_ic_lock"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/lock1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_lock"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="22dp"
|
||||
android:text="@string/type_lock"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:background="@color/white" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_ic_both"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/both1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_both"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="22dp"
|
||||
android:text="@string/type_both"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
18
test2/src/main/res/layout/fragment_animals.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/beij13">
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- 核心:RecyclerView 显示2列图片网格 -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_4d_images"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="4dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
27
test2/src/main/res/layout/fragment_home.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- 内层TabLayout - 关键修改:透明背景、无指示器、填充模式 -->
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/innerTabLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="@android:color/transparent"
|
||||
app:tabGravity="fill"
|
||||
app:tabMode="fixed"
|
||||
app:tabIndicatorHeight="0dp"
|
||||
app:tabPaddingStart="0dp"
|
||||
app:tabPaddingEnd="0dp"
|
||||
app:tabMinWidth="0dp" />
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/innerViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="5dp" />
|
||||
|
||||
</LinearLayout>
|
||||
14
test2/src/main/res/layout/fragment_nature.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/beij13">
|
||||
|
||||
<!-- RecyclerView 显示壁纸列表 -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_4k_images"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="4dp" />
|
||||
</LinearLayout>
|
||||
16
test2/src/main/res/layout/fragment_patterns.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/beij13">
|
||||
|
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_live_images"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="4dp"/>
|
||||
|
||||
</LinearLayout>
|
||||