Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Ready to release
Browse files Browse the repository at this point in the history
  • Loading branch information
fengberd committed Sep 3, 2017
1 parent 2ff6f15 commit 1c8799c
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.*;
import android.os.*;
import android.text.*;
import android.util.*;
import android.view.*;
import android.widget.*;

Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
Expand All @@ -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("");
}
Expand Down Expand Up @@ -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(""))
{
Expand All @@ -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("<","&lt;")
.replace(">","&gt;")
.replace(" ","&nbsp;")
.replace("\u001b[1G","")
.replace("\u001b[K",""));
Log.d("Parse Time",(System.currentTimeMillis() - timeSpan) + "ms");
}
currentLine=ansiMode ? Html.fromHtml(line) : line;
postNewLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -73,7 +76,7 @@ public void onStart()
radio_pocketmine.setOnClickListener(this);

reloadUrls();
refreshEnabled();
refreshElements();

super.onStart();
}
Expand Down Expand Up @@ -198,7 +201,7 @@ public void onClick(View v)
default:
return;
}
refreshEnabled();
refreshElements();
}

public void reloadUrls()
Expand Down Expand Up @@ -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);
}
Expand Down
38 changes: 25 additions & 13 deletions app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,16 +185,16 @@ public void run()
}
}
}
ConsoleFragment.log("[PE Server] Server was stopped.");
ConsoleFragment.logLine("[PE Server] Server was stopped.");
MainActivity.postStopService();
}
};
tMonitor.start();
}
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();
}
Expand All @@ -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
{
Expand Down
Binary file added app/src/main/res/drawable-hdpi/content_clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/content_copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/drawable-hdpi/content_discard.png
Binary file not shown.
Binary file added app/src/main/res/drawable-mdpi/content_clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/content_copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/content_clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/content_copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/content_clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/content_copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dip"
android:weightSum="2">

<RadioButton
Expand All @@ -84,14 +85,9 @@
android:id="@+id/button_mount"/>

<TextView
android:layout_height="wrap_content"
android:id="@+id/label_path_tip"
android:layout_width="wrap_content"
android:text="@string/label_pocketMine_to"/>

<TextView
android:layout_height="wrap_content"
android:text="@string/label_nukkit_to"
android:layout_width="wrap_content"/>
android:layout_height="wrap_content"/>

</LinearLayout>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/console.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item
android:id="@+id/menu_clear"
android:title="@string/menu_clear"
android:icon="@drawable/content_discard"
android:icon="@drawable/content_clear"
android:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_copy"
Expand Down

0 comments on commit 1c8799c

Please sign in to comment.