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(
42 ((JSONObject
) a
.get(i
)));
43 HashMap
<String
, String
> ss
= new HashMap
<String
, String
>();
44 ss
.put("NAME", ela
.getName());
45 ss
.put("DESC", ela
.getDescription());
47 } catch (JSONException e
) {
51 setListAdapter(new SimpleAdapter(this, ll
, R
.layout
.simple_list_item_2
,
52 new String
[] { "NAME", "DESC" }, new int[] {
53 android
.R
.id
.text1
, android
.R
.id
.text2
}));
57 private class JsonGetter
implements Runnable
{
61 HttpClient hc
= new HttpClient();
62 GetMethod gm
= new GetMethod(packages_url
);
66 Log
.e("ASD", gm
.getResponseBodyAsString() + "");
67 ar
= new JSONObject(gm
.getResponseBodyAsString())
68 .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() {
113 public String
getDescription() {
117 public String
getIcon() {
121 public String
getDownload() {
125 public String
getPlayId() {
129 public OwnCloudVersion
getVersion() {