Revision 856ad13d

b/AndroidManifest.xml
65 65
				<category android:name="android.intent.category.APPLICATION" />
66 66
			</intent-filter>
67 67
		</activity>
68
		<activity android:name=".PithosMySharedActivity"
69
			android:label="@string/app_name">
70
			<intent-filter>
71
				<action android:name="android.intent.action.MAIN" />
72
				<category android:name="android.intent.category.APPLICATION" />
73
			</intent-filter>
74
		</activity>
75
		<activity android:name=".PithosOthersActivity"
76
			android:label="@string/app_name">
77
			<intent-filter>
78
				<action android:name="android.intent.action.MAIN" />
79
				<category android:name="android.intent.category.APPLICATION" />
80
			</intent-filter>
81
		</activity>
82
		<activity android:name=".PithosGroupsActivity"
83
			android:label="@string/app_name">
84
			<intent-filter>
85
				<action android:name="android.intent.action.MAIN" />
86
				<category android:name="android.intent.category.APPLICATION" />
87
			</intent-filter>
88
		</activity>
68 89
		<activity android:name=".ContainerObjectDetails"
69 90
			android:label="@string/app_name">
70 91
			<intent-filter>
b/res/layout/groups.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
	android:layout_width="wrap_content" android:layout_height="wrap_content"
4
	android:orientation="vertical" >
5
	<RelativeLayout android:layout_width="fill_parent"
6
		android:layout_height="wrap_content" android:id="@+id/top_control_bar">
7
		<TextView android:layout_width="wrap_content"  
8
		android:layout_height="wrap_content" android:id="@+id/textPath"
9
		android:text="" android:textSize="20px"></TextView>
10
	</RelativeLayout>
11
	<RelativeLayout  android:id="@+id/bottom_control_bar"
12
		android:layout_width="fill_parent" android:layout_height="wrap_content"
13
		android:layout_alignParentBottom="true" android:background="#DDDDDD"
14
		>
15
		<!-- 
16
		<ImageButton android:id="@+id/newBottomItem"
17
		android:layout_width="wrap_content" 
18
		android:layout_height="wrap_content"
19
		
20
		
21
		android:src="@drawable/add"
22
		/>
23
		
24
		
25
		<ImageButton
26
android:id="@+id/refreshFolder"
27
android:layout_alignParentRight="true"
28
android:layout_width="wrap_content" 
29
		android:layout_height="wrap_content"
30
		
31
		
32
	android:src="@drawable/refresh"/>
33
		 -->
34
	</RelativeLayout>
35
	
36
	<com.rackspace.cloud.android.widget.GroupsListView
37
		android:id="@+id/groupsListView"
38
		android:layout_width="fill_parent"
39
		android:layout_height="0dip"
40
		android:layout_below="@id/top_control_bar" android:layout_above="@id/bottom_control_bar"
41
		></com.rackspace.cloud.android.widget.GroupsListView>
42
	
43
	<!-- <TextView android:id="@android:id/empty" android:layout_width="wrap_content"
44
		android:layout_height="wrap_content" android:text="@string/main_empty_list"
45
		android:layout_below="@id/top_control_bar" android:layout_above="@id/bottom_control_bar" />
46
		 -->
47
</RelativeLayout>
48

  
b/res/layout/groupsrow.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout
3
    xmlns:android="http://schemas.android.com/apk/res/android"
4
    android:layout_width="fill_parent"
5
    android:layout_height="wrap_content"
6
    android:orientation="horizontal"
7
        android:paddingLeft="20dip"
8
        
9
    >
10
<LinearLayout
11
        xmlns:android="http://schemas.android.com/apk/res/android"
12
        android:id="@+id/batch_button_area"
13
        android:layout_width="fill_parent"
14
        android:layout_height="wrap_content"
15
        android:orientation="horizontal"
16
        android:paddingLeft="10dip"
17
        android:paddingTop="3dip"
18
        android:paddingBottom="3dip"
19
        >
20
    <ImageView
21
        android:id="@+id/image"
22
        android:layout_width="24dip"
23
		android:layout_height="24dip"
24
		android:scaleType="fitXY"
25
		android:gravity="center|center"
26
		android:layout_marginLeft="5dip"
27
		android:layout_marginTop="5dip"/>
28

  
29
    <TextView
30
        android:id="@+id/name"
31
        android:layout_width="wrap_content"
32
        android:layout_height="wrap_content"
33
        android:layout_gravity="right|center_vertical" 
34
        android:layout_marginLeft="5dip"
35
        />
36
</LinearLayout>
37
</RelativeLayout>
b/src/com/rackspace/cloud/android/AndroidCloudApplication.java
1 1
package com.rackspace.cloud.android;
2 2

  
3 3
import java.util.ArrayList;
4
import java.util.List;
4 5

  
5 6
import org.apache.http.HttpEntity;
6 7

  
7 8
import com.rackspace.cloud.files.api.client.ContainerObjects;
9
import com.rackspace.cloud.files.api.client.GroupResource;
8 10

  
9 11
import android.app.Application;
10 12

  
......
24 26
	private boolean isSettingSessionPersistence;
25 27
	private HttpEntity downloadedObject;
26 28
	private ArrayList<ContainerObjects> curDirFiles;
29
	private List<GroupResource> groups = new ArrayList<GroupResource>();
30
	private List<String> others = new ArrayList<String>();
27 31
	public static long lastPause;
28 32
	
33
	public List<String> getOthers() {
34
		return others;
35
	}
36
	
37
	public void setOthers(List<String> others) {
38
		this.others = others;
39
	}
40
	
41
	public List<GroupResource> getGroups() {
42
		return groups;
43
	}
44
	
45
	public void setGroups(List<GroupResource> groups) {
46
		this.groups = groups;
47
	}
48
	
29 49
	public void setAddingObject(boolean processing){
30 50
		taskProcessing = processing;
31 51
	}
