Skip to content

Commit

Permalink
fix android open other app , update ui
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalgust committed May 15, 2024
1 parent 9a7c77b commit 19e198e
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 13 deletions.
14 changes: 13 additions & 1 deletion extlib/xgui/src/main/java/org/mini/gui/GButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
54 changes: 54 additions & 0 deletions extlib/xgui/src/main/java/org/mini/gui/GColorSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 14 additions & 1 deletion extlib/xgui/src/main/java/org/mini/gui/GListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions extlib/xgui/src/main/java/org/mini/gui/GToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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("⬆");
Expand Down Expand Up @@ -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) -> {
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions extlib/xgui/src/main/java/org/mini/layout/XButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class XButton
//
protected String pic;
protected int addon = XDef.SPACING_BUTTON_ADD;
float[] preiconColor;

protected GButton button;

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions extlib/xgui/src/main/java/org/mini/layout/XList.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected static class ListItem {
boolean selected;
float[] color;
String preicon;
float[] preiconColor;
}

protected Vector items = new Vector();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions mobile/c/glfm/glfm_platform_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 19e198e

Please sign in to comment.