From 8f446bc787e150b70d83b64003a321902e65e9b4 Mon Sep 17 00:00:00 2001 From: Sirko Date: Wed, 24 Aug 2016 09:16:09 +0200 Subject: [PATCH 1/4] fixed image links in README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0967366..597f698 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ App Language: english, deutsch Download: [https://github.com/volkszaehler/app-android/releases/latest](https://github.com/volkszaehler/app-android/releases/latest "Latest Release") -![ScreenShot1](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/uebersicht.png "ScreenShots 1 of VolkszaehlerApp") -![ScreenShot2](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/details.png "ScreenShots 2 of VolkszaehlerApp") -![ScreenShot3](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/grafik.png "ScreenShots 3 of VolkszaehlerApp") -![ScreenShot4](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/einstellungen.png "ScreenShots 4 of VolkszaehlerApp") +![ScreenShot1](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/uebersicht.png?w=200&tok=2908a1 "ScreenShots 1 of VolkszaehlerApp") +![ScreenShot2](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/details.png?w=200&tok=60ff35 "ScreenShots 2 of VolkszaehlerApp") +![ScreenShot3](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/grafik.png?w=200&tok=3e01fa "ScreenShots 3 of VolkszaehlerApp") +![ScreenShot4](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/einstellungen.png?w=200&tok=ede86f "ScreenShots 4 of VolkszaehlerApp") ## VolkszählerApp für Android, Version 0.8.8 --- From bf0dfb69db452efe56304d34935d710a800204d1 Mon Sep 17 00:00:00 2001 From: Sirko Date: Fri, 9 Sep 2016 10:56:50 +0200 Subject: [PATCH 2/4] fixed image links in README, reworked error handling --- app/build.gradle | 2 +- .../volkszaehlerapp/ChannelDetails.java | 67 ++++++------- .../volkszaehlerapp/ChartDetails.java | 95 +++++++++---------- .../volkszaehlerapp/MainActivity.java | 33 ++++--- .../volkszaehlerapp/MySSLSocketFactory.java | 4 +- .../volkszaehlerapp/Preferences.java | 50 +++++----- .../volkszaehlerapp/ServiceHandler.java | 53 +++++++---- .../volkszaehler/volkszaehlerapp/Tools.java | 30 +++--- 8 files changed, 170 insertions(+), 164 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 28ecc8b..932ec04 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { defaultConfig { applicationId "org.volkszaehler.volkszaehlerapp" minSdkVersion 14 - targetSdkVersion 23 + targetSdkVersion 24 } compileOptions { diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChannelDetails.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChannelDetails.java index 63d11cb..9886cd8 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChannelDetails.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChannelDetails.java @@ -1,9 +1,5 @@ package org.volkszaehler.volkszaehlerapp; -import java.text.DateFormat; -import java.util.Date; -import java.util.Locale; - import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -21,21 +17,24 @@ import android.widget.TextView; import android.widget.Toast; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.text.DateFormat; +import java.util.Date; +import java.util.Locale; + public class ChannelDetails extends Activity { private String mUUID = ""; private static Context myContext; private ProgressDialog pDialog; - String unit; - String jsonStrGesamt =""; - boolean strom = false; - boolean gas = false; - boolean water = false; - boolean temp = false; + private String unit; + private String jsonStrGesamt =""; + private boolean strom = false; + private boolean gas = false; + private boolean water = false; + private boolean temp = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -113,8 +112,8 @@ public void onCreate(Bundle savedInstanceState) { } else { // no cost - ((TextView) findViewById(R.id.textViewTitleCost)).setVisibility(View.GONE); - ((TextView) findViewById(R.id.textViewCost)).setVisibility(View.GONE); + findViewById(R.id.textViewTitleCost).setVisibility(View.GONE); + findViewById(R.id.textViewCost).setVisibility(View.GONE); } } catch (NumberFormatException nfe) { Log.e("ChannelDetails", "strange costs: " + Tools.getPropertyOfChannel(myContext, mUUID, Tools.TAG_COST)); @@ -160,8 +159,8 @@ else if (!"".equals(jsonStrGesamt)) else { //remove consumption from dialog - ((TextView) findViewById(R.id.textViewTitleGesamt)).setVisibility(View.GONE); - ((TextView) findViewById(R.id.textViewGesamt)).setVisibility(View.GONE); + findViewById(R.id.textViewTitleGesamt).setVisibility(View.GONE); + findViewById(R.id.textViewGesamt).setVisibility(View.GONE); } } @@ -198,31 +197,23 @@ protected String doInBackground(String... arg0) { } else { jsonStrGesamt = sh.makeServiceCall(urlDef, ServiceHandler.GET, null, uname, pwd); } - if (jsonStrGesamt != null) { - if (!jsonStrGesamt.startsWith("{\"version\":\"0.3\",\"data")) { - JSONFehler = true; - fehlerAusgabe = jsonStrGesamt; - } else { - Log.d("ChannelDetails", "jsonStrGesamt: " + jsonStrGesamt); - try { - if (gas) - { - jsonStrGesamt = String.valueOf(Tools.f000.format(new JSONObject(jsonStrGesamt).getJSONObject(Tools.TAG_DATA).getDouble(Tools.TAG_CONSUMPTION) + Double.valueOf(arg0[0]))); - } - else if (strom) - { - jsonStrGesamt = String.valueOf(Tools.f000.format((new JSONObject(jsonStrGesamt).getJSONObject(Tools.TAG_DATA).getDouble(Tools.TAG_CONSUMPTION) + Double.valueOf(arg0[0]) * 1000)/1000)); - } - else if (water) - { - jsonStrGesamt = String.valueOf(Tools.f0.format(new JSONObject(jsonStrGesamt).getJSONObject(Tools.TAG_DATA).getDouble(Tools.TAG_CONSUMPTION) + Double.valueOf(arg0[0]))); - } - } catch (JSONException je) { - Log.e("ChannelDetails", je.getMessage()); + + if (jsonStrGesamt.startsWith("Error: ")) { + JSONFehler = true; + fehlerAusgabe = jsonStrGesamt; + } else { + Log.d("ChannelDetails", "jsonStrGesamt: " + jsonStrGesamt); + try { + if (gas) { + jsonStrGesamt = String.valueOf(Tools.f000.format(new JSONObject(jsonStrGesamt).getJSONObject(Tools.TAG_DATA).getDouble(Tools.TAG_CONSUMPTION) + Double.valueOf(arg0[0]))); + } else if (strom) { + jsonStrGesamt = String.valueOf(Tools.f000.format((new JSONObject(jsonStrGesamt).getJSONObject(Tools.TAG_DATA).getDouble(Tools.TAG_CONSUMPTION) + Double.valueOf(arg0[0]) * 1000) / 1000)); + } else if (water) { + jsonStrGesamt = String.valueOf(Tools.f0.format(new JSONObject(jsonStrGesamt).getJSONObject(Tools.TAG_DATA).getDouble(Tools.TAG_CONSUMPTION) + Double.valueOf(arg0[0]))); } + } catch (JSONException je) { + Log.e("ChannelDetails", je.getMessage()); } - } else { - Log.e("ChannelDetails", "Couldn't get any data from the url"); } return null; } diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java index aef8b71..7e4b604 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java @@ -1,26 +1,5 @@ package org.volkszaehler.volkszaehlerapp; -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.achartengine.ChartFactory; -import org.achartengine.GraphicalView; -import org.achartengine.model.SeriesSelection; -import org.achartengine.model.TimeSeries; -import org.achartengine.model.XYMultipleSeriesDataset; -import org.achartengine.renderer.XYMultipleSeriesRenderer; -import org.achartengine.renderer.XYSeriesRenderer; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -47,6 +26,26 @@ import android.widget.TextView; import android.widget.Toast; +import org.achartengine.ChartFactory; +import org.achartengine.GraphicalView; +import org.achartengine.model.SeriesSelection; +import org.achartengine.model.TimeSeries; +import org.achartengine.model.XYMultipleSeriesDataset; +import org.achartengine.renderer.XYMultipleSeriesRenderer; +import org.achartengine.renderer.XYSeriesRenderer; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + public class ChartDetails extends Activity { @@ -305,10 +304,10 @@ public boolean onTouchEvent(MotionEvent event) { private void addMultipleGraphs() { - List channelNames = new ArrayList(); + List channelNames = new ArrayList<>(); int i = 0; - final HashMap channelsToRequest = new HashMap(); + final HashMap channelsToRequest = new HashMap<>(); //get the currently set Channels (in preferences) for (String uuid : PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getAll().keySet()) { // assume its a UUID of a channel @@ -670,40 +669,35 @@ protected String doInBackground(Void... arg0) { } } - if (jsonStr != null) { - if (!jsonStr.startsWith("{\"version\":\"0.3\",\"data")) { + if (jsonStr.startsWith("Error: ")) { JSONFehler = true; fehlerAusgabe = jsonStr; - } else { + } else { - // store all data stuff in a shared preference - getApplicationContext().getSharedPreferences("JSONChannelPrefs", Activity.MODE_PRIVATE).edit().putString("JSONChannelsData", jsonStr).commit(); - - JSONObject jsonObj; - try { - jsonObj = new JSONObject(jsonStr); - werte = jsonObj.getJSONArray(Tools.TAG_DATA); - for (int l = 0; l < werte.length(); l++) { - JSONObject c = werte.getJSONObject(l); - if (c.has(Tools.TAG_TUPLES)) { - JSONArray tuples = c.getJSONArray(Tools.TAG_TUPLES); - // at least one with tuples - JSONFehler = false; - break; - } else { - JSONFehler = true; - fehlerAusgabe = "no tuples data"; - } + // store all data stuff in a shared preference + getApplicationContext().getSharedPreferences("JSONChannelPrefs", Activity.MODE_PRIVATE).edit().putString("JSONChannelsData", jsonStr).commit(); + + JSONObject jsonObj; + try { + jsonObj = new JSONObject(jsonStr); + werte = jsonObj.getJSONArray(Tools.TAG_DATA); + for (int l = 0; l < werte.length(); l++) { + JSONObject c = werte.getJSONObject(l); + if (c.has(Tools.TAG_TUPLES)) { + JSONArray tuples = c.getJSONArray(Tools.TAG_TUPLES); + // at least one with tuples + JSONFehler = false; + break; + } else { + JSONFehler = true; + fehlerAusgabe = "no tuples data"; } - - } catch (JSONException e) { - e.printStackTrace(); } + + } catch (JSONException e) { + e.printStackTrace(); } - } else { - Log.e("ChartDetails", "Couldn't get any data from the url"); } - return null; } @@ -715,7 +709,6 @@ protected void onPostExecute(String result) { if (pDialog.isShowing()) pDialog.dismiss(); } catch (Exception e) { - // TODO Auto-generated catch block // handle Exception } if (JSONFehler) { diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java index ed4ed5f..6d0a5b8 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java @@ -1,12 +1,5 @@ package org.volkszaehler.volkszaehlerapp; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; - -import org.json.JSONArray; -import org.json.JSONObject; - import android.app.Activity; import android.app.AlertDialog; import android.app.ListActivity; @@ -31,6 +24,13 @@ import android.widget.TextView; import android.widget.Toast; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Locale; + public class MainActivity extends ListActivity { private static Context myContext; private String jsonStr = ""; @@ -250,7 +250,6 @@ protected Void doInBackground(String... arg0) { String url = sharedPref.getString("volkszaehlerURL", ""); long millisNow = System.currentTimeMillis(); - long plus1second = millisNow + 1000; url = url + "/data.json?from=now&" + uRLUUIDs; Log.d("MainActivity: ", "url: " + url); @@ -267,16 +266,17 @@ protected Void doInBackground(String... arg0) { Log.d("MainActivity", "response: " + jsonStr); } - if (jsonStr != null) { - if (!jsonStr.startsWith("{\"version\":\"0.3\",\"data")) { + if (jsonStr.startsWith("Error: ")) { JSONFehler = true; fehlerAusgabe = android.text.Html.fromHtml(jsonStr).toString(); - if (jsonStr.startsWith("{\"version\":\"0.3\"}")) { - fehlerAusgabe = fehlerAusgabe + "\n" + getString(R.string.no_ChannelsSelected); - } + + } else { + JSONObject jsonObj = new JSONObject(jsonStr); + + if (!jsonObj.has(Tools.TAG_DATA)) { + fehlerAusgabe = fehlerAusgabe + "\n" + getString(R.string.no_ChannelsSelected); } else { - JSONObject jsonObj = new JSONObject(jsonStr); // Getting JSON Array node werte = jsonObj.getJSONArray(Tools.TAG_DATA); @@ -312,8 +312,7 @@ protected Void doInBackground(String... arg0) { String rows = c.has(Tools.TAG_ROWS) ? c.getString(Tools.TAG_ROWS) : ""; if (c.has(Tools.TAG_TUPLES)) { JSONArray tuples = c.getJSONArray(Tools.TAG_TUPLES); - if(tuples.length()<1) - { + if (tuples.length() < 1) { continue; } // only one tuple (in URL), otherwise loop here @@ -388,7 +387,7 @@ public View getView(int position, View convertView, android.view.ViewGroup paren HashMap items = (HashMap) getListView().getItemAtPosition(position); //empty color, default = blue - String col = "".equals(items.get(Tools.TAG_COLOR)) ? "blue" : items.get(Tools.TAG_COLOR); + String col = "".equals(items.get(Tools.TAG_COLOR)) ? "#0000FF" : items.get(Tools.TAG_COLOR); if (col.startsWith("#")) { ((TextView) view.findViewById(R.id.channelName)).setTextColor(Color.parseColor(col.toUpperCase(Locale.getDefault()))); diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/MySSLSocketFactory.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/MySSLSocketFactory.java index 1301789..22e2a4a 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/MySSLSocketFactory.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/MySSLSocketFactory.java @@ -1,5 +1,7 @@ package org.volkszaehler.volkszaehlerapp; +import org.apache.http.conn.ssl.SSLSocketFactory; + import java.io.IOException; import java.net.Socket; import java.security.KeyManagementException; @@ -14,8 +16,6 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; -import org.apache.http.conn.ssl.SSLSocketFactory; - class MySSLSocketFactory extends SSLSocketFactory { private final SSLContext sslContext = SSLContext.getInstance("TLS"); diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java index 6dbab4c..e15e17f 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java @@ -1,8 +1,5 @@ package org.volkszaehler.volkszaehlerapp; -import java.util.ArrayList; -import java.util.HashMap; - import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -17,6 +14,12 @@ import android.preference.PreferenceManager; import android.util.Log; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; + public class Preferences extends PreferenceActivity { private boolean newChannels = false; private ProgressDialog pDialog; @@ -175,29 +178,31 @@ protected String doInBackground(Void... arg0) { jsonStr = sh.makeServiceCall(url, ServiceHandler.GET, null, uname, pwd); jsonStrDef = sh.makeServiceCall(urlDef, ServiceHandler.GET, null, uname, pwd); } - if (jsonStr != null) { - if (!jsonStr.startsWith("{\"version\":\"0.3\",\"entities")) { + if (jsonStr.startsWith("Error: ") || jsonStrDef.startsWith("Error: ")) { + //{"version":"0.3","entities JSONFehler = true; - fehlerAusgabe = jsonStr; - } else { - newChannels = true; - Log.d("Preferences", "jsonStr: " + jsonStr); - // store all channel stuff in a shared preference - getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_CHANNELS, jsonStr).commit(); + fehlerAusgabe = jsonStr + " | " +jsonStrDef;; + } else { + try { + JSONObject jsonStrObj = new JSONObject(jsonStr); + JSONObject jsonStrDefObj = new JSONObject(jsonStrDef); + if(jsonStrObj.has("entities")) { + newChannels = true; + Log.d("Preferences", "jsonStr: " + jsonStr); + // store all channel stuff in a shared preference + getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_CHANNELS, jsonStr).commit(); + } + if (jsonStrDefObj.has("capabilities")) { + Log.d("Preferences", "jsonStrDef: " + jsonStrDef); + // store all definitions stuff in a shared preference + getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_DEFINITIONS, jsonStrDef).commit(); + } + } catch (JSONException e) { + JSONFehler = true; + fehlerAusgabe = jsonStr + " | " +jsonStrDef; } - if (!jsonStrDef.startsWith("{\"version\":\"0.3\",\"capabilities")) { - JSONFehler2 = true; - fehlerAusgabe2 = jsonStrDef; - } else { - Log.d("Preferences", "jsonStrDef: " + jsonStrDef); - // store all definitions stuff in a shared preference - getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_DEFINITIONS, jsonStrDef).commit(); - } - } else { - Log.e("Preferences", "Couldn't get any data from the url"); } - return null; } @@ -209,7 +214,6 @@ protected void onPostExecute(String result) { if (pDialog.isShowing()) pDialog.dismiss(); } catch (Exception e) { - // TODO Auto-generated catch block // handle Exception } if (JSONFehler || JSONFehler2) { diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java index 0f25dee..942d797 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java @@ -1,14 +1,7 @@ package org.volkszaehler.volkszaehlerapp; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.IDN; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.security.KeyStore; -import java.util.List; +import android.util.Base64; +import android.util.Log; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -32,9 +25,18 @@ import org.apache.http.params.HttpProtocolParams; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; +import org.json.JSONException; +import org.json.JSONObject; -import android.util.Base64; -import android.util.Log; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.IDN; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.KeyStore; +import java.util.List; class ServiceHandler { @@ -107,7 +109,7 @@ private String makeServiceCall(String url, int method, List param } public String makeServiceCall(String url, int method, List params, String uname, String pwd) { - String response; + String response =""; try { // http client @@ -142,18 +144,35 @@ public String makeServiceCall(String url, int method, List params } httpResponse = httpClient.execute(httpGet); } - httpEntity = httpResponse.getEntity(); - response = EntityUtils.toString(httpEntity); + + if(200 == (httpResponse.getStatusLine().getStatusCode())) + { + httpEntity = httpResponse.getEntity(); + response = EntityUtils.toString(httpEntity); + try { + JSONObject jsonObj = new JSONObject(response); + } catch (JSONException e) { + //no JSON response + response = "Error: " + response; + e.printStackTrace(); + } + } + else + { + //error occurred + response = "Error: " + response; + } + } catch (UnsupportedEncodingException e) { e.printStackTrace(); - return e.getMessage(); + return "Error: " + e.getMessage(); } catch (ClientProtocolException e) { e.printStackTrace(); - return e.getMessage(); + return "Error: " + e.getMessage(); } catch (IOException e) { e.printStackTrace(); - return e.getMessage(); + return "Error: " + e.getMessage(); } return response; } diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java index 78edbbe..bc7d3e9 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java @@ -1,20 +1,5 @@ package org.volkszaehler.volkszaehlerapp; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; - -import org.achartengine.model.TimeSeries; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import android.app.Activity; import android.app.AlertDialog; import android.content.Context; @@ -29,6 +14,21 @@ import android.view.WindowManager; import android.widget.TextView; +import org.achartengine.model.TimeSeries; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; + class Tools { private static final String TAG_ENTITIES = "entities"; From 3a52e83e90f5f16737a72cbadd1a12b6db8bc5b4 Mon Sep 17 00:00:00 2001 From: Sirko Date: Fri, 7 Oct 2016 13:14:20 +0200 Subject: [PATCH 3/4] fixed image links in README, reworked error handling Values copyable, Fontsize --- README.md | 27 +++++--- app/app.iml | 16 ++--- app/src/main/AndroidManifest.xml | 4 +- .../volkszaehlerapp/ChartDetails.java | 2 +- .../volkszaehlerapp/MainActivity.java | 3 +- .../volkszaehlerapp/Preferences.java | 63 +++++++++++++++++-- .../volkszaehlerapp/ServiceHandler.java | 7 ++- .../volkszaehler/volkszaehlerapp/Tools.java | 12 +++- app/src/main/res/layout/details.xml | 43 ++++++++----- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values/strings.xml | 8 ++- .../main/res/xml/volkszaehler_preferences.xml | 4 ++ build.gradle | 2 +- 13 files changed, 144 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 597f698..c4b89a5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Download: [https://github.com/volkszaehler/app-android/releases/latest](https:// ![ScreenShot3](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/grafik.png?w=200&tok=3e01fa "ScreenShots 3 of VolkszaehlerApp") ![ScreenShot4](http://wiki.volkszaehler.org/_media/software/frontends/vz_app/einstellungen.png?w=200&tok=ede86f "ScreenShots 4 of VolkszaehlerApp") -## VolkszählerApp für Android, Version 0.8.8 +## VolkszählerApp für Android, Version 0.8.9 --- Funktionen: @@ -35,7 +35,7 @@ Wenn das Clonen bzw. das Öffnen des Projektes wegen eines ausgegrauten "Use def English: -## VolkszaehlerApp for Android, Version 0.8.8 +## VolkszaehlerApp for Android, Version 0.8.9 --- Features: @@ -62,17 +62,28 @@ If the cloning resp. opening of the project fails due to a grayed "Use default g ###Version history: --- -###Version 0.8.8 +###Version 0.8.9 ####New - - It is now possible to have several graphs in one chart, use "Long Press" in chart view, Limitation: there is only one y-Axis - - ChannelDetails show now the total value if an initial value is set for the channel - - Number of Tuples can be set now (default is 1000), a higher number makes the Charts more detailled (as long as there are enough values in the database), but slows down the charts + - Private channels can be manually added in preferences, if there are more than one, add them comma separated like uuid1,uuid2,uuid3 ####Fixed - - fixed display issues with Channels of type "water" and costs + - better error handling, works with older Volkszaehler version now + +####Changed + - small optimizations ([Font Size](https://github.com/volkszaehler/app-android/issues/16), [Values can be copied](https://github.com/volkszaehler/app-android/issues/14)) + +###Version 0.8.8 +####New + - It is now possible to have several graphs in one chart, use "Long Press" in chart view, Limitation: there is only one y-Axis + - ChannelDetails show now the total value if an initial value is set for the channel + - Number of Tuples can be set now (default is 1000), a higher number makes the Charts more detailled (as long as there are enough values in the database), but slows down the charts + +####Fixed + - fixed display issues with Channels of type "water" and costs + ####Changed - - small optimizations + - small optimizations ###Version 0.8.7 ####Fixed diff --git a/app/app.iml b/app/app.iml index 1148675..eb680c7 100644 --- a/app/app.iml +++ b/app/app.iml @@ -64,14 +64,6 @@ - - - - - - - - @@ -80,6 +72,14 @@ + + + + + + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ffc802e..b1fdf3f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="89" + android:versionName="0.8.9" > diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java index 7e4b604..09aba8a 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ChartDetails.java @@ -55,7 +55,7 @@ public class ChartDetails extends Activity { private final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); - private final XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); + private final XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(2); private GraphicalView mChartView; diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java index 6d0a5b8..769babb 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/MainActivity.java @@ -250,7 +250,7 @@ protected Void doInBackground(String... arg0) { String url = sharedPref.getString("volkszaehlerURL", ""); long millisNow = System.currentTimeMillis(); - url = url + "/data.json?from=now&" + uRLUUIDs; + url = url + "/data.json?from=now" + uRLUUIDs; Log.d("MainActivity: ", "url: " + url); @@ -275,6 +275,7 @@ protected Void doInBackground(String... arg0) { JSONObject jsonObj = new JSONObject(jsonStr); if (!jsonObj.has(Tools.TAG_DATA)) { + JSONFehler = true; fehlerAusgabe = fehlerAusgabe + "\n" + getString(R.string.no_ChannelsSelected); } else { diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java index e15e17f..e8f1d30 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Preferences.java @@ -14,6 +14,7 @@ import android.preference.PreferenceManager; import android.util.Log; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -29,6 +30,7 @@ public class Preferences extends PreferenceActivity { private static String uname; private static String pwd; private static String tuples; + private static String privateChannelString; private ArrayList> channelList = new ArrayList<>(); @@ -55,6 +57,8 @@ public boolean onPreferenceClick(Preference arg0) { boolean bZeroBased = prefs.getBoolean("ZeroBasedYAxis", false); boolean bAutoReload = prefs.getBoolean("autoReload", false); tuples = prefs.getString("Tuples","1000"); + privateChannelString = prefs.getString("privateChannelUUIDs",""); + // remove all @@ -66,6 +70,7 @@ public boolean onPreferenceClick(Preference arg0) { prefs.edit().putBoolean("ZeroBasedYAxis", bZeroBased).commit(); prefs.edit().putBoolean("autoReload", bAutoReload).commit(); prefs.edit().putString("Tuples", tuples).commit(); + prefs.edit().putString("privateChannelUUIDs", privateChannelString).commit(); // call Channels from VZ installation new GetChannels().execute(); return true; @@ -87,8 +92,9 @@ public void onBackPressed() { private void addPreferenceChannels() { SharedPreferences prefs = getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE); String JSONChannels = prefs.getString(Tools.JSON_CHANNELS, ""); - Log.d("Preferences", "JSONChannels" + JSONChannels); + Log.d("Preferences", "JSONChannels: " + JSONChannels); if (JSONChannels.equals("")) { + //Todo: sinnfrei? return; } PreferenceCategory targetCategory = (PreferenceCategory) findPreference("channel_preference_category"); @@ -158,12 +164,20 @@ protected String doInBackground(Void... arg0) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Preferences.this); url = sharedPref.getString("volkszaehlerURL", ""); + //private channels + String privateChannelString = sharedPref.getString("privateChannelUUIDs",""); + String[] privateChannels = privateChannelString.split(","); + String baseURL = url; + // get also definitions (Units) String urlDef = url + "/capabilities/definitions/entities.json"; url = url + "/entity.json"; String jsonStr; String jsonStrDef; + String jsonprivateStr; + + JSONObject jsonStrObj = null; uname = sharedPref.getString("username", ""); pwd = sharedPref.getString("password", ""); @@ -178,19 +192,19 @@ protected String doInBackground(Void... arg0) { jsonStr = sh.makeServiceCall(url, ServiceHandler.GET, null, uname, pwd); jsonStrDef = sh.makeServiceCall(urlDef, ServiceHandler.GET, null, uname, pwd); } + if (jsonStr.startsWith("Error: ") || jsonStrDef.startsWith("Error: ")) { - //{"version":"0.3","entities JSONFehler = true; fehlerAusgabe = jsonStr + " | " +jsonStrDef;; } else { try { - JSONObject jsonStrObj = new JSONObject(jsonStr); + jsonStrObj = new JSONObject(jsonStr); JSONObject jsonStrDefObj = new JSONObject(jsonStrDef); - if(jsonStrObj.has("entities")) { + if(jsonStrObj.has("entities") && !jsonStrObj.getString("entities").equals("[]")) { newChannels = true; Log.d("Preferences", "jsonStr: " + jsonStr); // store all channel stuff in a shared preference - getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_CHANNELS, jsonStr).commit(); + //getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_CHANNELS, jsonStr).commit(); } if (jsonStrDefObj.has("capabilities")) { Log.d("Preferences", "jsonStrDef: " + jsonStrDef); @@ -203,6 +217,45 @@ protected String doInBackground(Void... arg0) { } } + + String privatChannelURL =""; + if(!"".equals(privateChannelString)) { + //Loop over each private channel + for (String channelUUID : privateChannels) { + channelUUID = channelUUID.trim(); + privatChannelURL = baseURL + "/entity/" + channelUUID + ".json"; + Log.d("Preferences", "privatChannelURL: " + privatChannelURL); + if (uname.equals("")) { + jsonprivateStr = sh.makeServiceCall(privatChannelURL, ServiceHandler.GET); + } else { + jsonprivateStr = sh.makeServiceCall(privatChannelURL, ServiceHandler.GET, null, uname, pwd); + } + if (jsonprivateStr.startsWith("Error: ")) { + JSONFehler = true; + fehlerAusgabe = jsonprivateStr; + } else { + try { + JSONObject jsonprivateStrObj = new JSONObject(jsonprivateStr); + if (jsonprivateStrObj.has("entity") && !jsonprivateStrObj.getString("entity").equals("[]")) { + newChannels = true; + Log.d("Preferences", "jsonprivateStr: " + jsonprivateStr); + JSONObject privateChannelEntity = jsonprivateStrObj.getJSONObject("entity"); + JSONArray entitiesArray = jsonStrObj.getJSONArray("entities"); + entitiesArray.put(privateChannelEntity); + jsonStrObj.put("entities", entitiesArray); + } + } catch (JSONException e) { + JSONFehler = true; + fehlerAusgabe = jsonprivateStr; + } + } + } + } + + // store all channel stuff in a shared preference + jsonStr = jsonStrObj.toString(); + getApplicationContext().getSharedPreferences(Tools.JSON_CHANNEL_PREFS, Activity.MODE_PRIVATE).edit().putString(Tools.JSON_CHANNELS, jsonStr).commit(); + return null; } diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java index 942d797..9aa4c1b 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/ServiceHandler.java @@ -145,10 +145,11 @@ public String makeServiceCall(String url, int method, List params httpResponse = httpClient.execute(httpGet); } + httpEntity = httpResponse.getEntity(); + response = EntityUtils.toString(httpEntity); + if(200 == (httpResponse.getStatusLine().getStatusCode())) { - httpEntity = httpResponse.getEntity(); - response = EntityUtils.toString(httpEntity); try { JSONObject jsonObj = new JSONObject(response); } catch (JSONException e) { @@ -160,7 +161,7 @@ public String makeServiceCall(String url, int method, List params else { //error occurred - response = "Error: " + response; + response = "Error: " + httpResponse.getStatusLine() + " " + response; } diff --git a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java index bc7d3e9..1e96d12 100644 --- a/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java +++ b/app/src/main/java/org/volkszaehler/volkszaehlerapp/Tools.java @@ -394,6 +394,7 @@ static boolean saveFile(Context context) { fw.write(JSON_DEFINITIONS + "=" + prefs.getString(JSON_DEFINITIONS, "") + "\n"); fw.write("volkszaehlerURL" + "=" + sharedPrefs.getString("volkszaehlerURL", "") + "\n"); fw.write("Tuples" + "=" + sharedPrefs.getString("Tuples", "1000") + "\n"); + fw.write("privateChannelUUIDs" + "=" + sharedPrefs.getString("privateChannelUUIDs", "") + "\n"); fw.write("ZeroBasedYAxis" + "=" + (sharedPrefs.getBoolean("ZeroBasedYAxis", false) ? "true" : "false") + "\n"); fw.write("autoReload" + "=" + (sharedPrefs.getBoolean("autoReload", false) ? "true" : "false")); } catch (IOException e) { @@ -455,7 +456,16 @@ static boolean loadFile(Context context) { continue; } PreferenceManager.getDefaultSharedPreferences(context).edit().putString("Tuples", line).commit(); - }else if (line.startsWith("ZeroBasedYAxis")) { + } else if (line.startsWith("privateChannelUUIDs")) { + try { + line = line.split("=")[1]; + } + catch (IndexOutOfBoundsException iobx) + { + continue; + } + PreferenceManager.getDefaultSharedPreferences(context).edit().putString("privateChannelUUIDs", line).commit(); + } else if (line.startsWith("ZeroBasedYAxis")) { try { line = line.split("=")[1]; } diff --git a/app/src/main/res/layout/details.xml b/app/src/main/res/layout/details.xml index 8e9a0d7..c6f310c 100644 --- a/app/src/main/res/layout/details.xml +++ b/app/src/main/res/layout/details.xml @@ -32,14 +32,16 @@ android:layout_height="wrap_content" android:ellipsize="end" android:gravity="left" - android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textAppearance="?android:attr/textAppearanceLarge" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceLarge" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceSmall" /> + android:textAppearance="?android:attr/textAppearanceSmall" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" + android:textIsSelectable="true" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" + android:textIsSelectable="true" /> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index f015045..bd65b4f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -14,7 +14,9 @@ Liste der bekannten Kanäle Klicken um Kanäle abzurufen Kanäle abrufen - Kanäle neuladen + Kanäle hinzufügen + UUIDs privater Kanäle hinzufügen, kommasepariert, z.B.: uuid1,uuid2 + UUIDs manuell hinzufügen Rufe Daten von der Volkszählerinstallation ab… NeuLaden Kanaldetails diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b1ffec2..1da8678 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,9 +12,11 @@ Volkszaehler URL The Channels get from the Volkszaehler installation List of known Channels - Click to get the channels list. - Get Channels - ReLoad Channels + Click to get all Channels. + Load Channels + Enter UUIDs of private Channels, comma separated, e.g. uuid1,uuid2 + Add UUIDs manually + Get Channels Requesting data from Volkszaehler… ReLoad Channel Details diff --git a/app/src/main/res/xml/volkszaehler_preferences.xml b/app/src/main/res/xml/volkszaehler_preferences.xml index 343ef4a..c58c0ca 100644 --- a/app/src/main/res/xml/volkszaehler_preferences.xml +++ b/app/src/main/res/xml/volkszaehler_preferences.xml @@ -32,6 +32,10 @@ + Date: Fri, 14 Oct 2016 11:52:11 +0200 Subject: [PATCH 4/4] fixed image links in README, reworked error handling Values copyable, Fontsize --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4b89a5..2b78cf6 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ If the cloning resp. opening of the project fails due to a grayed "Use default g ###Version 0.8.6 ####Fixed - empty Channel Color causes crash - - Umlauts in host name causes crash + - Umlauts in host name cause crash ###Version 0.8.5 ####Changed