root / src / com / rackspace / cloud / android / PithosOthersActivity.java @ 94abc2c7
History | View | Annotate | Download (2.1 kB)
1 | 856ad13d | koutsoub | package com.rackspace.cloud.android; |
---|---|---|---|
2 | 856ad13d | koutsoub | |
3 | 856ad13d | koutsoub | import java.util.ArrayList; |
4 | 856ad13d | koutsoub | import java.util.List; |
5 | 856ad13d | koutsoub | |
6 | 856ad13d | koutsoub | import android.os.Bundle; |
7 | db9092dd | koutsoub | import android.view.Menu; |
8 | db9092dd | koutsoub | import android.view.MenuInflater; |
9 | 856ad13d | koutsoub | |
10 | 856ad13d | koutsoub | import com.rackspace.cloud.android.ListContainerActivity.FileAdapter; |
11 | 856ad13d | koutsoub | import com.rackspace.cloud.files.api.client.Container; |
12 | 856ad13d | koutsoub | import com.rackspace.cloud.files.api.client.ContainerManager; |
13 | 856ad13d | koutsoub | import com.rackspace.cloud.servers.api.client.CloudServersException; |
14 | 856ad13d | koutsoub | |
15 | 856ad13d | koutsoub | public class PithosOthersActivity extends ListContainerActivity{ |
16 | 856ad13d | koutsoub | @Override
|
17 | 856ad13d | koutsoub | public void onCreate(Bundle savedInstanceState) { |
18 | 856ad13d | koutsoub | super.onCreate(savedInstanceState);
|
19 | 856ad13d | koutsoub | trackPageView(GoogleAnalytics.PAGE_CONTAINERS); |
20 | 856ad13d | koutsoub | context = getApplicationContext(); |
21 | 856ad13d | koutsoub | restoreState(savedInstanceState); |
22 | 856ad13d | koutsoub | } |
23 | 856ad13d | koutsoub | |
24 | 856ad13d | koutsoub | @Override
|
25 | 856ad13d | koutsoub | protected void onSaveInstanceState(Bundle outState) { |
26 | 856ad13d | koutsoub | super.onSaveInstanceState(outState);
|
27 | 856ad13d | koutsoub | outState.putSerializable("container", containers);
|
28 | 856ad13d | koutsoub | outState.putBoolean("loading", loading);
|
29 | 856ad13d | koutsoub | } |
30 | 856ad13d | koutsoub | |
31 | 856ad13d | koutsoub | private void restoreState(Bundle state) { |
32 | 856ad13d | koutsoub | if (state != null && state.containsKey("loading") |
33 | 856ad13d | koutsoub | && state.getBoolean("loading")) {
|
34 | 856ad13d | koutsoub | loadContainers(); |
35 | 856ad13d | koutsoub | registerForContextMenu(getListView()); |
36 | 856ad13d | koutsoub | } else if (state != null && state.containsKey("container") |
37 | 856ad13d | koutsoub | && state.getSerializable("container") != null) { |
38 | 856ad13d | koutsoub | containers = (Container[]) state.getSerializable("container"); |
39 | 856ad13d | koutsoub | if (containers.length == 0) { |
40 | 856ad13d | koutsoub | displayNoServersCell(); |
41 | 856ad13d | koutsoub | } else {
|
42 | 856ad13d | koutsoub | getListView().setDividerHeight(1); // restore divider lines |
43 | 856ad13d | koutsoub | setListAdapter(new FileAdapter());
|
44 | 856ad13d | koutsoub | } |
45 | 856ad13d | koutsoub | } else {
|
46 | 856ad13d | koutsoub | loadContainers(); |
47 | 856ad13d | koutsoub | registerForContextMenu(getListView()); |
48 | 856ad13d | koutsoub | } |
49 | 856ad13d | koutsoub | } |
50 | db9092dd | koutsoub | @Override
|
51 | db9092dd | koutsoub | public boolean onCreateOptionsMenu(Menu menu) { |
52 | db9092dd | koutsoub | super.onCreateOptionsMenu(menu);
|
53 | db9092dd | koutsoub | menu.findItem(R.id.add_container).setVisible(false);
|
54 | db9092dd | koutsoub | return true; |
55 | db9092dd | koutsoub | } |
56 | 856ad13d | koutsoub | protected ArrayList<Container> loadContainersInner() throws CloudServersException{ |
57 | 856ad13d | koutsoub | ArrayList<Container> result = new ArrayList<Container>(); |
58 | 856ad13d | koutsoub | List<String> users = ((AndroidCloudApplication)getContext().getApplicationContext()).getOthers(); |
59 | 856ad13d | koutsoub | for(String u :users){ |
60 | 856ad13d | koutsoub | ArrayList<Container> c = (new ContainerManager(getContext())).createOthersList(u,true); |
61 | 856ad13d | koutsoub | result.addAll(c); |
62 | 856ad13d | koutsoub | } |
63 | 856ad13d | koutsoub | return result;
|
64 | 856ad13d | koutsoub | } |
65 | 856ad13d | koutsoub | } |