-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4950817
commit ef02f3c
Showing
13 changed files
with
325 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 51 additions & 1 deletion
52
app/src/main/java/com/zeropercenthappy/glidesample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,62 @@ | ||
package com.zeropercenthappy.glidesample | ||
|
||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions | ||
import com.bumptech.glide.request.RequestOptions | ||
import com.zeropercenthappy.glideutil.downloadImage | ||
import com.zeropercenthappy.glideutil.loadImage | ||
import com.zeropercenthappy.utilslibrary.utils.CacheUtils | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
import kotlinx.coroutines.MainScope | ||
import kotlinx.coroutines.launch | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private val mainScope = MainScope() | ||
// private val imageUrl = "https://imgs.aixifan.com/2fJC0sJcLK-BZRZfa-Y3iqEz-Q7jmEv-6Rrmmq.jpg" | ||
private val imageUrl = "https://imgs.aixifan.com/AcFccYdFRE-ZbAB7n-n2iymm-aEBFbu-mqIRni.gif" | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
load() | ||
download() | ||
} | ||
|
||
private fun load() { | ||
// options | ||
val options = RequestOptions().apply { | ||
placeholder(R.mipmap.ic_launcher) | ||
error(R.mipmap.ic_launcher_round) | ||
centerInside() | ||
} | ||
// load | ||
loadImage { | ||
context = this@MainActivity | ||
imageView = iv | ||
url = imageUrl | ||
requestOptions = options | ||
transitionOptions = DrawableTransitionOptions.withCrossFade(1500) | ||
} | ||
} | ||
|
||
private fun download() = mainScope.launch { | ||
val file = CacheUtils.createFormatedCacheFile(this@MainActivity, "gif") ?: return@launch | ||
val downloadResult = downloadImage { | ||
context = this@MainActivity | ||
url = imageUrl | ||
storageFile = file | ||
} | ||
val log = StringBuilder() | ||
log.append("下载") | ||
if (downloadResult) { | ||
log.append("成功") | ||
} else { | ||
log.append("失败") | ||
} | ||
log.append("\n").append("路径:").append(file.absolutePath) | ||
tv.text = log.toString() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/iv" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintDimensionRatio="H,1:1" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:src="@android:color/holo_orange_dark" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"/> | ||
android:id="@+id/tv" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:layout_marginEnd="8dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/iv" | ||
tools:text="Log" /> | ||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<resources> | ||
<string name="app_name">GlideUtil</string> | ||
<string name="app_name">GlideSample</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.zeropercenthappy.glideutil"/> | ||
package="com.zeropercenthappy.glideutil"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
</manifest> |
Oops, something went wrong.