> {
+ return CollectionUtils.newArrayList(
+ getItemSeekBar("Voice Call", AudioManager.STREAM_VOICE_CALL),
+ getItemSeekBar("System", AudioManager.STREAM_SYSTEM),
+ getItemSeekBar("Music", AudioManager.STREAM_MUSIC),
+ getItemSeekBar("Ring", AudioManager.STREAM_RING),
+ getItemSeekBar("Alarm", AudioManager.STREAM_ALARM),
+ getItemSeekBar("Notification", AudioManager.STREAM_NOTIFICATION),
+ getItemSeekBar("Dtmf", AudioManager.STREAM_DTMF)
+ )
+ }
+
+ private fun getItemSeekBar(title: CharSequence, streamType: Int): CommonItemSeekBar {
+ return CommonItemSeekBar(title, VolumeUtils.getMaxVolume(streamType), object : CommonItemSeekBar.ProgressListener() {
+ override fun getCurValue(): Int {
+ return VolumeUtils.getVolume(streamType)
+ }
+
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
+ VolumeUtils.setVolume(streamType, progress, AudioManager.FLAG_SHOW_UI)
+ }
+ })
+ }
+
+ override fun onResume() {
+ super.onResume()
+ itemsView.updateItems(bindItems())
+ }
+}
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt
index 6643ec7806..7d38fda3ca 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt
@@ -4,7 +4,6 @@ import android.content.Context
import android.content.DialogInterface
import android.graphics.Bitmap
import android.graphics.drawable.ColorDrawable
-import android.support.v4.app.FragmentActivity
import android.text.method.ScrollingMovementMethod
import android.view.Gravity
import android.view.View
@@ -13,6 +12,7 @@ import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
+import androidx.fragment.app.FragmentActivity
import com.blankj.base.dialog.BaseDialogFragment
import com.blankj.base.dialog.DialogLayoutCallback
import com.blankj.utilcode.pkg.R
@@ -155,4 +155,4 @@ object DialogHelper {
override fun onDismiss(dialog: BaseDialogFragment) {}
}).show()
}
-}
+}
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/layout/activity_adaptscreen.xml b/feature/utilcode/pkg/src/main/res/layout/activity_adaptscreen.xml
new file mode 100644
index 0000000000..278fe8c2c6
--- /dev/null
+++ b/feature/utilcode/pkg/src/main/res/layout/activity_adaptscreen.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/feature/utilcode/pkg/src/main/res/layout/adaptscreen_close_activity.xml b/feature/utilcode/pkg/src/main/res/layout/adaptscreen_close_activity.xml
index 0214eb4806..2f8476a4a0 100644
--- a/feature/utilcode/pkg/src/main/res/layout/adaptscreen_close_activity.xml
+++ b/feature/utilcode/pkg/src/main/res/layout/adaptscreen_close_activity.xml
@@ -7,7 +7,7 @@
android:fillViewport="true"
tools:context=".feature.adaptScreen.AdaptCloseActivity">
-
@@ -42,6 +42,6 @@
android:textSize="30pt"
app:layout_constraintTop_toBottomOf="@id/adaptScreenCloseAdaptDpTv" />
-
+
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/layout/adaptscreen_height_activity.xml b/feature/utilcode/pkg/src/main/res/layout/adaptscreen_height_activity.xml
index 819d6bb99d..75fa87e8e5 100644
--- a/feature/utilcode/pkg/src/main/res/layout/adaptscreen_height_activity.xml
+++ b/feature/utilcode/pkg/src/main/res/layout/adaptscreen_height_activity.xml
@@ -6,7 +6,7 @@
android:layout_height="match_parent"
tools:context=".feature.adaptScreen.AdaptHeightActivity">
-
@@ -93,6 +93,6 @@
android:textSize="30pt" />
-
+
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/layout/adaptscreen_width_activity.xml b/feature/utilcode/pkg/src/main/res/layout/adaptscreen_width_activity.xml
index 9c5e953ecb..b6bfdb2c80 100644
--- a/feature/utilcode/pkg/src/main/res/layout/adaptscreen_width_activity.xml
+++ b/feature/utilcode/pkg/src/main/res/layout/adaptscreen_width_activity.xml
@@ -7,7 +7,7 @@
android:fillViewport="true"
tools:context=".feature.adaptScreen.AdaptWidthActivity">
-
@@ -148,6 +148,6 @@
-
+
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/layout/bar_status_fragment_activity.xml b/feature/utilcode/pkg/src/main/res/layout/bar_status_fragment_activity.xml
index 23dbb69305..16518fc22f 100644
--- a/feature/utilcode/pkg/src/main/res/layout/bar_status_fragment_activity.xml
+++ b/feature/utilcode/pkg/src/main/res/layout/bar_status_fragment_activity.xml
@@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
-
-
+
+
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/values-en-rUS/strings.xml b/feature/utilcode/pkg/src/main/res/values-en-rUS/strings.xml
index 84ac729412..20efc6c063 100644
--- a/feature/utilcode/pkg/src/main/res/values-en-rUS/strings.xml
+++ b/feature/utilcode/pkg/src/main/res/values-en-rUS/strings.xml
@@ -3,11 +3,10 @@
Language Demo
- Language
- Language App Context
- Language Activity Context
Apply Simple Chinese
Apply American
+ Apply English
+ Apply Arabic
Apply System
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/values-zh-rCN/strings.xml b/feature/utilcode/pkg/src/main/res/values-zh-rCN/strings.xml
index d1ba24cff1..e06759a6d0 100644
--- a/feature/utilcode/pkg/src/main/res/values-zh-rCN/strings.xml
+++ b/feature/utilcode/pkg/src/main/res/values-zh-rCN/strings.xml
@@ -3,11 +3,10 @@
语言例子
- 语言
- App 上下文语言
- Activity 上下文语言
- 应用简体中文
- 应用英语
- 应用系统语言
+ 设置简体中文
+ 设置美语
+ 设置英语
+ 设置阿拉伯语
+ 设置系统语言
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/values/strings.xml b/feature/utilcode/pkg/src/main/res/values/strings.xml
index 02f2622ab2..551f9adbaf 100644
--- a/feature/utilcode/pkg/src/main/res/values/strings.xml
+++ b/feature/utilcode/pkg/src/main/res/values/strings.xml
@@ -9,12 +9,14 @@
BusUtils Demo
CleanUtils Demo
ClickUtils Demo
+ ClipboardUtils Demo
CrashUtils Demo
DeviceUtils Demo
FileUtils Demo
FlashlightUtils Demo
FragmentUtils Demo
ImageUtils Demo
+ IntentUtils Demo
KeyboardUtils Demo
Language Demo
LogUtils Demo
@@ -40,6 +42,7 @@
UiMessage Demo
TransActivity Demo
VibrateUtils Demo
+ VolumeUtils Demo
Shared Element
@@ -138,6 +141,7 @@
Clean Internal Databases
Clean Internal SP
Clean External Cache
+ cleanAppUserData
Click View Scale Default
@@ -226,18 +230,20 @@
Close Dialog
- Language
- Language App Context
- Language Activity Context
+ Relaunch App
Apply Simple Chinese
Apply American
+ Apply English
+ Apply Arabic
Apply System
Log Switch
- Console Switch
+ Console Switch
+ Console Listener Switch
Head Switch
File Switch
+ File Listener Switch
Border Switch
Single Tag Switch
Log With No Tag
@@ -324,15 +330,23 @@
Show Short
Show Long
+ Show Null
+ Show Empty
Show Green Font
Show Bg Color
Show Bg Resource
Show Span
+ Show Left Icon
+ Show Dark Mode
+ Show Long String
+ A toast is a view containing a quick little message for the user. The ToastUtils class helps you create and show those.
Show Custom View
Custom View
Show Middle
+ Show Top
Cancel
Show Toast Dialog
+ Show Toast When Start Activity
Short
Long
Green Font
@@ -340,6 +354,7 @@
Custom Bg
Spannable String
Middle
+ Top
Add Listener Id
@@ -351,5 +366,6 @@
Vibrate 1000ms
Vibrate Custom
+ Vibrate Background
Cancel
diff --git a/gradle.properties b/gradle.properties
index 63f495a02a..b9d5f2bcbf 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -13,10 +13,14 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#org.gradle.jvmargs=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
+
+android.enableJetifier=true
+android.useAndroidX=true
+
org.gradle.jvmargs=-Xmx8192m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8
org.gradle.daemon=true
#org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.caching=true
-#-Dorg.gradle.debug=true --no-daemon
\ No newline at end of file
+#-Dorg.gradle.debug=true --no-daemon
diff --git a/gradle/publish.gradle b/gradle/publish.gradle
deleted file mode 100644
index f6fdfb4dda..0000000000
--- a/gradle/publish.gradle
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- 1. must add the following classpath in root build.gradle
- classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
- classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
-
- 2. add bintrayUser, bintrayKey in root local.properties
-
- 3. copy the file to the directory of gradle, and apply the file in the module
- apply from: "${rootDir.path}/gradle/publish.gradle"
- publish {
- name = "UtilCode"
- groupId = "com.blankj"
- artifactId = "utilcode"
- version = "xx.xx"
- website = "https://github.com/Blankj/AndroidUtilCode"
- }
-
- 4. execute following command to publish
- ./gradlew bintrayUpload -> upload to bintray
- ./gradlew mavenLocal -> upload to local maven
-*/
-
-apply plugin: "com.github.dcendents.android-maven"
-apply plugin: "com.jfrog.bintray"
-
-extensions.create('publish', PublishExtension)
-
-afterEvaluate {
- def ext = project['publish'] as PublishExtension
- loadBintray(ext)
- configMaven(project, ext)
- configBintray(project, ext)
- configJavadoc(project, ext)
-}
-
-private void loadBintray(PublishExtension ext) {
- Properties properties = new Properties()
- File localPropertiesFile = project.rootProject.file("local.properties");
- if (localPropertiesFile.exists()) {
- properties.load(localPropertiesFile.newDataInputStream())
- ext.bintrayUser = properties.getProperty("bintrayUser")
- ext.bintrayKey = properties.getProperty("bintrayKey")
- }
-}
-
-def configMaven(Project project, PublishExtension ext) {
- project.group = ext.groupId
- project.version = ext.version
-
- project.install {
- repositories.mavenInstaller {
- configPom(pom, ext)
- }
- }
-
- project.tasks.create("mavenLocal", Upload) {
- group("publishing")
- configuration = project.configurations.archives
-
- repositories.mavenDeployer {
- repository(url: uri(new File(project.rootDir.getPath() + "/mavenLocal")))
- configPom(pom, ext)
- }
-
- doFirst {
- checkExt(project, ext)
- }
- }
-
- project.tasks.findByName("bintrayUpload").doFirst {
- checkExt(project, ext)
- }
-}
-
-def configPom(pom, PublishExtension ext) {
- pom.project {
- name ext.name
- groupId ext.groupId
- artifactId ext.artifactId
- version ext.version
- packaging isAndroid() ? "aar" : "jar"
- description ext.name
- url ext.website
-
- scm {
- url ext.website
- connection ext.website
- developerConnection ext.website + ".git"
- }
-
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
-
- developers {
- developer {
- id ext.bintrayUser
- name ext.bintrayUser
- }
- }
- }
-}
-
-static def checkExt(Project project, PublishExtension ext) {
- if (ext.isBintrayEmpty()) {
- throw new NullPointerException("U should set bintrayUser and bintrayKey in local.properties")
- }
- ext.check()
-}
-
-def configBintray(Project project, PublishExtension ext) {
- project.bintray {
- user = ext.bintrayUser
- key = ext.bintrayKey
- configurations = ['archives']
- override = false
- publish = true
- pkg {
- repo = "maven"
- name = ext.name
- websiteUrl = ext.website
- vcsUrl = ext.website + '.git'
- licenses = ["Apache-2.0"]
- }
- }
-}
-
-private void configJavadoc(Project project, PublishExtension ext) {
- if (isAndroid()) {
- // This generates sources.jar
- task sourcesJar(type: Jar) {
- classifier = 'sources'
- from android.sourceSets.main.java.source
- }
-
- task javadoc(type: Javadoc) {
- source = android.sourceSets.main.java.source
- classpath += configurations.compile
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- }
-
- task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
- }
- } else {
- task sourcesJar(type: Jar, dependsOn: classes) {
- classifier = 'sources'
- from sourceSets.main.allSource
- }
-
- task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
- }
- }
-
- if (project.hasProperty("kotlin")) {
- // Disable creating javadocs
- project.tasks.withType(Javadoc) {
- enabled = false
- }
- }
-
- javadoc {
- options {
- encoding "UTF-8"
- charSet 'UTF-8'
- author true
- version ext.version
- links "http://docs.oracle.com/javase/7/docs/api"
- title "${ext.name} ${ext.version}"
- }
- }
-
- artifacts {
- archives javadocJar
- archives sourcesJar
- }
-}
-
-def isAndroid() {
- return project.getPlugins().hasPlugin('com.android.application') ||
- project.getPlugins().hasPlugin('com.android.library')
-}
-
-class PublishExtension {
- String name
- String groupId
- String artifactId
- String version
- String website
-
- String bintrayUser
- String bintrayKey
-
- void check() {
- checkField(name, "name")
- checkField(groupId, "groupId")
- checkField(artifactId, "artifactId")
- checkField(version, "version")
- checkField(website, "website")
-
- checkField(bintrayUser, "bintrayUser")
- checkField(bintrayKey, "bintrayKey")
- }
-
- boolean isBintrayEmpty() {
- return isEmpty(bintrayUser) || isEmpty(bintrayKey)
- }
-
- static void checkField(String field, String fieldName) {
- if (isEmpty(field)) {
- throw new NullPointerException("$fieldName is empty!!")
- }
- }
-
- static boolean isEmpty(String str) {
- return str == null || str.length() == 0
- }
-}
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 13372aef5e..5c2d1cf016 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index e4718dff4d..1e0ae1a108 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
diff --git a/gradlew b/gradlew
index 9d82f78915..b0d6d0ab5d 100755
--- a/gradlew
+++ b/gradlew
@@ -1,4 +1,20 @@
-#!/usr/bin/env bash
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
##############################################################################
##
@@ -6,20 +22,38 @@
##
##############################################################################
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
+# 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"'
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
-warn ( ) {
+warn () {
echo "$*"
}
-die ( ) {
+die () {
echo
echo "$*"
echo
@@ -30,6 +64,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
+nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
@@ -40,26 +75,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
+ NONSTOP* )
+ nonstop=true
+ ;;
esac
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -85,7 +105,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -150,11 +170,19 @@ if $cygwin ; then
esac
fi
-# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
-function splitJvmOpts() {
- JVM_OPTS=("$@")
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
}
-eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
-JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
-exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index 8a0b282aa6..15e1ee37a7 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,90 +1,100 @@
-@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
-
-@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=
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windowz variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="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!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@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 http://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
+
+@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=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@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%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="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!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/lib/base/build.gradle b/lib/base/build.gradle
index 20033bc3f0..b7eb9d588c 100644
--- a/lib/base/build.gradle
+++ b/lib/base/build.gradle
@@ -1,15 +1,14 @@
dependencies {
- implementation fileTree(include: ['*.jar'], dir: 'libs')
- api Config.depConfig.lib_subutil.dep
- api Config.depConfig.lib_utilcode.dep
+ api Config.modules.lib_subutil.dep
+ api Config.modules.lib_utilcode.dep
- api Config.depConfig.support_appcompat_v7.dep
- api Config.depConfig.support_design.dep
- api Config.depConfig.support_multidex.dep
- api Config.depConfig.support_constraint.dep
- api Config.depConfig.kotlin.dep
- api Config.depConfig.free_proguard.dep
- api Config.depConfig.swipe_panel.dep
- api Config.depConfig.eventbus_lib.dep
- compileOnly Config.depConfig.lib_utildebug_no_op.dep
+ api Config.libs.androidx_appcompat.path
+ api Config.libs.androidx_material.path
+ api Config.libs.androidx_multidex.path
+ api Config.libs.androidx_constraint.path
+ api Config.libs.kotlin.path
+ api Config.libs.free_proguard.path
+ api Config.libs.swipe_panel.path
+ api Config.libs.eventbus_lib.path
+ compileOnly Config.modules.lib_utildebug_no_op.dep
}
\ No newline at end of file
diff --git a/lib/base/src/main/java/com/blankj/base/BaseActivity.java b/lib/base/src/main/java/com/blankj/base/BaseActivity.java
index c0c1fce1ce..c0348203f8 100644
--- a/lib/base/src/main/java/com/blankj/base/BaseActivity.java
+++ b/lib/base/src/main/java/com/blankj/base/BaseActivity.java
@@ -2,10 +2,12 @@
import android.app.Activity;
import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
+import androidx.annotation.LayoutRes;
+import androidx.appcompat.app.AppCompatActivity;
+
import com.blankj.utilcode.util.ClickUtils;
/**
diff --git a/lib/base/src/main/java/com/blankj/base/BaseApplication.java b/lib/base/src/main/java/com/blankj/base/BaseApplication.java
index aedea57cb4..f1fd6186c0 100644
--- a/lib/base/src/main/java/com/blankj/base/BaseApplication.java
+++ b/lib/base/src/main/java/com/blankj/base/BaseApplication.java
@@ -2,7 +2,8 @@
import android.app.Application;
import android.content.Context;
-import android.support.multidex.MultiDex;
+
+import androidx.multidex.MultiDex;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.CrashUtils;
@@ -74,15 +75,16 @@ public String format(ArrayList arrayList) {
return "LogUtils Formatter ArrayList { " + arrayList.toString() + " }";
}
})
- .setFileWriter(null);
+ .addFileExtraHead("ExtraKey", "ExtraValue");
LogUtils.i(config.toString());
}
private void initCrash() {
CrashUtils.init(new CrashUtils.OnCrashListener() {
@Override
- public void onCrash(String crashInfo, Throwable e) {
- LogUtils.e(crashInfo);
+ public void onCrash(CrashUtils.CrashInfo crashInfo) {
+ crashInfo.addExtraHead("extraKey", "extraValue");
+ LogUtils.e(crashInfo.toString());
AppUtils.relaunchApp();
}
});
diff --git a/lib/base/src/main/java/com/blankj/base/BaseFragment.java b/lib/base/src/main/java/com/blankj/base/BaseFragment.java
index 2ff0a90913..ab2b8877fe 100644
--- a/lib/base/src/main/java/com/blankj/base/BaseFragment.java
+++ b/lib/base/src/main/java/com/blankj/base/BaseFragment.java
@@ -2,13 +2,6 @@
import android.content.Context;
import android.os.Bundle;
-import android.support.annotation.IdRes;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentTransaction;
-import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -17,6 +10,14 @@
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ClickUtils;
+import androidx.annotation.IdRes;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+
/**
*
* author: Blankj
@@ -89,7 +90,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
} else {
ft.show(this);
}
- ft.commitAllowingStateLoss();
+ ft.commitNowAllowingStateLoss();
}
Bundle bundle = getArguments();
initData(bundle);
diff --git a/lib/base/src/main/java/com/blankj/base/IBaseView.java b/lib/base/src/main/java/com/blankj/base/IBaseView.java
index 282649b774..821cbf4399 100644
--- a/lib/base/src/main/java/com/blankj/base/IBaseView.java
+++ b/lib/base/src/main/java/com/blankj/base/IBaseView.java
@@ -1,11 +1,12 @@
package com.blankj.base;
import android.os.Bundle;
-import android.support.annotation.LayoutRes;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.view.View;
+import androidx.annotation.LayoutRes;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
/**
*
diff --git a/lib/base/src/main/java/com/blankj/base/dialog/BaseDialog.java b/lib/base/src/main/java/com/blankj/base/dialog/BaseDialog.java
index 274f451a56..1599d8becc 100644
--- a/lib/base/src/main/java/com/blankj/base/dialog/BaseDialog.java
+++ b/lib/base/src/main/java/com/blankj/base/dialog/BaseDialog.java
@@ -4,13 +4,14 @@
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
-import android.support.annotation.NonNull;
import android.view.View;
import android.view.Window;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ThreadUtils;
+import androidx.annotation.NonNull;
+
/**
*
* author: blankj
diff --git a/lib/base/src/main/java/com/blankj/base/dialog/BaseDialogFragment.java b/lib/base/src/main/java/com/blankj/base/dialog/BaseDialogFragment.java
index d83dc5cc32..e115e78878 100644
--- a/lib/base/src/main/java/com/blankj/base/dialog/BaseDialogFragment.java
+++ b/lib/base/src/main/java/com/blankj/base/dialog/BaseDialogFragment.java
@@ -6,12 +6,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v4.app.DialogFragment;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -21,6 +15,13 @@
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ThreadUtils;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.DialogFragment;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+
/**
*
* author: blankj
diff --git a/lib/base/src/main/java/com/blankj/base/dialog/DialogCallback.java b/lib/base/src/main/java/com/blankj/base/dialog/DialogCallback.java
index 7d1c6e632a..defd34483f 100644
--- a/lib/base/src/main/java/com/blankj/base/dialog/DialogCallback.java
+++ b/lib/base/src/main/java/com/blankj/base/dialog/DialogCallback.java
@@ -2,9 +2,10 @@
import android.app.Activity;
import android.app.Dialog;
-import android.support.annotation.NonNull;
import android.view.Window;
+import androidx.annotation.NonNull;
+
/**
*
* author: blankj
diff --git a/lib/base/src/main/java/com/blankj/base/mvp/BaseModel.java b/lib/base/src/main/java/com/blankj/base/mvp/BaseModel.java
index cbdd94c2be..b48ed32f23 100644
--- a/lib/base/src/main/java/com/blankj/base/mvp/BaseModel.java
+++ b/lib/base/src/main/java/com/blankj/base/mvp/BaseModel.java
@@ -1,10 +1,8 @@
package com.blankj.base.mvp;
-import com.blankj.utilcode.util.ThreadUtils;
-import com.blankj.utilcode.util.ToastUtils;
+import android.util.Log;
-import java.util.ArrayList;
-import java.util.List;
+import androidx.annotation.CallSuper;
/**
*
@@ -16,24 +14,12 @@
*/
public abstract class BaseModel {
- private List mTasks = new ArrayList<>();
+ private static final String TAG = BaseView.TAG;
- public abstract void onCreateModel();
+ public abstract void onCreate();
- public abstract void onDestroyModel();
-
- public ThreadUtils.Task addAutoDestroyTask(ThreadUtils.Task task) {
- if (task == null) return null;
- mTasks.add(task);
- return task;
- }
-
- void destroy() {
- onDestroyModel();
- for (ThreadUtils.Task task : mTasks) {
- if (task == null) continue;
- task.cancel();
- ToastUtils.showLong("Mvp Task Canceled.");
- }
+ @CallSuper
+ public void onDestroy() {
+ Log.i(TAG, "destroy model: " + getClass().getSimpleName());
}
}
diff --git a/lib/base/src/main/java/com/blankj/base/mvp/BasePresenter.java b/lib/base/src/main/java/com/blankj/base/mvp/BasePresenter.java
index 7365c3490a..32e672417b 100644
--- a/lib/base/src/main/java/com/blankj/base/mvp/BasePresenter.java
+++ b/lib/base/src/main/java/com/blankj/base/mvp/BasePresenter.java
@@ -1,16 +1,14 @@
package com.blankj.base.mvp;
-import android.app.Activity;
-import android.arch.lifecycle.Lifecycle;
-import android.support.annotation.NonNull;
-
-import com.blankj.utilcode.util.ActivityUtils;
-import com.blankj.utilcode.util.LogUtils;
-import com.blankj.utilcode.util.Utils;
+import android.util.Log;
import java.util.HashMap;
import java.util.Map;
+import androidx.annotation.CallSuper;
+import androidx.lifecycle.ViewModel;
+import androidx.lifecycle.ViewModelProvider;
+
/**
*
* author: blankj
@@ -19,17 +17,19 @@
* desc :
*
*/
-public abstract class BasePresenter extends Utils.ActivityLifecycleCallbacks {
+public abstract class BasePresenter {
+
+ private static final String TAG = BaseView.TAG;
- private V mView;
- private Map mModelMap = new HashMap<>();
+ private V mView;
+ private Map, BaseModel> mModelMap = new HashMap<>();
+ private boolean isAlive = true;
- public abstract void onAttachView();
+ public abstract void onBindView();
void bindView(V view) {
this.mView = view;
- onAttachView();
- ActivityUtils.addActivityLifecycleCallbacks(mView.getActivity(), this);
+ onBindView();
}
public V getView() {
@@ -45,35 +45,29 @@ public M getModel(Class modelClass) {
try {
M model = modelClass.newInstance();
mModelMap.put(modelClass, model);
- model.onCreateModel();
+ model.onCreate();
return model;
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ Log.e("BasePresenter", "getModel", e);
} catch (InstantiationException e) {
- e.printStackTrace();
+ Log.e("BasePresenter", "getModel", e);
}
return null;
}
- @Override
- public void onLifecycleChanged(@NonNull Activity activity, Lifecycle.Event event) {
- super.onLifecycleChanged(activity, event);
- if (event == Lifecycle.Event.ON_DESTROY) {
- destroyPresenter();
- }
- LogUtils.i("onLifecycleChanged: " + event);
- }
-
- private void destroyPresenter() {
- if (mView != null) {
- mView.mPresenterMap.remove(this.getClass());
- mView.onDestroyView();
- }
+ @CallSuper
+ public void onDestroy() {
+ Log.i(TAG, "destroy presenter: " + getClass().getSimpleName());
+ isAlive = false;
for (BaseModel model : mModelMap.values()) {
if (model != null) {
- model.destroy();
+ model.onDestroy();
}
}
mModelMap.clear();
}
+
+ public boolean isAlive() {
+ return isAlive;
+ }
}
diff --git a/lib/base/src/main/java/com/blankj/base/mvp/BaseView.java b/lib/base/src/main/java/com/blankj/base/mvp/BaseView.java
index a870e06d82..a68909d01f 100644
--- a/lib/base/src/main/java/com/blankj/base/mvp/BaseView.java
+++ b/lib/base/src/main/java/com/blankj/base/mvp/BaseView.java
@@ -1,17 +1,17 @@
package com.blankj.base.mvp;
-import android.app.Activity;
-import android.arch.lifecycle.Lifecycle;
-import android.support.annotation.NonNull;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentActivity;
-
-import com.blankj.utilcode.util.ActivityUtils;
-import com.blankj.utilcode.util.Utils;
+import android.util.Log;
import java.util.HashMap;
import java.util.Map;
+import androidx.annotation.CallSuper;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+
/**
*
* author: blankj
@@ -20,45 +20,95 @@
* desc :
*
*/
-public abstract class BaseView {
+public class BaseView implements LifecycleObserver {
+
+ public static final String TAG = "UtilsMVP";
- private FragmentActivity mActivity;
- private Fragment mFragment;
- Map> mPresenterMap = new HashMap<>();
+ private FragmentActivity mActivity;
+ private Fragment mFragment;
+ private Lifecycle mLifecycle;
+ private Map, BasePresenter> mPresenterMap = new HashMap<>();
- public abstract void onDestroyView();
+ public BaseView(Fragment fragment) {
+ mFragment = fragment;
+ mActivity = fragment.getActivity();
+ mLifecycle = mFragment.getLifecycle();
+ addLifecycle(this);
+ }
public BaseView(FragmentActivity activity) {
mActivity = activity;
+ mLifecycle = mActivity.getLifecycle();
+ addLifecycle(this);
}
- public BaseView(Fragment fragment) {
- mFragment = fragment;
- mActivity = fragment.getActivity();
+ public BaseView(Lifecycle lifecycle) {
+ mLifecycle = lifecycle;
+ addLifecycle(this);
}
public T getActivity() {
+ if (mActivity == null) {
+ return null;
+ }
//noinspection unchecked
return (T) mActivity;
}
public T getFragment() {
+ if (mFragment == null) {
+ return null;
+ }
//noinspection unchecked
return (T) mFragment;
}
- public void addPresenter(BasePresenter presenter) {
+ public V addPresenter(BasePresenter presenter) {
+ if (presenter == null) return (V) this;
mPresenterMap.put(presenter.getClass(), presenter);
//noinspection unchecked
presenter.bindView((V) this);
+ return (V) this;
}
public > P getPresenter(Class
presenterClass) {
+ if (presenterClass == null) {
+ throw new IllegalArgumentException("presenterClass is null!");
+ }
BasePresenter basePresenter = mPresenterMap.get(presenterClass);
- if (basePresenter != null) {
- //noinspection unchecked
- return (P) basePresenter;
+ if (basePresenter == null) {
+ throw new IllegalArgumentException("presenter of <" + presenterClass.getSimpleName() + "> is not added!");
+ }
+ //noinspection unchecked
+ return (P) basePresenter;
+ }
+
+ @CallSuper
+ @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
+ public void onDestroy() {
+ Log.i(TAG, "destroy view: " + getClass().getSimpleName());
+ removeLifecycle(this);
+ for (BasePresenter presenter : mPresenterMap.values()) {
+ if (presenter != null) {
+ presenter.onDestroy();
+ }
+ }
+ mPresenterMap.clear();
+ }
+
+ private void addLifecycle(LifecycleObserver observer) {
+ if (mLifecycle == null) {
+ Log.w(TAG, "addLifecycle: mLifecycle is null");
+ return;
+ }
+ mLifecycle.addObserver(observer);
+ }
+
+ private void removeLifecycle(LifecycleObserver observer) {
+ if (mLifecycle == null) {
+ Log.w(TAG, "removeLifecycle: mLifecycle is null");
+ return;
}
- return null;
+ mLifecycle.removeObserver(observer);
}
}
diff --git a/lib/base/src/main/java/com/blankj/base/rv/BaseItem.java b/lib/base/src/main/java/com/blankj/base/rv/BaseItem.java
index cb93770b3a..b0d6de04fa 100644
--- a/lib/base/src/main/java/com/blankj/base/rv/BaseItem.java
+++ b/lib/base/src/main/java/com/blankj/base/rv/BaseItem.java
@@ -1,8 +1,5 @@
package com.blankj.base.rv;
-import android.support.annotation.LayoutRes;
-import android.support.annotation.NonNull;
-import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
@@ -11,6 +8,10 @@
import java.util.List;
+import androidx.annotation.LayoutRes;
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
/**
*
* author: Blankj
@@ -23,6 +24,7 @@ public abstract class BaseItem {
private static final SparseIntArray LAYOUT_SPARSE_ARRAY = new SparseIntArray();
private static final SparseArray VIEW_SPARSE_ARRAY = new SparseArray<>();
+ public boolean isBindViewHolder = false;
static ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
int layoutByType = LAYOUT_SPARSE_ARRAY.get(viewType, -1);
@@ -42,6 +44,7 @@ public void partialUpdate(List
- * china unicom: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186
- * china telecom: 133, 153, 173, 177, 180, 181, 189, 199, 191
+ * china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 165, 172, 178, 182, 183, 184, 187, 188, 195, 197, 198
+ * china unicom: 130, 131, 132, 145, 155, 156, 166, 167, 175, 176, 185, 186, 196
+ * china telecom: 133, 149, 153, 162, 173, 177, 180, 181, 189, 190, 191, 199
+ * china broadcasting: 192
* global star: 1349
- * virtual operator: 170
+ * virtual operator: 170, 171
*/
- public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[57])|(15[0-35-9])|(16[6])|(17[0135-8])|(18[0-9])|(19[189]))\\d{8}$";
+ public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[579])|(15[0-35-9])|(16[2567])|(17[0-35-8])|(18[0-9])|(19[0-35-9]))\\d{8}$";
/**
* Regex of telephone number.
*/
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/constant/TimeConstants.java b/lib/utilcode/src/main/java/com/blankj/utilcode/constant/TimeConstants.java
index 9932037bf8..45090576e3 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/constant/TimeConstants.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/constant/TimeConstants.java
@@ -1,6 +1,6 @@
package com.blankj.utilcode.constant;
-import android.support.annotation.IntDef;
+import androidx.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java
index 2a5cc80f3c..d49ce6ff06 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java
@@ -10,12 +10,6 @@
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
-import android.support.annotation.AnimRes;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v4.app.ActivityOptionsCompat;
-import android.support.v4.app.Fragment;
-import android.support.v4.util.Pair;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -25,6 +19,13 @@
import java.util.ArrayList;
import java.util.List;
+import androidx.annotation.AnimRes;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.core.app.ActivityOptionsCompat;
+import androidx.core.util.Pair;
+import androidx.fragment.app.Fragment;
+
/**
*
* author: Blankj
@@ -39,23 +40,41 @@ private ActivityUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
+ /**
+ * Add callbacks of activity lifecycle.
+ *
+ * @param callbacks The callbacks.
+ */
+ public static void addActivityLifecycleCallbacks(@Nullable final Utils.ActivityLifecycleCallbacks callbacks) {
+ UtilsBridge.addActivityLifecycleCallbacks(callbacks);
+ }
+
/**
* Add callbacks of activity lifecycle.
*
* @param activity The activity.
* @param callbacks The callbacks.
*/
- public static void addActivityLifecycleCallbacks(final Activity activity,
- final Utils.ActivityLifecycleCallbacks callbacks) {
+ public static void addActivityLifecycleCallbacks(@Nullable final Activity activity,
+ @Nullable final Utils.ActivityLifecycleCallbacks callbacks) {
UtilsBridge.addActivityLifecycleCallbacks(activity, callbacks);
}
+ /**
+ * Remove callbacks of activity lifecycle.
+ *
+ * @param callbacks The callbacks.
+ */
+ public static void removeActivityLifecycleCallbacks(@Nullable final Utils.ActivityLifecycleCallbacks callbacks) {
+ UtilsBridge.removeActivityLifecycleCallbacks(callbacks);
+ }
+
/**
* Remove callbacks of activity lifecycle.
*
* @param activity The activity.
*/
- public static void removeActivityLifecycleCallbacks(final Activity activity) {
+ public static void removeActivityLifecycleCallbacks(@Nullable final Activity activity) {
UtilsBridge.removeActivityLifecycleCallbacks(activity);
}
@@ -65,8 +84,8 @@ public static void removeActivityLifecycleCallbacks(final Activity activity) {
* @param activity The activity.
* @param callbacks The callbacks.
*/
- public static void removeActivityLifecycleCallbacks(final Activity activity,
- final Utils.ActivityLifecycleCallbacks callbacks) {
+ public static void removeActivityLifecycleCallbacks(@Nullable final Activity activity,
+ @Nullable final Utils.ActivityLifecycleCallbacks callbacks) {
UtilsBridge.removeActivityLifecycleCallbacks(activity, callbacks);
}
@@ -76,13 +95,16 @@ public static void removeActivityLifecycleCallbacks(final Activity activity,
* @param context The context.
* @return the activity by context.
*/
- public static Activity getActivityByContext(Context context) {
+ @Nullable
+ public static Activity getActivityByContext(@Nullable Context context) {
+ if (context == null) return null;
Activity activity = getActivityByContextInner(context);
if (!isActivityAlive(activity)) return null;
return activity;
}
- private static Activity getActivityByContextInner(Context context) {
+ @Nullable
+ private static Activity getActivityByContextInner(@Nullable Context context) {
if (context == null) return null;
List list = new ArrayList<>();
while (context instanceof ContextWrapper) {
@@ -104,7 +126,8 @@ private static Activity getActivityByContextInner(Context context) {
return null;
}
- private static Activity getActivityFromDecorContext(Context context) {
+ @Nullable
+ private static Activity getActivityFromDecorContext(@Nullable Context context) {
if (context == null) return null;
if (context.getClass().getName().equals("com.android.internal.policy.DecorContext")) {
try {
@@ -141,7 +164,7 @@ public static boolean isActivityExists(@NonNull final String pkg,
* @param clz The activity class.
*/
public static void startActivity(@NonNull final Class extends Activity> clz) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, null, context.getPackageName(), clz.getName(), null);
}
@@ -153,7 +176,7 @@ public static void startActivity(@NonNull final Class extends Activity> clz) {
*/
public static void startActivity(@NonNull final Class extends Activity> clz,
@Nullable final Bundle options) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, null, context.getPackageName(), clz.getName(), options);
}
@@ -169,7 +192,7 @@ public static void startActivity(@NonNull final Class extends Activity> clz,
public static void startActivity(@NonNull final Class extends Activity> clz,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, null, context.getPackageName(), clz.getName(),
getOptionsBundle(context, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
@@ -245,7 +268,7 @@ public static void startActivity(@NonNull final Activity activity,
*/
public static void startActivity(@NonNull final Bundle extras,
@NonNull final Class extends Activity> clz) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, extras, context.getPackageName(), clz.getName(), null);
}
@@ -259,7 +282,7 @@ public static void startActivity(@NonNull final Bundle extras,
public static void startActivity(@NonNull final Bundle extras,
@NonNull final Class extends Activity> clz,
@Nullable final Bundle options) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, extras, context.getPackageName(), clz.getName(), options);
}
@@ -277,7 +300,7 @@ public static void startActivity(@NonNull final Bundle extras,
@NonNull final Class extends Activity> clz,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, extras, context.getPackageName(), clz.getName(),
getOptionsBundle(context, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
@@ -361,7 +384,7 @@ public static void startActivity(@NonNull final Bundle extras,
*/
public static void startActivity(@NonNull final String pkg,
@NonNull final String cls) {
- startActivity(UtilsBridge.getTopActivityOrApp(), null, pkg, cls, null);
+ startActivity(getTopActivityOrApp(), null, pkg, cls, null);
}
/**
@@ -374,7 +397,7 @@ public static void startActivity(@NonNull final String pkg,
public static void startActivity(@NonNull final String pkg,
@NonNull final String cls,
@Nullable final Bundle options) {
- startActivity(UtilsBridge.getTopActivityOrApp(), null, pkg, cls, options);
+ startActivity(getTopActivityOrApp(), null, pkg, cls, options);
}
/**
@@ -391,7 +414,7 @@ public static void startActivity(@NonNull final String pkg,
@NonNull final String cls,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, null, pkg, cls, getOptionsBundle(context, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
((Activity) context).overridePendingTransition(enterAnim, exitAnim);
@@ -474,7 +497,7 @@ public static void startActivity(@NonNull final Activity activity,
public static void startActivity(@NonNull final Bundle extras,
@NonNull final String pkg,
@NonNull final String cls) {
- startActivity(UtilsBridge.getTopActivityOrApp(), extras, pkg, cls, null);
+ startActivity(getTopActivityOrApp(), extras, pkg, cls, null);
}
/**
@@ -489,7 +512,7 @@ public static void startActivity(@NonNull final Bundle extras,
@NonNull final String pkg,
@NonNull final String cls,
@Nullable final Bundle options) {
- startActivity(UtilsBridge.getTopActivityOrApp(), extras, pkg, cls, options);
+ startActivity(getTopActivityOrApp(), extras, pkg, cls, options);
}
/**
@@ -508,7 +531,7 @@ public static void startActivity(@NonNull final Bundle extras,
@NonNull final String cls,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivity(context, extras, pkg, cls, getOptionsBundle(context, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
((Activity) context).overridePendingTransition(enterAnim, exitAnim);
@@ -595,7 +618,7 @@ public static void startActivity(@NonNull final Bundle extras,
* @return {@code true}: success
{@code false}: fail
*/
public static boolean startActivity(@NonNull final Intent intent) {
- return startActivity(intent, UtilsBridge.getTopActivityOrApp(), null);
+ return startActivity(intent, getTopActivityOrApp(), null);
}
/**
@@ -607,7 +630,7 @@ public static boolean startActivity(@NonNull final Intent intent) {
*/
public static boolean startActivity(@NonNull final Intent intent,
@Nullable final Bundle options) {
- return startActivity(intent, UtilsBridge.getTopActivityOrApp(), options);
+ return startActivity(intent, getTopActivityOrApp(), options);
}
/**
@@ -623,7 +646,7 @@ public static boolean startActivity(@NonNull final Intent intent,
public static boolean startActivity(@NonNull final Intent intent,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
boolean isSuccess = startActivity(intent, context, getOptionsBundle(context, enterAnim, exitAnim));
if (isSuccess) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
@@ -1315,7 +1338,7 @@ public static void startActivityForResult(@NonNull final Fragment fragment,
* @param intents The descriptions of the activities to start.
*/
public static void startActivities(@NonNull final Intent[] intents) {
- startActivities(intents, UtilsBridge.getTopActivityOrApp(), null);
+ startActivities(intents, getTopActivityOrApp(), null);
}
/**
@@ -1326,7 +1349,7 @@ public static void startActivities(@NonNull final Intent[] intents) {
*/
public static void startActivities(@NonNull final Intent[] intents,
@Nullable final Bundle options) {
- startActivities(intents, UtilsBridge.getTopActivityOrApp(), options);
+ startActivities(intents, getTopActivityOrApp(), options);
}
/**
@@ -1341,7 +1364,7 @@ public static void startActivities(@NonNull final Intent[] intents,
public static void startActivities(@NonNull final Intent[] intents,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
- Context context = UtilsBridge.getTopActivityOrApp();
+ Context context = getTopActivityOrApp();
startActivities(intents, context, getOptionsBundle(context, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
((Activity) context).overridePendingTransition(enterAnim, exitAnim);
@@ -1888,6 +1911,7 @@ public static void finishAllActivitiesExceptNewest(@AnimRes final int enterAnim,
* @param activity The activity.
* @return the icon of activity
*/
+ @Nullable
public static Drawable getActivityIcon(@NonNull final Activity activity) {
return getActivityIcon(activity.getComponentName());
}
@@ -1898,6 +1922,7 @@ public static Drawable getActivityIcon(@NonNull final Activity activity) {
* @param clz The activity class.
* @return the icon of activity
*/
+ @Nullable
public static Drawable getActivityIcon(@NonNull final Class extends Activity> clz) {
return getActivityIcon(new ComponentName(Utils.getApp(), clz));
}
@@ -1908,6 +1933,7 @@ public static Drawable getActivityIcon(@NonNull final Class extends Activity>
* @param activityName The name of activity.
* @return the icon of activity
*/
+ @Nullable
public static Drawable getActivityIcon(@NonNull final ComponentName activityName) {
PackageManager pm = Utils.getApp().getPackageManager();
try {
@@ -1924,6 +1950,7 @@ public static Drawable getActivityIcon(@NonNull final ComponentName activityName
* @param activity The activity.
* @return the logo of activity
*/
+ @Nullable
public static Drawable getActivityLogo(@NonNull final Activity activity) {
return getActivityLogo(activity.getComponentName());
}
@@ -1934,6 +1961,7 @@ public static Drawable getActivityLogo(@NonNull final Activity activity) {
* @param clz The activity class.
* @return the logo of activity
*/
+ @Nullable
public static Drawable getActivityLogo(@NonNull final Class extends Activity> clz) {
return getActivityLogo(new ComponentName(Utils.getApp(), clz));
}
@@ -1944,6 +1972,7 @@ public static Drawable getActivityLogo(@NonNull final Class extends Activity>
* @param activityName The name of activity.
* @return the logo of activity
*/
+ @Nullable
public static Drawable getActivityLogo(@NonNull final ComponentName activityName) {
PackageManager pm = Utils.getApp().getPackageManager();
try {
@@ -1968,28 +1997,22 @@ private static void startActivity(final Context context,
private static boolean startActivity(final Intent intent,
final Context context,
final Bundle options) {
- if (!isIntentAvailable(intent)) {
- Log.e("ActivityUtils", "intent is unavailable");
- return false;
- }
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
- if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- context.startActivity(intent, options);
- } else {
- context.startActivity(intent);
+ try {
+ if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ context.startActivity(intent, options);
+ } else {
+ context.startActivity(intent);
+ }
+ } catch (Exception e) {
+ Log.e("ActivityUtils", "An exception occurred in startActivity, error message: " + e.getLocalizedMessage());
+ return false;
}
return true;
}
- private static boolean isIntentAvailable(final Intent intent) {
- return Utils.getApp()
- .getPackageManager()
- .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
- .size() > 0;
- }
-
private static boolean startActivityForResult(final Activity activity,
final Bundle extras,
final String pkg,
@@ -2006,15 +2029,16 @@ private static boolean startActivityForResult(final Intent intent,
final Activity activity,
final int requestCode,
@Nullable final Bundle options) {
- if (!isIntentAvailable(intent)) {
- Log.e("ActivityUtils", "intent is unavailable");
+ try {
+ if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ activity.startActivityForResult(intent, requestCode, options);
+ } else {
+ activity.startActivityForResult(intent, requestCode);
+ }
+ } catch (Exception e) {
+ Log.e("ActivityUtils", "An exception occurred in startActivityForResult, error message: " + e.getLocalizedMessage());
return false;
}
- if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- activity.startActivityForResult(intent, requestCode, options);
- } else {
- activity.startActivityForResult(intent, requestCode);
- }
return true;
}
@@ -2049,18 +2073,19 @@ private static boolean startActivityForResult(final Intent intent,
final Fragment fragment,
final int requestCode,
@Nullable final Bundle options) {
- if (!isIntentAvailable(intent)) {
- Log.e("ActivityUtils", "intent is unavailable");
- return false;
- }
if (fragment.getActivity() == null) {
Log.e("ActivityUtils", "Fragment " + fragment + " not attached to Activity");
return false;
}
- if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- fragment.startActivityForResult(intent, requestCode, options);
- } else {
- fragment.startActivityForResult(intent, requestCode);
+ try {
+ if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ fragment.startActivityForResult(intent, requestCode, options);
+ } else {
+ fragment.startActivityForResult(intent, requestCode);
+ }
+ } catch (Exception e) {
+ Log.e("ActivityUtils", "An exception occurred in fragment.startActivityForResult, error message: " + e.getLocalizedMessage());
+ return false;
}
return true;
}
@@ -2099,4 +2124,13 @@ private static Bundle getOptionsBundle(final Activity activity,
}
return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pairs).toBundle();
}
+
+ private static Context getTopActivityOrApp() {
+ if (UtilsBridge.isAppForeground()) {
+ Activity topActivity = getTopActivity();
+ return topActivity == null ? Utils.getApp() : topActivity;
+ } else {
+ return Utils.getApp();
+ }
+ }
}
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/AdaptScreenUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/AdaptScreenUtils.java
index 5a47ecc9d8..aef62a44dc 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/AdaptScreenUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/AdaptScreenUtils.java
@@ -2,12 +2,13 @@
import android.content.res.Resources;
import android.util.DisplayMetrics;
-import android.util.Log;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
+import androidx.annotation.NonNull;
+
/**
*
* author: Blankj
@@ -27,7 +28,8 @@ private AdaptScreenUtils() {
/**
* Adapt for the horizontal screen, and call it in {@link android.app.Activity#getResources()}.
*/
- public static Resources adaptWidth(final Resources resources, final int designWidth) {
+ @NonNull
+ public static Resources adaptWidth(@NonNull final Resources resources, final int designWidth) {
float newXdpi = (resources.getDisplayMetrics().widthPixels * 72f) / designWidth;
applyDisplayMetrics(resources, newXdpi);
return resources;
@@ -36,14 +38,16 @@ public static Resources adaptWidth(final Resources resources, final int designWi
/**
* Adapt for the vertical screen, and call it in {@link android.app.Activity#getResources()}.
*/
- public static Resources adaptHeight(final Resources resources, final int designHeight) {
+ @NonNull
+ public static Resources adaptHeight(@NonNull final Resources resources, final int designHeight) {
return adaptHeight(resources, designHeight, false);
}
/**
* Adapt for the vertical screen, and call it in {@link android.app.Activity#getResources()}.
*/
- public static Resources adaptHeight(final Resources resources, final int designHeight, final boolean includeNavBar) {
+ @NonNull
+ public static Resources adaptHeight(@NonNull final Resources resources, final int designHeight, final boolean includeNavBar) {
float screenHeight = (resources.getDisplayMetrics().heightPixels
+ (includeNavBar ? getNavBarHeight(resources) : 0)) * 72f;
float newXdpi = screenHeight / designHeight;
@@ -51,7 +55,7 @@ public static Resources adaptHeight(final Resources resources, final int designH
return resources;
}
- private static int getNavBarHeight(final Resources resources) {
+ private static int getNavBarHeight(@NonNull final Resources resources) {
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId != 0) {
return resources.getDimensionPixelSize(resourceId);
@@ -64,7 +68,8 @@ private static int getNavBarHeight(final Resources resources) {
* @param resources The resources.
* @return the resource
*/
- public static Resources closeAdapt(final Resources resources) {
+ @NonNull
+ public static Resources closeAdapt(@NonNull final Resources resources) {
float newXdpi = Resources.getSystem().getDisplayMetrics().density * 72f;
applyDisplayMetrics(resources, newXdpi);
return resources;
@@ -92,7 +97,7 @@ public static int px2Pt(final float pxValue) {
return (int) (pxValue * 72 / metrics.xdpi + 0.5);
}
- private static void applyDisplayMetrics(final Resources resources, final float newXdpi) {
+ private static void applyDisplayMetrics(@NonNull final Resources resources, final float newXdpi) {
resources.getDisplayMetrics().xdpi = newXdpi;
Utils.getApp().getResources().getDisplayMetrics().xdpi = newXdpi;
applyOtherDisplayMetrics(resources, newXdpi);
@@ -145,7 +150,7 @@ private static void applyMetricsFields(final Resources resources, final float ne
DisplayMetrics dm = (DisplayMetrics) metricsField.get(resources);
if (dm != null) dm.xdpi = newXdpi;
} catch (Exception e) {
- Log.e("AdaptScreenUtils", "applyMetricsFields: " + e);
+ e.printStackTrace();
}
}
}
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ApiUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ApiUtils.java
index f99bc77f19..2fb3a88b74 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ApiUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ApiUtils.java
@@ -1,6 +1,5 @@
package com.blankj.utilcode.util;
-import android.support.annotation.NonNull;
import android.util.Log;
import java.lang.annotation.ElementType;
@@ -11,6 +10,9 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
/**
*
* author: Blankj
@@ -47,14 +49,17 @@ private void registerImpl(Class implClass) {
* @param The type.
* @return the api
*/
+ @Nullable
public static T getApi(@NonNull final Class apiClass) {
return getInstance().getApiInner(apiClass);
}
- public static void register(Class extends BaseApi> implClass) {
+ public static void register(@Nullable Class extends BaseApi> implClass) {
+ if (implClass == null) return;
getInstance().registerImpl(implClass);
}
+ @NonNull
public static String toString_() {
return getInstance().toString();
}
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java
index 55923524dc..3a07653fb0 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java
@@ -1,6 +1,5 @@
package com.blankj.utilcode.util;
-import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
@@ -9,11 +8,15 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
+import android.content.pm.SigningInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
-import android.support.annotation.NonNull;
+import android.os.Build;
import android.util.Log;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -142,8 +145,14 @@ public static boolean isAppDebug() {
*/
public static boolean isAppDebug(final String packageName) {
if (UtilsBridge.isSpace(packageName)) return false;
- ApplicationInfo ai = Utils.getApp().getApplicationInfo();
- return ai != null && (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
+ try {
+ PackageManager pm = Utils.getApp().getPackageManager();
+ ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
+ return (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ }
}
/**
@@ -166,7 +175,7 @@ public static boolean isAppSystem(final String packageName) {
try {
PackageManager pm = Utils.getApp().getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
- return ai != null && (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+ return (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return false;
@@ -179,18 +188,7 @@ public static boolean isAppSystem(final String packageName) {
* @return {@code true}: yes
{@code false}: no
*/
public static boolean isAppForeground() {
- ActivityManager am = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE);
- if (am == null) return false;
- List info = am.getRunningAppProcesses();
- if (info == null || info.size() == 0) return false;
- for (ActivityManager.RunningAppProcessInfo aInfo : info) {
- if (aInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
- if (aInfo.processName.equals(Utils.getApp().getPackageName())) {
- return true;
- }
- }
- }
- return false;
+ return UtilsBridge.isAppForeground();
}
/**
@@ -213,8 +211,6 @@ public static boolean isAppForeground(@NonNull final String pkgName) {
*/
public static boolean isAppRunning(final String pkgName) {
if (UtilsBridge.isSpace(pkgName)) return false;
- ApplicationInfo ai = Utils.getApp().getApplicationInfo();
- int uid = ai.uid;
ActivityManager am = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE);
if (am != null) {
List taskInfo = am.getRunningTasks(Integer.MAX_VALUE);
@@ -230,7 +226,7 @@ public static boolean isAppRunning(final String pkgName) {
List serviceInfo = am.getRunningServices(Integer.MAX_VALUE);
if (serviceInfo != null && serviceInfo.size() > 0) {
for (ActivityManager.RunningServiceInfo aInfo : serviceInfo) {
- if (uid == aInfo.uid) {
+ if (pkgName.equals(aInfo.service.getPackageName())) {
return true;
}
}
@@ -338,6 +334,7 @@ public static void exitApp() {
*
* @return the application's icon
*/
+ @Nullable
public static Drawable getAppIcon() {
return getAppIcon(Utils.getApp().getPackageName());
}
@@ -348,6 +345,7 @@ public static Drawable getAppIcon() {
* @param packageName The name of the package.
* @return the application's icon
*/
+ @Nullable
public static Drawable getAppIcon(final String packageName) {
if (UtilsBridge.isSpace(packageName)) return null;
try {
@@ -387,11 +385,44 @@ public static int getAppIconId(final String packageName) {
}
}
+
+ /**
+ * Return true if this is the first ever time that the application is installed on the device.
+ *
+ * @return true if this is the first ever time that the application is installed on the device.
+ */
+ public static boolean isFirstTimeInstall() {
+ try {
+ long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(getAppPackageName(), 0).firstInstallTime;
+ long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(getAppPackageName(), 0).lastUpdateTime;
+ return firstInstallTime == lastUpdateTime;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * Return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.
+ *
+ * @return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.
+ */
+ public static boolean isAppUpgraded() {
+ try {
+ long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(getAppPackageName(), 0).firstInstallTime;
+ long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(getAppPackageName(), 0).lastUpdateTime;
+ return firstInstallTime != lastUpdateTime;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+
/**
* Return the application's package name.
*
* @return the application's package name
*/
+ @NonNull
public static String getAppPackageName() {
return Utils.getApp().getPackageName();
}
@@ -401,6 +432,7 @@ public static String getAppPackageName() {
*
* @return the application's name
*/
+ @NonNull
public static String getAppName() {
return getAppName(Utils.getApp().getPackageName());
}
@@ -411,12 +443,13 @@ public static String getAppName() {
* @param packageName The name of the package.
* @return the application's name
*/
+ @NonNull
public static String getAppName(final String packageName) {
if (UtilsBridge.isSpace(packageName)) return "";
try {
PackageManager pm = Utils.getApp().getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? null : pi.applicationInfo.loadLabel(pm).toString();
+ return pi == null ? "" : pi.applicationInfo.loadLabel(pm).toString();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "";
@@ -428,6 +461,7 @@ public static String getAppName(final String packageName) {
*
* @return the application's path
*/
+ @NonNull
public static String getAppPath() {
return getAppPath(Utils.getApp().getPackageName());
}
@@ -438,12 +472,13 @@ public static String getAppPath() {
* @param packageName The name of the package.
* @return the application's path
*/
+ @NonNull
public static String getAppPath(final String packageName) {
if (UtilsBridge.isSpace(packageName)) return "";
try {
PackageManager pm = Utils.getApp().getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? null : pi.applicationInfo.sourceDir;
+ return pi == null ? "" : pi.applicationInfo.sourceDir;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "";
@@ -455,6 +490,7 @@ public static String getAppPath(final String packageName) {
*
* @return the application's version name
*/
+ @NonNull
public static String getAppVersionName() {
return getAppVersionName(Utils.getApp().getPackageName());
}
@@ -465,12 +501,13 @@ public static String getAppVersionName() {
* @param packageName The name of the package.
* @return the application's version name
*/
+ @NonNull
public static String getAppVersionName(final String packageName) {
if (UtilsBridge.isSpace(packageName)) return "";
try {
PackageManager pm = Utils.getApp().getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? null : pi.versionName;
+ return pi == null ? "" : pi.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "";
@@ -504,13 +541,73 @@ public static int getAppVersionCode(final String packageName) {
}
}
+ /**
+ * Return the application's minimum sdk version code.
+ *
+ * @return the application's minimum sdk version code
+ */
+ public static int getAppMinSdkVersion() {
+ return getAppMinSdkVersion(Utils.getApp().getPackageName());
+ }
+
+ /**
+ * Return the application's minimum sdk version code.
+ *
+ * @param packageName The name of the package.
+ * @return the application's minimum sdk version code
+ */
+ public static int getAppMinSdkVersion(final String packageName) {
+ if (UtilsBridge.isSpace(packageName)) return -1;
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) return -1;
+ try {
+ PackageManager pm = Utils.getApp().getPackageManager();
+ PackageInfo pi = pm.getPackageInfo(packageName, 0);
+ if (null == pi) return -1;
+ ApplicationInfo ai = pi.applicationInfo;
+ return null == ai ? -1 : ai.minSdkVersion;
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ return -1;
+ }
+ }
+
+ /**
+ * Return the application's target sdk version code.
+ *
+ * @return the application's target sdk version code
+ */
+ public static int getAppTargetSdkVersion() {
+ return getAppTargetSdkVersion(Utils.getApp().getPackageName());
+ }
+
+ /**
+ * Return the application's target sdk version code.
+ *
+ * @param packageName The name of the package.
+ * @return the application's target sdk version code
+ */
+ public static int getAppTargetSdkVersion(final String packageName) {
+ if (UtilsBridge.isSpace(packageName)) return -1;
+ try {
+ PackageManager pm = Utils.getApp().getPackageManager();
+ PackageInfo pi = pm.getPackageInfo(packageName, 0);
+ if (null == pi) return -1;
+ ApplicationInfo ai = pi.applicationInfo;
+ return null == ai ? -1 : ai.targetSdkVersion;
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ return -1;
+ }
+ }
+
/**
* Return the application's signature.
*
* @return the application's signature
*/
- public static Signature[] getAppSignature() {
- return getAppSignature(Utils.getApp().getPackageName());
+ @Nullable
+ public static Signature[] getAppSignatures() {
+ return getAppSignatures(Utils.getApp().getPackageName());
}
/**
@@ -519,26 +616,69 @@ public static Signature[] getAppSignature() {
* @param packageName The name of the package.
* @return the application's signature
*/
- public static Signature[] getAppSignature(final String packageName) {
+ @Nullable
+ public static Signature[] getAppSignatures(final String packageName) {
if (UtilsBridge.isSpace(packageName)) return null;
try {
PackageManager pm = Utils.getApp().getPackageManager();
- @SuppressLint("PackageManagerGetSignatures")
- PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
- return pi == null ? null : pi.signatures;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES);
+ if (pi == null) return null;
+
+ SigningInfo signingInfo = pi.signingInfo;
+ if (signingInfo.hasMultipleSigners()) {
+ return signingInfo.getApkContentsSigners();
+ } else {
+ return signingInfo.getSigningCertificateHistory();
+ }
+ } else {
+ PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
+ if (pi == null) return null;
+
+ return pi.signatures;
+ }
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
+ /**
+ * Return the application's signature.
+ *
+ * @param file The file.
+ * @return the application's signature
+ */
+ @Nullable
+ public static Signature[] getAppSignatures(final File file) {
+ if (file == null) return null;
+ PackageManager pm = Utils.getApp().getPackageManager();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ PackageInfo pi = pm.getPackageArchiveInfo(file.getAbsolutePath(), PackageManager.GET_SIGNING_CERTIFICATES);
+ if (pi == null) return null;
+
+ SigningInfo signingInfo = pi.signingInfo;
+ if (signingInfo.hasMultipleSigners()) {
+ return signingInfo.getApkContentsSigners();
+ } else {
+ return signingInfo.getSigningCertificateHistory();
+ }
+ } else {
+ PackageInfo pi = pm.getPackageArchiveInfo(file.getAbsolutePath(), PackageManager.GET_SIGNATURES);
+ if (pi == null) return null;
+
+ return pi.signatures;
+ }
+ }
+
/**
* Return the application's signature for SHA1 value.
*
* @return the application's signature for SHA1 value
*/
- public static String getAppSignatureSHA1() {
- return getAppSignatureSHA1(Utils.getApp().getPackageName());
+ @NonNull
+ public static List getAppSignaturesSHA1() {
+ return getAppSignaturesSHA1(Utils.getApp().getPackageName());
}
/**
@@ -547,8 +687,9 @@ public static String getAppSignatureSHA1() {
* @param packageName The name of the package.
* @return the application's signature for SHA1 value
*/
- public static String getAppSignatureSHA1(final String packageName) {
- return getAppSignatureHash(packageName, "SHA1");
+ @NonNull
+ public static List getAppSignaturesSHA1(final String packageName) {
+ return getAppSignaturesHash(packageName, "SHA1");
}
/**
@@ -556,8 +697,9 @@ public static String getAppSignatureSHA1(final String packageName) {
*
* @return the application's signature for SHA256 value
*/
- public static String getAppSignatureSHA256() {
- return getAppSignatureSHA256(Utils.getApp().getPackageName());
+ @NonNull
+ public static List getAppSignaturesSHA256() {
+ return getAppSignaturesSHA256(Utils.getApp().getPackageName());
}
/**
@@ -566,8 +708,9 @@ public static String getAppSignatureSHA256() {
* @param packageName The name of the package.
* @return the application's signature for SHA256 value
*/
- public static String getAppSignatureSHA256(final String packageName) {
- return getAppSignatureHash(packageName, "SHA256");
+ @NonNull
+ public static List getAppSignaturesSHA256(final String packageName) {
+ return getAppSignaturesHash(packageName, "SHA256");
}
/**
@@ -575,8 +718,9 @@ public static String getAppSignatureSHA256(final String packageName) {
*
* @return the application's signature for MD5 value
*/
- public static String getAppSignatureMD5() {
- return getAppSignatureMD5(Utils.getApp().getPackageName());
+ @NonNull
+ public static List getAppSignaturesMD5() {
+ return getAppSignaturesMD5(Utils.getApp().getPackageName());
}
/**
@@ -585,11 +729,11 @@ public static String getAppSignatureMD5() {
* @param packageName The name of the package.
* @return the application's signature for MD5 value
*/
- public static String getAppSignatureMD5(final String packageName) {
- return getAppSignatureHash(packageName, "MD5");
+ @NonNull
+ public static List getAppSignaturesMD5(final String packageName) {
+ return getAppSignaturesHash(packageName, "MD5");
}
-
/**
* Return the application's user-ID.
*
@@ -610,16 +754,21 @@ public static int getAppUid(String pkgName) {
return Utils.getApp().getPackageManager().getApplicationInfo(pkgName, 0).uid;
} catch (Exception e) {
e.printStackTrace();
+ return -1;
}
- return -1;
}
- private static String getAppSignatureHash(final String packageName, final String algorithm) {
- if (UtilsBridge.isSpace(packageName)) return "";
- Signature[] signature = getAppSignature(packageName);
- if (signature == null || signature.length <= 0) return "";
- return UtilsBridge.bytes2HexString(UtilsBridge.hashTemplate(signature[0].toByteArray(), algorithm))
- .replaceAll("(?<=[0-9A-F]{2})[0-9A-F]{2}", ":$0");
+ private static List getAppSignaturesHash(final String packageName, final String algorithm) {
+ ArrayList result = new ArrayList<>();
+ if (UtilsBridge.isSpace(packageName)) return result;
+ Signature[] signatures = getAppSignatures(packageName);
+ if (signatures == null || signatures.length <= 0) return result;
+ for (Signature signature : signatures) {
+ String hash = UtilsBridge.bytes2HexString(UtilsBridge.hashTemplate(signature.toByteArray(), algorithm))
+ .replaceAll("(?<=[0-9A-F]{2})[0-9A-F]{2}", ":$0");
+ result.add(hash);
+ }
+ return result;
}
/**
@@ -631,11 +780,14 @@ private static String getAppSignatureHash(final String packageName, final String
* path of package
* version name
* version code
+ * minimum sdk version code
+ * target sdk version code
* is system
*
*
* @return the application's information
*/
+ @Nullable
public static AppInfo getAppInfo() {
return getAppInfo(Utils.getApp().getPackageName());
}
@@ -649,12 +801,15 @@ public static AppInfo getAppInfo() {
* path of package
* version name
* version code
+ * minimum sdk version code
+ * target sdk version code
* is system
*
*
* @param packageName The name of the package.
* @return the application's information
*/
+ @Nullable
public static AppInfo getAppInfo(final String packageName) {
try {
PackageManager pm = Utils.getApp().getPackageManager();
@@ -671,6 +826,7 @@ public static AppInfo getAppInfo(final String packageName) {
*
* @return the applications' information
*/
+ @NonNull
public static List getAppsInfo() {
List list = new ArrayList<>();
PackageManager pm = Utils.getApp().getPackageManager();
@@ -689,6 +845,7 @@ public static List getAppsInfo() {
*
* @return the application's package information
*/
+ @Nullable
public static AppUtils.AppInfo getApkInfo(final File apkFile) {
if (apkFile == null || !apkFile.isFile() || !apkFile.exists()) return null;
return getApkInfo(apkFile.getAbsolutePath());
@@ -699,6 +856,7 @@ public static AppUtils.AppInfo getApkInfo(final File apkFile) {
*
* @return the application's package information
*/
+ @Nullable
public static AppUtils.AppInfo getApkInfo(final String apkFilePath) {
if (UtilsBridge.isSpace(apkFilePath)) return null;
PackageManager pm = Utils.getApp().getPackageManager();
@@ -711,17 +869,41 @@ public static AppUtils.AppInfo getApkInfo(final String apkFilePath) {
return getBean(pm, pi);
}
+
+ /**
+ * Return whether the application was first installed.
+ *
+ * @return {@code true}: yes
{@code false}: no
+ */
+ public static boolean isFirstTimeInstalled() {
+ try {
+ PackageInfo pi = Utils.getApp().getPackageManager().getPackageInfo(Utils.getApp().getPackageName(), 0);
+ return pi.firstInstallTime == pi.lastUpdateTime;
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ return true;
+ }
+ }
+
private static AppInfo getBean(final PackageManager pm, final PackageInfo pi) {
if (pi == null) return null;
- ApplicationInfo ai = pi.applicationInfo;
+ String versionName = pi.versionName;
+ int versionCode = pi.versionCode;
String packageName = pi.packageName;
+ ApplicationInfo ai = pi.applicationInfo;
+ if (ai == null) {
+ return new AppInfo(packageName, "", null, "", versionName, versionCode, -1, -1, false);
+ }
String name = ai.loadLabel(pm).toString();
Drawable icon = ai.loadIcon(pm);
String packagePath = ai.sourceDir;
- String versionName = pi.versionName;
- int versionCode = pi.versionCode;
+ int minSdkVersion = -1;
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+ minSdkVersion = ai.minSdkVersion;
+ }
+ int targetSdkVersion = ai.targetSdkVersion;
boolean isSystem = (ApplicationInfo.FLAG_SYSTEM & ai.flags) != 0;
- return new AppInfo(packageName, name, icon, packagePath, versionName, versionCode, isSystem);
+ return new AppInfo(packageName, name, icon, packagePath, versionName, versionCode, minSdkVersion, targetSdkVersion, isSystem);
}
/**
@@ -729,13 +911,15 @@ private static AppInfo getBean(final PackageManager pm, final PackageInfo pi) {
*/
public static class AppInfo {
- private String packageName;
- private String name;
+ private String packageName;
+ private String name;
private Drawable icon;
- private String packagePath;
- private String versionName;
- private int versionCode;
- private boolean isSystem;
+ private String packagePath;
+ private String versionName;
+ private int versionCode;
+ private int minSdkVersion;
+ private int targetSdkVersion;
+ private boolean isSystem;
public Drawable getIcon() {
return icon;
@@ -793,18 +977,36 @@ public void setVersionName(final String versionName) {
this.versionName = versionName;
}
- public AppInfo(String packageName, String name, Drawable icon, String packagePath,
- String versionName, int versionCode, boolean isSystem) {
+ public int getMinSdkVersion() {
+ return minSdkVersion;
+ }
+
+ public void setMinSdkVersion(int minSdkVersion) {
+ this.minSdkVersion = minSdkVersion;
+ }
+
+ public int getTargetSdkVersion() {
+ return targetSdkVersion;
+ }
+
+ public void setTargetSdkVersion(int targetSdkVersion) {
+ this.targetSdkVersion = targetSdkVersion;
+ }
+
+ public AppInfo(String packageName, String name, Drawable icon, String packagePath, String versionName, int versionCode, int minSdkVersion, int targetSdkVersion, boolean isSystem) {
this.setName(name);
this.setIcon(icon);
this.setPackageName(packageName);
this.setPackagePath(packagePath);
this.setVersionName(versionName);
this.setVersionCode(versionCode);
+ this.setMinSdkVersion(minSdkVersion);
+ this.setTargetSdkVersion(targetSdkVersion);
this.setSystem(isSystem);
}
@Override
+ @NonNull
public String toString() {
return "{" +
"\n pkg name: " + getPackageName() +
@@ -813,6 +1015,8 @@ public String toString() {
"\n app path: " + getPackagePath() +
"\n app v name: " + getVersionName() +
"\n app v code: " + getVersionCode() +
+ "\n app v min: " + getMinSdkVersion() +
+ "\n app v target: " + getTargetSdkVersion() +
"\n is system: " + isSystem() +
"\n}";
}
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java
index 08b6142276..48594cedb5 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java
@@ -8,6 +8,9 @@
import java.util.LinkedList;
import java.util.List;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
/**
*
* author: blankj
@@ -30,39 +33,47 @@ private ArrayUtils() {
* @param array The array.
* @return a new array only of those given elements.
*/
- @SafeVarargs
+ @NonNull
public static T[] newArray(T... array) {
return array;
}
+ @NonNull
public static long[] newLongArray(long... array) {
return array;
}
+ @NonNull
public static int[] newIntArray(int... array) {
return array;
}
+ @NonNull
public static short[] newShortArray(short... array) {
return array;
}
+ @NonNull
public static char[] newCharArray(char... array) {
return array;
}
+ @NonNull
public static byte[] newByteArray(byte... array) {
return array;
}
+ @NonNull
public static double[] newDoubleArray(double... array) {
return array;
}
+ @NonNull
public static float[] newFloatArray(float... array) {
return array;
}
+ @NonNull
public static boolean[] newBooleanArray(boolean... array) {
return array;
}
@@ -73,7 +84,7 @@ public static boolean[] newBooleanArray(boolean... array) {
* @param array The array.
* @return {@code true}: yes
{@code false}: no
*/
- public static boolean isEmpty(Object array) {
+ public static boolean isEmpty(@Nullable Object array) {
return getLength(array) == 0;
}
@@ -83,12 +94,12 @@ public static boolean isEmpty(Object array) {
* @param array The array.
* @return the size of array
*/
- public static int getLength(Object array) {
+ public static int getLength(@Nullable Object array) {
if (array == null) return 0;
return Array.getLength(array);
}
- public static boolean isSameLength(Object array1, Object array2) {
+ public static boolean isSameLength(@Nullable Object array1, @Nullable Object array2) {
return getLength(array1) == getLength(array2);
}
@@ -99,7 +110,8 @@ public static boolean isSameLength(Object array1, Object array2) {
* @param index The index into the array.
* @return the value of the specified index of the array
*/
- public static Object get(Object array, int index) {
+ @Nullable
+ public static Object get(@Nullable Object array, int index) {
return get(array, index, null);
}
@@ -111,7 +123,8 @@ public static Object get(Object array, int index) {
* @param defaultValue The default value.
* @return the value of the specified index of the array
*/
- public static Object get(Object array, int index, Object defaultValue) {
+ @Nullable
+ public static Object get(@Nullable Object array, int index, @Nullable Object defaultValue) {
if (array == null) return defaultValue;
try {
return Array.get(array, index);
@@ -127,7 +140,7 @@ public static Object get(Object array, int index, Object defaultValue) {
* @param index The index into the array.
* @param value The new value of the indexed component.
*/
- public static void set(Object array, int index, Object value) {
+ public static void set(@Nullable Object array, int index, @Nullable Object value) {
if (array == null) return;
Array.set(array, index, value);
}
@@ -139,7 +152,7 @@ public static void set(Object array, int index, Object value) {
* @param a2 The other array.
* @return {@code true}: yes
{@code false}: no
*/
- public static boolean equals(Object[] a, Object[] a2) {
+ public static boolean equals(@Nullable Object[] a, @Nullable Object[] a2) {
return Arrays.deepEquals(a, a2);
}
@@ -344,52 +357,62 @@ public static void reverse(boolean[] array) {
* @param array the array to shallow clone, may be null
* @return the cloned array, null
if null
input
*/
- public static T[] copy(T[] array) {
+ @Nullable
+ public static T[] copy(@Nullable T[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static long[] copy(long[] array) {
+ @Nullable
+ public static long[] copy(@Nullable long[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static int[] copy(int[] array) {
+ @Nullable
+ public static int[] copy(@Nullable int[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static short[] copy(short[] array) {
+ @Nullable
+ public static short[] copy(@Nullable short[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static char[] copy(char[] array) {
+ @Nullable
+ public static char[] copy(@Nullable char[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static byte[] copy(byte[] array) {
+ @Nullable
+ public static byte[] copy(@Nullable byte[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static double[] copy(double[] array) {
+ @Nullable
+ public static double[] copy(@Nullable double[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static float[] copy(float[] array) {
+ @Nullable
+ public static float[] copy(@Nullable float[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- public static boolean[] copy(boolean[] array) {
+ @Nullable
+ public static boolean[] copy(@Nullable boolean[] array) {
if (array == null) return null;
return subArray(array, 0, array.length);
}
- private static Object realCopy(Object array) {
+ @Nullable
+ private static Object realCopy(@Nullable Object array) {
if (array == null) return null;
return realSubArray(array, 0, getLength(array));
}
@@ -398,44 +421,54 @@ private static Object realCopy(Object array) {
// subArray
///////////////////////////////////////////////////////////////////////////
- public static T[] subArray(T[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static T[] subArray(@Nullable T[] array, int startIndexInclusive, int endIndexExclusive) {
//noinspection unchecked
return (T[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static long[] subArray(long[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static long[] subArray(@Nullable long[] array, int startIndexInclusive, int endIndexExclusive) {
return (long[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static int[] subArray(int[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static int[] subArray(@Nullable int[] array, int startIndexInclusive, int endIndexExclusive) {
return (int[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static short[] subArray(short[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static short[] subArray(@Nullable short[] array, int startIndexInclusive, int endIndexExclusive) {
return (short[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static char[] subArray(char[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static char[] subArray(@Nullable char[] array, int startIndexInclusive, int endIndexExclusive) {
return (char[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static byte[] subArray(byte[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static byte[] subArray(@Nullable byte[] array, int startIndexInclusive, int endIndexExclusive) {
return (byte[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static double[] subArray(double[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static double[] subArray(@Nullable double[] array, int startIndexInclusive, int endIndexExclusive) {
return (double[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static float[] subArray(float[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static float[] subArray(@Nullable float[] array, int startIndexInclusive, int endIndexExclusive) {
return (float[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- public static boolean[] subArray(boolean[] array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ public static boolean[] subArray(@Nullable boolean[] array, int startIndexInclusive, int endIndexExclusive) {
return (boolean[]) realSubArray(array, startIndexInclusive, endIndexExclusive);
}
- private static Object realSubArray(Object array, int startIndexInclusive, int endIndexExclusive) {
+ @Nullable
+ private static Object realSubArray(@Nullable Object array, int startIndexInclusive, int endIndexExclusive) {
if (array == null) {
return null;
}
@@ -482,44 +515,54 @@ private static Object realSubArray(Object array, int startIndexInclusive, int en
* @param element the object to realAdd
* @return A new array containing the existing elements plus the new element
*/
- public static T[] add(T[] array, T element) {
+ @NonNull
+ public static T[] add(@Nullable T[] array, @Nullable T element) {
Class type = array != null ? array.getClass() : (element != null ? element.getClass() : Object.class);
return (T[]) realAddOne(array, element, type);
}
- public static boolean[] add(boolean[] array, boolean element) {
+ @NonNull
+ public static boolean[] add(@Nullable boolean[] array, boolean element) {
return (boolean[]) realAddOne(array, element, Boolean.TYPE);
}
- public static byte[] add(byte[] array, byte element) {
+ @NonNull
+ public static byte[] add(@Nullable byte[] array, byte element) {
return (byte[]) realAddOne(array, element, Byte.TYPE);
}
- public static char[] add(char[] array, char element) {
+ @NonNull
+ public static char[] add(@Nullable char[] array, char element) {
return (char[]) realAddOne(array, element, Character.TYPE);
}
- public static double[] add(double[] array, double element) {
+ @NonNull
+ public static double[] add(@Nullable double[] array, double element) {
return (double[]) realAddOne(array, element, Double.TYPE);
}
- public static float[] add(float[] array, float element) {
+ @NonNull
+ public static float[] add(@Nullable float[] array, float element) {
return (float[]) realAddOne(array, element, Float.TYPE);
}
- public static int[] add(int[] array, int element) {
+ @NonNull
+ public static int[] add(@Nullable int[] array, int element) {
return (int[]) realAddOne(array, element, Integer.TYPE);
}
- public static long[] add(long[] array, long element) {
+ @NonNull
+ public static long[] add(@Nullable long[] array, long element) {
return (long[]) realAddOne(array, element, Long.TYPE);
}
- public static short[] add(short[] array, short element) {
+ @NonNull
+ public static short[] add(@Nullable short[] array, short element) {
return (short[]) realAddOne(array, element, Short.TYPE);
}
- private static Object realAddOne(Object array, Object element, Class newArrayComponentType) {
+ @NonNull
+ private static Object realAddOne(@Nullable Object array, @Nullable Object element, Class newArrayComponentType) {
Object newArray;
int arrayLength = 0;
if (array != null) {
@@ -553,43 +596,52 @@ private static Object realAddOne(Object array, Object element, Class newArrayCom
* @return The new array, null
if null
array inputs.
* The type of the new array is the type of the first array.
*/
- public static T[] add(T[] array1, T[] array2) {
+ @Nullable
+ public static T[] add(@Nullable T[] array1, @Nullable T[] array2) {
return (T[]) realAddArr(array1, array2);
}
- public static boolean[] add(boolean[] array1, boolean[] array2) {
+ @Nullable
+ public static boolean[] add(@Nullable boolean[] array1, @Nullable boolean[] array2) {
return (boolean[]) realAddArr(array1, array2);
}
- public static char[] add(char[] array1, char[] array2) {
+ @Nullable
+ public static char[] add(@Nullable char[] array1, @Nullable char[] array2) {
return (char[]) realAddArr(array1, array2);
}
- public static byte[] add(byte[] array1, byte[] array2) {
+ @Nullable
+ public static byte[] add(@Nullable byte[] array1, @Nullable byte[] array2) {
return (byte[]) realAddArr(array1, array2);
}
- public static short[] add(short[] array1, short[] array2) {
+ @Nullable
+ public static short[] add(@Nullable short[] array1, @Nullable short[] array2) {
return (short[]) realAddArr(array1, array2);
}
- public static int[] add(int[] array1, int[] array2) {
+ @Nullable
+ public static int[] add(@Nullable int[] array1, @Nullable int[] array2) {
return (int[]) realAddArr(array1, array2);
}
- public static long[] add(long[] array1, long[] array2) {
+ @Nullable
+ public static long[] add(@Nullable long[] array1, @Nullable long[] array2) {
return (long[]) realAddArr(array1, array2);
}
- public static float[] add(float[] array1, float[] array2) {
+ @Nullable
+ public static float[] add(@Nullable float[] array1, @Nullable float[] array2) {
return (float[]) realAddArr(array1, array2);
}
- public static double[] add(double[] array1, double[] array2) {
+ @Nullable
+ public static double[] add(@Nullable double[] array1, @Nullable double[] array2) {
return (double[]) realAddArr(array1, array2);
}
- private static Object realAddArr(Object array1, Object array2) {
+ private static Object realAddArr(@Nullable Object array1, @Nullable Object array2) {
if (array1 == null && array2 == null) return null;
if (array1 == null) {
return realCopy(array2);
@@ -619,11 +671,11 @@ private static Object realAddArr(Object array1, Object array2) {
* whose component type is the same as the element.
*
*
- * ArrayUtils.add(null, 0, null) = [null]
- * ArrayUtils.add(null, 0, "a") = ["a"]
- * ArrayUtils.add(["a"], 1, null) = ["a", null]
- * ArrayUtils.add(["a"], 1, "b") = ["a", "b"]
- * ArrayUtils.add(["a", "b"], 3, "c") = ["a", "b", "c"]
+ * ArrayUtils.add(null, 0, null) = null
+ * ArrayUtils.add(null, 0, ["a"]) = ["a"]
+ * ArrayUtils.add(["a"], 1, null) = ["a"]
+ * ArrayUtils.add(["a"], 1, ["b"]) = ["a", "b"]
+ * ArrayUtils.add(["a", "b"], 2, ["c"]) = ["a", "b", "c"]
*
*
* @param array1 the array to realAdd the element to, may be null
@@ -633,51 +685,76 @@ private static Object realAddArr(Object array1, Object array2) {
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
- public static T[] add(T[] array1, int index, T[] array2) {
+ @Nullable
+ public static T[] add(@Nullable T[] array1, int index, @Nullable T[] array2) {
Class clss;
if (array1 != null) {
clss = array1.getClass().getComponentType();
} else if (array2 != null) {
clss = array2.getClass().getComponentType();
} else {
- return (T[]) new Object[]{null};
+ return null;
}
return (T[]) realAddArr(array1, index, array2, clss);
}
- public static boolean[] add(boolean[] array1, int index, boolean[] array2) {
- return (boolean[]) realAddArr(array1, index, array2, Boolean.TYPE);
+ @Nullable
+ public static boolean[] add(@Nullable boolean[] array1, int index, @Nullable boolean[] array2) {
+ Object result = realAddArr(array1, index, array2, Boolean.TYPE);
+ if (result == null) return null;
+ return (boolean[]) result;
}
- public static char[] add(char[] array1, int index, char[] array2) {
- return (char[]) realAddArr(array1, index, array2, Character.TYPE);
+ public static char[] add(@Nullable char[] array1, int index, @Nullable char[] array2) {
+ Object result = realAddArr(array1, index, array2, Character.TYPE);
+ if (result == null) return null;
+ return (char[]) result;
}
- public static byte[] add(byte[] array1, int index, byte[] array2) {
- return (byte[]) realAddArr(array1, index, array2, Byte.TYPE);
+ @Nullable
+ public static byte[] add(@Nullable byte[] array1, int index, @Nullable byte[] array2) {
+ Object result = realAddArr(array1, index, array2, Byte.TYPE);
+ if (result == null) return null;
+ return (byte[]) result;
}
- public static short[] add(short[] array1, int index, short[] array2) {
- return (short[]) realAddArr(array1, index, array2, Short.TYPE);
+ @Nullable
+ public static short[] add(@Nullable short[] array1, int index, @Nullable short[] array2) {
+ Object result = realAddArr(array1, index, array2, Short.TYPE);
+ if (result == null) return null;
+ return (short[]) result;
}
- public static int[] add(int[] array1, int index, int[] array2) {
- return (int[]) realAddArr(array1, index, array2, Integer.TYPE);
+ @Nullable
+ public static int[] add(@Nullable int[] array1, int index, @Nullable int[] array2) {
+ Object result = realAddArr(array1, index, array2, Integer.TYPE);
+ if (result == null) return null;
+ return (int[]) result;
}
- public static long[] add(long[] array1, int index, long[] array2) {
- return (long[]) realAddArr(array1, index, array2, Long.TYPE);
+ @Nullable
+ public static long[] add(@Nullable long[] array1, int index, @Nullable long[] array2) {
+ Object result = realAddArr(array1, index, array2, Long.TYPE);
+ if (result == null) return null;
+ return (long[]) result;
}
- public static float[] add(float[] array1, int index, float[] array2) {
- return (float[]) realAddArr(array1, index, array2, Float.TYPE);
+ @Nullable
+ public static float[] add(@Nullable float[] array1, int index, @Nullable float[] array2) {
+ Object result = realAddArr(array1, index, array2, Float.TYPE);
+ if (result == null) return null;
+ return (float[]) result;
}
- public static double[] add(double[] array1, int index, double[] array2) {
- return (double[]) realAddArr(array1, index, array2, Double.TYPE);
+ @Nullable
+ public static double[] add(@Nullable double[] array1, int index, @Nullable double[] array2) {
+ Object result = realAddArr(array1, index, array2, Double.TYPE);
+ if (result == null) return null;
+ return (double[]) result;
}
- private static Object realAddArr(Object array1, int index, Object array2, Class clss) {
+ @Nullable
+ private static Object realAddArr(@Nullable Object array1, int index, @Nullable Object array2, Class clss) {
if (array1 == null && array2 == null) return null;
int len1 = getLength(array1);
int len2 = getLength(array2);
@@ -736,7 +813,8 @@ private static Object realAddArr(Object array1, int index, Object array2, Class
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
- public static T[] add(T[] array, int index, T element) {
+ @NonNull
+ public static T[] add(@Nullable T[] array, int index, @Nullable T element) {
Class clss;
if (array != null) {
clss = array.getClass().getComponentType();
@@ -748,39 +826,48 @@ public static T[] add(T[] array, int index, T element) {
return (T[]) realAdd(array, index, element, clss);
}
- public static boolean[] add(boolean[] array, int index, boolean element) {
+ @NonNull
+ public static boolean[] add(@Nullable boolean[] array, int index, boolean element) {
return (boolean[]) realAdd(array, index, element, Boolean.TYPE);
}
- public static char[] add(char[] array, int index, char element) {
+ @NonNull
+ public static char[] add(@Nullable char[] array, int index, char element) {
return (char[]) realAdd(array, index, element, Character.TYPE);
}
- public static byte[] add(byte[] array, int index, byte element) {
+ @NonNull
+ public static byte[] add(@Nullable byte[] array, int index, byte element) {
return (byte[]) realAdd(array, index, element, Byte.TYPE);
}
- public static short[] add(short[] array, int index, short element) {
+ @NonNull
+ public static short[] add(@Nullable short[] array, int index, short element) {
return (short[]) realAdd(array, index, element, Short.TYPE);
}
- public static int[] add(int[] array, int index, int element) {
+ @NonNull
+ public static int[] add(@Nullable int[] array, int index, int element) {
return (int[]) realAdd(array, index, element, Integer.TYPE);
}
- public static long[] add(long[] array, int index, long element) {
+ @NonNull
+ public static long[] add(@Nullable long[] array, int index, long element) {
return (long[]) realAdd(array, index, element, Long.TYPE);
}
- public static float[] add(float[] array, int index, float element) {
+ @NonNull
+ public static float[] add(@Nullable float[] array, int index, float element) {
return (float[]) realAdd(array, index, element, Float.TYPE);
}
- public static double[] add(double[] array, int index, double element) {
+ @NonNull
+ public static double[] add(@Nullable double[] array, int index, double element) {
return (double[]) realAdd(array, index, element, Double.TYPE);
}
- private static Object realAdd(Object array, int index, Object element, Class clss) {
+ @NonNull
+ private static Object realAdd(@Nullable Object array, int index, @Nullable Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
@@ -826,15 +913,16 @@ private static Object realAdd(Object array, int index, Object element, Class cls
* ArrayUtils.remove(["a", "b", "c"], 1) = ["a", "c"]
*
*
- * @param array the array to remove the element from, may not be null
+ * @param array the array to remove the element from, may be null
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
- * (index < 0 || index >= array.length), or if the array is null
.
- * @since 2.1
+ * (index < 0 || index >= array.length)
*/
- public static Object[] remove(Object[] array, int index) {
+ @Nullable
+ public static Object[] remove(@Nullable Object[] array, int index) {
+ if (array == null) return null;
return (Object[]) remove((Object) array, index);
}
@@ -861,9 +949,9 @@ public static Object[] remove(Object[] array, int index) {
* @param element the element to be removed
* @return A new array containing the existing elements except the first
* occurrence of the specified element.
- * @since 2.1
*/
- public static Object[] removeElement(Object[] array, Object element) {
+ @Nullable
+ public static Object[] removeElement(@Nullable Object[] array, @Nullable Object element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -871,11 +959,14 @@ public static Object[] removeElement(Object[] array, Object element) {
return remove(array, index);
}
- public static boolean[] remove(boolean[] array, int index) {
+ @Nullable
+ public static boolean[] remove(@Nullable boolean[] array, int index) {
+ if (array == null) return null;
return (boolean[]) remove((Object) array, index);
}
- public static boolean[] removeElement(boolean[] array, boolean element) {
+ @Nullable
+ public static boolean[] removeElement(@Nullable boolean[] array, boolean element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -883,11 +974,14 @@ public static boolean[] removeElement(boolean[] array, boolean element) {
return remove(array, index);
}
- public static byte[] remove(byte[] array, int index) {
+ @Nullable
+ public static byte[] remove(@Nullable byte[] array, int index) {
+ if (array == null) return null;
return (byte[]) remove((Object) array, index);
}
- public static byte[] removeElement(byte[] array, byte element) {
+ @Nullable
+ public static byte[] removeElement(@Nullable byte[] array, byte element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -895,11 +989,14 @@ public static byte[] removeElement(byte[] array, byte element) {
return remove(array, index);
}
- public static char[] remove(char[] array, int index) {
+ @Nullable
+ public static char[] remove(@Nullable char[] array, int index) {
+ if (array == null) return null;
return (char[]) remove((Object) array, index);
}
- public static char[] removeElement(char[] array, char element) {
+ @Nullable
+ public static char[] removeElement(@Nullable char[] array, char element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -907,23 +1004,30 @@ public static char[] removeElement(char[] array, char element) {
return remove(array, index);
}
- public static double[] remove(double[] array, int index) {
+ @Nullable
+ public static double[] remove(@Nullable double[] array, int index) {
+ if (array == null) return null;
return (double[]) remove((Object) array, index);
}
- public static double[] removeElement(double[] array, double element) {
+ @Nullable
+ public static double[] removeElement(@Nullable double[] array, double element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
}
+ //noinspection ConstantConditions
return remove(array, index);
}
- public static float[] remove(float[] array, int index) {
+ @Nullable
+ public static float[] remove(@Nullable float[] array, int index) {
+ if (array == null) return null;
return (float[]) remove((Object) array, index);
}
- public static float[] removeElement(float[] array, float element) {
+ @Nullable
+ public static float[] removeElement(@Nullable float[] array, float element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -931,11 +1035,14 @@ public static float[] removeElement(float[] array, float element) {
return remove(array, index);
}
- public static int[] remove(int[] array, int index) {
+ @Nullable
+ public static int[] remove(@Nullable int[] array, int index) {
+ if (array == null) return null;
return (int[]) remove((Object) array, index);
}
- public static int[] removeElement(int[] array, int element) {
+ @Nullable
+ public static int[] removeElement(@Nullable int[] array, int element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -943,11 +1050,14 @@ public static int[] removeElement(int[] array, int element) {
return remove(array, index);
}
- public static long[] remove(long[] array, int index) {
+ @Nullable
+ public static long[] remove(@Nullable long[] array, int index) {
+ if (array == null) return null;
return (long[]) remove((Object) array, index);
}
- public static long[] removeElement(long[] array, long element) {
+ @Nullable
+ public static long[] removeElement(@Nullable long[] array, long element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -955,11 +1065,14 @@ public static long[] removeElement(long[] array, long element) {
return remove(array, index);
}
- public static short[] remove(short[] array, int index) {
+ @Nullable
+ public static short[] remove(@Nullable short[] array, int index) {
+ if (array == null) return null;
return (short[]) remove((Object) array, index);
}
- public static short[] removeElement(short[] array, short element) {
+ @Nullable
+ public static short[] removeElement(@Nullable short[] array, short element) {
int index = indexOf(array, element);
if (index == INDEX_NOT_FOUND) {
return copy(array);
@@ -967,7 +1080,8 @@ public static short[] removeElement(short[] array, short element) {
return remove(array, index);
}
- private static Object remove(Object array, int index) {
+ @NonNull
+ private static Object remove(@NonNull Object array, int index) {
int length = getLength(array);
if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
@@ -986,11 +1100,11 @@ private static Object remove(Object array, int index) {
// object indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(Object[] array, Object objectToFind) {
+ public static int indexOf(@Nullable Object[] array, @Nullable Object objectToFind) {
return indexOf(array, objectToFind, 0);
}
- public static int indexOf(Object[] array, final Object objectToFind, int startIndex) {
+ public static int indexOf(@Nullable Object[] array, @Nullable final Object objectToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1013,11 +1127,11 @@ public static int indexOf(Object[] array, final Object objectToFind, int startIn
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(Object[] array, Object objectToFind) {
+ public static int lastIndexOf(@Nullable Object[] array, @Nullable Object objectToFind) {
return lastIndexOf(array, objectToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(Object[] array, Object objectToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable Object[] array, @Nullable Object objectToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1042,7 +1156,7 @@ public static int lastIndexOf(Object[] array, Object objectToFind, int startInde
return INDEX_NOT_FOUND;
}
- public static boolean contains(Object[] array, Object objectToFind) {
+ public static boolean contains(@Nullable Object[] array, @Nullable Object objectToFind) {
return indexOf(array, objectToFind) != INDEX_NOT_FOUND;
}
@@ -1050,11 +1164,11 @@ public static boolean contains(Object[] array, Object objectToFind) {
// long indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(long[] array, long valueToFind) {
+ public static int indexOf(@Nullable long[] array, long valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(long[] array, long valueToFind, int startIndex) {
+ public static int indexOf(@Nullable long[] array, long valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1069,11 +1183,11 @@ public static int indexOf(long[] array, long valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(long[] array, long valueToFind) {
+ public static int lastIndexOf(@Nullable long[] array, long valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(long[] array, long valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable long[] array, long valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1090,7 +1204,7 @@ public static int lastIndexOf(long[] array, long valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static boolean contains(long[] array, long valueToFind) {
+ public static boolean contains(@Nullable long[] array, long valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
@@ -1098,11 +1212,11 @@ public static boolean contains(long[] array, long valueToFind) {
// int indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(int[] array, int valueToFind) {
+ public static int indexOf(@Nullable int[] array, int valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(int[] array, int valueToFind, int startIndex) {
+ public static int indexOf(@Nullable int[] array, int valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1117,11 +1231,11 @@ public static int indexOf(int[] array, int valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(int[] array, int valueToFind) {
+ public static int lastIndexOf(@Nullable int[] array, int valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(int[] array, int valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable int[] array, int valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1138,7 +1252,7 @@ public static int lastIndexOf(int[] array, int valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static boolean contains(int[] array, int valueToFind) {
+ public static boolean contains(@Nullable int[] array, int valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
@@ -1146,11 +1260,11 @@ public static boolean contains(int[] array, int valueToFind) {
// short indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(short[] array, short valueToFind) {
+ public static int indexOf(@Nullable short[] array, short valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(short[] array, short valueToFind, int startIndex) {
+ public static int indexOf(@Nullable short[] array, short valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1165,11 +1279,11 @@ public static int indexOf(short[] array, short valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(short[] array, short valueToFind) {
+ public static int lastIndexOf(@Nullable short[] array, short valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(short[] array, short valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable short[] array, short valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1186,7 +1300,7 @@ public static int lastIndexOf(short[] array, short valueToFind, int startIndex)
return INDEX_NOT_FOUND;
}
- public static boolean contains(short[] array, short valueToFind) {
+ public static boolean contains(@Nullable short[] array, short valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
@@ -1194,11 +1308,11 @@ public static boolean contains(short[] array, short valueToFind) {
// char indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(char[] array, char valueToFind) {
+ public static int indexOf(@Nullable char[] array, char valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(char[] array, char valueToFind, int startIndex) {
+ public static int indexOf(@Nullable char[] array, char valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1213,11 +1327,11 @@ public static int indexOf(char[] array, char valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(char[] array, char valueToFind) {
+ public static int lastIndexOf(@Nullable char[] array, char valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(char[] array, char valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable char[] array, char valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1234,7 +1348,7 @@ public static int lastIndexOf(char[] array, char valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static boolean contains(char[] array, char valueToFind) {
+ public static boolean contains(@Nullable char[] array, char valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
@@ -1242,11 +1356,11 @@ public static boolean contains(char[] array, char valueToFind) {
// byte indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(byte[] array, byte valueToFind) {
+ public static int indexOf(@Nullable byte[] array, byte valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(byte[] array, byte valueToFind, int startIndex) {
+ public static int indexOf(@Nullable byte[] array, byte valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1261,11 +1375,11 @@ public static int indexOf(byte[] array, byte valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(byte[] array, byte valueToFind) {
+ public static int lastIndexOf(@Nullable byte[] array, byte valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(byte[] array, byte valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable byte[] array, byte valueToFind, int startIndex) {
if (array == null) {
return INDEX_NOT_FOUND;
}
@@ -1282,7 +1396,7 @@ public static int lastIndexOf(byte[] array, byte valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static boolean contains(byte[] array, byte valueToFind) {
+ public static boolean contains(@Nullable byte[] array, byte valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
@@ -1290,15 +1404,15 @@ public static boolean contains(byte[] array, byte valueToFind) {
// double indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(double[] array, double valueToFind) {
+ public static int indexOf(@Nullable double[] array, double valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(double[] array, double valueToFind, double tolerance) {
+ public static int indexOf(@Nullable double[] array, double valueToFind, double tolerance) {
return indexOf(array, valueToFind, 0, tolerance);
}
- public static int indexOf(double[] array, double valueToFind, int startIndex) {
+ public static int indexOf(@Nullable double[] array, double valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1313,7 +1427,7 @@ public static int indexOf(double[] array, double valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static int indexOf(double[] array, double valueToFind, int startIndex, double tolerance) {
+ public static int indexOf(@Nullable double[] array, double valueToFind, int startIndex, double tolerance) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1330,15 +1444,15 @@ public static int indexOf(double[] array, double valueToFind, int startIndex, do
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(double[] array, double valueToFind) {
+ public static int lastIndexOf(@Nullable double[] array, double valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(double[] array, double valueToFind, double tolerance) {
+ public static int lastIndexOf(@Nullable double[] array, double valueToFind, double tolerance) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE, tolerance);
}
- public static int lastIndexOf(double[] array, double valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable double[] array, double valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1355,7 +1469,7 @@ public static int lastIndexOf(double[] array, double valueToFind, int startIndex
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(double[] array, double valueToFind, int startIndex, double tolerance) {
+ public static int lastIndexOf(@Nullable double[] array, double valueToFind, int startIndex, double tolerance) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1374,11 +1488,11 @@ public static int lastIndexOf(double[] array, double valueToFind, int startIndex
return INDEX_NOT_FOUND;
}
- public static boolean contains(double[] array, double valueToFind) {
+ public static boolean contains(@Nullable double[] array, double valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
- public static boolean contains(double[] array, double valueToFind, double tolerance) {
+ public static boolean contains(@Nullable double[] array, double valueToFind, double tolerance) {
return indexOf(array, valueToFind, 0, tolerance) != INDEX_NOT_FOUND;
}
@@ -1386,11 +1500,11 @@ public static boolean contains(double[] array, double valueToFind, double tolera
// float indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(float[] array, float valueToFind) {
+ public static int indexOf(@Nullable float[] array, float valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(float[] array, float valueToFind, int startIndex) {
+ public static int indexOf(@Nullable float[] array, float valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1405,11 +1519,11 @@ public static int indexOf(float[] array, float valueToFind, int startIndex) {
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(float[] array, float valueToFind) {
+ public static int lastIndexOf(@Nullable float[] array, float valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(float[] array, float valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable float[] array, float valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1426,7 +1540,7 @@ public static int lastIndexOf(float[] array, float valueToFind, int startIndex)
return INDEX_NOT_FOUND;
}
- public static boolean contains(float[] array, float valueToFind) {
+ public static boolean contains(@Nullable float[] array, float valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
@@ -1434,11 +1548,11 @@ public static boolean contains(float[] array, float valueToFind) {
// bool indexOf
///////////////////////////////////////////////////////////////////////////
- public static int indexOf(boolean[] array, boolean valueToFind) {
+ public static int indexOf(@Nullable boolean[] array, boolean valueToFind) {
return indexOf(array, valueToFind, 0);
}
- public static int indexOf(boolean[] array, boolean valueToFind, int startIndex) {
+ public static int indexOf(@Nullable boolean[] array, boolean valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1453,11 +1567,11 @@ public static int indexOf(boolean[] array, boolean valueToFind, int startIndex)
return INDEX_NOT_FOUND;
}
- public static int lastIndexOf(boolean[] array, boolean valueToFind) {
+ public static int lastIndexOf(@Nullable boolean[] array, boolean valueToFind) {
return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
}
- public static int lastIndexOf(boolean[] array, boolean valueToFind, int startIndex) {
+ public static int lastIndexOf(@Nullable boolean[] array, boolean valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
@@ -1474,7 +1588,7 @@ public static int lastIndexOf(boolean[] array, boolean valueToFind, int startInd
return INDEX_NOT_FOUND;
}
- public static boolean contains(boolean[] array, boolean valueToFind) {
+ public static boolean contains(@Nullable boolean[] array, boolean valueToFind) {
return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
}
@@ -1482,7 +1596,8 @@ public static boolean contains(boolean[] array, boolean valueToFind) {
// char converters
///////////////////////////////////////////////////////////////////////////
- public static char[] toPrimitive(Character[] array) {
+ @Nullable
+ public static char[] toPrimitive(@Nullable Character[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1495,7 +1610,8 @@ public static char[] toPrimitive(Character[] array) {
return result;
}
- public static char[] toPrimitive(Character[] array, char valueForNull) {
+ @Nullable
+ public static char[] toPrimitive(@Nullable Character[] array, char valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1509,7 +1625,8 @@ public static char[] toPrimitive(Character[] array, char valueForNull) {
return result;
}
- public static Character[] toObject(char[] array) {
+ @Nullable
+ public static Character[] toObject(@Nullable char[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1526,7 +1643,8 @@ public static Character[] toObject(char[] array) {
// long converters
///////////////////////////////////////////////////////////////////////////
- public static long[] toPrimitive(Long[] array) {
+ @Nullable
+ public static long[] toPrimitive(@Nullable Long[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1539,7 +1657,8 @@ public static long[] toPrimitive(Long[] array) {
return result;
}
- public static long[] toPrimitive(Long[] array, long valueForNull) {
+ @Nullable
+ public static long[] toPrimitive(@Nullable Long[] array, long valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1553,7 +1672,8 @@ public static long[] toPrimitive(Long[] array, long valueForNull) {
return result;
}
- public static Long[] toObject(long[] array) {
+ @Nullable
+ public static Long[] toObject(@Nullable long[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1570,7 +1690,8 @@ public static Long[] toObject(long[] array) {
// int converters
///////////////////////////////////////////////////////////////////////////
- public static int[] toPrimitive(Integer[] array) {
+ @Nullable
+ public static int[] toPrimitive(@Nullable Integer[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1583,7 +1704,8 @@ public static int[] toPrimitive(Integer[] array) {
return result;
}
- public static int[] toPrimitive(Integer[] array, int valueForNull) {
+ @Nullable
+ public static int[] toPrimitive(@Nullable Integer[] array, int valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1597,7 +1719,8 @@ public static int[] toPrimitive(Integer[] array, int valueForNull) {
return result;
}
- public static Integer[] toObject(int[] array) {
+ @Nullable
+ public static Integer[] toObject(@Nullable int[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1614,7 +1737,8 @@ public static Integer[] toObject(int[] array) {
// short converters
///////////////////////////////////////////////////////////////////////////
- public static short[] toPrimitive(Short[] array) {
+ @Nullable
+ public static short[] toPrimitive(@Nullable Short[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1627,7 +1751,8 @@ public static short[] toPrimitive(Short[] array) {
return result;
}
- public static short[] toPrimitive(Short[] array, short valueForNull) {
+ @Nullable
+ public static short[] toPrimitive(@Nullable Short[] array, short valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1641,7 +1766,8 @@ public static short[] toPrimitive(Short[] array, short valueForNull) {
return result;
}
- public static Short[] toObject(short[] array) {
+ @Nullable
+ public static Short[] toObject(@Nullable short[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1658,7 +1784,8 @@ public static Short[] toObject(short[] array) {
// byte converters
///////////////////////////////////////////////////////////////////////////
- public static byte[] toPrimitive(Byte[] array) {
+ @Nullable
+ public static byte[] toPrimitive(@Nullable Byte[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1671,7 +1798,8 @@ public static byte[] toPrimitive(Byte[] array) {
return result;
}
- public static byte[] toPrimitive(Byte[] array, byte valueForNull) {
+ @Nullable
+ public static byte[] toPrimitive(@Nullable Byte[] array, byte valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1685,7 +1813,8 @@ public static byte[] toPrimitive(Byte[] array, byte valueForNull) {
return result;
}
- public static Byte[] toObject(byte[] array) {
+ @Nullable
+ public static Byte[] toObject(@Nullable byte[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1702,7 +1831,8 @@ public static Byte[] toObject(byte[] array) {
// double converters
///////////////////////////////////////////////////////////////////////////
- public static double[] toPrimitive(Double[] array) {
+ @Nullable
+ public static double[] toPrimitive(@Nullable Double[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1715,7 +1845,8 @@ public static double[] toPrimitive(Double[] array) {
return result;
}
- public static double[] toPrimitive(Double[] array, double valueForNull) {
+ @Nullable
+ public static double[] toPrimitive(@Nullable Double[] array, double valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1729,7 +1860,8 @@ public static double[] toPrimitive(Double[] array, double valueForNull) {
return result;
}
- public static Double[] toObject(double[] array) {
+ @Nullable
+ public static Double[] toObject(@Nullable double[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1746,7 +1878,8 @@ public static Double[] toObject(double[] array) {
// float converters
///////////////////////////////////////////////////////////////////////////
- public static float[] toPrimitive(Float[] array) {
+ @Nullable
+ public static float[] toPrimitive(@Nullable Float[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1759,7 +1892,8 @@ public static float[] toPrimitive(Float[] array) {
return result;
}
- public static float[] toPrimitive(Float[] array, float valueForNull) {
+ @Nullable
+ public static float[] toPrimitive(@Nullable Float[] array, float valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1773,7 +1907,8 @@ public static float[] toPrimitive(Float[] array, float valueForNull) {
return result;
}
- public static Float[] toObject(float[] array) {
+ @Nullable
+ public static Float[] toObject(@Nullable float[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1790,7 +1925,8 @@ public static Float[] toObject(float[] array) {
// boolean converters
///////////////////////////////////////////////////////////////////////////
- public static boolean[] toPrimitive(Boolean[] array) {
+ @Nullable
+ public static boolean[] toPrimitive(@Nullable Boolean[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1803,7 +1939,8 @@ public static boolean[] toPrimitive(Boolean[] array) {
return result;
}
- public static boolean[] toPrimitive(Boolean[] array, boolean valueForNull) {
+ @Nullable
+ public static boolean[] toPrimitive(@Nullable Boolean[] array, boolean valueForNull) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1817,7 +1954,8 @@ public static boolean[] toPrimitive(Boolean[] array, boolean valueForNull) {
return result;
}
- public static Boolean[] toObject(boolean[] array) {
+ @Nullable
+ public static Boolean[] toObject(@Nullable boolean[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
@@ -1830,67 +1968,71 @@ public static Boolean[] toObject(boolean[] array) {
return result;
}
- public static List asList(T... array) {
+ @NonNull
+ public static List asList(@Nullable T... array) {
if (array == null || array.length == 0) {
return Collections.emptyList();
}
return Arrays.asList(array);
}
- public static List asUnmodifiableList(T... array) {
+ @NonNull
+ public static List asUnmodifiableList(@Nullable T... array) {
return Collections.unmodifiableList(asList(array));
}
- public static List asArrayList(T... array) {
+ @NonNull
+ public static List asArrayList(@Nullable T... array) {
List list = new ArrayList<>();
if (array == null || array.length == 0) return list;
list.addAll(Arrays.asList(array));
return list;
}
- public static List asLinkedList(T... array) {
+ @NonNull
+ public static List asLinkedList(@Nullable T... array) {
List list = new LinkedList<>();
if (array == null || array.length == 0) return list;
list.addAll(Arrays.asList(array));
return list;
}
- public static void sort(T[] array, Comparator super T> c) {
+ public static void sort(@Nullable T[] array, Comparator super T> c) {
if (array == null || array.length < 2) return;
Arrays.sort(array, c);
}
- public static void sort(byte[] array) {
+ public static void sort(@Nullable byte[] array) {
if (array == null || array.length < 2) return;
Arrays.sort(array);
}
- public static void sort(char[] array) {
+ public static void sort(@Nullable char[] array) {
if (array == null || array.length < 2) return;
Arrays.sort(array);
}
- public static void sort(double[] array) {
+ public static void sort(@Nullable double[] array) {
if (array == null || array.length < 2) return;
Arrays.sort(array);
}
- public static void sort(float[] array) {
+ public static void sort(@Nullable float[] array) {
if (array == null || array.length < 2) return;
Arrays.sort(array);
}
- public static void sort(int[] array) {
+ public static void sort(@Nullable int[] array) {
if (array == null || array.length < 2) return;
Arrays.sort(array);
}
- public static void sort(long[] array) {
+ public static void sort(@Nullable long[] array) {
if (array == null || array.length < 2) return;
Arrays.sort(array);
}
- public static void sort(short[] array) {
+ public static void sort(@Nullable short[] array) {
if (array == null || array.length < 2) return;
Arrays.sort(array);
}
@@ -1903,7 +2045,7 @@ public static void sort(short[] array) {
* @param array The array.
* @param closure the closure to perform, may be null
*/
- public static void forAllDo(Object array, Closure closure) {
+ public static void forAllDo(@Nullable Object array, @Nullable Closure closure) {
if (array == null || closure == null) return;
if (array instanceof Object[]) {
Object[] objects = (Object[]) array;
@@ -1970,7 +2112,8 @@ public static void forAllDo(Object array, Closure closure) {
* @param array The array.
* @return the string of array
*/
- public static String toString(Object array) {
+ @NonNull
+ public static String toString(@Nullable Object array) {
if (array == null) return "null";
if (array instanceof Object[]) {
return Arrays.deepToString((Object[]) array);
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java
index 37596cd9eb..e8cacc5f0c 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java
@@ -1,5 +1,7 @@
package com.blankj.utilcode.util;
+import static android.Manifest.permission.EXPAND_STATUS_BAR;
+
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
@@ -7,11 +9,7 @@
import android.graphics.Color;
import android.graphics.Point;
import android.os.Build;
-import android.support.annotation.ColorInt;
-import android.support.annotation.NonNull;
-import android.support.annotation.RequiresApi;
-import android.support.annotation.RequiresPermission;
-import android.support.v4.widget.DrawerLayout;
+import android.provider.Settings;
import android.util.TypedValue;
import android.view.Display;
import android.view.KeyCharacterMap;
@@ -23,9 +21,13 @@
import android.view.Window;
import android.view.WindowManager;
-import java.lang.reflect.Method;
+import androidx.annotation.ColorInt;
+import androidx.annotation.NonNull;
+import androidx.annotation.RequiresApi;
+import androidx.annotation.RequiresPermission;
+import androidx.drawerlayout.widget.DrawerLayout;
-import static android.Manifest.permission.EXPAND_STATUS_BAR;
+import java.lang.reflect.Method;
/**
*
@@ -42,8 +44,8 @@ public final class BarUtils {
///////////////////////////////////////////////////////////////////////////
private static final String TAG_STATUS_BAR = "TAG_STATUS_BAR";
- private static final String TAG_OFFSET = "TAG_OFFSET";
- private static final int KEY_OFFSET = -123;
+ private static final String TAG_OFFSET = "TAG_OFFSET";
+ private static final int KEY_OFFSET = -123;
private BarUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
@@ -192,14 +194,14 @@ public static void subtractMarginTopEqualStatusBarHeight(@NonNull View view) {
view.setTag(KEY_OFFSET, false);
}
- private static void addMarginTopEqualStatusBarHeight(final Window window) {
+ private static void addMarginTopEqualStatusBarHeight(@NonNull final Window window) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
View withTag = window.getDecorView().findViewWithTag(TAG_OFFSET);
if (withTag == null) return;
addMarginTopEqualStatusBarHeight(withTag);
}
- private static void subtractMarginTopEqualStatusBarHeight(final Window window) {
+ private static void subtractMarginTopEqualStatusBarHeight(@NonNull final Window window) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
View withTag = window.getDecorView().findViewWithTag(TAG_OFFSET);
if (withTag == null) return;
@@ -347,13 +349,13 @@ public static void setStatusBarColor4Drawer(@NonNull final DrawerLayout drawer,
}
}
- private static View applyStatusBarColor(final Activity activity,
+ private static View applyStatusBarColor(@NonNull final Activity activity,
final int color,
boolean isDecor) {
return applyStatusBarColor(activity.getWindow(), color, isDecor);
}
- private static View applyStatusBarColor(final Window window,
+ private static View applyStatusBarColor(@NonNull final Window window,
final int color,
boolean isDecor) {
ViewGroup parent = isDecor ?
@@ -372,25 +374,25 @@ private static View applyStatusBarColor(final Window window,
return fakeStatusBarView;
}
- private static void hideStatusBarView(final Activity activity) {
+ private static void hideStatusBarView(@NonNull final Activity activity) {
hideStatusBarView(activity.getWindow());
}
- private static void hideStatusBarView(final Window window) {
+ private static void hideStatusBarView(@NonNull final Window window) {
ViewGroup decorView = (ViewGroup) window.getDecorView();
View fakeStatusBarView = decorView.findViewWithTag(TAG_STATUS_BAR);
if (fakeStatusBarView == null) return;
fakeStatusBarView.setVisibility(View.GONE);
}
- private static void showStatusBarView(final Window window) {
+ private static void showStatusBarView(@NonNull final Window window) {
ViewGroup decorView = (ViewGroup) window.getDecorView();
View fakeStatusBarView = decorView.findViewWithTag(TAG_STATUS_BAR);
if (fakeStatusBarView == null) return;
fakeStatusBarView.setVisibility(View.VISIBLE);
}
- private static View createStatusBarView(final Context context,
+ private static View createStatusBarView(@NonNull final Context context,
final int color) {
View statusBarView = new View(context);
statusBarView.setLayoutParams(new ViewGroup.LayoutParams(
@@ -400,11 +402,11 @@ private static View createStatusBarView(final Context context,
return statusBarView;
}
- public static void transparentStatusBar(final Activity activity) {
+ public static void transparentStatusBar(@NonNull final Activity activity) {
transparentStatusBar(activity.getWindow());
}
- public static void transparentStatusBar(final Window window) {
+ public static void transparentStatusBar(@NonNull final Window window) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
@@ -431,7 +433,7 @@ public static int getActionBarHeight() {
TypedValue tv = new TypedValue();
if (Utils.getApp().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
return TypedValue.complexToDimensionPixelSize(
- tv.data, Resources.getSystem().getDisplayMetrics()
+ tv.data, Utils.getApp().getResources().getDisplayMetrics()
);
}
return 0;
@@ -565,9 +567,22 @@ public static boolean isNavBarVisible(@NonNull final Window window) {
}
}
if (isVisible) {
+ // 对于三星手机,android10以下非OneUI2的版本,比如 s8,note8 等设备上,
+ // 导航栏显示存在bug:"当用户隐藏导航栏时显示输入法的时候导航栏会跟随显示",会导致隐藏输入法之后判断错误
+ // 这个问题在 OneUI 2 & android 10 版本已修复
+ if (UtilsBridge.isSamsung()
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
+ && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ try {
+ return Settings.Global.getInt(Utils.getApp().getContentResolver(), "navigationbar_hide_bar_enabled") == 0;
+ } catch (Exception ignore) {
+ }
+ }
+
int visibility = decorView.getSystemUiVisibility();
isVisible = (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
}
+
return isVisible;
}
@@ -700,4 +715,26 @@ public static boolean isNavBarLightMode(@NonNull final Window window) {
}
return false;
}
+
+ public static void transparentNavBar(@NonNull final Activity activity) {
+ transparentNavBar(activity.getWindow());
+ }
+
+ public static void transparentNavBar(@NonNull final Window window) {
+ if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) return;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ window.setNavigationBarContrastEnforced(false);
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ window.setNavigationBarColor(Color.TRANSPARENT);
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ if ((window.getAttributes().flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0) {
+ window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
+ }
+ }
+ View decorView = window.getDecorView();
+ int vis = decorView.getSystemUiVisibility();
+ int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
+ decorView.setSystemUiVisibility(vis | option);
+ }
}
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BrightnessUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BrightnessUtils.java
index f9344b0a59..08dd46ff9b 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BrightnessUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BrightnessUtils.java
@@ -2,11 +2,12 @@
import android.content.ContentResolver;
import android.provider.Settings;
-import android.support.annotation.IntRange;
-import android.support.annotation.NonNull;
import android.view.Window;
import android.view.WindowManager;
+import androidx.annotation.IntRange;
+import androidx.annotation.NonNull;
+
/**
*
* author: Blankj
@@ -105,7 +106,7 @@ public static void setWindowBrightness(@NonNull final Window window,
* @param window 窗口
* @return 屏幕亮度 0-255
*/
- public static int getWindowBrightness(final Window window) {
+ public static int getWindowBrightness(@NonNull final Window window) {
WindowManager.LayoutParams lp = window.getAttributes();
float brightness = lp.screenBrightness;
if (brightness < 0) return getBrightness();
diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BusUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BusUtils.java
index 860d369b39..537a55fd92 100644
--- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BusUtils.java
+++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BusUtils.java
@@ -8,8 +8,6 @@
import java.lang.annotation.Target;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -18,6 +16,9 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
/**
*
* author: Blankj
@@ -31,8 +32,7 @@ public final class BusUtils {
private static final Object NULL = "nULl";
private static final String TAG = "BusUtils";
- private final Map> mTag_BusInfoListMap = new HashMap<>();
-
+ private final Map> mTag_BusInfoListMap = new ConcurrentHashMap<>();
private final Map> mClassName_BusesMap = new ConcurrentHashMap<>();
private final Map> mClassName_TagsMap = new ConcurrentHashMap<>();
private final Map> mClassName_Tag_Arg4StickyMap = new ConcurrentHashMap<>();
@@ -58,33 +58,33 @@ private void registerBus(String tag,
boolean sticky, String threadMode, int priority) {
List busInfoList = mTag_BusInfoListMap.get(tag);
if (busInfoList == null) {
- busInfoList = new ArrayList<>();
+ busInfoList = new CopyOnWriteArrayList<>();
mTag_BusInfoListMap.put(tag, busInfoList);
}
- busInfoList.add(new BusInfo(className, funName, paramType, paramName, sticky, threadMode, priority));
+ busInfoList.add(new BusInfo(tag, className, funName, paramType, paramName, sticky, threadMode, priority));
}
- public static void register(final Object bus) {
+ public static void register(@Nullable final Object bus) {
getInstance().registerInner(bus);
}
- public static void unregister(final Object bus) {
+ public static void unregister(@Nullable final Object bus) {
getInstance().unregisterInner(bus);
}
- public static void post(final String tag) {
+ public static void post(@NonNull final String tag) {
post(tag, NULL);
}
- public static void post(final String tag, final Object arg) {
+ public static void post(@NonNull final String tag, @NonNull final Object arg) {
getInstance().postInner(tag, arg);
}
- public static void postSticky(final String tag) {
+ public static void postSticky(@NonNull final String tag) {
postSticky(tag, NULL);
}
- public static void postSticky(final String tag, final Object arg) {
+ public static void postSticky(@NonNull final String tag, final Object arg) {
getInstance().postStickyInner(tag, arg);
}
@@ -105,18 +105,32 @@ private static BusUtils getInstance() {
return LazyHolder.INSTANCE;
}
- private void registerInner(final Object bus) {
+ private void registerInner(@Nullable final Object bus) {
if (bus == null) return;
- Class aClass = bus.getClass();
+ Class> aClass = bus.getClass();
String className = aClass.getName();
+ boolean isNeedRecordTags = false;
synchronized (mClassName_BusesMap) {
Set