Added loading dialog, using AsyncTask

master
unknown 13 years ago
parent 92044c1746
commit 49d509eb2f

@ -1,37 +1,37 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thinkit.lewebconnect" package="com.thinkit.lewebconnect"
android:versionCode="2" android:versionCode="2"
android:versionName="1.1" > android:versionName="1.1" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"/> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"/>
<application <application
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:debuggable="false"> android:label="@string/app_name" android:debuggable="true">
<activity <activity
android:label="@string/app_name" android:label="@string/app_name"
android:name=".LeWebConnect" android:name=".LeWebConnect"
android:theme="@android:style/Theme.NoTitleBar" > android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter > <intent-filter >
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".Perticipents"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:label="@string/app_name"
android:name=".ThinkIT"
android:theme="@android:style/Theme.NoTitleBar" >
</activity> </activity>
<activity android:name=".UserProfile"></activity> <activity
</application> android:label="@string/app_name"
<uses-permission android:name="android.permission.INTERNET"></uses-permission> android:name=".Perticipents"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:label="@string/app_name"
android:name=".ThinkIT"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity android:name=".UserProfile"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest> </manifest>

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#eaeaea" <gradient android:startColor="#FFFFFF" android:endColor="#eaeaea"
android:angle="270"/> android:angle="270"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/> android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape> </shape>

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<gradient android:startColor="#eaeaea" android:endColor="#d7d7d7" <gradient android:startColor="#eaeaea" android:endColor="#d7d7d7"
android:angle="270"/> android:angle="270"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/> android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape> </shape>

@ -0,0 +1,16 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:gravity="center" android:orientation="vertical"
android:layout_height="fill_parent" android:background="#E5E5E5">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/main_loading" android:visibility="visible" android:layout_gravity="center">
</ProgressBar>
<ListView
android:id="@android:id/list"
android:layout_height="0dip" android:visibility="invisible" android:layout_width="wrap_content" android:layout_weight="1">
</ListView>
</LinearLayout>

@ -17,6 +17,7 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:padding="5dp"> android:padding="5dp">
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
</TabHost> </TabHost>

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="#ffffff" android:background="#ffffff"
android:orientation="vertical" android:layout_gravity="center"> android:orientation="vertical" android:layout_gravity="center">
<TextView <TextView
android:id="@+id/textView1" android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Developed by:" android:text="Developed by:"
android:textAppearance="?android:attr/textAppearanceLarge" android:layout_gravity="center" android:layout_marginTop="160px" android:textColor="#000000"/> android:textAppearance="?android:attr/textAppearanceLarge" android:layout_gravity="center" android:layout_marginTop="160px" android:textColor="#000000"/>
<ImageButton <ImageButton
android:id="@+id/thinkit_button" android:id="@+id/thinkit_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/logo_thinkit" android:layout_gravity="center_vertical|center_horizontal" android:layout_marginTop="30px" android:paddingBottom="0px" android:paddingLeft="0px" android:paddingRight="0px" android:paddingTop="0px"/> android:src="@drawable/logo_thinkit" android:layout_gravity="center_vertical|center_horizontal" android:layout_marginTop="30px" android:paddingBottom="0px" android:paddingLeft="0px" android:paddingRight="0px" android:paddingTop="0px"/>
<TextView <TextView
android:id="@+id/email" android:id="@+id/email"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Contact us !" android:text="Contact us !"
android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#000000" android:layout_gravity="center" android:clickable="true" android:layout_marginTop="10px"/> android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#000000" android:layout_gravity="center" android:clickable="true" android:layout_marginTop="10px"/>
</LinearLayout> </LinearLayout>

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Window;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.TextView; import android.widget.TextView;

