From 09803b4a85cad00a5f7b27b67ceeb08f9d849a87 Mon Sep 17 00:00:00 2001 From: George Metaxas Date: Thu, 4 Oct 2018 15:32:49 +0300 Subject: [PATCH 1/3] Update the project to gradle 4.6 and build tools 3.2.0 --- build.gradle | 12 +++++++----- config/quality.gradle | 5 ++++- config/quality/checkstyle/checkstyle.xml | 4 +--- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 12 ++++++------ sample/build.gradle | 18 ++++++++---------- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index c606683..871bd4b 100644 --- a/build.gradle +++ b/build.gradle @@ -2,11 +2,12 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1' + classpath 'com.android.tools.build:gradle:3.2.0' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,6 +16,7 @@ buildscript { allprojects { repositories { + google() jcenter() } } @@ -25,9 +27,9 @@ task clean(type: Delete) { ext { - buildToolsVersion = "25.0.0" - compileSdkVersion = 25 - targetSdkVersion = 25 + buildToolsVersion = "28.0.2" + compileSdkVersion = 27 + targetSdkVersion = 27 minSdkVersion = 14 versionCode = 4 versionName = "0.0.4" diff --git a/config/quality.gradle b/config/quality.gradle index f80a937..33b2851 100644 --- a/config/quality.gradle +++ b/config/quality.gradle @@ -14,6 +14,9 @@ task checkstyle(type: Checkstyle) { exclude '**/gen/**' classpath = files() + checkstyle { + toolVersion = "6.5" + } } @@ -22,7 +25,7 @@ task findbugs(type: FindBugs) { effort = "max" reportLevel = "high" excludeFilter = new File("${project.rootDir}/config/quality/findbugs/findbugs-filter.xml") - classes = files("${project.rootDir}/library/build/intermediates/classes") + classes = fileTree("${project.rootDir}/library/build/intermediates/javac/") source 'src' include '**/*.java' diff --git a/config/quality/checkstyle/checkstyle.xml b/config/quality/checkstyle/checkstyle.xml index 410ab1e..c182c0d 100644 --- a/config/quality/checkstyle/checkstyle.xml +++ b/config/quality/checkstyle/checkstyle.xml @@ -314,9 +314,7 @@ - - - + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 85380ee..dffbb65 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-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/library/build.gradle b/library/build.gradle index 161d873..762ebbb 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -28,12 +28,12 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - testCompile 'org.mockito:mockito-core:1.9.5' - testCompile 'org.robolectric:robolectric:3.0' - compile 'com.android.support:appcompat-v7:25.0.0' - compile 'com.android.support:recyclerview-v7:25.0.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-core:1.9.5' + testImplementation 'org.robolectric:robolectric:3.0' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support:recyclerview-v7:27.1.1' } Properties properties = new Properties() diff --git a/sample/build.gradle b/sample/build.gradle index 76f92d5..95569ac 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.0" + compileSdkVersion 27 + buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { applicationId "fr.tvbarthel.intentsharesample" minSdkVersion 14 - targetSdkVersion 25 + targetSdkVersion 27 versionCode 3 versionName "1.2" } @@ -20,11 +20,9 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:25.0.0' - compile 'com.android.support:design:25.0.0' - compile project(':library') - compile project(':picasso-loader') - compile project(':glide-loader') + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support:design:27.1.1' + implementation project(':library') } From 4e79c2a54340e7a145af10e9397cf188632a7d4a Mon Sep 17 00:00:00 2001 From: George Metaxas Date: Thu, 4 Oct 2018 15:33:28 +0300 Subject: [PATCH 2/3] Remove unnecessary modules (the loading functionality will be changed) --- glide-loader/.gitignore | 1 - glide-loader/build.gradle | 125 ------------------ glide-loader/proguard-rules.pro | 17 --- glide-loader/src/main/AndroidManifest.xml | 5 - .../loader/glide/GlideIconLoader.java | 69 ---------- picasso-loader/.gitignore | 1 - picasso-loader/build.gradle | 125 ------------------ picasso-loader/proguard-rules.pro | 17 --- picasso-loader/src/main/AndroidManifest.xml | 5 - .../loader/picasso/PicassoIconLoader.java | 68 ---------- .../intentsharesample/MainActivity.java | 16 --- settings.gradle | 2 +- 12 files changed, 1 insertion(+), 450 deletions(-) delete mode 100644 glide-loader/.gitignore delete mode 100644 glide-loader/build.gradle delete mode 100644 glide-loader/proguard-rules.pro delete mode 100644 glide-loader/src/main/AndroidManifest.xml delete mode 100644 glide-loader/src/main/java/fr/tvbarthel/intentshare/loader/glide/GlideIconLoader.java delete mode 100644 picasso-loader/.gitignore delete mode 100644 picasso-loader/build.gradle delete mode 100644 picasso-loader/proguard-rules.pro delete mode 100644 picasso-loader/src/main/AndroidManifest.xml delete mode 100644 picasso-loader/src/main/java/fr/tvbarthel/intentshare/loader/picasso/PicassoIconLoader.java diff --git a/glide-loader/.gitignore b/glide-loader/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/glide-loader/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/glide-loader/build.gradle b/glide-loader/build.gradle deleted file mode 100644 index 6eaaa24..0000000 --- a/glide-loader/build.gradle +++ /dev/null @@ -1,125 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'com.jfrog.bintray' -apply from: '../config/quality.gradle' - -group = 'fr.tvbarthel.intentshare' -version = rootProject.ext.versionName - -android { - compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion - - defaultConfig { - minSdkVersion rootProject.ext.minSdkVersion - targetSdkVersion rootProject.ext.targetSdkVersion - versionCode rootProject.ext.versionCode - versionName rootProject.ext.versionName - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - - compile project(':library') - - compile 'com.github.bumptech.glide:glide:3.7.0' -} - -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) -def bintrayUser = properties.getProperty('bintray.user') -def bintrayKey = properties.getProperty('bintray.apikey') - -bintray { - user = bintrayUser - key = bintrayKey - - - configurations = ['archives'] //When uploading configuration files - - dryRun = false //Whether to run this as dry-run, without deploying - publish = true //If version should be auto published after an upload - //Package configuration. The plugin will use the repo and name properties to check if the package already exists. In that case, there's no need to configure the other package properties (like userOrg, desc, etc). - pkg { - repo = 'maven' - name = 'GlideLoader' - desc = 'Icon loader based on Glide for IntentShare library.' - websiteUrl = 'https://github.com/tvbarthel/IntentShare' - issueTrackerUrl = 'https://github.com/tvbarthel/IntentShare/issues' - vcsUrl = 'https://github.com/tvbarthel/IntentShare.git' - licenses = ['Apache-2.0'] - labels = ['android', 'intent', 'sharing', 'share', 'glide'] - publicDownloadNumbers = true - version { - gpg { - sign = true //Determines whether to GPG sign the files. The default is false - } - } - - } -} - -install { - repositories.mavenInstaller { - pom { - project { - packaging 'aar' - name 'GlideLoader' - url 'https://github.com/tvbarthel/IntentShare' - description 'Icon loader based on Glide for IntentShare library.' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - developers { - developer { - id 'tbarthel-fr' - name 'Thomas Barthelemy' - email 'thomas.barthelemy.utc@gmail.com' - } - developer { - id 'vbarthel-fr' - name 'Vincent Barthelemy' - email 'vincent.barthelemy.perso@gmail.com' - } - } - scm { - connection 'https://github.com/tvbarthel/IntentShare.git' - developerConnection 'https://github.com/tvbarthel/IntentShare.git' - url 'https://github.com/tvbarthel/IntentShare' - - } - } - } - } -} - -task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' -} - -task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - failOnError = false -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} -artifacts { - archives javadocJar - archives sourcesJar -} diff --git a/glide-loader/proguard-rules.pro b/glide-loader/proguard-rules.pro deleted file mode 100644 index 4c0b463..0000000 --- a/glide-loader/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/thomasbarthelemy/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/glide-loader/src/main/AndroidManifest.xml b/glide-loader/src/main/AndroidManifest.xml deleted file mode 100644 index f432399..0000000 --- a/glide-loader/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/glide-loader/src/main/java/fr/tvbarthel/intentshare/loader/glide/GlideIconLoader.java b/glide-loader/src/main/java/fr/tvbarthel/intentshare/loader/glide/GlideIconLoader.java deleted file mode 100644 index d7cf09b..0000000 --- a/glide-loader/src/main/java/fr/tvbarthel/intentshare/loader/glide/GlideIconLoader.java +++ /dev/null @@ -1,69 +0,0 @@ -package fr.tvbarthel.intentshare.loader.glide; - -import android.net.Uri; -import android.os.Parcel; -import android.widget.ImageView; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.engine.DiskCacheStrategy; - -import fr.tvbarthel.intentshare.IconLoader; - -/** - * {@link fr.tvbarthel.intentshare.IconLoader} based on {@link com.bumptech.glide.Glide} - */ -public class GlideIconLoader implements IconLoader { - - /** - * Parcelable - */ - public static final Creator CREATOR = new Creator() { - @Override - public GlideIconLoader createFromParcel(Parcel source) { - return new GlideIconLoader(source); - } - - @Override - public GlideIconLoader[] newArray(int size) { - return new GlideIconLoader[size]; - } - }; - - /** - * {@link fr.tvbarthel.intentshare.IconLoader} based on {@link com.bumptech.glide.Glide} - */ - public GlideIconLoader() { - } - - /** - * {@link fr.tvbarthel.intentshare.IconLoader} based on {@link com.bumptech.glide.Glide} - * - * @param in parcel. - */ - protected GlideIconLoader(Parcel in) { - } - - @Override - public void load(Uri iconUri, ImageView imageView) { - Glide.with(imageView.getContext()) - .load(iconUri) - .fitCenter() - .diskCacheStrategy(DiskCacheStrategy.RESULT) - .into(imageView); - } - - @Override - public void cancel(ImageView imageView) { - Glide.clear(imageView); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - } - -} diff --git a/picasso-loader/.gitignore b/picasso-loader/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/picasso-loader/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/picasso-loader/build.gradle b/picasso-loader/build.gradle deleted file mode 100644 index e73c99d..0000000 --- a/picasso-loader/build.gradle +++ /dev/null @@ -1,125 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'com.jfrog.bintray' -apply from: '../config/quality.gradle' - -group = 'fr.tvbarthel.intentshare' -version = rootProject.ext.versionName - -android { - compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion - - defaultConfig { - minSdkVersion rootProject.ext.minSdkVersion - targetSdkVersion rootProject.ext.targetSdkVersion - versionCode rootProject.ext.versionCode - versionName rootProject.ext.versionName - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - - compile 'com.squareup.picasso:picasso:2.5.2' - - compile project(':library') -} - -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) -def bintrayUser = properties.getProperty('bintray.user') -def bintrayKey = properties.getProperty('bintray.apikey') - -bintray { - user = bintrayUser - key = bintrayKey - - - configurations = ['archives'] //When uploading configuration files - - dryRun = false //Whether to run this as dry-run, without deploying - publish = true //If version should be auto published after an upload - //Package configuration. The plugin will use the repo and name properties to check if the package already exists. In that case, there's no need to configure the other package properties (like userOrg, desc, etc). - pkg { - repo = 'maven' - name = 'PicassoLoader' - desc = 'Icon loader based on Picasso for IntentShare library.' - websiteUrl = 'https://github.com/tvbarthel/IntentShare' - issueTrackerUrl = 'https://github.com/tvbarthel/IntentShare/issues' - vcsUrl = 'https://github.com/tvbarthel/IntentShare.git' - licenses = ['Apache-2.0'] - labels = ['android', 'intent', 'sharing', 'share', 'picasso'] - publicDownloadNumbers = true - version { - gpg { - sign = true //Determines whether to GPG sign the files. The default is false - } - } - - } -} - -install { - repositories.mavenInstaller { - pom { - project { - packaging 'aar' - name 'PicassoLoader' - url 'https://github.com/tvbarthel/IntentShare' - description 'Icon loader based on Picasso for IntentShare library.' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - developers { - developer { - id 'tbarthel-fr' - name 'Thomas Barthelemy' - email 'thomas.barthelemy.utc@gmail.com' - } - developer { - id 'vbarthel-fr' - name 'Vincent Barthelemy' - email 'vincent.barthelemy.perso@gmail.com' - } - } - scm { - connection 'https://github.com/tvbarthel/IntentShare.git' - developerConnection 'https://github.com/tvbarthel/IntentShare.git' - url 'https://github.com/tvbarthel/IntentShare' - - } - } - } - } -} - -task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' -} - -task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - failOnError = false -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} -artifacts { - archives javadocJar - archives sourcesJar -} diff --git a/picasso-loader/proguard-rules.pro b/picasso-loader/proguard-rules.pro deleted file mode 100644 index 4c0b463..0000000 --- a/picasso-loader/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/thomasbarthelemy/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/picasso-loader/src/main/AndroidManifest.xml b/picasso-loader/src/main/AndroidManifest.xml deleted file mode 100644 index c12c9fc..0000000 --- a/picasso-loader/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/picasso-loader/src/main/java/fr/tvbarthel/intentshare/loader/picasso/PicassoIconLoader.java b/picasso-loader/src/main/java/fr/tvbarthel/intentshare/loader/picasso/PicassoIconLoader.java deleted file mode 100644 index 2d63c64..0000000 --- a/picasso-loader/src/main/java/fr/tvbarthel/intentshare/loader/picasso/PicassoIconLoader.java +++ /dev/null @@ -1,68 +0,0 @@ -package fr.tvbarthel.intentshare.loader.picasso; - -import android.net.Uri; -import android.os.Parcel; -import android.widget.ImageView; - -import com.squareup.picasso.Picasso; - -import fr.tvbarthel.intentshare.IconLoader; - -/** - * {@link IconLoader} based on {@link com.squareup.picasso.Picasso}. - */ -public class PicassoIconLoader implements IconLoader { - - /** - * Parcelable. - */ - public static final Creator CREATOR = new Creator() { - @Override - public PicassoIconLoader createFromParcel(Parcel source) { - return new PicassoIconLoader(source); - } - - @Override - public PicassoIconLoader[] newArray(int size) { - return new PicassoIconLoader[size]; - } - }; - - /** - * {@link IconLoader} based on {@link com.squareup.picasso.Picasso}. - */ - public PicassoIconLoader() { - } - - /** - * {@link IconLoader} based on {@link com.squareup.picasso.Picasso}. - * - * @param in parcel. - */ - protected PicassoIconLoader(Parcel in) { - } - - @Override - public void load(Uri iconUri, ImageView imageView) { - Picasso.with(imageView.getContext()) - .load(iconUri) - .fit() - .centerInside() - .into(imageView); - } - - @Override - public void cancel(ImageView imageView) { - Picasso.with(imageView.getContext()).cancelRequest(imageView); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - } - -} diff --git a/sample/src/main/java/fr/tvbarthel/intentsharesample/MainActivity.java b/sample/src/main/java/fr/tvbarthel/intentsharesample/MainActivity.java index 4af81ef..de0c8fb 100644 --- a/sample/src/main/java/fr/tvbarthel/intentsharesample/MainActivity.java +++ b/sample/src/main/java/fr/tvbarthel/intentsharesample/MainActivity.java @@ -27,8 +27,6 @@ import fr.tvbarthel.intentshare.IntentShare; import fr.tvbarthel.intentshare.IntentShareListener; import fr.tvbarthel.intentshare.TargetActivityComparatorProvider; -import fr.tvbarthel.intentshare.loader.glide.GlideIconLoader; -import fr.tvbarthel.intentshare.loader.picasso.PicassoIconLoader; public class MainActivity extends AppCompatActivity implements Adapter.Listener, View.OnClickListener, ExtraProviderDialogFragment.Callback { @@ -48,10 +46,8 @@ public class MainActivity extends AppCompatActivity implements private IntentShareListener intentShareListener; - private PicassoIconLoader picassoIconLoader; private IconLoader iconLoader; private TargetActivityComparatorProvider customComparatorProvider; - private GlideIconLoader glideIconLoader; private String targetPackage; private String dialogTitle; @@ -111,18 +107,6 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.sample_icon_loader_default: iconLoader = null; break; - case R.id.sample_icon_loader_picasso: - if (picassoIconLoader == null) { - picassoIconLoader = new PicassoIconLoader(); - } - iconLoader = picassoIconLoader; - break; - case R.id.sample_icon_loader_glide: - if (glideIconLoader == null) { - glideIconLoader = new GlideIconLoader(); - } - iconLoader = picassoIconLoader; - break; case R.id.sorting_default: customComparatorProvider = null; break; diff --git a/settings.gradle b/settings.gradle index a0b86f8..f171b1f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':library', ':sample', ':picasso-loader', ':glide-loader' \ No newline at end of file +include ':library', ':sample' \ No newline at end of file From ca9bf587ff355f371c662b305830fe0bd70e03a3 Mon Sep 17 00:00:00 2001 From: George Metaxas Date: Thu, 4 Oct 2018 16:18:27 +0300 Subject: [PATCH 3/3] Modify the Icon loading functionality to use ActivityInfo#loadIcon instead --- .../intentshare/AsyncIconLoader.java | 116 +++++------------- .../fr/tvbarthel/intentshare/IconLoader.java | 8 +- .../tvbarthel/intentshare/TargetActivity.java | 31 +---- .../intentshare/TargetActivityManager.java | 2 +- .../intentshare/TargetActivityView.java | 6 +- 5 files changed, 40 insertions(+), 123 deletions(-) diff --git a/library/src/main/java/fr/tvbarthel/intentshare/AsyncIconLoader.java b/library/src/main/java/fr/tvbarthel/intentshare/AsyncIconLoader.java index 642f2db..95796af 100644 --- a/library/src/main/java/fr/tvbarthel/intentshare/AsyncIconLoader.java +++ b/library/src/main/java/fr/tvbarthel/intentshare/AsyncIconLoader.java @@ -1,23 +1,20 @@ package fr.tvbarthel.intentshare; import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.net.Uri; +import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Parcel; import android.util.Log; import android.util.SparseArray; import android.widget.ImageView; +import java.lang.ref.WeakReference; import java.util.HashMap; -import java.util.List; /** * Icon loader based on an {@link AsyncTask}. *

- * No cashing is performed for decoded {@link Bitmap}. */ class AsyncIconLoader implements IconLoader { @@ -37,12 +34,11 @@ public AsyncIconLoader[] newArray(int size) { }; private SparseArray task; - private HashMap cachedIcons; + private HashMap cachedIcons; /** * Icon loader based on an {@link AsyncTask} *

- * No cashing is performed for decoded {@link Bitmap}. * * @param in parcel. */ @@ -53,7 +49,6 @@ protected AsyncIconLoader(Parcel in) { /** * Icon loader based on an {@link AsyncTask} *

- * No cashing is performed for decoded {@link Bitmap}. */ public AsyncIconLoader() { task = new SparseArray<>(); @@ -67,16 +62,17 @@ public int describeContents() { @Override public void writeToParcel(Parcel dest, int flags) { + } @Override - public void load(Uri iconUri, ImageView imageView) { - Bitmap bitmap = cachedIcons.get(iconUri); - if (bitmap != null) { - imageView.setImageBitmap(bitmap); + public void load(ResolveInfo resolveInfo, ImageView imageView) { + Drawable drawable = cachedIcons.get(resolveInfo.activityInfo.packageName); + if (drawable != null) { + imageView.setImageDrawable(drawable); } else { AsyncIconLoaderTask asyncIconLoaderTask - = new AsyncIconLoaderTask(iconUri, imageView, cachedIcons); + = new AsyncIconLoaderTask(resolveInfo, imageView, cachedIcons); task.put(imageView.hashCode(), asyncIconLoaderTask); asyncIconLoaderTask.execute(); } @@ -95,105 +91,51 @@ public void cancel(ImageView imageView) { /** * {@link AsyncTask} used to load an icon off the ui thread. */ - private static final class AsyncIconLoaderTask extends AsyncTask { + private static final class AsyncIconLoaderTask extends AsyncTask { private static final String TAG = AsyncIconLoaderTask.class.getSimpleName(); - private final ImageView imageTarget; + private final WeakReference imageTarget; private final PackageManager packageManager; - private final String targetPackage; - private final HashMap cachedIcons; - private final Uri uri; - private int iconResId; - private int targetSize; + private final HashMap cachedIcons; + private ResolveInfo resolveInfo; /** * {@link AsyncTask} used to load an icon off the ui thread. * - * @param uri uri of the icon to load. + * @param resolveInfo the resolve info object of the correspoding resolved activity * @param imageView image view in which the icon should be loaded. * @param cachedIcons list of bitmap to which the new decoded one will be added. */ - public AsyncIconLoaderTask(Uri uri, ImageView imageView, HashMap cachedIcons) { + public AsyncIconLoaderTask(ResolveInfo resolveInfo, ImageView imageView, + HashMap cachedIcons) { packageManager = imageView.getContext().getPackageManager(); - this.uri = uri; - targetPackage = uri.getAuthority(); - iconResId = 0; - - List pathSegments = uri.getPathSegments(); - if (pathSegments.size() != 1) { - Log.e(TAG, "Can't find the icon res id for : " + uri.toString()); - } else { - try { - iconResId = Integer.parseInt(pathSegments.get(0)); - } catch (NumberFormatException e) { - Log.e(TAG, "Can't parse the icon res id : " + pathSegments.get(0)); - } - } + this.resolveInfo = resolveInfo; - imageTarget = imageView; - targetSize = imageView.getContext().getResources() - .getDimensionPixelSize(R.dimen.isl_target_activity_view_icon_size); + imageTarget = new WeakReference<>(imageView); this.cachedIcons = cachedIcons; } @Override - protected Bitmap doInBackground(Void... params) { - Resources resources; - try { - resources = packageManager.getResourcesForApplication(targetPackage); - } catch (PackageManager.NameNotFoundException e) { - Log.e(TAG, "Wrong package name, can't access to the resources : " + targetPackage); - return null; - } - - if (isCancelled()) { - return null; - } - - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - options.inPreferredConfig = Bitmap.Config.RGB_565; - BitmapFactory.decodeResource(resources, iconResId, options); - - if (isCancelled()) { - return null; - } - - options.inSampleSize = calculateInSampleSize(options, targetSize, targetSize); - options.inJustDecodeBounds = false; + protected Drawable doInBackground(Void... params) { if (isCancelled()) { return null; } else { - return BitmapFactory.decodeResource(resources, iconResId, options); + return resolveInfo.activityInfo.loadIcon(packageManager); } } @Override - protected void onPostExecute(Bitmap bitmap) { - super.onPostExecute(bitmap); - if (bitmap != null) { - imageTarget.setImageBitmap(bitmap); - cachedIcons.put(uri, bitmap); - } else { - Log.e(TAG, "Failed to load icon from uri : " + uri); - } - } - - private int calculateInSampleSize( - BitmapFactory.Options options, - int reqWidth, - int reqHeight) { - final int height = options.outHeight; - final int width = options.outWidth; - - if (reqWidth == 0 || reqHeight == 0) { - return 1; + protected void onPostExecute(Drawable drawable) { + super.onPostExecute(drawable); + if (drawable != null) { + if (imageTarget.get() != null) { + imageTarget.get().setImageDrawable(drawable); + } + cachedIcons.put(resolveInfo.activityInfo.packageName, drawable); } else { - int heightRatio = (int) Math.floor((float) height / (float) reqHeight); - int widthRatio = (int) Math.floor((float) width / (float) reqWidth); - return Math.min(heightRatio, widthRatio); + Log.e(TAG, "Failed to load icon from uri : " + resolveInfo.resolvePackageName); } } } diff --git a/library/src/main/java/fr/tvbarthel/intentshare/IconLoader.java b/library/src/main/java/fr/tvbarthel/intentshare/IconLoader.java index 7c851bb..28697dd 100644 --- a/library/src/main/java/fr/tvbarthel/intentshare/IconLoader.java +++ b/library/src/main/java/fr/tvbarthel/intentshare/IconLoader.java @@ -1,6 +1,6 @@ package fr.tvbarthel.intentshare; -import android.net.Uri; +import android.content.pm.ResolveInfo; import android.os.Parcelable; import android.widget.ImageView; @@ -15,16 +15,16 @@ public interface IconLoader extends Parcelable { *

* See also : {@link IconLoader#cancel(ImageView)} * - * @param iconUri uri of the icon to load. + * @param resolveInfo the resolve info associated with the corresponding target activity * @param imageView image view in which the icon should be loaded. */ - void load(Uri iconUri, ImageView imageView); + void load(ResolveInfo resolveInfo, ImageView imageView); /** * Called when the icon doesn't need to be loaded anymore. * Should cancel any async loading started previously. *

- * See also : {@link IconLoader#load(Uri, ImageView)} + * See also : {@link IconLoader#load(android.content.pm.ResolveInfo, ImageView)} * * @param imageView image view for which the async loading should be canceled. */ diff --git a/library/src/main/java/fr/tvbarthel/intentshare/TargetActivity.java b/library/src/main/java/fr/tvbarthel/intentshare/TargetActivity.java index 5e44238..13414ef 100644 --- a/library/src/main/java/fr/tvbarthel/intentshare/TargetActivity.java +++ b/library/src/main/java/fr/tvbarthel/intentshare/TargetActivity.java @@ -1,11 +1,8 @@ package fr.tvbarthel.intentshare; -import android.content.Context; import android.content.pm.ResolveInfo; -import android.net.Uri; import android.os.Parcel; -import java.io.File; import java.util.Comparator; /** @@ -14,7 +11,6 @@ public class TargetActivity { private final int activityLabelResId; - private final Uri iconUri; private final boolean isMail; private final long lastSelection; private ResolveInfo resolveInfo; @@ -23,25 +19,13 @@ public class TargetActivity { /** * Plain java model for a sharing target activity. * - * @param context context used to load target activity label. - * @param resolveInfo {@link ResolveInfo} linked to the target activity. + * @param resolveInfo {@link ResolveInfo} linked to the target activity. * @param lastSelection time stamp in milli of last selection. */ - public TargetActivity(Context context, ResolveInfo resolveInfo, long lastSelection) { + public TargetActivity(ResolveInfo resolveInfo, long lastSelection) { this.lastSelection = lastSelection; this.resolveInfo = resolveInfo; - int icon = resolveInfo.activityInfo.icon; - if (icon == 0) { - icon = resolveInfo.activityInfo.applicationInfo.icon; - } - this.iconUri = Uri.parse( - "android.resource://" - + resolveInfo.activityInfo.applicationInfo.packageName - + File.separator - + icon - ); - this.activityLabelResId = resolveInfo.labelRes; this.isMail = resolveInfo.filter.hasDataType("message/rfc822"); } @@ -104,15 +88,6 @@ public int getActivityLabelResId() { return activityLabelResId; } - /** - * Retrieve the Uri used to access to the target application launcher icon. - * - * @return uri linking to the application launcher icon. - */ - public Uri getIconUri() { - return iconUri; - } - /** * Used to know if the target activity is a mail client. *

@@ -175,6 +150,7 @@ public static final class RecencyComparatorProvider implements TargetActivityCom * Parcelable. */ public static final Creator CREATOR = new Creator() { + @Override public RecencyComparatorProvider createFromParcel(Parcel source) { return new RecencyComparatorProvider(source); @@ -212,7 +188,6 @@ protected RecencyComparatorProvider(Parcel in) { } - @Override public Comparator provideComparator() { return new Comparator() { diff --git a/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityManager.java b/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityManager.java index 9bf390c..0206d99 100644 --- a/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityManager.java +++ b/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityManager.java @@ -89,7 +89,7 @@ public void resolveTargetActivities(Context context, ResolveListener listener, long lastSelection = sharedPreferences.getLong(lastSelectionKey, 0); TargetActivity targetActivity - = new TargetActivity(context, targetActivityInfo, lastSelection); + = new TargetActivity(targetActivityInfo, lastSelection); targetActivities.add(targetActivity); } } diff --git a/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityView.java b/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityView.java index b639c9d..d192bb2 100644 --- a/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityView.java +++ b/library/src/main/java/fr/tvbarthel/intentshare/TargetActivityView.java @@ -93,7 +93,7 @@ public void setListener(Listener listener) { */ public void loadIcon() { icon.setImageDrawable(null); - asyncIconLoader.load(model.getIconUri(), icon); + asyncIconLoader.load(model.getResolveInfo(), icon); } /** @@ -126,8 +126,8 @@ private void initialize(Context context) { ) ); - icon = ((ImageView) findViewById(R.id.target_activity_view_icon)); - label = ((TextView) findViewById(R.id.target_activity_view_label)); + icon = findViewById(R.id.target_activity_view_icon); + label = findViewById(R.id.target_activity_view_label); mInternalClickListener = new OnClickListener() { @Override