1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package org.linaro.connect;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
public class PostingsActivity extends Activity {
private PostingsAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = getIntent();
String label = i.getStringExtra(JSONLayoutItem.INTENT_LABEL);
String title = getTitle() + " - " + label;
setTitle(title);
ListView lv = (ListView) findViewById(R.id.connect_items);
mAdapter = new PostingsAdapter(label);
lv.setAdapter(mAdapter);
lv.setOnItemClickListener(mClickListener);
}
@Override
protected void onResume() {
super.onResume();
mAdapter.refresh(false);
}
private class PostingsAdapter extends CachedJSONLayoutAdapter {
private final static long INTERVAL = 1000*60*10; //check every 10 minutes
PostingsAdapter(String label) {
super(getApplicationContext(), R.layout.posting_item, R.id.posting_item_title);
setRefreshInterval(INTERVAL);
setCacheFileName("postings.json." + label);
setJSONUrl(getIntent().getDataString());
}
@Override
protected void updateLayout(JSONObject jso) {
clear();
if(jso == null)
return;
try {
JSONArray postings = jso.getJSONArray("postings");
for(int i = 0; i < postings.length() && !postings.isNull(i); i++) {
add(new JSONPostingItem(postings.getJSONObject(i)));
}
}
catch(JSONException e) {
Log.e(LinaroConnect.TAG, "Error accessing JSON posting", e);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
TextView tv = (TextView)v.findViewById(R.id.posting_item_summary);
JSONPostingItem jso = (JSONPostingItem)getItem(position);
tv.setText(jso.getSummary());
return v;
}
@Override
protected void onBusy(boolean busy) {
setProgressBarIndeterminateVisibility(busy);
}
}
private final OnItemClickListener mClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int pos, long id)
{
JSONPostingItem jsi = (JSONPostingItem)mAdapter.getItem(pos);
if( jsi != null ) {
startActivityForResult(jsi.getIntent(), 0);
}
}
};
}
|