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

Commit

Permalink
Update gradle & code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fengberd committed Apr 18, 2020
1 parent be093a8 commit 377059b
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 79 deletions.
8 changes: 4 additions & 4 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 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "net.fengberd.minecraftpe_server"
minSdkVersion 14
minSdkVersion 19
//noinspection OldTargetApi
targetSdkVersion 27
versionCode 1096
versionName "1.0.9.6"
versionCode 1100
versionName "1.1.0.0"
}

buildTypes {
Expand Down
31 changes: 10 additions & 21 deletions app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.pm.*;
import android.net.*;
import android.os.*;
import android.support.annotation.*;
import android.support.v4.app.*;
import android.support.v4.content.*;
import android.view.*;
Expand All @@ -18,7 +19,7 @@

import java.io.*;
import java.net.*;
import java.util.*;
import java.nio.charset.*;

import moe.berd.pocket_server.exception.*;
import moe.berd.pocket_server.fragment.*;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void onCreate(Bundle savedInstanceState)
}
catch(ABINotSupportedException e)
{
alertABIWarning(e.binaryName,null,e.supportedABIS);
alertABIWarning(e.binaryName,null);
}
catch(Exception e)
{
Expand All @@ -113,16 +114,14 @@ public void onCreate(Bundle savedInstanceState)
}

@Override
public void onRequestPermissionsResult(int requestCode,String[] permissions,int[] grantResults)
public void onRequestPermissionsResult(int requestCode,@NonNull String[] permissions,@NonNull int[] grantResults)
{
switch(requestCode)
if(requestCode==REQUEST_STORAGE)
{
case REQUEST_STORAGE:
if(grantResults.length==0 || grantResults[0]!=PackageManager.PERMISSION_GRANTED)
{
toast("The app won't work without storage permission");
}
break;
}
}

Expand Down Expand Up @@ -317,13 +316,13 @@ public void reloadUrls()
byte[] data=new byte[is.available()];
is.read(data);
is.close();
current_version=new JSONObject(new String(data,"UTF-8")).getInt("version");
current_version=new JSONObject(new String(data,StandardCharsets.UTF_8)).getInt("version");

is=new FileInputStream(file);
data=new byte[(int)file.length()];
is.read(data);
is.close();
JSONObject json=new JSONObject(new String(data,"UTF-8"));
JSONObject json=new JSONObject(new String(data,StandardCharsets.UTF_8));

if(!json.has("version") || json.getInt("version")<current_version)
{
Expand Down Expand Up @@ -603,7 +602,7 @@ public void copyAsset(String name,File target) throws Exception
ServerUtils.copyStream(getAssets().open(name),new FileOutputStream(target));
}

