root / src / com / rackspacecloud / android / ViewLoadBalancerActivity.java @ 23bc5e75
History | View | Annotate | Download (6.5 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspacecloud.android; |
5 |
|
6 |
import java.util.ArrayList; |
7 |
|
8 |
import android.app.Activity; |
9 |
import android.app.AlertDialog; |
10 |
import android.app.ProgressDialog; |
11 |
import android.content.DialogInterface; |
12 |
import android.os.AsyncTask; |
13 |
import android.os.Bundle; |
14 |
import android.util.Log; |
15 |
import android.view.WindowManager; |
16 |
import android.view.ViewGroup.LayoutParams; |
17 |
import android.widget.ProgressBar; |
18 |
import android.widget.TextView; |
19 |
|
20 |
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancer; |
21 |
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancerManager; |
22 |
import com.rackspace.cloud.loadbalancers.api.client.http.LoadBalancersException; |
23 |
|
24 |
public class ViewLoadBalancerActivity extends Activity { |
25 |
private LoadBalancer loadBalancer;
|
26 |
private LoadBalancer returnLoadBalancer;
|
27 |
ProgressDialog pDialog; |
28 |
|
29 |
@Override
|
30 |
public void onCreate(Bundle savedInstanceState) { |
31 |
super.onCreate(savedInstanceState);
|
32 |
loadBalancer = (LoadBalancer) this.getIntent().getExtras().get("loadBalancer"); |
33 |
Log.i("VIEWLOADBALANCERS: ", loadBalancer.getAlgorithm() +","+loadBalancer.getProtocol()+","+loadBalancer.getStatus()); |
34 |
|
35 |
setContentView(R.layout.view_loadbalancer); |
36 |
restoreState(savedInstanceState); |
37 |
} |
38 |
|
39 |
@Override
|
40 |
protected void onSaveInstanceState(Bundle outState) { |
41 |
super.onSaveInstanceState(outState);
|
42 |
outState.putSerializable("loadBalancer", loadBalancer);
|
43 |
} |
44 |
|
45 |
private void restoreState(Bundle state) { |
46 |
if (state != null && state.containsKey("loadBalancer")) { |
47 |
loadBalancer = (LoadBalancer) state.getSerializable("loadBalancer");
|
48 |
} |
49 |
new LoadLoadBalancerTask().execute((Void[]) null); |
50 |
} |
51 |
|
52 |
private void loadLoadBalancerData() { |
53 |
TextView name = (TextView) findViewById(R.id.view_name); |
54 |
name.setText(returnLoadBalancer.getName()); |
55 |
|
56 |
TextView id = (TextView) findViewById(R.id.view_lb_id); |
57 |
id.setText(returnLoadBalancer.getId()); |
58 |
|
59 |
TextView protocol = (TextView) findViewById(R.id.view_protocol); |
60 |
protocol.setText(returnLoadBalancer.getProtocol()); |
61 |
|
62 |
TextView port = (TextView) findViewById(R.id.view_port); |
63 |
port.setText(returnLoadBalancer.getPort()); |
64 |
|
65 |
TextView algorithm = (TextView) findViewById(R.id.view_algorithm); |
66 |
algorithm.setText(returnLoadBalancer.getAlgorithm()); |
67 |
|
68 |
TextView status = (TextView) findViewById(R.id.view_status); |
69 |
status.setText(returnLoadBalancer.getStatus()); |
70 |
|
71 |
TextView connectionLogging = (TextView) findViewById(R.id.view_islogging); |
72 |
connectionLogging.setText(returnLoadBalancer.getIsConnectionLoggingEnabled()); |
73 |
|
74 |
loadVirutalIpData(); |
75 |
} |
76 |
|
77 |
private void loadVirutalIpData() { |
78 |
TextView vipId = (TextView) findViewById(R.id.view_vip_id); |
79 |
vipId.setText(returnLoadBalancer.getVirtualIps().get(0).getId());
|
80 |
|
81 |
TextView address = (TextView) findViewById(R.id.view_vip_address); |
82 |
address.setText(returnLoadBalancer.getVirtualIps().get(0).getAddress());
|
83 |
|
84 |
TextView ipVersion = (TextView) findViewById(R.id.view_ipversion); |
85 |
ipVersion.setText(returnLoadBalancer.getVirtualIps().get(0).getIpVersion());
|
86 |
|
87 |
TextView type = (TextView) findViewById(R.id.view_vip_type); |
88 |
type.setText(returnLoadBalancer.getVirtualIps().get(0).getType());
|
89 |
|
90 |
loadNodeData(); |
91 |
} |
92 |
|
93 |
private void loadNodeData() { |
94 |
TextView nodeID = (TextView) findViewById(R.id.view_node_id); |
95 |
nodeID.setText(returnLoadBalancer.getNodes().get(0).getId());
|
96 |
|
97 |
TextView address = (TextView) findViewById(R.id.view_node_address); |
98 |
address.setText(returnLoadBalancer.getNodes().get(0).getAddress());
|
99 |
|
100 |
TextView nodePort = (TextView) findViewById(R.id.view_node_port); |
101 |
nodePort.setText(returnLoadBalancer.getNodes().get(0).getPort());
|
102 |
|
103 |
TextView condition = (TextView) findViewById(R.id.view_node_condition); |
104 |
condition.setText(returnLoadBalancer.getNodes().get(0).getCondition());
|
105 |
|
106 |
TextView nodeStatus = (TextView) findViewById(R.id.view_node_status); |
107 |
nodeStatus.setText(returnLoadBalancer.getNodes().get(0).getStatus());
|
108 |
|
109 |
} |
110 |
|
111 |
// HTTP request tasks
|
112 |
private class PollServerTask extends AsyncTask<Void, Void, LoadBalancer> { |
113 |
|
114 |
@Override
|
115 |
protected LoadBalancer doInBackground(Void... arg0) { |
116 |
try {
|
117 |
returnLoadBalancer = (new LoadBalancerManager()).getLoadBalncerById(Integer.parseInt(loadBalancer.getId())); |
118 |
} catch (NumberFormatException e) { |
119 |
// we're polling, so need to show exceptions
|
120 |
} catch (LoadBalancersException e) {
|
121 |
// we're polling, so need to show exceptions
|
122 |
} |
123 |
return returnLoadBalancer;
|
124 |
} |
125 |
|
126 |
@Override
|
127 |
protected void onPostExecute(LoadBalancer result) { |
128 |
returnLoadBalancer = result; |
129 |
loadLoadBalancerData(); |
130 |
} |
131 |
} |
132 |
|
133 |
private class LoadLoadBalancerTask extends AsyncTask<Void, Void, LoadBalancer> { |
134 |
private LoadBalancersException exception;
|
135 |
|
136 |
protected void onPreExecute() { |
137 |
Log.d("rscloudactivity", " pre execute async"); |
138 |
showDialog(); |
139 |
} |
140 |
|
141 |
@Override
|
142 |
protected LoadBalancer doInBackground(Void... arg0) { |
143 |
try {
|
144 |
returnLoadBalancer = (new LoadBalancerManager()).getLoadBalncerById(Integer.parseInt(loadBalancer.getId())); |
145 |
} catch (LoadBalancersException e) {
|
146 |
exception = e; |
147 |
} |
148 |
pDialog.dismiss(); |
149 |
return returnLoadBalancer;
|
150 |
} |
151 |
|
152 |
@Override
|
153 |
protected void onPostExecute(LoadBalancer result) { |
154 |
if (exception != null) { |
155 |
pDialog.dismiss(); |
156 |
showAlert("Error", exception.getMessage());
|
157 |
} |
158 |
pDialog.dismiss(); |
159 |
returnLoadBalancer = result; |
160 |
loadLoadBalancerData(); |
161 |
} |
162 |
} |
163 |
|
164 |
private void showAlert(String title, String message) { |
165 |
// Can't create handler inside thread that has not called
|
166 |
// Looper.prepare()
|
167 |
// Looper.prepare();
|
168 |
try {
|
169 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
170 |
alert.setTitle(title); |
171 |
alert.setMessage(message); |
172 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
173 |
public void onClick(DialogInterface dialog, int which) { |
174 |
return;
|
175 |
} |
176 |
}); |
177 |
alert.show(); |
178 |
} catch (Exception e) { |
179 |
e.printStackTrace(); |
180 |
} |
181 |
} |
182 |
|
183 |
protected void showDialog() { |
184 |
pDialog = new ProgressDialog(this, R.style.NewDialog); |
185 |
// // Set blur to background
|
186 |
WindowManager.LayoutParams lp = pDialog.getWindow().getAttributes(); |
187 |
lp.dimAmount = 0.0f;
|
188 |
pDialog.getWindow().setAttributes(lp); |
189 |
pDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
190 |
pDialog.show(); |
191 |
pDialog.setContentView(new ProgressBar(this), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); |
192 |
} |
193 |
} |