@ -14,9 +14,11 @@ import com.thinkit.lewebconnect.Attendee.LeWebByCountryComparator;
import com.thinkit.lewebconnect.Attendee.LeWebByLnameComparator; import com.thinkit.lewebconnect.Attendee.LeWebByLnameComparator;
import android.app.ListActivity; import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.sax.Element; import android.sax.Element;
import android.text.Editable; import android.text.Editable;
@ -35,6 +37,7 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Filterable; import android.widget.Filterable;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
@ -52,62 +55,34 @@ public class Perticipents extends ListActivity {
private ArrayList<Attendee> users; private ArrayList<Attendee> users;
private EditText filterText = null; private EditText filterText = null;
ArrayAdapter<Attendee> adapter = null; ArrayAdapter<Attendee> adapter = null;
private ListView lv;
private Context mContext;
private ProgressDialog mDialog;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mContext = this;
String xml; mDialog = new ProgressDialog(mContext);
xml = XMLfunctions.getXML(); setContentView(R.layout.perticipents);
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc); new getXmlTask().execute();
//Log.d(TAG, "numResults length: " + String.valueOf(numResults));
if((numResults <= 0)) {
Toast.makeText(this, "Please make sure connection is available !", Toast.LENGTH_LONG).show();
finish();
}
NodeList nodes = doc.getElementsByTagName("user");
try {
users = new ArrayList<Attendee>();
//fill in the list items from the XML document
for (int i = 0; i < nodes.getLength(); i++) {
Node e = (Node)nodes.item(i);
users.add(NodeToAttendee(e));
}
Collections.sort(users, new LeWebByLnameComparator());
setContentView(R.layout.perticipents);
filterText= (EditText) findViewById(R.building_list.search_box); filterText= (EditText) findViewById(R.building_list.search_box);
filterText.addTextChangedListener(filterTextWatcher); filterText.addTextChangedListener(filterTextWatcher);
lv = getListView();
ListView lv = getListView();
lv.setFastScrollEnabled(true); lv.setFastScrollEnabled(true);
lv.setTextFilterEnabled(false); lv.setTextFilterEnabled(false);
registerForContextMenu(lv); registerForContextMenu(lv);
adapter = new LeWebAdapter(this, users, true, false, false);
setListAdapter(adapter);
registerForContextMenu(getListView());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
} }
private TextWatcher filterTextWatcher = new TextWatcher() { private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
} }
@ -326,4 +301,57 @@ public class Perticipents extends ListActivity {
return user; return user;
} }
}
private class getXmlTask extends AsyncTask<Void, Void, ArrayList<Attendee>> {
@Override
protected void onPreExecute(){
mDialog.setMessage("Loading data");
mDialog.show();
}
@Override
protected ArrayList<Attendee> doInBackground(Void... params) {
// TODO Auto-generated method stub
String xml;
xml = XMLfunctions.getXML();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);
//Log.d(TAG, "numResults length: " + String.valueOf(numResults));
if((numResults <= 0)) {
// Toast.makeText(this, "Please make sure connection is available !", Toast.LENGTH_LONG).show();
// finish();
return null;
}
NodeList nodes = doc.getElementsByTagName("user");
try {
users = new ArrayList<Attendee>();
//fill in the list items from the XML document
for (int i = 0; i < nodes.getLength(); i++) {
Node e = (Node)nodes.item(i);
users.add(NodeToAttendee(e));
}
Collections.sort(users, new LeWebByLnameComparator());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return users;
}
@Override
protected void onPostExecute(final ArrayList<Attendee> users){
adapter = new LeWebAdapter(mContext, users, true, false, false);
mDialog.hide();
setListAdapter(adapter);
registerForContextMenu(getListView());
}
}
}

@ -1,55 +1,55 @@
package com.thinkit.lewebconnect; package com.thinkit.lewebconnect;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
public class ThinkIT extends Activity { public class ThinkIT extends Activity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.thinkit); setContentView(R.layout.thinkit);
try { try {
View button = findViewById(R.id.thinkit_button); View button = findViewById(R.id.thinkit_button);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
String url = "http://i-think-it.com/"; String url = "http://i-think-it.com/";
Intent i = new Intent(Intent.ACTION_VIEW); Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url)); i.setData(Uri.parse(url));
startActivity(i); startActivity(i);
} }
}); });
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
View button = findViewById(R.id.email); View button = findViewById(R.id.email);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text"); emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"contact@i-think-it.com"}); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"contact@i-think-it.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hello guys, your app is great ... "); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hello guys, your app is great ... ");
startActivity(Intent.createChooser(emailIntent, "Send mail...")); startActivity(Intent.createChooser(emailIntent, "Send mail..."));
} }
}); });
} }
} }

