re-classify bg update
authorEugene Crosser <crosser@average.org>
Mon, 30 Jan 2012 07:40:22 +0000 (11:40 +0400)
committerEugene Crosser <crosser@average.org>
Mon, 30 Jan 2012 07:40:22 +0000 (11:40 +0400)
src/org/average/whereami/WhereAmI.java

index 9d012c35997d4f4b11d625b678b0879ca3ce1e1a..5a665d1ed02346e3eae46830b3ebf9558eef60dd 100644 (file)
@@ -26,11 +26,44 @@ public class WhereAmI extends Activity
     private Integer runningtasks = 0;
 
     private class UpdateTarget {
-        public TextView tv;
-        public Integer updater; // will be the function/object
+        private TextView tv;
+        private Integer updater; // will be the function/object
+        private BgUpdate task;
+
+        private class BgUpdate extends AsyncTask<Void, Void, String> {
+            @Override
+            protected String doInBackground(Void... params) {
+                Log.w("WhereAmI", "BgUpdate " + updater + " starting");
+                SystemClock.sleep(5000); // real job do be done here
+                Log.w("WhereAmI", "BgUpdate about to return");
+                return "5 seconds passed in " + updater;
+            }
+        
+            @Override
+            protected void onPostExecute(String str) {
+                Log.w("WhereAmI", "BgUpdate callback executing");
+                tv.setText(str);
+                runningtasks--;
+                if (runningtasks <= 0) {
+                    boolean wifion = wifiman.setWifiEnabled(false);
+                    Log.w("WhereAmI", "disabling wifi result " + wifion);
+                    Time tm = new Time();
+                    tm.setToNow();
+                    tvs.setText(R.string.lasttry);
+                    tvs.append(tm.format(" %d/%m/%Y %H:%M:%S"));
+                }
+            }
+        }
+
         public UpdateTarget(TextView tv, Integer updater) {
-           this.tv = tv;
-           this.updater = updater;
+            this.tv = tv;
+            this.updater = updater;
+            this.task = new BgUpdate();
+        }
+
+        public void launch() {
+            tv.setText(R.string.updating);
+            task.execute();
         }
     }
     private UpdateTarget[] ut;
@@ -83,7 +116,7 @@ public class WhereAmI extends Activity
             boolean wifion = wifiman.setWifiEnabled(true);
             Log.w("WhereAmI", "enabling wifi result " + wifion);
             mHandler.postDelayed(resetInfo, 30000);
-            mHandler.postDelayed(this, 60000);
+            mHandler.postDelayed(this, 1200000);
         }
     };
 
@@ -114,40 +147,12 @@ public class WhereAmI extends Activity
             if (isConnected) {
                 for (int i = 0; i < ut.length; i++) {
                     runningtasks++;
-                    ut[i].tv.setText(R.string.updating);
-                    new BgUpdate().execute(ut[i]);
+                    ut[i].launch();
                 }
             }
         }
     };
 
-    private class BgUpdate extends AsyncTask<UpdateTarget, Void, String> {
-        private UpdateTarget ut;
-       @Override
-        protected String doInBackground(UpdateTarget... whereto) {
-            Log.w("WhereAmI", "BgUpdate starting");
-            ut = whereto[0];
-            SystemClock.sleep(5000); // real job do be done here
-            Log.w("WhereAmI", "BgUpdate about to return");
-            return "5 seconds passed";
-        }
-    
-       @Override
-        protected void onPostExecute(String str) {
-            Log.w("WhereAmI", "BgUpdate callback executing");
-            ut.tv.setText(str);
-            runningtasks--;
-            if (runningtasks <= 0) {
-                boolean wifion = wifiman.setWifiEnabled(false);
-                Log.w("WhereAmI", "disabling wifi result " + wifion);
-                Time tm = new Time();
-                tm.setToNow();
-                tvs.setText(R.string.lasttry);
-                tvs.append(tm.format(" %d/%m/%Y %H:%M:%S"));
-            }
-        }
-    }
-
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
@@ -183,7 +188,7 @@ public class WhereAmI extends Activity
     {
         super.onPause();
         Log.w("WhereAmI", "calling finish");
-        this.finish();
+        finish();
     }
 
     /** Called when the activity is destroyed. */