|
|
|
@ -27,14 +27,24 @@ import android.view.WindowManager;
|
|
|
|
|
import com.dowse.camera.client.DSCameraManager;
|
|
|
|
|
import com.xinyingpower.microphoto.databinding.ActivityMainBinding;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -54,32 +64,43 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class AppConfig {
|
|
|
|
|
public String cmdid;
|
|
|
|
|
public String server;
|
|
|
|
|
public int port;
|
|
|
|
|
public int protocol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
|
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
|
|
|
|
|
|
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
|
|
Display defaultDisplay = windowManager.getDefaultDisplay();
|
|
|
|
|
int width = defaultDisplay.getWidth();
|
|
|
|
|
int height = defaultDisplay.getHeight();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "Screen Size: " + width + " x " + height);
|
|
|
|
|
|
|
|
|
|
SharedPreferences sp = MainActivity.this.getApplicationContext().getSharedPreferences("xymp", Context.MODE_PRIVATE);
|
|
|
|
|
binding.cmdid.setText(sp.getString("cmdid", "XY-ANDROIDSIM-001"));
|
|
|
|
|
binding.server.setText(sp.getString("server", "47.96.238.157"));
|
|
|
|
|
binding.port.setText(sp.getString("port", "6891"));
|
|
|
|
|
String cmdid = "0123456789ABCDEFG";
|
|
|
|
|
String server = "47.96.238.157";
|
|
|
|
|
Integer port = new Integer(6891);
|
|
|
|
|
Integer protocol = new Integer(0xFF00); // 0xFF00
|
|
|
|
|
|
|
|
|
|
AppConfig appConfig = getAppConfig();
|
|
|
|
|
binding.cmdid.setText(appConfig.cmdid);
|
|
|
|
|
binding.server.setText(appConfig.server);
|
|
|
|
|
binding.port.setText(Integer.toString(appConfig.port));
|
|
|
|
|
|
|
|
|
|
this.binding.startServBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String[] accessPermissions = new String[]{
|
|
|
|
|
Manifest.permission.CAMERA,
|
|
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
|
@ -109,19 +130,19 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
String fileName = buildPhotoFileName(channel, 255);
|
|
|
|
|
// MainActivity.this.takePhoto(channel, 255, path, fileName);
|
|
|
|
|
|
|
|
|
|
SharedPreferences sp = MainActivity.this.getApplicationContext().getSharedPreferences("xymp", Context.MODE_PRIVATE);
|
|
|
|
|
SharedPreferences.Editor editor = sp.edit();
|
|
|
|
|
editor.putString("cmdid", MainActivity.this.binding.cmdid.getText().toString());
|
|
|
|
|
editor.putString("server", MainActivity.this.binding.server.getText().toString());
|
|
|
|
|
editor.putString("port", MainActivity.this.binding.port.getText().toString());
|
|
|
|
|
editor.commit();
|
|
|
|
|
String cmdid = MainActivity.this.binding.cmdid.getText().toString();
|
|
|
|
|
String server = MainActivity.this.binding.server.getText().toString();
|
|
|
|
|
int port = Integer.parseInt(MainActivity.this.binding.port.getText().toString());
|
|
|
|
|
int protocol = 0xFF00;
|
|
|
|
|
|
|
|
|
|
MainActivity.this.saveAppConfig(cmdid, server, port, protocol);
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, MicroPhotoService.class);
|
|
|
|
|
intent.setAction(MicroPhotoService.ACTION_START);
|
|
|
|
|
intent.putExtra("cmdid", MainActivity.this.binding.cmdid.getText().toString());
|
|
|
|
|
intent.putExtra("server", MainActivity.this.binding.server.getText().toString());
|
|
|
|
|
String port = MainActivity.this.binding.port.getText().toString();
|
|
|
|
|
intent.putExtra("port", Integer.parseInt(port));
|
|
|
|
|
intent.putExtra("cmdid", cmdid);
|
|
|
|
|
intent.putExtra("server", server);
|
|
|
|
|
intent.putExtra("port", port);
|
|
|
|
|
intent.putExtra("protocol", protocol);
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
MainActivity.this.startForegroundService(intent);
|
|
|
|
@ -131,10 +152,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
binding.startServBtn.setEnabled(false);
|
|
|
|
|
binding.stopServBtn.setEnabled(true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.binding.takePhotoBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@ -181,11 +199,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
binding.startServBtn.setEnabled(true);
|
|
|
|
|
binding.stopServBtn.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.simchange.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
@ -218,7 +233,6 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
handler.postDelayed(runnable, 1000);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setDefaultDataSubId(int subId) {
|
|
|
|
@ -232,7 +246,81 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AppConfig getAppConfig() {
|
|
|
|
|
|
|
|
|
|
AppConfig appConfig = new AppConfig();
|
|
|
|
|
|
|
|
|
|
String appPath = MicroPhotoService.buildAppDir(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
InputStreamReader inputStreamReader = null;
|
|
|
|
|
try {
|
|
|
|
|
inputStreamReader = new InputStreamReader(new FileInputStream(new File(appPath + "App.json")), "UTF-8");
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
|
|
String line;
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
while((line = bufferedReader.readLine()) != null) {
|
|
|
|
|
stringBuilder.append(line);
|
|
|
|
|
}
|
|
|
|
|
bufferedReader.close();
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
|
|
|
|
|
appConfig.cmdid = jsonObject.getString("CMDID");
|
|
|
|
|
appConfig.server = jsonObject.getString("Server");
|
|
|
|
|
appConfig.port = jsonObject.getInt("Port");
|
|
|
|
|
appConfig.protocol = jsonObject.getInt("Protocol");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
try {
|
|
|
|
|
inputStreamReader.close();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveAppConfig(String cmdid, String server, int port, int protocol) {
|
|
|
|
|
|
|
|
|
|
String appPath = MicroPhotoService.buildAppDir(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
OutputStreamWriter outputStreamWriter = null;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("CMDID", cmdid);
|
|
|
|
|
jsonObject.put("Server", server);
|
|
|
|
|
jsonObject.put("Port", port);
|
|
|
|
|
jsonObject.put("Protocol", protocol);
|
|
|
|
|
|
|
|
|
|
outputStreamWriter = new OutputStreamWriter(new FileOutputStream(new File(appPath + "App.json")), "UTF-8");
|
|
|
|
|
outputStreamWriter.write(jsonObject.toString());
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
|
try {
|
|
|
|
|
outputStreamWriter.close();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getDefaultDataSubId() {
|
|
|
|
|