1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.extensions
;
21 import java
.util
.HashMap
;
22 import java
.util
.LinkedList
;
24 import org
.apache
.commons
.httpclient
.HttpClient
;
25 import org
.apache
.commons
.httpclient
.methods
.GetMethod
;
26 import org
.json
.JSONArray
;
27 import org
.json
.JSONException
;
28 import org
.json
.JSONObject
;
30 import com
.owncloud
.android
.utils
.OwnCloudVersion
;
34 import android
.app
.ListActivity
;
35 import android
.os
.Bundle
;
36 import android
.os
.Handler
;
37 import android
.util
.Log
;
38 import android
.widget
.SimpleAdapter
;
40 public class ExtensionsListActivity
extends ListActivity
{
42 private static final String packages_url
= "http://alefzero.eu/a/packages.php";
44 private Thread mGetterThread
;
45 private final Handler mHandler
= new Handler();
48 protected void onCreate(Bundle savedInstanceState
) {
49 super.onCreate(savedInstanceState
);
50 mGetterThread
= new Thread(new JsonGetter());
51 mGetterThread
.start();
54 public void done(JSONArray a
) {
55 LinkedList
<HashMap
<String
, String
>> ll
= new LinkedList
<HashMap
<String
, String
>>();
56 for (int i
= 0; i
< a
.length(); ++i
) {
58 ExtensionApplicationEntry ela
= new ExtensionApplicationEntry(
59 ((JSONObject
) a
.get(i
)));
60 HashMap
<String
, String
> ss
= new HashMap
<String
, String
>();
61 ss
.put("NAME", ela
.getName());
62 ss
.put("DESC", ela
.getDescription());
64 } catch (JSONException e
) {
68 setListAdapter(new SimpleAdapter(this, ll
, R
.layout
.simple_list_item_2
,
69 new String
[] { "NAME", "DESC" }, new int[] {
70 android
.R
.id
.text1
, android
.R
.id
.text2
}));
74 private class JsonGetter
implements Runnable
{
78 HttpClient hc
= new HttpClient();
79 GetMethod gm
= new GetMethod(packages_url
);
83 Log
.e("ASD", gm
.getResponseBodyAsString() + "");
84 ar
= new JSONObject(gm
.getResponseBodyAsString())
85 .getJSONArray("apps");
86 } catch (Exception e
) {
91 mHandler
.post(new Runnable() {
102 private class ExtensionApplicationEntry
{
103 private static final String APP_NAME
= "name";
104 private static final String APP_VERSION
= "version";
105 private static final String APP_DESC
= "description";
106 private static final String APP_ICON
= "icon";
107 private static final String APP_URL
= "download";
108 private static final String APP_PLAYID
= "play_id";
110 private String mName
, mDescription
, mIcon
, mDownload
, mPlayId
;
111 private OwnCloudVersion mVersion
;
113 public ExtensionApplicationEntry(JSONObject appentry
) {
115 mName
= appentry
.getString(APP_NAME
);
116 mDescription
= appentry
.getString(APP_DESC
);
117 mIcon
= appentry
.getString(APP_ICON
);
118 mDownload
= appentry
.getString(APP_URL
);
119 mPlayId
= appentry
.getString(APP_PLAYID
);
120 mVersion
= new OwnCloudVersion(appentry
.getString(APP_VERSION
));
121 } catch (JSONException e
) {
126 public String
getName() {
130 public String
getDescription() {
134 @SuppressWarnings("unused")
135 public String
getIcon() {
139 @SuppressWarnings("unused")
140 public String
getDownload() {
144 @SuppressWarnings("unused")
145 public String
getPlayId() {
149 @SuppressWarnings("unused")
150 public OwnCloudVersion
getVersion() {