2012-06-27 Santiago Munin <burning1@gmail.com>
* 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
This commit is contained in:
parent
638d8b183e
commit
968c73c184
|
@ -1,3 +1,12 @@
|
||||||
|
2012-06-27 Santiago Munín <burning1@gmail.com>
|
||||||
|
|
||||||
|
* 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 <burning1@gmail.com>
|
2012-06-26 Santiago Munín <burning1@gmail.com>
|
||||||
|
|
||||||
* src/pandroid_event_viewer/pandorafms/API.java: Added new api calls.
|
* src/pandroid_event_viewer/pandorafms/API.java: Added new api calls.
|
||||||
|
|
|
@ -84,6 +84,20 @@
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
android:singleLine="true" />
|
android:singleLine="true" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingRight="5dip"
|
||||||
|
android:text="@string/api_password_label_str"
|
||||||
|
android:textColor="#ffffff" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/api_password"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:singleLine="true" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<string name="url_label_str">URL</string>
|
<string name="url_label_str">URL</string>
|
||||||
<string name="user_label_str">User</string>
|
<string name="user_label_str">User</string>
|
||||||
<string name="password_label_str">Password</string>
|
<string name="password_label_str">Password</string>
|
||||||
|
<string name="api_password_label_str">API Password</string>
|
||||||
<string name="update_button_str">Update</string>
|
<string name="update_button_str">Update</string>
|
||||||
<string name="option_title_str">Options</string>
|
<string name="option_title_str">Options</string>
|
||||||
<string name="load_more_events_button_str">Load more events</string>
|
<string name="load_more_events_button_str">Load more events</string>
|
||||||
|
@ -130,4 +131,5 @@
|
||||||
<string name="profile_delete">Delete profile</string>
|
<string name="profile_delete">Delete profile</string>
|
||||||
<string name="connection_problem">There was a problem. Check your connection.</string>
|
<string name="connection_problem">There was a problem. Check your connection.</string>
|
||||||
<string name="connection_settings_problem">The operation can not be performed until you configure a correct connection.</string>
|
<string name="connection_settings_problem">The operation can not be performed until you configure a correct connection.</string>
|
||||||
|
<string name="unknown_version">Unknown version</string>
|
||||||
</resources>
|
</resources>
|
|
@ -38,11 +38,14 @@ public class API {
|
||||||
|
|
||||||
String return_api = Core.httpGet(context, parameters);
|
String return_api = Core.httpGet(context, parameters);
|
||||||
String[] lines = return_api.split("\n");
|
String[] lines = return_api.split("\n");
|
||||||
|
try {
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
String[] groups = lines[i].split(";", 21);
|
String[] groups = lines[i].split(";", 21);
|
||||||
result.put(Integer.valueOf(groups[0]), groups[1]);
|
result.put(Integer.valueOf(groups[0]), groups[1]);
|
||||||
}
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.e(TAG, "Problem parsing number in response");
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +92,12 @@ public class API {
|
||||||
return_api = Core.httpGet(context, parameters);
|
return_api = Core.httpGet(context, parameters);
|
||||||
// TODO wait version
|
// TODO wait version
|
||||||
if (return_api.contains("OK")) {
|
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 {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -132,10 +140,14 @@ public class API {
|
||||||
String return_api = Core.httpGet(context, parameters);
|
String return_api = Core.httpGet(context, parameters);
|
||||||
String[] lines = return_api.split("\n");
|
String[] lines = return_api.split("\n");
|
||||||
array.add("");
|
array.add("");
|
||||||
|
try {
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
String[] tags = lines[i].split(";", 2);
|
String[] tags = lines[i].split(";", 2);
|
||||||
array.add(tags[1]);
|
array.add(tags[1]);
|
||||||
}
|
}
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
Log.e(TAG, "There was a problem getting tags: " + e.getMessage());
|
||||||
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -318,12 +318,16 @@ public class Core {
|
||||||
String url = preferences.getString("url", "") + "/include/api.php";
|
String url = preferences.getString("url", "") + "/include/api.php";
|
||||||
String user = preferences.getString("user", "");
|
String user = preferences.getString("user", "");
|
||||||
String password = preferences.getString("password", "");
|
String password = preferences.getString("password", "");
|
||||||
|
String apiPassword = preferences.getString("api_password", "");
|
||||||
if (url.length() == 0 || user.length() == 0) {
|
if (url.length() == 0 || user.length() == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||||
parameters.add(new BasicNameValuePair("user", user));
|
parameters.add(new BasicNameValuePair("user", user));
|
||||||
parameters.add(new BasicNameValuePair("pass", password));
|
parameters.add(new BasicNameValuePair("pass", password));
|
||||||
|
if (apiPassword.length() > 0) {
|
||||||
|
parameters.add(new BasicNameValuePair("apipass", apiPassword));
|
||||||
|
}
|
||||||
parameters.addAll(additionalParameters);
|
parameters.addAll(additionalParameters);
|
||||||
if (url.toLowerCase().contains("https")) {
|
if (url.toLowerCase().contains("https")) {
|
||||||
// Secure connection
|
// Secure connection
|
||||||
|
|
|
@ -53,10 +53,6 @@ import android.widget.Toast;
|
||||||
public class Options extends Activity {
|
public class Options extends Activity {
|
||||||
private static String TAG = "Options";
|
private static String TAG = "Options";
|
||||||
private static int RINGTONE_PICK_CODE = 999;
|
private static int RINGTONE_PICK_CODE = 999;
|
||||||
private String url;
|
|
||||||
private String user;
|
|
||||||
private String password;
|
|
||||||
private int refreshTimeKey;
|
|
||||||
private TextView connectionStatus;
|
private TextView connectionStatus;
|
||||||
private ProgressDialog retrievingCertificate;
|
private ProgressDialog retrievingCertificate;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
@ -77,18 +73,15 @@ public class Options extends Activity {
|
||||||
this.getString(R.string.const_string_preferences),
|
this.getString(R.string.const_string_preferences),
|
||||||
Activity.MODE_PRIVATE);
|
Activity.MODE_PRIVATE);
|
||||||
// Connection
|
// 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);
|
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 = (EditText) findViewById(R.id.user);
|
||||||
text.setText(user);
|
text.setText(preferences.getString("user", "demo"));
|
||||||
text = (EditText) findViewById(R.id.password);
|
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);
|
Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
|
||||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
||||||
|
@ -96,7 +89,7 @@ public class Options extends Activity {
|
||||||
android.R.layout.simple_spinner_item);
|
android.R.layout.simple_spinner_item);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
combo.setAdapter(adapter);
|
combo.setAdapter(adapter);
|
||||||
combo.setSelection(refreshTimeKey);
|
combo.setSelection(preferences.getInt("refreshTimeKey", 3));
|
||||||
|
|
||||||
final Button button = (Button) findViewById(R.id.update_options);
|
final Button button = (Button) findViewById(R.id.update_options);
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -205,6 +198,8 @@ public class Options extends Activity {
|
||||||
editorPreferences.putString("user", text.getText().toString());
|
editorPreferences.putString("user", text.getText().toString());
|
||||||
text = (EditText) findViewById(R.id.password);
|
text = (EditText) findViewById(R.id.password);
|
||||||
editorPreferences.putString("password", text.getText().toString());
|
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);
|
Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
|
||||||
editorPreferences.putInt("refreshTimeKey",
|
editorPreferences.putInt("refreshTimeKey",
|
||||||
|
@ -293,6 +288,14 @@ public class Options extends Activity {
|
||||||
protected Boolean doInBackground(Void... arg0) {
|
protected Boolean doInBackground(Void... arg0) {
|
||||||
try {
|
try {
|
||||||
version = API.getVersion(getApplicationContext());
|
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) {
|
if (version.length() > 0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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
|
private class CheckCertificateAsyncTask extends
|
||||||
AsyncTask<URL, Void, Boolean> {
|
AsyncTask<URL, Void, Boolean> {
|
||||||
private URL url;
|
private URL url;
|
||||||
|
|
|
@ -347,14 +347,9 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
String[] items = lines[i].split(";", 23);
|
String[] items = lines[i].split(";");
|
||||||
|
|
||||||
EventListItem event = new EventListItem();
|
EventListItem event = new EventListItem();
|
||||||
|
|
||||||
if (items.length != 23) {
|
|
||||||
event.event = getApplication().getString(
|
|
||||||
R.string.unknown_event_str);
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
if (items[0].length() == 0) {
|
if (items[0].length() == 0) {
|
||||||
event.id_event = 0;
|
event.id_event = 0;
|
||||||
|
@ -402,19 +397,20 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
||||||
}
|
}
|
||||||
event.user_comment = items[12];
|
event.user_comment = items[12];
|
||||||
event.tags = items[13];
|
event.tags = items[13];
|
||||||
event.agent_name = items[16];
|
event.agent_name = items[14];
|
||||||
event.group_name = items[17];
|
event.group_name = items[15];
|
||||||
event.group_icon = items[18];
|
event.group_icon = items[16];
|
||||||
event.description_event = items[19];
|
event.description_event = items[17];
|
||||||
event.description_image = items[20];
|
event.description_image = items[18];
|
||||||
event.criticity_name = items[21];
|
event.criticity_name = items[19];
|
||||||
event.criticity_image = items[22];
|
event.criticity_image = items[20];
|
||||||
|
|
||||||
event.opened = false;
|
event.opened = false;
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
|
event.event = getApplication().getString(
|
||||||
|
R.string.unknown_event_str);
|
||||||
launchProblemParsingNotification();
|
launchProblemParsingNotification();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.eventList.add(event);
|
this.eventList.add(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue