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 Jul 1, 2017
1 parent 279d786 commit 0ed1889
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 105 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
101 changes: 78 additions & 23 deletions app/src/main/java/moe/berd/pocket_server/activity/ConsoleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +56,7 @@ public boolean onKey(View p1,int keyCode,KeyEvent p3)
return false;
}
});

button_command.setOnClickListener(new View.OnClickListener()
{
@Override
Expand All @@ -63,73 +67,124 @@ 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)
{
switch(item.getItemId())
{
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:
return super.onOptionsItemSelected(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("<","&lt;")
.replace(">","&gt;")
.replace(" ","&nbsp;")
.replace("\u001b[1G","")
.replace("\u001b[K","")) + "<br />";
.replace("\u001b[K",""));
}
if(!currentLine.equals(""))
{
currentLog.append(MainActivity.ansiMode ? Html.fromHtml("<br />") : "\n");
postAppend(MainActivity.ansiMode ? Html.fromHtml("<br />") : "\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);
}
}
Loading

0 comments on commit 0ed1889

Please sign in to comment.