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>
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/API.java: Added new api calls.
|
||||
|
|
|
@ -83,6 +83,20 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
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
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<string name="url_label_str">URL</string>
|
||||
<string name="user_label_str">User</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="option_title_str">Options</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="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="unknown_version">Unknown version</string>
|
||||
</resources>
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
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
|
||||
|
|
|
@ -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<CharSequence> 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<URL, Void, Boolean> {
|
||||
private URL url;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue