mirror of
https://github.com/bspeice/itcs4180
synced 2024-12-04 13:18:16 -05:00
Initial TweetListActivity commit
This commit is contained in:
parent
3a5e0b2918
commit
e23b4bd798
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="edu.uncc.itcs4180.hw5"
|
||||
android:versionCode="1"
|
||||
@ -6,8 +6,9 @@
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="12"
|
||||
android:targetSdkVersion="18" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
android:targetSdkVersion="18" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@ -23,6 +24,10 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="edu.uncc.itcs4180.hw5.TweetsListActivity"
|
||||
android:label="@string/title_activity_tweets_list" >
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
BIN
HW5/res/drawable/add_bookmark.png
Normal file
BIN
HW5/res/drawable/add_bookmark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
BIN
HW5/res/drawable/not_retweeted.png
Normal file
BIN
HW5/res/drawable/not_retweeted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
BIN
HW5/res/drawable/profile_twitter.png
Normal file
BIN
HW5/res/drawable/profile_twitter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
HW5/res/drawable/retweeted.png
Normal file
BIN
HW5/res/drawable/retweeted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
19
HW5/res/layout/activity_tweets_list.xml
Normal file
19
HW5/res/layout/activity_tweets_list.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".TweetsListActivity" >
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listTweetList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true" >
|
||||
</ListView>
|
||||
|
||||
</RelativeLayout>
|
57
HW5/res/layout/tweet_list.xml
Normal file
57
HW5/res/layout/tweet_list.xml
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/RelativeLayout1"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="match_parent"
|
||||
android:columnCount="2"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgProfileImage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:src="@drawable/ic_launcher" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@+id/imageView1"
|
||||
android:layout_alignParentTop="true"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtTweetText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtTweetInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgIsRetweet"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/not_retweeted" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibtnSaveTweet"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onSaveTweet"
|
||||
android:src="@drawable/add_bookmark" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
9
HW5/res/menu/tweets_list.xml
Normal file
9
HW5/res/menu/tweets_list.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/action_settings"/>
|
||||
|
||||
</menu>
|
@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">HW5</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="title_activity_tweets_list">TweetsListActivity</string>
|
||||
|
||||
</resources>
|
||||
|
51
HW5/src/edu/uncc/itcs4180/hw5/BitmapDownloader.java
Normal file
51
HW5/src/edu/uncc/itcs4180/hw5/BitmapDownloader.java
Normal file
@ -0,0 +1,51 @@
|
||||
package edu.uncc.itcs4180.hw5;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class BitmapDownloader extends AsyncTask<String, Void, Void> {
|
||||
ImageView iv;
|
||||
Bitmap downloaded;
|
||||
|
||||
public BitmapDownloader(ImageView iv) {
|
||||
this.iv = iv;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... params) {
|
||||
downloaded = downloadBitmap(params[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Bitmap downloadBitmap(String sUrl) {
|
||||
try {
|
||||
URL url = new URL(sUrl);
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.connect();
|
||||
if (con.getResponseCode() == 200) {
|
||||
return BitmapFactory.decodeStream(con.getInputStream());
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
iv.setImageBitmap(downloaded);
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import edu.uncc.itcs4180.hw5.twitter.TweetList;
|
||||
import edu.uncc.itcs4180.hw5.twitter.TwitterClient;
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
@ -46,6 +47,19 @@ public class MainActivity extends Activity {
|
||||
ListView feeds = (ListView)findViewById(R.id.listNewsFeeds);
|
||||
ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.news_site, R.id.txtSiteName, newsSitesTitles);
|
||||
feeds.setAdapter(adapter);
|
||||
feeds.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
String key = ((TextView)view.findViewById(R.id.txtSiteName)).getText().toString();
|
||||
String handle = newsSites.get(key);
|
||||
// Shenanigans to get the parent instance
|
||||
// http://stackoverflow.com/questions/2076037/inside-onclicklistener-i-cannot-access-a-lot-of-things-how-to-approach
|
||||
Intent i = new Intent(MainActivity.this, TweetsListActivity.class);
|
||||
i.putExtra("handle", handle);
|
||||
startActivity(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,16 +78,4 @@ public class MainActivity extends Activity {
|
||||
Toast.makeText(this, "All Saved News are Cleared!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private class FeedListener implements OnItemClickListener {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
String key = ((TextView)view.findViewById(R.id.txtSiteName)).getText().toString();
|
||||
String handle = newsSites.get(key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
88
HW5/src/edu/uncc/itcs4180/hw5/TweetListAdapter.java
Normal file
88
HW5/src/edu/uncc/itcs4180/hw5/TweetListAdapter.java
Normal file
@ -0,0 +1,88 @@
|
||||
package edu.uncc.itcs4180.hw5;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.http.HttpConnection;
|
||||
|
||||
import edu.uncc.itcs4180.hw5.twitter.Tweet;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class TweetListAdapter extends ArrayAdapter<Tweet> {
|
||||
private final int TWEET_TAG_KEY = 1337;
|
||||
Activity activity;
|
||||
Tweet[] tweets;
|
||||
|
||||
public TweetListAdapter(Activity activity, Tweet[] tweets) {
|
||||
super(activity, R.layout.tweet_list, tweets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View rowView = convertView;
|
||||
TweetView tv = null;
|
||||
Tweet tweet = tweets[position];
|
||||
|
||||
if (rowView == null) {
|
||||
// Inflate a new row
|
||||
rowView = activity.getLayoutInflater().inflate(R.layout.tweet_list, null);
|
||||
|
||||
tv = new TweetView();
|
||||
tv.imgProfileImage = (ImageView) rowView.findViewById(R.id.imgProfileImage);
|
||||
tv.txtTweetText = (TextView) rowView.findViewById(R.id.txtTweetText);
|
||||
tv.txtTweetInfo = (TextView) rowView.findViewById(R.id.txtTweetInfo);
|
||||
tv.imgIsRetweet = (ImageView) rowView.findViewById(R.id.imgIsRetweet);
|
||||
tv.ibtnSaveTweet = (ImageButton) rowView.findViewById(R.id.ibtnSaveTweet);
|
||||
|
||||
rowView.setTag(tv);
|
||||
rowView.setTag(TWEET_TAG_KEY, tweet);
|
||||
} else {
|
||||
tv = (TweetView) rowView.getTag();
|
||||
}
|
||||
|
||||
// Add information to the current row
|
||||
// Start up our BitmapDownloader - it will update the ImageView for us
|
||||
new BitmapDownloader(tv.imgProfileImage).execute(tweet.getUser().getProfileImageUrl());
|
||||
tv.txtTweetText.setText(tweet.getText());
|
||||
tv.txtTweetInfo.setText(tweet.getDateCreated());
|
||||
// Set the retweet image
|
||||
if (tweet.isRetweet()) {
|
||||
tv.imgIsRetweet.setImageDrawable(activity.getResources().getDrawable(R.drawable.retweeted));
|
||||
}
|
||||
// Save tweets when we are clicked
|
||||
tv.ibtnSaveTweet.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveTweet((Tweet)v.getTag(TWEET_TAG_KEY));
|
||||
}
|
||||
});
|
||||
|
||||
return rowView;
|
||||
}
|
||||
|
||||
protected static class TweetView {
|
||||
ImageView imgProfileImage;
|
||||
TextView txtTweetText;
|
||||
TextView txtTweetInfo;
|
||||
ImageView imgIsRetweet;
|
||||
ImageButton ibtnSaveTweet;
|
||||
}
|
||||
|
||||
private void saveTweet(Tweet t) {
|
||||
// TODO: Save tweets here.
|
||||
Toast.makeText(activity, "Saved in DB!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
53
HW5/src/edu/uncc/itcs4180/hw5/TweetsListActivity.java
Normal file
53
HW5/src/edu/uncc/itcs4180/hw5/TweetsListActivity.java
Normal file
@ -0,0 +1,53 @@
|
||||
package edu.uncc.itcs4180.hw5;
|
||||
|
||||
import edu.uncc.itcs4180.hw5.twitter.TweetList;
|
||||
import edu.uncc.itcs4180.hw5.twitter.TwitterClient;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
||||
public class TweetsListActivity extends Activity {
|
||||
|
||||
ProgressDialog dialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_tweets_list);
|
||||
|
||||
// Fetch our tweets
|
||||
String handle = getIntent().getExtras().getString("handle");
|
||||
|
||||
dialog = new ProgressDialog(this);
|
||||
dialog.setCancelable(false);
|
||||
dialog.setMessage("Downloading tweets for: " + handle);
|
||||
dialog.show();
|
||||
|
||||
// For whatever reason, we have to call the TwitterClient downloader ourselves.
|
||||
// AsyncTask inside AsyncTask simply doesn't work. This leads to an ugly double-new,
|
||||
// despite me trying to write a nice clean API.
|
||||
// Also, totally didn't know Java syntax allowed me to do this.
|
||||
new TwitterClient().new TweetListDownloader(){
|
||||
@Override
|
||||
protected void onPostExecute(TweetList result) {
|
||||
displayTweets(result);
|
||||
dialog.cancel();
|
||||
};
|
||||
}.execute(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.tweets_list, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void displayTweets(TweetList list) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -29,6 +29,9 @@ public class Tweet {
|
||||
|
||||
@SerializedName("user")
|
||||
private TwitterUser user;
|
||||
|
||||
@SerializedName("retweeted")
|
||||
private boolean retweeted;
|
||||
|
||||
public String getDateCreated() {
|
||||
return dateCreated;
|
||||
@ -85,6 +88,14 @@ public class Tweet {
|
||||
public TwitterUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public boolean isRetweet() {
|
||||
return retweeted;
|
||||
}
|
||||
|
||||
public void setRetweet(boolean retweeted) {
|
||||
this.retweeted = retweeted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -47,7 +47,7 @@ public class TwitterClient {
|
||||
return null;
|
||||
}
|
||||
|
||||
private class TweetListDownloader extends AsyncTask<String, Void, TweetList> {
|
||||
public class TweetListDownloader extends AsyncTask<String, Void, TweetList> {
|
||||
|
||||
@Override
|
||||
protected TweetList doInBackground(String... params) {
|
||||
|
@ -15,6 +15,9 @@ public class TwitterUser {
|
||||
|
||||
@SerializedName("profile_image_url")
|
||||
private String profileImageUrl;
|
||||
|
||||
@SerializedName("profile_background_image_url")
|
||||
private String profileBackgroundImageUrl;
|
||||
|
||||
public String getProfileImageUrl() {
|
||||
return profileImageUrl;
|
||||
@ -39,4 +42,12 @@ public class TwitterUser {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getProfileBackgroundImageUrl() {
|
||||
return profileBackgroundImageUrl;
|
||||
}
|
||||
|
||||
public void setProfileBackgroundImageUrl(String profileBackgroundImageUrl) {
|
||||
this.profileBackgroundImageUrl = profileBackgroundImageUrl;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user