2012-06-20 Santiago Munin <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/API.java: New class, it will provide all API calls. * src/pandroid_event_viewer/pandorafms/EventList.java: Loading more events on scroll down. * src/pandroid_event_viewer/pandorafms/Core.java: Added HTTPS connections. * src/pandroid_event_viewer/pandorafms/Options.java: Added self-signed certificates check. * src/pandroid_event_viewer/pandorafms/NaiveTrustManager.java: HTTPS through self-signed websites. * src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: Added ListAdapter to get events asynctask as a parameter. * res/layout/list_view_layout.xml: Little UI changes. * res/layout/item_list_event_layout.xml: Little UI changes. * res/values/strings.xml: Added new entries. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6612 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
e197350df4
commit
d9552510b5
|
@ -1,3 +1,15 @@
|
|||
2012-06-20 Santiago Munín <burning1@gmail.com>
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/API.java: New class, it will provide all API calls.
|
||||
* src/pandroid_event_viewer/pandorafms/EventList.java: Loading more events on scroll down.
|
||||
* src/pandroid_event_viewer/pandorafms/Core.java: Added HTTPS connections.
|
||||
* src/pandroid_event_viewer/pandorafms/Options.java: Added self-signed certificates check.
|
||||
* src/pandroid_event_viewer/pandorafms/NaiveTrustManager.java: HTTPS through self-signed websites.
|
||||
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: Added ListAdapter to get events asynctask as a parameter.
|
||||
* res/layout/list_view_layout.xml: Little UI changes.
|
||||
* res/layout/item_list_event_layout.xml: Little UI changes.
|
||||
* res/values/strings.xml: Added new entries.
|
||||
|
||||
2012-06-11 Santiago Munín <burning1@gmail.com>
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/Core.java,
|
||||
|
|
|
@ -62,12 +62,12 @@
|
|||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<Button
|
||||
<!-- <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" />
|
||||
android:visibility="gone" /> -->
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/loading_more_events"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<LinearLayout
|
||||
<!-- <LinearLayout
|
||||
android:id="@+id/loading_layout"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -39,7 +39,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:textStyle="bold"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout> -->
|
||||
<LinearLayout
|
||||
android:id="@+id/empty_list_layout"
|
||||
android:orientation="horizontal"
|
||||
|
|
|
@ -117,5 +117,7 @@
|
|||
<string name="creating_incident">Creating new incident…</string>
|
||||
<string name="create_incident">Create incident</string>
|
||||
<string name="create_incident_group_error">There was an error creating the incident: unrecognized event group. Please, contact administrator.</string>
|
||||
|
||||
<string name="url_not_valid">Incorrect url. Please, insert a valid url</string>
|
||||
<string name="certificate_not_valid">This server has a certificate not signed by a CA, do you trust it?</string>
|
||||
<string name="options_not_saved">Options not saved.</string>
|
||||
</resources>
|
|
@ -87,7 +87,7 @@ public class API {
|
|||
parameters.add(new BasicNameValuePair("op2", "test"));
|
||||
String return_api = Core.httpGet(context, parameters);
|
||||
// TODO wait version
|
||||
if (return_api.equals("OK\n")) {
|
||||
if (return_api.contains("OK")) {
|
||||
return "4.0.2";
|
||||
} else {
|
||||
return "";
|
||||
|
@ -96,4 +96,21 @@ public class API {
|
|||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get events from pandora console.
|
||||
*
|
||||
* @param newEvents
|
||||
*/
|
||||
public static String getEvents(Context context, String other) {
|
||||
// Get total count.
|
||||
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", other));
|
||||
return Core.httpGet(context, parameters);
|
||||
}
|
||||
}
|
|
@ -20,14 +20,27 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
|
@ -59,6 +72,8 @@ import android.widget.TextView;
|
|||
public class Core {
|
||||
private static String TAG = "Core";
|
||||
private static Map<String, Bitmap> imgCache = new HashMap<String, Bitmap>();
|
||||
// Don't use this variable, just call getSocketFactory
|
||||
private static SSLSocketFactory sslSocketFactory;
|
||||
|
||||
/**
|
||||
* Reads from the input stream and returns a string.
|
||||
|
@ -266,7 +281,8 @@ public class Core {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts params to string.
|
||||
* Converts params to string.
|
||||
*
|
||||
* @param params
|
||||
* @return All params in a single string.
|
||||
*/
|
||||
|
@ -305,6 +321,10 @@ public class Core {
|
|||
parameters.add(new BasicNameValuePair("user", user));
|
||||
parameters.add(new BasicNameValuePair("pass", password));
|
||||
parameters.addAll(additionalParameters);
|
||||
if (url.contains("https")) {
|
||||
// Secure connection
|
||||
return Core.httpsGet(url, parameters);
|
||||
}
|
||||
try {
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
UrlEncodedFormEntity entity;
|
||||
|
@ -343,16 +363,30 @@ public class Core {
|
|||
|
||||
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;
|
||||
if (fileUrl.contains("https")) {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(fileUrl)
|
||||
.openConnection();
|
||||
con.setHostnameVerifier(new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
con.setSSLSocketFactory(getSocketFactory());
|
||||
Bitmap img = BitmapFactory.decodeStream(con.getInputStream());
|
||||
imgCache.put(fileUrl, img);
|
||||
return img;
|
||||
} else {
|
||||
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");
|
||||
Log.e(TAG, "Downloading image "+fileUrl+": error");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -398,4 +432,92 @@ public class Core {
|
|||
image.setBounds(0, 0, size, size);
|
||||
view.setCompoundDrawables(image, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds out if the given url has a CA signed certificate.
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidCertificate(URL url) {
|
||||
|
||||
HttpsURLConnection con;
|
||||
try {
|
||||
con = (HttpsURLConnection) url.openConnection();
|
||||
con.connect();
|
||||
con.disconnect();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String httpsGet(String url,
|
||||
List<NameValuePair> additionalParameters) {
|
||||
String result = "";
|
||||
try {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(url)
|
||||
.openConnection();
|
||||
con.setHostnameVerifier(new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
con.setSSLSocketFactory(getSocketFactory());
|
||||
con.setDoOutput(true);
|
||||
String postData = "";
|
||||
boolean first = true;
|
||||
for (NameValuePair nameValuePair : additionalParameters) {
|
||||
postData = first ? postData : postData + "&";
|
||||
first = false;
|
||||
postData += URLEncoder.encode(nameValuePair.getName()) + "="
|
||||
+ URLEncoder.encode(nameValuePair.getValue());
|
||||
}
|
||||
if (postData.length() > 0) {
|
||||
OutputStreamWriter wr = new OutputStreamWriter(
|
||||
con.getOutputStream());
|
||||
wr.write(postData);
|
||||
wr.flush();
|
||||
}
|
||||
|
||||
InputStream inputStream;
|
||||
inputStream = con.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(inputStream));
|
||||
String temp;
|
||||
while ((temp = bufferedReader.readLine()) != null) {
|
||||
Log.d("CONTENT", temp);
|
||||
result += temp+"\n";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return "";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SSL Factory instance that accepts all server certificates.
|
||||
*
|
||||
* @return An SSL-specific socket factory.
|
||||
**/
|
||||
private static final SSLSocketFactory getSocketFactory() {
|
||||
if (sslSocketFactory == null) {
|
||||
try {
|
||||
TrustManager[] tm = new TrustManager[] { new NaiveTrustManager() };
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
context.init(new KeyManager[0], tm, new SecureRandom());
|
||||
|
||||
sslSocketFactory = (SSLSocketFactory) context
|
||||
.getSocketFactory();
|
||||
|
||||
} catch (KeyManagementException e) {
|
||||
Log.e("No SSL algorithm support: " + e.getMessage(),
|
||||
e.toString());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Log.e("Exception when setting up the Naive key management.",
|
||||
e.toString());
|
||||
}
|
||||
}
|
||||
return sslSocketFactory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.graphics.Color;
|
|||
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;
|
||||
|
@ -38,11 +39,12 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AbsListView.OnScrollListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
|
@ -55,6 +57,7 @@ public class EventList extends ListActivity {
|
|||
private ListView lv;
|
||||
private MyAdapter la;
|
||||
private PandroidEventviewerActivity object;
|
||||
private boolean moreEvents;
|
||||
|
||||
private BroadcastReceiver onBroadcast;
|
||||
|
||||
|
@ -68,13 +71,40 @@ public class EventList extends ListActivity {
|
|||
|
||||
setContentView(R.layout.list_view_layout);
|
||||
|
||||
this.toggleLoadingLayout();
|
||||
|
||||
//this.toggleLoadingLayout();
|
||||
moreEvents = true;
|
||||
lv = (ListView) findViewById(android.R.id.list);
|
||||
|
||||
la = new MyAdapter(getBaseContext(), object);
|
||||
|
||||
this.object.adapter = la;
|
||||
lv.setAdapter(la);
|
||||
lv.setOnScrollListener(new OnScrollListener() {
|
||||
private int priorFirst = -1;
|
||||
|
||||
@Override
|
||||
public void onScroll(final AbsListView view, final int first,
|
||||
final int visible, final int total) {
|
||||
// detect if last item is visible
|
||||
if (visible < total && (first + visible == total)) {
|
||||
// see if we have more results
|
||||
if (first != priorFirst) {
|
||||
priorFirst = first;
|
||||
Log.d("EventList", "Loading smthing");
|
||||
if (((long) object.eventList.size()) < object.count_events) {
|
||||
loadMoreEvents();
|
||||
// moreEvents = true;
|
||||
} /*
|
||||
* else { Log.d("eventList", "moreEvents FALSE");
|
||||
* moreEvents = false; }
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
}
|
||||
});
|
||||
|
||||
onBroadcast = new BroadcastReceiver() {
|
||||
|
||||
|
@ -82,37 +112,26 @@ public class EventList extends ListActivity {
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
int load_more = intent.getIntExtra("load_more", 0);
|
||||
|
||||
Button button = (Button) findViewById(R.id.button_load_more_events);
|
||||
|
||||
if (object.eventList.size() == 0) {
|
||||
button.setVisibility(Button.GONE);
|
||||
} else if (((long) object.eventList.size()) >= object.count_events) {
|
||||
button.setVisibility(Button.GONE);
|
||||
} else {
|
||||
button.setVisibility(Button.VISIBLE);
|
||||
}
|
||||
|
||||
if (load_more == 1) {
|
||||
LinearLayout layout = (LinearLayout) findViewById(R.id.loading_layout);
|
||||
layout.setVisibility(LinearLayout.GONE);
|
||||
/* LinearLayout layout = (LinearLayout) findViewById(R.id.loading_layout);
|
||||
layout.setVisibility(LinearLayout.GONE);*/
|
||||
la.showLoadingEvents = false;
|
||||
} else {
|
||||
LinearLayout layout = (LinearLayout) findViewById(R.id.loading_layout);
|
||||
layout.setVisibility(LinearLayout.GONE);
|
||||
/*LinearLayout layout = (LinearLayout) findViewById(R.id.loading_layout);
|
||||
layout.setVisibility(LinearLayout.GONE);*/
|
||||
|
||||
if (((int) object.count_events) == 0) {
|
||||
layout = (LinearLayout) findViewById(R.id.empty_list_layout);
|
||||
LinearLayout layout = (LinearLayout) findViewById(R.id.empty_list_layout);
|
||||
layout.setVisibility(LinearLayout.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
la.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
registerReceiver(onBroadcast, new IntentFilter("eventlist.java"));
|
||||
|
||||
this.toggleLoadingLayout();
|
||||
//this.toggleLoadingLayout();
|
||||
|
||||
if (this.object.show_popup_info) {
|
||||
this.object.show_popup_info = false;
|
||||
|
@ -126,7 +145,7 @@ public class EventList extends ListActivity {
|
|||
|
||||
if (this.object.showOptionsFirstTime) {
|
||||
this.object.loadInProgress = true;
|
||||
toggleLoadingLayout();
|
||||
// toggleLoadingLayout();
|
||||
|
||||
this.object.showOptionsFirstTime = false;
|
||||
this.object.executeBackgroundGetEvents();
|
||||
|
@ -138,7 +157,7 @@ public class EventList extends ListActivity {
|
|||
|
||||
registerReceiver(onBroadcast, new IntentFilter("eventlist.java"));
|
||||
|
||||
this.toggleLoadingLayout();
|
||||
//this.toggleLoadingLayout();
|
||||
|
||||
if (!this.object.loadInProgress) {
|
||||
if (((int) object.count_events) == 0) {
|
||||
|
@ -170,7 +189,7 @@ public class EventList extends ListActivity {
|
|||
this.object.loadInProgress = true;
|
||||
this.object.getNewListEvents = true;
|
||||
this.object.eventList = new ArrayList<EventListItem>();
|
||||
this.toggleLoadingLayout();
|
||||
// this.toggleLoadingLayout();
|
||||
this.object.executeBackgroundGetEvents();
|
||||
break;
|
||||
case R.id.about_button_menu_options:
|
||||
|
@ -185,7 +204,7 @@ public class EventList extends ListActivity {
|
|||
/**
|
||||
* Shows loading information.
|
||||
*/
|
||||
private void toggleLoadingLayout() {
|
||||
/*private void toggleLoadingLayout() {
|
||||
LinearLayout layout;
|
||||
|
||||
layout = (LinearLayout) findViewById(R.id.empty_list_layout);
|
||||
|
@ -198,7 +217,7 @@ public class EventList extends ListActivity {
|
|||
} else {
|
||||
layout.setVisibility(LinearLayout.GONE);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private String getImageGroupUrl(String group_icon) {
|
||||
SharedPreferences preferences = getApplicationContext()
|
||||
|
@ -244,7 +263,12 @@ public class EventList extends ListActivity {
|
|||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
|
||||
EventListItem item = this.object.eventList.get(position);
|
||||
EventListItem item;
|
||||
try {
|
||||
item = this.object.eventList.get(position);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
item.opened = !item.opened;
|
||||
this.object.eventList.set(position, item);
|
||||
|
@ -258,8 +282,7 @@ public class EventList extends ListActivity {
|
|||
*/
|
||||
private void loadMoreEvents() {
|
||||
la.showLoadingEvents = true;
|
||||
la.notifyDataSetChanged();
|
||||
|
||||
object.offset += object.pagination;
|
||||
object.executeBackgroundGetEvents();
|
||||
}
|
||||
|
||||
|
@ -304,49 +327,83 @@ public class EventList extends ListActivity {
|
|||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = inflater.inflate(R.layout.item_list_event_layout, null);
|
||||
|
||||
LinearLayout layout = (LinearLayout) view
|
||||
.findViewById(R.id.loading_more_events);
|
||||
// layout.setVisibility(LinearLayout.GONE);*/
|
||||
// If the end of the list.
|
||||
if (this.object.eventList.size() == position) {
|
||||
// Show button to get more events
|
||||
if ((!object.loadInProgress) && (object.count_events != 0)) {
|
||||
if (showLoadingEvents) {
|
||||
LinearLayout layout = (LinearLayout) view
|
||||
.findViewById(R.id.loading_more_events);
|
||||
layout.setVisibility(LinearLayout.VISIBLE);
|
||||
|
||||
RelativeLayout layout2 = (RelativeLayout) view
|
||||
.findViewById(R.id.content_event_item);
|
||||
layout2.setVisibility(RelativeLayout.GONE);
|
||||
|
||||
Button button = (Button) view
|
||||
.findViewById(R.id.button_load_more_events);
|
||||
button.setVisibility(Button.GONE);
|
||||
} else {
|
||||
Button button = (Button) view
|
||||
.findViewById(R.id.button_load_more_events);
|
||||
|
||||
if (object.eventList.size() == 0) {
|
||||
button.setVisibility(Button.GONE);
|
||||
} else if (((long) object.eventList.size()) >= object.count_events) {
|
||||
button.setVisibility(Button.GONE);
|
||||
} else {
|
||||
button.setVisibility(Button.VISIBLE);
|
||||
}
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
object.offset += object.pagination;
|
||||
loadMoreEvents();
|
||||
}
|
||||
});
|
||||
|
||||
RelativeLayout content_event_item = (RelativeLayout) view
|
||||
.findViewById(R.id.content_event_item);
|
||||
content_event_item.setVisibility(RelativeLayout.GONE);
|
||||
if (object.newEvents) {
|
||||
Log.d("loading", "true");
|
||||
layout.setVisibility(LinearLayout.VISIBLE);
|
||||
if (convertView != null) {
|
||||
convertView.setClickable(false);
|
||||
}
|
||||
} else {
|
||||
Log.d("loading", "false");
|
||||
layout.setVisibility(LinearLayout.GONE);
|
||||
if (convertView != null) {
|
||||
convertView.setClickable(false);
|
||||
}
|
||||
}
|
||||
this.notifyDataSetChanged();
|
||||
// if (showLoadingEvents) {
|
||||
/*
|
||||
* layout = (LinearLayout) view
|
||||
* .findViewById(R.id.loading_more_events);
|
||||
* layout.setVisibility(LinearLayout.VISIBLE);
|
||||
*/
|
||||
// }// else {
|
||||
/*
|
||||
* LinearLayout layout = (LinearLayout) view
|
||||
* .findViewById(R.id.loading_more_events);
|
||||
* layout.setVisibility(LinearLayout.GONE);
|
||||
*/
|
||||
// }
|
||||
// Show button to get more events
|
||||
if ((!object.loadInProgress) && (object.count_events != 0)) {
|
||||
|
||||
}
|
||||
/*
|
||||
* Log.d("error", "crash2"); LinearLayout layout =
|
||||
* (LinearLayout) view .findViewById(R.id.loading_more_events);
|
||||
* layout.setVisibility(LinearLayout.VISIBLE);
|
||||
*
|
||||
* RelativeLayout layout2 = (RelativeLayout) view
|
||||
* .findViewById(R.id.content_event_item);
|
||||
* layout2.setVisibility(RelativeLayout.GONE);
|
||||
*/
|
||||
|
||||
/*
|
||||
* Button button = (Button) view
|
||||
* .findViewById(R.id.button_load_more_events);
|
||||
* button.setVisibility(Button.GONE);
|
||||
*/
|
||||
// } else {
|
||||
/*
|
||||
* Log.d("error", "crash1"); LinearLayout layout =
|
||||
* (LinearLayout) view .findViewById(R.id.loading_more_events);
|
||||
* layout.setVisibility(LinearLayout.GONE);
|
||||
*/
|
||||
|
||||
/*
|
||||
* RelativeLayout content_event_item = (RelativeLayout) view
|
||||
* .findViewById(R.id.content_event_item);
|
||||
* content_event_item.setVisibility(RelativeLayout.GONE);
|
||||
*/
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
final EventListItem item = this.object.eventList.get(position);
|
||||
/*
|
||||
* LinearLayout layout = (LinearLayout) view
|
||||
* .findViewById(R.id.loading_more_events);
|
||||
* layout.setVisibility(LinearLayout.GONE);
|
||||
*/
|
||||
final EventListItem item;
|
||||
try {
|
||||
item = this.object.eventList.get(position);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return view;
|
||||
}
|
||||
|
||||
switch (item.criticity) {
|
||||
|
||||
|
@ -543,7 +600,7 @@ public class EventList extends ListActivity {
|
|||
itemLinearLayout.addView(viewEventExtended);
|
||||
}
|
||||
}
|
||||
|
||||
this.notifyDataSetChanged();
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -618,7 +675,12 @@ public class EventList extends ListActivity {
|
|||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
EventListItem item = this.object.eventList.get(mPosition);
|
||||
EventListItem item;
|
||||
try {
|
||||
item = this.object.eventList.get(mPosition);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return;
|
||||
}
|
||||
item.opened = !item.opened;
|
||||
this.object.eventList.set(mPosition, item);
|
||||
la.notifyDataSetChanged();
|
||||
|
|
|
@ -74,7 +74,7 @@ public class IncidentList extends ListActivity {
|
|||
layout = (LinearLayout) findViewById(R.id.empty_list_layout);
|
||||
layout.setVisibility(LinearLayout.GONE);
|
||||
|
||||
layout = (LinearLayout) findViewById(R.id.loading_layout);
|
||||
// layout = (LinearLayout) findViewById(R.id.loading_layout);
|
||||
|
||||
if (loadInProgress) {
|
||||
layout.setVisibility(LinearLayout.VISIBLE);
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package pandroid_event_viewer.pandorafms;
|
||||
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/**
|
||||
* This Trust Manager is "naive" because it trusts everyone.
|
||||
**/
|
||||
public class NaiveTrustManager implements X509TrustManager
|
||||
{
|
||||
/**
|
||||
* Doesn't throw an exception, so this is how it approves a certificate.
|
||||
* @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[], String)
|
||||
**/
|
||||
public void checkClientTrusted ( X509Certificate[] cert, String authType )
|
||||
throws CertificateException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't throw an exception, so this is how it approves a certificate.
|
||||
* @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[], String)
|
||||
**/
|
||||
public void checkServerTrusted ( X509Certificate[] cert, String authType )
|
||||
throws CertificateException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
|
||||
**/
|
||||
public X509Certificate[] getAcceptedIssuers ()
|
||||
{
|
||||
return null; // I've seen someone return new X509Certificate[ 0 ];
|
||||
}
|
||||
}
|
|
@ -16,8 +16,13 @@ GNU General Public License for more details.
|
|||
*/
|
||||
package pandroid_event_viewer.pandorafms;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.Ringtone;
|
||||
|
@ -129,7 +134,7 @@ public class Options extends Activity {
|
|||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
|
||||
getString(R.string.select_sound));
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT,
|
||||
false);
|
||||
true);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT,
|
||||
false);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
|
||||
|
@ -160,6 +165,48 @@ public class Options extends Activity {
|
|||
* Saves all options
|
||||
*/
|
||||
private void save_options() {
|
||||
String url = ((EditText) findViewById(R.id.url)).getText().toString();
|
||||
if (url.contains("https")) {
|
||||
try {
|
||||
if (!Core.isValidCertificate(new URL(url))) {
|
||||
// Displays confirmation dialog
|
||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
Toast.makeText(getApplicationContext(),
|
||||
R.string.options_not_saved,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
writeChanges();
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(
|
||||
getString(R.string.certificate_not_valid))
|
||||
.setPositiveButton(getString(android.R.string.yes),
|
||||
dialogClickListener)
|
||||
.setNegativeButton(getString(android.R.string.no),
|
||||
dialogClickListener).show();
|
||||
} else {
|
||||
writeChanges();
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
Toast.makeText(getApplicationContext(), R.string.url_not_valid,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
writeChanges();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeChanges() {
|
||||
SharedPreferences preferences = getSharedPreferences(
|
||||
this.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
|
@ -171,7 +218,6 @@ public class Options extends Activity {
|
|||
if (url.charAt(url.length() - 1) == '/') {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
|
||||
editorPreferences.putString("url", url);
|
||||
// MainActivity uses this to know if it has to check tags and groups
|
||||
// again
|
||||
|
|
|
@ -23,9 +23,6 @@ import java.util.Date;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.TabActivity;
|
||||
import android.content.Intent;
|
||||
|
@ -34,6 +31,7 @@ import android.content.res.Configuration;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -44,11 +42,13 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
|
||||
// Data aplication
|
||||
public ArrayList<EventListItem> eventList;
|
||||
public BaseAdapter adapter;
|
||||
public long count_events;
|
||||
|
||||
// Flags
|
||||
public boolean loadInProgress;
|
||||
public boolean getNewListEvents;
|
||||
public boolean newEvents;
|
||||
|
||||
// Configuration
|
||||
public boolean show_popup_info;
|
||||
|
@ -283,20 +283,11 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
/**
|
||||
* Get events from pandora console.
|
||||
*
|
||||
* @param newEvents
|
||||
*/
|
||||
private void getEvents(boolean newEvents) {
|
||||
private void getEvents() {
|
||||
// Get total count.
|
||||
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(true)));
|
||||
String return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
Log.i(TAG + " getEvents", return_api);
|
||||
String return_api = API.getEvents(getApplicationContext(),
|
||||
serializeParams2Api(true));
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
this.count_events = new Long(return_api).longValue();
|
||||
|
@ -310,16 +301,9 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
}
|
||||
|
||||
// Get the list of events.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(false)));
|
||||
return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
|
||||
return_api = API.getEvents(getApplicationContext(),
|
||||
serializeParams2Api(false));
|
||||
Log.d(TAG, "List of events: " + return_api);
|
||||
Pattern pattern = Pattern
|
||||
.compile("Unable to process XML data file '(.*)'");
|
||||
Matcher matcher;
|
||||
|
@ -346,8 +330,10 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
Log.i(TAG + " getEvents - return_api", return_api);
|
||||
|
||||
String[] lines = return_api.split("\n");
|
||||
|
||||
newEvents = true;
|
||||
if (return_api.length() == 0) {
|
||||
Log.d("WORKS?", "NEWEVENTS = FALSE");
|
||||
newEvents = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -424,7 +410,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
* Executes the async task of getting events.
|
||||
*/
|
||||
public void executeBackgroundGetEvents() {
|
||||
new GetEventsAsyncTask().execute();
|
||||
new GetEventsAsyncTask(adapter).execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -435,14 +421,16 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
*/
|
||||
public class GetEventsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private BaseAdapter adapter;
|
||||
|
||||
public GetEventsAsyncTask(BaseAdapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Log.i(TAG + " GetEventsAsyncTask", "doInBackground");
|
||||
if (getNewListEvents) {
|
||||
getEvents(true);
|
||||
} else {
|
||||
getEvents(false);
|
||||
}
|
||||
getEvents();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -460,7 +448,9 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
i.putExtra("load_more", 1);
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
getApplicationContext().sendBroadcast(i);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue