mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
2012-08-24 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java: Fixed a bug (possible null argument as image). * src/pandroid_event_viewer/pandorafms/EventList.java: Create incident is displayed as a dialog * src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: FIXME comment removed. * src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java: No longer needed. Removed. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6912 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
40b026df46
commit
d4b8b4d9d3
@ -1,4 +1,10 @@
|
|||||||
2012-08-10 Santiago Munín <burning1@gmail.com>
|
2012-08-24 Santiago Munín <burning1@gmail.com>
|
||||||
|
* src/pandroid_event_viewer/pandorafms/Core.java: Fixed a bug (possible null argument as image).
|
||||||
|
* src/pandroid_event_viewer/pandorafms/EventList.java: Create incident is displayed as a dialog
|
||||||
|
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: FIXME comment removed.
|
||||||
|
* src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java: No longer needed. Removed.
|
||||||
|
|
||||||
|
2012-08-24 Santiago Munín <burning1@gmail.com>
|
||||||
* src/pandroid_event_viewer/pandorafms/Options.java: Fixed a little bug with the connection status textview.
|
* src/pandroid_event_viewer/pandorafms/Options.java: Fixed a little bug with the connection status textview.
|
||||||
* res/layout/options.xml: Connection status textview now has a fixed width.
|
* res/layout/options.xml: Connection status textview now has a fixed width.
|
||||||
* res/values/strings.xml: Added an entry.
|
* res/values/strings.xml: Added an entry.
|
||||||
|
@ -463,8 +463,10 @@ public class Core {
|
|||||||
*/
|
*/
|
||||||
public static void setTextViewLeftImage(TextView view, Drawable image,
|
public static void setTextViewLeftImage(TextView view, Drawable image,
|
||||||
int size) {
|
int size) {
|
||||||
image.setBounds(0, 0, size, size);
|
if (image != null) {
|
||||||
view.setCompoundDrawables(image, null, null, null);
|
image.setBounds(0, 0, size, size);
|
||||||
|
view.setCompoundDrawables(image, null, null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,144 +0,0 @@
|
|||||||
package pandroid_event_viewer.pandorafms;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows user to create an incident.
|
|
||||||
*
|
|
||||||
* @author Santiago Munín González
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class CreateIncidentActivity extends Activity {
|
|
||||||
private static String TAG = "CreateIncidentActivity";
|
|
||||||
private static int DEFAULT_STATUS_CODE = 0;
|
|
||||||
private static int DEFAULT_PRIORITY_CODE = 0;
|
|
||||||
private static String DEFAULT_SOURCE = "Pandora FMS Event";
|
|
||||||
private EditText title, description;
|
|
||||||
private ProgressDialog dialog;
|
|
||||||
private String eventTitle, eventDescription, eventGroup;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
Bundle extras = getIntent().getExtras();
|
|
||||||
if (extras != null) {
|
|
||||||
eventTitle = extras.getString("title");
|
|
||||||
eventDescription = extras.getString("description");
|
|
||||||
eventGroup = extras.getString("group");
|
|
||||||
}
|
|
||||||
setContentView(R.layout.create_incident);
|
|
||||||
initializeViews();
|
|
||||||
resetViews();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes views.
|
|
||||||
*/
|
|
||||||
private void initializeViews() {
|
|
||||||
title = (EditText) findViewById(R.id.incident_title);
|
|
||||||
description = (EditText) findViewById(R.id.incident_description);
|
|
||||||
|
|
||||||
((Button) findViewById(R.id.incident_create_button))
|
|
||||||
.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (title != null && title.length() > 0) {
|
|
||||||
dialog = ProgressDialog
|
|
||||||
.show(CreateIncidentActivity.this,
|
|
||||||
"",
|
|
||||||
getString(R.string.creating_incident),
|
|
||||||
true);
|
|
||||||
new SetNewIncidentAsyncTask().execute((Void) null);
|
|
||||||
} else {
|
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
R.string.title_empty, Toast.LENGTH_SHORT)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets views.
|
|
||||||
*/
|
|
||||||
private void resetViews() {
|
|
||||||
|
|
||||||
title.setText(eventTitle);
|
|
||||||
description.setText(eventDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the create incident petition.
|
|
||||||
*
|
|
||||||
* @return <b>true</b> if it is created.
|
|
||||||
* @throws IOException
|
|
||||||
* If there is a problem with the connection.
|
|
||||||
*/
|
|
||||||
private void sendNewIncident() throws IOException {
|
|
||||||
Log.i(TAG, "Sending new incident");
|
|
||||||
String incidentParams[] = new String[6];
|
|
||||||
incidentParams[0] = title.getText().toString();
|
|
||||||
incidentParams[1] = description.getText().toString();
|
|
||||||
incidentParams[2] = String.valueOf(DEFAULT_SOURCE);
|
|
||||||
incidentParams[3] = String.valueOf(DEFAULT_PRIORITY_CODE);
|
|
||||||
incidentParams[4] = String.valueOf(DEFAULT_STATUS_CODE);
|
|
||||||
int groupCode = -1;
|
|
||||||
for (Entry<Integer, String> entry : API.getGroups(
|
|
||||||
getApplicationContext()).entrySet()) {
|
|
||||||
if (entry.getValue().equals(eventGroup)) {
|
|
||||||
groupCode = entry.getKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (groupCode >= 0) {
|
|
||||||
incidentParams[5] = String.valueOf(groupCode);
|
|
||||||
}
|
|
||||||
API.createNewIncident(getApplicationContext(), incidentParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the api call to add the new incident
|
|
||||||
*
|
|
||||||
* @author Santiago Munín González
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private class SetNewIncidentAsyncTask extends
|
|
||||||
AsyncTask<Void, Void, Boolean> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Boolean doInBackground(Void... params) {
|
|
||||||
try {
|
|
||||||
sendNewIncident();
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Boolean result) {
|
|
||||||
if (result) {
|
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
R.string.incident_created, Toast.LENGTH_SHORT).show();
|
|
||||||
dialog.dismiss();
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
R.string.create_incident_group_error,
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,18 +16,24 @@ GNU General Public License for more details.
|
|||||||
*/
|
*/
|
||||||
package pandroid_event_viewer.pandorafms;
|
package pandroid_event_viewer.pandorafms;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@ -37,10 +43,12 @@ import android.view.View.OnClickListener;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity where events are displayed.
|
* Activity where events are displayed.
|
||||||
@ -49,11 +57,18 @@ import android.widget.TextView;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EventList extends ListActivity {
|
public class EventList extends ListActivity {
|
||||||
|
private static String TAG = "EventList";
|
||||||
|
|
||||||
|
private static int DEFAULT_STATUS_CODE = 0;
|
||||||
|
private static int DEFAULT_PRIORITY_CODE = 0;
|
||||||
|
private static String DEFAULT_SOURCE = "Pandora FMS Event";
|
||||||
|
private static final int CREATE_INCIDENT_DIALOG = 1;
|
||||||
private ListView lv;
|
private ListView lv;
|
||||||
private MyAdapter la;
|
private MyAdapter la;
|
||||||
private PandroidEventviewerActivity object;
|
private PandroidEventviewerActivity object;
|
||||||
|
|
||||||
private BroadcastReceiver onBroadcast;
|
private BroadcastReceiver onBroadcast;
|
||||||
|
private Dialog creatingIncidentDialog;
|
||||||
|
private Context context = this;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -179,6 +194,60 @@ public class EventList extends ListActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dialog onCreateDialog(int id, Bundle args) {
|
||||||
|
switch (id) {
|
||||||
|
case CREATE_INCIDENT_DIALOG:
|
||||||
|
final String group;
|
||||||
|
Dialog dialog = new Dialog(this);
|
||||||
|
dialog.setContentView(R.layout.create_incident);
|
||||||
|
dialog.setTitle(getString(R.string.create_incident));
|
||||||
|
final EditText titleEditText = (EditText) dialog
|
||||||
|
.findViewById(R.id.incident_title);
|
||||||
|
final EditText descriptionEditText = (EditText) dialog
|
||||||
|
.findViewById(R.id.incident_description);
|
||||||
|
String temp = args.getString("title");
|
||||||
|
|
||||||
|
if (temp != null) {
|
||||||
|
titleEditText.setText(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = args.getString("description");
|
||||||
|
if (temp != null) {
|
||||||
|
descriptionEditText.setText(temp);
|
||||||
|
}
|
||||||
|
temp = args.getString("group");
|
||||||
|
if (temp != null) {
|
||||||
|
group = temp;
|
||||||
|
} else {
|
||||||
|
group = "";
|
||||||
|
}
|
||||||
|
dialog.findViewById(R.id.incident_create_button)
|
||||||
|
.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (titleEditText != null
|
||||||
|
&& titleEditText.length() > 0) {
|
||||||
|
creatingIncidentDialog = ProgressDialog.show(
|
||||||
|
context, "",
|
||||||
|
getString(R.string.creating_incident),
|
||||||
|
true);
|
||||||
|
String title = titleEditText.getText().toString();
|
||||||
|
String description = descriptionEditText.getText().toString();
|
||||||
|
new SetNewIncidentAsyncTask().execute(title,
|
||||||
|
description, group);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(getApplicationContext(),
|
||||||
|
R.string.title_empty,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows loading information.
|
* Shows loading information.
|
||||||
*/
|
*/
|
||||||
@ -202,10 +271,10 @@ public class EventList extends ListActivity {
|
|||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EventListItem item = this.object.eventList.get(position);
|
EventListItem item = this.object.eventList.get(position);
|
||||||
item.opened = !item.opened;
|
item.opened = !item.opened;
|
||||||
this.object.eventList.set(position, item);
|
this.object.eventList.set(position, item);
|
||||||
la.notifyDataSetChanged();
|
la.notifyDataSetChanged();
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -343,7 +412,8 @@ public class EventList extends ListActivity {
|
|||||||
timestamp.setText(item.timestamp);
|
timestamp.setText(item.timestamp);
|
||||||
|
|
||||||
if (item.criticity_image.length() != 0)
|
if (item.criticity_image.length() != 0)
|
||||||
Core.setTextViewLeftImage((TextView) view.findViewById(R.id.event_name), Core
|
Core.setTextViewLeftImage((TextView) view
|
||||||
|
.findViewById(R.id.event_name), Core
|
||||||
.getSeverityImage(getApplicationContext(),
|
.getSeverityImage(getApplicationContext(),
|
||||||
item.criticity), 16);
|
item.criticity), 16);
|
||||||
|
|
||||||
@ -416,8 +486,9 @@ public class EventList extends ListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Core.setTextViewLeftImage((TextView) viewEventExtended
|
Core.setTextViewLeftImage((TextView) viewEventExtended
|
||||||
.findViewById(R.id.type_text),
|
.findViewById(R.id.type_text), Core
|
||||||
Core.getEventTypeImage(getApplicationContext(), item.event_type), 16);
|
.getEventTypeImage(getApplicationContext(),
|
||||||
|
item.event_type), 16);
|
||||||
|
|
||||||
text = (TextView) viewEventExtended
|
text = (TextView) viewEventExtended
|
||||||
.findViewById(R.id.type_text);
|
.findViewById(R.id.type_text);
|
||||||
@ -460,15 +531,12 @@ public class EventList extends ListActivity {
|
|||||||
.setOnClickListener(new OnClickListener() {
|
.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(
|
Bundle b = new Bundle();
|
||||||
getBaseContext(),
|
b.putString("group", item.group_name);
|
||||||
CreateIncidentActivity.class);
|
b.putString("title", item.event);
|
||||||
intent.putExtra("group",
|
b.putString("description",
|
||||||
item.group_name);
|
|
||||||
intent.putExtra("title", item.event);
|
|
||||||
intent.putExtra("description",
|
|
||||||
item.description_event);
|
item.description_event);
|
||||||
startActivity(intent);
|
showDialog(CREATE_INCIDENT_DIALOG, b);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -581,4 +649,68 @@ public class EventList extends ListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the create incident petition.
|
||||||
|
*
|
||||||
|
* @return <b>true</b> if it is created.
|
||||||
|
* @throws IOException
|
||||||
|
* If there is a problem with the connection.
|
||||||
|
*/
|
||||||
|
private void sendNewIncident(String title, String description, String group)
|
||||||
|
throws IOException {
|
||||||
|
Log.i(TAG, "Sending new incident");
|
||||||
|
String incidentParams[] = new String[6];
|
||||||
|
incidentParams[0] = title;
|
||||||
|
incidentParams[1] = description;
|
||||||
|
incidentParams[2] = String.valueOf(DEFAULT_SOURCE);
|
||||||
|
incidentParams[3] = String.valueOf(DEFAULT_PRIORITY_CODE);
|
||||||
|
incidentParams[4] = String.valueOf(DEFAULT_STATUS_CODE);
|
||||||
|
int groupCode = -1;
|
||||||
|
for (Entry<Integer, String> entry : API.getGroups(
|
||||||
|
getApplicationContext()).entrySet()) {
|
||||||
|
if (entry.getValue().equals(group)) {
|
||||||
|
groupCode = entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (groupCode >= 0) {
|
||||||
|
incidentParams[5] = String.valueOf(groupCode);
|
||||||
|
}
|
||||||
|
API.createNewIncident(getApplicationContext(), incidentParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the api call to add the new incident
|
||||||
|
*
|
||||||
|
* @author Santiago Munín González
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private class SetNewIncidentAsyncTask extends
|
||||||
|
AsyncTask<String, Void, Boolean> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(String... params) {
|
||||||
|
try {
|
||||||
|
sendNewIncident(params[0], params[1], params[2]);
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
if (result) {
|
||||||
|
Toast.makeText(getApplicationContext(),
|
||||||
|
R.string.incident_created, Toast.LENGTH_SHORT).show();
|
||||||
|
creatingIncidentDialog.dismiss();
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(getApplicationContext(),
|
||||||
|
R.string.create_incident_group_error,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
creatingIncidentDialog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -40,7 +40,6 @@ import android.util.Log;
|
|||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
//FIXME grey buttons doesn't become white when connection is correctly set
|
|
||||||
public class PandroidEventviewerActivity extends TabActivity implements
|
public class PandroidEventviewerActivity extends TabActivity implements
|
||||||
Serializable {
|
Serializable {
|
||||||
private static String TAG = "PandroidEventviewerActivity";
|
private static String TAG = "PandroidEventviewerActivity";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user