mirror of
https://github.com/bspeice/itcs4180
synced 2025-04-21 07:11:35 -04:00
Add the main page functionality for HW 5
This commit is contained in:
parent
c81decd705
commit
3a5e0b2918
@ -8,9 +8,33 @@
|
|||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
tools:context=".MainActivity" >
|
tools:context=".MainActivity" >
|
||||||
|
|
||||||
<TextView
|
<ListView
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/listNewsFeeds"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
</ListView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/hello_world" />
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentLeft="true" >
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnViewSaved"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="View Saved News"
|
||||||
|
android:onClick="onViewSaved" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnClearSaved"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Clear Saved News"
|
||||||
|
android:onClick="onClearSaved" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
16
HW5/res/layout/news_site.xml
Normal file
16
HW5/res/layout/news_site.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtSiteName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:padding="15dp"
|
||||||
|
android:text="Large Text"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -2,6 +2,7 @@ package edu.uncc.itcs4180.hw5;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import edu.uncc.itcs4180.hw5.twitter.TweetList;
|
import edu.uncc.itcs4180.hw5.twitter.TweetList;
|
||||||
@ -10,21 +11,41 @@ import android.os.Bundle;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ListAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
private static final Map<String, String> newsSites;
|
private static final Map<String, String> newsSites;
|
||||||
|
private static final String[] newsSitesTitles;
|
||||||
static {
|
static {
|
||||||
Map<String, String> mMap = new HashMap<String, String>();
|
Map<String, String> mMap = new LinkedHashMap<String, String>();
|
||||||
|
// Put news sites here
|
||||||
mMap.put("CNN Breaking News", "cnnbrk");
|
mMap.put("CNN Breaking News", "cnnbrk");
|
||||||
|
mMap.put("The New York Times", "nytimes");
|
||||||
|
mMap.put("NBA", "nba");
|
||||||
|
mMap.put("BBC Breaking News", "bbcbreaking");
|
||||||
|
|
||||||
newsSites = Collections.unmodifiableMap(mMap);
|
newsSites = Collections.unmodifiableMap(mMap);
|
||||||
|
newsSitesTitles = newsSites.keySet().toArray(new String[newsSites.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
// Set up all the news feeds
|
||||||
|
ListView feeds = (ListView)findViewById(R.id.listNewsFeeds);
|
||||||
|
ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.news_site, R.id.txtSiteName, newsSitesTitles);
|
||||||
|
feeds.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -34,4 +55,25 @@ public class MainActivity extends Activity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onViewSaved(View v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClearSaved(View v) {
|
||||||
|
// TODO: Implement the database clearing functionality here.
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user