Skip to content

Commit 3a848c0

Browse files
committed
[platform] remove app icon and get bigger app name
- remove app icon - get app name bigger - support one env variable to start app
1 parent fa773dc commit 3a848c0

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

app/src/main/java/seven/drawalive/nodebase/NodeBase.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.net.NetworkInterface;
2929
import java.util.ArrayList;
3030
import java.util.Collections;
31+
import java.util.HashMap;
3132
import java.util.List;
3233

3334

@@ -147,6 +148,12 @@ protected LinearLayout prepareLayout() {
147148
subview.addView(_btnRefreshAppList);
148149
view.addView(subview);
149150

151+
_txtEnv = new EditText(this);
152+
_txtEnv.setText("");
153+
_txtEnv.setHint("Environment KeyValue ...");
154+
_txtEnv.setVisibility(View.GONE);
155+
view.addView(_txtEnv);
156+
150157
_txtAppFilter = new EditText(this);
151158
_txtAppFilter.setText("");
152159
_txtAppFilter.setHint("Filter app ...");
@@ -268,12 +275,16 @@ protected void refreshAppList() {
268275
if ("node_modules".compareTo(name) == 0) continue;
269276
if (name.indexOf('.') == 0) continue;
270277
Log.i("UI:AppList", f.getAbsolutePath());
271-
NodeBaseApp app = new NodeBaseApp(this, new AppAction(this), f);
278+
HashMap<String, Object> env = new HashMap<>();
279+
env.put("appdir", f);
280+
env.put("txtenv", _txtEnv);
281+
NodeBaseApp app = new NodeBaseApp(this, new AppAction(this), env);
272282
_appList.add(app);
273283
_panelAppList.addView(app);
274284
}
275285
if (_appList.size() > 0) {
276286
_txtAppFilter.setText("");
287+
_txtEnv.setVisibility(View.VISIBLE);
277288
_txtAppFilter.setVisibility(View.VISIBLE);
278289
}
279290
} catch (Exception e) {
@@ -341,6 +352,7 @@ private void show_node_version() {
341352
private TextView _labelIp;
342353
private EditText _txtAppRootDir;
343354
private Button _btnRefreshAppList;
355+
private EditText _txtEnv;
344356
private EditText _txtAppFilter;
345357
private LinearLayout _panelAppList;
346358
}

app/src/main/java/seven/drawalive/nodebase/NodeBaseApp.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Bitmap;
55
import android.graphics.BitmapFactory;
66
import android.util.Log;
7+
import android.util.TypedValue;
78
import android.view.View;
89
import android.widget.ArrayAdapter;
910
import android.widget.Button;
@@ -16,13 +17,15 @@
1617
import android.widget.TextView;
1718

1819
import java.io.File;
20+
import java.util.HashMap;
1921

2022
public class NodeBaseApp extends LinearLayout {
21-
public NodeBaseApp(Context context, NodeBase.AppAction delegate, File appdir) {
23+
public NodeBaseApp(Context context, NodeBase.AppAction delegate, HashMap<String, Object> env) {
2224
super(context);
2325
setOrientation(LinearLayout.VERTICAL);
26+
_env = env;
2427
_delegate = delegate;
25-
_appdir = appdir;
28+
_appdir = (File)env.get("appdir");
2629

2730
collectAppInformation();
2831
prepareLayout();
@@ -68,32 +71,13 @@ public void prepareLayout() {
6871
LinearLayout frame = new LinearLayout(context);
6972
frame.setOrientation(LinearLayout.HORIZONTAL);
7073

71-
ImageView image = new ImageView(context);
72-
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(64, 64);
73-
params.setMargins(1, 1, 1, 1);
74-
image.setLayoutParams(params);
75-
image.setMaxHeight(64);
76-
image.setMaxWidth(64);
77-
image.setMinimumHeight(64);
78-
image.setMinimumWidth(64);
79-
try {
80-
File imgfile = new File(_appdir.getAbsolutePath().concat("/icon.png"));
81-
if (imgfile.exists()) {
82-
Bitmap bmp = BitmapFactory.decodeFile(imgfile.getAbsolutePath());
83-
image.setImageBitmap(bmp);
84-
} else {
85-
image.setBackgroundResource(R.drawable.default_icon);
86-
}
87-
} catch (Exception e) {
88-
}
89-
frame.addView(image);
90-
9174
LinearLayout contents = new LinearLayout(context);
9275
contents.setOrientation(LinearLayout.VERTICAL);
9376

9477
TextView label;
9578
label = new TextView(context);
96-
label.setText(String.format("\n=============== App: %s ===", _appdir.getName()));
79+
label.setText(String.format("\nApp: %s", _appdir.getName()));
80+
label.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);
9781
contents.addView(label);
9882
label = new TextView(context);
9983
label.setText(_readme);
@@ -154,7 +138,8 @@ public void onClick(View view) {
154138
"start",
155139
_appdir.getAbsolutePath(),
156140
String.valueOf(_listEntries.getSelectedItem()),
157-
_txtParams.getText().toString()
141+
_txtParams.getText().toString(),
142+
((EditText)_env.get("txtenv")).getText().toString()
158143
});
159144
}
160145
});
@@ -197,6 +182,7 @@ public String getAppName() {
197182
return _appdir.getName();
198183
}
199184

