added gps old and gpd new. they dont work like expected... application builds.

This commit is contained in:
Toni
2017-03-21 09:13:43 +01:00
parent dad881e2b0
commit d9f56b7fd6
11 changed files with 333 additions and 20 deletions

7
.idea/gradle.xml generated
View File

@@ -12,12 +12,7 @@
<option value="$PROJECT_DIR$/app" /> <option value="$PROJECT_DIR$/app" />
</set> </set>
</option> </option>
<option name="myModules"> <option name="resolveModulePerSourceSet" value="false" />
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

2
.idea/misc.xml generated
View File

@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 23 compileSdkVersion 23
buildToolsVersion '23.0.2' buildToolsVersion '25.0.0'
defaultConfig { defaultConfig {
applicationId "de.fhws.indoor.sensorreadout" applicationId "de.fhws.indoor.sensorreadout"
@@ -23,7 +23,8 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.support:wearable:1.3.0' compile 'com.google.android.gms:play-services:10.2.0'
//compile 'com.google.android.support:wearable:1.3.0'
//compile 'com.google.android.gms:play-services-wearable:8.4.0' //compile 'com.google.android.gms:play-services-wearable:8.4.0'
//provided 'com.google.android.wearable:wearable:1.0.0' //provided 'com.google.android.wearable:wearable:1.3.0'
} }

View File

@@ -3,7 +3,7 @@
package="de.fhws.indoor.sensorreadout">> package="de.fhws.indoor.sensorreadout">>
<uses-feature android:name="android.hardware.type.watch" /> <!--<uses-feature android:name="android.hardware.type.watch" /> -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
@@ -14,6 +14,9 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BODY_SENSORS"/> <uses-permission android:name="android.permission.BODY_SENSORS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:allowBackup="true" android:icon="@drawable/icon" <application android:allowBackup="true" android:icon="@drawable/icon"

View File

