Permalink
Browse files

Make ListView work, add EmptyView to it

  • Loading branch information...
1 parent 80367e7 commit 7d91fd33e8cc209925a7946dc14780d02fa87ddd @itsbilal committed Oct 23, 2011
@@ -20,21 +20,25 @@
public static final int icon=0x7f020000;
}
public static final class id {
- public static final int button_submit=0x7f080002;
- public static final int dropdown_duration=0x7f080001;
- public static final int edittext_tweet=0x7f080000;
+ public static final int button_submit=0x7f080004;
+ public static final int dropdown_duration=0x7f080003;
+ public static final int edittext_tweet=0x7f080002;
+ public static final int list_tweet_time=0x7f080001;
+ public static final int list_tweet_tweet=0x7f080000;
}
public static final class layout {
- public static final int list_tweets=0x7f030000;
- public static final int main=0x7f030001;
- public static final int window_title=0x7f030002;
+ public static final int list_tweet_item=0x7f030000;
+ public static final int list_tweets=0x7f030001;
+ public static final int main=0x7f030002;
+ public static final int window_title=0x7f030003;
}
public static final class string {
public static final int app_name=0x7f050001;
public static final int button_submit_label=0x7f050005;
public static final int dropdown_duration_prompt=0x7f050002;
public static final int duration_textview_text=0x7f050003;
public static final int edittext_tweet_hint=0x7f050004;
+ public static final int empty_tweet_list_text=0x7f050007;
public static final int hello=0x7f050000;
public static final int titlebar_text=0x7f050006;
}
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:padding="6dip"
+ android:layout_height="wrap_content"
+ >
+ <TextView android:id="@+id/list_tweet_tweet"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:text="test" />
+
+ <TextView android:id="@+id/list_tweet_time"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/list_tweet_tweet"
+ android:layout_alignParentLeft="true"
+ android:textSize="9dip"
+ android:text="test2" />
+
+</RelativeLayout>
View
@@ -1,10 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+<ListView
+ android:id="@id/android:list"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"/>
+
+<TextView android:id="@id/android:empty"
+ android:text="@string/empty_tweet_list_text"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:text="HELLO!" />
+ android:textSize="20dip"
+ android:gravity="center"
+ android:layout_height="fill_parent"/>
</LinearLayout>
View
@@ -7,6 +7,7 @@
<string name="edittext_tweet_hint">Enter tweet</string>
<string name="button_submit_label">Submit</string>
<string name="titlebar_text">List of Scheduled Tweets</string>
+ <string name="empty_tweet_list_text">No tweets scheduled yet!</string>
<string-array name="dropdown_duration_options">
<item>After 5 minutes</item>
<item>After 10 minutes</item>
@@ -1,40 +1,54 @@
package com.bilal.schedulemytweets;
+import java.util.*;
+
import android.app.*;
import android.content.*;
import android.net.*;
import android.os.*;
import android.util.*;
import android.view.*;
+import android.widget.*;
-public class ListTweetsActivity extends Activity {
+public class ListTweetsActivity extends ListActivity {
private String TAG="ScheduleMyTweets";
private Twitter twitter_instance;
+ private ListAdapter tweets_list_adapter;
+ private List<Tweet> tweets_list;
+
SQLiteTweetDB tweet_db_helper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
- setContentView(R.layout.list_tweets);
+ setContentView(R.layout.list_tweets); // Necessary for titlebar to come up properly
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
+ tweets_list = new ArrayList<Tweet>();
+ //tweets_list.add(new Tweet("Hi",1231242,1)); // TODO: This is just a test
+ tweets_list_adapter = new TweetListAdapter(this,tweets_list);
+ setListAdapter(tweets_list_adapter);
+
+ /*TextView empty_text_view = new TextView(this);
+ empty_text_view.setText(getString(R.string.empty_tweet_list_text));
+ getListView().setEmptyView(empty_text_view);*/
+
tweet_db_helper = new SQLiteTweetDB(this);
SharedPreferences sp = getPreferences(MODE_PRIVATE);
if (sp.contains("access_token") != true) {
- //setup_twitter_auth();
+
twitter_instance = new Twitter(null, null);
// Open OAuth login page
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(twitter_instance.setup_twitter_auth())));
} else {
Log.d(TAG,"Access token: " + sp.getString("access_token", "heynow") + "\nAccess Token Secret: " + sp.getString("access_token_secret", "beep"));
- //OAuthConsumer = new CommonsHttpOAuthConsumer(consumer_key, consumer_secret);
- //OAuthConsumer.setTokenWithSecret(sp.getString("access_token", "beep"), sp.getString("access_token_secret", "beep"));
+
twitter_instance = new Twitter (sp.getString("access_token", "beep"), sp.getString("access_token_secret", "beep"));
// Start the service
@@ -0,0 +1,25 @@
+package com.bilal.schedulemytweets;
+
+public class Tweet {
+ private String tweet_text;
+ private long tweet_time;
+ private Integer tweet_id;
+
+ Tweet(String _tweet_text, long _tweet_time, Integer _tweet_id) {
+ tweet_text = _tweet_text;
+ tweet_time = _tweet_time;
+ tweet_id = _tweet_id;
+ }
+
+ public String get_tweet_text() {
+ return tweet_text;
+ }
+
+ public long get_tweet_time() {
+ return tweet_time;
+ }
+
+ public Integer get_tweet_id() {
+ return tweet_id;
+ }
+}
@@ -0,0 +1,57 @@
+package com.bilal.schedulemytweets;
+
+import android.view.*;
+import android.widget.*;
+import android.content.*;
+
+import java.util.*;
+
+public class TweetListAdapter extends BaseAdapter {
+
+ private List<Tweet> tweets_list = new ArrayList<Tweet>();
+
+ private Context context;
+
+ TweetListAdapter(Context _context, List<Tweet> _tweets_list) {
+ context = _context;
+
+ tweets_list = _tweets_list;
+ }
+
+ public int getCount() {
+ // TODO Auto-generated method stub
+ return tweets_list.size();
+ }
+
+ public Object getItem(int arg0) {
+ // TODO Auto-generated method stub
+ return tweets_list.get(arg0);
+ }
+
+ public long getItemId(int arg0) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public View getView(int arg0, View arg1, ViewGroup arg2) {
+
+ Tweet tweet = (Tweet) tweets_list.get(arg0);
+
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+
+ RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.list_tweet_item, null, false);
+
+ TextView tweet_text_view = (TextView)layout.findViewById(R.id.list_tweet_tweet);
+ tweet_text_view.setText(tweet.get_tweet_text());
+
+ TextView tweet_time_view = (TextView) layout.findViewById(R.id.list_tweet_time);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(tweet.get_tweet_time() * 1000);
+ Date date = calendar.getTime();
+ tweet_time_view.setText(date.toString());
+
+ return layout;
+ }
+
+}

0 comments on commit 7d91fd3

Please sign in to comment.