Skip to content

Commit

Permalink
add main menu to app manager
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalgust committed Jun 30, 2024
1 parent bcd305c commit 88309ec
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 29 deletions.
57 changes: 48 additions & 9 deletions extlib/xgui/src/main/java/org/mini/apploader/AppManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class AppManager extends GApplication {
static final String APP_UPGRADE_BTN = "APP_UPGRADE_BTN";
static final String APP_DELETE_BTN = "APP_DELETE_BTN";

static final String STR_PLUGIN = "PLUGIN";
static final String STR_DISCOVERY = "DISCOVERY";
static final String STR_MY = "MY";
static final String STR_EXIT = "Exit";
static final String STR_SETTING = "SETTING";
static final String STR_TITLE = "PLUGIN MANAGER";
Expand Down Expand Up @@ -64,18 +67,18 @@ public class AppManager extends GApplication {
static private void regStrings() {
GLanguage.addString(STR_SETTING, new String[]{STR_SETTING, "设置", "设置"});
GLanguage.addString(STR_EXIT, new String[]{STR_EXIT, "退出", "退出"});
GLanguage.addString(STR_TITLE, new String[]{STR_TITLE, "组件管理器", "組件管理器"});
GLanguage.addString(STR_TITLE, new String[]{STR_TITLE, "组件管理器", "元件管理器"});
GLanguage.addString(STR_START_WEB_SRV_FOR_UPLOAD, new String[]{STR_START_WEB_SRV_FOR_UPLOAD, "启动Web服务器上传", "啟動Web伺服器上傳"});
GLanguage.addString(STR_DOWN_APP_FROM_WEB, new String[]{STR_DOWN_APP_FROM_WEB, "从网站下载组件", "從網站下載組件"});
GLanguage.addString(STR_DOWN_APP_FROM_WEB, new String[]{STR_DOWN_APP_FROM_WEB, "从网站下载组件", "從網站下載元件"});
GLanguage.addString(STR_DOWNLOAD, new String[]{"", "下载", "下載"});
GLanguage.addString(STR_START, new String[]{"", "启动", "啟動"});
GLanguage.addString(STR_STOP, new String[]{"", "停止", "停止"});
GLanguage.addString(STR_CLOSE, new String[]{"Close", "关闭", "關閉"});
GLanguage.addString(STR_WEB_LISTEN_ON, new String[]{STR_WEB_LISTEN_ON, "Web服务器临听 : ", "Web伺服器臨聽 : "});
GLanguage.addString(STR_APP_LIST, new String[]{STR_APP_LIST, "组件列表 : ", "組件列表"});
GLanguage.addString(STR_APP_LIST, new String[]{STR_APP_LIST, "组件列表 : ", "元件列表"});
GLanguage.addString(STR_BACK, new String[]{STR_BACK, "返回", "返回"});
GLanguage.addString(STR_RUN, new String[]{STR_RUN, "运行", "運行"});
GLanguage.addString(STR_SET_AS_BOOT, new String[]{STR_SET_AS_BOOT, "置顶组件", "置頂組件"});
GLanguage.addString(STR_SET_AS_BOOT, new String[]{STR_SET_AS_BOOT, "置顶组件", "置頂元件"});
GLanguage.addString(STR_UPGRADE, new String[]{STR_UPGRADE, "升级", "升級"});
GLanguage.addString(STR_DELETE, new String[]{STR_DELETE, "删除", "刪除"});
GLanguage.addString(STR_VERSION, new String[]{STR_VERSION, "版本: ", "版本: "});
Expand All @@ -88,14 +91,17 @@ static private void regStrings() {
GLanguage.addString(STR_UPLOAD_FILE, new String[]{STR_UPLOAD_FILE, "文件上传结束", "文件上傳結束"});
GLanguage.addString(STR_SUCCESS, new String[]{STR_SUCCESS, "成功", "成功"});
GLanguage.addString(STR_FAIL, new String[]{STR_FAIL, "失败", "失敗"});
GLanguage.addString(STR_OPEN_APP_FAIL, new String[]{STR_OPEN_APP_FAIL, "打开组件失败", "打開組件失敗"});
GLanguage.addString(STR_OPEN_APP_FAIL, new String[]{STR_OPEN_APP_FAIL, "打开组件失败", "打開元件失敗"});
GLanguage.addString(STR_BRIGHT_STYLE, new String[]{STR_BRIGHT_STYLE, "浅色外观", "淺色外觀"});
GLanguage.addString(STR_DARK_STYLE, new String[]{STR_DARK_STYLE, "深色外观", "深色外觀"});
GLanguage.addString(STR_MESSAGE, new String[]{STR_MESSAGE, "信息", "信息"});
GLanguage.addString(STR_CONFIRM_DELETE, new String[]{STR_CONFIRM_DELETE, "您要删除组件吗", "您要刪除組件嗎"});
GLanguage.addString(STR_APP_NOT_RUNNING, new String[]{STR_APP_NOT_RUNNING, "组件没有运行", "組件沒有運行"});
GLanguage.addString(STR_MESSAGE, new String[]{STR_MESSAGE, "信息", "資訊"});
GLanguage.addString(STR_CONFIRM_DELETE, new String[]{STR_CONFIRM_DELETE, "您要删除组件吗", "您要刪除元件嗎"});
GLanguage.addString(STR_APP_NOT_RUNNING, new String[]{STR_APP_NOT_RUNNING, "组件没有运行", "元件沒有運行"});
GLanguage.addString(STR_INSTALL_FROM_LOCAL, new String[]{STR_INSTALL_FROM_LOCAL, "选取文件安装", "選取檔案安裝"});
GLanguage.addString(STR_SELECT_FILE, new String[]{"", "安装", "安裝"});
GLanguage.addString(STR_PLUGIN, new String[]{STR_PLUGIN, "组件", "元件"});
GLanguage.addString(STR_DISCOVERY, new String[]{STR_DISCOVERY, "发现", "發現"});
GLanguage.addString(STR_MY, new String[]{STR_MY, "我的", "我的"});
}

static AppManager instance = new AppManager();
Expand Down Expand Up @@ -220,6 +226,8 @@ public void init() {
}
});
add(getMainPanel(this));
int i = AppLoader.getGuiStyle();
setStyleButton(i);
}


Expand Down Expand Up @@ -335,7 +343,7 @@ public void action(GObject gobj) {
mainPanelShowLeft();
break;
case "BT_BACK1":
mainSlot.moveTo(0, 0);
mainSlot.moveTo(4, 0);
break;
case "BT_STARTWEB":
GButton uploadbtn = (GButton) gobj;
Expand Down Expand Up @@ -489,11 +497,33 @@ public boolean accept(File file) {
case "LI_BRIGHT":
GToolkit.setStyle(new GStyleBright());
AppLoader.setGuiStyle(0);
setStyleButton(0);
break;
case "LI_DARK":
GToolkit.setStyle(new GStyleDark());
AppLoader.setGuiStyle(1);
setStyleButton(1);
break;
case "MI_PLUGINMGR": {
mainSlot.moveTo(0, 0);
break;
}
case "MI_DISCOVERY": {
mainSlot.moveTo(3, 0);
break;
}
case "MI_MY": {
mainSlot.moveTo(4, 0);
break;
}
case "BT_STYLE": {
int i = AppLoader.getGuiStyle();
i = i == 0 ? 1 : 0;
setStyleButton(i);
GToolkit.setStyle(i == 0 ? new GStyleBright() : new GStyleDark());
AppLoader.setGuiStyle(i);
break;
}
}
}

Expand Down Expand Up @@ -532,6 +562,15 @@ MiniHttpClient.DownloadCompletedHandle getDownloadCallback() {
};
}

void setStyleButton(int i) {
GButton bt = GToolkit.getComponent(mgrForm, "BT_STYLE");
if (i == 0) {
bt.setPreIcon("●");
} else {
bt.setPreIcon("◑");
}
}

