山海小管家.apk(点击下载) / Drawables.java


package com.stardust.autojs.core.ui.inflater.util;

import a.b.c.a.a;
import a.c.a.c;
import a.c.a.j;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Base64;
import android.view.View;
import android.widget.ImageView;
import com.stardust.autojs.core.ui.inflater.ImageLoader;
import e.c.b.f;
import e.c.b.h;
import e.g.g;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.mozilla.javascript.ES6Iterator;

public class Drawables {
    public static final Companion Companion = new Companion(null);
    public static final Pattern DATA_PATTERN = Pattern.compile("data:(\\w+/\\w+);base64,(.+)");
    public static ImageLoader defaultImageLoader = new DefaultImageLoader();
    public ImageLoader imageLoader = defaultImageLoader;

    public static final class Companion {
        public Companion() {
        }

        public /* synthetic */ Companion(f fVar) {
        }

        public final ImageLoader getDefaultImageLoader() {
            return Drawables.defaultImageLoader;
        }

        public final Bitmap loadBase64Data(String str) {
            if (str != null) {
                Matcher matcher = Drawables.DATA_PATTERN.matcher(str);
                if (matcher.matches() && matcher.groupCount() == 2) {
                    str = matcher.group(2);
                    h.a((Object) str, "matcher.group(2)");
                }
                byte[] decode = Base64.decode(str, 0);
                Bitmap decodeByteArray = BitmapFactory.decodeByteArray(decode, 0, decode.length);
                h.a((Object) decodeByteArray, "BitmapFactory.decodeByte…ray(bytes, 0, bytes.size)");
                return decodeByteArray;
            }
            h.a("data");
            throw null;
        }

        public final void setDefaultImageLoader(ImageLoader imageLoader) {
            if (imageLoader != null) {
                Drawables.defaultImageLoader = imageLoader;
            } else {
                h.a("<set-?>");
                throw null;
            }
        }
    }

    private static final class DefaultImageLoader implements ImageLoader {
        @Override // com.stardust.autojs.core.ui.inflater.ImageLoader
        public Drawable load(View view, Uri uri) {
            if (view == null) {
                h.a("view");
                throw null;
            } else if (uri != null) {
                throw new UnsupportedOperationException();
            } else {
                h.a("uri");
                throw null;
            }
        }

        @Override // com.stardust.autojs.core.ui.inflater.ImageLoader
        public void loadInto(ImageView imageView, Uri uri) {
            if (imageView == null) {
                h.a("imageView");
                throw null;
            } else if (uri != null) {
                Context context = imageView.getContext();
                h.a((Object) context, "imageView.context");
                c.c(context.getApplicationContext()).a(uri).a(imageView);
            } else {
                h.a("uri");
                throw null;
            }
        }

        @Override // com.stardust.autojs.core.ui.inflater.ImageLoader
        public void loadIntoBackground(View view, Uri uri) {
            if (view == null) {
                h.a("view");
                throw null;
            } else if (uri != null) {
                Context context = view.getContext();
                h.a((Object) context, "view.context");
                j<Drawable> a2 = c.c(context.getApplicationContext()).a(uri);
                a2.a(new Drawables$DefaultImageLoader$loadIntoBackground$1(view), a2.a());
            } else {
                h.a("uri");
                throw null;
            }
        }

        @Override // com.stardust.autojs.core.ui.inflater.ImageLoader
        public void load(View view, Uri uri, ImageLoader.BitmapCallback bitmapCallback) {
            if (view == null) {
                h.a("view");
                throw null;
            } else if (uri == null) {
                h.a("uri");
                throw null;
            } else if (bitmapCallback != null) {
                Context context = view.getContext();
                h.a((Object) context, "view.context");
                j<Bitmap> a2 = c.c(context.getApplicationContext()).a();
                a2.b(uri);
                a2.a(new Drawables$DefaultImageLoader$load$2(bitmapCallback), a2.a());
            } else {
                h.a("bitmapCallback");
                throw null;
            }
        }

        @Override // com.stardust.autojs.core.ui.inflater.ImageLoader
        public void load(View view, Uri uri, ImageLoader.DrawableCallback drawableCallback) {
            if (view == null) {
                h.a("view");
                throw null;
            } else if (uri == null) {
                h.a("uri");
                throw null;
            } else if (drawableCallback != null) {
                Context context = view.getContext();
                h.a((Object) context, "view.context");
                j<Drawable> a2 = c.c(context.getApplicationContext()).a(uri);
                a2.a(new Drawables$DefaultImageLoader$load$1(drawableCallback), a2.a());
            } else {
                h.a("drawableCallback");
                throw null;
            }
        }
    }

    private final void loadDataInto(ImageView imageView, String str) {
        imageView.setImageBitmap(Companion.loadBase64Data(str));
    }

