2012-06-01 Santiago Munin <burnin1@gmail.com>

* src/pandroid_event_viewer/pandorafms/Core.java: Added image setting methods.
	* src/pandroid_event_viewer/pandorafms/EventList.java: Removed image setting methods.
	* res/layout/item_list_event_layout.xml: Removed not needed ImageViews.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6401 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
santimunin 2012-06-01 12:30:33 +00:00
parent ff7d71c5b3
commit 75ebce15a2
4 changed files with 240 additions and 265 deletions

View File

@ -1,3 +1,8 @@
2012-06-01 Santiago Munín <burnin1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java: Added image setting methods.
* src/pandroid_event_viewer/pandorafms/EventList.java: Removed image setting methods.
* res/layout/item_list_event_layout.xml: Removed not needed ImageViews.
2012-06-01 Santiago Munín <burnin1@gmail.com>
* src/pandroid_event_viewer/pandorafms/EventList.java: Now Agent's link points to mobile console.

View File

@ -14,104 +14,80 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/item_linear_layout"
>
<RelativeLayout
android:id="@+id/content_event_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:layout_weight="0"
android:id="@+id/img_severity_colapse_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5px"
/>
<TextView
android:id="@+id/event_name"
android:layout_toRightOf="@id/img_severity_colapse_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textColorHighlight="#000"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/event_name"
>
<ImageView
android:layout_weight="0"
android:id="@+id/img_group_colapse_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5px"
/>
<TextView
android:id="@+id/agent_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000"
android:textColorHighlight="#000"
android:layout_weight="1"
/>
<ImageView
android:layout_weight="0"
android:id="@+id/img_validate_colapse_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5px"
/>
<TextView
android:id="@+id/timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textColorHighlight="#000"
android:layout_weight="0"
android:textSize="10sp"
/>
</LinearLayout>
</RelativeLayout>
<Button
android:id="@+id/button_load_more_events"
android:text="@string/load_more_events_button_str"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<LinearLayout
android:id="@+id/loading_more_events"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
style="?android:attr/progressBarStyleSmall"
android:paddingRight="10dip"
/>
<TextView
android:textColor="#ffffff"
android:text="@string/loading_label_str"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_linear_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="5dp"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/content_event_item"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="@+id/event_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:textColor="#000"
android:textColorHighlight="#000" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/event_name"
android:orientation="horizontal" >
<TextView
android:id="@+id/agent_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="5dp"
android:textColor="#000"
android:textColorHighlight="#000"
android:textStyle="bold" />
<TextView
android:id="@+id/timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:drawablePadding="5dp"
android:textColor="#000"
android:textColorHighlight="#000"
android:textSize="10sp" />
</LinearLayout>
</RelativeLayout>
<Button
android:id="@+id/button_load_more_events"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/load_more_events_button_str"
android:visibility="gone" />
<LinearLayout
android:id="@+id/loading_more_events"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" >
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/loading_label_str"
android:textColor="#ffffff"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

View File

@ -20,9 +20,13 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@ -38,7 +42,12 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.TextView;
/**
* This class provides basic functions to manage services and some received
@ -49,6 +58,7 @@ import android.util.Log;
*/
public class Core {
private static String TAG = "Core";
private static Map<String, Bitmap> imgCache = new HashMap<String, Bitmap>();
/**
* Reads from the input stream and returns a string.
@ -273,8 +283,11 @@ public class Core {
/**
* Performs an http get petition.
* @param context Application context.
* @param additionalParameters Petition additional parameters
*
* @param context
* Application context.
* @param additionalParameters
* Petition additional parameters
* @return Petition result.
*/
public static String httpGet(Context context,
@ -309,8 +322,80 @@ public class Core {
.convertStreamToString(entityResponse.getContent());
return return_api;
} catch (Exception e) {
Log.e(TAG+" http petition", e.getMessage());
Log.e(TAG + " http petition", e.getMessage());
}
return "";
}
/**
* Downloads an image
*
* @param fileUrl
* Image's url.
* @return A bitmap of that image.
*/
public static Bitmap downloadImage(String fileUrl) {
if (imgCache.containsKey(fileUrl)) {
Log.i(TAG, "Fetched from cache: " + fileUrl);
return imgCache.get(fileUrl);
}
Log.i(TAG, "Downloading image: " + fileUrl);
URL myFileUrl = null;
try {
myFileUrl = new URL(fileUrl);
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);
imgCache.put(fileUrl, img);
return img;
} catch (IOException e) {
Log.e(TAG, "Downloading image: error");
}
return null;
}
/**
* Puts the image to the left of theTextView.
*
* @param view
* TextView.
* @param image
* Bitmap.
*/
public static void setTextViewLeftImage(TextView view, Bitmap image) {
Drawable d = new BitmapDrawable(image);
setTextViewLeftImage(view, d, 16);
}
/**
* Puts the image to the left of theTextView.
*
* @param view
* TextView.
* @param url
* Image's url.
*/
public static void setTextViewLeftImage(TextView view, String url) {
Drawable d = new BitmapDrawable(Core.downloadImage(url));
setTextViewLeftImage(view, d, 16);
}
/**
* Puts the image to the left of theTextView.
*
* @param view
* TextView.
* @param image
* Image.
* @param size Image size
*/
public static void setTextViewLeftImage(TextView view, Drawable image,
int size) {
image.setBounds(0, 0, size, size);
view.setCompoundDrawables(image, null, null, null);
}
}

