├── .gitignore
├── FrescoImageLoader
├── .gitignore
├── build.gradle.kts
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── net
│ └── mikaelzero
│ └── mojito
│ └── loader
│ └── fresco
│ ├── FrescoImageLoader.kt
│ ├── IOUtils.kt
│ └── ImageDownloadSubscriber.kt
├── GlideImageLoader
├── .gitignore
├── build.gradle.kts
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── net
│ └── mikaelzero
│ └── mojito
│ └── loader
│ └── glide
│ ├── GlideImageLoader.kt
│ ├── GlideLoaderException.kt
│ ├── GlideProgressSupport.kt
│ ├── ImageDownloadTarget.kt
│ └── PrefetchTarget.kt
├── LICENSE
├── PhotoViewImageViewLoader
├── .gitignore
├── build.gradle.kts
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── net
│ │ └── mikaelzero
│ │ └── mojito
│ │ └── photoviewimageviewloader
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ └── java
│ │ └── net
│ │ └── mikaelzero
│ │ └── mojito
│ │ └── photoviewimageviewloader
│ │ ├── PhotoViewContentLoaderImpl.kt
│ │ └── PhotoViewImageLoadFactory.java
│ └── test
│ └── java
│ └── net
│ └── mikaelzero
│ └── mojito
│ └── photoviewimageviewloader
│ └── ExampleUnitTest.kt
├── README.md
├── README_en.md
├── SketchImageViewLoader
├── .gitignore
├── build.gradle.kts
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── net
│ └── mikaelzero
│ └── mojito
│ └── view
│ └── sketch
│ ├── SketchContentLoaderImpl.kt
│ ├── SketchImageLoadFactory.java
│ └── core
│ ├── Configuration.java
│ ├── ErrorTracker.java
│ ├── Initializer.java
│ ├── Key.java
│ ├── SLog.java
│ ├── Sketch.java
│ ├── SketchImageView.java
│ ├── SketchView.java
│ ├── cache
│ ├── BitmapPool.java
│ ├── BitmapPoolUtils.java
│ ├── DiskCache.java
│ ├── LruBitmapPool.java
│ ├── LruDiskCache.java
│ ├── LruMemoryCache.java
│ ├── MemoryCache.java
│ ├── MemorySizeCalculator.java
│ └── recycle
│ │ ├── AttributeStrategy.java
│ │ ├── BaseKeyPool.java
│ │ ├── GroupedLinkedMap.java
│ │ ├── LruPoolStrategy.java
│ │ ├── Poolable.java
│ │ └── SizeConfigStrategy.java
│ ├── datasource
│ ├── AssetsDataSource.java
│ ├── ByteArrayDataSource.java
│ ├── ContentDataSource.java
│ ├── DataSource.java
│ ├── DiskCacheDataSource.java
│ ├── DrawableDataSource.java
│ └── FileDataSource.java
│ ├── decode
│ ├── BitmapDecodeResult.java
│ ├── CorrectOrientationException.java
│ ├── DecodeException.java
│ ├── DecodeHelper.java
│ ├── DecodeResult.java
│ ├── DecodeTimeAnalyze.java
│ ├── GifDecodeHelper.java
│ ├── GifDecodeResult.java
│ ├── ImageAttrs.java
│ ├── ImageDecodeUtils.java
│ ├── ImageDecoder.java
│ ├── ImageOrientationCorrector.java
│ ├── ImageSizeCalculator.java
│ ├── ImageType.java
│ ├── NormalDecodeHelper.java
│ ├── NotFoundGifLibraryException.java
│ ├── ProcessException.java
│ ├── ProcessImageResultProcessor.java
│ ├── ProcessedCacheDecodeHelper.java
│ ├── ProcessedImageCache.java
│ ├── ProcessedResultCacheProcessor.java
│ ├── ResizeCalculator.java
│ ├── ResultProcessor.java
│ └── ThumbnailModeDecodeHelper.java
│ ├── display
│ ├── DefaultImageDisplayer.java
│ ├── ImageDisplayer.java
│ ├── TransitionImageDisplayer.java
│ ├── ZoomInImageDisplayer.java
│ └── ZoomOutImageDisplayer.java
│ ├── drawable
│ ├── SketchBitmap.java
│ ├── SketchBitmapDrawable.java
│ ├── SketchDrawable.java
│ ├── SketchGifDrawable.java
│ ├── SketchGifDrawableImpl.java
│ ├── SketchGifFactory.java
│ ├── SketchLoadingDrawable.java
│ ├── SketchRefBitmap.java
│ ├── SketchRefDrawable.java
│ ├── SketchShapeBitmapDrawable.java
│ └── SketchTransitionDrawable.java
│ ├── http
│ ├── DownloadException.java
│ ├── HttpStack.java
│ ├── HurlStack.java
│ ├── ImageDownloader.java
│ └── RedirectsException.java
│ ├── optionsfilter
│ ├── InPreferQualityOverSpeedOptionsFilter.java
│ ├── LowQualityOptionsFilter.java
│ ├── MobileDataPauseDownloadController.java
│ ├── OptionsFilter.java
│ ├── OptionsFilterManager.java
│ ├── PauseDownloadOptionsFilter.java
│ └── PauseLoadOptionsFilter.java
│ ├── process
│ ├── ImageProcessor.java
│ └── ResizeImageProcessor.java
│ ├── request
│ ├── AsyncRequest.java
│ ├── BaseRequest.java
│ ├── CallbackHandler.java
│ ├── CancelCause.java
│ ├── CanceledException.java
│ ├── DisplayCache.java
│ ├── DisplayHelper.java
│ ├── DisplayListener.java
│ ├── DisplayOptions.java
│ ├── DisplayRequest.java
│ ├── DisplayResult.java
│ ├── DownloadListener.java
│ ├── DownloadOptions.java
│ ├── DownloadProgressListener.java
│ ├── DownloadRequest.java
│ ├── DownloadResult.java
│ ├── ErrorCause.java
│ ├── FixedSize.java
│ ├── FreeRideDisplayRequest.java
│ ├── FreeRideDownloadRequest.java
│ ├── FreeRideManager.java
│ ├── HelperFactory.java
│ ├── ImageFrom.java
│ ├── Listener.java
│ ├── LoadHelper.java
│ ├── LoadListener.java
│ ├── LoadOptions.java
│ ├── LoadRequest.java
│ ├── LoadResult.java
│ ├── MaxSize.java
│ ├── RedisplayListener.java
│ ├── RequestAndViewBinder.java
│ ├── RequestExecutor.java
│ ├── RequestFactory.java
│ ├── RequestLevel.java
│ ├── Resize.java
│ ├── ShapeSize.java
│ └── ViewInfo.java
│ ├── shaper
│ ├── CircleImageShaper.java
│ ├── ImageShaper.java
│ └── RoundRectImageShaper.java
│ ├── state
│ ├── DrawableStateImage.java
│ ├── MakerStateImage.java
│ ├── MemoryCacheStateImage.java
│ ├── OldStateImage.java
│ └── StateImage.java
│ ├── uri
│ ├── AbsBitmapDiskCacheUriModel.java
│ ├── AbsDiskCacheUriModel.java
│ ├── AbsStreamDiskCacheUriModel.java
│ ├── AndroidResUriModel.java
│ ├── ApkIconUriModel.java
│ ├── AppIconUriModel.java
│ ├── AssetUriModel.java
│ ├── Base64UriModel.java
│ ├── Base64VariantUriModel.java
│ ├── ContentUriModel.java
│ ├── DrawableUriModel.java
│ ├── FileUriModel.java
│ ├── FileVariantUriModel.java
│ ├── GetDataSourceException.java
│ ├── HttpUriModel.java
│ ├── HttpsUriModel.java
│ ├── UriModel.java
│ └── UriModelManager.java
│ ├── util
│ ├── DiskLruCache.java
│ ├── DrawableWrapper.java
│ ├── KeyCounter.java
│ ├── LruCache.java
│ ├── NoSpaceException.java
│ ├── ObjectPool.java
│ ├── SketchMD5Utils.java
│ ├── SketchUtils.java
│ ├── Stopwatch.java
│ ├── UnableCreateDirException.java
│ └── UnableCreateFileException.java
│ ├── viewfun
│ ├── DisplayListenerProxy.java
│ ├── FunctionCallbackView.java
│ ├── FunctionPropertyView.java
│ ├── ImageZoomFunction.java
│ ├── OnClickListenerProxy.java
│ ├── ProgressListenerProxy.java
│ ├── RequestFunction.java
│ ├── ViewFunction.java
│ └── ViewFunctions.java
│ └── zoom
│ ├── AdaptiveTwoLevelScales.java
│ ├── BlockDisplayer.java
│ ├── FlingRunner.java
│ ├── ImageZoomer.java
│ ├── LocationRunner.java
│ ├── ScaleDragGestureDetector.java
│ ├── ScaleDragHelper.java
│ ├── Size.java
│ ├── Sizes.java
│ ├── TapHelper.java
│ ├── ZoomRunner.java
│ ├── ZoomScales.java
│ └── block
│ ├── Block.java
│ ├── BlockDecoder.java
│ ├── BlockExecutor.java
│ ├── BlockManager.java
│ ├── CallbackHandler.java
│ ├── DecodeHandler.java
│ ├── ImageRegionDecoder.java
│ └── InitHandler.java
├── app
├── build.gradle.kts
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── androidTest.iml
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── net
│ │ │ └── mikaelzero
│ │ │ └── app
│ │ │ ├── ActivityCoverActivity.kt
│ │ │ ├── App.kt
│ │ │ ├── BilibiliActivityCoverLoader.kt
│ │ │ ├── DifferentScenesActivity.kt
│ │ │ ├── DifferentScenesAdapter.kt
│ │ │ ├── ImageAdapter.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── PreviewActivity.kt
│ │ │ ├── SourceUtil.java
│ │ │ ├── TargetActivity.kt
│ │ │ ├── UrlBean.kt
│ │ │ ├── ViewUtil.kt
│ │ │ ├── local
│ │ │ ├── LocalImageActivity.kt
│ │ │ └── LocalImageAdapter.kt
│ │ │ ├── stagger
│ │ │ ├── StaggerActivity.kt
│ │ │ └── StaggerAdapter.kt
│ │ │ └── video
│ │ │ ├── ArtLoadFactory.java
│ │ │ ├── ArtplayerLoadImpl.kt
│ │ │ ├── HackVideoView.java
│ │ │ └── VideoActivity.kt
│ ├── main.iml
│ └── res
│ │ ├── drawable
│ │ ├── close.png
│ │ ├── comment.png
│ │ ├── good.png
│ │ ├── ic_baseline_near_me_24.xml
│ │ ├── item_bg.webp
│ │ ├── more.png
│ │ └── trans.png
│ │ ├── layout
│ │ ├── activity_cover.xml
│ │ ├── activity_different_scenes.xml
│ │ ├── activity_display.xml
│ │ ├── activity_local.xml
│ │ ├── activity_main.xml
│ │ ├── activity_stagger.xml
│ │ ├── activity_target.xml
│ │ ├── activity_video.xml
│ │ ├── bilibili_cover_layout.xml
│ │ ├── header_layout.xml
│ │ ├── item_grid.xml
│ │ ├── item_grid_fresco.xml
│ │ ├── item_local.xml
│ │ ├── item_local_fresco.xml
│ │ ├── item_stagger.xml
│ │ └── video_layout.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── test.iml
├── build.gradle.kts
├── buildSrc
├── build.gradle.kts
├── plugins.gradle.kts
└── src
│ └── main
│ └── kotlin
│ ├── Extensions.kt
│ ├── Library.kt
│ └── Projects.kt
├── coilimageloader
├── .gitignore
├── build.gradle.kts
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── net
│ │ └── mikaelzero
│ │ └── coilimageloader
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── net
│ │ │ └── mikaelzero
│ │ │ └── coilimageloader
│ │ │ ├── CoilImageLoader.kt
│ │ │ ├── CoilLoaderException.kt
│ │ │ ├── ImageDownloadTarget.kt
│ │ │ └── ProgressSupport.kt
│ └── res
│ │ ├── values-night
│ │ └── themes.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── net
│ └── mikaelzero
│ └── coilimageloader
│ └── ExampleUnitTest.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── mojito
├── build.gradle.kts
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── net
│ │ └── mikaelzero
│ │ └── mojito
│ │ ├── Mojito.kt
│ │ ├── MojitoBuilder.kt
│ │ ├── MojitoLoader.kt
│ │ ├── MojitoView.java
│ │ ├── bean
│ │ ├── ActivityConfig.kt
│ │ ├── FragmentConfig.kt
│ │ ├── ViewPagerBean.kt
│ │ └── ViewParams.java
│ │ ├── ext
│ │ └── MojitoViewExt.kt
│ │ ├── impl
│ │ ├── DefaultMojitoConfig.kt
│ │ ├── DefaultPercentProgress.java
│ │ ├── DefaultTargetFragmentCover.kt
│ │ ├── LoadingView.java
│ │ ├── NumIndicator.java
│ │ └── SimpleMojitoViewCallback.kt
│ │ ├── interfaces
│ │ ├── ActivityCoverLoader.kt
│ │ ├── IIndicator.java
│ │ ├── IMojitoActivity.kt
│ │ ├── IMojitoConfig.kt
│ │ ├── IMojitoFragment.kt
│ │ ├── IProgress.java
│ │ ├── ImageViewLoadFactory.kt
│ │ ├── OnMojitoListener.kt
│ │ └── OnMojitoViewCallback.java
│ │ ├── loader
│ │ ├── ContentLoader.kt
│ │ ├── DefaultImageCallback.java
│ │ ├── FragmentCoverLoader.kt
│ │ ├── ImageInfoExtractor.java
│ │ ├── ImageLoader.java
│ │ ├── InstanceLoader.kt
│ │ ├── MultiContentLoader.kt
│ │ ├── OnLongTapCallback.kt
│ │ └── OnTapCallback.kt
│ │ ├── tools
│ │ ├── BitmapUtil.kt
│ │ ├── CommonExt.kt
│ │ ├── DataWrapUtil.kt
│ │ ├── MarginViewWrapper.java
│ │ ├── MojitoConstant.kt
│ │ ├── NoScrollViewPager.java
│ │ ├── ScreenUtils.java
│ │ ├── TransitionAdapterListener.java
│ │ └── Utils.java
│ │ └── ui
│ │ ├── ImageMojitoActivity.kt
│ │ └── ImageMojitoFragment.kt
│ └── res
│ ├── drawable
│ └── target_button_shape.xml
│ ├── layout
│ ├── activity_image.xml
│ ├── default_target_cover_layout.xml
│ ├── fragment_image.xml
│ └── layout_content.xml
│ ├── styles.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── ids.xml
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle.kts
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/*
5 | .DS_Store
6 | /build
7 | /captures
8 | /app/seeds.txt
9 | /app/mapping.txt
10 | /app/bugly
11 | .externalNativeBuild
12 |
13 | # Built application files
14 | *.apk
15 | *.ap_
16 |
17 | # Files for the ART/Dalvik VM
18 | *.dex
19 |
20 | # Java class files
21 | *.class
22 |
23 | # Generated files
24 | bin/
25 | gen/
26 | out/
27 |
28 | # Gradle files
29 | .gradle/
30 | build/
31 |
32 | # Local configuration file (sdk path, etc)
33 | local.properties
34 |
35 | # Proguard folder generated by Eclipse
36 | proguard/
37 |
38 | # Log Files
39 | *.log
40 |
41 | # Android Studio Navigation editor temp files
42 | .navigation/
43 |
44 | # Android Studio captures folder
45 | captures/
46 |
47 | # Keystore files
48 | *.jks
49 |
--------------------------------------------------------------------------------
/FrescoImageLoader/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/FrescoImageLoader/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import mojito.setupLibraryModule
2 |
3 | plugins {
4 | id("com.android.library")
5 | id("kotlin-android")
6 | id("com.github.dcendents.android-maven")
7 | }
8 |
9 | group = "com.github.mikaelzero"
10 | setupLibraryModule {
11 | defaultConfig {
12 | minSdk = 16
13 | }
14 | }
15 | dependencies {
16 | implementation(mojito.Library.KOTLINX_STDLIB)
17 | implementation(mojito.Library.ANDROIDX_APPCOMPAT)
18 | implementation(mojito.Library.ANDROIDX_CORE)
19 | implementation(mojito.Library.OKHTTP)
20 | implementation("com.facebook.fresco:fresco:2.1.0")
21 | implementation("androidx.annotation:annotation:1.2.0")
22 | implementation(project(":mojito"))
23 | }
24 |
--------------------------------------------------------------------------------
/FrescoImageLoader/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/FrescoImageLoader/consumer-rules.pro
--------------------------------------------------------------------------------
/FrescoImageLoader/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/FrescoImageLoader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/GlideImageLoader/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/GlideImageLoader/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import mojito.setupLibraryModule
2 |
3 | plugins {
4 | id("com.android.library")
5 | id("kotlin-android")
6 | id("com.github.dcendents.android-maven")
7 | }
8 |
9 | group = "com.github.mikaelzero"
10 | setupLibraryModule {
11 | defaultConfig {
12 | minSdk = 16
13 | }
14 | }
15 |
16 |
17 | dependencies {
18 | implementation(mojito.Library.KOTLINX_STDLIB)
19 | implementation(mojito.Library.ANDROIDX_APPCOMPAT)
20 | implementation(mojito.Library.ANDROIDX_CORE)
21 | implementation(mojito.Library.OKHTTP)
22 | api("com.github.bumptech.glide:okhttp3-integration:4.11.0")
23 | implementation(project(":mojito"))
24 | }
25 |
--------------------------------------------------------------------------------
/GlideImageLoader/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/GlideImageLoader/consumer-rules.pro
--------------------------------------------------------------------------------
/GlideImageLoader/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/GlideImageLoader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/GlideImageLoader/src/main/java/net/mikaelzero/mojito/loader/glide/GlideLoaderException.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader.glide
2 |
3 | import android.graphics.drawable.Drawable
4 |
5 | class GlideLoaderException(val errorDrawable: Drawable?) : RuntimeException()
--------------------------------------------------------------------------------
/GlideImageLoader/src/main/java/net/mikaelzero/mojito/loader/glide/PrefetchTarget.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader.glide
2 |
3 | import android.graphics.drawable.Drawable
4 | import com.bumptech.glide.request.Request
5 | import com.bumptech.glide.request.target.SizeReadyCallback
6 | import com.bumptech.glide.request.target.Target
7 | import com.bumptech.glide.request.transition.Transition
8 | import com.bumptech.glide.util.Util
9 | import java.io.File
10 |
11 | class PrefetchTarget private constructor(private val width: Int, private val height: Int) :
12 | Target {
13 | private var request: Request? = null
14 |
15 | constructor() : this(
16 | Target.SIZE_ORIGINAL,
17 | Target.SIZE_ORIGINAL
18 | ) {
19 | }
20 |
21 | override fun onResourceReady(
22 | resource: File,
23 | transition: Transition?
24 | ) {
25 | // not interested in result
26 | }
27 |
28 | /**
29 | * Immediately calls the given callback with the sizes given in the constructor.
30 | *
31 | * @param cb {@inheritDoc}
32 | */
33 | override fun getSize(cb: SizeReadyCallback) {
34 | require(Util.isValidDimensions(width, height)) {
35 | ("Width and height must both be > 0 or Target#SIZE_ORIGINAL, but given" + " width: "
36 | + width + " and height: " + height + ", either provide dimensions in the constructor"
37 | + " or call override()")
38 | }
39 | cb.onSizeReady(width, height)
40 | }
41 |
42 | override fun removeCallback(cb: SizeReadyCallback) {
43 | // Do nothing, we never retain a reference to the callback.
44 | }
45 |
46 | override fun setRequest(request: Request?) {
47 | this.request = request
48 | }
49 |
50 | override fun getRequest(): Request? {
51 | return request
52 | }
53 |
54 | override fun onLoadCleared(placeholder: Drawable?) {
55 | // Do nothing.
56 | }
57 |
58 | override fun onLoadStarted(placeholder: Drawable?) {
59 | // Do nothing.
60 | }
61 |
62 | override fun onLoadFailed(errorDrawable: Drawable?) {
63 | // Do nothing.
64 | }
65 |
66 | override fun onStart() {
67 | // Do nothing.
68 | }
69 |
70 | override fun onStop() {
71 | // Do nothing.
72 | }
73 |
74 | override fun onDestroy() {
75 | // Do nothing.
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import mojito.setupLibraryModule
2 |
3 | plugins {
4 | id("com.android.library")
5 | id("kotlin-android")
6 | id("com.github.dcendents.android-maven")
7 | }
8 |
9 | group = "com.github.mikaelzero"
10 | setupLibraryModule {
11 | defaultConfig {
12 | minSdk = 16
13 | }
14 | }
15 |
16 | dependencies {
17 | implementation(mojito.Library.KOTLINX_STDLIB)
18 | implementation(mojito.Library.ANDROIDX_APPCOMPAT)
19 | implementation(mojito.Library.ANDROIDX_CORE)
20 | implementation("com.github.chrisbanes:PhotoView:2.3.0")
21 | implementation(project(":mojito"))
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/PhotoViewImageViewLoader/consumer-rules.pro
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/src/androidTest/java/net/mikaelzero/mojito/photoviewimageviewloader/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.photoviewimageviewloader
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("net.mikaelzero.mojito.photoviewimageviewloader.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/src/main/java/net/mikaelzero/mojito/photoviewimageviewloader/PhotoViewImageLoadFactory.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.photoviewimageviewloader;
2 |
3 | import android.net.Uri;
4 | import android.view.View;
5 |
6 | import com.github.chrisbanes.photoview.PhotoView;
7 |
8 | import net.mikaelzero.mojito.interfaces.ImageViewLoadFactory;
9 | import net.mikaelzero.mojito.loader.ContentLoader;
10 |
11 | import org.jetbrains.annotations.NotNull;
12 |
13 |
14 | public class PhotoViewImageLoadFactory implements ImageViewLoadFactory {
15 | @Override
16 | public void loadSillContent(@NotNull View view, @NotNull Uri uri) {
17 | if (view instanceof PhotoView) {
18 | ((PhotoView) view).setImageURI(uri);
19 | }
20 | }
21 |
22 | @Override
23 | public void loadContentFail(@NotNull View view, int drawableResId) {
24 | if (view instanceof PhotoView) {
25 | ((PhotoView) view).setImageResource(drawableResId);
26 | }
27 | }
28 |
29 | @NotNull
30 | @Override
31 | public ContentLoader newContentLoader() {
32 | return new PhotoViewContentLoaderImpl();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/PhotoViewImageViewLoader/src/test/java/net/mikaelzero/mojito/photoviewimageviewloader/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.photoviewimageviewloader
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/SketchImageViewLoader/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import mojito.setupLibraryModule
2 |
3 | plugins {
4 | id("com.android.library")
5 | id("kotlin-android")
6 | id("com.github.dcendents.android-maven")
7 | }
8 |
9 | group = "com.github.mikaelzero"
10 | setupLibraryModule {
11 | defaultConfig {
12 | minSdk = 16
13 | }
14 | }
15 |
16 | dependencies {
17 | implementation(mojito.Library.KOTLINX_STDLIB)
18 | implementation(mojito.Library.ANDROIDX_APPCOMPAT)
19 | implementation(mojito.Library.ANDROIDX_CORE)
20 | implementation(mojito.Library.OKHTTP)
21 | implementation("me.panpf:sketch-gif:2.7.1")
22 | implementation("androidx.exifinterface:exifinterface:1.3.3")
23 | implementation(project(":mojito"))
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/SketchImageViewLoader/consumer-rules.pro
--------------------------------------------------------------------------------
/SketchImageViewLoader/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/SketchImageLoadFactory.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.view.sketch;
2 |
3 | import android.net.Uri;
4 | import android.view.View;
5 |
6 | import net.mikaelzero.mojito.interfaces.ImageViewLoadFactory;
7 | import net.mikaelzero.mojito.loader.ContentLoader;
8 | import net.mikaelzero.mojito.view.sketch.core.Sketch;
9 | import net.mikaelzero.mojito.view.sketch.core.SketchImageView;
10 |
11 | import org.jetbrains.annotations.NotNull;
12 |
13 |
14 | public class SketchImageLoadFactory implements ImageViewLoadFactory {
15 | @Override
16 | public void loadSillContent(@NotNull View view, @NotNull Uri uri) {
17 | if (view instanceof SketchImageView) {
18 | Sketch.with(view.getContext()).display(uri.getPath(), (SketchImageView) view).loadingImage((context, sketchView, displayOptions) -> {
19 | return ((SketchImageView) view).getDrawable(); // 解决缩略图切换到原图显示的时候会闪烁的问题
20 | }).commit();
21 | }
22 | }
23 |
24 | @Override
25 | public void loadContentFail(@NotNull View view, int drawableResId) {
26 | if (view instanceof SketchImageView) {
27 | ((SketchImageView) view).displayResourceImage(drawableResId);
28 | }
29 | }
30 |
31 | @NotNull
32 | @Override
33 | public ContentLoader newContentLoader() {
34 | return new SketchContentLoaderImpl();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/Initializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core;
18 |
19 | import android.content.Context;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 |
24 | public interface Initializer {
25 | void onInitialize(@NonNull Context context, @NonNull Configuration configuration);
26 | }
27 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/Key.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core;
18 |
19 | import androidx.annotation.Nullable;
20 |
21 | public interface Key {
22 |
23 | @Nullable
24 | String getKey();
25 | }
26 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/cache/MemoryCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.cache;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import net.mikaelzero.mojito.view.sketch.core.drawable.SketchRefBitmap;
23 |
24 | /**
25 | * 内存缓存管理器
26 | */
27 | public interface MemoryCache {
28 | /**
29 | * 缓存一张图片
30 | *
31 | * @param key 缓存 key
32 | * @param refBitmap 待缓存图片
33 | */
34 | void put(@NonNull String key, @NonNull SketchRefBitmap refBitmap);
35 |
36 | /**
37 | * 根据指定 key 获取图片
38 | *
39 | * @param key 缓存 key
40 | */
41 | @Nullable
42 | SketchRefBitmap get(@NonNull String key);
43 |
44 | /**
45 | * 根据指定 key 删除图片
46 | *
47 | * @param key 缓存 key
48 | */
49 | @Nullable
50 | SketchRefBitmap remove(@NonNull String key);
51 |
52 | /**
53 | * 获取已用容量
54 | */
55 | long getSize();
56 |
57 | /**
58 | * 获取最大容量
59 | */
60 | long getMaxSize();
61 |
62 | /**
63 | * 根据 level 修整缓存
64 | *
65 | * @param level 修剪级别,对应 APP 的不同状态
66 | * @see android.content.ComponentCallbacks2
67 | */
68 | void trimMemory(int level);
69 |
70 | /**
71 | * 是否禁用
72 | */
73 | boolean isDisabled();
74 |
75 | /**
76 | * 设置是否禁用
77 | *
78 | * @param disabled 是否禁用
79 | */
80 | void setDisabled(boolean disabled);
81 |
82 | /**
83 | * 清除缓存
84 | */
85 | void clear();
86 |
87 | /**
88 | * 是否已关闭
89 | */
90 | boolean isClosed();
91 |
92 | /**
93 | * 关闭,关闭后就彻底不能用了,如果你只是想暂时的关闭就使用 {@link #setDisabled(boolean)}
94 | */
95 | void close();
96 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/cache/recycle/BaseKeyPool.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.view.sketch.core.cache.recycle;
2 |
3 | import java.util.ArrayDeque;
4 | import java.util.Queue;
5 |
6 | abstract class BaseKeyPool {
7 | private static final int MAX_SIZE = 20;
8 | private final Queue keyPool = new ArrayDeque(MAX_SIZE);
9 |
10 | protected T get() {
11 | T result = keyPool.poll();
12 | if (result == null) {
13 | result = create();
14 | }
15 | return result;
16 | }
17 |
18 | public void offer(T key) {
19 | if (keyPool.size() < MAX_SIZE) {
20 | keyPool.offer(key);
21 | }
22 | }
23 |
24 | protected abstract T create();
25 | }
26 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/cache/recycle/LruPoolStrategy.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.view.sketch.core.cache.recycle;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import net.mikaelzero.mojito.view.sketch.core.Key;
6 |
7 |
8 | public interface LruPoolStrategy extends Key {
9 | void put(Bitmap bitmap);
10 |
11 | Bitmap get(int width, int height, Bitmap.Config config);
12 |
13 | Bitmap removeLast();
14 |
15 | String logBitmap(Bitmap bitmap);
16 |
17 | String logBitmap(int width, int height, Bitmap.Config config);
18 |
19 | int getSize(Bitmap bitmap);
20 | }
21 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/cache/recycle/Poolable.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.view.sketch.core.cache.recycle;
2 |
3 | interface Poolable {
4 | void offer();
5 | }
6 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/CorrectOrientationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | @SuppressWarnings("WeakerAccess")
22 | public class CorrectOrientationException extends Exception {
23 | public CorrectOrientationException(@NonNull String message) {
24 | super(message);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/DecodeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.ErrorCause;
22 | @SuppressWarnings("WeakerAccess")
23 | public class DecodeException extends Exception {
24 |
25 | @NonNull
26 | private ErrorCause errorCause;
27 |
28 | public DecodeException(@NonNull Throwable cause, @NonNull ErrorCause errorCause) {
29 | super(cause);
30 | this.errorCause = errorCause;
31 | }
32 |
33 | public DecodeException(@NonNull String message, @NonNull ErrorCause errorCause) {
34 | super(message);
35 | this.errorCause = errorCause;
36 | }
37 |
38 | public DecodeException(@NonNull String message, @NonNull Throwable cause, @NonNull ErrorCause errorCause) {
39 | super(message, cause);
40 | this.errorCause = errorCause;
41 | }
42 |
43 | @NonNull
44 | public ErrorCause getErrorCause() {
45 | return errorCause;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/DecodeResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import net.mikaelzero.mojito.view.sketch.core.cache.BitmapPool;
23 | import net.mikaelzero.mojito.view.sketch.core.request.ImageFrom;
24 |
25 | /**
26 | * 解码结果
27 | */
28 | public interface DecodeResult {
29 |
30 | /**
31 | * 获取图片的属性
32 | *
33 | * @return {@link ImageAttrs}
34 | */
35 | @NonNull
36 | ImageAttrs getImageAttrs();
37 |
38 | /**
39 | * 获取图片的来源
40 | *
41 | * @return {@link ImageFrom}
42 | */
43 | @Nullable
44 | ImageFrom getImageFrom();
45 |
46 | /**
47 | * 设置图片的来源
48 | *
49 | * @param imageFrom {@link ImageFrom}
50 | */
51 | void setImageFrom(@NonNull ImageFrom imageFrom);
52 |
53 | /**
54 | * 是否禁止对图片进行后期处理
55 | */
56 | boolean isBanProcess();
57 |
58 | /**
59 | * 设置是否禁止对图片进行后期处理
60 | *
61 | * @param banProcess 是否禁止对图片进行后期处理
62 | * @return {@link me.panpf.sketch.decode.DecodeResult}
63 | */
64 | @NonNull
65 | DecodeResult setBanProcess(boolean banProcess);
66 |
67 | /**
68 | * 是否经过了后期处理
69 | */
70 | boolean isProcessed();
71 |
72 | /**
73 | * 设置是否经过了后期处理
74 | *
75 | * @param processed 否经过了后期处理
76 | * @return {@link me.panpf.sketch.decode.DecodeResult}
77 | */
78 | @NonNull
79 | DecodeResult setProcessed(boolean processed);
80 |
81 | /**
82 | * 回收图片
83 | *
84 | * @param bitmapPool {@link BitmapPool}
85 | */
86 | void recycle(@NonNull BitmapPool bitmapPool);
87 | }
88 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/DecodeTimeAnalyze.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.SLog;
22 |
23 | import java.text.DecimalFormat;
24 |
25 |
26 | public class DecodeTimeAnalyze {
27 | private volatile static long decodeCount;
28 | private volatile static long useTimeCount;
29 | private static DecimalFormat decimalFormat;
30 |
31 | public long decodeStart() {
32 | return System.currentTimeMillis();
33 | }
34 |
35 | public synchronized void decodeEnd(long startTime, @NonNull String logName, String key) {
36 | long useTime = System.currentTimeMillis() - startTime;
37 | if ((Long.MAX_VALUE - decodeCount) < 1 || (Long.MAX_VALUE - useTimeCount) < useTime) {
38 | decodeCount = 0;
39 | useTimeCount = 0;
40 | }
41 | decodeCount++;
42 | useTimeCount += useTime;
43 | if (decimalFormat == null) {
44 | decimalFormat = new DecimalFormat("#.##");
45 | }
46 | SLog.d(logName, "decode use time %dms, average %sms. %s",
47 | useTime, decimalFormat.format((double) useTimeCount / decodeCount), key);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/ImageAttrs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | /**
22 | * 图片的真实宽、高、格式、方向等属性
23 | */
24 | public class ImageAttrs {
25 | private int width;
26 | private int height;
27 | @NonNull
28 | private String mimeType;
29 | private int exifOrientation;
30 |
31 | public ImageAttrs(@NonNull String mimeType, int width, int height, int exifOrientation) {
32 | this.mimeType = mimeType;
33 | this.width = width;
34 | this.height = height;
35 | this.exifOrientation = exifOrientation;
36 | }
37 |
38 | public int getExifOrientation() {
39 | return exifOrientation;
40 | }
41 |
42 | @NonNull
43 | public String getMimeType() {
44 | return mimeType;
45 | }
46 |
47 | public int getHeight() {
48 | return height;
49 | }
50 |
51 | public int getWidth() {
52 | return width;
53 | }
54 |
55 | void resetSize(int width, int height) {
56 | this.width = width;
57 | this.height = height;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/NotFoundGifLibraryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | public class NotFoundGifLibraryException extends Exception {
20 | }
21 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/ProcessException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | public class ProcessException extends Exception {
22 |
23 | public ProcessException(@NonNull Throwable cause) {
24 | super(cause);
25 | }
26 |
27 | public ProcessException(@NonNull String message, @NonNull Throwable cause) {
28 | super(message, cause);
29 | }
30 |
31 | public ProcessException(@NonNull String message) {
32 | super(message);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/ProcessedResultCacheProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.LoadRequest;
22 |
23 |
24 | /**
25 | * 缓存经过处理的图片,方便下次直接读取,加快速度
26 | */
27 | public class ProcessedResultCacheProcessor implements ResultProcessor {
28 |
29 | @Override
30 | public void process(@NonNull LoadRequest request, @NonNull DecodeResult result) {
31 | if (result.isBanProcess()) {
32 | return;
33 | }
34 |
35 | if (!(result instanceof BitmapDecodeResult)) {
36 | return;
37 | }
38 |
39 | ProcessedImageCache processedImageCache = request.getConfiguration().getProcessedImageCache();
40 | if (!processedImageCache.canUse(request.getOptions())) {
41 | return;
42 | }
43 |
44 | if (!result.isProcessed()) {
45 | return;
46 | }
47 |
48 | BitmapDecodeResult bitmapDecodeResult = (BitmapDecodeResult) result;
49 | processedImageCache.saveToDiskCache(request, bitmapDecodeResult.getBitmap());
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/decode/ResultProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.decode;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.LoadRequest;
22 |
23 |
24 | /**
25 | * 解码完成后处理图片
26 | */
27 | public interface ResultProcessor {
28 |
29 | /**
30 | * 后期处理
31 | *
32 | * @param request {@link LoadRequest}
33 | * @param result {@link DecodeResult}
34 | * @throws ProcessException 后期处理失败了
35 | */
36 | void process(@NonNull LoadRequest request, @NonNull DecodeResult result) throws ProcessException;
37 | }
38 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/display/DefaultImageDisplayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.display;
18 |
19 | import android.graphics.drawable.Drawable;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import net.mikaelzero.mojito.view.sketch.core.SketchView;
24 |
25 | /**
26 | * 默认的图片显示器,没有任何动画效果
27 | */
28 | public class DefaultImageDisplayer implements ImageDisplayer {
29 | private static final String KEY = "DefaultImageDisplayer";
30 |
31 | public DefaultImageDisplayer() {
32 | }
33 |
34 | @Override
35 | public void display(@NonNull SketchView sketchView, @NonNull Drawable newDrawable) {
36 | sketchView.clearAnimation();
37 | sketchView.setImageDrawable(newDrawable);
38 | }
39 |
40 | @Override
41 | public int getDuration() {
42 | return 0;
43 | }
44 |
45 | @Override
46 | public boolean isAlwaysUse() {
47 | return false;
48 | }
49 |
50 | @NonNull
51 | @Override
52 | public String toString() {
53 | return KEY;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/display/ImageDisplayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.display;
18 |
19 | import android.graphics.drawable.Drawable;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import net.mikaelzero.mojito.view.sketch.core.SketchView;
24 | /**
25 | * 图片显示器,用来在加载完成后显示图片
26 | */
27 | public interface ImageDisplayer {
28 | int DEFAULT_ANIMATION_DURATION = 400;
29 |
30 | /**
31 | * 显示
32 | */
33 | void display(@NonNull SketchView sketchView, @NonNull Drawable newDrawable);
34 |
35 | /**
36 | * 获取持续时间,单位毫秒
37 | */
38 | int getDuration();
39 |
40 | /**
41 | * 只要涉及到显示图片就得使用 {@link me.panpf.sketch.display.ImageDisplayer}(显示从内存里取出的缓存图片时也不例外)
42 | */
43 | boolean isAlwaysUse();
44 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/drawable/SketchBitmap.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.view.sketch.core.drawable;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.annotation.Nullable;
7 |
8 | import net.mikaelzero.mojito.view.sketch.core.decode.ImageAttrs;
9 | import net.mikaelzero.mojito.view.sketch.core.util.SketchUtils;
10 |
11 |
12 | public abstract class SketchBitmap {
13 |
14 | @NonNull
15 | private String key;
16 | @NonNull
17 | private String uri;
18 | @Nullable
19 | protected Bitmap bitmap;
20 | @NonNull
21 | private ImageAttrs attrs;
22 |
23 | protected SketchBitmap(@NonNull Bitmap bitmap, @NonNull String key, @NonNull String uri, @NonNull ImageAttrs attrs) {
24 | //noinspection ConstantConditions
25 | if (bitmap == null || bitmap.isRecycled()) {
26 | throw new IllegalArgumentException("bitmap is null or recycled");
27 | }
28 |
29 | this.bitmap = bitmap;
30 | this.key = key;
31 | this.uri = uri;
32 | this.attrs = attrs;
33 | }
34 |
35 | @Nullable
36 | public Bitmap getBitmap() {
37 | return bitmap;
38 | }
39 |
40 | @NonNull
41 | public String getKey() {
42 | return key;
43 | }
44 |
45 | @NonNull
46 | public String getUri() {
47 | return uri;
48 | }
49 |
50 | @NonNull
51 | public ImageAttrs getAttrs() {
52 | return attrs;
53 | }
54 |
55 | @NonNull
56 | public abstract String getInfo();
57 |
58 | public int getByteCount() {
59 | return SketchUtils.getByteCount(getBitmap());
60 | }
61 |
62 | @Nullable
63 | public Bitmap.Config getBitmapConfig() {
64 | return bitmap != null ? bitmap.getConfig() : null;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/drawable/SketchDrawable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.drawable;
18 |
19 | import android.graphics.Bitmap;
20 |
21 | import androidx.annotation.Nullable;
22 |
23 | import net.mikaelzero.mojito.view.sketch.core.request.ImageFrom;
24 |
25 | public interface SketchDrawable {
26 | /**
27 | * 获取图片 ID
28 | */
29 | @Nullable
30 | String getKey();
31 |
32 | /**
33 | * 获取图片 uri
34 | */
35 | @Nullable
36 | String getUri();
37 |
38 | /**
39 | * 获取图片原始宽
40 | */
41 | int getOriginWidth();
42 |
43 | /**
44 | * 获取图片原始高
45 | */
46 | int getOriginHeight();
47 |
48 | /**
49 | * 获取图片类型
50 | */
51 | @Nullable
52 | String getMimeType();
53 |
54 | /**
55 | * 获取图片方向
56 | */
57 | int getExifOrientation();
58 |
59 | /**
60 | * 获取占用内存,单位字节
61 | */
62 | int getByteCount();
63 |
64 | /**
65 | * 获取 {@link Bitmap} 配置
66 | */
67 | @Nullable
68 | Bitmap.Config getBitmapConfig();
69 |
70 | /**
71 | * 获取图片来源
72 | */
73 | @Nullable
74 | ImageFrom getImageFrom();
75 |
76 | /**
77 | * 获取一些信息
78 | */
79 | @Nullable
80 | String getInfo();
81 | }
82 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/drawable/SketchRefDrawable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.drawable;
18 |
19 |
20 | public interface SketchRefDrawable extends SketchDrawable {
21 |
22 | void setIsDisplayed(String callingStation, boolean displayed);
23 |
24 | void setIsWaitingUse(String callingStation, boolean waitingUse);
25 |
26 | boolean isRecycled();
27 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/http/DownloadException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.http;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.ErrorCause;
22 |
23 | @SuppressWarnings("WeakerAccess")
24 | public class DownloadException extends Exception {
25 | @NonNull
26 | private ErrorCause errorCause;
27 |
28 | public DownloadException(@NonNull String message, @NonNull ErrorCause errorCause) {
29 | super(message);
30 | this.errorCause = errorCause;
31 | }
32 |
33 | public DownloadException(@NonNull String message, @NonNull Throwable cause, @NonNull ErrorCause errorCause) {
34 | super(message, cause);
35 | this.errorCause = errorCause;
36 | }
37 |
38 | @NonNull
39 | public ErrorCause getErrorCause() {
40 | return errorCause;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/http/RedirectsException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.http;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | @SuppressWarnings("WeakerAccess")
22 | public class RedirectsException extends Exception {
23 | @NonNull
24 | private String newUrl;
25 |
26 | public RedirectsException(@NonNull String newUrl) {
27 | this.newUrl = newUrl;
28 | }
29 |
30 | @NonNull
31 | public String getNewUrl() {
32 | return newUrl;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/optionsfilter/InPreferQualityOverSpeedOptionsFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.optionsfilter;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadOptions;
22 | import net.mikaelzero.mojito.view.sketch.core.request.LoadOptions;
23 |
24 | /**
25 | * 解码时质量优先于速度
26 | */
27 | public class InPreferQualityOverSpeedOptionsFilter implements OptionsFilter {
28 |
29 | @Override
30 | public void filter(@NonNull DownloadOptions options) {
31 | if (options instanceof LoadOptions) {
32 | ((LoadOptions) options).setInPreferQualityOverSpeed(true);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/optionsfilter/LowQualityOptionsFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.optionsfilter;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadOptions;
22 | import net.mikaelzero.mojito.view.sketch.core.request.LoadOptions;
23 |
24 |
25 | /**
26 | * 低质量 Bitmap.Config
27 | */
28 | public class LowQualityOptionsFilter implements OptionsFilter {
29 |
30 | @Override
31 | public void filter(@NonNull DownloadOptions options) {
32 | if (options instanceof LoadOptions) {
33 | ((LoadOptions) options).setLowQualityImage(true);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/optionsfilter/OptionsFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.optionsfilter;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadOptions;
22 | /**
23 | * 选项过滤器,用于统一修改 Options
24 | */
25 | public interface OptionsFilter {
26 | /**
27 | * 过滤 Options
28 | *
29 | * @param options {@link DownloadOptions}
30 | */
31 | void filter(@NonNull DownloadOptions options);
32 | }
33 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/optionsfilter/PauseDownloadOptionsFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.optionsfilter;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadOptions;
22 | import net.mikaelzero.mojito.view.sketch.core.request.LoadOptions;
23 | import net.mikaelzero.mojito.view.sketch.core.request.RequestLevel;
24 |
25 | /**
26 | * 暂停下载
27 | */
28 | public class PauseDownloadOptionsFilter implements OptionsFilter {
29 |
30 | @Override
31 | public void filter(@NonNull DownloadOptions options) {
32 | // 仅限 display 和 load 请求
33 | if (options instanceof LoadOptions) {
34 | // TODO 这里改成了 按大小覆盖之后强制点击显示就不起作用了
35 | RequestLevel level = options.getRequestLevel();
36 | if (level == null || level.getLevel() > RequestLevel.LOCAL.getLevel()) {
37 | options.setRequestLevel(RequestLevel.LOCAL);
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/optionsfilter/PauseLoadOptionsFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.optionsfilter;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.DisplayOptions;
22 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadOptions;
23 | import net.mikaelzero.mojito.view.sketch.core.request.RequestLevel;
24 |
25 |
26 | /**
27 | * 暂停加载
28 | */
29 | public class PauseLoadOptionsFilter implements OptionsFilter {
30 |
31 | @Override
32 | public void filter(@NonNull DownloadOptions options) {
33 | // 仅限 display 请求
34 | if (options instanceof DisplayOptions) {
35 | // TODO 这里改成了 按大小覆盖之后强制点击显示就不起作用了
36 | RequestLevel level = options.getRequestLevel();
37 | if (level == null || level.getLevel() > RequestLevel.MEMORY.getLevel()) {
38 | options.setRequestLevel(RequestLevel.MEMORY);
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/process/ImageProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.process;
18 |
19 | import android.graphics.Bitmap;
20 |
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 |
24 | import net.mikaelzero.mojito.view.sketch.core.Key;
25 | import net.mikaelzero.mojito.view.sketch.core.Sketch;
26 | import net.mikaelzero.mojito.view.sketch.core.request.Resize;
27 |
28 |
29 | /**
30 | * 用于在图片读取到内存后对图片进行修改
31 | */
32 | public interface ImageProcessor extends Key {
33 | /**
34 | * 修改图片并返回修改后的图片,请不要回收原图片
35 | *
36 | * @param sketch {@link Sketch}
37 | * @param bitmap {@link Bitmap}. 原图片
38 | * @param resize {@link Resize}. resize 决定了新图片的尺寸
39 | * @param lowQualityImage 是否使用低质量的图片
40 | * @return {@link Bitmap}. 修改后的图片,可以是一个新的 {@link Bitmap},也可以在原 {@link Bitmap} 基础上修改
41 | */
42 | @NonNull
43 | Bitmap process(@NonNull Sketch sketch, @NonNull Bitmap bitmap, @Nullable Resize resize, boolean lowQualityImage);
44 | }
45 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/CancelCause.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | /**
20 | * 取消的原因
21 | */
22 | public enum CancelCause {
23 | /**
24 | * 通过Sketch.cancel()方法取消
25 | */
26 | BE_CANCELLED,
27 |
28 | /**
29 | * 暂停下载
30 | */
31 | PAUSE_DOWNLOAD,
32 |
33 | /**
34 | * 暂停加载
35 | */
36 | PAUSE_LOAD,
37 |
38 | /**
39 | * ImageView从Window移除
40 | */
41 | ON_DETACHED_FROM_WINDOW,
42 |
43 | /**
44 | * 被替换了
45 | */
46 | BE_REPLACED,
47 |
48 | /**
49 | * 在DisplayHelper中替换取消
50 | */
51 | BE_REPLACED_ON_HELPER,
52 |
53 | /**
54 | * 在setImageDrawable的时候替换取消
55 | */
56 | BE_REPLACED_ON_SET_DRAWABLE,
57 |
58 | /**
59 | * 页面隐藏用户看不见
60 | */
61 | USERS_NOT_VISIBLE,
62 |
63 | /**
64 | * 检测到绑定关系断开
65 | */
66 | BIND_DISCONNECT,
67 | }
68 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/CanceledException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | public class CanceledException extends Exception {
20 | }
21 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/DisplayCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 |
23 | public class DisplayCache {
24 | @Nullable
25 | public String uri;
26 | // todo 删除 optioins,增加 optionskey,
27 | @NonNull
28 | public DisplayOptions options = new DisplayOptions();
29 | }
30 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/DisplayListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import android.graphics.drawable.Drawable;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import net.mikaelzero.mojito.view.sketch.core.decode.ImageAttrs;
24 | /**
25 | * 显示监听器,所有的方法都会在主线中执行,所以不必考虑异步线程中刷新 UI 的问题
26 | */
27 | public interface DisplayListener extends Listener {
28 | /**
29 | * 开始转入异步线程加载图片
30 | */
31 | @Override
32 | void onStarted();
33 |
34 | void onCompleted(@NonNull Drawable drawable, @NonNull ImageFrom imageFrom, @NonNull ImageAttrs imageAttrs);
35 |
36 | // todo 提供 SimpleListener
37 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/DisplayResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import android.graphics.drawable.Drawable;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import net.mikaelzero.mojito.view.sketch.core.decode.ImageAttrs;
24 | @SuppressWarnings("WeakerAccess")
25 | public class DisplayResult {
26 | @NonNull
27 | private Drawable drawable;
28 | @NonNull
29 | private ImageAttrs imageAttrs;
30 | @NonNull
31 | private ImageFrom imageFrom;
32 |
33 | public DisplayResult(@NonNull Drawable drawable, @NonNull ImageFrom imageFrom, @NonNull ImageAttrs imageAttrs) {
34 | this.drawable = drawable;
35 | this.imageFrom = imageFrom;
36 | this.imageAttrs = imageAttrs;
37 | }
38 |
39 | @NonNull
40 | public Drawable getDrawable() {
41 | return drawable;
42 | }
43 |
44 | @NonNull
45 | public ImageFrom getImageFrom() {
46 | return imageFrom;
47 | }
48 |
49 | @NonNull
50 | public ImageAttrs getImageAttrs() {
51 | return imageAttrs;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/DownloadListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 |
22 | /**
23 | * 下载监听器
24 | */
25 | public interface DownloadListener extends Listener {
26 | /**
27 | * 开始转入异步线程下载图片
28 | */
29 | @Override
30 | void onStarted();
31 |
32 | void onCompleted(@NonNull DownloadResult result);
33 |
34 | // todo 提供 SimpleListener
35 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/DownloadProgressListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | /**
20 | * 下载进度监听器
21 | */
22 | public interface DownloadProgressListener {
23 |
24 | /**
25 | * 更新下载进度
26 | *
27 | * @param totalLength 总长度
28 | * @param completedLength 已完成长度
29 | */
30 | // TODO: 2019-05-02 这里用的是 int 改成 long,涉及到的所有代码都要改
31 | void onUpdateDownloadProgress(int totalLength, int completedLength);
32 | }
33 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/DownloadResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import net.mikaelzero.mojito.view.sketch.core.cache.DiskCache;
23 |
24 |
25 | @SuppressWarnings("WeakerAccess")
26 | public class DownloadResult {
27 | @Nullable
28 | private DiskCache.Entry diskCacheEntry;
29 | @Nullable
30 | private byte[] imageData;
31 | @NonNull
32 | private ImageFrom imageFrom;
33 |
34 | public DownloadResult(@NonNull DiskCache.Entry diskCacheEntry, @NonNull ImageFrom imageFrom) {
35 | this.diskCacheEntry = diskCacheEntry;
36 | this.imageFrom = imageFrom;
37 | }
38 |
39 | public DownloadResult(@NonNull byte[] imageData, @NonNull ImageFrom imageFrom) {
40 | this.imageData = imageData;
41 | this.imageFrom = imageFrom;
42 | }
43 |
44 | @Nullable
45 | public DiskCache.Entry getDiskCacheEntry() {
46 | return diskCacheEntry;
47 | }
48 |
49 | @Nullable
50 | public byte[] getImageData() {
51 | return imageData;
52 | }
53 |
54 | @NonNull
55 | public ImageFrom getImageFrom() {
56 | return imageFrom;
57 | }
58 |
59 | public boolean hasData() {
60 | return diskCacheEntry != null || (imageData != null && imageData.length > 0);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/ErrorCause.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | /**
20 | * 错误原因
21 | */
22 | public enum ErrorCause {
23 | URI_INVALID,
24 |
25 | URI_NO_SUPPORT,
26 |
27 |
28 | DOWNLOAD_GET_RESPONSE_CODE_EXCEPTION,
29 |
30 | DOWNLOAD_RESPONSE_CODE_EXCEPTION,
31 |
32 | DOWNLOAD_EXCEPTION_AND_CANCELED,
33 |
34 | DOWNLOAD_DISK_CACHE_COMMIT_EXCEPTION,
35 |
36 | DOWNLOAD_DATA_NOT_FULLY_READ,
37 |
38 | DOWNLOAD_READ_DATA_EXCEPTION,
39 |
40 | DOWNLOAD_OPEN_DISK_CACHE_EXCEPTION,
41 |
42 | DOWNLOAD_NOT_FOUND_DISK_CACHE_AFTER_SUCCESS,
43 |
44 | DOWNLOAD_UNKNOWN_EXCEPTION,
45 |
46 |
47 | DECODE_UNKNOWN_RESULT_TYPE,
48 |
49 | DECODE_UNABLE_CREATE_DATA_SOURCE,
50 |
51 | DECODE_UNABLE_READ_BOUND_INFORMATION,
52 |
53 | DECODE_BOUND_RESULT_IMAGE_SIZE_INVALID,
54 |
55 | DECODE_NO_MATCHING_DECODE_HELPER,
56 |
57 | DECODE_UNABLE_CREATE_GIF_DRAWABLE,
58 |
59 | DECODE_NOT_FOUND_GIF_LIBRARY,
60 |
61 | DECODE_NO_MATCHING_GIF_SO,
62 |
63 | DECODE_FILE_IO_EXCEPTION,
64 |
65 | DECODE_RESULT_BITMAP_INVALID,
66 |
67 | DECODE_RESULT_BITMAP_SIZE_INVALID,
68 |
69 | DECODE_UNKNOWN_EXCEPTION,
70 |
71 | DECODE_PROCESS_IMAGE_FAIL,
72 |
73 | DECODE_CORRECT_ORIENTATION_FAIL,
74 |
75 |
76 | BITMAP_RECYCLED,
77 |
78 | GIF_DRAWABLE_RECYCLED,
79 |
80 | DATA_LOST_AFTER_LOAD_COMPLETED,
81 |
82 | DATA_LOST_AFTER_DOWNLOAD_COMPLETED,
83 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/FixedSize.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import java.util.Locale;
22 |
23 | /**
24 | * {@link android.widget.ImageView} 的固定尺寸,只能是通过 layout_width 和 layout_height 设置的固定值才能算是固定尺寸
25 | */
26 | public class FixedSize {
27 | private int width;
28 | private int height;
29 |
30 | public FixedSize(int width, int height) {
31 | this.width = width;
32 | this.height = height;
33 | }
34 |
35 | public int getWidth() {
36 | return width;
37 | }
38 |
39 | public int getHeight() {
40 | return height;
41 | }
42 |
43 | @Override
44 | public boolean equals(final Object obj) {
45 | if (obj == null) {
46 | return false;
47 | }
48 | if (this == obj) {
49 | return true;
50 | }
51 | if (obj instanceof FixedSize) {
52 | FixedSize other = (FixedSize) obj;
53 | return width == other.width && height == other.height;
54 | }
55 | return false;
56 | }
57 |
58 | @NonNull
59 | @Override
60 | public String toString() {
61 | return String.format(Locale.US, "FixedSize(%dx%d)", width, height);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/HelperFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import net.mikaelzero.mojito.view.sketch.core.Sketch;
23 | import net.mikaelzero.mojito.view.sketch.core.SketchView;
24 | /**
25 | * 负责创建 {@link DisplayHelper}、{@link LoadHelper}
26 | */
27 | @SuppressWarnings("WeakerAccess")
28 | public class HelperFactory {
29 | private static final String KEY = "HelperFactory";
30 |
31 | @Nullable
32 | private DisplayHelper cacheDisplayHelper;
33 |
34 |
35 | @NonNull
36 | public LoadHelper getLoadHelper(@NonNull Sketch sketch, @NonNull String uri, @Nullable LoadListener listener) {
37 | return new LoadHelper(sketch, uri, listener);
38 | }
39 |
40 | @NonNull
41 | public DisplayHelper getDisplayHelper(@NonNull Sketch sketch, @Nullable String uri, @NonNull SketchView sketchView) {
42 | if (this.cacheDisplayHelper == null) {
43 | this.cacheDisplayHelper = new DisplayHelper();
44 | }
45 |
46 | DisplayHelper displayHelper = this.cacheDisplayHelper;
47 | this.cacheDisplayHelper = null;
48 | displayHelper.init(sketch, uri, sketchView);
49 | return displayHelper;
50 | }
51 |
52 | /**
53 | * 用完了要回收
54 | */
55 | public void recycleDisplayHelper(@NonNull DisplayHelper displayHelper) {
56 | displayHelper.reset();
57 | if (this.cacheDisplayHelper == null) {
58 | this.cacheDisplayHelper = displayHelper;
59 | }
60 | }
61 |
62 | @NonNull
63 | @Override
64 | public String toString() {
65 | return KEY;
66 | }
67 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/ImageFrom.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | /**
20 | * 图片来源
21 | */
22 | public enum ImageFrom {
23 | /**
24 | * 网络
25 | */
26 | NETWORK,
27 |
28 | /**
29 | * 磁盘缓存
30 | */
31 | DISK_CACHE,
32 |
33 | /**
34 | * 本地图片
35 | */
36 | LOCAL,
37 |
38 | /**
39 | * 内存缓存
40 | */
41 | MEMORY_CACHE,
42 |
43 | /**
44 | * 内存
45 | */
46 | MEMORY,
47 | }
48 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/Listener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 |
22 | /**
23 | * 请求监听器,可监听开始、失败、取消
24 | */
25 | public interface Listener {
26 | void onStarted();
27 |
28 | /**
29 | * 失败
30 | *
31 | * @param cause 原因
32 | */
33 | void onError(@NonNull ErrorCause cause);
34 |
35 | /**
36 | * 取消
37 | *
38 | * @param cause 原因
39 | */
40 | void onCanceled(@NonNull CancelCause cause);
41 |
42 | // todo 提供 SimpleListener
43 | }
44 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/LoadListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 |
22 | public interface LoadListener extends Listener {
23 | /**
24 | * 开始转入异步线程加载图片
25 | */
26 | @Override
27 | void onStarted();
28 |
29 | void onCompleted(@NonNull LoadResult result);
30 |
31 | // todo 提供 SimpleListener
32 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/LoadResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import android.graphics.Bitmap;
20 |
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 |
24 | import net.mikaelzero.mojito.view.sketch.core.decode.DecodeResult;
25 | import net.mikaelzero.mojito.view.sketch.core.decode.ImageAttrs;
26 | import net.mikaelzero.mojito.view.sketch.core.drawable.SketchGifDrawable;
27 |
28 | @SuppressWarnings("WeakerAccess")
29 | public class LoadResult {
30 | @Nullable
31 | private Bitmap bitmap;
32 | @Nullable
33 | private SketchGifDrawable gifDrawable;
34 | @NonNull
35 | private ImageFrom imageFrom;
36 | @NonNull
37 | private ImageAttrs imageAttrs;
38 |
39 | public LoadResult(@NonNull Bitmap bitmap, @NonNull DecodeResult decodeResult) {
40 | this.bitmap = bitmap;
41 |
42 | this.imageAttrs = decodeResult.getImageAttrs();
43 | this.imageFrom = decodeResult.getImageFrom();
44 | }
45 |
46 | public LoadResult(@NonNull SketchGifDrawable gifDrawable, @NonNull DecodeResult decodeResult) {
47 | this.gifDrawable = gifDrawable;
48 |
49 | this.imageAttrs = decodeResult.getImageAttrs();
50 | this.imageFrom = decodeResult.getImageFrom();
51 | }
52 |
53 | @Nullable
54 | public Bitmap getBitmap() {
55 | return bitmap;
56 | }
57 |
58 | @Nullable
59 | public SketchGifDrawable getGifDrawable() {
60 | return gifDrawable;
61 | }
62 |
63 | @NonNull
64 | public ImageFrom getImageFrom() {
65 | return imageFrom;
66 | }
67 |
68 | @NonNull
69 | public ImageAttrs getImageAttrs() {
70 | return imageAttrs;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/MaxSize.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.Key;
22 |
23 | import java.util.Locale;
24 |
25 |
26 | /**
27 | * 用于计算 inSimpleSize 缩小图片
28 | */
29 | public class MaxSize implements Key {
30 | private int width;
31 | private int height;
32 |
33 | public MaxSize(int width, int height) {
34 | this.width = width;
35 | this.height = height;
36 | }
37 |
38 | public int getWidth() {
39 | return width;
40 | }
41 |
42 | public int getHeight() {
43 | return height;
44 | }
45 |
46 | @Override
47 | public boolean equals(final Object obj) {
48 | if (obj == null) {
49 | return false;
50 | }
51 | if (this == obj) {
52 | return true;
53 | }
54 | if (obj instanceof MaxSize) {
55 | MaxSize other = (MaxSize) obj;
56 | return width == other.width && height == other.height;
57 | }
58 | return false;
59 | }
60 |
61 | @NonNull
62 | @Override
63 | public String toString() {
64 | return String.format(Locale.US, "MaxSize(%dx%d)", width, height);
65 | }
66 |
67 | @Override
68 | public String getKey() {
69 | return toString();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/RedisplayListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 |
22 | public interface RedisplayListener {
23 | void onPreCommit(@NonNull String cacheUri, @NonNull DisplayOptions cacheOptions);
24 | }
25 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/RequestAndViewBinder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import net.mikaelzero.mojito.view.sketch.core.SketchView;
23 | import net.mikaelzero.mojito.view.sketch.core.util.SketchUtils;
24 |
25 | import java.lang.ref.WeakReference;
26 |
27 |
28 | /**
29 | * Request与ImageView的关系绑定器
30 | */
31 | @SuppressWarnings("WeakerAccess")
32 | public class RequestAndViewBinder {
33 | @Nullable
34 | private DisplayRequest displayRequest;
35 | @NonNull
36 | private WeakReference imageViewReference;
37 |
38 | public RequestAndViewBinder(@NonNull SketchView imageView) {
39 | this.imageViewReference = new WeakReference<>(imageView);
40 | }
41 |
42 | public void setDisplayRequest(@Nullable DisplayRequest displayRequest) {
43 | this.displayRequest = displayRequest;
44 | }
45 |
46 | @Nullable
47 | public SketchView getView() {
48 | final SketchView sketchView = imageViewReference.get();
49 | if (displayRequest != null) {
50 | DisplayRequest holderDisplayRequest = SketchUtils.findDisplayRequest(sketchView);
51 | if (holderDisplayRequest != null && holderDisplayRequest == displayRequest) {
52 | return sketchView;
53 | } else {
54 | return null;
55 | }
56 | } else {
57 | return sketchView;
58 | }
59 | }
60 |
61 | public boolean isBroken() {
62 | return getView() == null;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/request/RequestLevel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.request;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | /**
22 | * 决定请求的处理深度
23 | */
24 | public enum RequestLevel {
25 | /**
26 | * 正常的情况,内存没有就从本地加载,本地还没有就从网络加载,适用于所有类型的图片
27 | */
28 | NET(2),
29 |
30 | /**
31 | * 只从内存或本地加载图片,如果本地还没有就结束处理,适用于网络图片
32 | */
33 | LOCAL(1),
34 |
35 | /**
36 | * 只从内存中加载图片,如果内存缓存中没有就结束处理,适用于所有类型的图片,对加载请求和下载请求不起作用
37 | */
38 | MEMORY(0);
39 |
40 | private int level;
41 |
42 | RequestLevel(int level) {
43 | this.level = level;
44 | }
45 |
46 | @NonNull
47 | public static RequestLevel fromLevel(int level) {
48 | level = level % 3;
49 | if (level == 0) {
50 | return MEMORY;
51 | } else if (level == 1) {
52 | return LOCAL;
53 | } else {
54 | return NET;
55 | }
56 | }
57 |
58 | public int getLevel() {
59 | return level;
60 | }
61 | }
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/shaper/ImageShaper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.shaper;
18 |
19 | import android.graphics.Canvas;
20 | import android.graphics.Matrix;
21 | import android.graphics.Paint;
22 | import android.graphics.Path;
23 | import android.graphics.Rect;
24 | import android.graphics.Shader;
25 |
26 | import androidx.annotation.NonNull;
27 | import androidx.annotation.Nullable;
28 |
29 | import net.mikaelzero.mojito.view.sketch.core.request.ShapeSize;
30 | /**
31 | * 用于绘制时改变图片的形状
32 | */
33 | public interface ImageShaper {
34 | /**
35 | * 获取形状 Path
36 | */
37 | @NonNull
38 | Path getPath(@NonNull Rect bounds);
39 |
40 | /**
41 | * {@link Shader} 的 {@link Matrix} 更新时回调
42 | *
43 | * @param matrix {@link Shader} 的 {@link Matrix}
44 | * @param bounds {@link Rect}. 绘制区域的边界位置
45 | * @param bitmapWidth bitmap 宽
46 | * @param bitmapHeight bitmap 高
47 | * @param shapeSize {@link ShapeSize}
48 | * @param srcRect {@link Rect}. 原图中的位置
49 | */
50 | void onUpdateShaderMatrix(@NonNull Matrix matrix, @NonNull Rect bounds, int bitmapWidth, int bitmapHeight, @Nullable ShapeSize shapeSize, @NonNull Rect srcRect);
51 |
52 | /**
53 | * 绘制
54 | *
55 | * @param canvas {@link Canvas}
56 | * @param paint {@link Paint}
57 | * @param bounds {@link Rect}. 绘制区域的边界位置
58 | */
59 | void draw(@NonNull Canvas canvas, @NonNull Paint paint, @NonNull Rect bounds);
60 | }
61 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/state/StateImage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.state;
18 |
19 | import android.content.Context;
20 | import android.graphics.drawable.Drawable;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 |
25 | import net.mikaelzero.mojito.view.sketch.core.SketchView;
26 | import net.mikaelzero.mojito.view.sketch.core.request.DisplayOptions;
27 |
28 | /**
29 | * 用于为加载中、失败、暂停状态提供占位图片
30 | */
31 | public interface StateImage {
32 |
33 | /**
34 | * 获取图片
35 | *
36 | * @param context {@link Context}
37 | * @param sketchView {@link SketchView}
38 | * @param displayOptions {@link DisplayOptions}
39 | * @return {@link Drawable}
40 | */
41 | @Nullable
42 | Drawable getDrawable(@NonNull Context context, @NonNull SketchView sketchView, @NonNull DisplayOptions displayOptions);
43 | }
44 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/AbsBitmapDiskCacheUriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 |
22 | import androidx.annotation.NonNull;
23 |
24 | import net.mikaelzero.mojito.view.sketch.core.Sketch;
25 | import net.mikaelzero.mojito.view.sketch.core.cache.BitmapPoolUtils;
26 | import net.mikaelzero.mojito.view.sketch.core.util.SketchUtils;
27 |
28 | import java.io.OutputStream;
29 |
30 | public abstract class AbsBitmapDiskCacheUriModel extends AbsDiskCacheUriModel {
31 |
32 | @Override
33 | protected final void outContent(@NonNull Bitmap bitmap, @NonNull OutputStream outputStream) throws Exception {
34 | bitmap.compress(SketchUtils.bitmapConfigToCompressFormat(bitmap.getConfig()), 100, outputStream);
35 | }
36 |
37 | @Override
38 | protected final void closeContent(@NonNull Bitmap bitmap, @NonNull Context context) {
39 | BitmapPoolUtils.freeBitmapToPool(bitmap, Sketch.with(context).getConfiguration().getBitmapPool());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/AbsStreamDiskCacheUriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.content.Context;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import net.mikaelzero.mojito.view.sketch.core.util.SketchUtils;
24 |
25 | import java.io.InputStream;
26 | import java.io.OutputStream;
27 |
28 | public abstract class AbsStreamDiskCacheUriModel extends AbsDiskCacheUriModel {
29 |
30 | @Override
31 | protected final void outContent(@NonNull InputStream inputStream, @NonNull OutputStream outputStream) throws Exception {
32 | byte[] buffer = new byte[8 * 1024];
33 | int realLength;
34 | while (true) {
35 | realLength = inputStream.read(buffer);
36 | if (realLength < 0) {
37 | break;
38 | }
39 | outputStream.write(buffer, 0, realLength);
40 | }
41 | }
42 |
43 | @Override
44 | protected final void closeContent(@NonNull InputStream inputStream, @NonNull Context context) {
45 | SketchUtils.close(inputStream);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/AssetUriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.content.Context;
20 | import android.text.TextUtils;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 |
25 | import net.mikaelzero.mojito.view.sketch.core.datasource.AssetsDataSource;
26 | import net.mikaelzero.mojito.view.sketch.core.datasource.DataSource;
27 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadResult;
28 |
29 | public class AssetUriModel extends UriModel {
30 |
31 | public static final String SCHEME = "asset://";
32 |
33 | @NonNull
34 | public static String makeUri(@NonNull String assetResName) {
35 | if (TextUtils.isEmpty(assetResName)) {
36 | throw new IllegalArgumentException("Param assetResName is null or empty");
37 | }
38 | return !assetResName.startsWith(SCHEME) ? SCHEME + assetResName : assetResName;
39 | }
40 |
41 | @Override
42 | protected boolean match(@NonNull String uri) {
43 | return !TextUtils.isEmpty(uri) && uri.startsWith(SCHEME);
44 | }
45 |
46 | /**
47 | * 获取 uri 所真正包含的内容部分,例如 "asset://test.png",就会返回 "test.png"
48 | *
49 | * @param uri 图片 uri
50 | * @return uri 所真正包含的内容部分,例如 "asset://test.png",就会返回 "test.png"
51 | */
52 | @NonNull
53 | @Override
54 | public String getUriContent(@NonNull String uri) {
55 | return match(uri) ? uri.substring(SCHEME.length()) : uri;
56 | }
57 |
58 | @NonNull
59 | @Override
60 | public DataSource getDataSource(@NonNull Context context, @NonNull String uri, @Nullable DownloadResult downloadResult) throws GetDataSourceException {
61 | return new AssetsDataSource(context, getUriContent(uri));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/Base64UriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.content.Context;
20 | import android.text.TextUtils;
21 | import android.util.Base64;
22 |
23 | import androidx.annotation.NonNull;
24 |
25 | import java.io.ByteArrayInputStream;
26 | import java.io.InputStream;
27 |
28 |
29 | public class Base64UriModel extends AbsStreamDiskCacheUriModel {
30 |
31 | public static final String SCHEME = "data:image/";
32 |
33 | @Override
34 | protected boolean match(@NonNull String uri) {
35 | return !TextUtils.isEmpty(uri) && uri.startsWith(SCHEME);
36 | }
37 |
38 | /**
39 | * 获取 uri 所真正包含的内容部分,例如 "data:image/jpeg;base64,/9j/4QaORX...C8bg/U7T/in//Z",就会返回 "/9j/4QaORX...C8bg/U7T/in//Z"
40 | *
41 | * @param uri 图片 uri
42 | * @return uri 所真正包含的内容部分,例如 "data:image/jpeg;base64,/9j/4QaORX...C8bg/U7T/in//Z",就会返回 "/9j/4QaORX...C8bg/U7T/in//Z"
43 | */
44 | @NonNull
45 | @Override
46 | public String getUriContent(@NonNull String uri) {
47 | return !TextUtils.isEmpty(uri) ? uri.substring(uri.indexOf(";") + ";base64,".length()) : uri;
48 | }
49 |
50 | @NonNull
51 | @Override
52 | public String getDiskCacheKey(@NonNull String uri) {
53 | return getUriContent(uri);
54 | }
55 |
56 | @Override
57 | public boolean isConvertShortUriForKey() {
58 | return true;
59 | }
60 |
61 | @NonNull
62 | @Override
63 | protected InputStream getContent(@NonNull Context context, @NonNull String uri) throws GetDataSourceException {
64 | return new ByteArrayInputStream(Base64.decode(getUriContent(uri), Base64.DEFAULT));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/Base64VariantUriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.text.TextUtils;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | public class Base64VariantUriModel extends Base64UriModel {
24 |
25 | public static final String SCHEME = "data:img/";
26 |
27 | /**
28 | * 获取 uri 所真正包含的内容部分,例如 "data:img/jpeg;base64,/9j/4QaORX...C8bg/U7T/in//Z",就会返回 "/9j/4QaORX...C8bg/U7T/in//Z"
29 | *
30 | * @param uri 图片 uri
31 | * @return uri 所真正包含的内容部分,例如 "data:img/jpeg;base64,/9j/4QaORX...C8bg/U7T/in//Z",就会返回 "/9j/4QaORX...C8bg/U7T/in//Z"
32 | */
33 | @NonNull
34 | @Override
35 | public String getUriContent(@NonNull String uri) {
36 | return super.getUriContent(uri);
37 | }
38 |
39 | @Override
40 | protected boolean match(@NonNull String uri) {
41 | return !TextUtils.isEmpty(uri) && uri.startsWith(SCHEME);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/ContentUriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.content.Context;
20 | import android.net.Uri;
21 | import android.text.TextUtils;
22 |
23 | import androidx.annotation.NonNull;
24 | import androidx.annotation.Nullable;
25 |
26 | import net.mikaelzero.mojito.view.sketch.core.datasource.ContentDataSource;
27 | import net.mikaelzero.mojito.view.sketch.core.datasource.DataSource;
28 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadResult;
29 |
30 |
31 | public class ContentUriModel extends UriModel {
32 |
33 | public static final String SCHEME = "content://";
34 |
35 | @Override
36 | protected boolean match(@NonNull String uri) {
37 | return !TextUtils.isEmpty(uri) && uri.startsWith(SCHEME);
38 | }
39 |
40 | @NonNull
41 | @Override
42 | public DataSource getDataSource(@NonNull Context context, @NonNull String uri, @Nullable DownloadResult downloadResult) {
43 | return new ContentDataSource(context, Uri.parse(uri));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/FileUriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.content.Context;
20 | import android.text.TextUtils;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 |
25 | import net.mikaelzero.mojito.view.sketch.core.datasource.DataSource;
26 | import net.mikaelzero.mojito.view.sketch.core.datasource.FileDataSource;
27 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadResult;
28 |
29 | import java.io.File;
30 |
31 |
32 | public class FileUriModel extends UriModel {
33 |
34 | public static final String SCHEME = "/";
35 |
36 | @Override
37 | protected boolean match(@NonNull String uri) {
38 | return !TextUtils.isEmpty(uri) && uri.startsWith(SCHEME);
39 | }
40 |
41 | @NonNull
42 | @Override
43 | public DataSource getDataSource(@NonNull Context context, @NonNull String uri, @Nullable DownloadResult downloadResult) {
44 | return new FileDataSource(new File(uri));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/GetDataSourceException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | public class GetDataSourceException extends Exception {
22 |
23 | public GetDataSourceException(@NonNull String message) {
24 | super(message);
25 | }
26 |
27 | public GetDataSourceException(@NonNull String message, @NonNull Throwable cause) {
28 | super(message, cause);
29 | }
30 |
31 | public GetDataSourceException(@NonNull Throwable cause) {
32 | super(cause);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/uri/HttpsUriModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.uri;
18 |
19 | import android.text.TextUtils;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 |
24 | public class HttpsUriModel extends HttpUriModel {
25 |
26 | public static final String SCHEME = "https://";
27 |
28 | @Override
29 | protected boolean match(@NonNull String uri) {
30 | return !TextUtils.isEmpty(uri) && uri.startsWith(SCHEME);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/util/KeyCounter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.util;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import java.util.concurrent.atomic.AtomicInteger;
22 |
23 | /**
24 | * Key 计数器
25 | */
26 | public class KeyCounter {
27 | @NonNull
28 | private AtomicInteger number;
29 |
30 | public KeyCounter() {
31 | this.number = new AtomicInteger();
32 | }
33 |
34 | /**
35 | * 刷新 key
36 | */
37 | public void refresh() {
38 | if (number.get() == Integer.MAX_VALUE) {
39 | number.set(0);
40 | } else {
41 | number.addAndGet(1);
42 | }
43 | }
44 |
45 | public int getKey() {
46 | return number.get();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/util/NoSpaceException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
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 net.mikaelzero.mojito.view.sketch.core.util;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | @SuppressWarnings("WeakerAccess")
22 | public class NoSpaceException extends Exception {
23 |
24 | public NoSpaceException(@NonNull String detailMessage) {
25 | super(detailMessage);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/util/UnableCreateDirException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
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 net.mikaelzero.mojito.view.sketch.core.util;
18 |
19 | public class UnableCreateDirException extends Exception {
20 |
21 | public UnableCreateDirException(String detailMessage) {
22 | super(detailMessage);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/util/UnableCreateFileException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
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 net.mikaelzero.mojito.view.sketch.core.util;
18 |
19 | public class UnableCreateFileException extends Exception {
20 |
21 | public UnableCreateFileException(String detailMessage) {
22 | super(detailMessage);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/viewfun/OnClickListenerProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.viewfun;
18 |
19 | import android.view.View;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import java.lang.ref.WeakReference;
24 |
25 |
26 | class OnClickListenerProxy implements View.OnClickListener {
27 | @NonNull
28 | private WeakReference viewWeakReference;
29 |
30 | OnClickListenerProxy(@NonNull FunctionCallbackView view) {
31 | this.viewWeakReference = new WeakReference<>(view);
32 | }
33 |
34 | @Override
35 | public void onClick(@NonNull View v) {
36 | FunctionCallbackView view = viewWeakReference.get();
37 | if (view == null) {
38 | return;
39 | }
40 |
41 |
42 | if (view.wrappedClickListener != null) {
43 | view.wrappedClickListener.onClick(v);
44 | }
45 | }
46 |
47 | boolean isClickable() {
48 | FunctionCallbackView view = viewWeakReference.get();
49 | if (view == null) {
50 | return false;
51 | }
52 |
53 | return view.wrappedClickListener != null;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/viewfun/ProgressListenerProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.viewfun;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import net.mikaelzero.mojito.view.sketch.core.request.DownloadProgressListener;
22 |
23 | import java.lang.ref.WeakReference;
24 |
25 |
26 | class ProgressListenerProxy implements DownloadProgressListener {
27 | @NonNull
28 | private WeakReference viewWeakReference;
29 |
30 | ProgressListenerProxy(@NonNull FunctionCallbackView view) {
31 | this.viewWeakReference = new WeakReference<>(view);
32 | }
33 |
34 | @Override
35 | public void onUpdateDownloadProgress(int totalLength, int completedLength) {
36 | FunctionCallbackView view = viewWeakReference.get();
37 | if (view == null) {
38 | return;
39 | }
40 |
41 | boolean needInvokeInvalidate = view.getFunctions().onUpdateDownloadProgress(totalLength, completedLength);
42 | if (needInvokeInvalidate) {
43 | view.invalidate();
44 | }
45 |
46 | if (view.wrappedProgressListener != null) {
47 | view.wrappedProgressListener.onUpdateDownloadProgress(totalLength, completedLength);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/SketchImageViewLoader/src/main/java/net/mikaelzero/mojito/view/sketch/core/zoom/ZoomScales.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 Peng fei Pan
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 net.mikaelzero.mojito.view.sketch.core.zoom;
18 |
19 | import android.content.Context;
20 | import android.widget.ImageView;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 |
25 |
26 | public interface ZoomScales {
27 |
28 | /**
29 | * 重置
30 | */
31 | void reset(@NonNull final Context context, @NonNull final Sizes sizes, @Nullable final ImageView.ScaleType scaleType, final float rotateDegrees, final boolean readMode);
32 |
33 | /**
34 | * 最小缩放比例
35 | */
36 | float getMinZoomScale();
37 |
38 | /**
39 | * 最大缩放比例
40 | */
41 | float getMaxZoomScale();
42 |
43 | /**
44 | * 最大初始缩放比例
45 | */
46 | float getInitZoomScale();
47 |
48 | /**
49 | * 能够看到图片全貌的缩放比例
50 | */
51 | float getFullZoomScale();
52 |
53 | /**
54 | * 获取能够宽或高能够填满屏幕的缩放比例
55 | */
56 | float getFillZoomScale();
57 |
58 | /**
59 | * 能够让图片按照真实尺寸一比一显示的缩放比例
60 | */
61 | float getOriginZoomScale();
62 |
63 | /**
64 | * 双击缩放所的比例组
65 | */
66 | float[] getZoomScales();
67 |
68 | /**
69 | * 清理一下
70 | */
71 | void clean();
72 | }
73 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import mojito.Library
2 | import mojito.setupAppModule
3 |
4 | plugins {
5 | id("com.android.application")
6 | id("kotlin-android")
7 | id("kotlin-parcelize")
8 | }
9 | setupAppModule {
10 | defaultConfig {
11 | minSdk = 21
12 | applicationId = "net.mikaelzero.app"
13 | multiDexEnabled = true
14 | buildFeatures {
15 | viewBinding = true
16 | }
17 | }
18 | buildTypes {
19 | getByName("release") {
20 | isMinifyEnabled = true
21 | isShrinkResources = true
22 | proguardFiles("proguard-rules.pro")
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 |
29 | implementation(Library.KOTLINX_STDLIB)
30 |
31 | implementation(Library.ANDROIDX_ACTIVITY)
32 | implementation(Library.ANDROIDX_APPCOMPAT)
33 | implementation(Library.ANDROIDX_CONSTRAINT_LAYOUT)
34 | implementation(Library.ANDROIDX_CORE)
35 | implementation(Library.ANDROIDX_LIFECYCLE_VIEW_MODEL)
36 | implementation(Library.ANDROIDX_MULTIDEX)
37 | implementation(Library.ANDROIDX_RECYCLER_VIEW)
38 | implementation(Library.MATERIAL)
39 |
40 | implementation(Library.GLIDE)
41 | implementation(Library.BASE_ADAPTER)
42 | implementation(Library.IMMERSIONBAR)
43 | implementation(Library.SWIPELAYOUT)
44 | implementation(Library.FRESCO)
45 | implementation(Library.ART_PLAY_CORE)
46 | implementation(Library.ART_PLAY_IJK)
47 | implementation(Library.ART_PLAY_V7A)
48 | implementation(Library.COIL)
49 |
50 | implementation(project(":mojito"))
51 | implementation(project(":GlideImageLoader"))
52 | implementation(project(":FrescoImageLoader"))
53 | implementation(project(":SketchImageViewLoader"))
54 | implementation(project(":coilimageloader"))
55 | implementation(project(":PhotoViewImageViewLoader"))
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/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 E:\AndroidDeveloper\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 | -keep public class pl.droidsonroids.gif.GifIOException{(int, java.lang.String);}
19 |
20 | # sketch 就以这两个类是否存在判断是否可以使用 gif
21 | -keep class me.panpf.sketch.gif.BuildConfig
22 | -keep class pl.droidsonroids.gif.GifDrawable
23 | # 只有 SketchGifDrawableImpl 类与 sketch-gif 有联系,因此当缺失 sketch-gif 时 SketchGifDrawableImpl 类在混淆时会发出警告
24 | -dontwarn me.panpf.sketch.drawable.SketchGifDrawableImpl
25 | -dontwarn me.panpf.sketch.drawable.SketchGifDrawableImpl$1
26 |
27 | # 实现了 Initializer 接口的类需要在 AndroidManifest 中配置,然后在运行时实例化,因此不能混淆
28 | -keep public class * implements me.panpf.sketch.Initializer
29 |
30 | -keep class net.mikaelzero.mojito.bean.* {*;}
31 | -keep class net.mikaelzero.mojito.interfaces.* {*;}
--------------------------------------------------------------------------------
/app/src/androidTest/androidTest.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/ActivityCoverActivity.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.recyclerview.widget.GridLayoutManager
7 | import net.mikaelzero.app.databinding.ActivityCoverBinding
8 | import net.mikaelzero.mojito.Mojito
9 | import net.mikaelzero.mojito.impl.DefaultPercentProgress
10 | import net.mikaelzero.mojito.impl.DefaultTargetFragmentCover
11 |
12 | class ActivityCoverActivity : AppCompatActivity() {
13 | var context: Context? = null
14 | private lateinit var binding: ActivityCoverBinding
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | context = this
18 | binding = ActivityCoverBinding.inflate(layoutInflater)
19 | setContentView(binding.root)
20 | binding.recyclerView.layoutManager = GridLayoutManager(this, 3)
21 | val adapter = ImageAdapter()
22 | adapter.setList(SourceUtil.getTargetButtonSmall())
23 | binding.recyclerView.adapter = adapter
24 | adapter.setOnItemClickListener { adapter, view, position ->
25 | Mojito.start(this) {
26 | urls(SourceUtil.getTargetButtonSmall(), SourceUtil.getTargetButtonTarget())
27 | position(position)
28 | views(binding.recyclerView, R.id.srcImageView)
29 | autoLoadTarget(false)
30 | setActivityCoverLoader(BilibiliActivityCoverLoader())
31 | fragmentCoverLoader {
32 | DefaultTargetFragmentCover()
33 | }
34 | progressLoader {
35 | DefaultPercentProgress()
36 | }
37 | }
38 |
39 | }
40 |
41 | }
42 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/App.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | import android.app.Application
4 | import android.content.Context
5 | import androidx.multidex.MultiDex
6 |
7 |
8 | class App : Application() {
9 |
10 | override fun attachBaseContext(base: Context?) {
11 | super.attachBaseContext(base)
12 | MultiDex.install(this)
13 | }
14 |
15 | override fun onCreate() {
16 | super.onCreate()
17 | }
18 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/BilibiliActivityCoverLoader.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | import android.annotation.SuppressLint
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.widget.ImageView
7 | import android.widget.TextView
8 | import net.mikaelzero.mojito.interfaces.ActivityCoverLoader
9 | import net.mikaelzero.mojito.interfaces.IMojitoActivity
10 |
11 | /**
12 | * @Author: MikaelZero
13 | * @CreateDate: 2020/6/17 11:29 AM
14 | * @Description:
15 | */
16 | class BilibiliActivityCoverLoader : ActivityCoverLoader {
17 | lateinit var view: View
18 | var numTv: TextView? = null
19 | override fun attach(context: IMojitoActivity) {
20 | view = LayoutInflater.from(context.getContext()).inflate(R.layout.bilibili_cover_layout, null)
21 | numTv = view.findViewById(R.id.numTv)
22 | val closeIv = view.findViewById(R.id.closeIv)
23 | closeIv.setOnClickListener {
24 | context.getCurrentFragment()?.backToMin()
25 | }
26 | }
27 |
28 | override fun providerView(): View {
29 | return view
30 | }
31 |
32 | override fun move(moveX: Float, moveY: Float) {
33 |
34 | }
35 |
36 | override fun fingerRelease(isToMax: Boolean, isToMin: Boolean) {
37 |
38 | }
39 |
40 | @SuppressLint("SetTextI18n")
41 | override fun pageChange(totalSize: Int, position: Int) {
42 | numTv?.text = (position + 1).toString() + "/" + totalSize
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/DifferentScenesActivity.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.view.LayoutInflater
6 | import androidx.appcompat.app.AppCompatActivity
7 | import androidx.recyclerview.widget.GridLayoutManager
8 | import net.mikaelzero.app.databinding.ActivityDifferentScenesBinding
9 | import net.mikaelzero.mojito.Mojito
10 | import net.mikaelzero.mojito.impl.NumIndicator
11 |
12 | class DifferentScenesActivity : AppCompatActivity() {
13 | var context: Context? = null
14 | private lateinit var binding: ActivityDifferentScenesBinding
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | context = this
18 | binding = ActivityDifferentScenesBinding.inflate(layoutInflater)
19 | setContentView(binding.root)
20 | binding.recyclerView.layoutManager = GridLayoutManager(this, 3)
21 | val adapter = DifferentScenesAdapter()
22 | val list = mutableListOf()
23 | list.add(UrlBean("", 0))
24 | list.add(UrlBean("", 0))
25 | SourceUtil.getNormalImages().forEachIndexed { index, s ->
26 | list.add(UrlBean(s, 1))
27 | }
28 | adapter.setList(list)
29 | binding.recyclerView.adapter = adapter
30 | val newUrls = mutableListOf()
31 | newUrls.add("")
32 | newUrls.add("")
33 | newUrls.addAll(SourceUtil.getNormalImages())
34 | adapter.setOnItemClickListener { _, view, position ->
35 | if (position == 0) {
36 | return@setOnItemClickListener
37 | }
38 | Mojito.start(context) {
39 | urls(newUrls)
40 | position(position, headerSize = adapter.headerLayoutCount, footerSize = adapter.footerLayoutCount)
41 | views(binding.recyclerView, R.id.srcImageView)
42 | setIndicator(NumIndicator())
43 | }
44 |
45 | }
46 | adapter.addHeaderView(LayoutInflater.from(this).inflate(R.layout.header_layout, null))
47 | adapter.addHeaderView(LayoutInflater.from(this).inflate(R.layout.header_layout, null))
48 | adapter.addHeaderView(LayoutInflater.from(this).inflate(R.layout.header_layout, null))
49 | adapter.addFooterView(LayoutInflater.from(this).inflate(R.layout.header_layout, null))
50 | adapter.addFooterView(LayoutInflater.from(this).inflate(R.layout.header_layout, null))
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/DifferentScenesAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | import android.widget.FrameLayout
4 | import com.chad.library.adapter.base.BaseQuickAdapter
5 | import com.chad.library.adapter.base.viewholder.BaseViewHolder
6 | import net.mikaelzero.mojito.tools.ScreenUtils
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2020/6/19 8:43 PM
11 | * @Description:
12 | */
13 | class DifferentScenesAdapter : BaseQuickAdapter(R.layout.item_grid) {
14 | override fun convert(holder: BaseViewHolder, item: UrlBean) {
15 | val srcImageView = holder.getView(R.id.srcImageView)
16 | (srcImageView.layoutParams as FrameLayout.LayoutParams).width = ScreenUtils.getScreenWidth(context) / 3
17 | (srcImageView.layoutParams as FrameLayout.LayoutParams).height = ScreenUtils.getScreenWidth(context) / 3
18 | if (item.type == 1) {
19 | srcImageView.addImg(item.url)
20 | } else {
21 | srcImageView.addImgLocal(R.drawable.good)
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/ImageAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | import android.widget.FrameLayout
4 | import com.chad.library.adapter.base.BaseQuickAdapter
5 | import com.chad.library.adapter.base.viewholder.BaseViewHolder
6 | import net.mikaelzero.mojito.tools.ScreenUtils
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2020/6/19 8:43 PM
11 | * @Description:
12 | */
13 | class ImageAdapter : BaseQuickAdapter(R.layout.item_grid) {
14 | override fun convert(holder: BaseViewHolder, item: String) {
15 | val srcImageView = holder.getView(R.id.srcImageView)
16 | srcImageView.addImg(item)
17 | (srcImageView.layoutParams as FrameLayout.LayoutParams).width = ScreenUtils.getScreenWidth(context) / 3
18 | (srcImageView.layoutParams as FrameLayout.LayoutParams).height = ScreenUtils.getScreenWidth(context) / 3
19 |
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/TargetActivity.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.recyclerview.widget.GridLayoutManager
7 | import net.mikaelzero.app.databinding.ActivityTargetBinding
8 | import net.mikaelzero.mojito.Mojito
9 | import net.mikaelzero.mojito.impl.DefaultPercentProgress
10 | import net.mikaelzero.mojito.impl.DefaultTargetFragmentCover
11 | import net.mikaelzero.mojito.impl.NumIndicator
12 |
13 | class TargetActivity : AppCompatActivity() {
14 | var context: Context? = null
15 | private lateinit var binding: ActivityTargetBinding
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | context = this
19 | binding = ActivityTargetBinding.inflate(layoutInflater)
20 | setContentView(binding.root)
21 | binding.recyclerView.layoutManager = GridLayoutManager(this, 3)
22 | val adapter = ImageAdapter()
23 | adapter.setList(SourceUtil.getTargetButtonSmall())
24 | binding.recyclerView.adapter = adapter
25 | adapter.setOnItemClickListener { adapter, view, position ->
26 | Mojito.start(context) {
27 | urls(SourceUtil.getTargetButtonSmall(), SourceUtil.getTargetButtonTarget())
28 | position(position)
29 | views(binding.recyclerView, R.id.srcImageView)
30 | autoLoadTarget(false)
31 | fragmentCoverLoader {
32 | DefaultTargetFragmentCover()
33 | }
34 | progressLoader {
35 | DefaultPercentProgress()
36 | }
37 | setIndicator(NumIndicator())
38 | }
39 |
40 | }
41 |
42 | }
43 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/UrlBean.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app
2 |
3 | /**
4 | * @Author: MikaelZero
5 | * @CreateDate: 2/20/21 3:18 PM
6 | * @Description:
7 | */
8 | // 0 为添加 1为图片
9 | data class UrlBean(val url:String,val type:Int)
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/local/LocalImageAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app.local
2 |
3 | import android.widget.FrameLayout
4 | import com.chad.library.adapter.base.BaseQuickAdapter
5 | import com.chad.library.adapter.base.viewholder.BaseViewHolder
6 | import net.mikaelzero.app.R
7 | import net.mikaelzero.app.addImgLocal
8 | import net.mikaelzero.mojito.tools.ScreenUtils
9 |
10 | /**
11 | * @Author: MikaelZero
12 | * @CreateDate: 2020/6/19 5:19 PM
13 | * @Description:
14 | */
15 | class LocalImageAdapter : BaseQuickAdapter(R.layout.item_local) {
16 | override fun convert(holder: BaseViewHolder, item: String) {
17 | val srcImageView = holder.getView(R.id.srcImageView)
18 | (srcImageView.layoutParams as FrameLayout.LayoutParams).width = ScreenUtils.getScreenWidth(context) / 3
19 | (srcImageView.layoutParams as FrameLayout.LayoutParams).height = ScreenUtils.getScreenWidth(context) / 3
20 | srcImageView.addImgLocal(item)
21 | }
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/stagger/StaggerActivity.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app.stagger
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.recyclerview.widget.StaggeredGridLayoutManager
6 | import net.mikaelzero.app.R
7 | import net.mikaelzero.app.SourceUtil
8 | import net.mikaelzero.app.databinding.ActivityStaggerBinding
9 | import net.mikaelzero.mojito.Mojito
10 |
11 | /**
12 | * @Author: MikaelZero
13 | * @CreateDate: 2020/6/22 8:38 PM
14 | * @Description:
15 | */
16 | class StaggerActivity : AppCompatActivity() {
17 | private lateinit var binding: ActivityStaggerBinding
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | binding = ActivityStaggerBinding.inflate(layoutInflater)
21 | setContentView(binding.root)
22 | binding.recyclerView.layoutManager = StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)
23 | val adapter = StaggerAdapter()
24 | binding.recyclerView.adapter = adapter
25 | adapter.setList(SourceUtil.getNormalImages())
26 | adapter.setOnItemClickListener { adapter, view, position ->
27 | Mojito.start(this) {
28 | urls(SourceUtil.getNormalImages())
29 | position(position)
30 | views(binding.recyclerView, R.id.srcImageView)
31 | }
32 |
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/stagger/StaggerAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app.stagger
2 |
3 | import android.widget.FrameLayout
4 | import android.widget.LinearLayout
5 | import com.chad.library.adapter.base.BaseQuickAdapter
6 | import com.chad.library.adapter.base.viewholder.BaseViewHolder
7 | import net.mikaelzero.app.R
8 | import net.mikaelzero.app.addImg
9 | import net.mikaelzero.mojito.tools.ScreenUtils
10 | import kotlin.random.Random
11 |
12 | /**
13 | * @Author: MikaelZero
14 | * @CreateDate: 2020/6/19 5:19 PM
15 | * @Description:
16 | */
17 | class StaggerAdapter : BaseQuickAdapter(R.layout.item_stagger) {
18 | override fun convert(holder: BaseViewHolder, item: String) {
19 | val srcImageView = holder.getView(R.id.srcImageView)
20 | (srcImageView.layoutParams as LinearLayout.LayoutParams).width = ScreenUtils.getScreenWidth(context) / 3
21 | (srcImageView.layoutParams as LinearLayout.LayoutParams).height = getRandomIntInRange(900, 200)
22 | srcImageView.addImg(item)
23 | }
24 |
25 | fun getRandomIntInRange(max: Int, min: Int): Int {
26 | return Random.nextInt(max - min + min) + min
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/video/ArtLoadFactory.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app.video;
2 |
3 | import android.net.Uri;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 |
7 | import net.mikaelzero.mojito.interfaces.ImageViewLoadFactory;
8 | import net.mikaelzero.mojito.loader.ContentLoader;
9 |
10 | import org.jetbrains.annotations.NotNull;
11 |
12 |
13 | public class ArtLoadFactory implements ImageViewLoadFactory {
14 | @Override
15 | public void loadSillContent(@NotNull View view, @NotNull Uri uri) {
16 | if (view instanceof ImageView) {
17 | ((ImageView) view).setImageURI(uri);
18 | }
19 | }
20 |
21 | @Override
22 | public void loadContentFail(@NotNull View view, int drawableResId) {
23 | if (view instanceof ImageView) {
24 | ((ImageView) view).setImageResource(drawableResId);
25 | }
26 | }
27 |
28 | @NotNull
29 | @Override
30 | public ContentLoader newContentLoader() {
31 | return new ArtplayerLoadImpl();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/net/mikaelzero/app/video/HackVideoView.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.app.video;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import org.jetbrains.annotations.NotNull;
7 | import org.jetbrains.annotations.Nullable;
8 | import org.salient.artplayer.conduction.ScaleType;
9 | import org.salient.artplayer.ui.ResizeTextureView;
10 | import org.salient.artplayer.ui.VideoView;
11 |
12 | import java.lang.reflect.Field;
13 |
14 | /**
15 | * @Author: MikaelZero
16 | * @CreateDate: 2020/6/22 3:29 PM
17 | * @Description:
18 | */
19 | public class HackVideoView extends VideoView {
20 | ResizeTextureView resizeTextureView;
21 |
22 | public HackVideoView(@NotNull Context context) {
23 | super(context);
24 | }
25 |
26 | public HackVideoView(@NotNull Context context, @Nullable AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | public HackVideoView(@NotNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | }
33 |
34 | void setScreenScale(ScaleType type) {
35 | if (resizeTextureView == null) {
36 | Field privateStringField = null;
37 | try {
38 | privateStringField = VideoView.class.getDeclaredField("textureView");
39 | privateStringField.setAccessible(true);
40 | resizeTextureView = (ResizeTextureView) privateStringField.get(this);
41 | } catch (NoSuchFieldException | IllegalAccessException e) {
42 | e.printStackTrace();
43 | }
44 | }
45 | if (resizeTextureView != null) {
46 | resizeTextureView.setScreenScale(type);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/drawable/close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/drawable/comment.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/good.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/drawable/good.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_near_me_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/item_bg.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/drawable/item_bg.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/drawable/more.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/trans.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/drawable/trans.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_cover.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_different_scenes.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_display.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
15 |
16 |
21 |
22 |
27 |
28 |
33 |
34 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_local.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_stagger.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_target.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_video.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/header_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_grid_fresco.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_local.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_local_fresco.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_stagger.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/video_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00F5B1
4 | #00F5B1
5 | #00F5B1
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | mojito
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/test/test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | buildscript {
2 | apply(from = "buildSrc/plugins.gradle.kts")
3 | repositories {
4 | mavenCentral()
5 | google()
6 | maven("https://jitpack.io")
7 | maven("https://oss.sonatype.org/content/repositories/public")
8 | gradlePluginPortal()
9 | }
10 | dependencies {
11 | classpath(rootProject.extra["androidPlugin"].toString())
12 | classpath(rootProject.extra["kotlinPlugin"].toString())
13 | classpath(rootProject.extra["mavenPublishPlugin"].toString())
14 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
15 | }
16 | }
17 | tasks.register(name = "clean") {
18 | group = "build"
19 | delete(rootProject.buildDir)
20 | }
21 | allprojects {
22 | repositories {
23 | mavenCentral()
24 | google()
25 | maven("https://jitpack.io")
26 | maven("https://oss.sonatype.org/content/repositories/public")
27 | gradlePluginPortal()
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl`
3 | }
4 |
5 | repositories {
6 | google()
7 | mavenCentral()
8 | }
9 |
10 | apply(from = "plugins.gradle.kts")
11 |
12 | dependencies {
13 | implementation(rootProject.extra["androidPlugin"].toString())
14 | implementation(rootProject.extra["kotlinPlugin"].toString())
15 | }
16 |
--------------------------------------------------------------------------------
/buildSrc/plugins.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.extra.apply {
2 | set("androidPlugin", "com.android.tools.build:gradle:4.2.2")
3 | set("kotlinPlugin", "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
4 | set("mavenPublishPlugin", "com.github.dcendents:android-maven-gradle-plugin:2.1")
5 | }
6 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/Projects.kt:
--------------------------------------------------------------------------------
1 | package mojito
2 |
3 | import com.android.build.gradle.BaseExtension
4 | import com.android.build.gradle.LibraryExtension
5 | import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
6 | import org.gradle.api.JavaVersion
7 | import org.gradle.api.Project
8 | import org.gradle.api.plugins.ExtensionAware
9 | import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
10 |
11 | fun Project.setupLibraryModule(block: LibraryExtension.() -> Unit = {}) {
12 | setupBaseModule {
13 | libraryVariants.all {
14 | generateBuildConfigProvider?.configure { enabled = false }
15 | }
16 | testOptions {
17 | unitTests.isIncludeAndroidResources = true
18 | }
19 | block()
20 | }
21 | }
22 |
23 | fun Project.setupAppModule(block: BaseAppModuleExtension.() -> Unit = {}) {
24 | setupBaseModule {
25 | defaultConfig {
26 | versionCode = project.versionCode
27 | versionName = project.versionName
28 | vectorDrawables.useSupportLibrary = true
29 | }
30 | block()
31 | }
32 | }
33 |
34 | private inline fun Project.setupBaseModule(crossinline block: T.() -> Unit = {}) {
35 | extensions.configure("android") {
36 | compileSdkVersion(project.compileSdk)
37 | defaultConfig {
38 | minSdk = project.minSdk
39 | targetSdk = project.targetSdk
40 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
41 | }
42 | compileOptions {
43 | sourceCompatibility = JavaVersion.VERSION_1_8
44 | targetCompatibility = JavaVersion.VERSION_1_8
45 | }
46 | kotlinOptions {
47 | jvmTarget = "1.8"
48 | }
49 | (this as T).block()
50 | }
51 | }
52 |
53 | private fun BaseExtension.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
54 | (this as ExtensionAware).extensions.configure("kotlinOptions", block)
55 | }
56 |
--------------------------------------------------------------------------------
/coilimageloader/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/coilimageloader/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import mojito.setupLibraryModule
2 |
3 | plugins {
4 | id("com.android.library")
5 | id("kotlin-android")
6 | id("com.github.dcendents.android-maven")
7 | }
8 |
9 | group = "com.github.mikaelzero"
10 | setupLibraryModule {
11 | defaultConfig {
12 | minSdk = 16
13 | }
14 | }
15 |
16 | dependencies {
17 | implementation(mojito.Library.KOTLINX_STDLIB)
18 | implementation(mojito.Library.ANDROIDX_APPCOMPAT)
19 | implementation(mojito.Library.ANDROIDX_CORE)
20 | implementation(mojito.Library.OKHTTP)
21 | implementation(mojito.Library.COIL)
22 | implementation("io.coil-kt:coil-base:2.1.0")
23 | implementation("io.coil-kt:coil-gif:2.1.0")
24 | implementation("io.coil-kt:coil-svg:2.1.0")
25 | implementation(project(":mojito"))
26 | }
27 |
--------------------------------------------------------------------------------
/coilimageloader/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/coilimageloader/src/androidTest/java/net/mikaelzero/coilimageloader/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.coilimageloader
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("net.mikaelzero.coilimageloader", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/coilimageloader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/coilimageloader/src/main/java/net/mikaelzero/coilimageloader/CoilLoaderException.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.coilimageloader
2 |
3 | import android.graphics.drawable.Drawable
4 |
5 | class CoilLoaderException(val errorDrawable: Drawable?) : RuntimeException()
--------------------------------------------------------------------------------
/coilimageloader/src/main/java/net/mikaelzero/coilimageloader/ImageDownloadTarget.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.coilimageloader
2 |
3 | import android.graphics.drawable.Drawable
4 | import net.mikaelzero.coilimageloader.ProgressSupport.expect
5 | import net.mikaelzero.coilimageloader.ProgressSupport.forget
6 |
7 |
8 | abstract class ImageDownloadTarget constructor(private val mUrl: String) : coil.target.Target, ProgressSupport.ProgressListener {
9 |
10 | override fun onError(error: Drawable?) {
11 | super.onError(error)
12 | forget(mUrl)
13 | }
14 |
15 | override fun onStart(placeholder: Drawable?) {
16 | super.onStart(placeholder)
17 | expect(mUrl, this)
18 | }
19 |
20 | override fun onSuccess(result: Drawable) {
21 | super.onSuccess(result)
22 | forget(mUrl)
23 | }
24 |
25 |
26 | }
--------------------------------------------------------------------------------
/coilimageloader/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/coilimageloader/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/coilimageloader/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CoilImageLoader
3 |
--------------------------------------------------------------------------------
/coilimageloader/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/coilimageloader/src/test/java/net/mikaelzero/coilimageloader/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.coilimageloader
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | android.useAndroidX=true
15 | # Automatically convert third-party libraries to use AndroidX
16 | android.enableJetifier=true
17 | # Kotlin code style for this project: "official" or "obsolete":
18 | kotlin.code.style=official
19 | # Config
20 | minSdk=16
21 | targetSdk=31
22 | compileSdk=31
23 | # Maven
24 | GROUP=com.github.mikaelzero
25 | VERSION_NAME=1.8.3
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikaelzero/mojito/3d773f3e9236e6816a5bbbace318c6a87c7f89f2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jun 16 13:47:58 CST 2020
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-6.7.1-all.zip
7 |
--------------------------------------------------------------------------------
/mojito/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import mojito.setupLibraryModule
2 |
3 | plugins {
4 | id("com.android.library")
5 | id("kotlin-android")
6 | id("kotlin-parcelize")
7 | id("com.github.dcendents.android-maven")
8 | }
9 |
10 | group = "com.github.mikaelzero"
11 | setupLibraryModule {
12 | defaultConfig {
13 | minSdk = 16
14 | buildFeatures {
15 | viewBinding = true
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation(mojito.Library.ANDROIDX_APPCOMPAT)
22 | implementation(mojito.Library.ANDROIDX_CORE)
23 | implementation(mojito.Library.ANDROIDX_RECYCLER_VIEW)
24 | implementation(mojito.Library.KOTLINX_STDLIB)
25 | implementation(mojito.Library.IMMERSIONBAR)
26 | implementation("androidx.exifinterface:exifinterface:1.3.3")
27 | implementation("androidx.viewpager2:viewpager2:1.0.0")
28 | }
29 |
--------------------------------------------------------------------------------
/mojito/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 E:\AndroidDeveloper\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 | -keep public class pl.droidsonroids.gif.GifIOException{(int, java.lang.String);}
19 |
20 | # sketch 就以这两个类是否存在判断是否可以使用 gif
21 | -keep class me.panpf.sketch.gif.BuildConfig
22 | -keep class pl.droidsonroids.gif.GifDrawable
23 | # 只有 SketchGifDrawableImpl 类与 sketch-gif 有联系,因此当缺失 sketch-gif 时 SketchGifDrawableImpl 类在混淆时会发出警告
24 | -dontwarn me.panpf.sketch.drawable.SketchGifDrawableImpl
25 | -dontwarn me.panpf.sketch.drawable.SketchGifDrawableImpl$1
26 |
27 | # 实现了 Initializer 接口的类需要在 AndroidManifest 中配置,然后在运行时实例化,因此不能混淆
28 | -keep public class * implements me.panpf.sketch.Initializer
29 |
30 | -keep class net.mikaelzero.mojito.bean.* {*;}
31 | -keep class net.mikaelzero.mojito.interfaces.* {*;}
--------------------------------------------------------------------------------
/mojito/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/MojitoLoader.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito
2 |
3 | import android.net.Uri
4 | import net.mikaelzero.mojito.interfaces.IMojitoConfig
5 | import net.mikaelzero.mojito.interfaces.ImageViewLoadFactory
6 | import net.mikaelzero.mojito.loader.ImageLoader
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2020/6/22 9:43 PM
11 | * @Description:
12 | */
13 | class MojitoLoader {
14 | private object SingletonHolder {
15 | val holder = MojitoLoader()
16 | }
17 |
18 | companion object {
19 | val instance = SingletonHolder.holder
20 |
21 | @JvmStatic
22 | fun prefetch(vararg uris: Uri?) {
23 | val imageLoader = Mojito.imageLoader()
24 | for (uri in uris) {
25 | imageLoader?.prefetch(uri)
26 | }
27 | }
28 |
29 | @JvmStatic
30 | fun prefetch(vararg uris: String?) {
31 | val imageLoader = Mojito.imageLoader()
32 | for (uri in uris) {
33 | imageLoader?.prefetch(Uri.parse(uri))
34 | }
35 | }
36 | }
37 |
38 | var mImageLoader: ImageLoader? = null
39 | var imageViewLoadFactory: ImageViewLoadFactory? = null
40 | var mojitoConfig: IMojitoConfig? = null
41 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/bean/ActivityConfig.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.bean
2 |
3 | import android.os.Parcelable
4 | import kotlinx.parcelize.Parcelize
5 |
6 | @Parcelize
7 | data class ActivityConfig(
8 | var originImageUrls: List? = null,
9 | var targetImageUrls: List? = null,
10 | var viewParams: List? = null,
11 | var position: Int = 0,
12 | var headerSize: Int = 0,
13 | var footerSize: Int = 0,
14 | var autoLoadTarget: Boolean = true,
15 | var errorDrawableResIdList: HashMap = hashMapOf()
16 | ) : Parcelable
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/bean/FragmentConfig.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.bean
2 |
3 | import android.os.Parcelable
4 | import kotlinx.parcelize.Parcelize
5 |
6 | /**
7 | * @Author: MikaelZero
8 | * @CreateDate: 2020/6/23 10:06 AM
9 | * @Description:
10 | */
11 | @Parcelize
12 | data class FragmentConfig(
13 | var originUrl: String,
14 | var targetUrl: String? = null,
15 | var viewParams: ViewParams? = null,
16 | var position: Int,
17 | var autoLoadTarget: Boolean = true,
18 | var showImmediately: Boolean,
19 | var errorDrawableResId: Int = 0
20 | ) : Parcelable
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/bean/ViewPagerBean.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.bean
2 |
3 | /**
4 | * @Author: MikaelZero
5 | * @CreateDate: 2020/6/12 7:16 PM
6 | * @Description:
7 | */
8 | data class ViewPagerBean(
9 | val url: String,
10 | val targetUrl: String? = null,
11 | val position: Int,
12 | val showImmediately: Boolean,
13 | val viewParams: ViewParams? = null
14 | )
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/bean/ViewParams.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.bean;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | public class ViewParams implements Parcelable {
7 | public int left;
8 | public int top;
9 | public int width;
10 | public int height;
11 |
12 | public int getLeft() {
13 | return left;
14 | }
15 |
16 | public void setLeft(int left) {
17 | this.left = left;
18 | }
19 |
20 | public int getTop() {
21 | return top;
22 | }
23 |
24 | public void setTop(int top) {
25 | this.top = top;
26 | }
27 |
28 | public int getWidth() {
29 | return width;
30 | }
31 |
32 | public void setWidth(int width) {
33 | this.width = width;
34 | }
35 |
36 | public int getHeight() {
37 | return height;
38 | }
39 |
40 | public void setHeight(int height) {
41 | this.height = height;
42 | }
43 |
44 | @Override
45 | public int describeContents() {
46 | return 0;
47 | }
48 |
49 | @Override
50 | public void writeToParcel(Parcel dest, int flags) {
51 | dest.writeInt(this.left);
52 | dest.writeInt(this.top);
53 | dest.writeInt(this.width);
54 | dest.writeInt(this.height);
55 | }
56 |
57 | public ViewParams() {
58 | }
59 |
60 | protected ViewParams(Parcel in) {
61 | this.left = in.readInt();
62 | this.top = in.readInt();
63 | this.width = in.readInt();
64 | this.height = in.readInt();
65 | }
66 |
67 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
68 | @Override
69 | public ViewParams createFromParcel(Parcel source) {
70 | return new ViewParams(source);
71 | }
72 |
73 | @Override
74 | public ViewParams[] newArray(int size) {
75 | return new ViewParams[size];
76 | }
77 | };
78 | }
79 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/ext/MojitoViewExt.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.ext
2 |
3 | import android.view.View
4 | import androidx.recyclerview.widget.RecyclerView
5 | import net.mikaelzero.mojito.Mojito
6 | import net.mikaelzero.mojito.MojitoBuilder
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2021/7/30 9:45 上午
11 | * @Description:
12 | */
13 |
14 | fun RecyclerView.mojito(itemId: Int, builder: MojitoBuilder.() -> Unit = {}) {
15 | Mojito.start(this.context) {
16 | apply(
17 | builder.apply {
18 | views(this@mojito, itemId)
19 | }
20 | )
21 | }
22 | }
23 |
24 | fun View.mojito(url: String, builder: MojitoBuilder.() -> Unit = {}) {
25 | Mojito.start(this.context) {
26 | apply(
27 | builder.apply {
28 | urls(url)
29 | views(this@mojito)
30 | }
31 | )
32 |
33 | }
34 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/impl/DefaultMojitoConfig.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.impl
2 |
3 | import net.mikaelzero.mojito.interfaces.IMojitoConfig
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/14 8:58 PM
8 | * @Description:
9 | */
10 | open class DefaultMojitoConfig : IMojitoConfig {
11 | override fun duration(): Long = 250
12 | override fun maxTransYRatio(): Float = 0.16f
13 | override fun errorDrawableResId(): Int = 0
14 | override fun transparentNavigationBar(): Boolean = true
15 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/impl/DefaultPercentProgress.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.impl;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 | import android.util.SparseArray;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.widget.FrameLayout;
9 |
10 | import net.mikaelzero.mojito.interfaces.IProgress;
11 |
12 | /**
13 | * Created by mikaelzero.
14 | * Date: 2018/10/17
15 | * 进度加载
16 | */
17 | public class DefaultPercentProgress implements IProgress {
18 | LoadingView loadingView;
19 |
20 | @Override
21 | public void attach(int position, FrameLayout parent) {
22 | if (parent == null) {
23 | return;
24 | }
25 | Context context = parent.getContext();
26 | int progressSize = LoadingView.dip2Px(context, 50);
27 | FrameLayout.LayoutParams progressLp = new FrameLayout.LayoutParams(progressSize, progressSize);
28 | progressLp.gravity = Gravity.CENTER;
29 | loadingView = new LoadingView(context);
30 | loadingView.setLayoutParams(progressLp);
31 | parent.addView(loadingView);
32 | }
33 |
34 | @Override
35 | public void onStart(int position) {
36 |
37 | }
38 |
39 | @Override
40 | public void onProgress(int position, int progress) {
41 | if (loadingView != null) {
42 | loadingView.setProgress(progress);
43 | }
44 | }
45 |
46 | @Override
47 | public void onFinish(int position) {
48 | if (loadingView != null) {
49 | loadingView.loadCompleted();
50 | }
51 | }
52 |
53 | @Override
54 | public void onFailed(int position) {
55 | if (loadingView != null) {
56 | loadingView.loadFaild();
57 | }
58 | }
59 |
60 | @Override
61 | public View getProgressView(int position) {
62 | return null;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/impl/SimpleMojitoViewCallback.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.impl
2 |
3 | import android.view.View
4 | import androidx.fragment.app.FragmentActivity
5 | import net.mikaelzero.mojito.MojitoView
6 | import net.mikaelzero.mojito.interfaces.OnMojitoListener
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2020/6/17 1:44 PM
11 | * @Description:
12 | */
13 | abstract class SimpleMojitoViewCallback : OnMojitoListener {
14 | override fun onStartAnim(position: Int) {
15 |
16 | }
17 | override fun onClick(view: View, x: Float, y: Float, position: Int) {
18 |
19 | }
20 |
21 | override fun onLongClick(fragmentActivity: FragmentActivity?, view: View, x: Float, y: Float, position: Int) {
22 | }
23 |
24 | override fun onShowFinish(mojitoView: MojitoView, showImmediately: Boolean) {
25 | }
26 |
27 | override fun onMojitoViewFinish(pagePosition:Int) {
28 | }
29 |
30 | override fun onDrag(view: MojitoView, moveX: Float, moveY: Float) {
31 | }
32 |
33 | override fun onLongImageMove(ratio: Float) {
34 | }
35 |
36 | override fun onViewPageSelected(position: Int) {
37 |
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/ActivityCoverLoader.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces
2 |
3 | import android.view.View
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/17 11:19 AM
8 | * @Description: 仅出现在activity
9 | */
10 | interface ActivityCoverLoader {
11 | fun attach(context: IMojitoActivity)
12 | fun providerView(): View
13 |
14 | /**
15 | * 拖动的时候 移动的 X 和 Y 距离
16 | */
17 | fun move(moveX: Float, moveY: Float)
18 |
19 | /**
20 | * 手指松开后的状态
21 | */
22 | fun fingerRelease(isToMax: Boolean, isToMin: Boolean)
23 | fun pageChange(totalSize: Int, position: Int)
24 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/IIndicator.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces;
2 |
3 | import android.widget.FrameLayout;
4 |
5 | import androidx.viewpager.widget.ViewPager;
6 | import androidx.viewpager2.widget.ViewPager2;
7 |
8 | public interface IIndicator {
9 |
10 | void attach(FrameLayout parent);
11 |
12 | void onShow(ViewPager viewPager);
13 |
14 | /**
15 | * 拖动的时候 移动的 X 和 Y 距离
16 | */
17 | void move(float moveX, float moveY);
18 |
19 | /**
20 | * 手指松开后的状态
21 | */
22 | void fingerRelease(boolean isToMax, boolean isToMin);
23 | }
24 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/IMojitoActivity.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces
2 |
3 | import android.content.Context
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/17 3:26 PM
8 | * @Description:
9 | */
10 | interface IMojitoActivity {
11 | fun getCurrentFragment(): IMojitoFragment?
12 | fun getContext():Context
13 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/IMojitoConfig.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces
2 |
3 |
4 | /**
5 | * @Author: MikaelZero
6 | * @CreateDate: 2020/6/14 8:54 PM
7 | * @Description:
8 | */
9 | interface IMojitoConfig {
10 | fun duration(): Long
11 | fun maxTransYRatio(): Float
12 | fun errorDrawableResId(): Int
13 | fun transparentNavigationBar():Boolean
14 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/IMojitoFragment.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces
2 |
3 | import androidx.fragment.app.Fragment
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/17 1:25 PM
8 | * @Description:
9 | */
10 | interface IMojitoFragment {
11 | fun providerContext(): Fragment?
12 | fun loadTargetUrl()
13 | fun backToMin()
14 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/IProgress.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces;
2 |
3 | import android.view.View;
4 | import android.widget.FrameLayout;
5 |
6 | public interface IProgress {
7 |
8 | void attach(int position, FrameLayout parent);
9 |
10 | void onStart(int position);
11 |
12 | void onProgress(int position, int progress);
13 |
14 | void onFinish(int position);
15 |
16 | void onFailed(int position);
17 |
18 | View getProgressView(int position);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/ImageViewLoadFactory.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces
2 |
3 | import android.net.Uri
4 | import android.view.View
5 | import androidx.annotation.DrawableRes
6 | import net.mikaelzero.mojito.loader.ContentLoader
7 |
8 | interface ImageViewLoadFactory {
9 | fun loadSillContent(view: View, uri: Uri)
10 | fun loadContentFail(view: View, @DrawableRes drawableResId: Int)
11 | fun newContentLoader(): ContentLoader
12 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/OnMojitoListener.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces
2 |
3 | import android.view.View
4 | import androidx.fragment.app.FragmentActivity
5 | import net.mikaelzero.mojito.MojitoView
6 |
7 | /**
8 | * @Author: MikaelZero
9 | * @CreateDate: 2020/6/17 1:39 PM
10 | * @Description:
11 | */
12 | interface OnMojitoListener {
13 | fun onStartAnim(position: Int)
14 | fun onClick(view: View, x: Float, y: Float, position: Int)
15 | fun onLongClick(fragmentActivity: FragmentActivity?, view: View, x: Float, y: Float, position: Int)
16 | fun onShowFinish(mojitoView: MojitoView, showImmediately: Boolean)
17 | fun onMojitoViewFinish(pagePosition: Int)
18 | fun onDrag(view: MojitoView, moveX: Float, moveY: Float)
19 | fun onLongImageMove(ratio: Float)
20 | fun onViewPageSelected(position: Int)
21 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/interfaces/OnMojitoViewCallback.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.interfaces;
2 |
3 | import net.mikaelzero.mojito.MojitoView;
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/17 1:33 PM
8 | * @Description:
9 | */
10 | public interface OnMojitoViewCallback {
11 | void onDrag(MojitoView view, float moveX, float moveY);
12 |
13 | void showFinish(MojitoView mojitoView, boolean showImmediately);
14 |
15 | void onMojitoViewFinish();
16 |
17 | void onRelease(boolean isToMax, boolean isToMin);
18 |
19 | void onLock(boolean isLock);
20 |
21 | void onLongImageMove(float ratio);
22 | }
23 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/ContentLoader.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader
2 |
3 | import android.content.Context
4 | import android.graphics.RectF
5 | import android.view.View
6 | import net.mikaelzero.mojito.interfaces.OnMojitoViewCallback
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2020/6/10 9:54 AM
11 | * @Description:
12 | */
13 | interface ContentLoader {
14 | val displayRect: RectF
15 | fun init(context: Context, originUrl:String,targetUrl: String?,onMojitoViewCallback: OnMojitoViewCallback?)
16 | fun providerView(): View
17 | fun providerRealView(): View
18 | fun dispatchTouchEvent(isDrag: Boolean, isActionUp: Boolean, isDown: Boolean, isHorizontal: Boolean): Boolean
19 | fun dragging(width: Int, height: Int, ratio: Float)
20 | fun beginBackToMin(isResetSize: Boolean)
21 | fun backToNormal()
22 | fun loadAnimFinish()
23 | fun needReBuildSize(): Boolean
24 | fun useTransitionApi(): Boolean
25 | fun isLongImage(width: Int, height: Int): Boolean
26 | fun onTapCallback(onTapCallback: OnTapCallback)
27 | fun onLongTapCallback(onLongTapCallback: OnLongTapCallback)
28 | fun pageChange(isHidden: Boolean)
29 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/DefaultImageCallback.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/9 8:41 PM
8 | * @Description:
9 | */
10 | public class DefaultImageCallback implements ImageLoader.Callback {
11 |
12 | @Override
13 | public void onStart() {
14 |
15 | }
16 |
17 | @Override
18 | public void onProgress(int progress) {
19 |
20 | }
21 |
22 | @Override
23 | public void onFinish() {
24 |
25 | }
26 |
27 | @Override
28 | public void onSuccess(File image) {
29 |
30 | }
31 |
32 | @Override
33 | public void onFail(Exception error) {
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/FragmentCoverLoader.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader
2 |
3 | import android.view.View
4 | import net.mikaelzero.mojito.interfaces.IMojitoFragment
5 |
6 | /**
7 | * @Author: MikaelZero
8 | * @CreateDate: 2020/6/18 10:54 AM
9 | * @Description: 每个fragment都会出现
10 | */
11 | interface FragmentCoverLoader {
12 | //对于查看原图的情况 如果 autoLoadTarget 为 true 需要对view进行隐藏
13 | fun attach(iMojitoFragment: IMojitoFragment, autoLoadTarget: Boolean): View?
14 | //对于查看原图的情况 如果hasTargetUrl为false代表没有设置目标url 则编写cover类时需要隐藏查看原图功能
15 | fun imageCacheHandle(isCache: Boolean,hasTargetUrl:Boolean)
16 |
17 | /**
18 | * 拖动的时候 移动的 X 和 Y 距离
19 | */
20 | fun move(moveX: Float, moveY: Float)
21 |
22 | /**
23 | * 手指松开后的状态
24 | */
25 | fun fingerRelease(isToMax: Boolean, isToMin: Boolean)
26 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader;
2 |
3 | import android.net.Uri;
4 |
5 | import androidx.annotation.UiThread;
6 |
7 | import java.io.File;
8 |
9 | public interface ImageLoader {
10 |
11 | void loadImage(int requestId, Uri uri, boolean onlyRetrieveFromCache,Callback callback);
12 |
13 | void prefetch(Uri uri);
14 |
15 | void cancel(int requestId);
16 |
17 | void cancelAll();
18 |
19 | void cleanCache();
20 |
21 | @UiThread
22 | interface Callback {
23 |
24 | void onStart();
25 |
26 | void onProgress(int progress);
27 |
28 | void onFinish();
29 |
30 | void onSuccess(File image);
31 |
32 | void onFail(Exception error);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/InstanceLoader.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader
2 |
3 | /**
4 | * @Author: MikaelZero
5 | * @CreateDate: 2020/6/18 9:45 AM
6 | * @Description:
7 | */
8 | interface InstanceLoader {
9 | fun providerInstance(): T
10 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/MultiContentLoader.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader
2 |
3 | import net.mikaelzero.mojito.interfaces.ImageViewLoadFactory
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/22 5:16 PM
8 | * @Description:
9 | */
10 | interface MultiContentLoader {
11 | fun providerLoader(position: Int): ImageViewLoadFactory
12 | fun providerEnableTargetLoad(position: Int): Boolean
13 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/OnLongTapCallback.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader
2 |
3 | import android.view.View
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/15 10:35 AM
8 | * @Description:
9 | */
10 | interface OnLongTapCallback {
11 | fun onLongTap(view: View, x: Float, y: Float)
12 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/loader/OnTapCallback.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.loader
2 |
3 | import android.view.View
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/15 10:35 AM
8 | * @Description:
9 | */
10 | interface OnTapCallback {
11 | fun onTap(view: View,x:Float,y:Float)
12 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/BitmapUtil.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.tools
2 |
3 | import android.graphics.BitmapFactory
4 | import androidx.exifinterface.media.ExifInterface
5 |
6 | /**
7 | * @Author: MikaelZero
8 | * @CreateDate: 2020/6/18 1:19 PM
9 | * @Description:
10 | */
11 | class BitmapUtil {
12 | companion object {
13 |
14 | private fun getImageOrientation(sourcePath: String): Int {
15 | return try {
16 | val exifInfo = ExifInterface(sourcePath)
17 | exifInfo.getAttributeInt(
18 | ExifInterface.TAG_ORIENTATION,
19 | ExifInterface.ORIENTATION_UNDEFINED
20 | )
21 | } catch (ignored: Exception) {
22 | ExifInterface.ORIENTATION_UNDEFINED
23 | }
24 | }
25 |
26 | fun getAdjustSize(sourcePath: String, option: BitmapFactory.Options): Array {
27 | return when (getImageOrientation(sourcePath)) {
28 | ExifInterface.ORIENTATION_ROTATE_90,
29 | ExifInterface.ORIENTATION_TRANSPOSE -> {
30 | //90
31 | arrayOf(option.outHeight, option.outWidth)
32 | }
33 | ExifInterface.ORIENTATION_ROTATE_270,
34 | ExifInterface.ORIENTATION_TRANSVERSE -> {
35 | //-90
36 | arrayOf(option.outHeight, option.outWidth)
37 | }
38 | else -> {
39 | arrayOf(option.outWidth, option.outHeight)
40 | }
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/CommonExt.kt:
--------------------------------------------------------------------------------
1 | @file:JvmName("CommonExt")
2 |
3 | package net.mikaelzero.mojito.tools
4 |
5 | import android.app.Activity
6 | import android.content.Context
7 | import android.content.ContextWrapper
8 | import android.view.View
9 |
10 | fun Context?.dp2px(dp: Int): Int {
11 | if (this == null) {
12 | return 0
13 | }
14 | val scale = resources.displayMetrics.density
15 | return (dp * scale + 0.5f).toInt()
16 | }
17 |
18 | fun Context?.dp2px(dp: Float): Int {
19 | if (this == null) {
20 | return 0
21 | }
22 | val scale = resources.displayMetrics.density
23 | return (dp * scale + 0.5f).toInt()
24 | }
25 |
26 | fun Context?.px2dp(px: Int): Int {
27 | if (this == null) {
28 | return 0
29 | }
30 | val scale = resources.displayMetrics.density
31 | return (px / scale + 0.5f).toInt()
32 | }
33 |
34 | fun View?.dp2px(dp: Int): Int {
35 | if (this == null) {
36 | return 0
37 | }
38 | if (dp == 0) {
39 | return 0
40 | }
41 | val scale = resources.displayMetrics.density
42 | return (dp * scale + 0.5f).toInt()
43 | }
44 |
45 | fun View?.px2dp(px: Int): Int {
46 | if (this == null) {
47 | return 0
48 | }
49 | val scale = resources.displayMetrics.density
50 | return (px / scale + 0.5f).toInt()
51 | }
52 |
53 | fun scanForActivity(context: Context?): Activity? {
54 | if (context == null) return null
55 | if (context is Activity) {
56 | return context
57 | } else if (context is ContextWrapper) {
58 | return scanForActivity(context.baseContext)
59 | }
60 | return null
61 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/DataWrapUtil.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.tools
2 |
3 | import net.mikaelzero.mojito.bean.ActivityConfig
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/9/24 1:22 PM
8 | * @Description:
9 | */
10 | class DataWrapUtil {
11 | companion object {
12 | var config: ActivityConfig? = null
13 | fun put(config: ActivityConfig) {
14 | this.config = config
15 | }
16 |
17 | fun get(): ActivityConfig? = config
18 |
19 | fun remove() {
20 | config = null
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/MarginViewWrapper.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.tools;
2 |
3 | import android.view.Gravity;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.LinearLayout;
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2020/6/10 9:26 AM
11 | * @Description:
12 | */
13 | public class MarginViewWrapper {
14 | private ViewGroup.MarginLayoutParams params;
15 | private View viewWrapper;
16 |
17 | public MarginViewWrapper(View view) {
18 | this.viewWrapper = view;
19 | params = (ViewGroup.MarginLayoutParams) viewWrapper.getLayoutParams();
20 | if (params instanceof LinearLayout.LayoutParams) {
21 | ((LinearLayout.LayoutParams) params).gravity = Gravity.START;
22 | }
23 | }
24 |
25 | public int getWidth() {
26 | return params.width;
27 | }
28 |
29 | public int getHeight() {
30 | return params.height;
31 | }
32 |
33 | public void setWidth(float width) {
34 | params.width = Math.round(width);
35 | viewWrapper.setLayoutParams(params);
36 | }
37 |
38 | public void setHeight(float height) {
39 | params.height = Math.round(height);
40 | viewWrapper.setLayoutParams(params);
41 | }
42 |
43 | public void setMarginTop(int m) {
44 | params.topMargin = m;
45 | viewWrapper.setLayoutParams(params);
46 | }
47 |
48 | public void setMarginBottom(int m) {
49 | params.bottomMargin = m;
50 | viewWrapper.setLayoutParams(params);
51 | }
52 |
53 | public int getMarginTop() {
54 | return params.topMargin;
55 | }
56 |
57 | public void setMarginRight(int mr) {
58 | params.rightMargin = mr;
59 | viewWrapper.setLayoutParams(params);
60 | }
61 |
62 | public void setMarginLeft(int mr) {
63 | params.leftMargin = mr;
64 | viewWrapper.setLayoutParams(params);
65 | }
66 |
67 | public int getMarginRight() {
68 | return params.rightMargin;
69 | }
70 |
71 | public int getMarginLeft() {
72 | return params.leftMargin;
73 | }
74 |
75 | public int getMarginBottom() {
76 | return params.bottomMargin;
77 | }
78 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/MojitoConstant.kt:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.tools
2 |
3 | /**
4 | * @Author: MikaelZero
5 | * @CreateDate: 2020/6/23 9:31 AM
6 | * @Description:
7 | */
8 | class MojitoConstant {
9 | companion object {
10 | const val KEY_ACTIVITY_PARAMS = "KEY_ACTIVITY_PARAMS"
11 | const val KEY_FRAGMENT_PARAMS = "KEY_FRAGMENT_PARAMS"
12 | }
13 | }
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/NoScrollViewPager.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.tools;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.MotionEvent;
6 |
7 | import androidx.viewpager.widget.ViewPager;
8 |
9 | /**
10 | * @Author: MikaelZero
11 | * @CreateDate: 2020/6/13 11:56 AM
12 | * @Description:
13 | */
14 | public class NoScrollViewPager extends ViewPager {
15 | private boolean isLocked;
16 |
17 | public NoScrollViewPager(Context context) {
18 | super(context);
19 | }
20 |
21 | public NoScrollViewPager(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | @Override
26 | public void setCurrentItem(int item, boolean smoothScroll) {
27 | super.setCurrentItem(item, smoothScroll);
28 | }
29 |
30 | @Override
31 | public void setCurrentItem(int item) {
32 | super.setCurrentItem(item, false);
33 | }
34 |
35 | @Override
36 | public boolean onInterceptTouchEvent(MotionEvent ev) {
37 | if (!isLocked) {
38 | try {
39 | return super.onInterceptTouchEvent(ev);
40 | } catch (IllegalArgumentException ex) {
41 | ex.printStackTrace();
42 | return false;
43 | }
44 | }
45 | return false;
46 | }
47 |
48 | @Override
49 | public boolean onTouchEvent(MotionEvent event) {
50 | return !isLocked && super.onTouchEvent(event);
51 | }
52 |
53 | public void setLocked(boolean isLocked) {
54 | this.isLocked = isLocked;
55 | }
56 |
57 | public boolean isLocked() {
58 | return isLocked;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/TransitionAdapterListener.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.tools;
2 |
3 | import android.os.Build;
4 | import android.transition.Transition;
5 |
6 | import androidx.annotation.RequiresApi;
7 |
8 | /**
9 | * @Author: MikaelZero
10 | * @CreateDate: 2020/6/19 4:38 PM
11 | * @Description:
12 | */
13 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
14 | public
15 | class TransitionAdapterListener implements Transition.TransitionListener {
16 | @Override
17 | public void onTransitionStart(Transition transition) {
18 |
19 | }
20 |
21 | @Override
22 | public void onTransitionEnd(Transition transition) {
23 |
24 | }
25 |
26 | @Override
27 | public void onTransitionCancel(Transition transition) {
28 |
29 | }
30 |
31 | @Override
32 | public void onTransitionPause(Transition transition) {
33 |
34 | }
35 |
36 | @Override
37 | public void onTransitionResume(Transition transition) {
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/mojito/src/main/java/net/mikaelzero/mojito/tools/Utils.java:
--------------------------------------------------------------------------------
1 | package net.mikaelzero.mojito.tools;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * @Author: MikaelZero
7 | * @CreateDate: 2020/6/13 5:41 PM
8 | * @Description:
9 | */
10 | public class Utils {
11 |
12 | public static int dip2px(Context c, float dpValue) {
13 | final float scale = c.getResources().getDisplayMetrics().density;
14 | return (int) (dpValue * scale + 0.5f);
15 | }
16 | }
--------------------------------------------------------------------------------
/mojito/src/main/res/drawable/target_button_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mojito/src/main/res/layout/activity_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
18 |
19 |
23 |
--------------------------------------------------------------------------------
/mojito/src/main/res/layout/default_target_cover_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/mojito/src/main/res/layout/fragment_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/mojito/src/main/res/layout/layout_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
--------------------------------------------------------------------------------
/mojito/src/main/res/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/mojito/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00000000
4 |
5 |
--------------------------------------------------------------------------------
/mojito/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mojito/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DragDiooto
3 |
4 |
5 |
--------------------------------------------------------------------------------
/mojito/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.buildFileName = "build.gradle.kts"
2 | include(":FrescoImageLoader")
3 | include(":SketchImageViewLoader")
4 | include(":GlideImageLoader")
5 | include(":app", ":mojito")
6 | include(":coilimageloader")
7 | include(":PhotoViewImageViewLoader")
8 |
--------------------------------------------------------------------------------