Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r410 committed - Fix errors around service creation, now seeing problems updating UI fr...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r410 committed - Fix errors around service creation, now seeing problems updating UI fr...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r410 committed - Fix errors around service creation, now seeing problems updating UI fr...
  • Date: Tue, 05 Jul 2011 19:54:09 +0000

Revision: 410
Author:

Date: Tue Jul 5 12:53:24 2011
Log: Fix errors around service creation, now seeing problems updating UI from separate thread.
http://code.google.com/p/ndt/source/detail?r=410

Modified:
/branches/android/Android/src/net/measurementlab/ndt/NdtService.java
/branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java

=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Tue Jul 5 12:19:32 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Tue Jul 5 12:53:24 2011
@@ -13,6 +13,10 @@
public static final int COMPLETE = 3;

private TestReporter testReporter = new TestReporter();
+
+ private String networkType;
+
+ private boolean testRunning;

@Override
public IBinder onBind(Intent intent) {
@@ -30,15 +34,17 @@
public void onStart(Intent intent, int startId) {
Log.i("ndt", "Starting NDT service.");
super.onStart(intent, startId);
- if (null == intent) {
- throw new IllegalArgumentException("Intent was
null!");
+ if (testRunning) {
+ return;
+ }
+ if (null != intent) {
+ networkType = intent.getStringExtra("networkType");
}
try {
+ testRunning = true;
new Thread(new NdtTests(

Constants.SERVER_HOST[Constants.DEFAULT_SERVER],
- new CaptiveUiServices(), intent
-
.getStringExtra("networkType"))).start();
- testReporter.setState(COMPLETE);
+ new CaptiveUiServices(),
networkType)).start();
} catch (Throwable tr) {
Log.e("ndt", "Problem running tests.", tr);
}
@@ -70,15 +76,20 @@
Log.d("ndt", String.format("Appended: (%1$d) %2$s.",
viewId, str
.trim()));

- if (str.contains("client-to-server") && UPLOADING ==
viewId) {
+ if (str.contains("client-to-server") && 0 == viewId) {
Log.i("ndt", "Starting upload test.");
testReporter.setState(UPLOADING);
}

- if (str.contains("server-to-client") && DOWNLOADING
== viewId) {
+ if (str.contains("server-to-client") && 0 == viewId) {
Log.i("ndt", "Starting upload test.");
testReporter.setState(DOWNLOADING);
}
+
+ if (str.contains("Test ended") && 0 == viewId) {
+ Log.i("ndt", "Starting upload test.");
+ testReporter.setState(COMPLETE);
+ }
}

@Override
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java Tue Jul 5 12:19:32 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java Tue Jul 5 12:53:24 2011
@@ -65,19 +65,29 @@

running = true;
new Thread() {
+
@Override
public void run() {
try {
while (true == running && (null == testReporter || NdtService.COMPLETE != testReporter.getState())) {
-
TimeUnit.MILLISECONDS.sleep(500l);
- Log.i("ndt", String.format(
+ TimeUnit.SECONDS.sleep(1l);
+ Log.d("ndt", String.format(
"Checking test
state, %1$d.",
(null ==
testReporter) ? -1 : testReporter

.getState()));
- // TODO need stop when
activity is paused
- }
- TextView textView = (TextView) findViewById(R.id.NdtServerLocationLabel);
- textView.setText("Complete!");
+ switch ((null ==
testReporter) ? 0 : testReporter.getState()) {
+ case NdtService.PREPARING:
+
updateHeader("Preparing...");
+ break;
+ case NdtService.UPLOADING:
+ updateHeader("Testing
upload...");
+ break;
+ case NdtService.DOWNLOADING:
+ updateHeader("Testing
download...");
+ break;
+ }
+ }
+ updateHeader("Test complete.");
} catch (RemoteException e) {
Log.e("ndt", "Error in busy-wait
loop.", e);
} catch (InterruptedException e) {
@@ -113,6 +123,11 @@
super.onDestroy();
running = false;
}
+
+ private void updateHeader(String labelText) {
+ TextView textView = (TextView)
findViewById(R.id.NdtServerLocationLabel);
+ textView.setText(labelText);
+ }

private String getNetworkType() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);


  • [ndt-dev] [ndt] r410 committed - Fix errors around service creation, now seeing problems updating UI fr..., ndt, 07/05/2011

Archive powered by MHonArc 2.6.16.

Top of Page