Revision d37efce5
b/res/layout/versionsrow.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="wrap_content" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<TextView |
|
8 |
android:id="@+id/versionName" |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="wrap_content" |
|
11 |
android:layout_weight="1" |
|
12 |
android:gravity="fill_horizontal" |
|
13 |
android:paddingLeft="8dip" |
|
14 |
android:textStyle="normal" /> |
|
15 |
|
|
16 |
<TextView |
|
17 |
android:id="@+id/versionSize" |
|
18 |
android:layout_width="fill_parent" |
|
19 |
android:layout_height="wrap_content" |
|
20 |
android:layout_weight="1" |
|
21 |
android:gravity="fill_horizontal" |
|
22 |
android:paddingLeft="8dip" |
|
23 |
android:textStyle="normal" /> |
|
24 |
|
|
25 |
<TextView |
|
26 |
android:id="@+id/versionCreation" |
|
27 |
android:layout_width="fill_parent" |
|
28 |
android:layout_height="wrap_content" |
|
29 |
android:layout_weight="1" |
|
30 |
android:gravity="fill_horizontal" |
|
31 |
android:paddingLeft="8dip" |
|
32 |
android:textStyle="normal" /> |
|
33 |
|
|
34 |
<TextView |
|
35 |
android:id="@+id/versionModified" |
|
36 |
android:layout_width="fill_parent" |
|
37 |
android:layout_height="wrap_content" |
|
38 |
android:layout_weight="1" |
|
39 |
android:gravity="fill_horizontal" |
|
40 |
android:paddingLeft="8dip" |
|
41 |
android:textStyle="normal" /> |
|
42 |
|
|
43 |
<RelativeLayout |
|
44 |
android:layout_width="fill_parent" |
|
45 |
android:layout_height="wrap_content" > |
|
46 |
|
|
47 |
<Button |
|
48 |
android:id="@+id/vdownload" |
|
49 |
android:layout_width="wrap_content" |
|
50 |
android:layout_height="wrap_content" |
|
51 |
android:text="Download" /> |
|
52 |
|
|
53 |
<Button |
|
54 |
android:id="@+id/vrestore" |
|
55 |
android:layout_width="wrap_content" |
|
56 |
android:layout_height="wrap_content" |
|
57 |
android:layout_toRightOf="@id/vdownload" |
|
58 |
android:text="Restore" /> |
|
59 |
<!-- |
|
60 |
<Button android:id="@+id/vremove" android:text="Remove" |
|
61 |
android:textColor="#DDDD" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/vrestore"/> |
|
62 |
--> |
|
63 |
</RelativeLayout> |
|
64 |
|
|
65 |
<LinearLayout |
|
66 |
android:id="@+id/horizontalLine" |
|
67 |
android:layout_width="fill_parent" |
|
68 |
android:layout_height="2dip" |
|
69 |
android:background="#444444" /> |
|
70 |
|
|
71 |
</LinearLayout> |
b/res/layout/viewobject.xml | ||
---|---|---|
299 | 299 |
<TextView |
300 | 300 |
android:layout_width="wrap_content" |
301 | 301 |
android:layout_height="wrap_content" |
302 |
android:layout_marginLeft="20dip" |
|
303 |
android:layout_marginRight="20dip" |
|
304 |
android:gravity="center" |
|
305 |
android:text="Files will be downloaded to the RackspaceCloud/ directory of your device's external storage." > |
|
306 |
</TextView> |
|
302 |
android:layout_marginTop="10dip" |
|
303 |
android:paddingTop="3dip" |
|
304 |
android:text="Versions List" |
|
305 |
android:textSize="16px" |
|
306 |
android:textStyle="bold" /> |
|
307 |
|
|
308 |
<LinearLayout |
|
309 |
android:id="@+id/versionsList" |
|
310 |
android:layout_width="fill_parent" |
|
311 |
android:layout_height="fill_parent" |
|
312 |
android:orientation="vertical" |
|
313 |
android:paddingLeft="3dip" |
|
314 |
android:paddingRight="3dip" > |
|
315 |
</LinearLayout> |
|
307 | 316 |
</LinearLayout> |
308 | 317 |
</ScrollView> |
309 | 318 |
</FrameLayout> |
b/src/com/rackspace/cloud/android/ContainerObjectDetails.java | ||
---|---|---|
5 | 5 |
import java.io.FileNotFoundException; |
6 | 6 |
import java.io.FileOutputStream; |
7 | 7 |
import java.io.IOException; |
8 |
import java.util.ArrayList; |
|
8 | 9 |
import java.util.Iterator; |
10 |
import java.util.List; |
|
9 | 11 |
import java.util.Map.Entry; |
10 | 12 |
|
11 | 13 |
import org.apache.http.HttpEntity; |
... | ... | |
32 | 34 |
import android.widget.CheckBox; |
33 | 35 |
import android.widget.CompoundButton; |
34 | 36 |
import android.widget.CompoundButton.OnCheckedChangeListener; |
37 |
import android.widget.ArrayAdapter; |
|
35 | 38 |
import android.widget.LinearLayout; |
36 | 39 |
import android.widget.TabHost; |
37 | 40 |
import android.widget.TextView; |
... | ... | |
39 | 42 |
|
40 | 43 |
import com.rackspace.cloud.files.api.client.ContainerObjectManager; |
41 | 44 |
import com.rackspace.cloud.files.api.client.ContainerObjects; |
45 |
import com.rackspace.cloud.files.api.client.ObjectVersion; |
|
42 | 46 |
import com.rackspace.cloud.files.api.client.Permission; |
43 | 47 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
44 | 48 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
... | ... | |
69 | 73 |
private AndroidCloudApplication app; |
70 | 74 |
private DeleteObjectListenerTask deleteObjTask; |
71 | 75 |
private DownloadObjectListenerTask downloadObjTask; |
76 |
private List<ObjectVersion> versions=new ArrayList<ObjectVersion>(); |
|
72 | 77 |
|
73 | 78 |
/** Called when the activity is first created. */ |
74 | 79 |
@Override |
... | ... | |
215 | 220 |
lastmod.setText(strDate); |
216 | 221 |
rebuildMetadataList(); |
217 | 222 |
rebuildPermissionList(); |
223 |
try { |
|
224 |
versions = new ContainerObjectManager(getApplicationContext()).getObjectVersions(objects.getContainerName(), objects.getCName()); |
|
225 |
rebuildVersionList(); |
|
226 |
} catch (CloudServersException e) { |
|
227 |
// TODO Auto-generated catch block |
|
228 |
e.printStackTrace(); |
|
229 |
} |
|
218 | 230 |
} |
219 | 231 |
|
220 | 232 |
private void rebuildMetadataList(){ |
... | ... | |
301 | 313 |
}); |
302 | 314 |
} |
303 | 315 |
|
316 |
private void rebuildVersionList() { |
|
317 |
LayoutInflater layoutInflater = LayoutInflater.from(ContainerObjectDetails.this); |
|
318 |
final LinearLayout properties = (LinearLayout) findViewById(R.id.versionsList); |
|
319 |
if (properties.getChildCount() > 0) |
|
320 |
properties.removeViews(0, properties.getChildCount()); |
|
321 |
properties.removeAllViews(); |
|
322 |
Iterator<ObjectVersion> it; |
|
323 |
//Collections.reverse(versions); |
|
324 |
it = versions.iterator(); |
|
325 |
int i = 0; |
|
326 |
while (it.hasNext()) { |
|
327 |
final ObjectVersion perm = it.next(); |
|
328 |
final View v = layoutInflater.inflate(R.layout.versionsrow, null); |
|
329 |
populateVersionList(perm, v, properties, i); |
|
330 |
i++; |
|
331 |
} |
|
332 |
} |
|
333 |
|
|
334 |
private void populateVersionList(final ObjectVersion perm, final View v, |
|
335 |
final LinearLayout properties, int i) { |
|
336 |
|
|
337 |
properties.addView(v, i); |
|
338 |
|
|
339 |
((TextView) v.findViewById(R.id.versionName)).setText("Version: " |
|
340 |
+ perm.getVersion()); |
|
341 |
|
|
342 |
((TextView) v.findViewById(R.id.versionModified)).setText("Modified: " |
|
343 |
+ perm.getDateString()); |
|
344 |
if(versions.size()==1){ |
|
345 |
//((Button) v.findViewById(R.id.vremove)).setVisibility(View.INVISIBLE); |
|
346 |
((Button) v.findViewById(R.id.vrestore)).setVisibility(View.INVISIBLE); |
|
347 |
} |
|
348 |
/* |
|
349 |
((Button) v.findViewById(R.id.vremove)) |
|
350 |
.setOnClickListener(new OnClickListener() { |
|
351 |
|
|
352 |
@Override |
|
353 |
public void onClick(View v1) { |
|
354 |
Log.d("PERMS", perm.getUri()); |
|
355 |
try { |
|
356 |
new GssHttpCommands(getDroidApplication() |
|
357 |
.getUserDetails()).deleteFolder(perm.getUri()+"?version="+perm.getVersion()); |
|
358 |
} catch (SystemErrorException e) { |
|
359 |
// TODO Auto-generated catch block |
|
360 |
e.printStackTrace(); |
|
361 |
} catch (GssHttpException e) { |
|
362 |
// TODO Auto-generated catch block |
|
363 |
e.printStackTrace(); |
|
364 |
} |
|
365 |
getFileTask().execute(res.getUri()); |
|
366 |
//properties.removeView(v); |
|
367 |
|
|
368 |
} |
|
369 |
});*/ |
|
370 |
((Button) v.findViewById(R.id.vrestore)) |
|
371 |
.setOnClickListener(new OnClickListener() { |
|
372 |
|
|
373 |
@Override |
|
374 |
public void onClick(View v1) { |
|
375 |
//Log.d("PERMS", perm.getUri()); |
|
376 |
//geRestoreVersionTask().execute(perm.getUri()+"?restoreVersion="+perm.getVersion()); |
|
377 |
|
|
378 |
} |
|
379 |
}); |
|
380 |
((Button) v.findViewById(R.id.vdownload)) |
|
381 |
.setOnClickListener(new OnClickListener() { |
|
382 |
|
|
383 |
@Override |
|
384 |
public void onClick(View v1) { |
|
385 |
|
|
386 |
//getDownloadTask().execute(perm.getUri()+"?version="+perm.getVersion()); |
|
387 |
//properties.removeView(v); |
|
388 |
|
|
389 |
} |
|
390 |
}); |
|
391 |
} |
|
392 |
|
|
304 | 393 |
|
305 | 394 |
private class MyOnClickListener implements View.OnClickListener { |
306 | 395 |
@Override |
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java | ||
---|---|---|
33 | 33 |
import android.util.Log; |
34 | 34 |
|
35 | 35 |
import com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser; |
36 |
import com.rackspace.cloud.files.api.client.parsers.ObjectVersionXMLParser; |
|
36 | 37 |
import com.rackspace.cloud.servers.api.client.Account; |
37 | 38 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
38 | 39 |
import com.rackspace.cloud.servers.api.client.EntityManager; |
... | ... | |
250 | 251 |
|
251 | 252 |
} |
252 | 253 |
|
254 |
public List<ObjectVersion> getObjectVersions(String Container, String Object) |
|
255 |
throws CloudServersException { |
|
256 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
|
257 |
String url = Account.getAccount().getStorageUrl()+"/"+ Container |
|
258 |
+ "/" + Object+"?format=xml&version=list"; |
|
259 |
Log.i("papala",url); |
|
260 |
HttpGet get = new HttpGet(url); |
|
261 |
List<ObjectVersion> versions =null; |
|
262 |
get.addHeader("Content-Type", "application/xml"); |
|
263 |
get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken); |
|
264 |
|
|
265 |
try { |
|
266 |
HttpResponse resp = httpclient.execute(get); |
|
267 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
|
268 |
String body = responseHandler.handleResponse(resp); |
|
269 |
|
|
270 |
if (resp.getStatusLine().getStatusCode() == 200 |
|
271 |
|| resp.getStatusLine().getStatusCode() == 203) { |
|
272 |
ObjectVersionXMLParser filesXMLParser = new ObjectVersionXMLParser(); |
|
273 |
SAXParser saxParser = SAXParserFactory.newInstance() |
|
274 |
.newSAXParser(); |
|
275 |
XMLReader xmlReader = saxParser.getXMLReader(); |
|
276 |
xmlReader.setContentHandler(filesXMLParser); |
|
277 |
|
|
278 |
xmlReader.parse(new InputSource(new StringReader(body))); |
|
279 |
versions = filesXMLParser.getContainers(); |
|
280 |
|
|
281 |
|
|
282 |
} else { |
|
283 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser(); |
|
284 |
SAXParser saxParser = SAXParserFactory.newInstance() |
|
285 |
.newSAXParser(); |
|
286 |
XMLReader xmlReader = saxParser.getXMLReader(); |
|
287 |
xmlReader.setContentHandler(parser); |
|
288 |
xmlReader.parse(new InputSource(new StringReader(body))); |
|
289 |
CloudServersException cse = parser.getException(); |
|
290 |
throw cse; |
|
291 |
} |
|
292 |
} catch (ClientProtocolException e) { |
|
293 |
CloudServersException cse = new CloudServersException(); |
|
294 |
cse.setMessage(e.getLocalizedMessage()); |
|
295 |
throw cse; |
|
296 |
} catch (IOException e) { |
|
297 |
CloudServersException cse = new CloudServersException(); |
|
298 |
cse.setMessage(e.getLocalizedMessage()); |
|
299 |
throw cse; |
|
300 |
} catch (ParserConfigurationException e) { |
|
301 |
CloudServersException cse = new CloudServersException(); |
|
302 |
cse.setMessage(e.getLocalizedMessage()); |
|
303 |
throw cse; |
|
304 |
} catch (SAXException e) { |
|
305 |
CloudServersException cse = new CloudServersException(); |
|
306 |
cse.setMessage(e.getLocalizedMessage()); |
|
307 |
throw cse; |
|
308 |
} catch (FactoryConfigurationError e) { |
|
309 |
CloudServersException cse = new CloudServersException(); |
|
310 |
cse.setMessage(e.getLocalizedMessage()); |
|
311 |
throw cse; |
|
312 |
} |
|
313 |
return versions; |
|
314 |
} |
|
315 |
|
|
253 | 316 |
public ArrayList<ContainerObjects> createListMyShared(boolean detail, |
254 | 317 |
String passName, List<Container> containers) throws CloudServersException { |
255 | 318 |
|
... | ... | |
342 | 405 |
} |
343 | 406 |
return bundle; |
344 | 407 |
} |
408 |
|
|
409 |
|
|
345 | 410 |
|
346 | 411 |
public HttpBundle addObject(String Container, String Path, String Object, |
347 | 412 |
String type) throws CloudServersException { |
b/src/com/rackspace/cloud/files/api/client/ObjectVersion.java | ||
---|---|---|
1 |
package com.rackspace.cloud.files.api.client; |
|
2 |
|
|
3 |
import java.text.SimpleDateFormat; |
|
4 |
import java.util.Date; |
|
5 |
|
|
6 |
public class ObjectVersion { |
|
7 |
String name; |
|
8 |
String timestamp; |
|
9 |
int version; |
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
public String getName() { |
|
14 |
return name; |
|
15 |
} |
|
16 |
public void setName(String name) { |
|
17 |
this.name = name; |
|
18 |
} |
|
19 |
public String getTimestamp() { |
|
20 |
return timestamp; |
|
21 |
} |
|
22 |
public void setTimestamp(String timestamp) { |
|
23 |
this.timestamp = timestamp; |
|
24 |
} |
|
25 |
public int getVersion() { |
|
26 |
return version; |
|
27 |
} |
|
28 |
public void setVersion(int version) { |
|
29 |
this.version = version; |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
public Date getVersionDate(){ |
|
34 |
return new Date((long) (Double.parseDouble(getTimestamp()) * 1000)); |
|
35 |
} |
|
36 |
|
|
37 |
public String getDateString(){ |
|
38 |
SimpleDateFormat formatter = new SimpleDateFormat("d/M/yyyy h:mm a"); |
|
39 |
return formatter.format(getVersionDate()); |
|
40 |
} |
|
41 |
|
|
42 |
} |
b/src/com/rackspace/cloud/files/api/client/parsers/ObjectVersionXMLParser.java | ||
---|---|---|
1 |
package com.rackspace.cloud.files.api.client.parsers; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
|
|
5 |
import org.xml.sax.Attributes; |
|
6 |
import org.xml.sax.helpers.DefaultHandler; |
|
7 |
|
|
8 |
import android.util.Log; |
|
9 |
|
|
10 |
import com.rackspace.cloud.files.api.client.ObjectVersion; |
|
11 |
|
|
12 |
public class ObjectVersionXMLParser extends DefaultHandler { |
|
13 |
|
|
14 |
|
|
15 |
private ArrayList<ObjectVersion> containers; |
|
16 |
ObjectVersion version; |
|
17 |
|
|
18 |
private StringBuffer currentData; |
|
19 |
|
|
20 |
public void startElement(String uri, String name, String qName, |
|
21 |
Attributes atts) { |
|
22 |
|
|
23 |
currentData = new StringBuffer(); |
|
24 |
if("object".equals(name)){ |
|
25 |
containers = new ArrayList<ObjectVersion>(); |
|
26 |
} |
|
27 |
if ("version".equals(name)) { |
|
28 |
version = new ObjectVersion(); |
|
29 |
version.setTimestamp(atts.getValue("timestamp")); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
public void endElement(String uri, String name, String qName) { |
|
34 |
|
|
35 |
String value = currentData.toString().trim(); |
|
36 |
|
|
37 |
if ("object".equals(name)) { |
|
38 |
|
|
39 |
} else if ("version".equals(name)) { |
|
40 |
version.setVersion(Integer.parseInt(value)); |
|
41 |
Log.i("papala","parsed:"+version.getVersion()+" "+version.getTimestamp()); |
|
42 |
containers.add(version); |
|
43 |
} |
|
44 |
|
|
45 |
} |
|
46 |
|
|
47 |
public void characters(char ch[], int start, int length) { |
|
48 |
|
|
49 |
// Log.d("Rackspace-Cloud", "Characters: \""); |
|
50 |
|
|
51 |
for (int i = start; i < start + length; i++) { |
|
52 |
switch (ch[i]) { |
|
53 |
case '\\': |
|
54 |
// Log.d("Rackspace-Cloud", "\\\\"); |
|
55 |
break; |
|
56 |
case '"': |
|
57 |
// Log.d("Rackspace-Cloud", "\\\""); |
|
58 |
break; |
|
59 |
case '\n': |
|
60 |
// Log.d("Rackspace-Cloud", "\\n"); |
|
61 |
break; |
|
62 |
case '\r': |
|
63 |
// Log.d("Rackspace-Cloud", "\\r"); |
|
64 |
break; |
|
65 |
case '\t': |
|
66 |
// Log.d("Rackspace-Cloud", "\\t"); |
|
67 |
break; |
|
68 |
default: |
|
69 |
// Log.d("Rackspace-Cloud", String.valueOf(ch[i])); |
|
70 |
break; |
|
71 |
} |
|
72 |
} |
|
73 |
// Log.d("Rackspace-Cloud", "\"\n"); |
|
74 |
|
|
75 |
for (int i = start; i < (start + length); i++) { |
|
76 |
currentData.append(ch[i]); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
/** |
|
82 |
* @return the files |
|
83 |
*/ |
|
84 |
public ArrayList<ObjectVersion> getContainers() { |
|
85 |
return containers; |
|
86 |
} |
|
87 |
|
|
88 |
} |
Also available in: Unified diff