@@ -11,7 +11,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.content.pm.ActivityInfoCompat; import android.support.v4.content.pm.ActivityInfoCompat;
import android.support.wearable.activity.WearableActivity; //import android.support.wearable.activity.WearableActivity;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@@ -25,6 +25,8 @@ import android.view.ViewGroup.LayoutParams;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.fhws.indoor.sensorreadout.sensors.Gps;
import de.fhws.indoor.sensorreadout.sensors.GpsNew;
import de.fhws.indoor.sensorreadout.sensors.GroundTruth; import de.fhws.indoor.sensorreadout.sensors.GroundTruth;
import de.fhws.indoor.sensorreadout.sensors.Logger; import de.fhws.indoor.sensorreadout.sensors.Logger;
import de.fhws.indoor.sensorreadout.sensors.PhoneSensors; import de.fhws.indoor.sensorreadout.sensors.PhoneSensors;
@@ -35,7 +37,7 @@ import de.fhws.indoor.sensorreadout.sensors.mySensor;
import de.fhws.indoor.sensorreadout.sensors.SensorType; import de.fhws.indoor.sensorreadout.sensors.SensorType;
public class MainActivity extends WearableActivity { public class MainActivity extends Activity {
private final ArrayList<mySensor> sensors = new ArrayList<mySensor>(); private final ArrayList<mySensor> sensors = new ArrayList<mySensor>();
private final Logger logger = new Logger(this); private final Logger logger = new Logger(this);
@@ -185,6 +187,14 @@ public class MainActivity extends WearableActivity {
@Override public void onData(final SensorType id, final String csv) {return; } @Override public void onData(final SensorType id, final String csv) {return; }
}); });
//log gps using sensor number 16
final GpsNew gps = new GpsNew(this);
sensors.add(gps);
gps.setListener(new mySensor.SensorListener(){
@Override public void onData(final String csv) { add(SensorType.GPS, csv); }
@Override public void onData(final SensorType id, final String csv) {return; }
});
// log iBeacons using sensor number 9 // log iBeacons using sensor number 9
final mySensor beacon; final mySensor beacon;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@@ -209,7 +219,6 @@ public class MainActivity extends WearableActivity {
MY_PERMISSIONS_REQUEST_READ_BT); MY_PERMISSIONS_REQUEST_READ_BT);
} }
// heartbeat permission // heartbeat permission
/* if(ActivityCompat.shouldShowRequestPermissionRationale(this, /* if(ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.BODY_SENSORS)) { Manifest.permission.BODY_SENSORS)) {
@@ -235,13 +244,15 @@ public class MainActivity extends WearableActivity {
private void stop() { private void stop() {
for (final mySensor s : sensors) {s.onPause(this);} for (final mySensor s : sensors) {s.onPause(this);}
logger.stop(); logger.stop();
((TextView) findViewById(R.id.txtWifi)).setText(""); ((TextView) findViewById(R.id.txtWifi)).setText("-");
((TextView) findViewById(R.id.txtBeacon)).setText(""); ((TextView) findViewById(R.id.txtBeacon)).setText("-");
((TextView) findViewById(R.id.txtGPS)).setText("-");
} }
/** new sensor data */ /** new sensor data */
private int loadCounterWifi = 0; private int loadCounterWifi = 0;
private int loadCounterBeacon = 0; private int loadCounterBeacon = 0;
private int loadCounterGPS = 0;
private int loadCounterAny = 0; private int loadCounterAny = 0;
private void add(final SensorType id, final String csv) { private void add(final SensorType id, final String csv) {
@@ -256,7 +267,9 @@ public class MainActivity extends WearableActivity {
} else if (id == SensorType.IBEACON){ } else if (id == SensorType.IBEACON){
final TextView txt = (TextView) findViewById(R.id.txtBeacon); final TextView txt = (TextView) findViewById(R.id.txtBeacon);
txt.setText( ((++loadCounterBeacon % 2) == 0) ? "ib" : "IB"); txt.setText( ((++loadCounterBeacon % 2) == 0) ? "ib" : "IB");
} } else if (id == SensorType.GPS){
final TextView txt = (TextView) findViewById(R.id.txtGPS);
txt.setText( ((++loadCounterGPS % 2) == 0) ? "gps" : "GPS");}
// dump buffer stats every x entries // dump buffer stats every x entries
if (++loadCounterAny % 250 == 0) { if (++loadCounterAny % 250 == 0) {

View File

@@ -0,0 +1,111 @@
package de.fhws.indoor.sensorreadout.sensors;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
/**
* Created by student on 20.03.17.
*/
@TargetApi(23)
public class Gps extends mySensor implements LocationListener {
private Activity act;
private LocationManager locationManager;
private Location location;
public Gps(Activity act) {
this.act = act;
initGPS();
}
private void initGPS(){
if ( Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission( act, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission( act, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return ;
}
try {
this.locationManager = (LocationManager) act.getSystemService(Context.LOCATION_SERVICE);
// Get GPS
boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (isGPSEnabled) {
//get the most accurate provider
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_HIGH);
String provider = locationManager.getBestProvider(criteria, true);
//use only gps and not network 0 and 0 for fastest updates possible
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0,
0, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);
setMostRecentLocation(location);
}
}
} catch (Exception ex) {
throw new MyException("error creating gps!");
}
}
private void setMostRecentLocation(Location loc){
this.location = loc;
}
@Override
public void onResume(Activity act) {
initGPS();
}
@Override
public void onPause(Activity act) {
locationManager.removeUpdates(this);
}
@Override
public void onLocationChanged(Location location) {
this.location = location;
// inform listeners
if (listener != null){
listener.onData(SensorType.GRAVITY,
Double.toString(location.getLatitude()) + ";" +
Double.toString(location.getLongitude()) + ";" +
Double.toString(location.getAltitude()) + ";" +
Double.toString(location.getBearing())
);
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
}

View File

@@ -0,0 +1,181 @@
package de.fhws.indoor.sensorreadout.sensors;
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import java.text.DateFormat;
import java.util.Date;
import de.fhws.indoor.sensorreadout.R;
import static android.content.ContentValues.TAG;
/**
* Created by student on 21.03.17.
*/
public class GpsNew extends mySensor implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener {
protected GoogleApiClient mGoogleApiClient;
protected Location mLastLocation;
private Activity act;
private Location mCurrentLocation;
private LocationRequest mLocationRequest;
protected Boolean mRequestingLocationUpdates;
protected String mLastUpdateTime;
public GpsNew(Activity act) {
this.act = act;
this.mRequestingLocationUpdates = false;
this.mLastUpdateTime = "";
buildGoogleApiClient();
}
/**
* Builds a GoogleApiClient. Uses the addApi() method to request the LocationServices API.
*/
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this.act)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
mRequestingLocationUpdates = true;
mGoogleApiClient.connect();
}
/**
* Sets up the location request.
*/
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1);
mLocationRequest.setFastestInterval(1);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
/**
* Requests location updates from the FusedLocationApi.
*/
protected void startLocationUpdates() {
// The final argument to {@code requestLocationUpdates()} is a LocationListener
// (http://developer.android.com/reference/com/google/android/gms/location/LocationListener.html).
if (ActivityCompat.checkSelfPermission(this.act, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this.act, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
/**
* Removes location updates from the FusedLocationApi.
*/
protected void stopLocationUpdates() {
// It is a good practice to remove location requests when the activity is in a paused or
// stopped state. Doing so helps battery performance and is especially
// recommended in applications that request frequent location updates.
// The final argument to {@code requestLocationUpdates()} is a LocationListener
// (http://developer.android.com/reference/com/google/android/gms/location/LocationListener.html).
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
@Override
public void onResume(Activity act) {
if (mGoogleApiClient.isConnected() && mRequestingLocationUpdates) {
startLocationUpdates();
}
}
@Override
public void onPause(Activity act) {
if (mGoogleApiClient.isConnected()) {
stopLocationUpdates();
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i(TAG, "Connected to GoogleApiClient");
if (this.mCurrentLocation == null) {
if (ActivityCompat.checkSelfPermission(this.act, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this.act, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
this.mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
}
if (mRequestingLocationUpdates) {
startLocationUpdates();
}
}
@Override
public void onConnectionSuspended(int i) {
// The connection to Google Play services was lost for some reason. We call connect() to
// attempt to re-establish the connection.
Log.i(TAG, "Connection suspended");
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
// Refer to the javadoc for ConnectionResult to see what error codes might be returned in
// onConnectionFailed.
Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode());
}
@Override
public void onLocationChanged(Location location) {
this.mCurrentLocation = location;
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
// inform listeners
if (listener != null){
listener.onData(SensorType.GRAVITY,
Double.toString(location.getLatitude()) + ";" +
Double.toString(location.getLongitude()) + ";" +
Double.toString(location.getAltitude()) + ";" +
Double.toString(location.getBearing())
);
}
}
}

View File

@@ -21,6 +21,7 @@ public enum SensorType {
LIGHT(13), LIGHT(13),
AMBIENT_TEMPERATURE(14), AMBIENT_TEMPERATURE(14),
HEART_RATE(15), HEART_RATE(15),
GPS(16),
GROUND_TRUTH(99), GROUND_TRUTH(99),
GROUND_TRUTH_PATH(-1), GROUND_TRUTH_PATH(-1),

View File

@@ -81,6 +81,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="-" android:text="-"
/> />
<TextView
android:id="@+id/txtGPS"
android:textColor="#ffffff"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="-"
/>
<TextView <TextView
android:id="@+id/txtBuffer" android:id="@+id/txtBuffer"
android:textColor="#ffffff" android:textColor="#ffffff"

View File

@@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha2' classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@@ -1,6 +1,6 @@
#Thu Jun 02 19:04:18 CEST 2016 #Fri Mar 17 13:55:27 CET 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip