├── app ├── .gitignore ├── src │ ├── main │ │ ├── ic_launcher-web.png │ │ ├── res │ │ │ ├── raw │ │ │ │ └── test_video.mov │ │ │ ├── drawable-xhdpi │ │ │ │ ├── cupcake.jpg │ │ │ │ ├── noise.png │ │ │ │ ├── floorplan.png │ │ │ │ └── full_cake.jpg │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── future_studio_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── future_studio_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── future_studio_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── future_studio_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── future_studio_launcher.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── layout │ │ │ │ ├── listview_item_image.xml │ │ │ │ ├── activity_usage_example_listview.xml │ │ │ │ ├── activity_usage_example_gridview.xml │ │ │ │ ├── custom_view_futurestudio.xml │ │ │ │ ├── listview_item_advanced.xml │ │ │ │ ├── activity_usage_example_simple_loading.xml │ │ │ │ ├── activity_standard_imageview.xml │ │ │ │ ├── remoteview_notification.xml │ │ │ │ └── activity_request_priority.xml │ │ │ ├── anim │ │ │ │ └── zoom_in.xml │ │ │ └── xml │ │ │ │ └── app_widget.xml │ │ ├── future_studio_launcher-web.png │ │ ├── java │ │ │ └── io │ │ │ │ └── futurestud │ │ │ │ └── tutorials │ │ │ │ └── glide │ │ │ │ ├── glidemodule │ │ │ │ ├── SimpleGlideModule.java │ │ │ │ ├── UnsafeOkHttpGlideModule.java │ │ │ │ ├── NetworkDisablingLoader.java │ │ │ │ ├── CheckLocalGlideModule.java │ │ │ │ ├── CustomImageSizeGlideModule.java │ │ │ │ └── CustomCachingGlideModule.java │ │ │ │ ├── ui │ │ │ │ ├── activities │ │ │ │ │ ├── UsageExampleGridViewAdapter.java │ │ │ │ │ ├── UsageExampleAdvancedAdapter.java │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ ├── UsageExampleDownload.java │ │ │ │ │ ├── UsageExampleGlideModuleUnsafeOkHttp.java │ │ │ │ │ ├── UsageExampleAnimate.java │ │ │ │ │ ├── UsageExampleCustomImageSize.java │ │ │ │ │ ├── UsageExampleListViewAdapter.java │ │ │ │ │ ├── UsageExampleThumbnails.java │ │ │ │ │ ├── GlideExampleActivity.java │ │ │ │ │ ├── UsageExampleErrorLogging.java │ │ │ │ │ ├── UsageExampleCacheBasics.java │ │ │ │ │ ├── UsageExampleRequestPriority.java │ │ │ │ │ ├── UsageExampleTransformations.java │ │ │ │ │ ├── UsageExampleGifAndVideos.java │ │ │ │ │ ├── UsageExampleImageResizing.java │ │ │ │ │ ├── UsageExampleNetworkDependent.java │ │ │ │ │ ├── UsageExampleSimpleLoading.java │ │ │ │ │ ├── UsageExamplePlaceholders.java │ │ │ │ │ ├── UsageExampleGlideUrl.java │ │ │ │ │ └── UsageExampleTargetsAndRemoteViews.java │ │ │ │ ├── views │ │ │ │ │ ├── FutureStudioView.java │ │ │ │ │ └── RoundedImageView.java │ │ │ │ ├── adapter │ │ │ │ │ ├── SimpleImageListAdapter.java │ │ │ │ │ └── AdvancedImageListAdapter.java │ │ │ │ ├── FSAppWidgetIntentReceiver.java │ │ │ │ ├── FSAppWidgetProvider.java │ │ │ │ └── MenuContent.java │ │ │ │ ├── transformation │ │ │ │ ├── RotateTransformation.java │ │ │ │ ├── BlurTransformation.java │ │ │ │ └── GrayscaleTransformation.java │ │ │ │ └── okhttp │ │ │ │ ├── OkHttpUrlLoader.java │ │ │ │ ├── UnsafeOkHttpClient.java │ │ │ │ └── OkHttpStreamFetcher.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── io │ │ └── futurestud │ │ └── tutorials │ │ └── glide │ │ └── ApplicationTest.java ├── proguard-rules.pro ├── build.gradle └── app.iml ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── libraries │ ├── renderscript_v8.xml │ ├── okio_1_6_0.xml │ ├── okhttp_2_7_5.xml │ ├── okhttp_3_2_0.xml │ ├── glide_3_7_0.xml │ ├── picasso_2_5_2.xml │ ├── butterknife_7_0_1.xml │ ├── support_annotations_23_2_1.xml │ ├── gpuimage_library_1_3_0.xml │ ├── glide_transformations_2_0_0.xml │ ├── support_vector_drawable_23_2_1.xml │ ├── okhttp3_integration_1_4_0.xml │ ├── animated_vector_drawable_23_2_1.xml │ ├── appcompat_v7_23_2_1.xml │ └── support_v4_23_2_1.xml ├── modules.xml ├── runConfigurations.xml ├── compiler.xml ├── gradle.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── android-tutorials-glide.iml ├── LICENSE ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/raw/test_video.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/raw/test_video.mov -------------------------------------------------------------------------------- /app/src/main/future_studio_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/future_studio_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/cupcake.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/drawable-xhdpi/cupcake.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/drawable-xhdpi/noise.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/floorplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/drawable-xhdpi/floorplan.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/full_cake.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/drawable-xhdpi/full_cake.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/future_studio_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-hdpi/future_studio_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/future_studio_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-mdpi/future_studio_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/future_studio_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-xhdpi/future_studio_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/future_studio_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-xxhdpi/future_studio_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/future_studio_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurestudio/android-tutorials-glide/HEAD/app/src/main/res/mipmap-xxxhdpi/future_studio_launcher.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Glide Tutorial 3 | UsageExample Detail 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/layout/listview_item_image.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Nov 08 21:08:12 CET 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_usage_example_listview.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/renderscript_v8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_usage_example_gridview.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | -------------------------------------------------------------------------------- /app/src/androidTest/java/io/futurestud/tutorials/glide/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/zoom_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/okio_1_6_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Glide Sample App 2 | 3 | This app demos a bunch of Glide's functionality. 4 | 5 | Deprecated. This app does not get updated anymore. An updated version to Glide 4.x can be found [here](https://futurestud.io/books/glide). 6 | 7 | 8 | 9 | ------ 10 | 11 | This Glide sample app is supported by Future Studio University 🚀 12 | 13 | Join the Future Studio University and Skyrocket in Android 14 | 15 | 16 | ------ 17 | -------------------------------------------------------------------------------- /.idea/libraries/okhttp_2_7_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/okhttp_3_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/glide_3_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/picasso_2_5_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/butterknife_7_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/gpuimage_library_1_3_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/glide_transformations_2_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/xml/app_widget.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_vector_drawable_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/okhttp3_integration_1_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_view_futurestudio.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/libraries/animated_vector_drawable_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/norman/Documents/Development/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/glidemodule/SimpleGlideModule.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.glidemodule; 2 | 3 | import android.content.Context; 4 | 5 | import com.bumptech.glide.Glide; 6 | import com.bumptech.glide.GlideBuilder; 7 | import com.bumptech.glide.load.DecodeFormat; 8 | import com.bumptech.glide.module.GlideModule; 9 | 10 | /** 11 | * Created by norman on 10/17/15. 12 | */ 13 | public class SimpleGlideModule implements GlideModule { 14 | @Override 15 | public void applyOptions(Context context, GlideBuilder builder) { 16 | builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); 17 | } 18 | 19 | @Override 20 | public void registerComponents(Context context, Glide glide) { 21 | // nothing to do here 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/glidemodule/UnsafeOkHttpGlideModule.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.glidemodule; 2 | 3 | import android.content.Context; 4 | 5 | import com.bumptech.glide.Glide; 6 | import com.bumptech.glide.GlideBuilder; 7 | import com.bumptech.glide.load.model.GlideUrl; 8 | import com.bumptech.glide.module.GlideModule; 9 | 10 | import java.io.InputStream; 11 | 12 | import io.futurestud.tutorials.glide.okhttp.OkHttpUrlLoader; 13 | 14 | public class UnsafeOkHttpGlideModule implements GlideModule { 15 | @Override 16 | public void applyOptions(Context context, GlideBuilder builder) { 17 | 18 | } 19 | 20 | @Override 21 | public void registerComponents(Context context, Glide glide) { 22 | glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); 23 | } 24 | } -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/res/layout/listview_item_advanced.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_23_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /android-tutorials-glide.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleGridViewAdapter.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.GridView; 6 | 7 | import butterknife.BindView; 8 | import butterknife.ButterKnife; 9 | import io.futurestud.tutorials.glide.R; 10 | import io.futurestud.tutorials.glide.ui.adapter.SimpleImageListAdapter; 11 | 12 | public class UsageExampleGridViewAdapter extends AppCompatActivity { 13 | 14 | @BindView(R.id.usage_example_gridview) GridView gridView; 15 | 16 | public UsageExampleGridViewAdapter() { 17 | } 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | 23 | setContentView(R.layout.activity_usage_example_gridview); 24 | ButterKnife.bind(this); 25 | 26 | gridView.setAdapter(new SimpleImageListAdapter(UsageExampleGridViewAdapter.this, UsageExampleListViewAdapter.eatFoodyImages)); 27 | } 28 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleAdvancedAdapter.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.ListView; 6 | 7 | import butterknife.BindView; 8 | import butterknife.ButterKnife; 9 | import io.futurestud.tutorials.glide.R; 10 | import io.futurestud.tutorials.glide.ui.adapter.AdvancedImageListAdapter; 11 | 12 | public class UsageExampleAdvancedAdapter extends AppCompatActivity { 13 | 14 | @BindView(R.id.usage_example_listview) ListView listView; 15 | 16 | public UsageExampleAdvancedAdapter() { 17 | } 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | 23 | setContentView(R.layout.activity_usage_example_listview); 24 | ButterKnife.bind(this); 25 | 26 | listView.setAdapter(new AdvancedImageListAdapter(UsageExampleAdvancedAdapter.this, UsageExampleListViewAdapter.eatFoodyImages)); 27 | } 28 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Future Studio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/glidemodule/NetworkDisablingLoader.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.glidemodule; 2 | 3 | import com.bumptech.glide.Priority; 4 | import com.bumptech.glide.load.data.DataFetcher; 5 | import com.bumptech.glide.load.model.stream.StreamModelLoader; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | /** 11 | * Created by norman on 12/3/16. 12 | */ 13 | 14 | public class NetworkDisablingLoader implements StreamModelLoader { 15 | @Override 16 | public DataFetcher getResourceFetcher(final String model, int width, int height) { 17 | return new DataFetcher() { 18 | @Override 19 | public InputStream loadData(Priority priority) throws Exception { 20 | throw new IOException("Forced Glide network failure"); 21 | } 22 | 23 | @Override 24 | public void cleanup() { 25 | } 26 | 27 | @Override 28 | public String getId() { 29 | return model; 30 | } 31 | 32 | @Override 33 | public void cancel() { 34 | } 35 | }; 36 | } 37 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/MainActivity.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.app.ListActivity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.ArrayAdapter; 8 | import android.widget.ListView; 9 | 10 | import io.futurestud.tutorials.glide.ui.MenuContent; 11 | 12 | 13 | public class MainActivity extends ListActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | 19 | setListAdapter(new ArrayAdapter<>( 20 | this, 21 | android.R.layout.simple_list_item_activated_1, 22 | android.R.id.text1, 23 | MenuContent.ITEMS)); 24 | } 25 | 26 | @Override 27 | protected void onListItemClick(ListView l, View v, int position, long id) { 28 | super.onListItemClick(l, v, position, id); 29 | 30 | showExampleActivity(MenuContent.ITEMS.get(position).goalClass); 31 | } 32 | 33 | private void showExampleActivity(Class targetClass) { 34 | startActivity(new Intent(this, targetClass)); 35 | } 36 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleDownload.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | import android.widget.Toast; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.request.FutureTarget; 8 | 9 | import java.io.File; 10 | import java.util.concurrent.ExecutionException; 11 | 12 | public class UsageExampleDownload extends GlideExampleActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | 18 | Toast.makeText(UsageExampleDownload.this, "No visual demo, check the source code :)", Toast.LENGTH_LONG).show(); 19 | 20 | //downloadImage(); 21 | } 22 | 23 | private void downloadImage() { 24 | FutureTarget fileFutureTarget = Glide 25 | .with(context) 26 | .load(eatFoodyImages[0]) 27 | .downloadOnly(500, 500); 28 | 29 | try { 30 | File file = fileFutureTarget.get(); 31 | } catch (InterruptedException e) { 32 | e.printStackTrace(); 33 | } catch (ExecutionException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/transformation/RotateTransformation.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.transformation; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Matrix; 6 | 7 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 8 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; 9 | 10 | /** 11 | * The code in this class is based on: 12 | * - https://github.com/bumptech/glide/issues/896 13 | */ 14 | public class RotateTransformation extends BitmapTransformation { 15 | 16 | private float rotateRotationAngle = 0f; 17 | 18 | public RotateTransformation(Context context, float rotateRotationAngle) { 19 | super(context); 20 | 21 | this.rotateRotationAngle = rotateRotationAngle; 22 | } 23 | 24 | @Override 25 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { 26 | Matrix matrix = new Matrix(); 27 | 28 | matrix.postRotate(rotateRotationAngle); 29 | 30 | return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true); 31 | } 32 | 33 | @Override 34 | public String getId() { 35 | return "rotate" + rotateRotationAngle; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/views/FutureStudioView.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.views; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.util.AttributeSet; 6 | import android.widget.FrameLayout; 7 | import android.widget.ImageView; 8 | import android.widget.TextView; 9 | 10 | import io.futurestud.tutorials.glide.R; 11 | 12 | /** 13 | * Created by norman on 10/10/15. 14 | */ 15 | public class FutureStudioView extends FrameLayout { 16 | ImageView iv; 17 | TextView tv; 18 | 19 | public void initialize(Context context) { 20 | inflate( context, R.layout.custom_view_futurestudio, this ); 21 | 22 | iv = (ImageView) findViewById( R.id.custom_view_image ); 23 | tv = (TextView) findViewById( R.id.custom_view_text ); 24 | } 25 | 26 | public FutureStudioView(Context context, AttributeSet attrs) { 27 | super( context, attrs ); 28 | initialize( context ); 29 | } 30 | 31 | public FutureStudioView(Context context, AttributeSet attrs, int defStyleAttr) { 32 | super( context, attrs, defStyleAttr ); 33 | initialize( context ); 34 | } 35 | 36 | public void setImage(Drawable drawable) { 37 | iv = (ImageView) findViewById( R.id.custom_view_image ); 38 | 39 | iv.setImageDrawable( drawable ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleGlideModuleUnsafeOkHttp.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.ImageView; 7 | 8 | import com.bumptech.glide.Glide; 9 | 10 | import butterknife.BindView; 11 | import butterknife.ButterKnife; 12 | import io.futurestud.tutorials.glide.R; 13 | 14 | public class UsageExampleGlideModuleUnsafeOkHttp extends AppCompatActivity { 15 | 16 | @BindView(R.id.standard_list_imageview1) ImageView imageView1; 17 | @BindView(R.id.standard_list_imageview2) ImageView imageView2; 18 | @BindView(R.id.standard_list_imageview3) ImageView imageView3; 19 | @BindView(R.id.standard_list_imageview4) ImageView imageView4; 20 | 21 | private Context context = this; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | 27 | setContentView(R.layout.activity_standard_imageview); 28 | ButterKnife.bind(this); 29 | 30 | loadImageViaUnsafeOkHttpPicassoInstance(); 31 | } 32 | 33 | private void loadImageViaUnsafeOkHttpPicassoInstance() { 34 | 35 | Glide 36 | .with(context) 37 | .load("unsafe https image") 38 | .into(imageView4); 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/adapter/SimpleImageListAdapter.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ArrayAdapter; 8 | import android.widget.ImageView; 9 | 10 | import com.bumptech.glide.Glide; 11 | 12 | import io.futurestud.tutorials.glide.R; 13 | 14 | /** 15 | * Created by norman on 4/10/15. 16 | */ 17 | public class SimpleImageListAdapter extends ArrayAdapter { 18 | private Context context; 19 | private LayoutInflater inflater; 20 | 21 | private String[] imageUrls; 22 | 23 | public SimpleImageListAdapter(Context context, String[] imageUrls) { 24 | super(context, R.layout.listview_item_image, imageUrls); 25 | 26 | this.context = context; 27 | this.imageUrls = imageUrls; 28 | 29 | inflater = LayoutInflater.from(context); 30 | } 31 | 32 | @Override 33 | public View getView(int position, View convertView, ViewGroup parent) { 34 | if (null == convertView) { 35 | convertView = inflater.inflate(R.layout.listview_item_image, parent, false); 36 | } 37 | 38 | Glide 39 | .with(context) 40 | .load(imageUrls[position]) 41 | .into((ImageView) convertView); 42 | 43 | return convertView; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/FSAppWidgetIntentReceiver.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.widget.RemoteViews; 7 | 8 | import io.futurestud.tutorials.glide.R; 9 | 10 | /** 11 | * Created by norman on 10/10/15. 12 | */ 13 | public class FSAppWidgetIntentReceiver extends BroadcastReceiver { 14 | 15 | private static int clickCount = 0; 16 | 17 | @Override 18 | public void onReceive(Context context, Intent intent) { 19 | if (intent.getAction().equals("pl.looksok.intent.action.CHANGE_PICTURE")) { 20 | updateWidgetPictureAndButtonListener(context); 21 | } 22 | } 23 | 24 | private void updateWidgetPictureAndButtonListener(Context context) { 25 | RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.custom_view_futurestudio); 26 | remoteViews.setImageViewResource(R.id.custom_view_image, getImageToSet()); 27 | 28 | //REMEMBER TO ALWAYS REFRESH YOUR BUTTON CLICK LISTENERS!!! 29 | //remoteViews.setOnClickPendingIntent( R.id.custom_view_image, FSAppWidgetProvider.buildButtonPendingIntent( context ) ); 30 | 31 | FSAppWidgetProvider.pushWidgetUpdate(context.getApplicationContext(), remoteViews); 32 | } 33 | 34 | private int getImageToSet() { 35 | clickCount++; 36 | return clickCount % 2 == 0 ? R.drawable.cupcake : R.drawable.floorplan; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleAnimate.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.animation.ObjectAnimator; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.bumptech.glide.request.animation.ViewPropertyAnimation; 9 | 10 | import io.futurestud.tutorials.glide.R; 11 | 12 | public class UsageExampleAnimate extends GlideExampleActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | 18 | loadImageAnimateResource(); 19 | loadImageAnimateCode(); 20 | } 21 | 22 | private void loadImageAnimateResource() { 23 | Glide 24 | .with(context) 25 | .load(eatFoodyImages[0]) 26 | .animate(R.anim.zoom_in) 27 | .into(imageView1); 28 | } 29 | 30 | private void loadImageAnimateCode() { 31 | ViewPropertyAnimation.Animator animationObject = new ViewPropertyAnimation.Animator() { 32 | @Override 33 | public void animate(View view) { 34 | view.setAlpha(0f); 35 | 36 | ObjectAnimator fadeAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f); 37 | fadeAnim.setDuration(2500); 38 | fadeAnim.start(); 39 | } 40 | }; 41 | 42 | Glide 43 | .with(context) 44 | .load(eatFoodyImages[1]) 45 | .animate(animationObject) 46 | .into(imageView2); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleCustomImageSize.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.bumptech.glide.Glide; 6 | 7 | import io.futurestud.tutorials.glide.glidemodule.CustomImageSizeGlideModule; 8 | 9 | import static io.futurestud.tutorials.glide.glidemodule.CustomImageSizeGlideModule.CustomImageSizeUrlLoader; 10 | 11 | public class UsageExampleCustomImageSize extends GlideExampleActivity { 12 | 13 | String baseImageUrl = "http://futurestud.io/blog/assets/images/futurestudio-logo.png"; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | 19 | loadImageWithCustomModel(); 20 | //loadImageWithGlideModule(); 21 | } 22 | 23 | private void loadImageWithCustomModel() { 24 | CustomImageSizeGlideModule.CustomImageSizeModel customImageRequest = new CustomImageSizeGlideModule.CustomImageSizeModelFutureStudio(baseImageUrl); 25 | 26 | Glide 27 | .with(context) 28 | .using(new CustomImageSizeUrlLoader(context)) 29 | .load(customImageRequest) 30 | .into(imageView1); 31 | } 32 | 33 | private void loadImageWithGlideModule() { 34 | CustomImageSizeGlideModule.CustomImageSizeModel customImageRequest = new CustomImageSizeGlideModule.CustomImageSizeModelFutureStudio(baseImageUrl); 35 | 36 | Glide 37 | .with(context) 38 | .load(customImageRequest) 39 | .into(imageView2); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_usage_example_simple_loading.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 12 | 13 | 19 | 20 | 26 | 27 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleListViewAdapter.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.ListView; 6 | 7 | import butterknife.BindView; 8 | import butterknife.ButterKnife; 9 | import io.futurestud.tutorials.glide.R; 10 | import io.futurestud.tutorials.glide.ui.adapter.SimpleImageListAdapter; 11 | 12 | public class UsageExampleListViewAdapter extends AppCompatActivity { 13 | 14 | public static String[] eatFoodyImages = { 15 | "http://i.imgur.com/rFLNqWI.jpg", 16 | "", 17 | "http://i.imgur.com/C9pBVt7.jpg", 18 | "", 19 | "", 20 | "http://i.imgur.com/rT5vXE1.jpg", 21 | "http://i.imgur.com/aIy5R2k.jpg", 22 | "http://i.imgur.com/MoJs9pT.jpg", 23 | "http://i.imgur.com/S963yEM.jpg", 24 | "http://i.imgur.com/rLR2cyc.jpg", 25 | "http://i.imgur.com/SEPdUIx.jpg", 26 | "http://i.imgur.com/aC9OjaM.jpg", 27 | "http://i.imgur.com/76Jfv9b.jpg", 28 | "http://i.imgur.com/fUX7EIB.jpg", 29 | "http://i.imgur.com/syELajx.jpg", 30 | "http://i.imgur.com/COzBnru.jpg", 31 | "http://i.imgur.com/Z3QjilA.jpg", 32 | }; 33 | 34 | @BindView(R.id.usage_example_listview) ListView listView; 35 | 36 | public UsageExampleListViewAdapter() { 37 | } 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | 43 | setContentView(R.layout.activity_usage_example_listview); 44 | ButterKnife.bind(this); 45 | 46 | listView.setAdapter(new SimpleImageListAdapter(UsageExampleListViewAdapter.this, eatFoodyImages)); 47 | } 48 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_standard_imageview.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 16 | 17 | 22 | 23 | 28 | 29 | 34 | 35 | 40 | 41 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleThumbnails.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.bumptech.glide.DrawableRequestBuilder; 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 8 | 9 | public class UsageExampleThumbnails extends GlideExampleActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | 15 | loadImageOriginal(); 16 | loadImageThumbnailScale(); 17 | loadImageThumbnailRequest(); 18 | } 19 | 20 | private void loadImageOriginal() { 21 | Glide 22 | .with(context) 23 | .load(eatFoodyImages[0]) 24 | .skipMemoryCache(true) 25 | .diskCacheStrategy(DiskCacheStrategy.NONE) 26 | .into(imageView1); 27 | } 28 | 29 | private void loadImageThumbnailScale() { 30 | Glide 31 | .with(context) 32 | .load(eatFoodyImages[1]) 33 | .skipMemoryCache(true) 34 | .diskCacheStrategy(DiskCacheStrategy.NONE) 35 | .thumbnail(0.1f) 36 | .into(imageView2); 37 | } 38 | 39 | private void loadImageThumbnailRequest() { 40 | DrawableRequestBuilder thumbnailRequest = Glide 41 | .with(context) 42 | .load(eatFoodyImages[2]) 43 | .skipMemoryCache(true) 44 | .diskCacheStrategy(DiskCacheStrategy.NONE); 45 | 46 | Glide 47 | .with(context) 48 | .load(UsageExampleGifAndVideos.gifUrl) 49 | .skipMemoryCache(true) 50 | .diskCacheStrategy(DiskCacheStrategy.NONE) 51 | .thumbnail(thumbnailRequest) 52 | .into(imageView3); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/remoteview_notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 22 | 23 | 28 | 29 | 36 | 37 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/FSAppWidgetProvider.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui; 2 | 3 | import android.appwidget.AppWidgetManager; 4 | import android.appwidget.AppWidgetProvider; 5 | import android.content.ComponentName; 6 | import android.content.Context; 7 | import android.graphics.Bitmap; 8 | import android.widget.RemoteViews; 9 | 10 | import com.bumptech.glide.Glide; 11 | import com.bumptech.glide.request.animation.GlideAnimation; 12 | import com.bumptech.glide.request.target.AppWidgetTarget; 13 | 14 | import io.futurestud.tutorials.glide.R; 15 | import io.futurestud.tutorials.glide.ui.activities.GlideExampleActivity; 16 | 17 | /** 18 | * Created by norman on 10/10/15. 19 | */ 20 | public class FSAppWidgetProvider extends AppWidgetProvider { 21 | 22 | private AppWidgetTarget appWidgetTarget; 23 | 24 | public static void pushWidgetUpdate(Context context, RemoteViews remoteViews) { 25 | ComponentName myWidget = new ComponentName(context, FSAppWidgetProvider.class); 26 | AppWidgetManager manager = AppWidgetManager.getInstance(context); 27 | manager.updateAppWidget(myWidget, remoteViews); 28 | } 29 | 30 | @Override 31 | public void onUpdate(Context context, AppWidgetManager appWidgetManager, 32 | int[] appWidgetIds) { 33 | 34 | RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.custom_view_futurestudio); 35 | 36 | appWidgetTarget = new AppWidgetTarget(context, remoteViews, R.id.custom_view_image, appWidgetIds) { 37 | @Override 38 | public void onResourceReady(Bitmap resource, GlideAnimation super Bitmap> glideAnimation) { 39 | super.onResourceReady(resource, glideAnimation); 40 | } 41 | }; 42 | 43 | Glide 44 | .with(context.getApplicationContext()) 45 | .load(GlideExampleActivity.eatFoodyImages[3]) 46 | .asBitmap() 47 | .into(appWidgetTarget); 48 | 49 | pushWidgetUpdate(context, remoteViews); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/GlideExampleActivity.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.ImageView; 7 | 8 | import butterknife.BindView; 9 | import butterknife.ButterKnife; 10 | import io.futurestud.tutorials.glide.R; 11 | import io.futurestud.tutorials.glide.ui.views.FutureStudioView; 12 | 13 | 14 | public abstract class GlideExampleActivity extends AppCompatActivity { 15 | 16 | public static String[] eatFoodyImages = { 17 | "http://i.imgur.com/rFLNqWI.jpg", 18 | "http://i.imgur.com/C9pBVt7.jpg", 19 | "http://i.imgur.com/rT5vXE1.jpg", 20 | "http://i.imgur.com/aIy5R2k.jpg", 21 | "http://i.imgur.com/MoJs9pT.jpg", 22 | "http://i.imgur.com/S963yEM.jpg", 23 | "http://i.imgur.com/rLR2cyc.jpg", 24 | "http://i.imgur.com/SEPdUIx.jpg", 25 | "http://i.imgur.com/aC9OjaM.jpg", 26 | "http://i.imgur.com/76Jfv9b.jpg", 27 | "http://i.imgur.com/fUX7EIB.jpg", 28 | "http://i.imgur.com/syELajx.jpg", 29 | "http://i.imgur.com/COzBnru.jpg", 30 | "http://i.imgur.com/Z3QjilA.jpg", 31 | }; 32 | 33 | @BindView(R.id.standard_list_imageview1) ImageView imageView1; 34 | @BindView(R.id.standard_list_imageview2) ImageView imageView2; 35 | @BindView(R.id.standard_list_imageview3) ImageView imageView3; 36 | @BindView(R.id.standard_list_imageview4) ImageView imageView4; 37 | @BindView(R.id.standard_list_imageview5) ImageView imageView5; 38 | @BindView(R.id.standard_list_custom_view) FutureStudioView customView; 39 | 40 | Context context = GlideExampleActivity.this; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | 46 | setContentView(R.layout.activity_standard_imageview); 47 | ButterKnife.bind(GlideExampleActivity.this); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/adapter/AdvancedImageListAdapter.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ArrayAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.bumptech.glide.Glide; 12 | 13 | import io.futurestud.tutorials.glide.R; 14 | 15 | /** 16 | * Created by norman on 4/10/15. 17 | */ 18 | public class AdvancedImageListAdapter extends ArrayAdapter { 19 | private Context context; 20 | private LayoutInflater inflater; 21 | 22 | private String[] imageUrls; 23 | 24 | public AdvancedImageListAdapter(Context context, String[] imageUrls) { 25 | super(context, R.layout.listview_item_image, imageUrls); 26 | 27 | this.context = context; 28 | this.imageUrls = imageUrls; 29 | 30 | inflater = LayoutInflater.from(context); 31 | } 32 | 33 | @Override 34 | public View getView(int position, View convertView, ViewGroup parent) { 35 | ViewHolder viewHolder; 36 | 37 | if (null == convertView) { 38 | convertView = inflater.inflate(R.layout.listview_item_advanced, parent, false); 39 | 40 | viewHolder = new ViewHolder(); 41 | viewHolder.text = (TextView) convertView.findViewById(R.id.listview_item_advanced_text); 42 | viewHolder.icon = (ImageView) convertView.findViewById(R.id.listview_item_advanced_imageview); 43 | 44 | convertView.setTag(viewHolder); 45 | } 46 | else { 47 | viewHolder = (ViewHolder) convertView.getTag(); 48 | } 49 | 50 | viewHolder.text.setText("Position " + position); 51 | 52 | Glide 53 | .with(context) 54 | .load(imageUrls[position]) 55 | .asBitmap() 56 | .centerCrop() 57 | .into(viewHolder.icon); 58 | 59 | return convertView; 60 | } 61 | 62 | static class ViewHolder { 63 | TextView text; 64 | ImageView icon; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleErrorLogging.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | import android.widget.ImageView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.load.resource.drawable.GlideDrawable; 8 | import com.bumptech.glide.request.RequestListener; 9 | import com.bumptech.glide.request.target.Target; 10 | 11 | import butterknife.BindView; 12 | import io.futurestud.tutorials.glide.R; 13 | 14 | public class UsageExampleErrorLogging extends GlideExampleActivity { 15 | 16 | @BindView(R.id.standard_list_imageview1) ImageView imageViewPlaceholder; 17 | @BindView(R.id.standard_list_imageview2) ImageView imageViewError; 18 | @BindView(R.id.standard_list_imageview3) ImageView imageViewNoFade; 19 | @BindView(R.id.standard_list_imageview4) ImageView imageViewCombined; 20 | @BindView(R.id.standard_list_imageview5) ImageView imageViewNoPlaceholder; 21 | 22 | private RequestListener requestListener = new RequestListener() { 23 | @Override 24 | public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { 25 | // todo log exception 26 | 27 | // important to return false so the error placeholder can be placed 28 | return false; 29 | } 30 | 31 | @Override 32 | public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { 33 | return false; 34 | } 35 | }; 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | 41 | loadImageWithErrorLogging(); 42 | } 43 | 44 | private void loadImageWithErrorLogging() { 45 | Glide 46 | .with(context) 47 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 48 | .listener(requestListener) 49 | .error(R.drawable.cupcake) 50 | .into(imageViewPlaceholder); 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/transformation/BlurTransformation.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.transformation; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.support.v8.renderscript.Allocation; 6 | import android.support.v8.renderscript.Element; 7 | import android.support.v8.renderscript.RenderScript; 8 | import android.support.v8.renderscript.ScriptIntrinsicBlur; 9 | 10 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 11 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; 12 | 13 | /** 14 | * The code in this class is based on: 15 | * - https://www.snip2code.com/Snippet/311486/This-is-a-Picasso-transform-that-blurs-a (adavis) 16 | * - https://gist.github.com/ryanbateman/6667995 (ryanbateman) 17 | * - https://futurestud.io/blog/how-to-use-the-renderscript-support-library-with-gradle-based-android-projects/ 18 | */ 19 | public class BlurTransformation extends BitmapTransformation { 20 | 21 | private RenderScript rs; 22 | 23 | public BlurTransformation(Context context) { 24 | super(context); 25 | 26 | rs = RenderScript.create(context); 27 | } 28 | 29 | @Override 30 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { 31 | Bitmap blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true); 32 | 33 | // Allocate memory for Renderscript to work with 34 | Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED); 35 | Allocation output = Allocation.createTyped(rs, input.getType()); 36 | 37 | // Load up an instance of the specific script that we want to use. 38 | ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 39 | script.setInput(input); 40 | 41 | // Set the blur radius 42 | script.setRadius(10); 43 | 44 | // Start the ScriptIntrinisicBlur 45 | script.forEach(output); 46 | 47 | // Copy the output to the blurred bitmap 48 | output.copyTo(blurredBitmap); 49 | 50 | toTransform.recycle(); 51 | 52 | return blurredBitmap; 53 | } 54 | 55 | @Override 56 | public String getId() { 57 | return "blur"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleCacheBasics.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.widget.ImageView; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 9 | 10 | import butterknife.BindView; 11 | import butterknife.ButterKnife; 12 | import io.futurestud.tutorials.glide.R; 13 | 14 | public class UsageExampleCacheBasics extends GlideExampleActivity { 15 | 16 | @BindView(R.id.simple_loading_internet) ImageView imageViewInternet; 17 | @BindView(R.id.simple_loading_resource) ImageView imageViewResource; 18 | @BindView(R.id.simple_loading_file) ImageView imageViewFile; 19 | @BindView(R.id.simple_loading_uri) ImageView imageViewUri; 20 | 21 | private Context context = this; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | 27 | setContentView(R.layout.activity_usage_example_simple_loading); 28 | ButterKnife.bind(this); 29 | 30 | loadImageSkipMemory(); 31 | loadImageSkipMemoryAndDisk(); 32 | loadImageDiskStrategySource(); 33 | loadImageDiskStrategyResult(); 34 | } 35 | 36 | private void loadImageSkipMemory() { 37 | Glide 38 | .with(context) 39 | .load(eatFoodyImages[0]) 40 | .skipMemoryCache(true) 41 | .into(imageViewInternet); 42 | } 43 | 44 | private void loadImageSkipMemoryAndDisk() { 45 | Glide 46 | .with(context) 47 | .load(eatFoodyImages[1]) 48 | .diskCacheStrategy(DiskCacheStrategy.NONE) 49 | .skipMemoryCache(true) 50 | .into(imageViewResource); 51 | } 52 | 53 | private void loadImageDiskStrategySource() { 54 | Glide 55 | .with(context) 56 | .load(eatFoodyImages[2]) 57 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 58 | .into(imageViewFile); 59 | } 60 | 61 | private void loadImageDiskStrategyResult() { 62 | Glide 63 | .with(context) 64 | .load(eatFoodyImages[3]) 65 | .diskCacheStrategy(DiskCacheStrategy.RESULT) 66 | .into(imageViewUri); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/okhttp/OkHttpUrlLoader.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.okhttp; 2 | 3 | import android.content.Context; 4 | 5 | import com.bumptech.glide.load.data.DataFetcher; 6 | import com.bumptech.glide.load.model.GenericLoaderFactory; 7 | import com.bumptech.glide.load.model.GlideUrl; 8 | import com.bumptech.glide.load.model.ModelLoader; 9 | import com.bumptech.glide.load.model.ModelLoaderFactory; 10 | import com.squareup.okhttp.OkHttpClient; 11 | 12 | import java.io.InputStream; 13 | 14 | public class OkHttpUrlLoader implements ModelLoader { 15 | 16 | /** 17 | * The default factory for {@link OkHttpUrlLoader}s. 18 | */ 19 | public static class Factory implements ModelLoaderFactory { 20 | private static volatile OkHttpClient internalClient; 21 | private OkHttpClient client; 22 | 23 | private static OkHttpClient getInternalClient() { 24 | if (internalClient == null) { 25 | synchronized (Factory.class) { 26 | if (internalClient == null) { 27 | internalClient = UnsafeOkHttpClient.getUnsafeOkHttpClient(); 28 | } 29 | } 30 | } 31 | return internalClient; 32 | } 33 | 34 | /** 35 | * Constructor for a new Factory that runs requests using a static singleton client. 36 | */ 37 | public Factory() { 38 | this(getInternalClient()); 39 | } 40 | 41 | /** 42 | * Constructor for a new Factory that runs requests using given client. 43 | */ 44 | public Factory(OkHttpClient client) { 45 | this.client = client; 46 | } 47 | 48 | @Override 49 | public ModelLoader build(Context context, GenericLoaderFactory factories) { 50 | return new OkHttpUrlLoader(client); 51 | } 52 | 53 | @Override 54 | public void teardown() { 55 | // Do nothing, this instance doesn't own the client. 56 | } 57 | } 58 | 59 | private final OkHttpClient client; 60 | 61 | public OkHttpUrlLoader(OkHttpClient client) { 62 | this.client = client; 63 | } 64 | 65 | @Override 66 | public DataFetcher getResourceFetcher(GlideUrl model, int width, int height) { 67 | return new OkHttpStreamFetcher(client, model); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "io.futurestud.tutorials.glide" 9 | 10 | minSdkVersion 21 11 | targetSdkVersion 25 12 | 13 | versionCode 1 14 | versionName "1.1.0" 15 | 16 | renderscriptTargetApi 19 17 | renderscriptSupportModeEnabled true 18 | } 19 | 20 | buildTypes { 21 | debug { 22 | debuggable true 23 | minifyEnabled false 24 | } 25 | 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | 32 | dexOptions { 33 | javaMaxHeapSize "2g" 34 | } 35 | 36 | // only necessary for ButterKnife, not for Glide! 37 | lintOptions { 38 | disable 'InvalidPackage' 39 | } 40 | 41 | packagingOptions { 42 | exclude 'META-INF/services/javax.annotation.processing.Processor' 43 | } 44 | } 45 | 46 | dependencies { 47 | // Android's support library for the framework (not necessary for Picasso) 48 | compile 'com.android.support:appcompat-v7:25.3.1' 49 | compile 'com.android.support:support-v4:25.3.1' 50 | 51 | // image loading library Glide 52 | compile 'com.github.bumptech.glide:glide:3.8.0' 53 | 54 | // glide with volley 55 | //compile 'com.github.bumptech.glide:volley-integration:1.5.0@aar' 56 | //compile 'com.mcxiaoke.volley:library:1.0.8' 57 | 58 | // glide with okhttp 2.x 59 | //compile 'com.github.bumptech.glide:okhttp-integration:1.5.0@aar' 60 | //compile 'com.squareup.okhttp:okhttp:2.7.5' 61 | 62 | // glide with okhttp 3.x 63 | compile 'com.github.bumptech.glide:okhttp3-integration:1.5.0@aar' 64 | compile 'com.squareup.okhttp3:okhttp:3.8.0' 65 | 66 | // glide with extra transformations 67 | compile 'jp.wasabeef:glide-transformations:2.0.2' 68 | compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1' // if GPU filters are needed 69 | 70 | // old stuff/helpers 71 | // image loading library Picasso 72 | compile 'com.squareup.picasso:picasso:2.5.2' 73 | compile 'com.squareup.okhttp:okhttp:2.7.5' 74 | 75 | // just a little view helper to makes things easier for us 76 | // not necessary for using Glide 77 | compile 'com.jakewharton:butterknife:8.6.0' 78 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0' 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_request_priority.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 | 15 | 16 | 23 | 24 | 30 | 31 | 36 | 37 | 42 | 43 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/okhttp/UnsafeOkHttpClient.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.okhttp; 2 | 3 | import com.squareup.okhttp.OkHttpClient; 4 | import com.squareup.okhttp.Protocol; 5 | 6 | import java.security.cert.CertificateException; 7 | import java.util.Arrays; 8 | 9 | import javax.net.ssl.HostnameVerifier; 10 | import javax.net.ssl.SSLContext; 11 | import javax.net.ssl.SSLSession; 12 | import javax.net.ssl.SSLSocketFactory; 13 | import javax.net.ssl.TrustManager; 14 | import javax.net.ssl.X509TrustManager; 15 | 16 | /** 17 | * Created by norman on 2/23/15. 18 | */ 19 | public class UnsafeOkHttpClient { 20 | public static OkHttpClient getUnsafeOkHttpClient() { 21 | try { 22 | // Create a trust manager that does not validate certificate chains 23 | final TrustManager[] trustAllCerts = new TrustManager[]{ 24 | new X509TrustManager() { 25 | @Override 26 | public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { 27 | } 28 | 29 | @Override 30 | public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { 31 | } 32 | 33 | @Override 34 | public java.security.cert.X509Certificate[] getAcceptedIssuers() { 35 | return null; 36 | } 37 | } 38 | }; 39 | 40 | // Install the all-trusting trust manager 41 | final SSLContext sslContext = SSLContext.getInstance("SSL"); 42 | sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); 43 | 44 | // Create an ssl socket factory with our all-trusting manager 45 | final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); 46 | 47 | OkHttpClient okHttpClient = new OkHttpClient(); 48 | okHttpClient.setSslSocketFactory(sslSocketFactory); 49 | okHttpClient.setProtocols(Arrays.asList(Protocol.HTTP_1_1)); 50 | okHttpClient.setHostnameVerifier(new HostnameVerifier() { 51 | @Override 52 | public boolean verify(String hostname, SSLSession session) { 53 | return true; 54 | } 55 | }); 56 | 57 | return okHttpClient; 58 | } catch (Exception e) { 59 | throw new RuntimeException(e); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/glidemodule/CheckLocalGlideModule.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.glidemodule; 2 | 3 | import android.content.Context; 4 | 5 | import com.bumptech.glide.Glide; 6 | import com.bumptech.glide.GlideBuilder; 7 | import com.bumptech.glide.load.model.GenericLoaderFactory; 8 | import com.bumptech.glide.load.model.ModelLoader; 9 | import com.bumptech.glide.load.model.stream.BaseGlideUrlLoader; 10 | import com.bumptech.glide.module.GlideModule; 11 | 12 | import java.io.InputStream; 13 | 14 | /** 15 | * Created by norman on 10/17/15. 16 | */ 17 | public class CheckLocalGlideModule implements GlideModule { 18 | @Override public void applyOptions(Context context, GlideBuilder builder) { 19 | // nothing to do here 20 | } 21 | 22 | @Override public void registerComponents(Context context, Glide glide) { 23 | glide.register(CustomImageSizeModel.class, InputStream.class, new CustomImageSizeModelFactory()); 24 | } 25 | 26 | public static class CustomImageSizeUrlLoader extends BaseGlideUrlLoader { 27 | public CustomImageSizeUrlLoader(Context context) { 28 | super( context ); 29 | } 30 | 31 | @Override 32 | protected String getUrl(CustomImageSizeModel model, int width, int height) { 33 | return model.requestCustomSizeUrl( width, height ); 34 | } 35 | } 36 | 37 | // way 1: statically via GlideModule; 38 | private class CustomImageSizeModelFactory implements com.bumptech.glide.load.model.ModelLoaderFactory { 39 | @Override 40 | public ModelLoader build(Context context, GenericLoaderFactory factories) { 41 | return new CustomImageSizeUrlLoader( context ); 42 | } 43 | 44 | 45 | @Override 46 | public void teardown() { 47 | 48 | } 49 | } 50 | 51 | // way 2: dynamically via using(); 52 | public interface CustomImageSizeModel { 53 | String requestCustomSizeUrl(int width, int height); 54 | } 55 | 56 | public static class CustomImageSizeModelFutureStudio implements CustomImageSizeModel { 57 | 58 | String baseImageUrl; 59 | 60 | public CustomImageSizeModelFutureStudio(String baseImageUrl) { 61 | this.baseImageUrl = baseImageUrl; 62 | } 63 | 64 | @Override 65 | public String requestCustomSizeUrl(int width, int height) { 66 | // assumes the server understands the additional parameters of the image 67 | return baseImageUrl + "?w=" + width + "&h=" + height; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/glidemodule/CustomImageSizeGlideModule.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.glidemodule; 2 | 3 | import android.content.Context; 4 | 5 | import com.bumptech.glide.Glide; 6 | import com.bumptech.glide.GlideBuilder; 7 | import com.bumptech.glide.load.model.GenericLoaderFactory; 8 | import com.bumptech.glide.load.model.ModelLoader; 9 | import com.bumptech.glide.load.model.stream.BaseGlideUrlLoader; 10 | import com.bumptech.glide.module.GlideModule; 11 | 12 | import java.io.InputStream; 13 | 14 | /** 15 | * Created by norman on 10/17/15. 16 | */ 17 | public class CustomImageSizeGlideModule implements GlideModule { 18 | @Override public void applyOptions(Context context, GlideBuilder builder) { 19 | // nothing to do here 20 | } 21 | 22 | @Override public void registerComponents(Context context, Glide glide) { 23 | glide.register(CustomImageSizeModel.class, InputStream.class, new CustomImageSizeModelFactory()); 24 | } 25 | 26 | public static class CustomImageSizeUrlLoader extends BaseGlideUrlLoader { 27 | public CustomImageSizeUrlLoader(Context context) { 28 | super( context ); 29 | } 30 | 31 | @Override 32 | protected String getUrl(CustomImageSizeModel model, int width, int height) { 33 | return model.requestCustomSizeUrl( width, height ); 34 | } 35 | } 36 | 37 | // way 1: statically via GlideModule; 38 | private class CustomImageSizeModelFactory implements com.bumptech.glide.load.model.ModelLoaderFactory { 39 | @Override 40 | public ModelLoader build(Context context, GenericLoaderFactory factories) { 41 | return new CustomImageSizeUrlLoader( context ); 42 | } 43 | 44 | @Override 45 | public void teardown() { 46 | 47 | } 48 | } 49 | 50 | // way 2: dynamically via using(); 51 | public interface CustomImageSizeModel { 52 | String requestCustomSizeUrl(int width, int height); 53 | } 54 | 55 | public static class CustomImageSizeModelFutureStudio implements CustomImageSizeModel { 56 | 57 | String baseImageUrl; 58 | 59 | public CustomImageSizeModelFutureStudio(String baseImageUrl) { 60 | this.baseImageUrl = baseImageUrl; 61 | } 62 | 63 | @Override 64 | public String requestCustomSizeUrl(int width, int height) { 65 | // assumes the server understands the additional parameters of the image 66 | return baseImageUrl + "?w=" + width + "&h=" + height; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleRequestPriority.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.ImageView; 7 | 8 | import com.bumptech.glide.Glide; 9 | import com.bumptech.glide.Priority; 10 | 11 | import butterknife.BindView; 12 | import butterknife.ButterKnife; 13 | import io.futurestud.tutorials.glide.R; 14 | 15 | public class UsageExampleRequestPriority extends AppCompatActivity { 16 | 17 | @BindView(R.id.activity_request_priority_hero) ImageView imageViewHero; 18 | @BindView(R.id.activity_request_priority_low_left) ImageView imageViewLowPrioLeft; 19 | @BindView(R.id.activity_request_priority_low_right) ImageView imageViewLowPrioRight; 20 | 21 | private Context context = this; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | 27 | setContentView(R.layout.activity_request_priority); 28 | ButterKnife.bind(this); 29 | 30 | loadImageWithHighPriority(); 31 | loadImagesWithLowPriority(); 32 | //loadImageWithNormalPriority(); 33 | //loadImageWithImmediatePriority(); 34 | } 35 | 36 | private void loadImageWithHighPriority() { 37 | Glide 38 | .with(context) 39 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 40 | .priority(Priority.HIGH) 41 | .into(imageViewHero); 42 | } 43 | 44 | private void loadImagesWithLowPriority() { 45 | Glide 46 | .with(context) 47 | .load(UsageExampleListViewAdapter.eatFoodyImages[1]) 48 | .priority(Priority.LOW) 49 | .into(imageViewLowPrioLeft); 50 | 51 | Glide 52 | .with(context) 53 | .load(UsageExampleListViewAdapter.eatFoodyImages[2]) 54 | .priority(Priority.LOW) 55 | .into(imageViewLowPrioRight); 56 | } 57 | 58 | private void loadImageWithNormalPriority() { 59 | Glide 60 | .with(context) 61 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 62 | .priority(Priority.NORMAL) 63 | .into(imageViewHero); 64 | } 65 | 66 | private void loadImageWithImmediatePriority() { 67 | Glide 68 | .with(context) 69 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 70 | .priority(Priority.IMMEDIATE) 71 | .into(imageViewHero); 72 | } 73 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleTransformations.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.bumptech.glide.Glide; 6 | 7 | import io.futurestud.tutorials.glide.transformation.BlurTransformation; 8 | import io.futurestud.tutorials.glide.transformation.RotateTransformation; 9 | import jp.wasabeef.glide.transformations.CropCircleTransformation; 10 | 11 | public class UsageExampleTransformations extends GlideExampleActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | loadImageOriginal(); 18 | loadImageTSingleTransformation(); 19 | loadImageMultipleTransformations(); 20 | loadImageTransformationLibrary(); 21 | loadImageRotate(); 22 | } 23 | 24 | private void loadImageOriginal() { 25 | Glide 26 | .with(context) 27 | .load(eatFoodyImages[0]) 28 | //.transform( new BlurTransformation( context ) ) 29 | //.bitmapTransform( new BlurTransformation( context ) ) 30 | .into(imageView1); 31 | } 32 | 33 | private void loadImageTSingleTransformation() { 34 | Glide 35 | .with(context) 36 | .load(eatFoodyImages[0]) 37 | //.transform( new BlurTransformation( context ) ) 38 | .bitmapTransform(new BlurTransformation(context)) 39 | .into(imageView2); 40 | } 41 | 42 | private void loadImageMultipleTransformations() { 43 | Glide 44 | .with(context) 45 | .load(eatFoodyImages[0]) 46 | .transform(new RotateTransformation(context, 45f)) 47 | //.transform( new GrayscaleTransformation( context ), new BlurTransformation( context ) ) 48 | .into(imageView3); 49 | } 50 | 51 | private void loadImageTransformationLibrary() { 52 | Glide 53 | .with(context) 54 | .load(eatFoodyImages[2]) 55 | .bitmapTransform(new jp.wasabeef.glide.transformations.BlurTransformation(context, 25, 2), new CropCircleTransformation(context)) 56 | .into(imageView4); 57 | } 58 | 59 | private void loadImageRotate() { 60 | Glide 61 | .with(context) 62 | .load(eatFoodyImages[0]) 63 | .transform(new RotateTransformation(context, 90f)) 64 | //.transform( new GrayscaleTransformation( context ), new BlurTransformation( context ) ) 65 | .into(imageView5); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/glidemodule/CustomCachingGlideModule.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.glidemodule; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.GlideBuilder; 8 | import com.bumptech.glide.load.DecodeFormat; 9 | import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool; 10 | import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory; 11 | import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory; 12 | import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; 13 | import com.bumptech.glide.load.engine.cache.LruResourceCache; 14 | import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; 15 | import com.bumptech.glide.module.GlideModule; 16 | 17 | /** 18 | * Created by norman on 10/17/15. 19 | */ 20 | public class CustomCachingGlideModule implements GlideModule { 21 | @Override 22 | public void applyOptions(Context context, GlideBuilder builder) { 23 | builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); 24 | 25 | // memory cache 26 | MemorySizeCalculator calculator = new MemorySizeCalculator(context); 27 | int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); 28 | int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); 29 | 30 | int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize); 31 | int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize); 32 | 33 | builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); 34 | builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); 35 | 36 | // disk cache 37 | // set size & external vs. internal 38 | int cacheSize100MegaBytes = 104857600; 39 | 40 | builder.setDiskCache( 41 | new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); 42 | 43 | builder.setDiskCache( 44 | new ExternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); 45 | 46 | // set custom location 47 | String downloadDirectoryPath = Environment.getDownloadCacheDirectory().getPath(); 48 | 49 | builder.setDiskCache( 50 | new DiskLruCacheFactory(downloadDirectoryPath, cacheSize100MegaBytes)); 51 | 52 | // In case you want to specify a cache folder ("glide"): 53 | //builder.setDiskCache( 54 | // new DiskLruCacheFactory( downloadDirectoryPath, "glidecache", cacheSize100MegaBytes ) ); 55 | 56 | } 57 | 58 | @Override 59 | public void registerComponents(Context context, Glide glide) { 60 | // nothing to do here 61 | } 62 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/okhttp/OkHttpStreamFetcher.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.okhttp; 2 | 3 | import com.bumptech.glide.Priority; 4 | import com.bumptech.glide.load.data.DataFetcher; 5 | import com.bumptech.glide.load.model.GlideUrl; 6 | import com.bumptech.glide.util.ContentLengthInputStream; 7 | import com.squareup.okhttp.OkHttpClient; 8 | import com.squareup.okhttp.Request; 9 | import com.squareup.okhttp.Response; 10 | import com.squareup.okhttp.ResponseBody; 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.util.Map; 15 | 16 | 17 | /** 18 | * Created by norman on 10/7/15. 19 | */ 20 | public class OkHttpStreamFetcher implements DataFetcher { 21 | private final OkHttpClient client; 22 | private final GlideUrl url; 23 | private InputStream stream; 24 | private ResponseBody responseBody; 25 | 26 | public OkHttpStreamFetcher(OkHttpClient client, GlideUrl url) { 27 | this.client = client; 28 | this.url = url; 29 | } 30 | 31 | @Override 32 | public InputStream loadData(Priority priority) throws Exception { 33 | Request.Builder requestBuilder = new Request.Builder() 34 | .url(url.toStringUrl()); 35 | 36 | for (Map.Entry headerEntry : url.getHeaders().entrySet()) { 37 | String key = headerEntry.getKey(); 38 | requestBuilder.addHeader(key, headerEntry.getValue()); 39 | } 40 | 41 | Request request = requestBuilder.build(); 42 | 43 | Response response = client.newCall(request).execute(); 44 | responseBody = response.body(); 45 | if (!response.isSuccessful()) { 46 | throw new IOException("Request failed with code: " + response.code()); 47 | } 48 | 49 | long contentLength = responseBody.contentLength(); 50 | stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength); 51 | return stream; 52 | } 53 | 54 | @Override 55 | public void cleanup() { 56 | if (stream != null) { 57 | try { 58 | stream.close(); 59 | } catch (IOException e) { 60 | // Ignored 61 | } 62 | } 63 | if (responseBody != null) { 64 | try { 65 | responseBody.close(); 66 | } catch (IOException e) { 67 | // Ignored. 68 | } 69 | } 70 | } 71 | 72 | @Override 73 | public String getId() { 74 | return url.getCacheKey(); 75 | } 76 | 77 | @Override 78 | public void cancel() { 79 | // TODO: call cancel on the client when this method is called on a background thread. See #257 80 | } 81 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleGifAndVideos.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.widget.ImageView; 8 | 9 | import com.bumptech.glide.Glide; 10 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 11 | 12 | import java.io.File; 13 | 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | import io.futurestud.tutorials.glide.R; 17 | 18 | public class UsageExampleGifAndVideos extends AppCompatActivity { 19 | 20 | @BindView(R.id.standard_list_imageview1) ImageView imageViewGif; 21 | @BindView(R.id.standard_list_imageview2) ImageView imageViewGifAsBitmap; 22 | @BindView(R.id.standard_list_imageview3) ImageView imageViewLocalVideo; 23 | @BindView(R.id.standard_list_imageview4) ImageView imageViewCombined; 24 | @BindView(R.id.standard_list_imageview5) ImageView imageViewNoPlaceholder; 25 | 26 | private Context context = this; 27 | 28 | public static String gifUrl = "http://i.kinja-img.com/gawker-media/image/upload/s--B7tUiM5l--/gf2r69yorbdesguga10i.gif"; 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate( savedInstanceState ); 33 | 34 | setContentView( R.layout.activity_standard_imageview ); 35 | ButterKnife.bind( this ); 36 | 37 | loadGif(); 38 | loadGifFast(); 39 | loadGifAsBitmap(); 40 | loaLocalVideo(); 41 | } 42 | 43 | private void loadGif() { 44 | 45 | Glide 46 | .with( context ) 47 | .load( gifUrl ) 48 | .asGif() 49 | .error( R.drawable.full_cake ) 50 | .into( imageViewGif ); 51 | } 52 | 53 | private void loadGifFast() { 54 | 55 | Glide 56 | .with( context ) 57 | .load( gifUrl ) 58 | .asGif() 59 | .error( R.drawable.full_cake ) 60 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 61 | .into( imageViewGif ); 62 | } 63 | 64 | private void loadGifAsBitmap() { 65 | Glide 66 | .with( context ) 67 | .load( gifUrl ) 68 | .asBitmap() 69 | .thumbnail( 0.5f ) 70 | .placeholder( R.drawable.cupcake ) 71 | .into( imageViewGifAsBitmap ); 72 | } 73 | 74 | private void loaLocalVideo() { 75 | // todo select a common video file 76 | String filePath = "/storage/emulated/0/Pictures/example_video.mp4"; 77 | 78 | Glide 79 | .with( context ) 80 | .load( Uri.fromFile( new File( filePath ) ) ) 81 | .error( R.drawable.cupcake ) 82 | .into( imageViewLocalVideo ); 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/views/RoundedImageView.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.views; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.PorterDuff; 9 | import android.graphics.PorterDuffXfermode; 10 | import android.graphics.Rect; 11 | import android.graphics.drawable.BitmapDrawable; 12 | import android.graphics.drawable.Drawable; 13 | import android.util.AttributeSet; 14 | import android.widget.ImageView; 15 | 16 | /** 17 | * This class provides the functionality to customize the regular squared imageview to a rounded one. 18 | * 19 | * Created by npeitek on 9/2/2014. 20 | */ 21 | public class RoundedImageView extends ImageView { 22 | 23 | public RoundedImageView(Context context) { 24 | super(context); 25 | } 26 | 27 | public RoundedImageView(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | public RoundedImageView(Context context, AttributeSet attrs, int defStyle) { 32 | super(context, attrs, defStyle); 33 | } 34 | 35 | public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) { 36 | Bitmap sbmp; 37 | if (bmp.getWidth() != radius || bmp.getHeight() != radius) { 38 | float smallest = Math.min(bmp.getWidth(), bmp.getHeight()); 39 | float factor = smallest / radius; 40 | sbmp = Bitmap.createScaledBitmap(bmp, (int) (bmp.getWidth() / factor), (int) (bmp.getHeight() / factor), false); 41 | } 42 | else { 43 | sbmp = bmp; 44 | } 45 | Bitmap output = Bitmap.createBitmap(radius, radius, 46 | Bitmap.Config.ARGB_8888); 47 | Canvas canvas = new Canvas(output); 48 | 49 | final int color = 0xffa19774; 50 | final Paint paint = new Paint(); 51 | final Rect rect = new Rect(0, 0, radius, radius); 52 | 53 | paint.setAntiAlias(true); 54 | paint.setFilterBitmap(true); 55 | paint.setDither(true); 56 | canvas.drawARGB(0, 0, 0, 0); 57 | paint.setColor(Color.parseColor("#BAB399")); 58 | canvas.drawCircle(radius / 2 + 0.7f, 59 | radius / 2 + 0.7f, radius / 2 + 0.1f, paint); 60 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 61 | canvas.drawBitmap(sbmp, rect, rect, paint); 62 | 63 | return output; 64 | } 65 | 66 | @Override 67 | protected void onDraw(Canvas canvas) { 68 | 69 | Drawable drawable = getDrawable(); 70 | 71 | if (drawable == null) { 72 | return; 73 | } 74 | 75 | if (getWidth() == 0 || getHeight() == 0) { 76 | return; 77 | } 78 | Bitmap b = ((BitmapDrawable) drawable).getBitmap(); 79 | Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true); 80 | 81 | int w = getWidth(), h = getHeight(); 82 | 83 | Bitmap roundBitmap = getCroppedBitmap(bitmap, w); 84 | canvas.drawBitmap(roundBitmap, 0, 0, null); 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/transformation/GrayscaleTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Square, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.futurestud.tutorials.glide.transformation; 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | import android.graphics.BitmapShader; 23 | import android.graphics.Canvas; 24 | import android.graphics.ColorMatrix; 25 | import android.graphics.ColorMatrixColorFilter; 26 | import android.graphics.Paint; 27 | import android.graphics.PorterDuff; 28 | import android.graphics.PorterDuffXfermode; 29 | 30 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 31 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; 32 | 33 | import io.futurestud.tutorials.glide.R; 34 | 35 | import static android.graphics.Bitmap.createBitmap; 36 | import static android.graphics.Paint.ANTI_ALIAS_FLAG; 37 | import static android.graphics.Shader.TileMode.REPEAT; 38 | 39 | public class GrayscaleTransformation extends BitmapTransformation { 40 | 41 | private Context context; 42 | 43 | public GrayscaleTransformation(Context context) { 44 | super(context); 45 | 46 | this.context = context; 47 | } 48 | 49 | @Override 50 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { 51 | Bitmap result = createBitmap(toTransform.getWidth(), toTransform.getHeight(), toTransform.getConfig()); 52 | Bitmap noise = BitmapFactory.decodeResource(context.getResources(), R.drawable.noise); 53 | 54 | BitmapShader shader = new BitmapShader(noise, REPEAT, REPEAT); 55 | 56 | ColorMatrix colorMatrix = new ColorMatrix(); 57 | colorMatrix.setSaturation(0); 58 | ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix); 59 | 60 | Paint paint = new Paint(ANTI_ALIAS_FLAG); 61 | paint.setColorFilter(filter); 62 | 63 | Canvas canvas = new Canvas(result); 64 | canvas.drawBitmap(toTransform, 0, 0, paint); 65 | 66 | paint.setColorFilter(null); 67 | paint.setShader(shader); 68 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); 69 | 70 | canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); 71 | 72 | toTransform.recycle(); 73 | noise.recycle(); 74 | 75 | return result; 76 | } 77 | 78 | @Override 79 | public String getId() { 80 | return "grayscaleTransformation()"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleImageResizing.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.ImageView; 7 | 8 | import com.bumptech.glide.Glide; 9 | 10 | import butterknife.BindView; 11 | import butterknife.ButterKnife; 12 | import io.futurestud.tutorials.glide.R; 13 | 14 | public class UsageExampleImageResizing extends AppCompatActivity { 15 | 16 | @BindView(R.id.standard_list_imageview1) ImageView imageViewResize; 17 | @BindView(R.id.standard_list_imageview2) ImageView imageViewResizeCenterCrop; 18 | @BindView(R.id.standard_list_imageview3) ImageView imageViewResizeFitCenter; 19 | @BindView(R.id.standard_list_imageview4) ImageView imageViewResizeScaleDown; 20 | @BindView(R.id.standard_list_imageview5) ImageView imageViewFit; 21 | 22 | private Context context = this; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | setContentView(R.layout.activity_standard_imageview); 29 | ButterKnife.bind(this); 30 | 31 | loadImageWithResize(); 32 | loadImageWithResizeCenterCrop(); 33 | loadImageWithResizeFitCenter(); 34 | loadImageWithResizeScaleDown(); 35 | } 36 | 37 | private void loadImageWithResize() { 38 | Glide 39 | .with(context) 40 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 41 | .override(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio 42 | .into(imageViewResize); 43 | } 44 | 45 | private void loadImageWithResizeCenterCrop() { 46 | Glide 47 | .with(context) 48 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 49 | .override(600, 200) // resizes the image to these dimensions (in pixel) 50 | .centerCrop() // this cropping technique scales the image so that it fills the requested bounds and then crops the extra. 51 | .into(imageViewResizeCenterCrop); 52 | } 53 | 54 | private void loadImageWithResizeFitCenter() { 55 | Glide 56 | .with(context) 57 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 58 | .override(600, 200) 59 | .fitCenter() // this scales the image so that both dimensions are equal to or less than the requested bounds. 60 | .into(imageViewResizeFitCenter); 61 | } 62 | 63 | private void loadImageWithResizeScaleDown() { 64 | // todo figure out if this is possible with glide 65 | /* 66 | Glide 67 | .with(context) 68 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 69 | .override(6000, 2000) 70 | .onlyScaleDown() // the image will only be resized if it's bigger than 6000x2000 pixels. 71 | .into(imageViewResizeScaleDown); 72 | */ 73 | } 74 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleNetworkDependent.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.widget.ImageView; 9 | 10 | import com.bumptech.glide.DrawableTypeRequest; 11 | import com.bumptech.glide.Glide; 12 | import com.bumptech.glide.RequestManager; 13 | 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | import io.futurestud.tutorials.glide.R; 17 | import io.futurestud.tutorials.glide.glidemodule.NetworkDisablingLoader; 18 | 19 | public class UsageExampleNetworkDependent extends AppCompatActivity { 20 | 21 | @BindView(R.id.standard_list_imageview1) ImageView imageView1; 22 | @BindView(R.id.standard_list_imageview3) ImageView imageView2; 23 | @BindView(R.id.standard_list_imageview4) ImageView imageView3; 24 | 25 | private Context context = this; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | 31 | setContentView(R.layout.activity_standard_imageview); 32 | ButterKnife.bind(this); 33 | 34 | //loadNetworkDependent(); 35 | loadNetworkDependentWithCache(); 36 | } 37 | 38 | private void loadNetworkDependent() { 39 | RequestManager requestManager = Glide.with(context); 40 | DrawableTypeRequest request; 41 | 42 | // if you need transformations or other options specific for the load, chain them here 43 | if (deviceOnWifi()) { 44 | request = requestManager.load("http://www.placehold.it/750x750"); 45 | } 46 | else { 47 | request = requestManager.load("http://www.placehold.it/100x100"); 48 | } 49 | 50 | request.into(imageView1); 51 | } 52 | 53 | private void loadNetworkDependentWithCache() { 54 | // if you need transformations or other options specific for the load, chain them here 55 | if (deviceOnWifi()) { 56 | Glide 57 | .with(context) 58 | .load("http://www.placehold.it/750x750") 59 | .into(imageView1); 60 | } 61 | else { 62 | Glide 63 | .with(context) 64 | .using(new NetworkDisablingLoader()) 65 | .load("http://www.placehold.it/750x750") 66 | .thumbnail( 67 | Glide 68 | .with(context) 69 | .load("http://www.placehold.it/100x100") 70 | ) 71 | .into(imageView1); 72 | 73 | } 74 | 75 | } 76 | 77 | 78 | private boolean deviceOnWifi() { 79 | ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 80 | NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 81 | 82 | return networkInfo.isConnected(); 83 | } 84 | 85 | 86 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleSimpleLoading.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.widget.ImageView; 9 | 10 | import com.bumptech.glide.Glide; 11 | 12 | import java.io.File; 13 | 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | import io.futurestud.tutorials.glide.R; 17 | 18 | public class UsageExampleSimpleLoading extends AppCompatActivity { 19 | 20 | public static final String ANDROID_RESOURCE = "android.resource://"; 21 | public static final String FOREWARD_SLASH = "/"; 22 | 23 | @BindView(R.id.simple_loading_internet) ImageView imageViewInternet; 24 | @BindView(R.id.simple_loading_resource) ImageView imageViewResource; 25 | @BindView(R.id.simple_loading_file) ImageView imageViewFile; 26 | @BindView(R.id.simple_loading_uri) ImageView imageViewUri; 27 | 28 | private Context context = this; 29 | 30 | /** 31 | * helper method which creates an Uri for a resourceId 32 | */ 33 | private static Uri resourceIdToUri(Context context, int resourceId) { 34 | return Uri.parse(ANDROID_RESOURCE + context.getPackageName() + FOREWARD_SLASH + resourceId); 35 | } 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | 41 | setContentView(R.layout.activity_usage_example_simple_loading); 42 | ButterKnife.bind(this); 43 | 44 | loadImageByInternetUrl(); 45 | loadImageByResourceId(); 46 | loadImageByFile(); 47 | loadImageByUri(); 48 | } 49 | 50 | private void loadImageByInternetUrl() { 51 | // the url could be any image URL, which is accessible with a normal HTTP GET request 52 | String internetUrl = "http://i.imgur.com/DvpvklR.png"; 53 | Glide 54 | .with(context) 55 | .load(internetUrl) 56 | .into(imageViewInternet); 57 | } 58 | 59 | private void loadImageByResourceId() { 60 | int resourceId = R.mipmap.ic_launcher; 61 | Glide 62 | .with(context) 63 | .load(resourceId) 64 | .into(imageViewResource); 65 | } 66 | 67 | private void loadImageByFile() { 68 | // this file probably does not exist on your device. However, you can use any file path, which points to an image file 69 | File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Running.jpg"); 70 | Glide 71 | .with(context) 72 | .load(file) 73 | .into(imageViewFile); 74 | } 75 | 76 | private void loadImageByUri() { 77 | // this could be any Uri. for demonstration purposes we're just creating an Uri pointing to a launcher icon 78 | Uri uri = resourceIdToUri(context, R.mipmap.future_studio_launcher); 79 | Glide 80 | .with(context) 81 | .load(uri) 82 | .into(imageViewUri); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/MenuContent.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleAdvancedAdapter; 9 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleAnimate; 10 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleCacheBasics; 11 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleCustomImageSize; 12 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleDownload; 13 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleGifAndVideos; 14 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleGlideUrl; 15 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleGridViewAdapter; 16 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleImageResizing; 17 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleListViewAdapter; 18 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleNetworkDependent; 19 | import io.futurestud.tutorials.glide.ui.activities.UsageExamplePlaceholders; 20 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleRequestPriority; 21 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleSimpleLoading; 22 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleTargetsAndRemoteViews; 23 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleThumbnails; 24 | import io.futurestud.tutorials.glide.ui.activities.UsageExampleTransformations; 25 | 26 | /** 27 | * Helper class for providing sample content for user interfaces created by 28 | * Android template wizards. 29 | * 30 | * TODO: Replace all uses of this class before publishing your app. 31 | */ 32 | public class MenuContent { 33 | 34 | /** 35 | * An array of sample (dummy) items. 36 | */ 37 | public static List ITEMS = new ArrayList(); 38 | 39 | /** 40 | * A map of sample (dummy) items, by ID. 41 | */ 42 | public static Map ITEM_MAP = new HashMap(); 43 | 44 | static { 45 | addItem(new DummyItem("Simple Image Loading", UsageExampleSimpleLoading.class)); 46 | addItem(new DummyItem("Adapter Use - ListView", UsageExampleListViewAdapter.class)); 47 | addItem(new DummyItem("Adapter Use - GridView", UsageExampleGridViewAdapter.class)); 48 | addItem(new DummyItem("Adapter Use - Advanced", UsageExampleAdvancedAdapter.class)); 49 | addItem(new DummyItem("Placeholder, Error & Fading", UsageExamplePlaceholders.class)); 50 | addItem(new DummyItem("Image Resizing, Scaling", UsageExampleImageResizing.class)); 51 | addItem(new DummyItem("Gif & Local Videos", UsageExampleGifAndVideos.class)); 52 | addItem(new DummyItem("Glide Cache Basics", UsageExampleCacheBasics.class)); 53 | addItem(new DummyItem("Glide Priority", UsageExampleRequestPriority.class)); 54 | addItem(new DummyItem("Thumbnails", UsageExampleThumbnails.class)); 55 | addItem(new DummyItem("Callbacks, Targets & Notifications", UsageExampleTargetsAndRemoteViews.class)); 56 | addItem(new DummyItem("Transformation", UsageExampleTransformations.class)); 57 | addItem(new DummyItem("Animation", UsageExampleAnimate.class)); 58 | addItem(new DummyItem("Custom Image Size", UsageExampleCustomImageSize.class)); 59 | addItem(new DummyItem("Network-Dependent", UsageExampleNetworkDependent.class)); 60 | addItem(new DummyItem("Glide URL", UsageExampleGlideUrl.class)); 61 | addItem(new DummyItem("Download Images", UsageExampleDownload.class)); 62 | } 63 | 64 | private static void addItem(DummyItem item) { 65 | ITEMS.add(item); 66 | ITEM_MAP.put(item.id, item); 67 | } 68 | 69 | /** 70 | * A dummy item representing a piece of content. 71 | */ 72 | public static class DummyItem { 73 | public String id; 74 | public String content; 75 | public Class goalClass; 76 | 77 | public DummyItem(String content, Class goalClass) { 78 | this.id = id; 79 | this.content = content; 80 | this.goalClass = goalClass; 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return content; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExamplePlaceholders.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.ImageView; 7 | 8 | import com.bumptech.glide.Glide; 9 | 10 | import butterknife.BindView; 11 | import butterknife.ButterKnife; 12 | import io.futurestud.tutorials.glide.R; 13 | 14 | public class UsageExamplePlaceholders extends AppCompatActivity { 15 | 16 | @BindView(R.id.standard_list_imageview1) ImageView imageViewPlaceholder; 17 | @BindView(R.id.standard_list_imageview2) ImageView imageViewError; 18 | @BindView(R.id.standard_list_imageview3) ImageView imageViewNoFade; 19 | @BindView(R.id.standard_list_imageview4) ImageView imageViewCombined; 20 | @BindView(R.id.standard_list_imageview5) ImageView imageViewNoPlaceholder; 21 | 22 | private Context context = this; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | setContentView(R.layout.activity_standard_imageview); 29 | ButterKnife.bind(this); 30 | 31 | loadImageWithPlaceholder(); 32 | loadImageWithError(); 33 | loadImageNoAnimation(); 34 | loadImageFallback(); 35 | loadImageCombination(); 36 | 37 | loadImageWithNoPlaceholder(); 38 | } 39 | 40 | private void loadImageWithPlaceholder() { 41 | Glide 42 | .with(context) 43 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 44 | .placeholder(R.mipmap.ic_launcher) // can also be a drawable 45 | .into(imageViewPlaceholder); 46 | } 47 | 48 | private void loadImageWithError() { 49 | Glide 50 | .with(context) 51 | .load("http://futurestud.io/non_existing_image.png") 52 | .error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded 53 | .into(imageViewError); 54 | } 55 | 56 | private void loadImageNoAnimation() { 57 | Glide 58 | .with(context) 59 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 60 | .dontAnimate() 61 | .into(imageViewNoFade); 62 | } 63 | 64 | private void loadImageFallback() { 65 | String nullString = null; // could be set to null dynamically 66 | 67 | Glide 68 | .with(context) 69 | .load(nullString) 70 | .fallback(R.drawable.floorplan) 71 | .into(imageViewNoFade); 72 | } 73 | 74 | private void loadImageCombination() { 75 | Glide 76 | .with(context) 77 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 78 | .placeholder(R.mipmap.ic_launcher) // can also be a drawable 79 | .error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded 80 | .crossFade(1000) 81 | .into(imageViewCombined); 82 | } 83 | 84 | private void loadImageWithNoPlaceholder() { 85 | // todo figure out if this is supported by glide 86 | // load an image into the imageview 87 | /* 88 | Glide 89 | .with(context) 90 | .load(UsageExampleListViewAdapter.eatFoodyImages[0]) 91 | .placeholder(R.mipmap.ic_launcher) // can also be a drawable 92 | .into(imageViewNoPlaceholder, new Callback() { 93 | @Override 94 | public void onSuccess() { 95 | // once the image is loaded, load the next image 96 | Picasso 97 | .with(context) 98 | .load(UsageExampleListViewAdapter.eatFoodyImages[1]) 99 | .noPlaceholder() // but don't clear the imageview or set a placeholder; just leave the previous image in until the new one is ready 100 | .into(imageViewNoPlaceholder); 101 | } 102 | 103 | @Override 104 | public void onError() { 105 | 106 | } 107 | }); 108 | */ 109 | 110 | } 111 | } -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Android 46 | 47 | 48 | Android > Lint > Correctness 49 | 50 | 51 | Android > Lint > Internationalization 52 | 53 | 54 | Android > Lint > Security 55 | 56 | 57 | Code style issuesJava 58 | 59 | 60 | CorrectnessLintAndroid 61 | 62 | 63 | Gradle 64 | 65 | 66 | ImportsJava 67 | 68 | 69 | Initialization issuesJava 70 | 71 | 72 | J2ME issuesJava 73 | 74 | 75 | Java 76 | 77 | 78 | Java language level issuesJava 79 | 80 | 81 | Java language level migration aidsJava 82 | 83 | 84 | LintAndroid 85 | 86 | 87 | Performance issuesJava 88 | 89 | 90 | Portability issuesJava 91 | 92 | 93 | Probable bugsGradle 94 | 95 | 96 | Threading issuesJava 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 1.8 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 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="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 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 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | 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" ;; 154 | esac 155 | fi 156 | 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=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 21 | 22 | 25 | 26 | 27 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 46 | 47 | 50 | 51 | 54 | 55 | 58 | 59 | 62 | 63 | 66 | 67 | 70 | 71 | 74 | 75 | 78 | 79 | 82 | 83 | 86 | 87 | 90 | 91 | 94 | 95 | 98 | 99 | 102 | 103 | 106 | 107 | 110 | 111 | 114 | 115 | 118 | 119 | 120 | 121 | 123 | 124 | 125 | 128 | 129 | 130 | 133 | 134 | 135 | 136 | 137 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleGlideUrl.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.ImageView; 7 | import android.widget.Toast; 8 | 9 | import com.bumptech.glide.Glide; 10 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 11 | import com.bumptech.glide.load.model.GlideUrl; 12 | import com.bumptech.glide.load.resource.drawable.GlideDrawable; 13 | import com.bumptech.glide.request.RequestListener; 14 | import com.bumptech.glide.request.target.Target; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import butterknife.BindView; 20 | import butterknife.ButterKnife; 21 | import io.futurestud.tutorials.glide.R; 22 | 23 | public class UsageExampleGlideUrl extends AppCompatActivity { 24 | 25 | @BindView(R.id.standard_list_imageview1) ImageView imageView1; 26 | @BindView(R.id.standard_list_imageview3) ImageView imageView2; 27 | @BindView(R.id.standard_list_imageview4) ImageView imageView3; 28 | 29 | private Context context = this; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | 35 | setContentView(R.layout.activity_standard_imageview); 36 | ButterKnife.bind(this); 37 | 38 | loadFirst(); 39 | } 40 | 41 | private void loadFirst() { 42 | Glide 43 | .with(context) 44 | .load(new GlideUrlWithQueryParameter("http://placehold.it/500x500", "access", "mysecrettoken")) 45 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 46 | .listener(new RequestListener() { 47 | @Override 48 | public boolean onException(Exception e, GlideUrlWithQueryParameter model, Target target, boolean isFirstResource) { 49 | Toast.makeText(context, "error", Toast.LENGTH_SHORT).show(); 50 | return false; 51 | } 52 | 53 | @Override 54 | public boolean onResourceReady(GlideDrawable resource, GlideUrlWithQueryParameter model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { 55 | loadSecond(); 56 | loadThird(); 57 | return false; 58 | } 59 | }) 60 | .into(imageView1); 61 | } 62 | 63 | // this photo should be loaded, since only the token is different 64 | private void loadSecond() { 65 | Toast.makeText(context, "loading 2", Toast.LENGTH_SHORT).show(); 66 | 67 | HashMap queryParams = new HashMap<>(); 68 | queryParams.put("source", "feed"); 69 | queryParams.put("access", "mysecrettoken"); 70 | 71 | Glide 72 | .with(context) 73 | //.using(new NetworkDisablingLoader()) 74 | .load(new GlideUrlWithQueryParameter("http://placehold.it/500x500", queryParams)) 75 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 76 | .into(imageView2); 77 | } 78 | 79 | // this photo should not be loaded, since the base part of the URL is different (in this case different size) 80 | private void loadThird() { 81 | Toast.makeText(context, "loading 3", Toast.LENGTH_SHORT).show(); 82 | 83 | Glide 84 | .with(context) 85 | //.using(new NetworkDisablingLoader()) 86 | .load(new GlideUrlWithQueryParameter("http://placehold.it/400x400", "access", "mysecrettoken")) 87 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 88 | .into(imageView3); 89 | } 90 | 91 | public static class GlideUrlWithQueryParameter extends GlideUrl { 92 | private String mSourceUrl; 93 | 94 | public GlideUrlWithQueryParameter(String baseUrl, String key, String value) { 95 | super(buildUrl(baseUrl, key, value)); 96 | 97 | mSourceUrl = baseUrl; 98 | } 99 | 100 | public GlideUrlWithQueryParameter(String baseUrl, Map queryParams) { 101 | super(buildUrl(baseUrl, queryParams)); 102 | 103 | mSourceUrl = baseUrl; 104 | } 105 | 106 | private static String buildUrl(String baseUrl, String key, String value) { 107 | StringBuilder stringBuilder = new StringBuilder(baseUrl); 108 | 109 | if (stringBuilder.toString().contains("?")) { 110 | stringBuilder.append("&"); 111 | } 112 | else { 113 | stringBuilder.append("?"); 114 | } 115 | 116 | stringBuilder.append(key); 117 | stringBuilder.append("="); 118 | stringBuilder.append(value); 119 | 120 | return stringBuilder.toString(); 121 | } 122 | 123 | private static String buildUrl(String baseUrl, Map queryParams) { 124 | StringBuilder stringBuilder = new StringBuilder(baseUrl); 125 | 126 | for (Map.Entry entry : queryParams.entrySet()) { 127 | String key = entry.getKey(); 128 | Object value = entry.getValue(); 129 | 130 | if (stringBuilder.toString().contains("?")) { 131 | stringBuilder.append("&"); 132 | } 133 | else { 134 | stringBuilder.append("?"); 135 | } 136 | 137 | stringBuilder.append(key); 138 | stringBuilder.append("="); 139 | stringBuilder.append(value); 140 | } 141 | 142 | return stringBuilder.toString(); 143 | } 144 | 145 | @Override 146 | public String getCacheKey() { 147 | return mSourceUrl; 148 | } 149 | 150 | @Override 151 | public String toString() { 152 | return super.getCacheKey(); 153 | } 154 | } 155 | 156 | } -------------------------------------------------------------------------------- /app/src/main/java/io/futurestud/tutorials/glide/ui/activities/UsageExampleTargetsAndRemoteViews.java: -------------------------------------------------------------------------------- 1 | package io.futurestud.tutorials.glide.ui.activities; 2 | 3 | import android.app.Notification; 4 | import android.app.NotificationManager; 5 | import android.content.Context; 6 | import android.graphics.Bitmap; 7 | import android.os.Bundle; 8 | import android.support.v4.app.NotificationCompat; 9 | import android.widget.ImageView; 10 | import android.widget.RemoteViews; 11 | 12 | import com.bumptech.glide.Glide; 13 | import com.bumptech.glide.load.resource.drawable.GlideDrawable; 14 | import com.bumptech.glide.request.animation.GlideAnimation; 15 | import com.bumptech.glide.request.target.NotificationTarget; 16 | import com.bumptech.glide.request.target.SimpleTarget; 17 | import com.bumptech.glide.request.target.ViewTarget; 18 | 19 | import butterknife.BindView; 20 | import butterknife.ButterKnife; 21 | import io.futurestud.tutorials.glide.R; 22 | import io.futurestud.tutorials.glide.ui.views.FutureStudioView; 23 | 24 | public class UsageExampleTargetsAndRemoteViews extends GlideExampleActivity { 25 | 26 | private static final int NOTIFICATION_ID = 34567; 27 | 28 | private SimpleTarget target = new SimpleTarget() { 29 | @Override 30 | public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) { 31 | // do something with the bitmap 32 | // for demonstration purposes, let's set it to an imageview 33 | imageView1.setImageBitmap( bitmap ); 34 | } 35 | }; 36 | 37 | private SimpleTarget target2 = new SimpleTarget( 250, 250 ) { 38 | @Override 39 | public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) { 40 | imageView2.setImageBitmap( bitmap ); 41 | } 42 | }; 43 | 44 | private ViewTarget viewTarget; 45 | private NotificationTarget notificationTarget; 46 | 47 | @BindView(R.id.standard_list_imageview1) ImageView imageView1; 48 | @BindView(R.id.standard_list_imageview2) ImageView imageView2; 49 | @BindView(R.id.standard_list_imageview3) ImageView imageView3; 50 | @BindView(R.id.standard_list_imageview4) ImageView imageView4; 51 | @BindView(R.id.standard_list_imageview5) ImageView imageView5; 52 | @BindView(R.id.standard_list_custom_view) FutureStudioView customView; 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate( savedInstanceState ); 57 | 58 | setContentView( R.layout.activity_standard_imageview ); 59 | ButterKnife.bind( this ); 60 | 61 | loadImageSimpleTarget(); 62 | loadImageSimpleTargetApplicationContext(); 63 | 64 | loadImageViewTarget(); 65 | loadImageNotification(); 66 | } 67 | 68 | private void loadImageSimpleTarget() { 69 | Glide 70 | .with( context ) // could be an issue! 71 | .load( eatFoodyImages[0] ) 72 | .asBitmap() 73 | .into( target ); 74 | } 75 | 76 | private void loadImageSimpleTargetApplicationContext() { 77 | Glide 78 | .with( context.getApplicationContext() ) // safer! 79 | .load( eatFoodyImages[1] ) 80 | .asBitmap() 81 | .into( target2 ); 82 | } 83 | 84 | private void loadImageViewTarget() { 85 | viewTarget = new ViewTarget( customView ) { 86 | @Override 87 | public void onResourceReady(GlideDrawable resource, GlideAnimation super GlideDrawable> glideAnimation) { 88 | this.view.setImage( resource.getCurrent() ); 89 | } 90 | }; 91 | 92 | Glide 93 | .with( context.getApplicationContext() ) // safer! 94 | .load( eatFoodyImages[2] ) 95 | .into( viewTarget ); 96 | } 97 | 98 | private void loadImageNotification() { 99 | // create RemoteViews 100 | final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.remoteview_notification); 101 | 102 | remoteViews.setImageViewResource(R.id.remoteview_notification_icon, R.mipmap.future_studio_launcher); 103 | 104 | remoteViews.setTextViewText(R.id.remoteview_notification_headline, "Headline"); 105 | remoteViews.setTextViewText(R.id.remoteview_notification_short_message, "Short Message"); 106 | 107 | remoteViews.setTextColor(R.id.remoteview_notification_headline, context.getResources().getColor( android.R.color.black)); 108 | remoteViews.setTextColor(R.id.remoteview_notification_short_message, context.getResources().getColor(android.R.color.black)); 109 | 110 | // build notification 111 | NotificationCompat.Builder mBuilder = 112 | new NotificationCompat.Builder(context) 113 | .setSmallIcon(R.mipmap.future_studio_launcher) 114 | .setContentTitle("Content Title") 115 | .setContentText("Content Text") 116 | .setContent(remoteViews) 117 | .setPriority( NotificationCompat.PRIORITY_MIN); 118 | 119 | final Notification notification = mBuilder.build(); 120 | 121 | // set big content view for newer androids 122 | if (android.os.Build.VERSION.SDK_INT >= 16) { 123 | notification.bigContentView = remoteViews; 124 | } 125 | 126 | NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 127 | mNotificationManager.notify(NOTIFICATION_ID, notification); 128 | 129 | notificationTarget = new NotificationTarget( 130 | context, 131 | remoteViews, 132 | R.id.remoteview_notification_icon, 133 | notification, 134 | NOTIFICATION_ID); 135 | 136 | Glide 137 | .with( context.getApplicationContext() ) // safer! 138 | .load( eatFoodyImages[3] ) 139 | .asBitmap() 140 | .into( notificationTarget ); 141 | } 142 | 143 | /* 144 | // todo remoteviews and notifications 145 | private void loadImageSimpleTargetApplicationContext() { 146 | Glide 147 | .with( context.getApplicationContext() ) // safer! 148 | .load( eatFoodyImages[0] ) 149 | .asBitmap() 150 | .into( target2 ); 151 | } 152 | */ 153 | 154 | // todo todo add appwidgets 155 | } 156 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | generateDebugSources 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | --------------------------------------------------------------------------------
This Glide sample app is supported by Future Studio University 🚀 12 | 13 | Join the Future Studio University and Skyrocket in Android 14 |