From 0ed1889925c9e6ff1ab465865c4edc8db15885f1 Mon Sep 17 00:00:00 2001 From: fengberd Date: Sat, 1 Jul 2017 23:07:25 +0800 Subject: [PATCH] Ready to release. --- app/build.gradle | 6 +- .../activity/ConsoleActivity.java | 101 ++++++++++++++---- .../pocket_server/activity/MainActivity.java | 88 +++++++-------- .../berd/pocket_server/utils/ServerUtils.java | 30 +++--- .../utils/TerminalColorConverter.java | 28 +++-- app/src/main/res/layout/activity_console.xml | 10 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 8 files changed, 164 insertions(+), 105 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dd818fa..fd2877a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,14 +2,14 @@ apply plugin: 'com.android.application' android { compileSdkVersion 21 - buildToolsVersion "21.1.2" + buildToolsVersion '25.0.0' defaultConfig { applicationId "net.fengberd.minecraftpe_server" minSdkVersion 14 targetSdkVersion 21 - versionCode 1076 - versionName "1.0.7.6" + versionCode 1080 + versionName "1.0.8.0" } buildTypes { diff --git a/app/src/main/java/moe/berd/pocket_server/activity/ConsoleActivity.java b/app/src/main/java/moe/berd/pocket_server/activity/ConsoleActivity.java index efe8045..91e78fb 100644 --- a/app/src/main/java/moe/berd/pocket_server/activity/ConsoleActivity.java +++ b/app/src/main/java/moe/berd/pocket_server/activity/ConsoleActivity.java @@ -14,31 +14,35 @@ public class ConsoleActivity extends Activity implements Handler.Callback { + private static final int MESSAGE_APPEND=1, MESSAGE_TITLE=2, MESSAGE_UPDATE_LINE=3; + public static Handler logUpdateHandler=null; - - public ScrollView scroll_log; + + public ScrollView scroll_log=null; public Button button_command=null; - public TextView label_log=null; + public TextView label_log=null, label_current=null; public EditText edit_command=null; - + public static float font_size=16.0f; + public static CharSequence currentLine=""; public static SpannableStringBuilder currentLog=new SpannableStringBuilder(); - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_console); - + logUpdateHandler=new Handler(this); - + label_log=(TextView)findViewById(R.id.label_log); + label_current=(TextView)findViewById(R.id.label_current); edit_command=(EditText)findViewById(R.id.edit_command); scroll_log=(ScrollView)findViewById(R.id.logScrollView); button_command=(Button)findViewById(R.id.button_send); - + label_log.setTextSize(font_size); - + edit_command.setOnKeyListener(new View.OnKeyListener() { @Override @@ -52,7 +56,7 @@ public boolean onKey(View p1,int keyCode,KeyEvent p3) return false; } }); - + button_command.setOnClickListener(new View.OnClickListener() { @Override @@ -63,14 +67,14 @@ public void onClick(View arg0) }); postAppend(currentLog); } - + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.console,menu); return true; } - + @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -78,10 +82,12 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.menu_clear: currentLog=new SpannableStringBuilder(); + currentLine=""; label_log.setText(""); + label_current.setText(""); break; case R.id.menu_copy: - ((ClipboardManager)getSystemService(CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("test",currentLog)); + ((ClipboardManager)getSystemService(CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("PocketServer_ConsoleLog",currentLog)); Toast.makeText(this,R.string.message_copied,Toast.LENGTH_SHORT).show(); break; default: @@ -89,47 +95,96 @@ public boolean onOptionsItemSelected(MenuItem item) } return true; } - + @Override public boolean handleMessage(Message msg) { - label_log.append((CharSequence)msg.obj); - scroll_log.fullScroll(ScrollView.FOCUS_DOWN); + switch(msg.arg1) + { + case MESSAGE_APPEND: + label_log.append((CharSequence)msg.obj); + scroll_log.fullScroll(ScrollView.FOCUS_DOWN); + break; + case MESSAGE_TITLE: + setTitle((CharSequence)msg.obj); + break; + case MESSAGE_UPDATE_LINE: + label_current.setText((CharSequence)msg.obj); + break; + } return true; } - + private void sendCommand() { log("> " + edit_command.getText()); ServerUtils.writeCommand(edit_command.getText().toString()); edit_command.setText(""); } - + + public static boolean postTitle(CharSequence data) + { + if(logUpdateHandler!=null) + { + Message msg=new Message(); + msg.arg1=MESSAGE_TITLE; + msg.obj=data; + logUpdateHandler.sendMessage(msg); + return true; + } + return false; + } + public static boolean postAppend(CharSequence data) { if(logUpdateHandler!=null) { Message msg=new Message(); + msg.arg1=MESSAGE_APPEND; msg.obj=data; logUpdateHandler.sendMessage(msg); return true; } return false; } - + + public static boolean postNewLine(CharSequence data) + { + if(logUpdateHandler!=null) + { + Message msg=new Message(); + msg.arg1=MESSAGE_UPDATE_LINE; + msg.obj=data; + logUpdateHandler.sendMessage(msg); + return true; + } + return false; + } + public static void log(String line) { if(MainActivity.ansiMode) { + int index=0; + while((index=line.indexOf("\u001b[1G"))!=-1) + { + line=line.substring(index + 4); + } line=TerminalColorConverter.control2html(line.replace("&","&") .replace("<","<") .replace(">",">") .replace(" "," ") .replace("\u001b[1G","") - .replace("\u001b[K","")) + "
"; + .replace("\u001b[K","")); + } + if(!currentLine.equals("")) + { + currentLog.append(MainActivity.ansiMode ? Html.fromHtml("
") : "\n"); + postAppend(MainActivity.ansiMode ? Html.fromHtml("
") : "\n"); + currentLog.append(currentLine); + postAppend(currentLine); } - CharSequence result=MainActivity.ansiMode ? Html.fromHtml(line) : (line + "\n"); - currentLog.append(result); - postAppend(result); + currentLine=MainActivity.ansiMode ? Html.fromHtml(line) : line; + postNewLine(currentLine); } } 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 2102e98..aeeae51 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 @@ -25,16 +25,16 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC { public static Handler actionHandler=null; public final static int ACTION_STOP_SERVICE=1; - + public final static int CHOOSE_PHP_CODE=1; - + public static Intent serverIntent=null; public static SharedPreferences config=null; - + public static boolean isStarted=false, nukkitMode=false, ansiMode=false; - + public static String[] jenkins_nukkit, jenkins_pocketmine; - + public static void postMessage(int arg1,int arg2,Object obj) { if(actionHandler!=null) @@ -46,46 +46,46 @@ public static void postMessage(int arg1,int arg2,Object obj) actionHandler.sendMessage(msg); } } - + static { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); } - + public RadioButton radio_pocketmine=null, radio_nukkit=null; public CheckBox check_kusud=null, check_ansi=null; public Button button_start=null, button_stop=null; public SeekBar seekbar_fontsize=null; - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - + actionHandler=new Handler(this); serverIntent=new Intent(this,ServerService.class); - + config=getSharedPreferences("config",0); ansiMode=config.getBoolean("ANSIMode",ansiMode); nukkitMode=config.getBoolean("NukkitMode",nukkitMode); - + button_stop=(Button)findViewById(R.id.button_stop); button_stop.setOnClickListener(this); button_start=(Button)findViewById(R.id.button_start); button_start.setOnClickListener(this); findViewById(R.id.button_mount).setOnClickListener(this); - + check_ansi=(CheckBox)findViewById(R.id.check_ansi); check_ansi.setOnClickListener(this); check_kusud=(CheckBox)findViewById(R.id.check_kusud); check_kusud.setOnClickListener(this); - + radio_nukkit=(RadioButton)findViewById(R.id.radio_nukkit); radio_nukkit.setOnClickListener(this); radio_pocketmine=(RadioButton)findViewById(R.id.radio_pocketmine); radio_pocketmine.setOnClickListener(this); - + seekbar_fontsize=(SeekBar)findViewById(R.id.seekbar_fontsize); seekbar_fontsize.setProgress(config.getInt("ConsoleFontSize",16)); seekbar_fontsize.setMax(30); @@ -94,15 +94,15 @@ public void onCreate(Bundle savedInstanceState) @Override public void onProgressChanged(SeekBar p1,int p2,boolean p3) { - + } - + @Override public void onStartTrackingTouch(SeekBar p1) { - + } - + @Override public void onStopTrackingTouch(SeekBar p1) { @@ -110,20 +110,20 @@ public void onStopTrackingTouch(SeekBar p1) config.edit().putInt("ConsoleFontSize",p1.getProgress()).apply(); } }); - + check_ansi.setChecked(ansiMode); check_kusud.setChecked(config.getBoolean("KusudMode",false)); - + radio_nukkit.setChecked(nukkitMode); radio_pocketmine.setChecked(!nukkitMode); - + ServerUtils.setAppDirectory(this); ConsoleActivity.font_size=seekbar_fontsize.getProgress(); - + reloadUrls(); refreshEnabled(); } - + @Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { @@ -188,14 +188,14 @@ public void run() break; } } - + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main,menu); return true; } - + @Override public boolean onPrepareOptionsMenu(Menu menu) { @@ -205,7 +205,7 @@ public boolean onPrepareOptionsMenu(Menu menu) menu.findItem(R.id.menu_download_server).setEnabled(!isStarted); return true; } - + @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -386,7 +386,7 @@ public void run() } return true; } - + @Override public boolean handleMessage(Message msg) { @@ -400,7 +400,7 @@ public boolean handleMessage(Message msg) } return false; } - + @Override public void onClick(View v) { @@ -464,7 +464,7 @@ public void onClick(View v) } refreshEnabled(); } - + public void installBusybox() throws Exception { File busybox=new File(ServerUtils.getAppDirectory() + "/busybox"); @@ -475,7 +475,7 @@ public void installBusybox() throws Exception copyAsset("busybox",busybox); busybox.setExecutable(true,true); } - + public void refreshEnabled() { radio_nukkit.setEnabled(!isStarted); @@ -496,7 +496,7 @@ else if(!nukkitMode && !new File(ServerUtils.getAppDirectory(),"php").exists()) } button_stop.setEnabled(isStarted); } - + public void chooseFile(int code,String title) { Intent intent=new Intent(Intent.ACTION_GET_CONTENT); @@ -523,7 +523,7 @@ public void chooseFile(int code,String title) toast("No suitable file chooser."); } } - + public String getInternetString(String url) { try @@ -544,12 +544,12 @@ public String getInternetString(String url) } return null; } - + public void toast(int text) { toast(getString(text)); } - + public void toast(final String text) { final MainActivity instance=this; @@ -561,7 +561,7 @@ public void run() } }); } - + public void reloadUrls() { try @@ -607,7 +607,7 @@ public void reloadUrls() toast(getString(R.string.message_install_fail) + "\n" + e.toString()); } } - + public void downloadServer(String jenkins,File saveTo,final ProgressDialog dialog) { try @@ -626,7 +626,7 @@ public void downloadServer(String jenkins,File saveTo,final ProgressDialog dialo toast(e.getMessage()); } } - + public void copyAsset(String name,File target) throws Exception { target.delete(); @@ -641,7 +641,7 @@ public void copyAsset(String name,File target) throws Exception is.close(); os.close(); } - + public URLConnection openNetConnection(String url) throws Exception { final SSLContext sc=SSLContext.getInstance("SSL"); @@ -652,16 +652,16 @@ public URLConnection openNetConnection(String url) throws Exception @SuppressLint("TrustAllX509TrustManager") public void checkClientTrusted(X509Certificate[] p1,String p2) throws CertificateException { - + } - + @Override @SuppressLint("TrustAllX509TrustManager") public void checkServerTrusted(X509Certificate[] p1,String p2) throws CertificateException { - + } - + @Override public X509Certificate[] getAcceptedIssuers() { @@ -683,7 +683,7 @@ public boolean verify(String hostname,SSLSession session) connection.connect(); return connection; } - + public void downloadFile(String url,File saveTo,final ProgressDialog dialog) { OutputStream output=null; @@ -750,7 +750,7 @@ public void run() } catch(Exception ignored) { - + } } } 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 3b4eb32..ab63c7d 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 @@ -13,28 +13,28 @@ public class ServerUtils private static File appDirectory=null; private static File nukkitDataDirectory=new File(Environment.getExternalStorageDirectory(),"Nukkit"), pocketmineDataDirectory=new File(Environment .getExternalStorageDirectory(),"PocketMine"); - + private static Process serverProcess=null; private static InputStreamReader stdout=null; private static OutputStreamWriter stdin=null; - + public static void setAppDirectory(Context ctx) { appDirectory=ctx.getFilesDir().getParentFile(); } - + public static File getAppDirectory() { return appDirectory; } - + public static File getDataDirectory() { File dir=MainActivity.nukkitMode ? nukkitDataDirectory : pocketmineDataDirectory; dir.mkdirs(); return dir; } - + public static void killServer() { try @@ -46,10 +46,10 @@ public static void killServer() } catch(Exception ignored) { - + } } - + public static boolean isRunning() { try @@ -62,7 +62,7 @@ public static boolean isRunning() } return false; } - + public static void runServer() { File f=new File(getDataDirectory(),"tmp"); @@ -87,7 +87,7 @@ public static void runServer() } catch(Exception ignored) { - + } } String[] args=null; @@ -137,7 +137,11 @@ public void run() continue; case '\n': String line=s.toString(); - if(!line.startsWith("\u001b]0;")) + if(line.startsWith("\u001b]0;")) + { + ConsoleActivity.postTitle(line.substring(8)); + } + else { ConsoleActivity.log(line); } @@ -153,7 +157,7 @@ public void run() } catch(IOException ignored) { - + } catch(Exception e) { @@ -185,7 +189,7 @@ public void run() killServer(); } } - + public static void setPermission() { try @@ -204,7 +208,7 @@ public static void setPermission() e.printStackTrace(); } } - + public static boolean writeCommand(String cmd) { try diff --git a/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java b/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java index da7f1cd..2cffab0 100644 --- a/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java +++ b/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java @@ -44,11 +44,12 @@ public class TerminalColorConverter "#626262","#6c6c6c","#767676","#808080","#8a8a8a","#949494","#9e9e9e","#a8a8a8","#b2b2b2", "#bcbcbc","#c6c6c6","#d0d0d0","#dadada","#e4e4e4","#eeeeee" }; - + public static String control2html(String input) { - Matcher match=pattern_SGR.matcher(input); String foreground="", background=""; + Matcher match=pattern_SGR.matcher(input); + StringBuffer sb=new StringBuffer(input.length()); boolean need_close=false, bright=false, dim=false, italic=false, underscore=false, reverse=false; while(match.find()) { @@ -81,28 +82,18 @@ public static String control2html(String input) case 38: // RGB foreground if(i" : "") + "")); + match.appendReplacement(sb,String.format("%s",(need_close ? "" : ""),foreground,background,(italic ? ";font-style: italic" : ""),(underscore ? ";text-decoration: underline" : ""))); need_close=true; } - return input + (need_close ? "" : ""); + match.appendTail(sb); + if(need_close) + { + sb.append(""); + } + return sb.toString(); } } diff --git a/app/src/main/res/layout/activity_console.xml b/app/src/main/res/layout/activity_console.xml index 0d469c1..acb12b8 100644 --- a/app/src/main/res/layout/activity_console.xml +++ b/app/src/main/res/layout/activity_console.xml @@ -1,10 +1,8 @@ + + diff --git a/build.gradle b/build.gradle index f46d653..5966013 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.android.tools.build:gradle:2.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f..2a7f543 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Sat Jul 01 16:21:13 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip