├── .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 |