Revision f506786e
b/res/layout/list_vips.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2 |
<RelativeLayout android:id="@+id/LinearLayout1" xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3 | 3 |
android:orientation="vertical" android:layout_width="fill_parent" |
4 | 4 |
android:layout_height="fill_parent"> |
5 |
<RelativeLayout android:id="@+id/LinearLayout1" xmlns:android="http://schemas.android.com/apk/res/android" |
|
6 |
android:orientation="vertical" android:layout_width="fill_parent" |
|
7 |
android:layout_height="fill_parent"> |
|
8 |
<ListView android:cacheColorHint="@android:color/transparent" android:layout_width="fill_parent" android:id="@+id/android:list" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_above="@+id/textView1"></ListView> |
|
9 |
<TextView android:layout_width="fill_parent" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="Based on the Protocol / Port you chose for this load balancer, some Virtual IPs may not be selectable in the list below. "></TextView> |
|
10 |
</RelativeLayout> |
|
11 |
</LinearLayout> |
|
5 |
<ScrollView android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:id="@+id/ScrollView1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_marginTop="10dip" android:fadeScrollbars="true" android:layout_above="@+id/select_vip_button"> |
|
6 |
<RadioGroup android:layout_height="fill_parent" android:id="@+id/vip_group" android:layout_width="fill_parent"></RadioGroup> |
|
7 |
</ScrollView> |
|
8 |
<Button android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_above="@+id/textView1" android:layout_width="130dip" android:layout_marginTop="5dip" android:text="Select Virtual Ip" android:id="@+id/select_vip_button"></Button> |
|
9 |
<TextView android:layout_alignParentLeft="true" android:id="@+id/textView1" android:text="Based on the Protocol / Port you chose for this load balancer, some Virtual IPs may not be selectable in the list below. " android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginTop="5dip"></TextView> |
|
10 |
</RelativeLayout> |
|
12 | 11 |
|
13 | 12 |
|
b/res/layout/listcontainerobjectcell.xml | ||
---|---|---|
4 | 4 |
android:layout_width="fill_parent" |
5 | 5 |
android:layout_height="64dip" |
6 | 6 |
> |
7 |
<ImageView android:src="@drawable/folder" android:layout_width="wrap_content" android:layout_height="fill_parent" android:id="@+id/file_type_image"></ImageView> |
|
7 | 8 |
|
8 | 9 |
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" |
9 | 10 |
android:orientation="vertical" |
b/res/layout/sharedvipcell.xml | ||
---|---|---|
3 | 3 |
xmlns:android="http://schemas.android.com/apk/res/android" |
4 | 4 |
android:layout_width="fill_parent" android:paddingTop="2.5dip" android:paddingBottom="2.5dip" android:layout_height="64dip" android:orientation="horizontal"> |
5 | 5 |
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:orientation="vertical"> |
6 |
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/ip_row" android:layout_marginLeft="5dip">
|
|
7 |
<TextView android:scrollbars="vertical" android:id="@+id/vip_address" android:layout_width="fill_parent" android:maxLines="1" android:layout_height="wrap_content" android:layout_weight="1" android:text="2001:4801:7901:0000:0704:cf69:0000:0005"></TextView>
|
|
8 |
</LinearLayout>
|
|
6 |
<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/ip_row" android:layout_marginLeft="5dip">
|
|
7 |
<TextView android:scrollbars="vertical" android:id="@+id/vip_address" android:layout_width="fill_parent" android:maxLines="1" android:layout_height="wrap_content" android:text="2001:4801:7901:0000:0704:cf69:0000:0005"></TextView> |
|
8 |
</HorizontalScrollView>
|
|
9 | 9 |
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout1"> |
10 | 10 |
<TextView android:id="@+id/load_balancer_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dip" android:text="test"></TextView> |
11 | 11 |
<TextView android:id="@+id/vip_protocol" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:text="HTTP(80)"></TextView> |
b/res/layout/viewobject.xml | ||
---|---|---|
18 | 18 |
android:text="Container Name" |
19 | 19 |
android:singleLine="false" |
20 | 20 |
/> |
21 |
<HorizontalScrollView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/HorizontalScrollView1" android:layout_marginLeft="22dip" android:layout_marginRight="30dip"> |
|
21 |
<HorizontalScrollView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/HorizontalScrollView1" android:layout_marginLeft="22dip" android:layout_marginRight="30dip" android:fadeScrollbars="true">
|
|
22 | 22 |
<TextView android:id="@+id/view_container_name" android:layout_width="fill_parent" android:layout_marginLeft="22dip" android:layout_marginBottom="15dip" android:scrollHorizontally="true" android:layout_height="wrap_content" android:gravity="fill_horizontal" android:layout_marginRight="30dip" android:textColor="#fff" android:lines="1" android:textSize="20.0sp" android:textStyle="bold" android:fadeScrollbars="true"></TextView> |
23 | 23 |
</HorizontalScrollView> |
24 | 24 |
|
b/src/com/rackspacecloud/android/AddLoadBalancerActivity.java | ||
---|---|---|
85 | 85 |
possibleNodes = new ArrayList<Server>(); |
86 | 86 |
} |
87 | 87 |
|
88 |
if(state != null && state.containsKey("selectedVip")){ |
|
89 |
selectedVip = (VirtualIp) state.getSerializable("selectedVip"); |
|
90 |
} |
|
91 |
|
|
88 | 92 |
setupText(); |
89 | 93 |
loadProtocolSpinner(); |
90 | 94 |
loadProtocolSubSpinner(); |
... | ... | |
99 | 103 |
super.onSaveInstanceState(outState); |
100 | 104 |
outState.putSerializable("nodes", nodes); |
101 | 105 |
outState.putSerializable("possibleNodes", possibleNodes); |
106 |
outState.putSerializable("selectedVip", selectedVip); |
|
102 | 107 |
} |
103 | 108 |
|
104 | 109 |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
b/src/com/rackspacecloud/android/ContainerObjectsActivity.java | ||
---|---|---|
12 | 12 |
import android.content.Intent; |
13 | 13 |
import android.os.AsyncTask; |
14 | 14 |
import android.os.Bundle; |
15 |
import android.util.Log; |
|
16 | 15 |
import android.view.LayoutInflater; |
17 | 16 |
import android.view.Menu; |
18 | 17 |
import android.view.MenuInflater; |
... | ... | |
21 | 20 |
import android.view.ViewGroup; |
22 | 21 |
import android.widget.ArrayAdapter; |
23 | 22 |
import android.widget.EditText; |
23 |
import android.widget.ImageView; |
|
24 | 24 |
import android.widget.ListView; |
25 | 25 |
import android.widget.TextView; |
26 | 26 |
|
... | ... | |
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
if(state.containsKey("loadingFiles") && state.getBoolean("loadingFiles")){ |
106 |
Log.d("info", "up here"); |
|
107 | 106 |
loadFiles(); |
108 | 107 |
} |
109 | 108 |
else if(state.containsKey("container")){ |
110 |
Log.d("info", "down here"); |
|
111 | 109 |
files = (ContainerObjects[]) state.getSerializable("container"); |
112 | 110 |
if (app.getCurFiles() == null || app.getCurFiles().size() == 0) { |
113 | 111 |
displayNoFilesCell(); |
... | ... | |
520 | 518 |
parent, false); |
521 | 519 |
|
522 | 520 |
TextView label = (TextView) row.findViewById(R.id.label); |
523 |
//label.setText(file.getCName()); |
|
524 | 521 |
label.setText(getShortName(file.getCName())); |
525 | 522 |
|
523 |
ImageView objectImage = (ImageView) row.findViewById(R.id.file_type_image); |
|
524 |
if(file.getContentType().equals("application/directory")){ |
|
525 |
objectImage.setImageResource(R.drawable.folder); |
|
526 |
} else { |
|
527 |
objectImage.setImageResource(R.drawable.file); |
|
528 |
} |
|
529 |
|
|
526 | 530 |
if (file.getBytes() >= bConver) { |
527 | 531 |
megaBytes = Math.abs(file.getBytes() / bConver + 0.2); |
528 | 532 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
b/src/com/rackspacecloud/android/SharedVipActivity.java | ||
---|---|---|
1 | 1 |
package com.rackspacecloud.android; |
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 |
import java.util.Arrays; |
|
5 | 4 |
|
6 | 5 |
import android.content.Intent; |
7 |
import android.graphics.Color; |
|
8 | 6 |
import android.os.AsyncTask; |
9 | 7 |
import android.os.Bundle; |
10 |
import android.view.LayoutInflater; |
|
8 |
import android.util.Log; |
|
9 |
import android.util.TypedValue; |
|
11 | 10 |
import android.view.View; |
12 |
import android.view.ViewGroup; |
|
13 |
import android.widget.ArrayAdapter; |
|
14 |
import android.widget.ListView; |
|
15 |
import android.widget.TextView; |
|
11 |
import android.view.View.OnClickListener; |
|
12 |
import android.widget.Button; |
|
13 |
import android.widget.RadioButton; |
|
14 |
import android.widget.RadioGroup; |
|
15 |
import android.widget.RadioGroup.OnCheckedChangeListener; |
|
16 | 16 |
|
17 | 17 |
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancer; |
18 | 18 |
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancerManager; |
19 | 19 |
import com.rackspace.cloud.loadbalancer.api.client.VirtualIp; |
20 | 20 |
import com.rackspace.cloud.loadbalancer.api.client.http.LoadBalancersException; |
21 | 21 |
|
22 |
public class SharedVipActivity extends CloudListActivity {
|
|
22 |
public class SharedVipActivity extends CloudActivity { |
|
23 | 23 |
|
24 |
private LoadBalancer[] loadBalancers; |
|
25 | 24 |
private VirtualIp[] vips; |
26 | 25 |
private String loadBalancerPort; |
27 | 26 |
private String loadBalancerRegion; |
28 | 27 |
private VirtualIp selectedVip; |
29 |
|
|
28 |
private RadioGroup vipGroup; |
|
29 |
|
|
30 | 30 |
@Override |
31 | 31 |
public void onCreate(Bundle savedInstanceState) { |
32 | 32 |
super.onCreate(savedInstanceState); |
... | ... | |
36 | 36 |
selectedVip = (VirtualIp) this.getIntent().getExtras().get("selectedVip"); |
37 | 37 |
restoreState(savedInstanceState); |
38 | 38 |
} |
39 |
|
|
39 |
|
|
40 | 40 |
@Override |
41 | 41 |
protected void onSaveInstanceState(Bundle outState) { |
42 | 42 |
super.onSaveInstanceState(outState); |
43 |
outState.putSerializable("loadBalancers", loadBalancers); |
|
43 |
outState.putSerializable("vips", vips); |
|
44 |
outState.putSerializable("selectedVip", selectedVip); |
|
44 | 45 |
} |
45 | 46 |
|
46 | 47 |
protected void restoreState(Bundle state) { |
47 | 48 |
super.restoreState(state); |
49 |
|
|
50 |
setupButton(); |
|
51 |
|
|
52 |
vipGroup = (RadioGroup) findViewById(R.id.vip_group); |
|
53 |
|
|
54 |
if(state != null && state.containsKey("selectedVip")){ |
|
55 |
selectedVip = (VirtualIp) state.getSerializable("selectedVip"); |
|
56 |
} |
|
48 | 57 |
|
49 |
if (state != null && state.containsKey("loadBalancers") && state.getSerializable("loadBalancers") != null) {
|
|
50 |
loadBalancers = (LoadBalancer[]) state.getSerializable("loadBalancers");
|
|
51 |
if (loadBalancers.length == 0) {
|
|
52 |
displayNoLoadBalancerCell();
|
|
58 |
if (state != null && state.containsKey("vips") && state.getSerializable("vips") != null) {
|
|
59 |
vips = (VirtualIp[]) state.getSerializable("vips");
|
|
60 |
if (vips.length == 0) {
|
|
61 |
displayNoVipsCell();
|
|
53 | 62 |
} else { |
54 |
getListView().setDividerHeight(1); // restore divider lines |
|
55 |
setListAdapter(new VirtualIpAdapter()); |
|
63 |
displayRadioButtons(); |
|
56 | 64 |
} |
57 | 65 |
} else { |
58 |
loadLoadBalancers();
|
|
66 |
loadVirtualIps();
|
|
59 | 67 |
} |
60 | 68 |
} |
69 |
|
|
70 |
private void setupButton(){ |
|
71 |
Button submit = (Button) findViewById(R.id.select_vip_button); |
|
72 |
submit.setOnClickListener(new OnClickListener() { |
|
73 |
|
|
74 |
@Override |
|
75 |
public void onClick(View v) { |
|
76 |
Intent viewIntent = new Intent(); |
|
77 |
viewIntent.putExtra("selectedVip", selectedVip); |
|
78 |
setResult(RESULT_OK, viewIntent); |
|
79 |
finish(); |
|
80 |
} |
|
81 |
}); |
|
82 |
} |
|
61 | 83 |
|
62 |
private void displayNoLoadBalancerCell() {
|
|
63 |
String a[] = new String[1]; |
|
84 |
private void displayNoVipsCell() {
|
|
85 |
/* String a[] = new String[1];
|
|
64 | 86 |
a[0] = "No Load Balancers"; |
65 | 87 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.noloadbalancerscell, R.id.no_loadbalancers_label, a)); |
66 | 88 |
getListView().setTextFilterEnabled(true); |
67 | 89 |
getListView().setDividerHeight(0); // hide the dividers so it won't look like a list row |
68 | 90 |
getListView().setItemsCanFocus(false); |
91 |
*/ |
|
69 | 92 |
} |
70 |
|
|
93 |
|
|
94 |
private void displayRadioButtons(){ |
|
95 |
for(VirtualIp vip : vips){ |
|
96 |
RadioButton button = new RadioButton(getContext()); |
|
97 |
//Display the load balancer info next to the radio |
|
98 |
//buttons |
|
99 |
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); |
|
100 |
button.setText(vip.getAddress() + "\n" + |
|
101 |
"Type: " + vip.getType() + "\n" + |
|
102 |
"Load Balancer: " + vip.getLoadBalancer().getName() + "\n"); |
|
103 |
|
|
104 |
//if can't add vip make it unselectable |
|
105 |
if((vip.getLoadBalancer().getPort().equals(loadBalancerPort) |
|
106 |
|| !vip.getLoadBalancer().getRegion().equals(loadBalancerRegion))){ |
|
107 |
button.setEnabled(false); |
|
108 |
} |
|
109 |
vipGroup.addView(button); |
|
110 |
if(selectedVip != null && selectedVip.getId().equals(vip.getId())){ |
|
111 |
((RadioButton)vipGroup.getChildAt(vipGroup.getChildCount() - 1)).toggle(); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
vipGroup.setOnCheckedChangeListener (new OnCheckedChangeListener() { |
|
116 |
|
|
117 |
@Override |
|
118 |
public void onCheckedChanged(RadioGroup group, int checkedId) { |
|
119 |
|
|
120 |
View radioButton = group.findViewById(checkedId); |
|
121 |
int index = group.indexOfChild(radioButton); |
|
122 |
|
|
123 |
if(vips[index].getLoadBalancer().getPort().equals(loadBalancerPort)){ |
|
124 |
showToast("Cannot use this Virtual IP. The same port cannot be used on multiple load balancers for a Shared Virtual IP."); |
|
125 |
} else if(!vips[index].getLoadBalancer().getRegion().equals(loadBalancerRegion)){ |
|
126 |
showToast("Cannot use this Virtual IP. The Shared Virtual IP must come the same region as the new load balancer."); |
|
127 |
} else { |
|
128 |
Log.d("info", "the selected vip is " + vips[index].getAddress()); |
|
129 |
selectedVip = vips[index]; |
|
130 |
} |
|
131 |
} |
|
132 |
}); |
|
133 |
|
|
134 |
} |
|
135 |
|
|
71 | 136 |
private void setLoadBalancersList(ArrayList<VirtualIp> vips) { |
72 | 137 |
if (vips == null) { |
73 | 138 |
vips = new ArrayList<VirtualIp>(); |
74 | 139 |
} |
75 |
|
|
140 |
|
|
76 | 141 |
this.vips = new VirtualIp[vips.size()]; |
77 | 142 |
|
78 | 143 |
if (vips != null) { |
... | ... | |
83 | 148 |
} |
84 | 149 |
|
85 | 150 |
if (this.vips.length == 0) { |
86 |
displayNoLoadBalancerCell();
|
|
151 |
displayNoVipsCell();
|
|
87 | 152 |
} else { |
88 |
getListView().setDividerHeight(1); // restore divider lines |
|
89 |
setListAdapter(new VirtualIpAdapter()); |
|
153 |
displayRadioButtons(); |
|
90 | 154 |
} |
91 | 155 |
} |
92 |
|
|
93 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
|
94 |
/* |
|
95 |
* only allow clicks on vips that do not have the same port |
|
96 |
* as the lb and are in same region |
|
97 |
*/ |
|
98 |
if (vips != null && vips.length > 0) { |
|
99 |
if(vips[position].getLoadBalancer().getPort().equals(loadBalancerPort)){ |
|
100 |
showToast("Cannot use this Virtual IP. The same port cannot be used on multiple load balancers for a Shared Virtual IP."); |
|
101 |
} else if(!vips[position].getLoadBalancer().getRegion().equals(loadBalancerRegion)){ |
|
102 |
showToast("Cannot use this Virtual IP. The Shared Virtual IP must come the same region as the new load balancer."); |
|
103 |
} else { |
|
104 |
Intent viewIntent = new Intent(); |
|
105 |
selectedVip = vips[position]; |
|
106 |
viewIntent.putExtra("selectedVip", vips[position]); |
|
107 |
setResult(RESULT_OK, viewIntent); |
|
108 |
//the redisplay will color the users selection white |
|
109 |
setLoadBalancersList(new ArrayList<VirtualIp>(Arrays.asList(vips))); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
// * Adapter/ |
|
115 |
class VirtualIpAdapter extends ArrayAdapter<VirtualIp> { |
|
116 |
|
|
117 |
VirtualIpAdapter() { |
|
118 |
super(SharedVipActivity.this, |
|
119 |
R.layout.sharedvipcell, vips); |
|
120 |
} |
|
121 |
|
|
122 |
public View getView(int position, View convertView, ViewGroup parent) { |
|
123 |
|
|
124 |
VirtualIp virtualIp = vips[position]; |
|
125 |
LayoutInflater inflater = getLayoutInflater(); |
|
126 |
View row = inflater.inflate(R.layout.sharedvipcell, |
|
127 |
parent, false); |
|
128 | 156 |
|
129 |
TextView vipAddress = (TextView) row.findViewById(R.id.vip_address); |
|
130 |
vipAddress.setText(virtualIp.getAddress()); |
|
131 |
|
|
132 |
TextView type = (TextView) row.findViewById(R.id.vip_type); |
|
133 |
type.setText(virtualIp.getType()); |
|
134 |
|
|
135 |
TextView name = (TextView) row.findViewById(R.id.load_balancer_name); |
|
136 |
name.setText(virtualIp.getLoadBalancer().getName()); |
|
137 |
|
|
138 |
TextView protocol = (TextView) row.findViewById(R.id.vip_protocol); |
|
139 |
protocol.setText(virtualIp.getLoadBalancer().getProtocol() |
|
140 |
+ "(" + virtualIp.getLoadBalancer().getPort() + ")"); |
|
141 |
|
|
142 |
//Set the text of the selected vip (if there is one) |
|
143 |
//to white so the user knows what they picked |
|
144 |
boolean isSelected = selectedVip != null && selectedVip.getAddress().equals(vips[position].getAddress()); |
|
145 |
if(isSelected){ |
|
146 |
vipAddress.setTextColor(Color.WHITE); |
|
147 |
type.setTextColor(Color.WHITE); |
|
148 |
name.setTextColor(Color.WHITE); |
|
149 |
protocol.setTextColor(Color.WHITE); |
|
150 |
protocol.setTextColor(Color.WHITE); |
|
151 |
} |
|
152 |
return (row); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
private void loadLoadBalancers() { |
|
157 |
new LoadLoadBalancersTask().execute((Void[]) null); |
|
157 |
private void loadVirtualIps() { |
|
158 |
new LoadVirtualIpsTask().execute((Void[]) null); |
|
158 | 159 |
} |
159 |
|
|
160 |
private class LoadLoadBalancersTask extends AsyncTask<Void, Void, ArrayList<LoadBalancer>> {
|
|
160 |
|
|
161 |
private class LoadVirtualIpsTask extends AsyncTask<Void, Void, ArrayList<LoadBalancer>> {
|
|
161 | 162 |
private LoadBalancersException exception; |
162 |
|
|
163 |
|
|
163 | 164 |
@Override |
164 | 165 |
protected void onPreExecute(){ |
165 | 166 |
showDialog(); |
166 | 167 |
} |
167 |
|
|
168 |
|
|
168 | 169 |
@Override |
169 | 170 |
protected ArrayList<LoadBalancer> doInBackground(Void... arg0) { |
170 | 171 |
ArrayList<LoadBalancer> loadBalancers = null; |
... | ... | |
175 | 176 |
} |
176 | 177 |
return loadBalancers; |
177 | 178 |
} |
178 |
|
|
179 |
|
|
179 | 180 |
@Override |
180 | 181 |
protected void onPostExecute(ArrayList<LoadBalancer> result) { |
181 | 182 |
hideDialog(); |
... | ... | |
186 | 187 |
setLoadBalancersList(vipList); |
187 | 188 |
} |
188 | 189 |
} |
189 |
|
|
190 |
|
|
190 | 191 |
private ArrayList<VirtualIp> getVipList(ArrayList<LoadBalancer> result){ |
191 | 192 |
ArrayList<VirtualIp> vips = new ArrayList<VirtualIp>(); |
192 | 193 |
for(LoadBalancer lb : result){ |
... | ... | |
197 | 198 |
} |
198 | 199 |
return vips; |
199 | 200 |
} |
200 |
|
|
201 |
|
|
201 | 202 |
} |
Also available in: Unified diff