Behebung diverser Design Fehler

This commit is contained in:
m_broelemann 2020-12-30 13:03:50 +01:00
parent 3e65d83ede
commit ff777de343

View File

@ -58,14 +58,18 @@ public class MainActivity extends AppCompatActivity {
/** zur Verwendung von favorite anstatt der direkten Einbindung.*/ /** zur Verwendung von favorite anstatt der direkten Einbindung.*/
public IFAVORITES favorite = new TestFavorites(); public IFAVORITES favorite = new TestFavorites();
/** allgemeines.*/ /** allgemeines.*/
String ip = "192.168.1.220"; private String ip = "192.168.1.220";
/**
*
* @param savedInstanceState
*/
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//checks that the permission to read and write the xml is granted //checks that the permission to read and write the xml is granted
ensurePermissions(); ensurePermissions();
setXML(); setXML();
uebergabe = new Communicator(ip,8080,this); uebergabe = new Communicator(ip, 8080, this);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -104,11 +108,11 @@ public class MainActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(final @NonNull MenuItem item) { public boolean onOptionsItemSelected(final @NonNull MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_set_IP: case R.id.action_set_IP:
Toast.makeText(this, "set IP", MaterialAlertDialogBuilder alert = new
Toast.LENGTH_SHORT).show(); MaterialAlertDialogBuilder(MainActivity.this);
MaterialAlertDialogBuilder alert = new MaterialAlertDialogBuilder(MainActivity.this);
alert.setTitle(R.string.action_set_IP); alert.setTitle(R.string.action_set_IP);
alert.setMessage("Please enter the ip address of the device to be connected"); alert.setMessage("Please enter the ip address of the "
+ "device to be connected");
final EditText input = new EditText(MainActivity.this); final EditText input = new EditText(MainActivity.this);
input.setText(ip); input.setText(ip);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
@ -118,18 +122,25 @@ public class MainActivity extends AppCompatActivity {
alert.setView(input); alert.setView(input);
alert.setPositiveButton("connect", alert.setPositiveButton("connect",
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) { public void onClick(final DialogInterface dialog,
final int which) {
// Write your code here to execute after dialog // Write your code here to execute after dialog
ip = input.getText().toString(); ip = input.getText().toString();
Toast.makeText(getApplicationContext(),ip +" IP connect", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),
uebergabe = new Communicator(ip,8080,MainActivity.this); ip + " IP connect",
Toast.LENGTH_SHORT).show();
uebergabe = new Communicator(ip, 8080,
MainActivity.this);
} }
}); });
alert.setNegativeButton("exit", alert.setNegativeButton("exit",
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(final DialogInterface dialog,
final int which) {
// Write your code here to execute after dialog // Write your code here to execute after dialog
Toast.makeText(getApplicationContext(),"exit clicked", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),
"exit clicked",
Toast.LENGTH_SHORT).show();
dialog.cancel(); dialog.cancel();
} }
}); });
@ -227,16 +238,18 @@ public class MainActivity extends AppCompatActivity {
} }
} }
private void setXML(){ private void setXML() {
try { try {
String xmlPath = ExternalStorageHandler.getExternalPrivateStorageDir(MainActivity.this); String xmlPath = ExternalStorageHandler.
File xmlFile = new File(xmlPath,"config.xml"); getExternalPrivateStorageDir(MainActivity.this);
File xmlFile = new File(xmlPath, "config.xml");
//create the default XML config by using the default.xml from the assets folder //create the default XML config by using the default.xml from the assets folder
if (xmlFile.exists()){ if (xmlFile.exists()) {
xmlFile.delete(); xmlFile.delete();
} }
InputStream inputStream = getAssets().open("XML/default.xml"); InputStream inputStream = getAssets().open(
"XML/default.xml");
byte[] buffer = new byte[inputStream.available()]; byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer); inputStream.read(buffer);
inputStream.close(); inputStream.close();
@ -246,9 +259,11 @@ public class MainActivity extends AppCompatActivity {
xml = new XMLHandler(xmlFile); xml = new XMLHandler(xmlFile);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e("Main Activity","Exception while reading the external private storage dir: " + e.getMessage()); Log.e("Main Activity", "Exception while reading the "
} catch (ParserConfigurationException | IOException | SAXException e){ + "external private storage dir: " + e.getMessage());
Log.e("Main Activity","XMLHandler failed to initialise: " + e.getMessage()); } catch (ParserConfigurationException | IOException | SAXException e) {
Log.e("Main Activity", "XMLHandler failed to initialise: "
+ e.getMessage());
} }
} }
} }