Skip to content

Commit ab57d80

Browse files
authored
Merge pull request #16 from technoir42/androidx
Migrate to AndroidX
2 parents 6af3c5f + ad7bc81 commit ab57d80

File tree

10 files changed

+137
-115
lines changed

10 files changed

+137
-115
lines changed

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Problem
77
-------
88

99
Original implementation of Handler always keeps hard reference to handler in queue of execution.
10-
Any object in Message or Runnable posted to `android.os.Handler` will be hard referenced for some time.
10+
Any object in Message or Runnable posted to `android.os.Handler` will be hard referenced for some time.
1111
If you create anonymous Runnable and call to `postDelayed` with large timeout, that Runnable will be held
12-
in memory until timeout passes. Even if your Runnable seems small, it indirectly references owner class,
12+
in memory until timeout passes. Even if your Runnable seems small, it indirectly references owner class,
1313
which is usually something as big as Activity or Fragment.
14-
15-
You can read more [on our blog post.](http://techblog.badoo.com/blog/2014/08/28/android-handler-memory-leaks)
14+
15+
You can read more [on our blog post](https://medium.com/bumble-tech/android-handler-memory-leaks-7291c5be6101).
1616

1717
Solution
1818
--------
@@ -24,18 +24,14 @@ and GC could collect them once `WeakHandler` instance is not referenced any more
2424

2525
Usage
2626
-----
27-
Add reference to your build.gradle:
27+
Add JitPack repository to your build.gradle:
2828
```groovy
2929
repositories {
30-
maven {
31-
repositories {
32-
url 'https://oss.sonatype.org/content/repositories/releases/'
33-
}
34-
}
30+
maven { url 'https://jitpack.io' }
3531
}
3632
3733
dependencies {
38-
compile 'com.badoo.mobile:android-weak-handler:1.1'
34+
implementation 'com.github.badoo:android-weak-handler:1.2'
3935
}
4036
```
4137

@@ -46,15 +42,15 @@ import com.badoo.mobile.util.WeakHandler;
4642

4743
public class ExampleActivity extends Activity {
4844

49-
private WeakHandler mHandler; // We still need at least one hard reference to WeakHandler
50-
45+
private WeakHandler handler; // We still need at least one hard reference to WeakHandler
46+
5147
protected void onCreate(Bundle savedInstanceState) {
52-
mHandler = new WeakHandler();
48+
handler = new WeakHandler();
5349
...
5450
}
55-
51+
5652
private void onClick(View view) {
57-
mHandler.postDelayed(new Runnable() {
53+
handler.postDelayed(new Runnable() {
5854
view.setVisibility(View.INVISIBLE);
5955
}, 5000);
6056
}
@@ -63,7 +59,7 @@ public class ExampleActivity extends Activity {
6359

6460
Credits
6561
-------
66-
Weak Handler is brought to you by [Badoo Trading Limited](http://corp.badoo.com) and it is released under the [MIT License](http://opensource.org/licenses/MIT).
62+
Weak Handler is brought to you by [Badoo Trading Limited](https://corp.badoo.com) and it is released under the [MIT License](https://opensource.org/licenses/MIT).
6763

6864
Created by [Dmytro Voronkevych](https://github.com/dmitry-voronkevich)
6965

build.gradle

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,50 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
* THE SOFTWARE.
2020
*/
21-
project.ext.set('VERSION_CODE', 2)
22-
project.ext.set('VERSION_NAME', '1.1')
21+
project.ext.set('VERSION_CODE', 3)
22+
project.ext.set('VERSION_NAME', '1.2')
2323

2424
buildscript {
2525
repositories {
2626
mavenCentral()
27+
google()
28+
jcenter()
2729
}
2830

2931
dependencies {
30-
classpath 'com.android.tools.build:gradle:1.2.3'
32+
classpath 'com.android.tools.build:gradle:4.1.1'
3133
}
3234
}
3335

3436
apply plugin: 'com.android.library'
3537

3638
repositories {
3739
mavenCentral()
40+
google()
41+
jcenter()
3842
}
3943

4044
dependencies {
41-
compile "com.android.support:support-annotations:22.2.0"
42-
androidTestCompile 'junit:junit:4.12'
43-
androidTestCompile('com.android.support.test:runner:0.2') {
44-
exclude group: 'junit'
45-
}
45+
implementation "androidx.annotation:annotation:1.1.0"
46+
androidTestImplementation 'junit:junit:4.12'
47+
androidTestImplementation 'androidx.test:runner:1.1.0'
4648
}
4749

4850

4951
android {
50-
compileSdkVersion 22
51-
buildToolsVersion "22.0.1"
52+
compileSdkVersion 30
5253

5354
defaultConfig {
5455
versionCode project.VERSION_CODE
5556
versionName project.VERSION_NAME
56-
minSdkVersion 8
57+
minSdkVersion 14
5758
targetSdkVersion 22
5859

59-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
60+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
61+
}
62+
63+
buildFeatures {
64+
buildConfig false
6065
}
6166
}
6267

@@ -65,4 +70,3 @@ if (project.hasProperty('badooMavenScript')) {
6570
} else {
6671
apply from: 'mvn-local-support.gradle'
6772
}
68-

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
android.useAndroidX=true

gradle/wrapper/gradle-wrapper.jar

7.91 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Tue Jun 02 19:11:40 BST 2015
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip

gradlew

Lines changed: 69 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,59 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
2+
3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
218

319
##############################################################################
420
##
521
## Gradle start up script for UN*X
622
##
723
##############################################################################
824

9-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10-
DEFAULT_JVM_OPTS=""
25+
# Attempt to set APP_HOME
26+
# Resolve links: $0 may be a link
27+
PRG="$0"
28+
# Need this for relative symlinks.
29+
while [ -h "$PRG" ] ; do
30+
ls=`ls -ld "$PRG"`
31+
link=`expr "$ls" : '.*-> \(.*\)$'`
32+
if expr "$link" : '/.*' > /dev/null; then
33+
PRG="$link"
34+
else
35+
PRG=`dirname "$PRG"`"/$link"
36+
fi
37+
done
38+
SAVED="`pwd`"
39+
cd "`dirname \"$PRG\"`/" >/dev/null
40+
APP_HOME="`pwd -P`"
41+
cd "$SAVED" >/dev/null
1142

1243
APP_NAME="Gradle"
1344
APP_BASE_NAME=`basename "$0"`
1445

46+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48+
1549
# Use the maximum available, or set MAX_FD != -1 to use that value.
1650
MAX_FD="maximum"
1751

18-
warn ( ) {
52+
warn () {
1953
echo "$*"
2054
}
2155

22-
die ( ) {
56+
die () {
2357
echo
2458
echo "$*"
2559
echo
@@ -30,6 +64,7 @@ die ( ) {
3064
cygwin=false
3165
msys=false
3266
darwin=false
67+
nonstop=false
3368
case "`uname`" in
3469
CYGWIN* )
3570
cygwin=true
@@ -40,33 +75,14 @@ case "`uname`" in
4075
MINGW* )
4176
msys=true
4277
;;
78+
NONSTOP* )
79+
nonstop=true
80+
;;
4381
esac
4482

45-
# For Cygwin, ensure paths are in UNIX format before anything is touched.
46-
if $cygwin ; then
47-
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48-
fi
49-
50-
# Attempt to set APP_HOME
51-
# Resolve links: $0 may be a link
52-
PRG="$0"
53-
# Need this for relative symlinks.
54-
while [ -h "$PRG" ] ; do
55-
ls=`ls -ld "$PRG"`
56-
link=`expr "$ls" : '.*-> \(.*\)$'`
57-
if expr "$link" : '/.*' > /dev/null; then
58-
PRG="$link"
59-
else
60-
PRG=`dirname "$PRG"`"/$link"
61-
fi
62-
done
63-
SAVED="`pwd`"
64-
cd "`dirname \"$PRG\"`/" >&-
65-
APP_HOME="`pwd -P`"
66-
cd "$SAVED" >&-
67-
6883
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6984

85+
7086
# Determine the Java command to use to start the JVM.
7187
if [ -n "$JAVA_HOME" ] ; then
7288
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -90,7 +106,7 @@ location of your Java installation."
90106
fi
91107

92108
# Increase the maximum file descriptors if we can.
93-
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
109+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
94110
MAX_FD_LIMIT=`ulimit -H -n`
95111
if [ $? -eq 0 ] ; then
96112
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -110,11 +126,13 @@ if $darwin; then
110126
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111127
fi
112128

113-
# For Cygwin, switch paths to Windows format before running java
114-
if $cygwin ; then
129+
# For Cygwin or MSYS, switch paths to Windows format before running java
130+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
115131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117133

134+
JAVACMD=`cygpath --unix "$JAVACMD"`
135+
118136
# We build the pattern for arguments to be converted via cygpath
119137
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120138
SEP=""
@@ -138,27 +156,30 @@ if $cygwin ; then
138156
else
139157
eval `echo args$i`="\"$arg\""
140158
fi
141-
i=$((i+1))
159+
i=`expr $i + 1`
142160
done
143161
case $i in
144-
(0) set -- ;;
145-
(1) set -- "$args0" ;;
146-
(2) set -- "$args0" "$args1" ;;
147-
(3) set -- "$args0" "$args1" "$args2" ;;
148-
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149-
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150-
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151-
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152-
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153-
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
162+
0) set -- ;;
163+
1) set -- "$args0" ;;
164+
2) set -- "$args0" "$args1" ;;
165+
3) set -- "$args0" "$args1" "$args2" ;;
166+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154172
esac
155173
fi
156174

157-
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158-
function splitJvmOpts() {
159-
JVM_OPTS=("$@")
175+
# Escape application args
176+
save () {
177+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178+
echo " "
160179
}
161-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
180+
APP_ARGS=`save "$@"`
181+
182+
# Collect all arguments for the java command, following the shell quoting and substitution rules
183+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
163184

164-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
185+
exec "$JAVACMD" "$@"

0 commit comments

Comments
 (0)