b/src/com/rackspace/cloud/android/ContainerObjectsActivity.java
63 63
	public void onCreate(Bundle savedInstanceState) {
64 64
		super.onCreate(savedInstanceState);
65 65
		trackPageView(GoogleAnalytics.PAGE_FOLDER);
66
		container = (Container) this.getIntent().getExtras().get("container");
66
		container = getContainer();
67 67
		if (container.isCdnEnabled() == true) {
68 68
			cdnEnabledIs = "true";
69 69
		} else {
......
71 71
		}
72 72
		restoreState(savedInstanceState);
73 73
	}
74

  
74
	
75
	protected Container getContainer(){
76
		return (Container) this.getIntent().getExtras().get("container");
77
	}
78
	
75 79
	@Override
76 80
	protected void onSaveInstanceState(Bundle outState) {
77 81
		super.onSaveInstanceState(outState);
......
204 208
	/* load only the files that should display for the 
205 209
	 * current directory in the curDirFiles[]
206 210
	 */
207
	private void loadCurrentDirectoryFiles(){
211
	protected void loadCurrentDirectoryFiles(){
208 212
		ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>();
209

  
213
		Log.i(LOG,"loading files");
210 214
		if(files != null){
211 215
			for(int i = 0 ; i < files.length; i ++){
216
				Log.i(LOG,"loading files"+i);
212 217
				if(fileBelongsInDir(files[i])){
213 218
					curFiles.add(files[i]);
214 219
				}
......
221 226
	 * determines if a file should be displayed in current 
222 227
	 * directory
223 228
	 */
224
	private Boolean fileBelongsInDir(ContainerObjects obj){
229
	protected Boolean fileBelongsInDir(ContainerObjects obj){
225 230
		String objPath = obj.getCName();
226
		Log.i("INFO",currentPath);
231
		
227 232
		if(!objPath.startsWith(currentPath)){
233
			Log.i(LOG,"Path is:"+currentPath+" "+objPath+" "+false);
228 234
			return false;
229 235
		}
230 236
		else{
231 237
			objPath = objPath.substring(currentPath.length());
238
			Log.i(LOG,"Path is:"+currentPath+" "+objPath+" "+!objPath.contains("/"));
232 239
			return !objPath.contains("/");
233 240
		}
234 241
	}
......
250 257
		if (files != null) {
251 258
			for (int i = 0; i < files.size(); i++) {
252 259
				ContainerObjects file = files.get(i);
253
				Log.i(file.getCName(),file.getCName());
260
				//Log.i(file.getCName(),file.getCName());
254 261
				this.files[i] = file;
255 262
				fileNames[i] = file.getName();
256 263
			}
257 264
		}
258 265
	}
259 266

  
260
	private void displayCurrentFiles(){
267
	protected void displayCurrentFiles(){
261 268
		if (app.getCurFiles().size() == 0) {
262 269
			displayNoFilesCell();
263 270
		} else {
......
275 282
	 * of if you are at top of container or
276 283
	 * in a folder
277 284
	 */
278
	private void displayNoFilesCell() {
285
	protected void displayNoFilesCell() {
279 286
		String a[] = new String[1];
280 287
		if(currentPath.equals("")){
281 288
			a[0] = "Empty Container";
......
348 355
		}
349 356
	}
350 357

  
351
	/* 
352
	 * Create the Menu options
358
	 
359
	
353 360
	@Override
354 361
	public boolean onCreateOptionsMenu(Menu menu) {
355 362
		super.onCreateOptionsMenu(menu);
......
572 579
				else if(container.getName().equals(Container.OTHERS)){
573 580
					
574 581
				}
575
				else
576
					files = (new ContainerObjectManager(getContext())).createList(true,
582
				else{
583
					if(container.getOtherUser()==null)
584
						files = (new ContainerObjectManager(getContext())).createList(true,
577 585
						container.getName());
586
					else
587
						files = (new ContainerObjectManager(getContext())).createOtherList(true,
588
								container.getName(), container.getOtherUser());
589
				}
578 590
			} catch (CloudServersException e) {
579 591
				exception = e;
580 592
				e.printStackTrace();
......
843 855
			finish();
844 856
		}
845 857
	}
858
	
859
	
860
	public String getCurrentPath() {
861
		return currentPath;
862
	}
863
	
864
	public ContainerObjects[] getFiles() {
865
		return files;
866
	}
846 867
}
b/src/com/rackspace/cloud/android/ListContainerActivity.java
33 33

  
34 34
	protected static final int DELETE_ID = 0;
35 35

  
36
	private Container[] containers;
36
	protected Container[] containers;
37 37
	public Container container;
38 38
	public Container cdnContainer;
39 39
	public String[] containerNames;
......
41 41
	public Object kiloBytes;
42 42
	public int bConver = 1048576;
43 43
	public int kbConver = 1024;
44
	private Context context;
45
	private boolean loading;
44
	protected Context context;
45
	protected boolean loading;
46 46

  
47 47
	@Override
48 48
	public void onCreate(Bundle savedInstanceState) {
......
87 87
		}
88 88
	}
89 89

  
90
	private void loadContainers() {
90
	protected void loadContainers() {
91 91
		displayLoadingCell();
92 92
		new LoadContainersTask().execute((Void[]) null);
93 93
	}
......
112 112
		getListView().setItemsCanFocus(false);
113 113
	}
114 114

  
115
	private void displayNoServersCell() {
115
	protected void displayNoServersCell() {
116 116
		String a[] = new String[1];
117 117
		a[0] = "No Containers";
118 118
		setListAdapter(new ArrayAdapter<String>(this,
......
142 142
		}
143 143
	}
144 144

  
145
	private class LoadContainersTask extends
145
	protected class LoadContainersTask extends
146 146
			AsyncTask<Void, Void, ArrayList<Container>> {
147 147

  
148 148
		private CloudServersException exception;
......
157 157
			ArrayList<Container> containers = null;
158 158

  
159 159
			try {
160
				containers = (new ContainerManager(context)).createList(true);
160
				containers = loadContainersInner();
161 161
			} catch (CloudServersException e) {
162 162
				exception = e;
163 163
			}
......
174 174
			ArrayList<Container> containerList = result;
175 175
			if(result==null)
176 176
				result = new ArrayList<Container>();
177
			Container containerToAdd = new Container();
177
			/*Container containerToAdd = new Container();
178 178
			containerToAdd.setCount(0);
179 179
			containerToAdd.setBytes(0);
180 180
			containerToAdd.setName(Container.MYSHARED);
......
189 189
			containerToAdd.setLogRetention(false);
190 190
			containerToAdd.setCdnEnabled(false);
191 191
			containerToAdd.setTtl(0);
192
			containerList.add(containerToAdd);
192
			containerList.add(containerToAdd);*/
193 193
			
194 194
			if (containerList != null) {
195 195
				containerNames = new String[containerList.size()];
......
207 207
			new LoadCDNContainersTask().execute((Void[]) null);
208 208
		}
209 209
	}
210

  
210
	
211
	protected ArrayList<Container>  loadContainersInner() throws CloudServersException{
212
		return (new ContainerManager(context)).createList(true);
213
	}
214
	public Context getContext() {
215
		return context;
216
	}
211 217
	private class LoadCDNContainersTask extends
212 218
			AsyncTask<Void, Void, ArrayList<Container>> {
213 219

  
......
297 303
					false);
298 304

  
299 305
			TextView label = (TextView) row.findViewById(R.id.label);
300
			label.setText(container.getName());
306
			if(container.getOtherUser()!=null)
307
				label.setText(container.getOtherUser()+"/"+container.getName());
308
			else
309
				label.setText(container.getName());
301 310

  
302 311
			if (container.getBytes() >= bConver) {
303 312
				megaBytes = Math.abs(container.getBytes() / bConver + 0.2);
b/src/com/rackspace/cloud/android/PithosGroupsActivity.java
1
package com.rackspace.cloud.android;
2

  
3
import android.app.Activity;
4
import android.content.Context;
5
import android.os.Build;
6
import android.os.Bundle;
7

  
8
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
9
import com.rackspace.cloud.android.widget.GroupsListView;
10
import com.rackspace.cloud.files.api.client.Container;
11

  
12
public class PithosGroupsActivity extends Activity {
13
	private Context context;
14
	private boolean loading;
15
	private GoogleAnalyticsTracker tracker;
16
	@Override
17
	public void onCreate(Bundle savedInstanceState) {
18
		super.onCreate(savedInstanceState);
19
		startTracker();
20
		trackPageView(GoogleAnalytics.PAGE_FOLDER);
21
		setContentView(R.layout.groups);
22
		GroupsListView groupsList = ((GroupsListView) findViewById(R.id.groupsListView));
23
		/*
24
		 * groupsList.setOnGroupExpandListener(new OnGroupExpandListener() {
25
		 * 
26
		 * @Override public void onGroupExpand(int groupPosition) {
27
		 * GroupResource g = (GroupResource)
28
		 * groupsList.getListdapter().getGroup(groupPosition); if(g!=null){
29
		 * getGroupUserTask(groupPosition).execute(g.getUri()); }
30
		 * 
31
		 * } });
32
		 */
33
	}
34

  
35
	protected Container getContainer() {
36
		return (Container) this.getIntent().getExtras().get("container");
37
	}
38

  
39
	@Override
40
	protected void onSaveInstanceState(Bundle outState) {
41
		super.onSaveInstanceState(outState);
42

  
43
	}
44

  
45
	public void startTracker() {
46
		if (!"google_sdk".equals(Build.PRODUCT) && !"sdk".equals(Build.PRODUCT)) {
47
			tracker = GoogleAnalyticsTracker.getInstance();
48
			tracker.start(Config.WEB_PROPERTY_ID, 20, this);
49
		}
50
	}
51

  
52
	public void trackPageView(String page) {
53
		if (tracker != null) {
54
			tracker.trackPageView(page);
55
		}
56
	}
57

  
58
	@Override
59
	protected void onDestroy() {
60
		super.onDestroy();
61
		if (tracker != null) {
62
			tracker.stop();
63
		}
64
	}
65

  
66
	public void trackEvent(String category, String action, String label,
67
			int value) {
68
		if (tracker != null) {
69
			tracker.trackEvent(category, action, label, value);
70
		}
71
	}
72

  
73
}
b/src/com/rackspace/cloud/android/PithosMySharedActivity.java
1
package com.rackspace.cloud.android;
2

  
3
import java.util.ArrayList;
4

  
5
import android.util.Log;
6

  
7
import com.rackspace.cloud.android.ContainerObjectsActivity.FileAdapter;
8
import com.rackspace.cloud.files.api.client.Container;
9
import com.rackspace.cloud.files.api.client.ContainerObjects;
10

  
11
public class PithosMySharedActivity extends ContainerObjectsActivity{
12
	
13
	@Override
14
	protected Container getContainer() {
15
		Container myShared = new Container();
16
		myShared.setName(Container.MYSHARED);
17
		return myShared;
18
	}
19
	
20

  
21
	/* load only the files that should display for the 
22
	 * current directory in the curDirFiles[]
23
	 */
24
	protected void loadCurrentDirectoryFiles(){
25
		ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>();
26
		Log.i(LOG,"loading files");
27
		ContainerObjects[] files = getFiles();
28
		if(files != null){
29
			for(int i = 0 ; i < files.length; i ++){
30
				Log.i(LOG,"loading files"+i);
31
				if(fileBelongsInDir(files[i])){
32
					curFiles.add(files[i]);
33
				}
34
			}
35
			AndroidCloudApplication app = (AndroidCloudApplication)this.getApplication();
36
			app.setCurFiles(curFiles);
37
		}
38
	}
39

  
40
	/*
41
	 * determines if a file should be displayed in current 
42
	 * directory
43
	 */
44
	protected Boolean fileBelongsInDir(ContainerObjects obj){
45
		String objPath = obj.getCName();
46
		String currentPath = getCurrentPath();
47
		if(!objPath.startsWith(currentPath)){
48
			Log.i(LOG,"Path is:"+currentPath+" "+objPath+" "+false);
49
			return false;
50
		}
51
		else if(objPath.endsWith("/")){
52
			return true;
53
		}
54
		else{
55
			objPath = objPath.substring(currentPath.length());
56
			Log.i(LOG,"Path is:"+currentPath+" "+objPath+" "+!objPath.contains("/"));
57
			return !objPath.contains("/");
58
		}
59
	}
60
	
61
	protected void displayCurrentFiles(){
62
		AndroidCloudApplication app = (AndroidCloudApplication)this.getApplication();
63
		if (app.getCurFiles().size() == 0) {
64
			displayNoFilesCell();
65
		} else {
66
			ArrayList<ContainerObjects> tempList = new ArrayList<ContainerObjects>();
67
			for(int i = 0; i < app.getCurFiles().size(); i++){
68
				tempList.add(app.getCurFiles().get(i));
69
			}
70
			getListView().setDividerHeight(1); // restore divider lines
71
			setListAdapter(new FileAdapter());
72
		}
73
	}
74

  
75

  
76
}
b/src/com/rackspace/cloud/android/PithosOthersActivity.java
1
package com.rackspace.cloud.android;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import android.os.Bundle;
7

  
8
import com.rackspace.cloud.android.ListContainerActivity.FileAdapter;
9
import com.rackspace.cloud.files.api.client.Container;
10
import com.rackspace.cloud.files.api.client.ContainerManager;
11
import com.rackspace.cloud.servers.api.client.CloudServersException;
12

  
13
public class PithosOthersActivity extends ListContainerActivity{
14
	@Override
15
	public void onCreate(Bundle savedInstanceState) {
16
		super.onCreate(savedInstanceState);
17
		trackPageView(GoogleAnalytics.PAGE_CONTAINERS);
18
		context = getApplicationContext();
19
		restoreState(savedInstanceState);
20
	}
21

  
22
	@Override
23
	protected void onSaveInstanceState(Bundle outState) {
24
		super.onSaveInstanceState(outState);
25
		outState.putSerializable("container", containers);
26
		outState.putBoolean("loading", loading);
27
	}
28

  
29
	private void restoreState(Bundle state) {
30
		if (state != null && state.containsKey("loading")
31
				&& state.getBoolean("loading")) {
32
			loadContainers();
33
			registerForContextMenu(getListView());
34
		} else if (state != null && state.containsKey("container")
35
				&& state.getSerializable("container") != null) {
36
			containers = (Container[]) state.getSerializable("container");
37
			if (containers.length == 0) {
38
				displayNoServersCell();
39
			} else {
40
				getListView().setDividerHeight(1); // restore divider lines
41
				setListAdapter(new FileAdapter());
42
			}
43
		} else {
44
			loadContainers();
45
			registerForContextMenu(getListView());
46
		}
47
	}
48
	
49
	protected ArrayList<Container>  loadContainersInner() throws CloudServersException{
50
		ArrayList<Container> result = new ArrayList<Container>();
51
		List<String> users = ((AndroidCloudApplication)getContext().getApplicationContext()).getOthers();
52
		for(String u :users){
53
			ArrayList<Container> c = (new ContainerManager(getContext())).createOthersList(u,true);
54
			result.addAll(c);
55
		}
56
		return result;
57
	}
58
}
b/src/com/rackspace/cloud/android/TabViewActivity.java
35 35

  
36 36
		TabHost tabs = getTabHost();
37 37
		
38
		TabHost.TabSpec spec = tabs.newTabSpec("tab2");
38
		TabHost.TabSpec spec = tabs.newTabSpec("tab1");
39 39
		spec.setContent(new Intent(this, ListContainerActivity.class));
40 40
		spec.setIndicator("Cloud Files",
41 41
				getResources().getDrawable(R.drawable.cloudfiles));
42 42
		tabs.addTab(spec);
43
		
44
		spec = tabs.newTabSpec("tab2");
45
		spec.setContent(new Intent(this, PithosMySharedActivity.class));
46
		spec.setIndicator("MyShared",
47
				getResources().getDrawable(R.drawable.cloudfiles));
48
		tabs.addTab(spec);
49
		
50
		spec = tabs.newTabSpec("tab3");
51
		spec.setContent(new Intent(this, PithosOthersActivity.class));
52
		spec.setIndicator("Others",
53
				getResources().getDrawable(R.drawable.cloudfiles));
54
		tabs.addTab(spec);
55
		
56
		spec = tabs.newTabSpec("tab4");
57
		spec.setContent(new Intent(this, PithosGroupsActivity.class));
58
		spec.setIndicator("Groups",
59
				getResources().getDrawable(R.drawable.cloudfiles));
60
		tabs.addTab(spec);
43 61
		/*
44 62
		spec = tabs.newTabSpec("tab1");
45 63
		spec.setContent(new Intent(this, ListServersActivity.class));
b/src/com/rackspace/cloud/android/widget/GroupsListView.java
1
package com.rackspace.cloud.android.widget;
2

  
3

  
4

  
5

  
6
import java.util.List;
7

  
8
import android.content.Context;
9
import android.util.AttributeSet;
10
import android.view.LayoutInflater;
11
import android.view.View;
12
import android.view.ViewGroup;
13
import android.widget.BaseExpandableListAdapter;
14
import android.widget.ExpandableListView;
15
import android.widget.ImageView;
16
import android.widget.TextView;
17

  
18
import com.rackspace.cloud.android.AndroidCloudApplication;
19
import com.rackspace.cloud.android.R;
20
import com.rackspace.cloud.files.api.client.GroupResource;
21

  
22
public class GroupsListView extends ExpandableListView{
23
	LayoutInflater inflater;
24
	GroupsListAdapter adapter;
25
	public GroupsListView(Context context) {
26
		super(context);
27
		// TODO Auto-generated constructor stub
28
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
29
		setAdapter(adapter=new GroupsListAdapter());
30
	}
31
	
32
	
33
	
34
	public GroupsListView(Context context, AttributeSet attrs) {
35
		super(context, attrs);
36
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
37
		setAdapter(adapter=new GroupsListAdapter());
38
		
39
	}
40
	
41
	public GroupsListView(Context context, AttributeSet attrs, int defStyle) {
42
		super(context, attrs, defStyle);
43
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
44
		setAdapter(adapter=new GroupsListAdapter());
45
	}
46
	
47
	
48
	
49
	
50
	
51
	public class GroupsListAdapter extends BaseExpandableListAdapter{
52
		
53
		public GroupsListAdapter() {
54
			
55
		}
56
		
57
		
58
		@Override
59
		public View getChildView(int groupPosition, int childPosition,
60
				boolean isLastChild, View convertView, ViewGroup parent) {
61
			View v = inflater.inflate(R.layout.groupsrow, null);
62
			ImageView imageIcon = (ImageView) v.findViewById(R.id.image);
63
			
64
			TextView textFileName = (TextView) v.findViewById(R.id.name);
65
			String gr = (String) getChild(groupPosition, childPosition);
66
			textFileName.setText(gr);
67
			imageIcon.setImageResource(R.drawable.user);
68
			
69
			return v;
70
		}
71
		
72
		@Override
73
		public View getGroupView(int groupPosition, boolean isExpanded,
74
				View convertView, ViewGroup parent) {
75
			View v = inflater.inflate(R.layout.groupsrow, null);
76
			ImageView imageIcon = (ImageView) v.findViewById(R.id.image);
77
			TextView textFileName = (TextView) v.findViewById(R.id.name);
78
			GroupResource gr = (GroupResource) getGroup(groupPosition);
79
			textFileName.setText(gr.getName());
80
			
81
			imageIcon.setImageResource(R.drawable.group);
82
			//imageIcon.setVisibility(View.GONE);
83
			return v;
84
		}
85

  
86
		@Override
87
		public int getChildrenCount(int groupPosition) {
88
			if(getGroups().size()>groupPosition)
89
				return getGroups().get(groupPosition).getUsers().size();
90
			return 0;
91
		}
92

  
93
		@Override
94
		public Object getGroup(int groupPosition) {
95
			if(getGroups().size()>groupPosition)
96
				return getGroups().get(groupPosition);
97
			return null;
98
		}
99

  
100
		@Override
101
		public int getGroupCount() {
102
			return getGroups().size();
103
		}
104
		
105
		@Override
106
		public Object getChild(int groupPosition, int childPosition) {
107
			if(getGroups().size()>groupPosition)
108
				if(getGroups().get(groupPosition).getUsers().size()>childPosition)
109
					return getGroups().get(groupPosition).getUsers().get(childPosition);
110
			return null;
111
		}
112

  
113
		@Override
114
		public long getChildId(int groupPosition, int childPosition) {
115
			return childPosition;
116
		}
117
		
118
		@Override
119
		public long getGroupId(int groupPosition) {
120
			return groupPosition;
121
		}
122
		
123
		
124

  
125
		
126

  
127
		@Override
128
		public boolean hasStableIds() {
129
			// TODO Auto-generated method stub
130
			return true;
131
		}
132

  
133
		@Override
134
		public boolean isChildSelectable(int groupPosition, int childPosition) {
135
			// TODO Auto-generated method stub
136
			return false;
137
		}
138
		
139
	}
140
	public GroupsListAdapter getListdapter() {
141
		return adapter;
142
	}
143
	
144
	List<GroupResource> getGroups(){
145
		return ((AndroidCloudApplication)getContext().getApplicationContext()).getGroups();
146
	}
147
	
148

  
149
}
b/src/com/rackspace/cloud/files/api/client/Container.java
17 17
	private String name;
18 18
	private int count;
19 19
	private long bytes;
20

  
20
	private String otherUser=null;
21 21
	// CDN attributes
22 22
	private boolean cdnEnabled;
23 23
	private int Ttl;
......
32 32
				+ getName() + "\"></server>";
33 33
		return xml;
34 34
	}
35

  
35
	
36
	public Container() {
37
		// TODO Auto-generated constructor stub
38
	}
39
	
40
	public Container(String otherUser){
41
		this.otherUser = otherUser;
42
	}
43
	
44
	public void setOtherUser(String otherUser) {
45
		this.otherUser = otherUser;
46
	}
47
	
48
	public String getOtherUser() {
49
		return otherUser;
50
	}
51
	
36 52
	/**
37 53
	 * @return the name
38 54
	 */
b/src/com/rackspace/cloud/files/api/client/ContainerManager.java
6 6
import java.net.URI;
7 7
import java.net.URISyntaxException;
8 8
import java.util.ArrayList;
9
import java.util.List;
9 10

  
10 11
import javax.xml.parsers.FactoryConfigurationError;
11 12
import javax.xml.parsers.ParserConfigurationException;
12 13
import javax.xml.parsers.SAXParser;
13 14
import javax.xml.parsers.SAXParserFactory;
14 15

  
16
import org.apache.http.Header;
15 17
import org.apache.http.HttpResponse;
16 18
import org.apache.http.client.ClientProtocolException;
17 19
import org.apache.http.client.methods.HttpDelete;
......
28 30
import android.text.Editable;
29 31
import android.util.Log;
30 32

  
33
import com.rackspace.cloud.android.AndroidCloudApplication;
31 34
import com.rackspace.cloud.files.api.client.parsers.ContainerXMLParser;
35
import com.rackspace.cloud.files.api.client.parsers.OthersXmlParser;
32 36
import com.rackspace.cloud.servers.api.client.Account;
33 37
import com.rackspace.cloud.servers.api.client.CloudServersException;
34 38
import com.rackspace.cloud.servers.api.client.EntityManager;
......
41 45
 */
42 46
public class ContainerManager extends EntityManager {
43 47
	private Context context;
44

  
48
	public String LOG = "ContainerManager";
45 49
	public ContainerManager(Context context) {
46 50
		this.context = context;
47 51
	}
......
248 252

  
249 253
	public ArrayList<Container> createList(boolean detail)
250 254
			throws CloudServersException {
251

  
255
		Log.i(LOG,"Create List:"+Account.getAccount().getStorageUrl());
252 256
		CustomHttpClient httpclient = new CustomHttpClient(context);
253 257
		HttpGet get = new HttpGet(Account.getAccount().getStorageUrl()
254 258
				+ "?format=xml");
......
256 260
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, Account.getAccount()
257 261
				.getStorageToken());
258 262
		get.addHeader("Content-Type", "application/xml");
259

  
263
		
260 264
		try {
261 265
			HttpResponse resp = httpclient.execute(get);
266
			List<GroupResource> groups = new ArrayList<GroupResource>();
267
			for(Header h : resp.getAllHeaders()){
268
				if(h.getName().startsWith("X-Account-Group-")){
269
					GroupResource group = new GroupResource();
270
					group.setName(h.getName().replaceAll("X-Account-Group-", ""));
271
					String users = h.getValue();
272
					String[] us = users.split(",");
273
					for(String u : us){
274
						group.getUsers().add(u);
275
					}
276
					groups.add(group);
277
				}
278
			}
279
			List<String> others = createOthersList();
280
			((AndroidCloudApplication)context.getApplicationContext()).setOthers(others);
281
			((AndroidCloudApplication)context.getApplicationContext()).setGroups(groups);
262 282
			BasicResponseHandler responseHandler = new BasicResponseHandler();
263 283
			String body = responseHandler.handleResponse(resp);
264 284
			Log.i("ContainerManager", body);
......
306 326

  
307 327
		return containers;
308 328
	}
329
	
330
	
331
	public ArrayList<String> createOthersList()
332
			throws CloudServersException {
333
		CustomHttpClient httpclient = new CustomHttpClient(context);
334
		HttpGet get = new HttpGet(Account.getAccount().getStorageUrl().replaceAll(Account.getAccount().getUsername(), "")
335
				+ "?format=xml");
336
		ArrayList<String> containers = new ArrayList<String>();
337
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, Account.getAccount()
338
				.getStorageToken());
339
		get.addHeader("Content-Type", "application/xml");
340
		
341
		try {
342
			HttpResponse resp = httpclient.execute(get);
343
			BasicResponseHandler responseHandler = new BasicResponseHandler();
344
			String body = responseHandler.handleResponse(resp);
345
			Log.i("ContainerManager", body);
346
			if (resp.getStatusLine().getStatusCode() == 200
347
					|| resp.getStatusLine().getStatusCode() == 203) {
348
				OthersXmlParser containerXMLParser = new OthersXmlParser();
349
				SAXParser saxParser = SAXParserFactory.newInstance()
350
						.newSAXParser();
351
				XMLReader xmlReader = saxParser.getXMLReader();
352
				xmlReader.setContentHandler(containerXMLParser);
353

  
354
				xmlReader.parse(new InputSource(new StringReader(body)));
355
				containers = containerXMLParser.getContainers();
356
				Log.i(LOG,containers.toString());
357
			} else {
358
				CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
359
				SAXParser saxParser = SAXParserFactory.newInstance()
360
						.newSAXParser();
361
				XMLReader xmlReader = saxParser.getXMLReader();
362
				xmlReader.setContentHandler(parser);
363
				xmlReader.parse(new InputSource(new StringReader(body)));
364
				CloudServersException cse = parser.getException();
365
				throw cse;
366
			}
367
		} catch (ClientProtocolException e) {
368
			CloudServersException cse = new CloudServersException();
369
			cse.setMessage(e.getLocalizedMessage());
370
			throw cse;
371
		} catch (IOException e) {
372
			CloudServersException cse = new CloudServersException();
373
			cse.setMessage(e.getLocalizedMessage());
374
			throw cse;
375
		} catch (ParserConfigurationException e) {
376
			CloudServersException cse = new CloudServersException();
377
			cse.setMessage(e.getLocalizedMessage());
378
			throw cse;
379
		} catch (SAXException e) {
380
			CloudServersException cse = new CloudServersException();
381
			cse.setMessage(e.getLocalizedMessage());
382
			throw cse;
383
		} catch (FactoryConfigurationError e) {
384
			CloudServersException cse = new CloudServersException();
385
			cse.setMessage(e.getLocalizedMessage());
386
			throw cse;
387
		}
388

  
389
		return containers;
390
	}
309 391

  
310 392
	private String getSafeURL(String badURL, String name) {
311 393
		URI uri = null;
......
326 408
		return url.substring(0, url.length() - 1);
327 409
	}
328 410

  
411
	public ArrayList<Container> createOthersList(String user, boolean b) throws CloudServersException {
412
		Log.i(LOG,"Create List:"+Account.getAccount().getStorageUrl());
413
		CustomHttpClient httpclient = new CustomHttpClient(context);
414
		HttpGet get = new HttpGet(Account.getAccount().getStorageUrl().replaceAll(Account.getAccount().getUsername(), user)
415
				+ "?format=xml");
416
		ArrayList<Container> containers = new ArrayList<Container>();
417
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, Account.getAccount()
418
				.getStorageToken());
419
		get.addHeader("Content-Type", "application/xml");
420
		
421
		try {
422
			HttpResponse resp = httpclient.execute(get);
423
			List<GroupResource> groups = new ArrayList<GroupResource>();
424
			BasicResponseHandler responseHandler = new BasicResponseHandler();
425
			String body = responseHandler.handleResponse(resp);
426
			Log.i("ContainerManager", body);
427
			if (resp.getStatusLine().getStatusCode() == 200
428
					|| resp.getStatusLine().getStatusCode() == 203) {
429
				ContainerXMLParser containerXMLParser = new ContainerXMLParser();
430
				SAXParser saxParser = SAXParserFactory.newInstance()
431
						.newSAXParser();
432
				XMLReader xmlReader = saxParser.getXMLReader();
433
				xmlReader.setContentHandler(containerXMLParser);
434

  
435
				xmlReader.parse(new InputSource(new StringReader(body)));
436
				containers = containerXMLParser.getContainers();
437
				for(Container c : containers){
438
					c.setOtherUser(user);
439
				}
440
			} else {
441
				CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
442
				SAXParser saxParser = SAXParserFactory.newInstance()
443
						.newSAXParser();
444
				XMLReader xmlReader = saxParser.getXMLReader();
445
				xmlReader.setContentHandler(parser);
446
				xmlReader.parse(new InputSource(new StringReader(body)));
447
				CloudServersException cse = parser.getException();
448
				throw cse;
449
			}
450
		} catch (ClientProtocolException e) {
451
			CloudServersException cse = new CloudServersException();
452
			cse.setMessage(e.getLocalizedMessage());
453
			throw cse;
454
		} catch (IOException e) {
455
			CloudServersException cse = new CloudServersException();
456
			cse.setMessage(e.getLocalizedMessage());
457
			throw cse;
458
		} catch (ParserConfigurationException e) {
459
			CloudServersException cse = new CloudServersException();
460
			cse.setMessage(e.getLocalizedMessage());
461
			throw cse;
462
		} catch (SAXException e) {
463
			CloudServersException cse = new CloudServersException();
464
			cse.setMessage(e.getLocalizedMessage());
465
			throw cse;
466
		} catch (FactoryConfigurationError e) {
467
			CloudServersException cse = new CloudServersException();
468
			cse.setMessage(e.getLocalizedMessage());
469
			throw cse;
470
		}
471

  
472
		return containers;
473
	}
474

  
329 475
}
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
27 27
import org.xml.sax.XMLReader;
28 28

  
29 29
import android.content.Context;
30
import android.util.Log;
30 31

  
31 32
import com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser;
32 33
import com.rackspace.cloud.servers.api.client.Account;
......
53 54

  
54 55
	public ArrayList<ContainerObjects> createList(boolean detail,
55 56
			String passName) throws CloudServersException {
56

  
57
		Log.i(LOG,"Create List:"+passName);
57 58
		CustomHttpClient httpclient = new CustomHttpClient(context);
58 59
		String url = getSafeURL(Account.getAccount().getStorageUrl(), passName)
59 60
				+ "?format=xml";
......
116 117

  
117 118
	}
118 119
	
120
	public ArrayList<ContainerObjects> createOtherList(boolean detail,
121
			String passName, String user) throws CloudServersException {
122
		Log.i(LOG,"Create List:"+passName);
123
		CustomHttpClient httpclient = new CustomHttpClient(context);
124
		String url = getSafeURL(Account.getAccount().getStorageUrl().replaceAll(Account.getAccount().getUsername(), user), passName)
125
				+ "?format=xml";
126
		HttpGet get = new HttpGet(url);
127
		ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>();
128

  
129
		get.addHeader("Content-Type", "application/xml");
130
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken);
131

  
132
		try {
133
			HttpResponse resp = httpclient.execute(get);
134
			BasicResponseHandler responseHandler = new BasicResponseHandler();
135
			String body = responseHandler.handleResponse(resp);
136

  
137
			if (resp.getStatusLine().getStatusCode() == 200
138
					|| resp.getStatusLine().getStatusCode() == 203) {
139
				ContainerObjectXMLparser filesXMLParser = new ContainerObjectXMLparser();
140
				SAXParser saxParser = SAXParserFactory.newInstance()
141
						.newSAXParser();
142
				XMLReader xmlReader = saxParser.getXMLReader();
143
				xmlReader.setContentHandler(filesXMLParser);
144

  
145
				xmlReader.parse(new InputSource(new StringReader(body)));
146
				files = filesXMLParser.getViewFiles();
147
				for(ContainerObjects o :files)
148
					o.setContainerName(passName);
149

  
150
			} else {
151
				CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
152
				SAXParser saxParser = SAXParserFactory.newInstance()
153
						.newSAXParser();
154
				XMLReader xmlReader = saxParser.getXMLReader();
155
				xmlReader.setContentHandler(parser);
156
				xmlReader.parse(new InputSource(new StringReader(body)));
157
				CloudServersException cse = parser.getException();
158
				throw cse;
159
			}
160
		} catch (ClientProtocolException e) {
161
			CloudServersException cse = new CloudServersException();
162
			cse.setMessage(e.getLocalizedMessage());
163
			throw cse;
164
		} catch (IOException e) {
165
			CloudServersException cse = new CloudServersException();
166
			cse.setMessage(e.getLocalizedMessage());
167
			throw cse;
168
		} catch (ParserConfigurationException e) {
169
			CloudServersException cse = new CloudServersException();
170
			cse.setMessage(e.getLocalizedMessage());
171
			throw cse;
172
		} catch (SAXException e) {
173
			CloudServersException cse = new CloudServersException();
174
			cse.setMessage(e.getLocalizedMessage());
175
			throw cse;
176
		} catch (FactoryConfigurationError e) {
177
			CloudServersException cse = new CloudServersException();
178
			cse.setMessage(e.getLocalizedMessage());
179
			throw cse;
180
		}
181
		return files;
182

  
183
	}
184
	
185
	public ArrayList<ContainerObjects> createList(boolean detail,
186
			String passName, String prefix) throws CloudServersException {
187

  
188
		CustomHttpClient httpclient = new CustomHttpClient(context);
189
		String url = getSafeURL(Account.getAccount().getStorageUrl(), passName)
190
				+ "?format=xml&prefix="+prefix;
191
		HttpGet get = new HttpGet(url);
192
		ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>();
193

  
194
		get.addHeader("Content-Type", "application/xml");
195
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken);
196

  
197
		try {
198
			HttpResponse resp = httpclient.execute(get);
199
			BasicResponseHandler responseHandler = new BasicResponseHandler();
200
			String body = responseHandler.handleResponse(resp);
201

  
202
			if (resp.getStatusLine().getStatusCode() == 200
203
					|| resp.getStatusLine().getStatusCode() == 203) {
204
				ContainerObjectXMLparser filesXMLParser = new ContainerObjectXMLparser();
205
				SAXParser saxParser = SAXParserFactory.newInstance()
206
						.newSAXParser();
207
				XMLReader xmlReader = saxParser.getXMLReader();
208
				xmlReader.setContentHandler(filesXMLParser);
209

  
210
				xmlReader.parse(new InputSource(new StringReader(body)));
211
				files = filesXMLParser.getViewFiles();
212
				for(ContainerObjects o :files)
213
					o.setContainerName(passName);
214

  
215
			} else {
216
				CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
217
				SAXParser saxParser = SAXParserFactory.newInstance()
218
						.newSAXParser();
219
				XMLReader xmlReader = saxParser.getXMLReader();
220
				xmlReader.setContentHandler(parser);
221
				xmlReader.parse(new InputSource(new StringReader(body)));
222
				CloudServersException cse = parser.getException();
223
				throw cse;
224
			}
225
		} catch (ClientProtocolException e) {
226
			CloudServersException cse = new CloudServersException();
227
			cse.setMessage(e.getLocalizedMessage());
228
			throw cse;
229
		} catch (IOException e) {
230
			CloudServersException cse = new CloudServersException();
231
			cse.setMessage(e.getLocalizedMessage());
232
			throw cse;
233
		} catch (ParserConfigurationException e) {
234
			CloudServersException cse = new CloudServersException();
235
			cse.setMessage(e.getLocalizedMessage());
236
			throw cse;
237
		} catch (SAXException e) {
238
			CloudServersException cse = new CloudServersException();
239
			cse.setMessage(e.getLocalizedMessage());
240
			throw cse;
241
		} catch (FactoryConfigurationError e) {
242
			CloudServersException cse = new CloudServersException();
243
			cse.setMessage(e.getLocalizedMessage());
244
			throw cse;
245
		}
246
		return files;
247

  
248
	}
249
	
119 250
	public ArrayList<ContainerObjects> createListMyShared(boolean detail,
120 251
			String passName, List<Container> containers) throws CloudServersException {
121 252

  
122 253
		ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>();
123 254
		for(Container con :containers ){
255
			Log.i(LOG,"GEETING FILES OF COntainer:"+con.getName());
124 256
			if(con.getName().equalsIgnoreCase("trash")||con.getName().equals(Container.MYSHARED)||con.getName().equals(Container.OTHERS)){}
125 257
			else
126 258
			try{
127 259
				ArrayList<ContainerObjects> temp = createList(detail, con.getName());
128 260
				for(ContainerObjects o : temp){
129
					if(o.isShared())
261
					Log.i(LOG,o.getCName()+" "+o.isShared());
262
					if(o.isShared()){
263
						o.setContainerName(Container.MYSHARED);
130 264
						files.add(o);
265
					}
131 266
				}
132 267
			}
133 268
			catch(CloudServersException e){
b/src/com/rackspace/cloud/files/api/client/GroupResource.java
1

  
2
package com.rackspace.cloud.files.api.client;
3

  
4
import java.net.URL;
5
import java.net.URLDecoder;
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
import org.json.JSONArray;
10
import org.json.JSONException;
11

  
12
/**
13
 *
14
 */
15
public class GroupResource {
16
	String name;
17
	
18

  
19
	List<String> users = new ArrayList<String>();
20

  
21

  
22
	public String getName() {
23
		return name;
24
	}
25

  
26

  
27
	public void setName(String name) {
28
		this.name = name;
29
	}
30

  
31

  
32
	public List<String> getUsers() {
33
		return users;
34
	}
35

  
36

  
37
	public void setUsers(List<String> users) {
38
		this.users = users;
39
	}
40
	
41
	
42
	
43

  
44
	
45
}
b/src/com/rackspace/cloud/files/api/client/parsers/OthersXmlParser.java
1
package com.rackspace.cloud.files.api.client.parsers;
2

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Map;
6

  
7
import org.xml.sax.Attributes;
8
import org.xml.sax.helpers.DefaultHandler;
9

  
10
import android.util.Log;
11

  
12
import com.rackspace.cloud.files.api.client.Container;
13

  
14
public class OthersXmlParser  extends DefaultHandler {
15

  
16
	
17
	private ArrayList<String> containers;
18
	
19

  
20
	private StringBuffer currentData;
21

  
22
	public void startElement(String uri, String name, String qName,
23
			Attributes atts) {
24

  
25
		currentData = new StringBuffer();
26
		if ("accounts".equals(name)) {
27
			containers = new ArrayList<String>();
28
		}
29
	}
30

  
31
	public void endElement(String uri, String name, String qName) {
32

  
33
		String value = currentData.toString().trim();
34

  
35
		if ("account".equals(name)) {
36

  
37
		} else if ("name".equals(name)) {
38
			containers.add(value);
39
		}
40

  
41
	}
42

  
43
	public void characters(char ch[], int start, int length) {
44

  
45
		// Log.d("Rackspace-Cloud", "Characters:    \"");
46

  
47
		for (int i = start; i < start + length; i++) {
48
			switch (ch[i]) {
49
			case '\\':
50
				// Log.d("Rackspace-Cloud", "\\\\");
51
				break;
52
			case '"':
53
				// Log.d("Rackspace-Cloud", "\\\"");
54
				break;
55
			case '\n':
56
				// Log.d("Rackspace-Cloud", "\\n");
57
				break;
58
			case '\r':
59
				// Log.d("Rackspace-Cloud", "\\r");
60
				break;
61
			case '\t':
62
				// Log.d("Rackspace-Cloud", "\\t");
63
				break;
64
			default:
65
				// Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
66
				break;
67
			}
68
		}
69
		// Log.d("Rackspace-Cloud", "\"\n");
70

  
71
		for (int i = start; i < (start + length); i++) {
72
			currentData.append(ch[i]);
73
		}
74
	}
75

  
76
	
77
	/**
78
	 * @return the files
79
	 */
80
	public ArrayList<String> getContainers() {
81
		return containers;
82
	}
83

  
84
	
85

  
86
}

Also available in: Unified diff