View File

@ -16,12 +16,7 @@ GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.ListActivity;
@ -32,14 +27,10 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -49,7 +40,6 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
@ -62,24 +52,16 @@ import android.widget.TextView;
*
*/
public class EventList extends ListActivity {
private static String TAG = "EventList";
private ListView lv;
private MyAdapter la;
private PandroidEventviewerActivity object;
// private HashMap<Integer, Boolean> openedItem;
private HashMap<String, Bitmap> imgGroups;
private HashMap<String, Bitmap> imgType;
private BroadcastReceiver onBroadcast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.imgGroups = new HashMap<String, Bitmap>();
this.imgType = new HashMap<String, Bitmap>();
Intent i = getIntent();
this.object = (PandroidEventviewerActivity) i
.getSerializableExtra("object");
@ -218,148 +200,69 @@ public class EventList extends ListActivity {
}
}
/**
* Downloads an image
*
* @param fileUrl
* @return A bitmap of that image
*/
private Bitmap downloadImage(String fileUrl) {
Log.i(TAG, "Downloading image: " + fileUrl);
URL myFileUrl = null;
try {
myFileUrl = new URL(fileUrl);
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
return BitmapFactory.decodeStream(is);
} catch (IOException e) {
Log.e(TAG, "Downloading image: error");
}
return null;
}
/**
* Sets the group image on event list.
* @param view Parent view.
* @param group_icon Group icon.
* @param id Group's ImageView id.
*/
private void setImageGroup(View view, String group_icon, int id) {
ImageView imgview = (ImageView) view.findViewById(id);
Bitmap img;
if (this.imgGroups.containsKey(group_icon)) {
img = this.imgGroups.get(group_icon);
} else {
SharedPreferences preferences = getApplicationContext()
.getSharedPreferences(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "");
img = this.downloadImage(url + "/images/groups_small/" + group_icon
+ ".png");
if (img != null) {
this.imgGroups.put(group_icon, img);
}
}
if (img != null) {
imgview.setImageBitmap(img);
}
}
/**
* Sets type's image on event list.
*
* @param view
* @param url
* Parent view.
* @param group_icon
* Group icon.
* @param id
* Group's ImageView id.
*/
private void setImageType(View view, String url, int id) {
ImageView imgview = (ImageView) view.findViewById(id);
Bitmap img = null;
if (this.imgType.containsKey(url)) {
img = this.imgType.get(url);
} else {
img = this.downloadImage(url);
if (img != null) {
this.imgType.put(url, img);
}
}
if (img != null) {
imgview.setImageBitmap(img);
}
}
/**
* Sets an image to the left of a TextView.
* @param view Parent view.
* @param url Image uri.
* @param id TextView's id;
/*
* private void setImageGroup(View view, String group_icon, int id) {
* ImageView imgview = (ImageView) view.findViewById(id); Bitmap img;
*
* SharedPreferences preferences = getApplicationContext()
* .getSharedPreferences( getApplicationContext().getString(
* R.string.const_string_preferences), Activity.MODE_PRIVATE);
*
* String url = preferences.getString("url", "");
*
* img = Core.downloadImage(url + "/images/groups_small/" + group_icon +
* ".png");
*
* if (img != null) { imgview.setImageBitmap(img); } }
*/
private void setTextViewImage(View view, String url, int id) {
TextView tview = (TextView) view.findViewById(id);
Bitmap img = null;
if (this.imgType.containsKey(url)) {
img = this.imgType.get(url);
} else {
img = this.downloadImage(url);
private String getImageGroupUrl(String group_icon) {
SharedPreferences preferences = getApplicationContext()
.getSharedPreferences(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
if (img != null) {
this.imgType.put(url, img);
}
}
if (img != null) {
Drawable d = new BitmapDrawable(img);
d.setBounds(0, 0, 16, 16);
tview.setCompoundDrawables(d, null, null, null);
}
String url = preferences.getString("url", "");
return url + "/images/groups_small/" + group_icon + ".png";
}
/**
* Sets an image to the left of group's TextView.
* @param view Parent view.
* @param group_icon Icon name.
* @param id Group's TextView id;
*
* @param view
* Parent view.
* @param group_icon
* Icon name.
* @param id
* Group's TextView id;
*/
private void setTextViewGroupImage(View view, String group_icon, int id) {
TextView tview = (TextView) view.findViewById(id);
Bitmap img = null;
if (this.imgGroups.containsKey(group_icon)) {
img = this.imgGroups.get(group_icon);
} else {
SharedPreferences preferences = getApplicationContext()
.getSharedPreferences(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences preferences = getApplicationContext()
.getSharedPreferences(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "");
String url = preferences.getString("url", "");
img = Core.downloadImage(url + "/images/groups_small/" + group_icon
+ ".png");
img = this.downloadImage(url + "/images/groups_small/" + group_icon
+ ".png");
if (img != null) {
this.imgGroups.put(group_icon, img);
}
}
if (img != null) {
Drawable d = new BitmapDrawable(img);
d.setBounds(0, 0, 16, 16);
tview.setCompoundDrawables(d, null, null, null);
Core.setTextViewLeftImage(tview, img);
}
}
@ -510,18 +413,21 @@ public class EventList extends ListActivity {
timestamp.setText(item.timestamp);
if (item.criticity_image.length() != 0)
setImageType(view, item.criticity_image,
R.id.img_severity_colapse_item);
if (item.group_icon.length() != 0)
setImageGroup(view, item.group_icon,
R.id.img_group_colapse_item);
Core.setTextViewLeftImage(
(TextView) view.findViewById(R.id.event_name),
Core.downloadImage(item.criticity_image));
if (item.group_icon.length() != 0)
Core.setTextViewLeftImage(
(TextView) view.findViewById(R.id.agent_name),
getImageGroupUrl(item.group_icon));
ImageView imgValidate = (ImageView) view
.findViewById(R.id.img_validate_colapse_item);
if (item.status == 1) {
imgValidate.setImageResource(R.drawable.tick);
Core.setTextViewLeftImage(timestamp, getResources()
.getDrawable(R.drawable.tick), 24);
} else {
imgValidate.setImageResource(R.drawable.tick_off);
Core.setTextViewLeftImage(timestamp, getResources()
.getDrawable(R.drawable.tick_off), 24);
}
// Show extended info
@ -581,20 +487,21 @@ public class EventList extends ListActivity {
text = (TextView) viewEventExtended
.findViewById(R.id.agent_text);
text.setText(Html
.fromHtml("<a href='"
+ this.object.url
+ "/mobile/index.php?page=agent&id="
+ item.id_agent
+" &autologin=1&user="+this.object.user+"&password="+ this.object.password
+"'>"
+ item.agent_name + "</a>"));
text.setText(Html.fromHtml("<a href='"
+ this.object.url
+ "/mobile/index.php?page=agent&id="
+ item.id_agent + " &autologin=1&user="
+ this.object.user + "&password="
+ this.object.password + "'>" + item.agent_name
+ "</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance());
}
if (item.description_image.length() != 0)
setTextViewImage(viewEventExtended,
item.description_image, R.id.type_text);
Core.setTextViewLeftImage((TextView) viewEventExtended
.findViewById(R.id.type_text),
item.description_image);
text = (TextView) viewEventExtended
.findViewById(R.id.type_text);
text.setText(eventType2Text(item.event_type));
@ -605,8 +512,10 @@ public class EventList extends ListActivity {
text.setText(item.criticity_name);
if (item.criticity_image.length() != 0)
setTextViewImage(viewEventExtended,
item.criticity_image, R.id.severity_text);
Core.setTextViewLeftImage(
(TextView) viewEventExtended
.findViewById(R.id.severity_text),
item.criticity_image);
}
// Set the open and close the extended info event row