Skip to content

Commit

Permalink
Merge pull request #3 from SirkoVZ/SettingsBackup
Browse files Browse the repository at this point in the history
settings can be saved now, smaller modifications, version 0.8.3
  • Loading branch information
SirkoVZ committed Oct 6, 2015
2 parents 27820c1 + e9381ec commit 9ac2f68
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 23 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# app-android
Volkszaehler frontend for Android

VolkszählerApp (Android) Version 0.8.2
VolkszählerApp (Android) Version 0.8.3

- sie kann die Channels abrufen und die letzten Werte anzeigen
- ein paar Details zu jedem Channel anzeigen
- charts zu einzelnen Channels anzeigen, incl. Zoom, auch mit „Touch and Move“ im Diagramm
- HTTPS und Basic Authentication wird unterstützt, ABER das Zertifikat wird nicht wirklich geprüft, es werden auch ungültige oder Man-in-the-Middle-Zertifikate akzeptiert
- Die URL zur Middleware lautet z.B. http://raspberrypi/middleware.php. D.h. die middelware.php befindet sich im Rootordner der Installation.
- Einstellungen können (z.B. vor einem Update) gesichert und (nach dem Update/Neuinstallation) wieder eingespielt werden

Das ganze soll selbsterklärend sein, falls nicht, kann hier noch eine Anleitung rein bzw. die App verbessert werden.

Benötigte Berechtigungen:
- android.permission.INTERNET für den Zugriff auf die Volkszähler-Installation
- android.permission.WRITE_EXTERNAL_STORAGE für das Schreiben (und Lesen) des Backups

