Back to project page scala1_android.
The source code is released under:
Copyright (c) 2012, Magnetic Bear Studios Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditio...
If you think the Android project scala1_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.magneticbear.scala1; //ww w . ja v a 2 s .co m import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Date; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONObject; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.widget.ListView; import android.widget.Toast; public class Events extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_events); } @Override protected void onResume() { refreshFeed(); super.onResume(); } // Dont show the options menu @Override public boolean onPrepareOptionsMenu(Menu menu) { return false; } public void refreshFeed() { // Create an adapter Struct_Event_Adapter adapter = new Struct_Event_Adapter(getBaseContext(), R.id.struct_event_adapter_row_title, (ArrayList<Struct_Event>)ServerData.events.clone(), true, true); // Connect list to adapter ListView lv = (ListView)findViewById(R.id.events_list); lv.setAdapter(adapter); } public String readEventFeed() { StringBuilder builder = new StringBuilder(); HttpClient client = OpenAllSSLSocketFactory.getNewOpenAllSSLHttpClient(); //new DefaultHttpClient(); HttpGet httpGet = new HttpGet(getString(R.string.url_events_feed)); try { HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { //Toast.makeText(getBaseContext(), "HTTP 200 on events feed GET.", Toast.LENGTH_LONG).show(); HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } } else { Log.e(Events.class.getName(), "Failed to download events feed json."); Toast.makeText(getBaseContext(), "Failed to download events feed json.", Toast.LENGTH_LONG).show(); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); } @Override public void onBackPressed() { UserData.mixpanel.track("EventsListBack", null); super.onBackPressed(); } }