mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-29 00:32:11 -07:00
Use waklock for tracking
This commit is contained in:
parent
c7ddf0ed58
commit
aa8a213af2
@ -25,6 +25,7 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
||||
@ -24,6 +24,7 @@ import android.content.pm.PackageManager;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
@ -64,6 +65,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
TextView timeView, gpsStatusView;
|
||||
boolean isResumed= false;
|
||||
private Handler mHandler= new Handler();
|
||||
PowerManager.WakeLock wakeLock;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -80,15 +82,22 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
recorder= new WorkoutRecorder(this, ACTIVITY);
|
||||
recorder.start();
|
||||
|
||||
infoViews[0]= new InfoViewHolder((TextView) findViewById(R.id.recordInfo1Title), (TextView) findViewById(R.id.recordInfo1Value));
|
||||
infoViews[1]= new InfoViewHolder((TextView) findViewById(R.id.recordInfo2Title), (TextView) findViewById(R.id.recordInfo2Value));
|
||||
infoViews[2]= new InfoViewHolder((TextView) findViewById(R.id.recordInfo3Title), (TextView) findViewById(R.id.recordInfo3Value));
|
||||
infoViews[3]= new InfoViewHolder((TextView) findViewById(R.id.recordInfo4Title), (TextView) findViewById(R.id.recordInfo4Value));
|
||||
infoViews[0]= new InfoViewHolder(findViewById(R.id.recordInfo1Title), findViewById(R.id.recordInfo1Value));
|
||||
infoViews[1]= new InfoViewHolder(findViewById(R.id.recordInfo2Title), findViewById(R.id.recordInfo2Value));
|
||||
infoViews[2]= new InfoViewHolder(findViewById(R.id.recordInfo3Title), findViewById(R.id.recordInfo3Value));
|
||||
infoViews[3]= new InfoViewHolder(findViewById(R.id.recordInfo4Title), findViewById(R.id.recordInfo4Value));
|
||||
timeView= findViewById(R.id.recordTime);
|
||||
|
||||
updateDescription();
|
||||
|
||||
startUpdater();
|
||||
acquireWakelock();
|
||||
}
|
||||
|
||||
private void acquireWakelock(){
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "de.tadris.fitotrack:workout_recorder");
|
||||
wakeLock.acquire(1000*60*120);
|
||||
}
|
||||
|
||||
private void setupMap(){
|
||||
@ -110,25 +119,17 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
}
|
||||
|
||||
private void startUpdater(){
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Thread(() -> {
|
||||
try{
|
||||
while (recorder.isActive()){
|
||||
Thread.sleep(1000);
|
||||
if(isResumed){
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateDescription();
|
||||
}
|
||||
});
|
||||
mHandler.post(() -> updateDescription());
|
||||
}
|
||||
}
|
||||
}catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
timeView.setText(UnitUtils.getHourMinuteSecondTime(recorder.getDuration()));
|
||||
infoViews[0].setText(getString(R.string.workoutDistance), UnitUtils.getDistance(recorder.getDistance()));
|
||||
infoViews[1].setText(getString(R.string.workoutBurnedEnergy), recorder.getCalories() + " kcal");
|
||||
infoViews[2].setText(getString(R.string.workoutAvgSpeed), UnitUtils.getSpeed(recorder.getAvgSpeed()));
|
||||
infoViews[2].setText(getString(R.string.workoutAvgSpeed), UnitUtils.getSpeed(Math.min(100d, recorder.getAvgSpeed())));
|
||||
infoViews[3].setText(getString(R.string.workoutPauseDuration), UnitUtils.getHourMinuteSecondTime(recorder.getPauseDuration()));
|
||||
}
|
||||
|
||||
@ -180,6 +181,9 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
mapView.destroyAll();
|
||||
AndroidGraphicFactory.clearResourceMemoryCache();
|
||||
super.onDestroy();
|
||||
if(wakeLock.isHeld()){
|
||||
wakeLock.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
package de.tadris.fitness.activity;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
@ -114,7 +113,7 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
|
||||
|
||||
addTitle(getString(R.string.workoutBurnedEnergy));
|
||||
addKeyValue(getString(R.string.workoutTotalEnergy), workout.calorie + " kcal",
|
||||
getString(R.string.workoutEnergyConsumption), UnitUtils.getPace((double)workout.calorie / workout.length / 1000));
|
||||
getString(R.string.workoutEnergyConsumption), UnitUtils.getRelativeEnergyConsumption((double)workout.calorie / ((double)workout.length / 1000)));
|
||||
|
||||
|
||||
}
|
||||
@ -224,13 +223,10 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
|
||||
map.addLayer(workoutLayer);
|
||||
|
||||
final BoundingBox bounds= new BoundingBox(workoutLayer.getLatLongs()).extendMeters(50);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Handler().postDelayed(() -> {
|
||||
map.getModel().mapViewPosition.setMapPosition(new MapPosition(bounds.getCenterPoint(),
|
||||
(byte)(LatLongUtils.zoomForBounds(map.getDimension(), bounds, map.getModel().displayModel.getTileSize()))));
|
||||
map.animate().alpha(1f).setDuration(1000).start();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
map.getModel().mapViewPosition.setMapLimit(bounds);
|
||||
@ -282,12 +278,7 @@ public class ShowWorkoutActivity extends FitoTrackActivity {
|
||||
new AlertDialog.Builder(this).setTitle(R.string.deleteWorkout)
|
||||
.setMessage(R.string.deleteWorkoutMessage)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
deleteWorkout();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.delete, (dialog, which) -> deleteWorkout())
|
||||
.create().show();
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@ import androidx.room.PrimaryKey;
|
||||
public class Workout{
|
||||
|
||||
public static final String WORKOUT_TYPE_RUNNING= "running";
|
||||
public static final String WORKOUT_TYPE_WALKING= "running";
|
||||
public static final String WORKOUT_TYPE_HIKING= "hiking";
|
||||
public static final String WORKOUT_TYPE_CYCLING= "cycling";
|
||||
|
||||
|
||||
@ -210,9 +210,15 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
|
||||
return (int)distance;
|
||||
}
|
||||
|
||||
private int maxCalories= 0;
|
||||
public int getCalories(){
|
||||
workout.avgSpeed= getAvgSpeed();
|
||||
return CalorieCalculator.calculateCalories(workout, Instance.getInstance(context).userPreferences.weight);
|
||||
workout.duration= getDuration();
|
||||
int calories= CalorieCalculator.calculateCalories(workout, Instance.getInstance(context).userPreferences.weight);
|
||||
if(calories > maxCalories){
|
||||
maxCalories= calories;
|
||||
}
|
||||
return maxCalories;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -24,6 +24,8 @@ import de.tadris.fitness.data.Workout;
|
||||
public class CalorieCalculator {
|
||||
|
||||
/**
|
||||
*
|
||||
* workoutType, duration and avgSpeed of workout have to be set
|
||||
*
|
||||
* @param workout the workout
|
||||
* @param weight the weight of the person in kilogram
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user