mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
better grid view of data
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE AndroidXML>
|
||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/LayoutData"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:columnWidth="90dp"
|
||||
android:horizontalSpacing="10dp"
|
||||
android:columnWidth="150dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:verticalSpacing="10dp"
|
||||
android:horizontalSpacing="10dp"
|
||||
android:stretchMode="columnWidth"
|
||||
android:verticalSpacing="10dp" >
|
||||
|
||||
</TableLayout>
|
||||
android:gravity="center"
|
||||
/>
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.ridelogger;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class CurrentValuesAdapter extends BaseAdapter {
|
||||
|
||||
public StartActivity context;
|
||||
public LinkedHashMap<String, TextView> tvs = new LinkedHashMap<String, TextView>();
|
||||
|
||||
public CurrentValuesAdapter(StartActivity c) {
|
||||
context = c;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return tvs.size();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) { // if it's not recycled, initialize some attributes
|
||||
return (TextView) tvs.values().toArray()[position];
|
||||
} else {
|
||||
return (TextView) convertView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void update(LinkedHashMap<String, String> currentValues) {
|
||||
for (Entry<String, String> entry : currentValues.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
|
||||
String value = String.format("%.2f", Float.valueOf(entry.getValue())) + " " + key.toLowerCase();
|
||||
|
||||
|
||||
if(tvs.containsKey(key)) {
|
||||
tvs.get(key).setText(value);
|
||||
} else {
|
||||
TextView tv = new TextView(context);
|
||||
tv.setTextAppearance(context, android.R.attr.textAppearanceLarge);
|
||||
tv.setTypeface(null, Typeface.BOLD);
|
||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
||||
tv.setText(value);
|
||||
|
||||
tvs.put(key, tv);
|
||||
}
|
||||
}
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -56,10 +56,10 @@ public class RideService extends Service
|
||||
{
|
||||
public GzipWriter buf; //writes to log file buffered
|
||||
public long startTime; //start time of the ride
|
||||
public Map<String, String> currentValues; //hash of current values
|
||||
public LinkedHashMap<String, String> currentValues; //hash of current values
|
||||
public boolean rideStarted = false; //have we started logging the ride
|
||||
|
||||
public Map<String, Base<?>> sensors = new HashMap<String, Base<?>>();
|
||||
public LinkedHashMap<String, Base<?>> sensors = new LinkedHashMap<String, Base<?>>();
|
||||
//All other Android sensor class
|
||||
MultiDeviceSearch mSearch; //Ant+ device search class to init connections
|
||||
MultiDeviceSearch.SearchCallbacks mCallback; //Ant+ device class to setup sensors after they are found
|
||||
@@ -157,7 +157,7 @@ public class RideService extends Service
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
fileName = "ride-" + startTime + ".json.gzip";
|
||||
currentValues = new HashMap<String, String>();
|
||||
currentValues = new LinkedHashMap<String, String>();
|
||||
|
||||
SimpleDateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
f.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.ridelogger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningServiceInfo;
|
||||
@@ -12,7 +9,6 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -20,20 +16,17 @@ import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.GridView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class StartActivity extends FragmentActivity
|
||||
{
|
||||
Intent rsi;
|
||||
|
||||
TableLayout layout;
|
||||
public Map<String, TextView> textViews;
|
||||
GridView layout;
|
||||
|
||||
private RunningServiceInfo service;
|
||||
|
||||
@@ -69,6 +62,8 @@ public class StartActivity extends FragmentActivity
|
||||
mService = null;
|
||||
}
|
||||
};
|
||||
|
||||
private CurrentValuesAdapter currentValuesAdapter;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -106,9 +101,10 @@ public class StartActivity extends FragmentActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dashboard);
|
||||
rsi = new Intent(this, RideService.class);
|
||||
layout = (TableLayout)findViewById(R.id.LayoutData);
|
||||
textViews = new HashMap<String, TextView>();
|
||||
|
||||
|
||||
layout = (GridView) findViewById(R.id.LayoutData);
|
||||
currentValuesAdapter = new CurrentValuesAdapter(this);
|
||||
layout.setAdapter(currentValuesAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,24 +171,8 @@ public class StartActivity extends FragmentActivity
|
||||
*/
|
||||
public void updateValues(Bundle bundle) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> currentValues = (Map<String, String>) bundle.getSerializable("currentValues");
|
||||
TextView tv;
|
||||
Iterator<Entry<String, String>> it = currentValues.entrySet().iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
Entry<String, String> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
if(!textViews.containsKey(key)) {
|
||||
tv = new TextView(this);
|
||||
tv.setTextAppearance(this, android.R.attr.textAppearanceLarge);
|
||||
tv.setTypeface(null, Typeface.BOLD);
|
||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
|
||||
|
||||
textViews.put(key, tv);
|
||||
layout.addView(tv);
|
||||
}
|
||||
textViews.get(key).setText(entry.getValue() + " " + key);
|
||||
}
|
||||
LinkedHashMap<String, String> currentValues = (LinkedHashMap<String, String>) bundle.getSerializable("currentValues");
|
||||
currentValuesAdapter.update(currentValues);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ridelogger.listners;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dsi.ant.plugins.antplus.pcc.defines.DeviceState;
|
||||
import com.dsi.ant.plugins.antplus.pccbase.PccReleaseHandle;
|
||||
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IDeviceStateChangeReceiver;
|
||||
@@ -67,7 +69,7 @@ public class Ant extends Base<Object>
|
||||
|
||||
|
||||
@Override
|
||||
public void writeData(Map<String, String> map)
|
||||
public void writeData(LinkedHashMap<String, String> map)
|
||||
{
|
||||
if(prefix != "") {
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
@@ -87,7 +89,7 @@ public class Ant extends Base<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alterCurrentData(Map<String, String> map)
|
||||
public void alterCurrentData(LinkedHashMap<String, String> map)
|
||||
{
|
||||
if(prefix != "") {
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ridelogger.RideService;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -18,7 +19,7 @@ public class Base<T>
|
||||
{
|
||||
public static GzipWriter buf;
|
||||
public static long startTime;
|
||||
public static Map<String, String> currentValues;
|
||||
public static LinkedHashMap<String, String> currentValues;
|
||||
|
||||
public RideService context;
|
||||
|
||||
@@ -62,7 +63,7 @@ public class Base<T>
|
||||
}
|
||||
|
||||
|
||||
public void writeData(Map<String, String> map)
|
||||
public void writeData(LinkedHashMap<String, String> map)
|
||||
{
|
||||
String ts = getTs();
|
||||
currentValues.put("SECS", ts);
|
||||
@@ -105,7 +106,7 @@ public class Base<T>
|
||||
}
|
||||
|
||||
|
||||
public void alterCurrentData(Map<String, String> map)
|
||||
public void alterCurrentData(LinkedHashMap<String, String> map)
|
||||
{
|
||||
synchronized (currentValues) {
|
||||
currentValues.put("SECS", getTs());
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.ridelogger.listners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import com.ridelogger.RideService;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
@@ -27,7 +24,7 @@ public class Gps extends Base<Gps>
|
||||
//listen to gps events and log them
|
||||
LocationListener locationListener = new LocationListener() {
|
||||
public void onLocationChanged(Location location) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("ALTITUDE", reduceNumberToString(location.getAltitude()) );
|
||||
map.put("KPH", reduceNumberToString(location.getSpeed()) );
|
||||
map.put("bearing", reduceNumberToString(location.getBearing()) );
|
||||
|
||||
@@ -17,8 +17,7 @@ import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch.MultiDeviceSearchRe
|
||||
import com.ridelogger.RideService;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* Power
|
||||
@@ -149,7 +148,7 @@ public class Power extends Ant
|
||||
@Override
|
||||
public void onNewTorqueEffectiveness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final BigDecimal leftTorqueEffectiveness, final BigDecimal rightTorqueEffectiveness)
|
||||
{
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("LTE", reduceNumberToString(leftTorqueEffectiveness));
|
||||
map.put("RTE", reduceNumberToString(rightTorqueEffectiveness));
|
||||
alterCurrentData(map);
|
||||
@@ -162,7 +161,7 @@ public class Power extends Ant
|
||||
@Override
|
||||
public void onNewPedalSmoothness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final boolean separatePedalSmoothnessSupport, final BigDecimal leftOrCombinedPedalSmoothness, final BigDecimal rightPedalSmoothness)
|
||||
{
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("SNPLC", reduceNumberToString(leftOrCombinedPedalSmoothness));
|
||||
map.put("SNPR", reduceNumberToString(rightPedalSmoothness));
|
||||
alterCurrentData(map);
|
||||
@@ -177,7 +176,7 @@ public class Power extends Ant
|
||||
@Override
|
||||
public void zeroReadings()
|
||||
{
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("WATTS", "0");
|
||||
map.put("NM", "0");
|
||||
map.put("CAD", "0");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.ridelogger.listners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@@ -74,7 +73,7 @@ public class Sensors extends Base<Object>
|
||||
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("ms2x", reduceNumberToString(event.values[0]));
|
||||
map.put("ms2y", reduceNumberToString(event.values[1]));
|
||||
map.put("ms2z", reduceNumberToString(event.values[2]));
|
||||
@@ -134,7 +133,7 @@ public class Sensors extends Base<Object>
|
||||
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("ms2x", reduceNumberToString(event.values[0]));
|
||||
map.put("ms2y", reduceNumberToString(event.values[1]));
|
||||
map.put("ms2z", reduceNumberToString(event.values[2]));
|
||||
@@ -184,7 +183,7 @@ public class Sensors extends Base<Object>
|
||||
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("uTx", reduceNumberToString(event.values[0]));
|
||||
map.put("uTy", reduceNumberToString(event.values[1]));
|
||||
map.put("uTz", reduceNumberToString(event.values[2]));
|
||||
|
||||
Reference in New Issue
Block a user