diff --git a/extlib/xgui/src/main/java/org/mini/gui/GButton.java b/extlib/xgui/src/main/java/org/mini/gui/GButton.java index 5271f529..3a9e5a39 100644 --- a/extlib/xgui/src/main/java/org/mini/gui/GButton.java +++ b/extlib/xgui/src/main/java/org/mini/gui/GButton.java @@ -7,6 +7,7 @@ import org.mini.glfm.Glfm; +import static org.mini.gui.GToolkit.getStyle; import static org.mini.gui.GToolkit.nvgRGBA; import static org.mini.glwrap.GLUtil.toCstyleBytes; import static org.mini.nanovg.Nanovg.*; @@ -20,6 +21,7 @@ public class GButton extends GObject { protected byte[] text_arr; protected String preicon; protected byte[] preicon_arr; + protected float[] preiconColor; protected boolean bt_pressed = false; float oldX, oldY; @@ -58,6 +60,15 @@ public void setPreIcon(String preicon) { preicon_arr = toCstyleBytes(preicon); } + public float[] getPreiconColor() { + return preiconColor; + } + + public void setPreiconColor(float[] preiconColor) { + this.preiconColor = preiconColor; + } + + @Override public void mouseButtonEvent(int button, boolean pressed, int x, int y) { if (isInArea(x, y)) { @@ -156,7 +167,8 @@ boolean paintFlying(long vg, float x, float y) { iw = nvgTextBoundsJni(vg, 0, 0, preicon_arr, 0, preicon_arr.length, null); - nvgFillColor(vg, textColor); + float[] pc = preiconColor == null ? getStyle().getTextFontColor() : preiconColor; + nvgFillColor(vg, pc); nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE); nvgTextJni(vg, x + w * 0.5f - tw * 0.5f, y + h * 0.5f + move, preicon_arr, 0, preicon_arr.length); } diff --git a/extlib/xgui/src/main/java/org/mini/gui/GColorSelector.java b/extlib/xgui/src/main/java/org/mini/gui/GColorSelector.java index c18bc78d..06099be8 100644 --- a/extlib/xgui/src/main/java/org/mini/gui/GColorSelector.java +++ b/extlib/xgui/src/main/java/org/mini/gui/GColorSelector.java @@ -17,6 +17,9 @@ */ class GColorSelector extends GObject { + /** + * these color can't change by user + */ public static final float[] RED = new float[]{0xff, 0x00, 0x00, 0xff}; public static final float[] GREEN = new float[]{0x00, 0xff, 0x00, 0xff}; public static final float[] BLUE = new float[]{0x00, 0x00, 0xff, 0xff}; @@ -59,6 +62,57 @@ public GColorSelector(GForm form, float pos, float left, float top, float width, } + /** + * 0.0f - 1.0f value of r,g,b,a + * + * @param r + * @param g + * @param b + * @param a + * @return + */ + public static float[] getColor(float r, float g, float b, float a) { + return new float[]{r, g, b, a}; + } + + /** + * 0 - 255 value of r,g,b,a + * + * @param r + * @param g + * @param b + * @param a + * @return + */ + public static float[] getColor(int r, int g, int b, int a) { + return new float[]{r / 255f, g / 255f, b / 255f, a / 255f}; + } + + public static float[] getColor(int rgba) { + int r = (rgba >> 24) & 0xff; + int g = (rgba >> 16) & 0xff; + int b = (rgba >> 8) & 0xff; + int a = (rgba) & 0xff; + return new float[]{r / 255f, g / 255f, b / 255f, a / 255f}; + } + + public static int getHexColor(float[] color) { + int r = (int) (color[0] * 255); + int g = (int) (color[1] * 255); + int b = (int) (color[2] * 255); + int a = (int) (color[3] * 255); + return (a << 24) | (r << 16) | (g << 8) | b; + } + + public static float[] copyColor(float[] color) { + if (color == null) return new float[4]; + return new float[]{color[0], color[1], color[2], color[3]}; + } + + public static void copyColor(float[] src, float[] dest) { + if (src == null || dest == null || src.length != 4 || dest.length != 4) return; + System.arraycopy(src, 0, dest, 0, 4); + } @Override public void cursorPosEvent(int x, int y) { diff --git a/extlib/xgui/src/main/java/org/mini/gui/GListItem.java b/extlib/xgui/src/main/java/org/mini/gui/GListItem.java index 0b87ba76..8167fb6b 100644 --- a/extlib/xgui/src/main/java/org/mini/gui/GListItem.java +++ b/extlib/xgui/src/main/java/org/mini/gui/GListItem.java @@ -8,6 +8,7 @@ import org.mini.glfm.Glfm; import static org.mini.glwrap.GLUtil.toCstyleBytes; +import static org.mini.gui.GToolkit.getStyle; import static org.mini.gui.GToolkit.nvgRGBA; import static org.mini.nanovg.Nanovg.*; @@ -18,6 +19,7 @@ public class GListItem extends GContainer { protected byte[] preicon_arr; protected String preicon; + protected float[] preiconColor; protected GImage img; protected GList list; @@ -54,6 +56,15 @@ public void setPreIcon(String preicon) { preicon_arr = toCstyleBytes(preicon); } + public float[] getPreiconColor() { + return preiconColor; + } + + public void setPreiconColor(float[] preiconColor) { + this.preiconColor = preiconColor; + } + + /** * @return the label */ @@ -170,10 +181,12 @@ public boolean paint(long vg) { } else if (preicon_arr != null) { nvgFontSize(vg, GToolkit.getStyle().getIconFontSize()); nvgFontFace(vg, GToolkit.getFontIcon()); - nvgFillColor(vg, c); + float[] pc = preiconColor == null ? getStyle().getTextFontColor() : preiconColor; + nvgFillColor(vg, pc); nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE); nvgTextJni(vg, x + thumb * 0.5f, y + thumb * 0.5f + 2, preicon_arr, 0, preicon_arr.length); } + nvgFillColor(vg, c); GToolkit.drawTextLine(vg, tx + ((img == null && preicon_arr == null) ? 0 : thumb) + pad, ty + thumb / 2, getText(), list.getFontSize(), c, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); return true; } diff --git a/extlib/xgui/src/main/java/org/mini/gui/GToolkit.java b/extlib/xgui/src/main/java/org/mini/gui/GToolkit.java index f0fc3789..df349905 100644 --- a/extlib/xgui/src/main/java/org/mini/gui/GToolkit.java +++ b/extlib/xgui/src/main/java/org/mini/gui/GToolkit.java @@ -656,11 +656,11 @@ static public GFrame getFileChooser(GForm form, String title, String path, FileF path = AppLoader.getProperty("filechooserpath"); } if (path == null || "".equals(path)) { - path = "./"; + path = GCallBack.getInstance().getApplication().getSaveRoot(); //android can't access out of app dir } File file = new File(path); if (!file.exists()) { - file = new File(GCallBack.getInstance().getApplication().getSaveRoot()); + file = new File("."); } GContainer gp = frame.getView(); @@ -690,7 +690,7 @@ static public GFrame getFileChooser(GForm form, String title, String path, FileF y += btnH + pad; - btnH = 25f; + btnH = 35f; float btnW = 40f; GButton upBtn = new GButton(form, "", x, y, btnW, btnH); upBtn.setPreIcon("⬆"); @@ -840,6 +840,9 @@ private static void setChooserResult(GObject listItem) { } } + static float[] dirColor = new float[]{0.7f, 0.7f, 0.2f, 0.7f}; + static float[] fileColor = new float[]{0.4f, 0.4f, 0.7f, 0.7f}; + private static void chooserAddFilesToList(File dir, FileFilter filter, GList list) { File[] files = dir == null ? File.listRoots() : dir.listFiles(filter); Arrays.sort(files, (f1, f2) -> { @@ -865,8 +868,10 @@ private static void chooserAddFilesToList(File dir, FileFilter filter, GList lis GListItem item = list.addItem(null, lab + " | " + file.length() + " | " + new Date(file.lastModified())); if (file.isDirectory()) { item.setPreIcon("\uD83D\uDCC1"); + item.setPreiconColor(dirColor); } else { item.setPreIcon("\uD83D\uDCC4"); + item.setPreiconColor(fileColor); } item.setAttachment(file); item.setActionListener(fileChooserItemListener); diff --git a/extlib/xgui/src/main/java/org/mini/layout/XButton.java b/extlib/xgui/src/main/java/org/mini/layout/XButton.java index 619af879..3d15869a 100644 --- a/extlib/xgui/src/main/java/org/mini/layout/XButton.java +++ b/extlib/xgui/src/main/java/org/mini/layout/XButton.java @@ -14,6 +14,7 @@ public class XButton // protected String pic; protected int addon = XDef.SPACING_BUTTON_ADD; + float[] preiconColor; protected GButton button; @@ -32,6 +33,8 @@ protected void parseMoreAttribute(String attName, String attValue) { pic = attValue; } else if (attName.equals("addon")) { addon = Integer.parseInt(attValue); + } else if (attName.equals("pcolor")) { + preiconColor = parseHexColor(attValue); } } @@ -70,6 +73,9 @@ protected void createAndSetGui() { button = createGuiImpl(); initGuiMore(); button.setPreIcon(preicon); + if (preiconColor != null) { + button.setPreiconColor(preiconColor); + } } else { button.setLocation(x, y); button.setSize(width, height); diff --git a/extlib/xgui/src/main/java/org/mini/layout/XList.java b/extlib/xgui/src/main/java/org/mini/layout/XList.java index 46700f35..67198d2a 100644 --- a/extlib/xgui/src/main/java/org/mini/layout/XList.java +++ b/extlib/xgui/src/main/java/org/mini/layout/XList.java @@ -22,6 +22,7 @@ protected static class ListItem { boolean selected; float[] color; String preicon; + float[] preiconColor; } protected Vector items = new Vector(); @@ -85,6 +86,7 @@ public void parse(KXmlParser parser, XmlExtAssist assist) throws Exception { item.selected = ("1".equals(tmp1)) ? true : false; try { item.preicon = parser.getAttributeValue(null, "preicon"); + item.preiconColor = parseHexColor(parser.getAttributeValue(null, "pcolor")); } catch (Exception e) { } String tmp2 = parser.nextText(); @@ -147,6 +149,9 @@ protected void createAndSetGui() { if (item.color != null) { gli.setColor(item.color); } + if (item.preiconColor != null) { + gli.setPreiconColor(item.preiconColor); + } list.add(gli); if (item.selected) { selectCount++; diff --git a/mobile/androidapp/app/src/main/java/org/minijvm/activity/JvmNativeActivity.java b/mobile/androidapp/app/src/main/java/org/minijvm/activity/JvmNativeActivity.java index 2394b323..f420982e 100644 --- a/mobile/androidapp/app/src/main/java/org/minijvm/activity/JvmNativeActivity.java +++ b/mobile/androidapp/app/src/main/java/org/minijvm/activity/JvmNativeActivity.java @@ -5,6 +5,7 @@ import android.app.NativeActivity; import android.content.ClipData; import android.content.ClipboardManager; +import android.content.ComponentName; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -545,19 +546,31 @@ private boolean checkPackInfo(String packname) { public int openOtherApp(String urls, String more, int detectAppInstalled) { try { - if (detectAppInstalled != 0) { - if (!checkPackInfo(urls)) { - return 1; + + if (more != null && more.equals("URL")) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urls)); + startActivity(intent); + } else { + if (detectAppInstalled != 0) { + if (!checkPackInfo(urls)) { + return 1; + } } - } - Intent intent = getPackageManager().getLaunchIntentForPackage(urls); - if (intent != null) { - intent.putExtra("type", "110"); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + String[] paras = urls.split(" "); + String pkgName = paras[0]; + String activityName = paras[1]; + + Intent intent = new Intent(Intent.ACTION_MAIN); + ComponentName cmp = new ComponentName(pkgName, activityName); + intent.addCategory(Intent.CATEGORY_LAUNCHER); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.setComponent(cmp); startActivity(intent); return 0; } + } catch (Exception e) { + e.printStackTrace(); } return 1; } diff --git a/mobile/c/glfm/glfm_platform_android.c b/mobile/c/glfm/glfm_platform_android.c index 48c9ddf5..44e9835b 100755 --- a/mobile/c/glfm/glfm_platform_android.c +++ b/mobile/c/glfm/glfm_platform_android.c @@ -2295,6 +2295,7 @@ int openOtherApp(const char *curl, const char *more, int detectAppInstalled){ JNIEnv *jni = platformData->jniEnv; jstring jstrUrl = (*jni)->NewStringUTF(jni, curl); + if (!more)more = ""; jstring jstrMore = (*jni)->NewStringUTF(jni, more); glfm__callJavaMethodWithArgs(jni, app->activity->clazz, "openOtherApp",