2011-10-24 Miguel de Dios <miguel.dedios@artica.es>

* android/src/pandroid/agent/PandroidAgentListener.java: fixed the
	location and change to show the percent memory free.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5078 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-10-24 16:32:14 +00:00
parent 102b59b68e
commit 2f7a45d01a
2 changed files with 39 additions and 23 deletions

View File

@ -1,3 +1,8 @@
2011-10-24 Miguel de Dios <miguel.dedios@artica.es>
* android/src/pandroid/agent/PandroidAgentListener.java: fixed the
location and change to show the percent memory free.
2011-10-24 Junichi Satoh <junichi@rworks.jp> 2011-10-24 Junichi Satoh <junichi@rworks.jp>
* android/res/values-ja/strings.xml: Added Japanese strings. * android/res/values-ja/strings.xml: Added Japanese strings.

View File

@ -19,12 +19,12 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.text.DecimalFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.http.entity.StringEntity;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
@ -50,8 +50,6 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
public class PandroidAgentListener extends Service { public class PandroidAgentListener extends Service {
@ -181,8 +179,8 @@ public class PandroidAgentListener extends Service {
buffer += buildmoduleXML("proximity", "The actually device proximity detector (0/1)", "generic_data", proximity); buffer += buildmoduleXML("proximity", "The actually device proximity detector (0/1)", "generic_data", proximity);
} }
/*
if (taskStatus.equals("enabled")) { if (taskStatus.equals("enabled")) {
buffer += buildmoduleXML("taskStatus", "The Pandroid configuration watch task.", "generic_proc", "1");
buffer += buildmoduleXML("taskHumanName", "The task's human name.", "async_string", taskHumanName); buffer += buildmoduleXML("taskHumanName", "The task's human name.", "async_string", taskHumanName);
buffer += buildmoduleXML("task", "The task's package name.", "async_string", task); buffer += buildmoduleXML("task", "The task's package name.", "async_string", task);
if (taskRun.equals("true")) { if (taskRun.equals("true")) {
@ -192,17 +190,15 @@ public class PandroidAgentListener extends Service {
buffer += buildmoduleXML("taskRun", "The task is running.", "async_proc", "0"); buffer += buildmoduleXML("taskRun", "The task is running.", "async_proc", "0");
} }
} }
else { */
buffer += buildmoduleXML("taskStatus", "The Pandroid configuration watch task.", "generic_proc", "0");
}
if (memoryStatus.equals("enabled")) { if (memoryStatus.equals("enabled")) {
buffer += buildmoduleXML("memoryStatus", "The Pandroid configuration watch memory.", "async_proc", "1");
buffer += buildmoduleXML("availableRamKb", "The available ram in Kb of device.", "async_data", availableRamKb); Float freeMemory = new Float((Float.valueOf(availableRamKb) / Float.valueOf(totalRamKb)) * 100.0);
buffer += buildmoduleXML("totalRamKb", "The total ram in Kb of device.", "async_data", totalRamKb);
} DecimalFormat formatPercent = new DecimalFormat("#.##");
else { buffer += buildmoduleXML("freeRamMemory", "The available ram in percent value.", "async_data",
buffer += buildmoduleXML("memoryStatus", "The Pandroid configuration watch memory.", "async_proc", "1"); formatPercent.format(freeMemory.doubleValue()));
} }
//buffer += buildmoduleXML("last_gps_contact", "Datetime of the last geo-location contact", "generic_data", lastGpsContactDateTime); //buffer += buildmoduleXML("last_gps_contact", "Datetime of the last geo-location contact", "generic_data", lastGpsContactDateTime);
@ -246,16 +242,19 @@ public class PandroidAgentListener extends Service {
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
List<String> providers = lm.getProviders(true); List<String> providers = lm.getProviders(true);
Log.e("PANDROID providers count", "" + providers.size());
/* Loop over the array backwards, and if you get an accurate location, then break out the loop*/ /* Loop over the array backwards, and if you get an accurate location, then break out the loop*/
Location loc = null; Location loc = null;
for (int i=providers.size()-1; i>=0; i--) { for (int i=providers.size()-1; i>=0; i--) {
Log.e("PANDROID providers", providers.get(i));
loc = lm.getLastKnownLocation(providers.get(i)); loc = lm.getLastKnownLocation(providers.get(i));
if (loc != null) break; if (loc != null) break;
} }
if (loc != null) { if (loc != null) {
Log.e("PANDROID", "loc != null");
//if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) { //if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) {
lastGpsContactDateTime = getHumanDateTime(-1); lastGpsContactDateTime = getHumanDateTime(-1);
//} //}
@ -270,16 +269,26 @@ public class PandroidAgentListener extends Service {
criteria.setBearingRequired(false); criteria.setBearingRequired(false);
criteria.setCostAllowed(true); criteria.setCostAllowed(true);
String bestProvider = lm.getBestProvider(criteria, true); String bestProvider = lm.getBestProvider(criteria, true);
loc = lm.getLastKnownLocation(bestProvider);
if(loc != null) { lm.requestLocationUpdates(bestProvider, defaultInterval, 1000,
putSharedData("PANDROID_DATA", "latitude", new Double(loc.getLatitude()).toString(), "float"); new LocationListener() {
putSharedData("PANDROID_DATA", "longitude", new Double(loc.getLongitude()).toString(), "float"); public void onLocationChanged(Location location) {
} putSharedData("PANDROID_DATA", "latitude",
else { new Double(location.getLatitude()).toString(), "float");
putSharedData("PANDROID_DATA", "latitude", "181", "float"); putSharedData("PANDROID_DATA", "longitude",
putSharedData("PANDROID_DATA", "longitude", "181", "float"); new Double(location.getLongitude()).toString(), "float");
} }
public void onStatusChanged(String s, int i, Bundle bundle) {
}
public void onProviderEnabled(String s) {
// try switching to a different provider
}
public void onProviderDisabled(String s) {
putSharedData("PANDROID_DATA", "enabled_location_provider",
"disabled", "string");
}
});
} }
} }
@ -368,9 +377,11 @@ public class PandroidAgentListener extends Service {
String gpsStatus = getSharedData("PANDROID_DATA", "gpsStatus", defaultGpsStatus, "string"); String gpsStatus = getSharedData("PANDROID_DATA", "gpsStatus", defaultGpsStatus, "string");
if(gpsStatus.equals("enabled")) { if(gpsStatus.equals("enabled")) {
Log.e("PANDROID AGENT", "ENABLED");
gpsLocation(); gpsLocation();
} }
else { else {
Log.e("PANDROID AGENT", "DISABLED");
putSharedData("PANDROID_DATA", "latitude", "181.0", "float"); putSharedData("PANDROID_DATA", "latitude", "181.0", "float");
putSharedData("PANDROID_DATA", "longitude", "181.0", "float"); putSharedData("PANDROID_DATA", "longitude", "181.0", "float");
} }