public void alertABIWarning(final String name,final DialogInterface.OnClickListener onclick,ArrayList<String> supportedABIS)
public void alertABIWarning(final String name,final DialogInterface.OnClickListener onclick)
{
runOnUiThread(new Runnable()
{
Expand Down Expand Up @@ -644,19 +643,9 @@ public static void tryDismissDialog(Dialog dialog)
Context context=((ContextWrapper)dialog.getContext()).getBaseContext();
if(context instanceof Activity)
{
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR1)
{
if(!((Activity)context).isFinishing() && !((Activity)context).isDestroyed())
{
dialog.dismiss();
}
}
else
if(!((Activity)context).isFinishing() && !((Activity)context).isDestroyed())
{
if(!((Activity)context).isFinishing())
{
dialog.dismiss();
}
dialog.dismiss();
}
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package moe.berd.pocket_server.exception;

import java.util.*;

public class ABINotSupportedException extends RuntimeException
{
public String binaryName="";
public ArrayList<String> supportedABIS=null;
public String binaryName;

public ABINotSupportedException(String binaryName,ArrayList<String> supportedABIS)
public ABINotSupportedException(String binaryName)
{
this.binaryName=binaryName;
this.supportedABIS=supportedABIS;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package moe.berd.pocket_server.fragment;

import android.app.*;
import android.content.ClipboardManager;
import android.content.*;
import android.os.*;
import android.text.*;
Expand Down Expand Up @@ -29,6 +30,8 @@ public class ConsoleFragment extends Fragment implements Handler.Callback
public EditText edit_command=null;
public ScrollView scroll_log=null;

public ClipboardManager clipboardManager = null;

public ConsoleFragment()
{

Expand Down Expand Up @@ -61,11 +64,13 @@ public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle save
@Override
public void onStart()
{
super.onStart();

logUpdateHandler=new Handler(this);

label_log=(TextView)main.findViewById(R.id.label_log);
label_current=(TextView)main.findViewById(R.id.label_current);
edit_command=(EditText)main.findViewById(R.id.edit_command);
label_log=main.findViewById(R.id.label_log);
label_current=main.findViewById(R.id.label_current);
edit_command=main.findViewById(R.id.edit_command);
edit_command.setOnKeyListener(new View.OnKeyListener()
{
@Override
Expand All @@ -79,8 +84,8 @@ public boolean onKey(View p1,int keyCode,KeyEvent p3)
return false;
}
});
scroll_log=(ScrollView)main.findViewById(R.id.logScrollView);
button_command=(Button)main.findViewById(R.id.button_send);
scroll_log=main.findViewById(R.id.logScrollView);
button_command=main.findViewById(R.id.button_send);
button_command.setOnClickListener(new View.OnClickListener()
{
@Override
Expand All @@ -96,7 +101,7 @@ public void onClick(View arg0)
label_log.setText(currentLog);
label_current.setText(currentLine);

super.onStart();
clipboardManager = (ClipboardManager)main.getSystemService(Context.CLIPBOARD_SERVICE);
}

@Override
Expand Down Expand Up @@ -132,8 +137,7 @@ public boolean onOptionsItemSelected(MenuItem item)
label_current.setText("");
break;
case R.id.menu_copy:
((android.content.ClipboardManager)main.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData
.newPlainText("PocketServer_ConsoleLog",currentLog));
clipboardManager.setPrimaryClip(ClipData.newPlainText("PocketServer_ConsoleLog",currentLog));
main.toast(R.string.message_copied);
break;
default:
Expand Down Expand Up @@ -177,29 +181,25 @@ private void sendCommand()
edit_command.setText("");
}

public static boolean postAppend(CharSequence data)
public static void 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()
public static void postNewLine()
{
if(logUpdateHandler!=null)
{
Message msg=new Message();
msg.arg1=MESSAGE_UPDATE_LINE;
logUpdateHandler.sendMessage(msg);
return true;
}
return false;
}

public static void logLine(String line)
Expand All @@ -212,7 +212,7 @@ public static void logLine(String line)
}
if(ansiMode)
{
int index=0;
int index;
while((index=line.indexOf("\u001b[1G"))!=-1)
{
line=line.substring(index + 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ public void onStart()
{
main.findViewById(R.id.label_copyright).setOnClickListener(this);

label_path_tip=(TextView)main.findViewById(R.id.label_path_tip);
label_path_tip=main.findViewById(R.id.label_path_tip);

button_stop=(Button)main.findViewById(R.id.button_stop);
button_stop=main.findViewById(R.id.button_stop);
button_stop.setOnClickListener(this);
button_start=(Button)main.findViewById(R.id.button_start);
button_start=main.findViewById(R.id.button_start);
button_start.setOnClickListener(this);
button_mount=(Button)main.findViewById(R.id.button_mount);
button_mount=main.findViewById(R.id.button_mount);
button_mount.setOnClickListener(this);

radio_nukkit=(RadioButton)main.findViewById(R.id.radio_nukkit);
radio_nukkit=main.findViewById(R.id.radio_nukkit);
radio_nukkit.setChecked(nukkitMode);
radio_nukkit.setOnClickListener(this);
radio_pocketmine=(RadioButton)main.findViewById(R.id.radio_pocketmine);
radio_pocketmine=main.findViewById(R.id.radio_pocketmine);
radio_pocketmine.setChecked(!nukkitMode);
radio_pocketmine.setOnClickListener(this);

Expand Down Expand Up @@ -182,7 +182,7 @@ public void onClick(View v)
main.openUrlFromJson("source_code");
break;
case R.id.button_start:
if(nukkitMode && ConfigProvider.getBoolean("AutoMountJava",false) && !ServerUtils.mountedJavaLibrary())
if(nukkitMode && ConfigProvider.getBoolean("AutoMountJava",false) && ServerUtils.javaLibraryNotFound())
{
processing_dialog.setCancelable(false);
processing_dialog.setMessage(getString(R.string.message_running));
Expand Down Expand Up @@ -299,7 +299,7 @@ public void refreshElements()
{
running=true;
}
else if(!ServerUtils.mountedJavaLibrary() && !ConfigProvider.getBoolean("AutoMountJava",false))
else if(ServerUtils.javaLibraryNotFound() && !ConfigProvider.getBoolean("AutoMountJava",false))
{
running=true;
button_mount.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void run()
}
catch(ABINotSupportedException e)
{
main.alertABIWarning(e.binaryName,null,e.supportedABIS);
main.alertABIWarning(e.binaryName,null);
}
catch(Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.*;
import android.content.*;
import android.os.*;

import android.support.v4.app.*;

import net.fengberd.minecraftpe_server.*;
Expand All @@ -14,6 +13,7 @@
public class ServerService extends Service
{
@Override
@SuppressWarnings("ConstantConditions")
public int onStartCommand(Intent intent,int flags,int startId)
{
String channelId = "";
Expand All @@ -22,8 +22,7 @@ public int onStartCommand(Intent intent,int flags,int startId)
channelId = "running";
NotificationChannel channel=new NotificationChannel(channelId,"Server Running",NotificationManager.IMPORTANCE_LOW);
channel.setDescription("Make sure the service won't die");
NotificationManager notificationManager=getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
startForeground(1,new NotificationCompat.Builder(getApplicationContext(), channelId).setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import net.fengberd.minecraftpe_server.*;

@SuppressWarnings("WeakerAccess")
public class SeekBarPreference extends Preference implements SeekBar.OnSeekBarChangeListener
{
private int progress;
Expand All @@ -35,7 +36,7 @@ protected View onCreateView(ViewGroup parent)
protected void onBindView(View view)
{
super.onBindView(view);
SeekBar seekbar=(SeekBar)view.findViewById(R.id.preference_seekbar_seekbar);
SeekBar seekbar=view.findViewById(R.id.preference_seekbar_seekbar);
if(seekbar!=null)
{
seekbar.setProgress(progress);
Expand Down
Loading

0 comments on commit 377059b

Please sign in to comment.