185+
private HashMap<String, Object> _env;
200186
private NodeBase.AppAction _delegate;
201187
private File _appdir;
202188
private String[] _appentries;

app/src/main/java/seven/drawalive/nodebase/NodeBaseServer.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
3434
case "start":
3535
Log.i("Server:Command",
3636
String.format("Server starts for \"%s\" at \"%s\"", args[2], args[1]));
37-
startNode(args[1], args[2], args[3]);
37+
startNode(args[1], args[2], args[3], args[4]);
3838
break;
3939
case "restart":
4040
Log.i("Server:Command",
@@ -113,13 +113,14 @@ public static String nodeVersion(String _workdir) {
113113
}
114114
}
115115

116-
public int startNode(String appdir, String appentry, String appparams) {
116+
public int startNode(String appdir, String appentry, String appparams, String env) {
117117
if (!_valid) return -1;
118118
int result = 0;
119119
_crash = true;
120120
_appdir = appdir;
121121
_appentry = appentry;
122122
_appparams = appparams;
123+
_env = env;
123124
Utils.setServiceInfo(new String[] {_appdir, _appentry});
124125

125126
if (_node != null) {
@@ -144,7 +145,13 @@ public int startNode(String appdir, String appentry, String appparams) {
144145
}
145146
Log.i("Server:Start", String.format("Command - %s", cmd));
146147
try {
147-
_node = new NodeMonitor(this, Runtime.getRuntime().exec(cmd));
148+
if (_env != null && _env.length() > 0) {
149+
_node = new NodeMonitor(this, Runtime.getRuntime().exec(
150+
cmd, new String[] { _env }
151+
));
152+
} else {
153+
_node = new NodeMonitor(this, Runtime.getRuntime().exec(cmd));
154+
}
148155
_node.start();
149156
} catch (Exception e) {
150157
Log.e("Server:Start", "Cannot start \"node\"", e);
@@ -158,7 +165,7 @@ public int restartNode() {
158165
if (!_valid) return -1;
159166
int result = 0;
160167
stopNode();
161-
startNode(_appdir, _appentry, _appparams);
168+
startNode(_appdir, _appentry, _appparams, _env);
162169
return result;
163170
}
164171

@@ -183,7 +190,7 @@ public void onNodeTerminated() {
183190
}
184191

185192
private boolean _valid, _crash;
186-
private String _workdir, _appdir, _appentry, _appparams;
193+
private String _workdir, _appdir, _appentry, _appparams, _env;
187194
private NodeMonitor _node;
188195

189196
}
-538 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)