Virtual Trading v2.0.95版本的 MD5 值为:ef0f95d706f7364286da0edbbd29a27d

以下内容为反编译后的 ImageUtil.java 源代码,内容仅作参考


package com.gordonlu.imageutil;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.widget.ImageView;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesLibraries;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;

@SimpleObject(external = true)
@UsesPermissions(permissionNames = "")
@DesignerComponent(category = ComponentCategory.EXTENSION, description = "A non-visible extension that provides additional tools to the built-in Image component.<br><br>Made by Gordon Lu (AICODE). For details, please read my website: <a href='https://sites.google.com/view/appinventor-aicode/my-extensions/imageutil'>https://sites.google.com/view/appinventor-aicode/my-extensions/imageutil</a>", iconName = "https://docs.google.com/drawings/d/e/2PACX-1vQCI87PHLBF0jb8QWyYmIRQSjjNW3EFXf-qpsWCvBYkUQ9vEgPAB8SpxcMpblxNpbIYrjCjLrRLIU2c/pub?w=16&h=16", nonVisible = true, version = 4)
@UsesLibraries(libraries = "")
public class ImageUtil extends AndroidNonvisibleComponent {
    private Activity activity;
    private Context context;

    public ImageUtil(ComponentContainer componentContainer) {
        super(componentContainer.$form());
        this.activity = componentContainer.$context();
        this.context = componentContainer.$context();
    }

