1 package com
.owncloud
.android
.extensions
;
3 import java
.util
.HashMap
;
4 import java
.util
.LinkedList
;
6 import org
.apache
.commons
.httpclient
.HttpClient
;
7 import org
.apache
.commons
.httpclient
.methods
.GetMethod
;
8 import org
.json
.JSONArray
;
9 import org
.json
.JSONException
;
10 import org
.json
.JSONObject
;
12 import com
.owncloud
.android
.utils
.OwnCloudVersion
;
16 import android
.app
.ListActivity
;
17 import android
.os
.Bundle
;
18 import android
.os
.Handler
;
19 import android
.util
.Log
;
20 import android
.widget
.SimpleAdapter
;
22 public class ExtensionsListActivity
extends ListActivity
{
24 private static final String packages_url
= "http://alefzero.eu/a/packages.php";
26 private Thread mGetterThread
;
27 private final Handler mHandler
= new Handler();
30 protected void onCreate(Bundle savedInstanceState
) {
31 super.onCreate(savedInstanceState
);
32 mGetterThread
= new Thread(new JsonGetter());
33 mGetterThread
.start();
36 public void done(JSONArray a
) {
37 LinkedList
<HashMap
<String
, String
>> ll
= new LinkedList
<HashMap
<String
, String
>>();
38 for (int i
= 0; i
< a
.length(); ++i
) {
40 ExtensionApplicationEntry ela
= new ExtensionApplicationEntry(
41 ((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, ll
, R
.layout
.simple_list_item_2
,
51 new String
[] { "NAME", "DESC" }, new int[] {
52 android
.R
.id
.text1
, android
.R
.id
.text2
}));
56 private class JsonGetter
implements Runnable
{
60 HttpClient hc
= new HttpClient();
61 GetMethod gm
= new GetMethod(packages_url
);
65 Log
.e("ASD", gm
.getResponseBodyAsString() + "");
66 ar
= new JSONObject(gm
.getResponseBodyAsString())
67 .getJSONArray("apps");
68 } catch (Exception e
) {
73 mHandler
.post(new Runnable() {
84 private class ExtensionApplicationEntry
{
85 private static final String APP_NAME
= "name";
86 private static final String APP_VERSION
= "version";
87 private static final String APP_DESC
= "description";
88 private static final String APP_ICON
= "icon";
89 private static final String APP_URL
= "download";
90 private static final String APP_PLAYID
= "play_id";
92 private String mName
, mDescription
, mIcon
, mDownload
, mPlayId
;
93 private OwnCloudVersion mVersion
;
95 public ExtensionApplicationEntry(JSONObject appentry
) {
97 mName
= appentry
.getString(APP_NAME
);
98 mDescription
= appentry
.getString(APP_DESC
);
99 mIcon
= appentry
.getString(APP_ICON
);
100 mDownload
= appentry
.getString(APP_URL
);
101 mPlayId
= appentry
.getString(APP_PLAYID
);
102 mVersion
= new OwnCloudVersion(appentry
.getString(APP_VERSION
));
103 } catch (JSONException e
) {
108 public String
getName() {
112 public String
getDescription() {
116 @SuppressWarnings("unused")
117 public String
getIcon() {
121 @SuppressWarnings("unused")
122 public String
getDownload() {
126 @SuppressWarnings("unused")
127 public String
getPlayId() {
131 @SuppressWarnings("unused")
132 public OwnCloudVersion
getVersion() {