mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Fixup Settings
Add configurable display of sensors Add configurable text size Disable preferences if ride is logging
This commit is contained in:
@@ -7,4 +7,7 @@
|
||||
<header android:fragment="com.ridelogger.SettingsActivity$AntFragment"
|
||||
android:title="@string/setting_ant_title"
|
||||
android:summary="@string/setting_ant_note" />
|
||||
<header android:fragment="com.ridelogger.SettingsActivity$SensorsFragment"
|
||||
android:title="@string/setting_sensors_title"
|
||||
android:summary="@string/setting_sensors_note" />
|
||||
</preference-headers>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<string name="ant_setup_note">Pair your Ant+ devices now?</string>
|
||||
|
||||
<string name="ant_pair_dialog_title">Select Ant Devices</string>
|
||||
<string name="ant_pair_dialog_button_note">Pair</string>
|
||||
<string name="ant_pair_dialog_button_note">Pair</string>
|
||||
|
||||
<string name="gc_rider_name_dialog_title">Enter Rider Name</string>
|
||||
<string name="gc_rider_name_dialog_note">What is your Golder Cheata Rider Name?</string>
|
||||
@@ -68,12 +68,19 @@
|
||||
<string name="setting_ant_title">Ant+</string>
|
||||
<string name="setting_ant_note">Setup your Ant+ Devices</string>
|
||||
|
||||
<string name="setting_sensors_title">Display Sensors</string>
|
||||
<string name="setting_sensors_note">List of Sensors Display</string>
|
||||
|
||||
<string name="setting_size_title">Display Text Size</string>
|
||||
|
||||
<string name="PREFS_NAME">RideLogger</string>
|
||||
<string name="PREF_RIDER_NAME">RiderName</string>
|
||||
<string name="PREF_EMERGENCY_NUMBER">EmergencyNumbuer</string>
|
||||
<string name="PREF_DETECT_CRASH">DetectCrash</string>
|
||||
<string name="PREF_PHONE_HOME">PhoneHome</string>
|
||||
<string name="PREF_PAIRED_ANTS">PairedAnts</string>
|
||||
<string name="PREF_PHONE_HOME_PERIOD">PhoneHomePeriod</string>
|
||||
<string name="PREF_PHONE_HOME_PERIOD">PhoneHomePeriod</string>
|
||||
<string name="PREF_TRACKING_SENSORS">TrackingSensors</string>
|
||||
<string name="PREF_TRACKING_SIZE">TrackingSize</string>
|
||||
|
||||
</resources>
|
||||
|
||||
19
contrib/RideLogger/res/xml/sensors_settings.xml
Normal file
19
contrib/RideLogger/res/xml/sensors_settings.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<PreferenceCategory
|
||||
android:title="@string/PREFS_NAME">
|
||||
|
||||
<MultiSelectListPreference
|
||||
android:key="@string/PREF_TRACKING_SENSORS"
|
||||
android:title="@string/setting_sensors_title"
|
||||
android:summary="@string/setting_sensors_note"
|
||||
/>
|
||||
<EditTextPreference
|
||||
android:key="@string/PREF_TRACKING_SIZE"
|
||||
android:title="@string/setting_size_title"
|
||||
android:defaultValue="20"
|
||||
/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.ridelogger;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Typeface;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -8,27 +12,82 @@ import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class CurrentValuesAdapter extends BaseAdapter {
|
||||
|
||||
public StartActivity context;
|
||||
|
||||
public TextView[] tvs = new TextView[RideService.TOTALSENSORS];
|
||||
public StartActivity context;
|
||||
public int count = 0;
|
||||
public int[] keys;
|
||||
public TextView[] tvs = new TextView[RideService.TOTALSENSORS];
|
||||
public int size = 20;
|
||||
public static SharedPreferences.OnSharedPreferenceChangeListener spChanged;
|
||||
|
||||
public CurrentValuesAdapter(StartActivity c) {
|
||||
context = c;
|
||||
context = c;
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Set<String> sensors = settings.getStringSet(context.getString(R.string.PREF_TRACKING_SENSORS), null);
|
||||
size = Integer.valueOf(settings.getString(context.getString(R.string.PREF_TRACKING_SIZE), "20"));
|
||||
|
||||
for (int i = 0; i < RideService.TOTALSENSORS; i++) {
|
||||
tvs[i] = new TextView(context);
|
||||
tvs[i].setTextAppearance(context, android.R.attr.textAppearanceLarge);
|
||||
tvs[i].setTypeface(null, Typeface.BOLD);
|
||||
tvs[i].setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
||||
tvs[i].setText(String.format("%.2f", (float) 0.0) + " " + RideService.KEYS[i].toString().toLowerCase());
|
||||
if(sensors != null && sensors.size() > 0) {
|
||||
keys = new int[sensors.size()];
|
||||
int i = 0;
|
||||
for(String sensor : sensors) {
|
||||
keys[i] = Integer.parseInt(sensor);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
keys = new int[RideService.KEYS.length];
|
||||
|
||||
for (int i = 0; i < RideService.KEYS.length; i++) {
|
||||
keys[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
for (int key: keys) {
|
||||
tvs[key] = getNewTv(key);
|
||||
}
|
||||
|
||||
settings.registerOnSharedPreferenceChangeListener(
|
||||
new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String pkey) {
|
||||
if(pkey == context.getString(R.string.PREF_TRACKING_SIZE)) {
|
||||
size = Integer.valueOf(sharedPreferences.getString(context.getString(R.string.PREF_TRACKING_SIZE), "20"));
|
||||
for (int key: keys) {
|
||||
tvs[key].setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
|
||||
}
|
||||
} else if (pkey == context.getString(R.string.PREF_TRACKING_SENSORS)) {
|
||||
Set<String> sensors = sharedPreferences.getStringSet(context.getString(R.string.PREF_TRACKING_SENSORS), null);
|
||||
keys = new int[sensors.size()];
|
||||
int i = 0;
|
||||
for(String sensor : sensors) {
|
||||
keys[i] = Integer.parseInt(sensor);
|
||||
i++;
|
||||
}
|
||||
tvs = new TextView[RideService.TOTALSENSORS];
|
||||
for (int key: keys) {
|
||||
tvs[key] = getNewTv(key);
|
||||
}
|
||||
|
||||
context.layout.setAdapter(CurrentValuesAdapter.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public TextView getNewTv(int key){
|
||||
TextView tv = new TextView(context);
|
||||
|
||||
tv.setTextAppearance(context, android.R.attr.textAppearanceLarge);
|
||||
tv.setTypeface(null, Typeface.BOLD);
|
||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
|
||||
tv.setText(String.format("%.2f", 0.0) + " " + RideService.KEYS[key].toString().toLowerCase());
|
||||
|
||||
return tv;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return tvs.length;
|
||||
return keys.length;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +106,7 @@ public class CurrentValuesAdapter extends BaseAdapter {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
return (TextView) tvs[position];
|
||||
return (TextView) tvs[keys[position]];
|
||||
} else {
|
||||
return (TextView) convertView;
|
||||
}
|
||||
@@ -55,18 +114,10 @@ public class CurrentValuesAdapter extends BaseAdapter {
|
||||
|
||||
|
||||
public void update(float[] values) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if(tvs[i] != null) {
|
||||
tvs[i].setText(String.format("%.2f", values[i]) + " " + RideService.KEYS[i].toString().toLowerCase());
|
||||
} else {
|
||||
tvs[i] = new TextView(context);
|
||||
tvs[i].setTextAppearance(context, android.R.attr.textAppearanceLarge);
|
||||
tvs[i].setTypeface(null, Typeface.BOLD);
|
||||
tvs[i].setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
||||
tvs[i].setText(String.format("%.2f", values[i]) + " " + RideService.KEYS[i].toString().toLowerCase());
|
||||
}
|
||||
for (int key: keys) {
|
||||
tvs[key].setText(String.format("%.2f", values[key]) + " " + RideService.KEYS[key].toString().toLowerCase());
|
||||
}
|
||||
|
||||
this.notifyDataSetChanged();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.telephony.SmsManager;
|
||||
|
||||
|
||||
@@ -54,7 +55,7 @@ import android.telephony.SmsManager;
|
||||
public class RideService extends Service
|
||||
{
|
||||
public static final int notifyID = 1; //Id of the notification in the top android bar that this class creates and alters
|
||||
public static final int TOTALSENSORS = 25;
|
||||
|
||||
|
||||
public static final int SECS = 0;
|
||||
public static final int KPH = 1;
|
||||
@@ -110,6 +111,8 @@ public class RideService extends Service
|
||||
"lux"
|
||||
};
|
||||
|
||||
public static final int TOTALSENSORS = RideService.KEYS.length;
|
||||
|
||||
public float[] currentValues = new float[RideService.TOTALSENSORS]; //float array of current values
|
||||
public float[] snoopedValues = new float[RideService.TOTALSENSORS]; //float array of snooped values
|
||||
public GzipWriter buf; //writes to log file buffered
|
||||
@@ -408,7 +411,7 @@ public class RideService extends Service
|
||||
*/
|
||||
public void smsHome(String body) {
|
||||
SmsManager smsManager = SmsManager.getDefault();
|
||||
if(emergencyNumbuer != null) {
|
||||
if(emergencyNumbuer != null && PhoneNumberUtils.isWellFormedSmsAddress(emergencyNumbuer)) {
|
||||
smsManager.sendTextMessage(emergencyNumbuer, null, body, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,27 +11,71 @@ import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult;
|
||||
import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch;
|
||||
import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch.MultiDeviceSearchResult;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningServiceInfo;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.MultiSelectListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
public class SettingsActivity extends PreferenceActivity {
|
||||
public class SettingsActivity extends PreferenceActivity {
|
||||
|
||||
/**
|
||||
* This fragment contains a second-level set of preference that you
|
||||
* can get to by tapping an item in the first preferences fragment.
|
||||
*/
|
||||
public static class GeneralFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.general_settings);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onResume();
|
||||
|
||||
if(((SettingsActivity) getActivity()).getServiceRunning(RideService.class) != null) {
|
||||
Preference pref = findPreference(getString(R.string.PREF_RIDER_NAME));
|
||||
pref.setEnabled(false);
|
||||
|
||||
pref = findPreference(getString(R.string.PREF_EMERGENCY_NUMBER));
|
||||
pref.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This fragment contains a second-level set of preference that you
|
||||
* can get to by tapping an item in the first preferences fragment.
|
||||
*/
|
||||
public static class SensorsFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.sensors_settings);
|
||||
MultiSelectListPreference mMultiSelectListPreference = (MultiSelectListPreference) findPreference(getString(R.string.PREF_TRACKING_SENSORS));
|
||||
mMultiSelectListPreference.setEntries( RideService.KEYS );
|
||||
|
||||
CharSequence[] keys = new CharSequence[RideService.KEYS.length];
|
||||
|
||||
for (int i = 0; i < RideService.KEYS.length; i++) {
|
||||
keys[i] = String.valueOf(i);
|
||||
}
|
||||
mMultiSelectListPreference.setEntryValues(keys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isValidFragment(String fragment) {
|
||||
return true;
|
||||
@@ -43,9 +87,38 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
* can get to by tapping an item in the first preferences fragment.
|
||||
*/
|
||||
public static class AntFragment extends PreferenceFragment {
|
||||
|
||||
private MultiDeviceSearch mSearch;
|
||||
private MultiSelectListPreference mMultiSelectListPreference;
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onResume();
|
||||
|
||||
if(((SettingsActivity) getActivity()).getServiceRunning(RideService.class) != null) {
|
||||
setupAnt();
|
||||
|
||||
Timer timer = new Timer();
|
||||
final Handler handler = new Handler();
|
||||
|
||||
timer.schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
handler.post(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
mMultiSelectListPreference.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
5000
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -54,27 +127,8 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
addPreferencesFromResource(R.xml.ant_settings);
|
||||
mMultiSelectListPreference = (MultiSelectListPreference) findPreference(getString(R.string.PREF_PAIRED_ANTS));
|
||||
mMultiSelectListPreference.setEnabled(false);
|
||||
|
||||
setupAnt();
|
||||
|
||||
Timer timer = new Timer();
|
||||
final Handler handler = new Handler();
|
||||
|
||||
timer.schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
handler.post(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
mMultiSelectListPreference.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
5000
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* try to pair some ant+ devices
|
||||
@@ -135,6 +189,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if(mSearch != null) mSearch.close();
|
||||
@@ -149,4 +204,20 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
public void onBuildHeaders(List<Header> target) {
|
||||
loadHeadersFromResource(R.layout.settings, target);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* is a service running or not
|
||||
* @param serviceClass
|
||||
* @return
|
||||
*/
|
||||
public RunningServiceInfo getServiceRunning(Class<?> serviceClass) {
|
||||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (serviceClass.getName().equals(service.service.getClassName())) {
|
||||
return service;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,7 @@ public class StartActivity extends FragmentActivity
|
||||
public void bindToService() {
|
||||
service = getServiceRunning(RideService.class);
|
||||
if(service != null) {
|
||||
final StartActivity that = this;
|
||||
bindService(new Intent(that, RideService.class), mConnection, Context.BIND_AUTO_CREATE);
|
||||
bindService(new Intent(StartActivity.this, RideService.class), mConnection, Context.BIND_AUTO_CREATE);
|
||||
mIsBound = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ public class Ant extends Base<Object>
|
||||
public PccReleaseHandle<?> releaseHandle; //Handle class
|
||||
public IPluginAccessResultReceiver<?> mResultReceiver; //Receiver class
|
||||
public Boolean snooped = false; //should we snoop others connections?
|
||||
public Ant that = null;
|
||||
//setup listeners and logging
|
||||
public Ant(MultiDeviceSearchResult result, RideService mContext) {
|
||||
super(mContext);
|
||||
@@ -27,7 +26,6 @@ public class Ant extends Base<Object>
|
||||
|
||||
public Ant(MultiDeviceSearchResult result, RideService mContext, Boolean pSnoop) {
|
||||
super(mContext);
|
||||
that = this;
|
||||
snooped = pSnoop;
|
||||
}
|
||||
|
||||
@@ -41,7 +39,7 @@ public class Ant extends Base<Object>
|
||||
zeroReadings();
|
||||
if(snooped) {
|
||||
releaseHandle.close(); // release ourselves if snooped
|
||||
context.releaseSnoopedSensor(that);
|
||||
context.releaseSnoopedSensor(Ant.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user