1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.extensions
;
22 import java
.util
.HashMap
;
23 import java
.util
.LinkedList
;
25 import org
.apache
.commons
.httpclient
.HttpClient
;
26 import org
.apache
.commons
.httpclient
.methods
.GetMethod
;
27 import org
.json
.JSONArray
;
28 import org
.json
.JSONException
;
29 import org
.json
.JSONObject
;
31 import com
.owncloud
.android
.Log_OC
;
32 import com
.owncloud
.android
.utils
.OwnCloudVersion
;
36 import android
.app
.ListActivity
;
37 import android
.os
.Bundle
;
38 import android
.os
.Handler
;
39 import android
.util
.Log
;
40 import android
.widget
.SimpleAdapter
;
42 public class ExtensionsListActivity
extends ListActivity
{
44 private static final String packages_url
= "http://alefzero.eu/a/packages.php";
46 private Thread mGetterThread
;
47 private final Handler mHandler
= new Handler();
50 protected void onCreate(Bundle savedInstanceState
) {
51 super.onCreate(savedInstanceState
);
52 mGetterThread
= new Thread(new JsonGetter());
53 mGetterThread
.start();
56 public void done(JSONArray a
) {
57 LinkedList
<HashMap
<String
, String
>> ll
= new LinkedList
<HashMap
<String
, String
>>();
58 for (int i
= 0; i
< a
.length(); ++i
) {
60 ExtensionApplicationEntry ela
= new ExtensionApplicationEntry(
61 ((JSONObject
) a
.get(i
)));
62 HashMap
<String
, String
> ss
= new HashMap
<String
, String
>();
63 ss
.put("NAME", ela
.getName());
64 ss
.put("DESC", ela
.getDescription());
66 } catch (JSONException e
) {
70 setListAdapter(new SimpleAdapter(this, ll
, R
.layout
.simple_list_item_2
,
71 new String
[] { "NAME", "DESC" }, new int[] {
72 android
.R
.id
.text1
, android
.R
.id
.text2
}));
76 private class JsonGetter
implements Runnable
{
80 HttpClient hc
= new HttpClient();
81 GetMethod gm
= new GetMethod(packages_url
);
85 Log_OC
.e("ASD", gm
.getResponseBodyAsString() + "");
86 ar
= new JSONObject(gm
.getResponseBodyAsString())
87 .getJSONArray("apps");
88 } catch (Exception e
) {
93 mHandler
.post(new Runnable() {
104 private class ExtensionApplicationEntry
{
105 private static final String APP_NAME
= "name";
106 private static final String APP_VERSION
= "version";
107 private static final String APP_DESC
= "description";
108 private static final String APP_ICON
= "icon";
109 private static final String APP_URL
= "download";
110 private static final String APP_PLAYID
= "play_id";
112 private String mName
, mDescription
, mIcon
, mDownload
, mPlayId
;
113 private OwnCloudVersion mVersion
;
115 public ExtensionApplicationEntry(JSONObject appentry
) {
117 mName
= appentry
.getString(APP_NAME
);
118 mDescription
= appentry
.getString(APP_DESC
);
119 mIcon
= appentry
.getString(APP_ICON
);
120 mDownload
= appentry
.getString(APP_URL
);
121 mPlayId
= appentry
.getString(APP_PLAYID
);
122 mVersion
= new OwnCloudVersion(appentry
.getString(APP_VERSION
));
123 } catch (JSONException e
) {
128 public String
getName() {
132 public String
getDescription() {
136 @SuppressWarnings("unused")
137 public String
getIcon() {
141 @SuppressWarnings("unused")
142 public String
getDownload() {
146 @SuppressWarnings("unused")
147 public String
getPlayId() {
151 @SuppressWarnings("unused")
152 public OwnCloudVersion
getVersion() {