Tips zum Clonen von Github in AndroidStudio:
Wenn das Clonen bzw. das Öffnen des Projektes wegen eines ausgegrauten "Use default gradle wrapper (not configured for the current project)" nicht möglich ist, dann
- das Projekt nochmal normal als "Open an existing Android Studio project" öffnen und im "Gradle Sync" Dialog einfach OK klicken
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.volkszaehler.volkszaehlerapp"
android:versionCode="82"
android:versionName="0.8.2" >
android:versionCode="83"
android:versionName="0.8.3" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class ChannelDetails extends Activity {

Expand Down Expand Up @@ -184,6 +185,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_settings:
startActivity(new Intent(this, Preferences.class));
return (true);
case R.id.backup_settings:
boolean saved = Tools.saveFile(getApplicationContext());
if(saved)
{
Toast.makeText(this, R.string.saved, Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, R.string.notsaved , Toast.LENGTH_SHORT).show();
}
return (true);
case R.id.restore_settings:

boolean restored = Tools.loadFile(getApplicationContext());
if(restored)
{
Toast.makeText(this, R.string.restored , Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, R.string.notrestored , Toast.LENGTH_SHORT).show();
}
return (true);


case R.id.about:
String app_ver = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;


public class ChartDetails extends Activity {
Expand Down Expand Up @@ -354,8 +355,8 @@ private void buttonShowInfoHandler(View view, String UUID) {

String consumptionWert = Tools.getDataOfChannel(myContext, UUID, Tools.TAG_CONSUMPTION);
if (!"".equals(consumptionWert)) {
((TextView) layout.findViewById(R.id.conWertIDValue)).setText(consumptionWert + " " + unit + "/h");
((TextView) layout.findViewById(R.id.costWertIDValue)).setText(f.format(Double.valueOf(Tools.getPropertyOfChannel(myContext, UUID, Tools.TAG_COST)) * Double.valueOf(consumptionWert)) + " ");
((TextView) layout.findViewById(R.id.conWertIDValue)).setText(consumptionWert + " " + unit + "h");
((TextView) layout.findViewById(R.id.costWertIDValue)).setText(f.format(Double.valueOf(Tools.getPropertyOfChannel(myContext, UUID, Tools.TAG_COST)) / 1000 * Double.valueOf(consumptionWert)) + " ");
}

} catch (Exception e) {
Expand Down Expand Up @@ -511,6 +512,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_settings:
startActivity(new Intent(this, Preferences.class));
return (true);
case R.id.backup_settings:
boolean saved = Tools.saveFile(getApplicationContext());
if(saved)
{
Toast.makeText(this, R.string.saved, Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, R.string.notsaved , Toast.LENGTH_SHORT).show();
}
return (true);
case R.id.restore_settings:

boolean restored = Tools.loadFile(getApplicationContext());
if(restored)
{
Toast.makeText(this, R.string.restored , Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, R.string.notrestored , Toast.LENGTH_SHORT).show();
}
return (true);

case R.id.about:
String app_ver = "";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity<ViewGroup> extends ListActivity {
private static Context myContext;
Expand Down Expand Up @@ -134,6 +135,29 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_settings:
startActivityForResult(new Intent(this, Preferences.class), 1);
return (true);
case R.id.backup_settings:
boolean saved = Tools.saveFile(getApplicationContext());
if(saved)
{
Toast.makeText(this, R.string.saved , Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, R.string.notsaved , Toast.LENGTH_SHORT).show();
}
return (true);
case R.id.restore_settings:

boolean restored = Tools.loadFile(getApplicationContext());
if(restored)
{
Toast.makeText(this, R.string.restored , Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, R.string.notrestored , Toast.LENGTH_SHORT).show();
}
return (true);
case R.id.about:
String app_ver = "";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ public boolean onPreferenceClick(Preference arg0) {
url = prefs.getString("volkszaehlerURL", "");
uname = prefs.getString("username", "");
pwd = prefs.getString("password", "");
boolean zeroBased = prefs.getBoolean("ZeroBasedYAxis", false);
boolean bZeroBased = prefs.getBoolean("ZeroBasedYAxis", false);
boolean bAutoReload = prefs.getBoolean("autoReload", false);


// remove all
prefs.edit().clear().commit();
// and put back
prefs.edit().putString("volkszaehlerURL", url).commit();
prefs.edit().putString("username", uname).commit();
prefs.edit().putString("password", pwd).commit();
prefs.edit().putBoolean("ZeroBasedYAxis", zeroBased).commit();
prefs.edit().putBoolean("ZeroBasedYAxis", bZeroBased).commit();
prefs.edit().putBoolean("ZeroBasedYAxis", bAutoReload).commit();
// call Channels from VZ installation
new GetChannels().execute();
return true;
Expand All @@ -76,9 +79,9 @@ public void onBackPressed() {
}

private void addPreferenceChannels() {
SharedPreferences prefs = getSharedPreferences("JSONChannelPrefs", Activity.MODE_PRIVATE);
String JSONChannels = prefs.getString("JSONChannels", "");
Log.d("JSONChannels", JSONChannels);
SharedPreferences prefs = getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE);
String JSONChannels = prefs.getString(Tools.JSON_CHANNELS, "");
Log.d(Tools.JSON_CHANNELS, JSONChannels);
if (JSONChannels.equals("")) {
return;
}
Expand Down Expand Up @@ -176,15 +179,15 @@ protected String doInBackground(Void... arg0) {
} else {
newChannels = true;
// store all channel stuff in a shared preference
getApplicationContext().getSharedPreferences("JSONChannelPrefs", Activity.MODE_PRIVATE).edit().putString("JSONChannels", jsonStr).commit();
getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_CHANNELS, jsonStr).commit();

}
if (!jsonStrDef.startsWith("{\"version\":\"0.3\",\"capabilities")) {
JSONFehler2 = true;
fehlerAusgabe2 = jsonStrDef;
} else {
// store all definitions stuff in a shared preference
getApplicationContext().getSharedPreferences("JSONChannelPrefs", Activity.MODE_PRIVATE).edit().putString("JSONDefinitions", jsonStrDef).commit();
getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_DEFINITIONS, jsonStrDef).commit();

}
} else {
Expand Down
Loading

0 comments on commit 9ac2f68

Please sign in to comment.