void reloadAppList() {
if (appList == null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion extlib/xgui/src/main/java/org/mini/gui/GColorSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @author gust
*/
class GColorSelector extends GObject {
public class GColorSelector extends GObject {

/**
* these color can't change by user
Expand Down
4 changes: 2 additions & 2 deletions extlib/xgui/src/main/java/org/mini/gui/GListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public boolean paint(long vg) {
float tw = w - (pad * 2);
float th = list.list_item_heigh - pad;

nvgSave(vg);
// nvgSave(vg);
Nanovg.nvgScissor(vg, tx, ty, tw, th);


Expand Down Expand Up @@ -196,7 +196,7 @@ public boolean paint(long vg) {
}
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);
Nanovg.nvgRestore(vg);
// Nanovg.nvgRestore(vg);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions extlib/xgui/src/main/java/org/mini/gui/GMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void reAlign() {
* @return
*/
public boolean paint(long vg) {
super.paint(vg);

float x = getX();
float y = getY();
float w = getW();
Expand Down Expand Up @@ -146,7 +146,7 @@ public boolean paint(long vg) {
nvgFill(vg);
}
}

super.paint(vg);
return true;
}

Expand Down
19 changes: 10 additions & 9 deletions extlib/xgui/src/main/java/org/mini/gui/GMenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setText(String t) {
nvgFontSize(vg, GToolkit.getStyle().getTextFontSize());
nvgFontFace(vg, GToolkit.getFontWord());
nvgTextMetrics(vg, null, null, lineh);
box = GToolkit.getTextBoundle(vg, t, getW(), GToolkit.getStyle().getTextFontSize());
box = GToolkit.getTextBoundle(vg, t, GCallBack.getInstance().getDeviceWidth(), GToolkit.getStyle().getTextFontSize());
}

boolean isSelected() {
Expand Down Expand Up @@ -130,20 +130,20 @@ public boolean paint(long vg) {

if (img != null) {//有图
if (text != null) {//有文字
if (dh > lineh[0] * 2) { //上图下文排列
img_h = dh * .65f - pad - lineh[0];
if (dh > lineh[0] * 3) { //上图下文排列
img_h = dh - pad * 3 - lineh[0];
img_x = dx + dw / 2 - img_h / 2;
img_w = img_h;
img_y = dy + dh * .2f;
img_y = dy + pad;
txt_x = dx + dw / 2;
txt_y = img_y + img_h + pad + lineh[0] / 2;
} else { //前图后文
img_h = dh * .7f - pad;
img_h = dh * .8f - pad;
img_w = img_h;
img_x = dx + dw * .5f - pad - (img_w + box[WIDTH]) * .5f;
img_y = dy + dh * .2f;
txt_x = dx + dw * .5f + img_w * .5f + pad;
txt_y = img_y + pad + lineh[0] / 2;
img_x = dx + dw * .5f - pad * 2 - img_w - (box[WIDTH]) * .5f;
img_y = dy + dh * .1f;
txt_x = img_x + img_w + pad * 2 + box[WIDTH] * .5f;
txt_y = dy + dh * .5f;
}
} else {
img_h = dh * .75f - pad;
Expand All @@ -169,6 +169,7 @@ public boolean paint(long vg) {
}
//画文字
if (text != null) {
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
byte[] b = toCstyleBytes(text);
nvgFillColor(vg, GToolkit.getStyle().getTextShadowColor());
Nanovg.nvgTextJni(vg, txt_x + 1, txt_y + 1, b, 0, b.length);
Expand Down
4 changes: 0 additions & 4 deletions extlib/xgui/src/main/java/org/mini/layout/XMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ static class MenuItem {

protected Vector items = new Vector();
protected boolean contextMenu = false;
protected boolean fixed = true;

protected GMenu menu;

Expand All @@ -40,8 +39,6 @@ protected void parseMoreAttribute(String attName, String attValue) {
super.parseMoreAttribute(attName, attValue);
if (attName.equals("contextmenu")) {
contextMenu = "0".equals(attValue) ? false : true;
} else if (attName.equals("fixed")) {
fixed = "0".equals(attValue) ? false : true;
}
}

Expand Down Expand Up @@ -151,7 +148,6 @@ protected void createAndSetGui() {
gli.setOnClinkScript(item.onClick);
}
menu.setContextMenu(contextMenu);
menu.setFixed(fixed);
} else {
menu.setLocation(x, y);
menu.setSize(width, height);
Expand Down
4 changes: 4 additions & 0 deletions extlib/xgui/src/main/java/org/mini/layout/XObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public abstract class XObject implements GLayout {

protected String onStateChangeScript = null; //state change exec

protected boolean fixed = false;
//

XmlExtAssist assist;
Expand Down Expand Up @@ -148,6 +149,8 @@ protected void parseMoreAttribute(String attName, String attValue) {
enable = "0".equals(attValue) ? false : true;
} else if (attName.equals("move")) { // viewslot move mode
moveMode = attValue;
} else if (attName.equals("fixed")) {
fixed = "0".equals(attValue) ? false : true;
} else if (attName.equals("w")) {
if (attValue.equals("float")) {
hfloat = true;
Expand Down Expand Up @@ -231,6 +234,7 @@ public final void initGuiMore() {
gui.setActionListener(getRoot().getEventHandler());
gui.setStateChangeListener(getRoot().getEventHandler());
gui.setOnStateChangeScript(onStateChangeScript);
gui.setFixed(fixed);
if (fly) {
gui.setFlyListener(getRoot().getEventHandler());
}
Expand Down
29 changes: 27 additions & 2 deletions extlib/xgui/src/main/resource/res/ui/AppManager.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table name="ROOT_PAN">
<table name="ROOT_PAN" h="100%" w="100%">
<tr h="{STATEBAR_HEIGHT}" w="100%">
<td>
<label w="100%"></label>
Expand All @@ -15,7 +15,7 @@
<tr w="100%">
<td w="float"></td>
<td w="50">
<button name="BT_SETTING" w="50" h="30" preicon=""></button>
<button name="BT_STYLE" w="50" h="30" preicon=""></button>
</td>
</tr>
</table>
Expand Down Expand Up @@ -88,7 +88,32 @@
<label></label>
</viewport>
</panel>
<panel w="100%" h="100%" move="fixed" align="hcenter,top">
<viewport name="PAN_DISCOVERY" w="98%" h="100%">
<label w="100%" h="30" align="hcenter,vcenter">{DISCOVERY}</label>

<label></label>
</viewport>
</panel>
<panel w="100%" h="100%" move="fixed" align="hcenter,top">
<viewport name="PAN_MY" w="98%" h="100%">
<label w="100%" h="30" align="hcenter,vcenter">{MY}</label>
<br/>
<button name="BT_SETTING" w="100%" h="40" preicon="">{SETTING}</button>
<br/>
<label></label>
</viewport>
</panel>
</viewslot>
</td>
</tr>
<tr h="50" w="100%">
<td w="100%" h="100%">
<menu name="MENU_MAIN" w="100%" h="100%">
<mi name="MI_PLUGINMGR">{PLUGIN}</mi>
<mi name="MI_DISCOVERY">{DISCOVERY}</mi>
<mi name="MI_MY">{MY}</mi>
</menu>
</td>
</tr>
</table>

0 comments on commit 88309ec

Please sign in to comment.