// Path: library/src/main/java/xyz/zpayh/hdimage/core/HDImageViewFactory.java
// public class HDImageViewFactory {
//     private static HDImageViewFactory sInstance = null;
// 
//     private static HDImageViewFactory sDefaultInstance = null;
// 
//     public static HDImageViewFactory getInstance(){
//         if (sInstance == null){
//             return Preconditions.checkNotNull(sDefaultInstance, "Default HDImageViewFactory was not initialized!");
//         }
//         return sInstance;
//     }
// 
//     public static void initializeDefault(Context context){
//         if (sDefaultInstance == null){
//             synchronized (HDImageViewFactory.class){
//                 if (sDefaultInstance == null){
//                     sDefaultInstance = new HDImageViewFactory(HDImageViewConfig.newBuilder(context.getApplicationContext()).build());
//                 }
//             }
//         }
//     }
// 
//     public static void initialize(Context context){
//         initialize(HDImageViewConfig.newBuilder(context.getApplicationContext()).build());
//     }
// 
//     public static void initialize(HDImageViewConfig config){
//         sInstance = new HDImageViewFactory(config);
//     }
// 
//     private final HDImageViewConfig mConfig;
// 
//     public HDImageViewFactory(HDImageViewConfig config){
//         mConfig = Preconditions.checkNotNull(config);
//     }
// 
//     public Interpolator getScaleAnimationInterpolator() {
//         return mConfig.getScaleAnimationInterpolator();
//     }
// 
//     public Interpolator getTranslationAnimationInterpolator() {
//         return mConfig.getTranslationAnimationInterpolator();
//     }
// 
//     public List<Interceptor> getDataSourceInterceptor(){
//         return mConfig.getInterceptors();
//     }
// 
//     public List<OrientationInterceptor> getOrientationInterceptor() {
//         return mConfig.getOrientationInterceptors();
//     }
// 
//     public Bitmap.Config getBitmapConfig() {
//         return mConfig.getBitmapConfig();
//     }
// }


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import androidx.annotation.NonNull;
import java.io.IOException;
import xyz.zpayh.hdimage.core.HDImageViewFactory;
            mDecoder = getDecoderWithInterceptorChain(uri);
            if (mDecoder != null) {
                if (dimensions != null){
                    dimensions.set(mDecoder.getWidth(), mDecoder.getHeight());
                }
                if (listener != null){
                    listener.success();
                }
            }else{
                if (listener != null){
                    listener.failed(new IOException("init failed"));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            if (listener != null){
                listener.failed(e);
            }
        }
    }

    @Override
    public Bitmap decode(Rect sRect, int sampleSize) {
        if (mDecoder == null){
            return null;
        }
        synchronized (mDecoderLock) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = sampleSize;
            // Default RGB_565
// Path: library/src/main/java/xyz/zpayh/hdimage/core/HDImageViewFactory.java
// public class HDImageViewFactory {
//     private static HDImageViewFactory sInstance = null;
// 
//     private static HDImageViewFactory sDefaultInstance = null;
// 
//     public static HDImageViewFactory getInstance(){
//         if (sInstance == null){
//             return Preconditions.checkNotNull(sDefaultInstance, "Default HDImageViewFactory was not initialized!");
//         }
//         return sInstance;
//     }
// 
//     public static void initializeDefault(Context context){
//         if (sDefaultInstance == null){
//             synchronized (HDImageViewFactory.class){
//                 if (sDefaultInstance == null){
//                     sDefaultInstance = new HDImageViewFactory(HDImageViewConfig.newBuilder(context.getApplicationContext()).build());
//                 }
//             }
//         }
//     }
// 
//     public static void initialize(Context context){
//         initialize(HDImageViewConfig.newBuilder(context.getApplicationContext()).build());
//     }
// 
//     public static void initialize(HDImageViewConfig config){
//         sInstance = new HDImageViewFactory(config);
//     }
// 
//     private final HDImageViewConfig mConfig;
// 
//     public HDImageViewFactory(HDImageViewConfig config){
//         mConfig = Preconditions.checkNotNull(config);
//     }
// 
//     public Interpolator getScaleAnimationInterpolator() {
//         return mConfig.getScaleAnimationInterpolator();
//     }
// 
//     public Interpolator getTranslationAnimationInterpolator() {
//         return mConfig.getTranslationAnimationInterpolator();
//     }
// 
//     public List<Interceptor> getDataSourceInterceptor(){
//         return mConfig.getInterceptors();
//     }
// 
//     public List<OrientationInterceptor> getOrientationInterceptor() {
//         return mConfig.getOrientationInterceptors();
//     }
// 
//     public Bitmap.Config getBitmapConfig() {
//         return mConfig.getBitmapConfig();
//     }
// }


// Path: library/src/main/java/xyz/zpayh/hdimage/datasource/DefaultBitmapDataSource.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import androidx.annotation.NonNull;
import java.io.IOException;
import xyz.zpayh.hdimage.core.HDImageViewFactory;

            mDecoder = getDecoderWithInterceptorChain(uri);
            if (mDecoder != null) {
                if (dimensions != null){
                    dimensions.set(mDecoder.getWidth(), mDecoder.getHeight());
                }
                if (listener != null){
                    listener.success();
                }
            }else{
                if (listener != null){
                    listener.failed(new IOException("init failed"));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            if (listener != null){
                listener.failed(e);
            }
        }
    }

    @Override
    public Bitmap decode(Rect sRect, int sampleSize) {
        if (mDecoder == null){
            return null;
        }
        synchronized (mDecoderLock) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = sampleSize;
            // Default RGB_565
            options.inPreferredConfig = HDImageViewFactory.getInstance().getBitmapConfig();