1 package eu
.alefzero
.owncloud
.extensions
;
3 import java
.util
.HashMap
;
4 import java
.util
.LinkedList
;
5 import java
.util
.Vector
;
7 import org
.apache
.commons
.httpclient
.HttpClient
;
8 import org
.apache
.commons
.httpclient
.methods
.GetMethod
;
9 import org
.json
.JSONArray
;
10 import org
.json
.JSONException
;
11 import org
.json
.JSONObject
;
13 import eu
.alefzero
.owncloud
.utils
.OwnCloudVersion
;
16 import android
.app
.Activity
;
17 import android
.app
.ListActivity
;
18 import android
.os
.Bundle
;
19 import android
.os
.Handler
;
20 import android
.util
.Log
;
21 import android
.widget
.SimpleAdapter
;
23 public class ExtensionsListActivity
extends ListActivity
{
25 private static final String packages_url
= "http://alefzero.eu/a/packages.php";
27 private Thread mGetterThread
;
28 private final Handler mHandler
= new Handler();
31 protected void onCreate(Bundle savedInstanceState
) {
32 super.onCreate(savedInstanceState
);
33 mGetterThread
= new Thread(new JsonGetter());
34 mGetterThread
.start();
37 public void done(JSONArray a
) {
38 LinkedList
<HashMap
<String
, String
>> ll
= new LinkedList
<HashMap
<String
,String
>>();
39 for (int i
= 0; i
< a
.length(); ++i
) {
41 ExtensionApplicationEntry ela
= new ExtensionApplicationEntry(((JSONObject
)a
.get(i
)));
42 HashMap
<String
, String
> ss
= new HashMap
<String
, String
>();
43 ss
.put("NAME", ela
.getName());
44 ss
.put("DESC", ela
.getDescription());
46 } catch (JSONException e
) {
50 setListAdapter(new SimpleAdapter(this,
52 R
.layout
.simple_list_item_2
,
53 new String
[] {"NAME", "DESC"},
54 new int[] {android
.R
.id
.text1
, android
.R
.id
.text2
}));
58 private class JsonGetter
implements Runnable
{
62 HttpClient hc
= new HttpClient();
63 GetMethod gm
= new GetMethod(packages_url
);
67 Log
.e("ASD", gm
.getResponseBodyAsString()+"");
68 ar
= new JSONObject(gm
.getResponseBodyAsString()).getJSONArray("apps");
69 } catch (Exception e
) {
74 mHandler
.post(new Runnable() {
85 private class ExtensionApplicationEntry
{
86 private static final String APP_NAME
= "name";
87 private static final String APP_VERSION
= "version";
88 private static final String APP_DESC
= "description";
89 private static final String APP_ICON
= "icon";
90 private static final String APP_URL
= "download";
91 private static final String APP_PLAYID
= "play_id";
93 private String mName
, mDescription
, mIcon
, mDownload
, mPlayId
;
94 private OwnCloudVersion mVersion
;
96 public ExtensionApplicationEntry(JSONObject appentry
) {
98 mName
= appentry
.getString(APP_NAME
);
99 mDescription
= appentry
.getString(APP_DESC
);
100 mIcon
= appentry
.getString(APP_ICON
);
101 mDownload
= appentry
.getString(APP_URL
);
102 mPlayId
= appentry
.getString(APP_PLAYID
);
103 mVersion
= new OwnCloudVersion(appentry
.getString(APP_VERSION
));
104 } catch (JSONException e
) {
109 public String
getName() { return mName
; }
110 public String
getDescription() { return mDescription
; }
111 public String
getIcon() { return mIcon
; }
112 public String
getDownload() { return mDownload
; }
113 public String
getPlayId() { return mPlayId
; }
114 public OwnCloudVersion
getVersion() { return mVersion
; }