    @SimpleFunction(description = "Applies grayscale effect to an image and fades the image.")
    public void ApplyGrayscaleAndFade(AndroidViewComponent androidViewComponent) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0.0f);
        imageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        imageView.setImageAlpha(128);
    }

    @SimpleFunction(description = "Applies watermark text to the given image's content. Set the text of the watermark via the watermark parameter, and the x and y parameters are the co-ordinates of the watermark located on the image. The parameter color is the text color of the watermark, and alpha is the luminance of the watermark. The size parameter is the size of the watermark in points. Specify whether to underline the watermark via the underline boolean parameter. Use the blocks in the properties of this extension for the font parameter. If useCurrentFont is true, the font parameter will be ignored. ")
    public void ApplyWatermark(AndroidViewComponent androidViewComponent, String str, int i, int i2, int i3, int i4, int i5, boolean z, String str2, boolean z2) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        imageView.invalidate();
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
        Canvas canvas = new Canvas(createBitmap);
        canvas.drawBitmap(bitmap, 0.0f, 0.0f, (Paint) null);
        Paint paint = new Paint();
        paint.setColor(i3);
        paint.setAlpha(i4);
        paint.setTextSize(i5);
        paint.setAntiAlias(true);
        paint.setUnderlineText(z);
        Typeface typeface = Typeface.DEFAULT;
        if (z2) {
            typeface = paint.getTypeface();
        } else if (str2 == "DEFAULT") {
            typeface = Typeface.DEFAULT;
        } else if (str2 == "SERIF") {
            typeface = Typeface.SERIF;
        } else if (str2 == "SANS SERIF") {
            typeface = Typeface.SANS_SERIF;
        } else if (str2 == "MONOSPACE") {
            typeface = Typeface.MONOSPACE;
        }
        paint.setTypeface(typeface);
        canvas.drawText(str, i, i2, paint);
        imageView.setImageBitmap(createBitmap);
    }

    @SimpleFunction(description = "Applies color boost to the content of the given content. To find out the type parameter, go to: https://shaikhhamadali.blogspot.com/2013/07/color-boost-imagebitmap-in-imageview.html.")
    public void ColorBoost(AndroidViewComponent androidViewComponent, int i, float f) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        imageView.invalidate();
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap createBitmap = Bitmap.createBitmap(width, height, bitmap.getConfig());
        for (int i2 = 0; i2 < width; i2++) {
            for (int i3 = 0; i3 < height; i3++) {
                int pixel = bitmap.getPixel(i2, i3);
                int alpha = Color.alpha(pixel);
                int red = Color.red(pixel);
                int green = Color.green(pixel);
                int blue = Color.blue(pixel);
                if (i == 1) {
                    red = (int) (red * (f + 1.0f));
                    if (red > 255) {
                        red = 255;
                    }
                } else if (i == 2) {
                    green = (int) (green * (f + 1.0f));
                    if (green > 255) {
                        green = 255;
                    }
                } else if (i == 3 && (blue = (int) (blue * (f + 1.0f))) > 255) {
                    blue = 255;
                }
                createBitmap.setPixel(i2, i3, Color.argb(alpha, red, green, blue));
            }
        }
        imageView.setImageBitmap(createBitmap);
    }

    @SimpleProperty(description = "A font block.")
    public String DefaultFont() {
        return "DEFAULT";
    }

    @SimpleFunction(description = "Adds gamma effect to the given image.")
    public void GammaEffect(AndroidViewComponent androidViewComponent, double d, double d2, double d3) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        imageView.invalidate();
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int[] iArr = new int[256];
        int[] iArr2 = new int[256];
        int[] iArr3 = new int[256];
        int i = 0;
        for (int i2 = 256; i < i2; i2 = 256) {
            double d4 = i;
            Double.isNaN(d4);
            double d5 = d4 / 255.0d;
            int[] iArr4 = iArr;
            iArr4[i] = Math.min(255, (int) ((Math.pow(d5, 1.0d / d) * 255.0d) + 0.5d));
            int i3 = i;
            iArr2[i3] = Math.min(255, (int) ((Math.pow(d5, 1.0d / d2) * 255.0d) + 0.5d));
            iArr3[i3] = Math.min(255, (int) ((Math.pow(d5, 1.0d / d3) * 255.0d) + 0.5d));
            i = i3 + 1;
            iArr = iArr4;
        }
        int[] iArr5 = iArr;
        for (int i4 = 0; i4 < width; i4++) {
            for (int i5 = 0; i5 < height; i5++) {
                int pixel = bitmap.getPixel(i4, i5);
                createBitmap.setPixel(i4, i5, Color.argb(Color.alpha(pixel), iArr5[Color.red(pixel)], iArr2[Color.green(pixel)], iArr3[Color.blue(pixel)]));
            }
        }
        imageView.setImageBitmap(createBitmap);
    }

    @SimpleFunction(description = "Returns the alpha that was applied to this ImageView.")
    public int ImageAlpha(AndroidViewComponent androidViewComponent) {
        return ((ImageView) androidViewComponent.getView()).getImageAlpha();
    }

    @SimpleFunction(description = "Checks whether this ImageView crops to padding.")
    public boolean IsCroppedToPadding(AndroidViewComponent androidViewComponent) {
        return ((ImageView) androidViewComponent.getView()).getCropToPadding();
    }

    @SimpleProperty(description = "A font block.")
    public String Monospace() {
        return "MONOSPACE";
    }

    @SimpleFunction(description = "Applies round corners to the Image, with the radius parameter as the radius of each corner.")
    public void RoundCorners(AndroidViewComponent androidViewComponent, int i) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        imageView.invalidate();
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        Paint paint = new Paint();
        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        RectF rectF = new RectF(rect);
        float f = i;
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(-12434878);
        canvas.drawRoundRect(rectF, f, f, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        imageView.setImageBitmap(createBitmap);
    }

    @SimpleProperty(description = "A font block.")
    public String SansSerif() {
        return "SANS SERIF";
    }

    @SimpleFunction(description = "Sets the image to a Sepia Toning version of the image.")
    public void SepiaToningEffect(AndroidViewComponent androidViewComponent, int i, double d, double d2, double d3) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        imageView.invalidate();
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap createBitmap = Bitmap.createBitmap(width, height, bitmap.getConfig());
        int i2 = 0;
        while (i2 < width) {
            for (int i3 = 0; i3 < height; i3++) {
                int pixel = bitmap.getPixel(i2, i3);
                int alpha = Color.alpha(pixel);
                int red = Color.red(pixel);
                int green = Color.green(pixel);
                int blue = Color.blue(pixel);
                double d4 = red;
                Double.isNaN(d4);
                double d5 = green;
                Double.isNaN(d5);
                double d6 = blue;
                Double.isNaN(d6);
                double d7 = (int) ((d4 * 0.3d) + (d5 * 0.59d) + (d6 * 0.11d));
                double d8 = i;
                Double.isNaN(d8);
                Double.isNaN(d7);
                int i4 = (int) ((d8 * d) + d7);
                int i5 = 255;
                if (i4 > 255) {
                    i4 = 255;
                }
                Double.isNaN(d8);
                Double.isNaN(d7);
                int i6 = i2;
                int i7 = (int) (d7 + (d8 * d2));
                if (i7 > 255) {
                    i7 = 255;
                }
                Double.isNaN(d8);
                Double.isNaN(d7);
                int i8 = (int) (d7 + (d8 * d3));
                if (i8 <= 255) {
                    i5 = i8;
                }
                i2 = i6;
                createBitmap.setPixel(i2, i3, Color.argb(alpha, i4, i7, i5));
            }
            i2++;
        }
        imageView.setImageBitmap(createBitmap);
    }

    @SimpleProperty(description = "A font block.")
    public String Serif() {
        return "SERIF";
    }

    @SimpleFunction(description = "Sets the brightness of the content for the given image, according to the value parameter.")
    public void SetBrightness(AndroidViewComponent androidViewComponent, int i) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        imageView.invalidate();
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap createBitmap = Bitmap.createBitmap(width, height, bitmap.getConfig());
        for (int i2 = 0; i2 < width; i2++) {
            for (int i3 = 0; i3 < height; i3++) {
                int pixel = bitmap.getPixel(i2, i3);
                int alpha = Color.alpha(pixel);
                int red = Color.red(pixel);
                int green = Color.green(pixel);
                int blue = Color.blue(pixel);
                int i4 = red + i;
                int i5 = 255;
                if (i4 > 255) {
                    i4 = 255;
                } else if (i4 < 0) {
                    i4 = 0;
                }
                int i6 = green + i;
                if (i6 > 255) {
                    i6 = 255;
                } else if (i6 < 0) {
                    i6 = 0;
                }
                int i7 = blue + i;
                if (i7 <= 255) {
                    i5 = i7 < 0 ? 0 : i7;
                }
                createBitmap.setPixel(i2, i3, Color.argb(alpha, i4, i6, i5));
            }
        }
        imageView.setImageBitmap(createBitmap);
    }

    @SimpleFunction(description = "Sets whether the image should crop to padding.")
    public void SetCropToPadding(AndroidViewComponent androidViewComponent, boolean z) {
        ((ImageView) androidViewComponent.getView()).setCropToPadding(z);
    }

    @SimpleFunction(description = "Sets the alpha value that should be applied to the image.")
    public void SetImageAlpha(AndroidViewComponent androidViewComponent, int i) {
        ((ImageView) androidViewComponent.getView()).setImageAlpha(i);
    }

    @SimpleFunction(description = "Change the image tint color. You can use too alpha values if you want with the 'make a list' block. Do not forget to use the 'make color' block together with the 'make a list' block.")
    public void SetImageTintColor(AndroidViewComponent androidViewComponent, int i) {
        ((ImageView) androidViewComponent.getView()).setColorFilter(i);
    }

    @SimpleFunction(description = "Sets the padding of the given image.")
    public void SetPadding(AndroidViewComponent androidViewComponent, int i, int i2, int i3, int i4) {
        androidViewComponent.getView().setPadding(i, i2, i3, i4);
    }

    @SimpleFunction(description = "Undos the grayscale and fade effects applied with the AplyGrayscaleAndFade method.")
    public void UndoGrayscaleAndFade(AndroidViewComponent androidViewComponent) {
        ImageView imageView = (ImageView) androidViewComponent.getView();
        imageView.setColorFilter((ColorFilter) null);
        imageView.setImageAlpha(255);
    }
}