    public Drawable decodeImage(Resources resources, String str) {
        if (resources == null) {
            h.a("resources");
            throw null;
        } else if (str != null) {
            return new BitmapDrawable(resources, BitmapFactory.decodeFile(str));
        } else {
            h.a("path");
            throw null;
        }
    }

    public final ImageLoader getImageLoader() {
        return this.imageLoader;
    }

    public final Drawable loadAttrResources(Context context, String str) {
        if (context == null) {
            h.a("context");
            throw null;
        } else if (str != null) {
            Resources resources = context.getResources();
            String substring = str.substring(1);
            h.a((Object) substring, "(this as java.lang.String).substring(startIndex)");
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(new int[]{resources.getIdentifier(substring, "attr", context.getPackageName())});
            Drawable drawable = obtainStyledAttributes.getDrawable(0);
            obtainStyledAttributes.recycle();
            return drawable;
        } else {
            h.a(ES6Iterator.VALUE_PROPERTY);
            throw null;
        }
    }

    public final Drawable loadDrawableResources(Context context, String str) {
        if (context == null) {
            h.a("context");
            throw null;
        } else if (str != null) {
            int identifier = context.getResources().getIdentifier(str, "drawable", context.getPackageName());
            if (identifier != 0) {
                Drawable drawable = context.getResources().getDrawable(identifier);
                h.a((Object) drawable, "context.resources.getDrawable(resId)");
                return drawable;
            }
            throw new Resources.NotFoundException(a.b("drawable not found: ", str));
        } else {
            h.a(ES6Iterator.VALUE_PROPERTY);
            throw null;
        }
    }

    public final void loadInto(ImageView imageView, Uri uri) {
        if (imageView == null) {
            h.a("view");
            throw null;
        } else if (uri != null) {
            this.imageLoader.loadInto(imageView, uri);
        } else {
            h.a("uri");
            throw null;
        }
    }

    public final void loadIntoBackground(View view, Uri uri) {
        if (view == null) {
            h.a("view");
            throw null;
        } else if (uri != null) {
            this.imageLoader.loadIntoBackground(view, uri);
        } else {
            h.a("uri");
            throw null;
        }
    }

    public final Drawable parse(Context context, String str) {
        if (context == null) {
            h.a("context");
            throw null;
        } else if (str != null) {
            context.getResources();
            if (g.b(str, "@color/", false, 2) || g.b(str, "@android:color/", false, 2) || g.b(str, "#", false, 2)) {
                return new ColorDrawable(Colors.parse(context, str));
            }
            if (g.b(str, "?", false, 2)) {
                return loadAttrResources(context, str);
            }
            if (!g.b(str, "file://", false, 2)) {
                return loadDrawableResources(context, str);
            }
            Resources resources = context.getResources();
            h.a((Object) resources, "context.resources");
            String substring = str.substring(7);
            h.a((Object) substring, "(this as java.lang.String).substring(startIndex)");
            return decodeImage(resources, substring);
        } else {
            h.a(ES6Iterator.VALUE_PROPERTY);
            throw null;
        }
    }

    public final void setImageLoader(ImageLoader imageLoader2) {
        if (imageLoader2 != null) {
            this.imageLoader = imageLoader2;
        } else {
            h.a("<set-?>");
            throw null;
        }
    }

    public final <V extends ImageView> void setupWithImage(V v, String str) {
        if (v == null) {
            h.a("view");
            throw null;
        } else if (str == null) {
            h.a(ES6Iterator.VALUE_PROPERTY);
            throw null;
        } else if (g.b(str, "http://", false, 2) || g.b(str, "https://", false, 2)) {
            Uri parse = Uri.parse(str);
            h.a((Object) parse, "Uri.parse(value)");
            loadInto(v, parse);
        } else if (g.b(str, "data:", false, 2)) {
            loadDataInto(v, str);
        } else {
            v.setImageDrawable(parse(v, str));
        }
    }

    public final void setupWithViewBackground(View view, String str) {
        if (view == null) {
            h.a("view");
            throw null;
        } else if (str == null) {
            h.a(ES6Iterator.VALUE_PROPERTY);
            throw null;
        } else if (g.b(str, "http://", false, 2) || g.b(str, "https://", false, 2)) {
            Uri parse = Uri.parse(str);
            h.a((Object) parse, "Uri.parse(value)");
            loadIntoBackground(view, parse);
        } else {
            view.setBackground(parse(view, str));
        }
    }

    public final Drawable parse(View view, String str) {
        if (view == null) {
            h.a("view");
            throw null;
        } else if (str != null) {
            Context context = view.getContext();
            h.a((Object) context, "view.context");
            return parse(context, str);
        } else {
            h.a("name");
            throw null;
        }
    }
}