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 3 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
.utils
.OwnCloudVersion
;
35 import android
.app
.ListActivity
;
36 import android
.os
.Bundle
;
37 import android
.os
.Handler
;
38 import android
.util
.Log
;
39 import android
.widget
.SimpleAdapter
;
41 public class ExtensionsListActivity
extends ListActivity
{
43 private static final String packages_url
= "http://alefzero.eu/a/packages.php";
45 private Thread mGetterThread
;
46 private final Handler mHandler
= new Handler();
49 protected void onCreate(Bundle savedInstanceState
) {
50 super.onCreate(savedInstanceState
);
51 mGetterThread
= new Thread(new JsonGetter());
52 mGetterThread
.start();
55 public void done(JSONArray a
) {
56 LinkedList
<HashMap
<String
, String
>> ll
= new LinkedList
<HashMap
<String
, String
>>();
57 for (int i
= 0; i
< a
.length(); ++i
) {
59 ExtensionApplicationEntry ela
= new ExtensionApplicationEntry(
60 ((JSONObject
) a
.get(i
)));
61 HashMap
<String
, String
> ss
= new HashMap
<String
, String
>();
62 ss
.put("NAME", ela
.getName());
63 ss
.put("DESC", ela
.getDescription());
65 } catch (JSONException e
) {
69 setListAdapter(new SimpleAdapter(this, ll
, R
.layout
.simple_list_item_2
,
70 new String
[] { "NAME", "DESC" }, new int[] {
71 android
.R
.id
.text1
, android
.R
.id
.text2
}));
75 private class JsonGetter
implements Runnable
{
79 HttpClient hc
= new HttpClient();
80 GetMethod gm
= new GetMethod(packages_url
);
84 Log
.e("ASD", gm
.getResponseBodyAsString() + "");
85 ar
= new JSONObject(gm
.getResponseBodyAsString())
86 .getJSONArray("apps");
87 } catch (Exception e
) {
92 mHandler
.post(new Runnable() {
103 private class ExtensionApplicationEntry
{
104 private static final String APP_NAME
= "name";
105 private static final String APP_VERSION
= "version";
106 private static final String APP_DESC
= "description";
107 private static final String APP_ICON
= "icon";
108 private static final String APP_URL
= "download";
109 private static final String APP_PLAYID
= "play_id";
111 private String mName
, mDescription
, mIcon
, mDownload
, mPlayId
;
112 private OwnCloudVersion mVersion
;
114 public ExtensionApplicationEntry(JSONObject appentry
) {
116 mName
= appentry
.getString(APP_NAME
);
117 mDescription
= appentry
.getString(APP_DESC
);
118 mIcon
= appentry
.getString(APP_ICON
);
119 mDownload
= appentry
.getString(APP_URL
);
120 mPlayId
= appentry
.getString(APP_PLAYID
);
121 mVersion
= new OwnCloudVersion(appentry
.getString(APP_VERSION
));
122 } catch (JSONException e
) {
127 public String
getName() {
131 public String
getDescription() {
135 @SuppressWarnings("unused")
136 public String
getIcon() {
140 @SuppressWarnings("unused")
141 public String
getDownload() {
145 @SuppressWarnings("unused")
146 public String
getPlayId() {
150 @SuppressWarnings("unused")
151 public OwnCloudVersion
getVersion() {