mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
fix: colors.red() return NaN
This commit is contained in:
parent
1784a9f84d
commit
55ea745d57
@ -1,6 +1,7 @@
|
||||
package com.stardust.scriptdroid.ui.main.drawer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
@ -1,9 +1,18 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var images = {};
|
||||
var colors = Object.create(android.graphics.Color);
|
||||
colors.toString = function(color){
|
||||
return '#' + (color >>> 0).toString(16);
|
||||
var colors = Object.create(__runtime__.colors);
|
||||
colors.alpha = function(color){
|
||||
return color >>> 24;
|
||||
}
|
||||
colors.red = function(color){
|
||||
return (color >> 16) & 0xFF;
|
||||
}
|
||||
colors.green = function(color){
|
||||
return (color >> 8) & 0xFF;
|
||||
}
|
||||
colors.blue = function(color){
|
||||
return color & 0xFF;
|
||||
}
|
||||
if(android.os.Build.VERSION.SDK_INT < 19){
|
||||
return images;
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
package com.stardust.autojs.core.image;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/12/31.
|
||||
*/
|
||||
|
||||
public class Colors {
|
||||
|
||||
public int rgb(int red, int green, int blue) {
|
||||
return Color.rgb(red, green, blue);
|
||||
}
|
||||
|
||||
public int argb(int alpha, int red, int green, int blue) {
|
||||
return Color.argb(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public float luminance(int color) {
|
||||
double red = Color.red(color) / 255.0;
|
||||
red = red < 0.03928 ? red / 12.92 : Math.pow((red + 0.055) / 1.055, 2.4);
|
||||
double green = Color.green(color) / 255.0;
|
||||
green = green < 0.03928 ? green / 12.92 : Math.pow((green + 0.055) / 1.055, 2.4);
|
||||
double blue = Color.blue(color) / 255.0;
|
||||
blue = blue < 0.03928 ? blue / 12.92 : Math.pow((blue + 0.055) / 1.055, 2.4);
|
||||
return (float) ((0.2126 * red) + (0.7152 * green) + (0.0722 * blue));
|
||||
}
|
||||
|
||||
public int parseColor(String colorString) {
|
||||
return Color.parseColor(colorString);
|
||||
}
|
||||
|
||||
public void RGBToHSV(int red, int green, int blue, float[] hsv) {
|
||||
Color.RGBToHSV(red, green, blue, hsv);
|
||||
}
|
||||
|
||||
public void colorToHSV(int color, float[] hsv) {
|
||||
Color.colorToHSV(color, hsv);
|
||||
}
|
||||
|
||||
public int HSVToColor(float[] hsv) {
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
|
||||
public int HSVToColor(int alpha, float[] hsv) {
|
||||
return Color.HSVToColor(alpha, hsv);
|
||||
}
|
||||
|
||||
public String toString(int color) {
|
||||
return "#" + Integer.toHexString(color);
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@ import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.ScriptEngineService;
|
||||
import com.stardust.autojs.annotation.ScriptVariable;
|
||||
import com.stardust.autojs.core.accessibility.AccessibilityBridge;
|
||||
import com.stardust.autojs.core.image.Colors;
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.rhino.AndroidClassLoader;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
@ -161,6 +162,9 @@ public class ScriptRuntime {
|
||||
@ScriptVariable
|
||||
public UiHandler uiHandler;
|
||||
|
||||
@ScriptVariable
|
||||
public final Colors colors = new Colors();
|
||||
|
||||
private Images images;
|
||||
|
||||
private static WeakReference<Context> applicationContext;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user