diff --git a/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java b/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java index 7ef5ad8..8186c6c 100644 --- a/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java +++ b/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java @@ -85,11 +85,6 @@ public void onCreate(Bundle savedInstanceState) @Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { - if(requestCode!=CHOOSE_PHP_CODE && requestCode!=CHOOSE_JAVA_CODE) - { - super.onActivityResult(requestCode,resultCode,data); - return; - } if(data==null) { return; @@ -116,7 +111,7 @@ public void run() public void run() { processing_dialog.dismiss(); - fragment_main.refreshEnabled(); + fragment_main.refreshElements(); toast(R.string.message_install_success); } }); @@ -179,7 +174,7 @@ public boolean onOptionsItemSelected(MenuItem item) case R.id.menu_kill: ServerUtils.killServer(); stopService(serverIntent); - fragment_main.refreshEnabled(); + fragment_main.refreshElements(); break; default: return super.onOptionsItemSelected(item); @@ -205,7 +200,7 @@ public boolean handleMessage(Message msg) { case ACTION_STOP_SERVICE: stopService(serverIntent); - fragment_main.refreshEnabled(); + fragment_main.refreshElements(); break; default: return false; diff --git a/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java b/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java index 05a2bea..1bc4489 100644 --- a/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java +++ b/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java @@ -4,7 +4,6 @@ import android.content.*; import android.os.*; import android.text.*; -import android.util.*; import android.view.*; import android.widget.*; @@ -94,11 +93,19 @@ public void onClick(View arg0) label_log.setTextSize(ConfigProvider.getInt("ConsoleFontSize",16)); label_current.setTextSize(ConfigProvider.getInt("ConsoleFontSize",16)); - postAppend(currentLog); + label_log.setText(currentLog); + label_current.setText(currentLine); super.onStart(); } + @Override + public void onResume() + { + super.onResume(); + scrollToBottom(); + } + @Override public void onStop() { @@ -142,7 +149,14 @@ public boolean handleMessage(Message msg) { case MESSAGE_APPEND: label_log.append((CharSequence)msg.obj); - scrollToBottom(); + label_log.post(new Runnable() + { + @Override + public void run() + { + scrollToBottom(); + } + }); break; case MESSAGE_UPDATE_LINE: label_current.setText(currentLine); @@ -153,13 +167,12 @@ public boolean handleMessage(Message msg) public void scrollToBottom() { - scroll_log.smoothScrollBy(0,scroll_log.getChildAt(scroll_log.getChildCount() - 1) - .getBottom() + scroll_log.getPaddingBottom() - scroll_log.getScrollY() - scroll_log.getHeight()); + scroll_log.smoothScrollBy(0,scroll_log.getChildAt(scroll_log.getChildCount() - 1).getBottom()); } private void sendCommand() { - log("> " + edit_command.getText()); + logLine("> " + edit_command.getText()); ServerUtils.writeCommand(edit_command.getText().toString()); edit_command.setText(""); } @@ -189,7 +202,7 @@ public static boolean postNewLine() return false; } - public static void log(String line) + public static void logLine(String line) { if(!currentLine.equals("")) { @@ -204,14 +217,12 @@ public static void log(String line) { line=line.substring(index + 4); } - long timeSpan=System.currentTimeMillis(); line=TerminalColorConverter.control2html(line.replace("&","&") .replace("<","<") .replace(">",">") .replace(" "," ") .replace("\u001b[1G","") .replace("\u001b[K","")); - Log.d("Parse Time",(System.currentTimeMillis() - timeSpan) + "ms"); } currentLine=ansiMode ? Html.fromHtml(line) : line; postNewLine(); diff --git a/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java b/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java index 912bb9d..2cb3d1d 100644 --- a/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java +++ b/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java @@ -23,6 +23,7 @@ public class MainFragment extends Fragment implements View.OnClickListener public String[] jenkins_nukkit, jenkins_pocketmine; + public TextView label_path_tip=null; public Button button_start=null, button_stop=null, button_mount=null; public RadioButton radio_pocketmine=null, radio_nukkit=null; @@ -58,6 +59,8 @@ public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle save @Override public void onStart() { + label_path_tip=(TextView)main.findViewById(R.id.label_path_tip); + button_stop=(Button)main.findViewById(R.id.button_stop); button_stop.setOnClickListener(this); button_start=(Button)main.findViewById(R.id.button_start); @@ -73,7 +76,7 @@ public void onStart() radio_pocketmine.setOnClickListener(this); reloadUrls(); - refreshEnabled(); + refreshElements(); super.onStart(); } @@ -198,7 +201,7 @@ public void onClick(View v) default: return; } - refreshEnabled(); + refreshElements(); } public void reloadUrls() @@ -247,25 +250,39 @@ public void reloadUrls() } } - public void refreshEnabled() + public void refreshElements() { boolean running=ServerUtils.isRunning(); button_stop.setEnabled(running); button_mount.setEnabled(!running); radio_nukkit.setEnabled(!running); radio_pocketmine.setEnabled(!running); + label_path_tip.setText(""); - // Fake running state to prevent user starting server without Java/PHP installed if(nukkitMode) { + button_mount.setVisibility(View.VISIBLE); + if(!new File(ServerUtils.getDataDirectory(),"Nukkit.jar").exists()) + { + label_path_tip.setText(R.string.label_nukkit_to); + } if(!ServerUtils.installedJava()) { running=true; } } - else if(!ServerUtils.installedPHP()) + else { - running=true; + button_mount.setVisibility(View.GONE); + if(!new File(ServerUtils.getDataDirectory(),"PocketMine-MP.phar").exists() && !new File(ServerUtils + .getDataDirectory(),"src").exists()) + { + label_path_tip.setText(R.string.label_pocketMine_to); + } + if(!ServerUtils.installedPHP()) + { + running=true; + } } button_start.setEnabled(!running); } diff --git a/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java b/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java index 78a2f17..43698bc 100644 --- a/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java +++ b/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java @@ -154,15 +154,7 @@ public void run() case '\r': continue; case '\n': - String line=s.toString(); - /*if(line.startsWith("\u001b]0;")) - { - ConsoleFragment.postTitle(line.substring(8)); - } - else*/ - { - ConsoleFragment.log(line); - } + ConsoleFragment.logLine(s.toString()); case '\u0007': s.setLength(0); break; @@ -193,7 +185,7 @@ public void run() } } } - ConsoleFragment.log("[PE Server] Server was stopped."); + ConsoleFragment.logLine("[PE Server] Server was stopped."); MainActivity.postStopService(); } }; @@ -201,8 +193,8 @@ public void run() } catch(Exception e) { - ConsoleFragment.log("[PE Server] Unable to start " + (MainActivity.nukkitMode ? "Java" : "PHP") + "."); - ConsoleFragment.log(e.toString()); + ConsoleFragment.logLine("[PE Server] Unable to start " + (MainActivity.nukkitMode ? "Java" : "PHP") + "."); + ConsoleFragment.logLine(e.toString()); MainActivity.postStopService(); killServer(); } @@ -222,13 +214,33 @@ public static boolean writeCommand(String cmd) return true; } + public static void walkSetPermission(File folder) + { + folder.setReadable(true,true); + folder.setExecutable(true,true); + File[] files=folder.listFiles(); + if(files==null) + { + return; + } + for(File file : files) + { + file.setReadable(true,true); + file.setExecutable(true,true); + if(file.isDirectory()) + { + walkSetPermission(file); + } + } + } + public static void setPermission() { try { if(MainActivity.nukkitMode) { - Runtime.getRuntime().exec("./busybox chmod -R 755 java",new String[0],appDirectory).waitFor(); + walkSetPermission(new File(appDirectory,"java")); } else { diff --git a/app/src/main/res/drawable-hdpi/content_clear.png b/app/src/main/res/drawable-hdpi/content_clear.png new file mode 100644 index 0000000..1791cd7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/content_clear.png differ diff --git a/app/src/main/res/drawable-hdpi/content_copy.png b/app/src/main/res/drawable-hdpi/content_copy.png index 72c6bc6..d6bd2ec 100644 Binary files a/app/src/main/res/drawable-hdpi/content_copy.png and b/app/src/main/res/drawable-hdpi/content_copy.png differ diff --git a/app/src/main/res/drawable-hdpi/content_discard.png b/app/src/main/res/drawable-hdpi/content_discard.png deleted file mode 100644 index ffd19d9..0000000 Binary files a/app/src/main/res/drawable-hdpi/content_discard.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/content_clear.png b/app/src/main/res/drawable-mdpi/content_clear.png new file mode 100644 index 0000000..c02ac52 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/content_clear.png differ diff --git a/app/src/main/res/drawable-mdpi/content_copy.png b/app/src/main/res/drawable-mdpi/content_copy.png new file mode 100644 index 0000000..c8c66d8 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/content_copy.png differ diff --git a/app/src/main/res/drawable-xhdpi/content_clear.png b/app/src/main/res/drawable-xhdpi/content_clear.png new file mode 100644 index 0000000..27db318 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/content_clear.png differ diff --git a/app/src/main/res/drawable-xhdpi/content_copy.png b/app/src/main/res/drawable-xhdpi/content_copy.png new file mode 100644 index 0000000..7258bf0 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/content_copy.png differ diff --git a/app/src/main/res/drawable-xxhdpi/content_clear.png b/app/src/main/res/drawable-xxhdpi/content_clear.png new file mode 100644 index 0000000..6e68be9 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/content_clear.png differ diff --git a/app/src/main/res/drawable-xxhdpi/content_copy.png b/app/src/main/res/drawable-xxhdpi/content_copy.png new file mode 100644 index 0000000..a5b19ba Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/content_copy.png differ diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index 9d7e6d1..47cb58a 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -59,6 +59,7 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" + android:layout_marginBottom="10dip" android:weightSum="2"> - - + android:layout_height="wrap_content"/> diff --git a/app/src/main/res/menu/console.xml b/app/src/main/res/menu/console.xml index 6a8bd48..9711789 100644 --- a/app/src/main/res/menu/console.xml +++ b/app/src/main/res/menu/console.xml @@ -3,7 +3,7 @@