|
|
@ -1,6 +1,7 @@
|
|
|
|
package com.xypower.mpapp;
|
|
|
|
package com.xypower.mpapp;
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
import android.Manifest;
|
|
|
|
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
@ -35,6 +36,7 @@ import android.view.View;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
import com.dowse.camera.client.DSCameraManager;
|
|
|
|
import com.dowse.camera.client.DSCameraManager;
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
import com.xypower.mpapp.databinding.ActivityMainBinding;
|
|
|
|
import com.xypower.mpapp.databinding.ActivityMainBinding;
|
|
|
@ -53,6 +55,7 @@ import java.io.UnsupportedEncodingException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
@ -201,7 +204,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
mMessenger = new Messenger(new Handler());
|
|
|
|
// mMessenger = new Messenger(new Handler());
|
|
|
|
|
|
|
|
|
|
|
|
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
|
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
|
Display defaultDisplay = windowManager.getDefaultDisplay();
|
|
|
|
Display defaultDisplay = windowManager.getDefaultDisplay();
|
|
|
@ -241,6 +244,9 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
if (appConfig.networkProtocol < binding.networkProtocol.getCount()) {
|
|
|
|
if (appConfig.networkProtocol < binding.networkProtocol.getCount()) {
|
|
|
|
binding.networkProtocol.setSelection(appConfig.networkProtocol);
|
|
|
|
binding.networkProtocol.setSelection(appConfig.networkProtocol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.heartbeat.setText((appConfig.heartbeat > 0) ? Integer.toString(appConfig.heartbeat) : "");
|
|
|
|
|
|
|
|
binding.packetSize.setText((appConfig.packetSize > 0) ? Integer.toString(appConfig.packetSize) : "");
|
|
|
|
|
|
|
|
|
|
|
|
this.binding.startServBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
this.binding.startServBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
public void onClick(View view) {
|
|
|
@ -263,7 +269,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
AppConfig curAppConfig = retrieveAndSaveAppConfig();
|
|
|
|
AppConfig curAppConfig = retrieveAndSaveAppConfig();
|
|
|
|
|
|
|
|
|
|
|
|
startMicroPhotoService(MainActivity.this, appConfig);
|
|
|
|
startMicroPhotoService(MainActivity.this, appConfig, mMessenger);
|
|
|
|
|
|
|
|
|
|
|
|
binding.startServBtn.setEnabled(false);
|
|
|
|
binding.startServBtn.setEnabled(false);
|
|
|
|
binding.stopServBtn.setEnabled(true);
|
|
|
|
binding.stopServBtn.setEnabled(true);
|
|
|
@ -465,9 +471,39 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.btnSendHb.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mMessenger != null) {
|
|
|
|
|
|
|
|
Message msg = Message.obtain();
|
|
|
|
|
|
|
|
msg.what = MicroPhotoService.MSG_WHAT_SENDING_HB;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
mMessenger.send(msg);
|
|
|
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.btnRestartApp.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
Context context = v.getContext();
|
|
|
|
|
|
|
|
MicroPhotoService.restartApp(context, context.getPackageName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.btnReboot.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
SysApi.reboot(v.getContext());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void startMicroPhotoService(Context context, AppConfig curAppConfig) {
|
|
|
|
public static void startMicroPhotoService(Context context, AppConfig curAppConfig, Messenger messenger) {
|
|
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(curAppConfig.cmdid) || TextUtils.isEmpty(curAppConfig.server) || curAppConfig.port == 0) {
|
|
|
|
if (TextUtils.isEmpty(curAppConfig.cmdid) || TextUtils.isEmpty(curAppConfig.server) || curAppConfig.port == 0) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -479,7 +515,9 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
intent.putExtra("port", curAppConfig.port);
|
|
|
|
intent.putExtra("port", curAppConfig.port);
|
|
|
|
intent.putExtra("protocol", curAppConfig.protocol);
|
|
|
|
intent.putExtra("protocol", curAppConfig.protocol);
|
|
|
|
intent.putExtra("networkProtocol", curAppConfig.networkProtocol);
|
|
|
|
intent.putExtra("networkProtocol", curAppConfig.networkProtocol);
|
|
|
|
// intent.putExtra("messenger", mMessenger);
|
|
|
|
if (messenger != null) {
|
|
|
|
|
|
|
|
intent.putExtra("messenger", messenger);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
context.startForegroundService(intent);
|
|
|
|
context.startForegroundService(intent);
|
|
|
@ -581,6 +619,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
appConfig.port = jsonObject.getInt("Port");
|
|
|
|
appConfig.port = jsonObject.getInt("Port");
|
|
|
|
appConfig.protocol = jsonObject.getInt("Protocol");
|
|
|
|
appConfig.protocol = jsonObject.getInt("Protocol");
|
|
|
|
appConfig.networkProtocol = jsonObject.getInt("NetworkProtocol");
|
|
|
|
appConfig.networkProtocol = jsonObject.getInt("NetworkProtocol");
|
|
|
|
|
|
|
|
appConfig.heartbeat = jsonObject.optInt("heartbeat", 0);
|
|
|
|
|
|
|
|
appConfig.packetSize = jsonObject.optInt("packetSize", 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
if (appConfig.protocol == 0) {
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|
appConfig.protocol = DEFAULT_PROTOCOL;
|
|
|
|