24.03.2017
drawerItemList.add(new DrawerItem(o.getString("name"), Icons.getRoomIcon(o.getString("icon")), o.getString("location"), new RoomFragment()));
/**
* Gibt anhand des übergebenen Key's den passenden Icon zurück
* @param key
* @return
*/
public static int getRoomIcon(String key){
//Methode wird später genauer implementiert
switch(key){
default:
return R.mipmap.ic_launcher;
}
}
public class RoomItem{
//Hier wurde die Variable "deviceType" hinzugefügt
private String name, device, icon, type, value, deviceType;
//Hier wurde der Parameter "deviceType" hinzugefügt
public RoomItem(String name, String device, String icon, String deviceType, String type, String value){
this.name = name;
this.device = device;
this.icon = icon;
this.type = type;
this.value = value;
//Hier wurde eine Wertezuweisung hinzugefügt
this.deviceType = deviceType;
}
/**
* Gibt den Namen des Items zurück
* @return
*/
public String getName(){
return name;
}
/**
* Gibt den Wert des Items zurück
* @return
*/
public String getValue(){
return value;
}
/**
* Gibt den Typ des Items zurück
* @return
*/
public String getType(){
return type;
}
/**
* Gibt den Icon des Items zurück
* @return
*/
public String getIcon(){
return icon;
}
/**
* Gibt das Device des Items zurück
* @return
*/
public String getDevice(){
return device;
}
//Hier wurde eine Getter-Methode für den Gerätetypen hinzugefügt
/**
* Gibt den Gerätetypen des Items zurück
* @return
*/
public String getDeviceType(){
return deviceType;
}
}
roomItems.add(new RoomItem(c.getString("name"), c.getString("device"), c.getString("icon"),
c.getString("device_type"), c.getString("type"), c.getString("value")));
showOverview(ri.getDeviceType(), ri.getDevice());
setModes(ri, !switchViewHolder.switchView.isChecked());
public void showOverview(String type, String sensor){}
public void setModes(final RoomItem item, boolean mode){}
private static String username = null;
private static String password = null;
private static String serverIp = null;
private static String usernameFile = "uname.ini";
private static String passwordFile = "psw.ini";
private static String serverFile = "serverip.ini";
/**
* Gibt den Nutzernamen zurück
* @param context Kontext der App
* @return der Nutzername
*/
public static String getUsername(Context context){
String savedUsername = readFromFile(context, usernameFile);
if(savedUsername != null){
username = savedUsername;
}
return username;
}
/**
* Gibt das Password zurück
* @param context Kontext der App
* @return das Passwort
*/
public static String getPassword(Context context){
String savedPassword = readFromFile(context, passwordFile);
if(savedPassword != null){
password = savedPassword;
}
return password;
}
/**
* Gibt die IP zurück
* @param context Kontext der App
* @return die IP
*/
public static String getServerIp(Context context){
String savedIp = readFromFile(context, serverFile);
if(savedIp != null){
serverIp = savedIp;
}
return serverIp;
}
/**
* Setzt die Login-Daten des Nutzers
* @param context Kontext der App
* @param uname Nutzername
* @param pw Passwort
* @param saveData true, wenn Daten gespeichert werden sollen
* false, wenn nicht
*/
public static void setLoginData(Context context, String uname, String pw, boolean saveData){
if(saveData){
writeToFile(context, usernameFile, uname);
writeToFile(context, passwordFile, pw);
}
username = uname;
password = pw;
}
public static void setServerIp(Context context, String serverIp){}
/**
* Gibt zurück, ob die Nutzerdaten gespeichert wurden
* @param context Kontext der App
* @return
*/
public static boolean getSaveLoginData(Context context){
boolean saveLoginData = (getUsername(context) != null && getPassword(context) != null);
return saveLoginData;
}
/**
* Schreibt den übergebenen Text in die angegebene Datei
* @param context Kontext der App
* @param filePath Pfad der Datei
* @param text der zu schreibende Text
*/
private static void writeToFile(Context context, String filePath, String text){
try{
FileOutputStream fos = context.openFileOutput(filePath, Context.MODE_PRIVATE);
fos.write(text.getBytes());
fos.close();
}catch(IOException e){
e.printStackTrace();
}
}
/**
* Gibt den Text der ausgegebenen Datei aus
* @param context Kontext der App
* @param filePath Pfad der zu lesenden Datei
* @return String mit dem Inhalt der Datei oder null, falls Datei leer ist oder es einen Fehler gab
*/
private static String readFromFile(Context context, String filePath){
String text = "";
try{
FileInputStream fis = context.openFileInput(filePath);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader bufferedReader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
while((line = bufferedReader.readLine()) != null){
sb.append(line);
}
text = ""+sb;
if(text.equals("")){
return null;
}
}catch(Exception e){
e.printStackTrace();
text = null;
}
return text;
}
/**
* Löscht alle gespeicherten Nutzerdaten
* @param context Kontext der App
*/
public static void deleteAllUserData(Context context){
writeToFile(context, usernameFile, "");
writeToFile(context, passwordFile, "");
writeToFile(context, serverFile, "");
username = null;
password = null;
serverIp = null;
}
public void login(final String username, final String password, final String serverIp, final boolean saveData){
//...
}
SaveData.setLoginData(getApplicationContext(), username, password, saveData);
SaveData.setServerIp(getApplicationContext(), serverIp);
login(username, password, serverIp, saveLogin.isChecked());
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_ROOMS, result);
startActivity(intent);
finish();
<item
android:id="@+id/action_logout"
android:orderInCategory="100"
android:title="Ausloggen"
app:showAsAction="never" />
else if(post_id == R.id.action_logout){
SaveData.deleteAllUserData(getApplicationContext());
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
Dieser Beitrag hat dir gefallen?
Dann abonniere doch unseren Newsletter!