@ -1,102 +1,102 @@
package com.thinkit.lewebconnect; package com.thinkit.lewebconnect;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler; import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener; import org.json.JSONTokener;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.widget.Toast; import android.widget.Toast;
public class Tweet { public class Tweet {
public static final String TWEETS_URL = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name="; public static final String TWEETS_URL = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=";
public String message; public String message;
public String date_created; public String date_created;
public String tweet_id; public String tweet_id;
public String profile_image_url; public String profile_image_url;
public Tweet(String tweet_id, String message, String date_created, String profile_image_url) { public Tweet(String tweet_id, String message, String date_created, String profile_image_url) {
this.message = message; this.message = message;
this.date_created = date_created; this.date_created = date_created;
this.tweet_id = tweet_id; this.tweet_id = tweet_id;
this.profile_image_url = profile_image_url; this.profile_image_url = profile_image_url;
} }
public static ArrayList<Tweet> getTweets(String username) { public static ArrayList<Tweet> getTweets(String username) {
ArrayList<Tweet> tweets = new ArrayList<Tweet>(); ArrayList<Tweet> tweets = new ArrayList<Tweet>();
HttpClient client = new DefaultHttpClient(); HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(TWEETS_URL + username + "&count=10"); HttpGet get = new HttpGet(TWEETS_URL + username + "&count=10");
HttpResponse httpResponse = null; HttpResponse httpResponse = null;
// ResponseHandler<String> responseHandler = new BasicResponseHandler(); // ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = null; String responseBody = null;
try { try {
// responseBody = client.execute(get, responseHandler); // responseBody = client.execute(get, responseHandler);
httpResponse = client.execute(get); httpResponse = client.execute(get);
HttpEntity httpEntity = httpResponse.getEntity(); HttpEntity httpEntity = httpResponse.getEntity();
responseBody = EntityUtils.toString(httpEntity, "UTF-8"); responseBody = EntityUtils.toString(httpEntity, "UTF-8");
} catch (ClientProtocolException e) { } catch (ClientProtocolException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
try { try {
// JSONObject stats = (JSONObject) new JSONTokener(responseBody).nextValue(); // JSONObject stats = (JSONObject) new JSONTokener(responseBody).nextValue();
JSONTokener tokener = new JSONTokener(responseBody); JSONTokener tokener = new JSONTokener(responseBody);
JSONArray stats = new JSONArray(tokener); JSONArray stats = new JSONArray(tokener);
for (int i =0; i < stats.length(); i++) { for (int i =0; i < stats.length(); i++) {
JSONObject stat = stats.getJSONObject(i); JSONObject stat = stats.getJSONObject(i);
String tweet_id = stat.getString("id_str"); String tweet_id = stat.getString("id_str");
String tweet_msg = stat.getString("text"); String tweet_msg = stat.getString("text");
String tweet_date = stat.getString("created_at"); String tweet_date = stat.getString("created_at");
tweet_date = tweet_date.substring(0, 16); tweet_date = tweet_date.substring(0, 16);
JSONObject user = stat.getJSONObject("user"); JSONObject user = stat.getJSONObject("user");
String profile_image = user.getString("profile_image_url"); String profile_image = user.getString("profile_image_url");
Tweet tweet = new Tweet(tweet_id, tweet_msg, tweet_date, profile_image); Tweet tweet = new Tweet(tweet_id, tweet_msg, tweet_date, profile_image);
tweets.add(tweet); tweets.add(tweet);
} }
} catch (JSONException e) { } catch (JSONException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
return tweets; return tweets;
} }
public Bitmap getBitmap(String bitmapUrl) { public Bitmap getBitmap(String bitmapUrl) {
try { try {
URL url = new URL(bitmapUrl); URL url = new URL(bitmapUrl);
return BitmapFactory.decodeStream(url.openConnection().getInputStream()); return BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
return null; return null;
} }
} }
} }

@ -1,51 +1,51 @@
package com.thinkit.lewebconnect; package com.thinkit.lewebconnect;
import java.util.ArrayList; import java.util.ArrayList;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.TextView; import android.widget.TextView;
public class TweetsAdapter extends ArrayAdapter<Tweet> { public class TweetsAdapter extends ArrayAdapter<Tweet> {
private ArrayList<Tweet> tweets; private ArrayList<Tweet> tweets;
private Context context; private Context context;
public TweetsAdapter(Context context, int textViewResouceID, ArrayList<Tweet> tweets) { public TweetsAdapter(Context context, int textViewResouceID, ArrayList<Tweet> tweets) {
super(context, textViewResouceID, tweets); super(context, textViewResouceID, tweets);
this.tweets = tweets; this.tweets = tweets;
this.context = context; this.context = context;
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
if (v == null) { if (v == null) {
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.tweet_row, null); v = vi.inflate(R.layout.tweet_row, null);
} }
Tweet tweet = tweets.get(position); Tweet tweet = tweets.get(position);
if (tweet != null) { if (tweet != null) {
TextView tweet_msg = (TextView) v.findViewById(R.id.tweet_text); TextView tweet_msg = (TextView) v.findViewById(R.id.tweet_text);
TextView tweet_date = (TextView) v.findViewById(R.id.tweet_date); TextView tweet_date = (TextView) v.findViewById(R.id.tweet_date);
// ImageView image = (ImageView) v.findViewById(R.id.avatar); // ImageView image = (ImageView) v.findViewById(R.id.avatar);
// //
if (tweet_date != null) { if (tweet_date != null) {
tweet_date.setText(tweet.date_created); tweet_date.setText(tweet.date_created);
} }
if(tweet_msg != null) { if(tweet_msg != null) {
tweet_msg.setText(tweet.message); tweet_msg.setText(tweet.message);
} }
// if(image != null) { // if(image != null) {
// image.setImageBitmap(getBitmap(tweet.image_url)); // image.setImageBitmap(getBitmap(tweet.image_url));
// } // }
} }
return v; return v;
} }
} }

Loading…
Cancel
Save