2012-06-11 Santiago Munin <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java, src/pandroid_event_viewer/pandorafms/API.java: Moved api functions to API.java * src/pandroid_event_viewer/pandorafms/Options.java: Connection status works ok now. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6495 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
c255c14b97
commit
538d9c9874
|
@ -1,10 +1,16 @@
|
|||
2012-06-11 Santiago Munín <burning1@gmail.com>
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/Core.java,
|
||||
src/pandroid_event_viewer/pandorafms/API.java: Moved api functions to API.java
|
||||
* src/pandroid_event_viewer/pandorafms/Options.java: Connection status works ok now.
|
||||
|
||||
2012-06-11 Santiago Munín <burning1@gmail.com>
|
||||
|
||||
* res/values/arrays.xml: Removed some entries.
|
||||
* res/values/strings.xml: Added one entry.
|
||||
* res/layout/create_incident.xml: Removed form fields.
|
||||
* res/layout/item_list_event_extended.xml: Added a button to create an incident from the event.
|
||||
* src/pandroid_event_viewer/pandorafms/EventList.java: Added crate incident button logic.
|
||||
* src/pandroid_event_viewer/pandorafms/EventList.java: Added create incident button logic.
|
||||
* src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java: Removed fields logic.
|
||||
* src/pandroid_event_viewer/pandorafms/Main.java,
|
||||
src/pandroid_event_viewer/pandorafms/EventList.java,
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package pandroid_event_viewer.pandorafms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
public class API {
|
||||
|
||||
private static String TAG = "API";
|
||||
|
||||
/**
|
||||
* Get groups through an api call.
|
||||
*
|
||||
* @param context
|
||||
* Application context.
|
||||
* @return Map containing id -> group.
|
||||
*/
|
||||
public static Map<Integer, String> getGroups(Context context) {
|
||||
Map<Integer, String> result = new HashMap<Integer, String>();
|
||||
try {
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "groups"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", ";"));
|
||||
|
||||
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]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG + ": getting groups", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agents through an api call.
|
||||
*
|
||||
* @param context
|
||||
* @return Map containing id -> agent.
|
||||
*/
|
||||
public static Map<Integer, String> getAgents(Context context) {
|
||||
Map<Integer, String> result = new HashMap<Integer, String>();
|
||||
try {
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "all_agents"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
|
||||
String return_api = Core.httpGet(context, parameters);
|
||||
String[] lines = return_api.split("\n");
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String[] agents = lines[i].split(";");
|
||||
result.put(Integer.valueOf(agents[0]), agents[1]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG + ": getting groups", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API version.
|
||||
*
|
||||
* @param context
|
||||
* Application context.
|
||||
* @return API version or empty string if fails.
|
||||
*/
|
||||
public static String getVersion(Context context) {
|
||||
try {
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "test"));
|
||||
String return_api = Core.httpGet(context, parameters);
|
||||
// TODO wait version
|
||||
if (return_api.equals("OK\n")) {
|
||||
return "4.0.2";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -398,64 +398,4 @@ public class Core {
|
|||
image.setBounds(0, 0, size, size);
|
||||
view.setCompoundDrawables(image, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups through an api call.
|
||||
*
|
||||
* @param context
|
||||
* Application context.
|
||||
* @return Map containing id -> group.
|
||||
*/
|
||||
public static Map<Integer, String> getGroups(Context context) {
|
||||
Map<Integer, String> result = new HashMap<Integer, String>();
|
||||
try {
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "groups"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", ";"));
|
||||
|
||||
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]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG + ": getting groups", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agents through an api call.
|
||||
*
|
||||
* @param context
|
||||
* @return Map containing id -> agent.
|
||||
*/
|
||||
public static Map<Integer, String> getAgents(Context context) {
|
||||
Map<Integer, String> result = new HashMap<Integer, String>();
|
||||
try {
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "all_agents"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
|
||||
String return_api = Core.httpGet(context, parameters);
|
||||
String[] lines = return_api.split("\n");
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String[] agents = lines[i].split(";");
|
||||
|
||||
result.put(Integer.valueOf(agents[0]), agents[1]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG + ": getting groups", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public class CreateIncidentActivity extends Activity {
|
|||
incidentParams[3] = String.valueOf(DEFAULT_PRIORITY_CODE);
|
||||
incidentParams[4] = String.valueOf(DEFAULT_STATUS_CODE);
|
||||
int groupCode = -1;
|
||||
for (Entry<Integer, String> entry : Core.getGroups(
|
||||
for (Entry<Integer, String> entry : API.getGroups(
|
||||
getApplicationContext()).entrySet()) {
|
||||
if (entry.getValue().equals(eventGroup)) {
|
||||
groupCode = entry.getKey();
|
||||
|
|
|
@ -520,7 +520,6 @@ public class EventList extends ListActivity {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO
|
||||
Intent intent = new Intent(
|
||||
getBaseContext(),
|
||||
CreateIncidentActivity.class);
|
||||
|
|
|
@ -257,22 +257,28 @@ public class Options extends Activity {
|
|||
* @author Santiago Munín González
|
||||
*
|
||||
*/
|
||||
private class CheckConnectionAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private class CheckConnectionAsyncTask extends
|
||||
AsyncTask<Void, Void, String> {
|
||||
|
||||
private boolean connectionOk = false;
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... arg0) {
|
||||
// TODO implement check
|
||||
this.connectionOk = false;
|
||||
return null;
|
||||
protected String doInBackground(Void... arg0) {
|
||||
String version = API.getVersion(getApplicationContext());
|
||||
if (version.length() > 0) {
|
||||
this.connectionOk = true;
|
||||
} else {
|
||||
this.connectionOk = false;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose an image (ok or wrong)
|
||||
*/
|
||||
protected void onPostExecute(Void v) {
|
||||
protected void onPostExecute(String v) {
|
||||
if (this.connectionOk) {
|
||||
connectionStatus.setText(v);
|
||||
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||
0, R.drawable.ok);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue