Skip to content

Commit cb7128b

Browse files
committed
updates
1 parent 615a805 commit cb7128b

24 files changed

Lines changed: 434 additions & 85 deletions

File tree

‎com.example.android.rssfeed/res/layout/fragment_rsslist_overview.xml‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
android:layout_height="match_parent"
55
android:orientation="vertical" >
66

7-
<ListView
8-
android:id="@android:id/list"
9-
android:layout_width="match_parent"
10-
android:layout_height="wrap_content" >
11-
</ListView>
7+
<Button
8+
android:id="@+id/button1"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:text="Press to update"
12+
/>
1213

1314
</LinearLayout>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical" >
6+
7+
<ListView
8+
android:id="@android:id/list"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content" >
11+
</ListView>
12+
13+
</LinearLayout>
Lines changed: 33 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,60 @@
11
package com.example.android.rssfeed;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
6-
import android.app.ListFragment;
7-
import android.content.Intent;
8-
import android.content.SharedPreferences;
9-
import android.os.AsyncTask;
3+
import android.app.Activity;
4+
import android.app.Fragment;
105
import android.os.Bundle;
11-
import android.preference.PreferenceManager;
126
import android.view.LayoutInflater;
137
import android.view.View;
148
import android.view.ViewGroup;
15-
import android.widget.ArrayAdapter;
16-
import android.widget.ListView;
17-
18-
import com.example.android.rssfeedlibrary.RssFeedProvider;
19-
import com.example.android.rssfeedlibrary.RssItem;
20-
21-
public class MyListFragment extends ListFragment {
22-
ParseTask parseTask;
9+
import android.widget.Button;
2310

24-
@Override
25-
public void onCreate(Bundle savedInstanceState) {
26-
super.onCreate(savedInstanceState);
11+
public class MyListFragment extends Fragment {
2712

28-
List<RssItem> list = new ArrayList<RssItem>();
29-
MyAdapter adapter = new MyAdapter(getActivity(),
30-
android.R.layout.simple_list_item_1, list);
31-
setListAdapter(adapter);
32-
setRetainInstance(true);
33-
}
13+
private OnItemSelectedListener listener;
3414

3515
@Override
3616
public View onCreateView(LayoutInflater inflater, ViewGroup container,
3717
Bundle savedInstanceState) {
3818
View view = inflater.inflate(R.layout.fragment_rsslist_overview,
3919
container, false);
40-
20+
Button button = (Button) view.findViewById(R.id.button1);
21+
button.setOnClickListener(new View.OnClickListener() {
22+
@Override
23+
public void onClick(View v) {
24+
updateDetail();
25+
}
26+
});
4127
return view;
4228
}
4329

44-
@Override
45-
public void onListItemClick(ListView l, View v, int position, long id) {
46-
RssItem item = (RssItem) getListAdapter().getItem(position);
47-
updateDetail(item);
30+
public interface OnItemSelectedListener {
31+
public void onRssItemSelected(String link);
4832
}
4933

50-
private static class ParseTask extends
51-
AsyncTask<String, Void, List<RssItem>> {
52-
private MyListFragment fragment;
53-
54-
public synchronized void setFragment(MyListFragment fragment) {
55-
this.fragment = fragment;
56-
}
57-
58-
@Override
59-
protected List<RssItem> doInBackground(String... params) {
60-
List<RssItem> list = RssFeedProvider.parse(params[0]);
61-
return list;
62-
}
63-
64-
@Override
65-
protected void onPostExecute(List<RssItem> result) {
66-
fragment.setListContent(result);
67-
}
68-
}
69-
70-
public void updateListContent() {
71-
if (parseTask == null) {
72-
parseTask = new ParseTask();
73-
parseTask.setFragment(this);
74-
parseTask.execute("http://www.vogella.com/article.rss");
34+
@Override
35+
public void onAttach(Activity activity) {
36+
super.onAttach(activity);
37+
if (activity instanceof OnItemSelectedListener) {
38+
listener = (OnItemSelectedListener) activity;
39+
} else {
40+
throw new ClassCastException(activity.toString()
41+
+ " must implemenet MyListFragment.OnItemSelectedListener");
7542
}
7643
}
7744

78-
public void setListContent(List<RssItem> result) {
79-
ArrayAdapter listAdapter = (ArrayAdapter) getListAdapter();
80-
listAdapter.clear();
81-
listAdapter.addAll(result);
82-
parseTask.setFragment(null);
83-
parseTask = null;
45+
@Override
46+
public void onDetach() {
47+
super.onDetach();
48+
listener = null;
8449
}
8550

86-
public void updateDetail(RssItem item) {
87-
DetailFragment fragment = (DetailFragment) getFragmentManager()
88-
.findFragmentById(R.id.detailFragment);
89-
90-
if (fragment != null && fragment.isInLayout()) {
91-
fragment.setText(item.getLink());
92-
} else {
93-
Intent intent = new Intent(getActivity().getApplicationContext(),
94-
DetailActivity.class);
95-
intent.putExtra("value", item.getLink());
96-
startActivity(intent);
97-
}
98-
99-
SharedPreferences prefs = PreferenceManager
100-
.getDefaultSharedPreferences(getActivity());
101-
102-
// Get existing preference
103-
String string = prefs.getString("url", "kdsfkds");
51+
// May also be triggered from the Activity
52+
public void updateDetail() {
53+
// Create a string, just for testing
54+
String newTime = String.valueOf(System.currentTimeMillis());
10455

56+
// Inform the Activity about the change based
57+
// interface defintion
58+
listener.onRssItemSelected(newTime);
10559
}
10660
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.example.android.rssfeed;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import android.app.ListFragment;
7+
import android.content.Intent;
8+
import android.content.SharedPreferences;
9+
import android.os.AsyncTask;
10+
import android.os.Bundle;
11+
import android.preference.PreferenceManager;
12+
import android.view.LayoutInflater;
13+
import android.view.View;
14+
import android.view.ViewGroup;
15+
import android.widget.ArrayAdapter;
16+
import android.widget.ListView;
17+
18+
import com.example.android.rssfeedlibrary.RssFeedProvider;
19+
import com.example.android.rssfeedlibrary.RssItem;
20+
21+
public class MyListFragmentFinished extends ListFragment {
22+
ParseTask parseTask;
23+
24+
@Override
25+
public void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
28+
List<RssItem> list = new ArrayList<RssItem>();
29+
MyAdapter adapter = new MyAdapter(getActivity(),
30+
android.R.layout.simple_list_item_1, list);
31+
setListAdapter(adapter);
32+
setRetainInstance(true);
33+
}
34+
35+
@Override
36+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
37+
Bundle savedInstanceState) {
38+
View view = inflater.inflate(R.layout.fragment_rsslist_overview,
39+
container, false);
40+
41+
return view;
42+
}
43+
44+
@Override
45+
public void onListItemClick(ListView l, View v, int position, long id) {
46+
RssItem item = (RssItem) getListAdapter().getItem(position);
47+
updateDetail(item);
48+
}
49+
50+
private static class ParseTask extends
51+
AsyncTask<String, Void, List<RssItem>> {
52+
private MyListFragmentFinished fragment;
53+
54+
public synchronized void setFragment(MyListFragmentFinished fragment) {
55+
this.fragment = fragment;
56+
}
57+
58+
@Override
59+
protected List<RssItem> doInBackground(String... params) {
60+
List<RssItem> list = RssFeedProvider.parse(params[0]);
61+
return list;
62+
}
63+
64+
@Override
65+
protected void onPostExecute(List<RssItem> result) {
66+
fragment.setListContent(result);
67+
}
68+
}
69+
70+
public void updateListContent() {
71+
if (parseTask == null) {
72+
parseTask = new ParseTask();
73+
parseTask.setFragment(this);
74+
parseTask.execute("http://www.vogella.com/article.rss");
75+
}
76+
}
77+
78+
public void setListContent(List<RssItem> result) {
79+
ArrayAdapter listAdapter = (ArrayAdapter) getListAdapter();
80+
listAdapter.clear();
81+
listAdapter.addAll(result);
82+
parseTask.setFragment(null);
83+
parseTask = null;
84+
}
85+
86+
public void updateDetail(RssItem item) {
87+
DetailFragment fragment = (DetailFragment) getFragmentManager()
88+
.findFragmentById(R.id.detailFragment);
89+
90+
if (fragment != null && fragment.isInLayout()) {
91+
fragment.setText(item.getLink());
92+
} else {
93+
Intent intent = new Intent(getActivity().getApplicationContext(),
94+
DetailActivity.class);
95+
intent.putExtra("value", item.getLink());
96+
startActivity(intent);
97+
}
98+
99+
SharedPreferences prefs = PreferenceManager
100+
.getDefaultSharedPreferences(getActivity());
101+
102+
// Get existing preference
103+
String string = prefs.getString("url", "kdsfkds");
104+
105+
}
106+
}

‎com.example.android.rssfeed/src/com/example/android/rssfeed/RssfeedActivity.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
3232
case R.id.menuitem_refresh:
3333
MyListFragment fragment = (MyListFragment) getFragmentManager()
3434
.findFragmentById(R.id.listFragment);
35-
fragment.updateListContent();
35+
// fragment.updateListContent();
3636
break;
3737
case R.id.menuitem_settings:
3838
Intent intent = new Intent(this, MyPreferenceActivity.class);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.vogella.android.userinterface.undo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.vogella.android.actionbar.undo"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="16"
9+
android:targetSdkVersion="17" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@drawable/ic_launcher"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme" >
16+
<activity
17+
android:name="com.vogella.android.userinterface.undo.MainActivity"
18+
android:label="@string/app_name" >
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
54.4 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)