From 968c73c1844b2e9c27817954bfcf0551d518a621 Mon Sep 17 00:00:00 2001 From: santimunin Date: Wed, 27 Jun 2012 15:37:10 +0000 Subject: [PATCH] 2012-06-27 Santiago Munin * src/pandroid_event_viewer/pandorafms/Core.java: Added "apipass" parameter to petitions. * src/pandroid_event_viewer/pandorafms/Options.java: Added an API Password entry. Now, after getting the API version, it is stored in SharedPreferences. * src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: Changed event parsing. * src/pandroid_event_viewer/pandorafms/API.java: Added some checks before parsing tags and groups. * res/values/strings.xml: Added new entries. * res/layout/options.xml: Added an API Password entry. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6721 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- extras/pandroid_event_viewer/ChangeLog | 9 +++++ .../res/layout/options.xml | 14 +++++++ .../res/values/strings.xml | 2 + .../pandroid_event_viewer/pandorafms/API.java | 28 ++++++++++---- .../pandorafms/Core.java | 4 ++ .../pandorafms/Options.java | 37 ++++++++++++------- .../PandroidEventviewerActivity.java | 24 +++++------- 7 files changed, 82 insertions(+), 36 deletions(-) diff --git a/extras/pandroid_event_viewer/ChangeLog b/extras/pandroid_event_viewer/ChangeLog index 3fea6862ae..f0c29a28f1 100644 --- a/extras/pandroid_event_viewer/ChangeLog +++ b/extras/pandroid_event_viewer/ChangeLog @@ -1,3 +1,12 @@ +2012-06-27 Santiago Munín + + * src/pandroid_event_viewer/pandorafms/Core.java: Added "apipass" parameter to petitions. + * src/pandroid_event_viewer/pandorafms/Options.java: Added an API Password entry. Now, after getting the API version, it is stored in SharedPreferences. + * src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: Changed event parsing. + * src/pandroid_event_viewer/pandorafms/API.java: Added some checks before parsing tags and groups. + * res/values/strings.xml: Added new entries. + * res/layout/options.xml: Added an API Password entry. + 2012-06-26 Santiago Munín * src/pandroid_event_viewer/pandorafms/API.java: Added new api calls. diff --git a/extras/pandroid_event_viewer/res/layout/options.xml b/extras/pandroid_event_viewer/res/layout/options.xml index 13526978a4..11540fcc4f 100644 --- a/extras/pandroid_event_viewer/res/layout/options.xml +++ b/extras/pandroid_event_viewer/res/layout/options.xml @@ -83,6 +83,20 @@ android:layout_height="wrap_content" android:inputType="textPassword" android:singleLine="true" /> + + + + URL User Password + API Password Update Options Load more events @@ -130,4 +131,5 @@ Delete profile There was a problem. Check your connection. The operation can not be performed until you configure a correct connection. + Unknown version \ No newline at end of file diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/API.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/API.java index b993d16266..5eae38b4dc 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/API.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/API.java @@ -38,10 +38,13 @@ public class API { String return_api = Core.httpGet(context, parameters); String[] lines = return_api.split("\n"); - - for (int i = 0; i < lines.length; i++) { - String[] groups = lines[i].split(";", 21); - result.put(Integer.valueOf(groups[0]), groups[1]); + try { + for (int i = 0; i < lines.length; i++) { + String[] groups = lines[i].split(";", 21); + result.put(Integer.valueOf(groups[0]), groups[1]); + } + } catch (NumberFormatException e) { + Log.e(TAG, "Problem parsing number in response"); } return result; } @@ -89,7 +92,12 @@ public class API { return_api = Core.httpGet(context, parameters); // TODO wait version if (return_api.contains("OK")) { - return "4.0.2"; + String[] lines = return_api.split(","); + if (lines.length == 3) { + return lines[1]; + } else { + return context.getString(R.string.unknown_version); + } } else { return ""; } @@ -132,9 +140,13 @@ public class API { String return_api = Core.httpGet(context, parameters); String[] lines = return_api.split("\n"); array.add(""); - for (int i = 0; i < lines.length; i++) { - String[] tags = lines[i].split(";", 2); - array.add(tags[1]); + try { + for (int i = 0; i < lines.length; i++) { + String[] tags = lines[i].split(";", 2); + array.add(tags[1]); + } + } catch (ArrayIndexOutOfBoundsException e) { + Log.e(TAG, "There was a problem getting tags: " + e.getMessage()); } return array; } diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java index 58ddc75325..c8c4c29a54 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java @@ -318,12 +318,16 @@ public class Core { String url = preferences.getString("url", "") + "/include/api.php"; String user = preferences.getString("user", ""); String password = preferences.getString("password", ""); + String apiPassword = preferences.getString("api_password", ""); if (url.length() == 0 || user.length() == 0) { return ""; } ArrayList parameters = new ArrayList(); parameters.add(new BasicNameValuePair("user", user)); parameters.add(new BasicNameValuePair("pass", password)); + if (apiPassword.length() > 0) { + parameters.add(new BasicNameValuePair("apipass", apiPassword)); + } parameters.addAll(additionalParameters); if (url.toLowerCase().contains("https")) { // Secure connection diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java index d57604a575..f614bcb0f0 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java @@ -53,10 +53,6 @@ import android.widget.Toast; public class Options extends Activity { private static String TAG = "Options"; private static int RINGTONE_PICK_CODE = 999; - private String url; - private String user; - private String password; - private int refreshTimeKey; private TextView connectionStatus; private ProgressDialog retrievingCertificate; private Context context; @@ -77,18 +73,15 @@ public class Options extends Activity { this.getString(R.string.const_string_preferences), Activity.MODE_PRIVATE); // Connection - url = preferences.getString("url", - "http://firefly.artica.es/pandora_demo"); - user = preferences.getString("user", "demo"); - password = preferences.getString("password", "demo"); - refreshTimeKey = preferences.getInt("refreshTimeKey", 3); - EditText text = (EditText) findViewById(R.id.url); - text.setText(url); + text.setText(preferences.getString("url", + "http://firefly.artica.es/pandora_demo")); text = (EditText) findViewById(R.id.user); - text.setText(user); + text.setText(preferences.getString("user", "demo")); text = (EditText) findViewById(R.id.password); - text.setText(password); + text.setText(preferences.getString("password", "demo")); + text = (EditText) findViewById(R.id.api_password); + text.setText(preferences.getString("api_password", "")); Spinner combo = (Spinner) findViewById(R.id.refresh_combo); ArrayAdapter adapter = ArrayAdapter.createFromResource( @@ -96,7 +89,7 @@ public class Options extends Activity { android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); combo.setAdapter(adapter); - combo.setSelection(refreshTimeKey); + combo.setSelection(preferences.getInt("refreshTimeKey", 3)); final Button button = (Button) findViewById(R.id.update_options); button.setOnClickListener(new View.OnClickListener() { @@ -205,6 +198,8 @@ public class Options extends Activity { editorPreferences.putString("user", text.getText().toString()); text = (EditText) findViewById(R.id.password); editorPreferences.putString("password", text.getText().toString()); + text = (EditText) findViewById(R.id.api_password); + editorPreferences.putString("api_password", text.getText().toString()); Spinner combo = (Spinner) findViewById(R.id.refresh_combo); editorPreferences.putInt("refreshTimeKey", @@ -293,6 +288,14 @@ public class Options extends Activity { protected Boolean doInBackground(Void... arg0) { try { version = API.getVersion(getApplicationContext()); + SharedPreferences preferences = getSharedPreferences( + getString(R.string.const_string_preferences), + Activity.MODE_PRIVATE); + SharedPreferences.Editor editorPreferences = preferences.edit(); + editorPreferences.putString("api_version", version); + if (editorPreferences.commit()) { + Log.i(TAG, "API Version saved"); + } if (version.length() > 0) { return true; } else { @@ -318,6 +321,12 @@ public class Options extends Activity { } } + /** + * Checks (in background) if the certificate of the site is signed by a CA. + * + * @author Santiago Munín González + * + */ private class CheckCertificateAsyncTask extends AsyncTask { private URL url; diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java index 866e25e483..79190fa2c3 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java @@ -347,14 +347,9 @@ public class PandroidEventviewerActivity extends TabActivity implements } for (int i = 0; i < lines.length; i++) { - String[] items = lines[i].split(";", 23); + String[] items = lines[i].split(";"); EventListItem event = new EventListItem(); - - if (items.length != 23) { - event.event = getApplication().getString( - R.string.unknown_event_str); - } else { try { if (items[0].length() == 0) { event.id_event = 0; @@ -402,19 +397,20 @@ public class PandroidEventviewerActivity extends TabActivity implements } event.user_comment = items[12]; event.tags = items[13]; - event.agent_name = items[16]; - event.group_name = items[17]; - event.group_icon = items[18]; - event.description_event = items[19]; - event.description_image = items[20]; - event.criticity_name = items[21]; - event.criticity_image = items[22]; + event.agent_name = items[14]; + event.group_name = items[15]; + event.group_icon = items[16]; + event.description_event = items[17]; + event.description_image = items[18]; + event.criticity_name = items[19]; + event.criticity_image = items[20]; event.opened = false; } catch (NumberFormatException nfe) { + event.event = getApplication().getString( + R.string.unknown_event_str); launchProblemParsingNotification(); } - } this.eventList.add(event); } }