diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index 4fcbfd9132..5ca79a63ea 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,27 @@ +2011-02-07 Sergio Martin + + * android/AndroidManifest.xml + android/src/pandroid/agent/PandroidAgent.java + android/src/pandroid/agent/PandroidAgentListener.java + android/bin/pandroid/agent/PandroidAgentListener$2.class + android/bin/pandroid/agent/PandroidAgentListener$3.class + android/bin/pandroid/agent/PandroidAgentListener$MyLocationListener.class + android/bin/pandroid/agent/PandroidAgentListener$1.class + android/bin/pandroid/agent/PandroidAgent.class + android/bin/pandroid/agent/PandroidAgentListener.class + android/bin/pandroid/agent/PandroidAgent$1.class + android/bin/pandroid/agent/PandroidAgent$2.class + android/bin/pandroid/agent/PandroidAgent$3.class + android/bin/pandroid/agent/PandroidAgent$4.class + android/bin/pandroid/agent/PandroidAgent$5.class + android/bin/pandroid/agent/PandroidAgent$6.class + android/bin/pandroid/agent/PandroidAgent$7.class + android/bin/resources.ap_ + android/bin/classes.dex + android/res/drawable-hdpi/icon.png: Clean the code, changed the + app icon, added modules to the proximity and orientation sensors + and fixed little bugs + 2011-02-03 Ramon Novoa * win32/installer/pandora.mpi, win32/pandora.cc, unix/pandora_agent: Free diff --git a/pandora_agents/android/AndroidManifest.xml b/pandora_agents/android/AndroidManifest.xml index 0cb69e59c5..51dff20b8b 100755 --- a/pandora_agents/android/AndroidManifest.xml +++ b/pandora_agents/android/AndroidManifest.xml @@ -5,7 +5,8 @@ android:versionName="1.0"> + android:label="@string/app_name" + android:configChanges="keyboardHidden|orientation"> @@ -18,4 +19,8 @@ + + + + \ No newline at end of file diff --git a/pandora_agents/android/bin/classes.dex b/pandora_agents/android/bin/classes.dex index 7caa7306f8..dfdc277334 100755 Binary files a/pandora_agents/android/bin/classes.dex and b/pandora_agents/android/bin/classes.dex differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$1.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$1.class index 398311ea03..c5c705bc5b 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$1.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$1.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$2.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$2.class index 8820bc37ec..148fc9df34 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$2.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$2.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$3.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$3.class index c5aff10ae3..dc32a131e7 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$3.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$3.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$4.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$4.class index 7cf01dcfe0..474db13213 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$4.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$4.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$5.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$5.class index 6887018452..d3386b9524 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$5.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$5.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$6.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$6.class index bd456dbdf8..b1f219bb44 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$6.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$6.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$7.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$7.class index 000160c4ff..b15e81db97 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent$7.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent$7.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgent.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgent.class index 00d3c7c0b6..1127dd1ab0 100755 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgent.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgent.class differ diff --git a/pandora_agents/android/bin/pandroid/agent/PandroidAgentListener.class b/pandora_agents/android/bin/pandroid/agent/PandroidAgentListener.class index e787d82eb9..d4289b09df 100644 Binary files a/pandora_agents/android/bin/pandroid/agent/PandroidAgentListener.class and b/pandora_agents/android/bin/pandroid/agent/PandroidAgentListener.class differ diff --git a/pandora_agents/android/bin/resources.ap_ b/pandora_agents/android/bin/resources.ap_ index 2126180050..246d37d715 100755 Binary files a/pandora_agents/android/bin/resources.ap_ and b/pandora_agents/android/bin/resources.ap_ differ diff --git a/pandora_agents/android/res/drawable-hdpi/icon.png b/pandora_agents/android/res/drawable-hdpi/icon.png index 8074c4c571..2d43faded0 100755 Binary files a/pandora_agents/android/res/drawable-hdpi/icon.png and b/pandora_agents/android/res/drawable-hdpi/icon.png differ diff --git a/pandora_agents/android/src/pandroid/agent/PandroidAgent.java b/pandora_agents/android/src/pandroid/agent/PandroidAgent.java index acecd98bf8..0dc7bfb86c 100755 --- a/pandora_agents/android/src/pandroid/agent/PandroidAgent.java +++ b/pandora_agents/android/src/pandroid/agent/PandroidAgent.java @@ -14,8 +14,6 @@ import android.view.View.OnClickListener; import android.view.View.OnKeyListener; import android.view.KeyEvent; import android.view.inputmethod.InputMethodManager; -import android.location.Location; -import android.location.LocationListener; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -34,6 +32,8 @@ public class PandroidAgent extends Activity { String defaultAgentName = "pandroidAgent"; String defaultGpsStatus = "disabled"; // "disabled" or "enabled" + boolean alarmEnabled; + boolean showLastXML = true; String lastGpsContactDateTime = ""; @@ -41,14 +41,12 @@ public class PandroidAgent extends Activity { ComponentName service = null; PendingIntent sender = null; AlarmManager am = null; - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.main); - - //resetValues(); - + // Load the stored data into views loadViews(); @@ -61,23 +59,27 @@ public class PandroidAgent extends Activity { // Start the agent listener service //ComponentName service = startService(new Intent(this, PandroidAgentListener.class)); - // Setting an alarm to call service - Intent intentReceiver = new Intent(this, EventReceiver.class); - sender = PendingIntent.getBroadcast(this, 0, intentReceiver, 0); - am = (AlarmManager) getSystemService(ALARM_SERVICE); - - // Start the alert listener - startAgentListener(); - - // Update the UI each second - h.post(new Runnable() { - @Override - public void run() { - updateUI(); - h.postDelayed(this, 1000); - } - }); + if(!alarmEnabled) { + // Setting an alarm to call service + Intent intentReceiver = new Intent(this, EventReceiver.class); + sender = PendingIntent.getBroadcast(this, 0, intentReceiver, 0); + + am = (AlarmManager) getSystemService(ALARM_SERVICE); + + // Start the alert listener + restartAgentListener(); + + // Update the UI each second + h.post(new Runnable() { + @Override + public void run() { + updateUI(); + + h.postDelayed(this, 1000); + } + }); + } } @@ -290,15 +292,18 @@ public class PandroidAgent extends Activity { } } - private void stopAgentListener() { + private void stopAgentListener() { am.cancel(sender); + alarmEnabled = false; } private void startAgentListener() { + alarmEnabled = true; + int interval = Integer.parseInt(getSharedData("PANDROID_DATA", "interval", Integer.toString(defaultInterval), "integer")); // Set the alarm with the interval frequency - am.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), (interval * 1000), sender); + am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (interval * 1000), sender); } private void restartAgentListener() { @@ -338,6 +343,7 @@ public class PandroidAgent extends Activity { if(contactError == 1) { changeContactInfo("Contact error", "#FF0000"); + stopAgentListener(); } else { changeContactInfo("Last Contact: " + stringAgo, "#00FF00"); diff --git a/pandora_agents/android/src/pandroid/agent/PandroidAgentListener.java b/pandora_agents/android/src/pandroid/agent/PandroidAgentListener.java index 06d5d34a10..6f7cfa9f9a 100644 --- a/pandora_agents/android/src/pandroid/agent/PandroidAgentListener.java +++ b/pandora_agents/android/src/pandroid/agent/PandroidAgentListener.java @@ -8,13 +8,21 @@ import android.app.Service; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; +import android.location.Criteria; import android.os.Bundle; import android.os.IBinder; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.hardware.SensorManager; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; + import android.os.Handler; @@ -41,8 +49,12 @@ public class PandroidAgentListener extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); + WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); + wakeLock.acquire(); updateValues(); contact(); + wakeLock.release(); stopSelf(startId); return START_NOT_STICKY; } @@ -85,6 +97,8 @@ public class PandroidAgentListener extends Service { else { putSharedData("PANDROID_DATA", "contactError", "1", "integer"); } + + updateValues(); } private String buildXML(){ @@ -106,6 +120,15 @@ public class PandroidAgentListener extends Service { // Modules buffer += buildmoduleXML("battery_level", "The actually device battery level", "generic_data", getSharedData("PANDROID_DATA", "batteryLevel", "-1", "integer")); + String orientation = getSharedData("PANDROID_DATA", "orientation", "361", "float"); + String proximity = getSharedData("PANDROID_DATA", "proximity", "-1.0", "float"); + + if(!orientation.equals("361.0")) { + buffer += buildmoduleXML("orientation", "The actually device orientation (in degrees)", "generic_data", orientation); + } + if(!proximity.equals("-1.0")) { + buffer += buildmoduleXML("proximity", "The actually device proximity detector (0/1)", "generic_data", proximity); + } //buffer += buildmoduleXML("last_gps_contact", "Datetime of the last geo-location contact", "generic_data", lastGpsContactDateTime); // End_Modules @@ -166,9 +189,24 @@ public class PandroidAgentListener extends Service { putSharedData("PANDROID_DATA", "latitude", new Double(loc.getLatitude()).toString(), "float"); putSharedData("PANDROID_DATA", "longitude", new Double(loc.getLongitude()).toString(), "float"); } - else { - putSharedData("PANDROID_DATA", "latitude", "181", "float"); - putSharedData("PANDROID_DATA", "longitude", "181", "float"); + else { + Criteria criteria = new Criteria(); + criteria.setAccuracy(Criteria.ACCURACY_COARSE); + criteria.setPowerRequirement(Criteria.POWER_LOW); + criteria.setAltitudeRequired(false); + criteria.setBearingRequired(false); + criteria.setCostAllowed(true); + String bestProvider = lm.getBestProvider(criteria, true); + loc = lm.getLastKnownLocation(bestProvider); + if(loc != null) { + putSharedData("PANDROID_DATA", "latitude", new Double(loc.getLatitude()).toString(), "float"); + putSharedData("PANDROID_DATA", "longitude", new Double(loc.getLongitude()).toString(), "float"); + } + else { + putSharedData("PANDROID_DATA", "latitude", "181", "float"); + putSharedData("PANDROID_DATA", "longitude", "181", "float"); + } + } } @@ -187,6 +225,62 @@ public class PandroidAgentListener extends Service { IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(batteryLevelReceiver, batteryLevelFilter); } + + private void sensors() { + + // Sensor listeners + + SensorEventListener orientationLevelReceiver = new SensorEventListener() { + public void onSensorChanged(SensorEvent sensorEvent) { + putSharedData("PANDROID_DATA", "orientation", Float.toString(sensorEvent.values[0]), "float"); + } + public void onAccuracyChanged(Sensor sensor, int accuracy) { + } + }; + + SensorEventListener proximityLevelReceiver = new SensorEventListener() { + public void onSensorChanged(SensorEvent sensorEvent) { + putSharedData("PANDROID_DATA", "proximity", Float.toString(sensorEvent.values[0]), "float"); + } + public void onAccuracyChanged(Sensor sensor, int accuracy) { + } + }; + + // Sensor management + + SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); + + sensorManager = + (SensorManager)getSystemService( SENSOR_SERVICE ); + List sensors = sensorManager.getSensorList( Sensor.TYPE_ALL ); + Sensor proxSensor = null; + Sensor orientSensor = null; + + for( int i = 0 ; i < sensors.size() ; ++i ) { + switch(sensors.get( i ).getType()) { + case Sensor.TYPE_ORIENTATION: + orientSensor = sensors.get( i ); + break; + case Sensor.TYPE_PROXIMITY: + proxSensor = sensors.get( i ); + break; + } + } + + if( orientSensor != null ) { + sensorManager.registerListener( + orientationLevelReceiver, + orientSensor, + SensorManager.SENSOR_DELAY_UI ); + } + + if( proxSensor != null ) { + sensorManager.registerListener( + proximityLevelReceiver, + proxSensor, + SensorManager.SENSOR_DELAY_UI ); + } + } private void updateValues() { batteryLevel(); @@ -199,6 +293,8 @@ public class PandroidAgentListener extends Service { putSharedData("PANDROID_DATA", "latitude", "181.0", "float"); putSharedData("PANDROID_DATA", "longitude", "181.0", "float"); } + + sensors(); } private void putSharedData(String preferenceName, String tokenName, String data, String type) {