2011-02-07 Sergio Martin <sergio.martin@artica.es>
* 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 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3808 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
069b875274
commit
479f09cea2
|
@ -1,3 +1,27 @@
|
|||
2011-02-07 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* 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 <rnovoa@artica.es>
|
||||
|
||||
* win32/installer/pandora.mpi, win32/pandora.cc, unix/pandora_agent: Free
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
android:versionName="1.0">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".PandroidAgent"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="keyboardHidden|orientation">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -18,4 +19,8 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
||||
<uses-feature android:name="android.hardware.sensor.light" />
|
||||
<uses-feature android:name="android.hardware.location" />
|
||||
</manifest>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.1 KiB |
|
@ -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");
|
||||
|
|
|
@ -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<Sensor> 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) {
|
||||
|
|
Loading…
Reference in New Issue