Code Conventions

This commit is contained in:
m_broelemann 2021-01-06 08:38:38 +01:00
parent a121811b12
commit 85c67f525b

View File

@ -18,7 +18,6 @@ import com.example.aped.utils.ConfigurationHandler;
import com.example.aped.utils.ExternalStorageHandler;
import com.example.aped.utils.IFAVORITES;
import com.example.aped.utils.IXML;
import com.example.aped.utils.TestFavorites;
import com.example.aped.utils.XMLHandler;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.navigation.NavigationView;
@ -52,9 +51,7 @@ public class MainActivity extends AppCompatActivity {
public ConfigurationHandler configurationHandler;
/** zur Verwendung von favorite anstatt der direkten Einbindung.*/
public IFAVORITES favorite;
/** allgemeines.*/
/**
*
* @param savedInstanceState
*/
@Override
@ -64,7 +61,8 @@ public class MainActivity extends AppCompatActivity {
ensurePermissions();
setupConfigs();
favorite = configurationHandler;
uebergabe = new Communicator(configurationHandler.getAddress(), configurationHandler.getPort(), this);
uebergabe = new Communicator(configurationHandler.getAddress(),
configurationHandler.getPort(), this);
uebergabe.downloadXML();
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
@ -106,23 +104,32 @@ public class MainActivity extends AppCompatActivity {
MaterialAlertDialogBuilder alert = new
MaterialAlertDialogBuilder(MainActivity.this);
//alert.setTitle(R.string.action_set_connection);
View view2 = LayoutInflater.from(MainActivity.this).inflate(R.layout.alert_dialog_ip_pot_eingabe,null);
EditText ipAdress = (EditText) view2.findViewById(R.id.editTextIp);
View view2 = LayoutInflater.from(MainActivity.this).inflate(R.
layout.alert_dialog_ip_pot_eingabe, null);
EditText ipAdress = (EditText) view2.findViewById(R.id.
editTextIp);
ipAdress.setText(configurationHandler.getAddress());
EditText port = (EditText) view2.findViewById(R.id.editTextPort);
port.setText(String.valueOf(configurationHandler.getPort()) );
EditText port = (EditText) view2.findViewById(R.id.
editTextPort);
port.setText(String.valueOf(configurationHandler.getPort()));
alert.setView(view2);
alert.setPositiveButton("set",
new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,
final int which) {
// Write your code here to execute after dialog
configurationHandler.setAddress(ipAdress.getText().toString());
configurationHandler.setPort(Integer.parseInt(port.getText().toString()));
configurationHandler.setAddress(ipAdress.
getText().toString());
configurationHandler.setPort(Integer.parseInt(
port.getText().toString()));
Toast.makeText(getApplicationContext(),
configurationHandler.getAddress() + ":" + configurationHandler.getPort() + " is set",
configurationHandler.getAddress()
+ ":" + configurationHandler.
getPort() + " is set",
Toast.LENGTH_SHORT).show();
uebergabe = new Communicator(configurationHandler.getAddress(), configurationHandler.getPort(),
uebergabe = new Communicator(
configurationHandler.getAddress(),
configurationHandler.getPort(),
MainActivity.this);
}
});
@ -145,22 +152,23 @@ public class MainActivity extends AppCompatActivity {
Toast.LENGTH_SHORT).show();
String externalPrivateStorageDir = null;
try {
externalPrivateStorageDir = ExternalStorageHandler.getExternalPrivateStorageDir(this);
externalPrivateStorageDir = ExternalStorageHandler.
getExternalPrivateStorageDir(this);
} catch (FileNotFoundException e) {
Log.e("MainActivity","error while opening the config.xml for adjustment: " + e.getMessage());
Log.e("MainActivity", "error while opening the "
+ "config.xml for adjustment: " + e.getMessage());
}
File xmlFile = new File(externalPrivateStorageDir, "config.xml");
Uri uri = FileProvider.getUriForFile(this,this.getApplicationContext().getPackageName() + ".provider", xmlFile);
File xmlFile = new File(externalPrivateStorageDir,
"config.xml");
Uri uri = FileProvider.getUriForFile(this,
this.getApplicationContext().getPackageName()
+ ".provider", xmlFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri,"text/xml");
intent.setDataAndType(uri, "text/xml");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
/**
* xml anstatt beispieltext muss übergeben werden
* rückgabe der xml fehlt noch
*/
break;
case R.id.action_download_xml:
@ -255,25 +263,27 @@ public class MainActivity extends AppCompatActivity {
private void setupConfigs() {
try {
String externalConfigPath = ExternalStorageHandler.getExternalPrivateStorageDir(MainActivity.this);
File xmlFile = new File(externalConfigPath,"config.xml");
String externalConfigPath = ExternalStorageHandler.
getExternalPrivateStorageDir(MainActivity.this);
File xmlFile = new File(externalConfigPath, "config.xml");
File configFile = new File(externalConfigPath, "config.json");
if(!xmlFile.exists()){
if (!xmlFile.exists()) {
setDefaultXML(xmlFile);
}
if(!configFile.exists()){
if (!configFile.exists()) {
setDefaultConfig(configFile);
}
xml = new XMLHandler(xmlFile);
configurationHandler = new ConfigurationHandler(configFile.getPath());
} catch (FileNotFoundException e) {
Log.e("Main Activity", "failed to find the external private storage during CONFIG SETUP: " + e.getMessage());
Log.e("Main Activity", "failed to find the external "
+ "private storage during CONFIG SETUP: " + e.getMessage());
}
}
private void setDefaultXML(File xmlFile){
try{
private void setDefaultXML(final File xmlFile) {
try {
InputStream inputStream = getAssets().open(
"XML/default.xml");
byte[] buffer = new byte[inputStream.available()];
@ -283,12 +293,13 @@ public class MainActivity extends AppCompatActivity {
fileOutputStream.write(buffer);
fileOutputStream.close();
} catch (Exception e) {
Log.e("MainActivity", "error while transferring the default.xml into the config.xml: " + e.getMessage());
Log.e("MainActivity", "error while transferring the "
+ "default.xml into the config.xml: " + e.getMessage());
}
}
private void setDefaultConfig(File xmlFile){
try{
private void setDefaultConfig(final File xmlFile) {
try {
InputStream inputStream = getAssets().open(
"defaultConfig.json");
byte[] buffer = new byte[inputStream.available()];
@ -298,7 +309,9 @@ public class MainActivity extends AppCompatActivity {
fileOutputStream.write(buffer);
fileOutputStream.close();
} catch (Exception e) {
Log.e("MainActivity", "error while transferring the defaultConfig.json into the config.json: " + e.getMessage());
Log.e("MainActivity", "error while transferring the "
+ "defaultConfig.json into the config.json: "
+ e.getMessage());
}
}
}