mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Add a lot more string to strings.xml also add reset settings wf
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
android:installLocation="auto"
|
||||
package="com.ridelogger"
|
||||
android:versionCode="040000"
|
||||
android:versionName="4.0" >
|
||||
android:versionName="4.0.0" >
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
@@ -31,4 +31,4 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
||||
@@ -5,23 +5,32 @@
|
||||
<string name="service_name">Logging Ride</string>
|
||||
|
||||
<string name="emergency_contact_dialog_title">Emergency Contact</string>
|
||||
<string name="emergency_contact_dialog_note">Should a text messesage be sent on ride start and every 10 min. to your emergency contact?</string>
|
||||
<string name="emergency_contact_dialog_note">Should a text messesage be sent on ride start and periodically to let your emergency contact know you are alright?</string>
|
||||
|
||||
<string name="sms_period_dialog_title">Emergency Contact SMS Period</string>
|
||||
<string name="sms_period_dialog_note">Period in Minutes:</string>
|
||||
|
||||
|
||||
<string name="crash_detection_dialog_title">Crash Detection</string>
|
||||
<string name="crash_detection_dialog_note">Should a text messesage be sent on crash detction to your emergency contact?</string>
|
||||
|
||||
|
||||
<string name="emergency_contact_number_dialog_title">Emergency Contact Number</string>
|
||||
<string name="emergency_contact_number_dialog_note">Emergency phone number to update position on crash detection</string>
|
||||
|
||||
<string name="ant_setup_title">Set Ant+</string>
|
||||
<string name="ant_setup_note">Pair your Ant+ devices now?</string>
|
||||
|
||||
<string name="ant_pair_dialog_title">Emergency Contact Number</string>
|
||||
<string name="ant_pair_dialog_note">Emergency phone number to update position on crash detection.</string>
|
||||
<string name="ant_pair_dialog_title">Select Ant Devices</string>
|
||||
<string name="ant_pair_dialog_button_label">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>
|
||||
|
||||
<string name="save_setting_button">Next</string>
|
||||
<string name="skip_setting_button">Skip</string>
|
||||
|
||||
<string name="boolean_dialog_yes">Yes</string>
|
||||
<string name="boolean_dialog_no">No</string>
|
||||
|
||||
<string name="starting_ride">Starting Ride!</string>
|
||||
<string name="stopping_ride">Stoping Ride!</string>
|
||||
@@ -30,4 +39,26 @@
|
||||
<string name="building_ride">Building ride: </string>
|
||||
|
||||
<string name="click_to_stop"> Click to stop ride.</string>
|
||||
</resources>
|
||||
|
||||
<string name="ride_start_title">Start Ride</string>
|
||||
<string name="ride_start_note">Make sure locations is turned on. Internet connection is NOT required.</string>
|
||||
|
||||
<string name="start_and_close">Start</string>
|
||||
<string name="edit_settings">Settings</string>
|
||||
|
||||
<string name="ride_stop_title">Ride in Progress</string>
|
||||
<string name="ride_stop_note">Would you like to stop the ride or view current values.</string>
|
||||
|
||||
<string name="stop_and_close">Stop</string>
|
||||
<string name="view">View</string>
|
||||
|
||||
<string name="crash_warning">WARNING CRASH!</string>
|
||||
<string name="crash_confirm">CRASH CONFIRMED!</string>
|
||||
<string name="crash_unknow_location">Unknow location.</string>
|
||||
<string name="crash_magnitude">Mag</string>
|
||||
|
||||
<string name="ride_start_sms">I\'m starting my ride.</string>
|
||||
<string name="ride_stop_sms">I\'m starting my ride.</string>
|
||||
<string name="riding_ok_sms">I\'m ok.</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -62,12 +62,10 @@ public class RideService extends Service
|
||||
public int notifyID = 1; //Id of the notification in the top android bar that this class creates and alters
|
||||
|
||||
public String fileName = ""; //File where the ride will go
|
||||
SharedPreferences settings; //Object to load our setting from android's storage
|
||||
public SharedPreferences settings; //Object to load our setting from android's storage
|
||||
public Boolean snoop = false; //should we log others ant+ devices
|
||||
Set<String> pairedAnts; //list of ant devices to pair with
|
||||
public boolean phoneHome = false; //if we should send the messages or not
|
||||
private Timer timer; //timer class to control the periodic messages
|
||||
public boolean detectCrash = false; //should we try to detect crashes and message emergency contact
|
||||
public String emergencyNumbuer; //the number to send the messages to
|
||||
|
||||
/**
|
||||
@@ -129,8 +127,6 @@ public class RideService extends Service
|
||||
String year = Integer.toString(cal.get(Calendar.YEAR));
|
||||
settings = getSharedPreferences(StartActivity.PREFS_NAME, 0);
|
||||
emergencyNumbuer = settings.getString(StartActivity.EMERGENCY_NUMBER, "");
|
||||
detectCrash = settings.getBoolean(StartActivity.DETECT_CRASH, false);
|
||||
phoneHome = settings.getBoolean(StartActivity.PHONE_HOME, false);
|
||||
pairedAnts = settings.getStringSet(StartActivity.PAIRED_ANTS, null);
|
||||
|
||||
currentValues.put("SECS", "0.0");
|
||||
@@ -219,8 +215,9 @@ public class RideService extends Service
|
||||
}
|
||||
rideStarted = true;
|
||||
|
||||
if(phoneHome) {
|
||||
if(settings.getBoolean(StartActivity.PHONE_HOME, false)) {
|
||||
timer = new Timer();
|
||||
int period = Integer.parseInt(settings.getString(StartActivity.PHONE_HOME_PERIOD, "10"));
|
||||
|
||||
timer.scheduleAtFixedRate(
|
||||
new TimerTask() {
|
||||
@@ -229,8 +226,8 @@ public class RideService extends Service
|
||||
phoneHome();
|
||||
}
|
||||
},
|
||||
600000,
|
||||
600000
|
||||
60000 * period,
|
||||
60000 * period
|
||||
); //every ten min let them know where you are at
|
||||
phoneStart();
|
||||
}
|
||||
@@ -258,26 +255,26 @@ public class RideService extends Service
|
||||
* let a love one know where you are at about every 10 min
|
||||
*/
|
||||
public void phoneCrash(double mag) {
|
||||
String body = "CRASH DETECTED!\n";
|
||||
String body = getString(R.string.crash_warning) + "\n";
|
||||
if(currentValues.containsKey("LAT") && currentValues.containsKey("LON")) {
|
||||
body = body + "https://www.google.com/maps/place/" + currentValues.get("LAT") + "," + currentValues.get("LON");
|
||||
} else {
|
||||
body = body + "Unknow location.";
|
||||
body = body + getString(R.string.crash_unknow_location);
|
||||
}
|
||||
body = body + "\n Mag: " + String.valueOf(mag);
|
||||
body = body + "\n " + getString(R.string.crash_magnitude) + ": " + String.valueOf(mag);
|
||||
smsHome(body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* let a love one know where you are at about every 10 min
|
||||
* confirm the crash if we are not moving
|
||||
*/
|
||||
public void phoneCrashConfirm() {
|
||||
String body = "CRASH CONFIRMED!\n";
|
||||
String body = getString(R.string.crash_warning) + "!\n";
|
||||
if(currentValues.containsKey("LAT") && currentValues.containsKey("LON")) {
|
||||
body = body + "https://www.google.com/maps/place/" + currentValues.get("LAT") + "," + currentValues.get("LON");
|
||||
} else {
|
||||
body = body + "Unknow location.";
|
||||
body = body + getString(R.string.crash_unknow_location);
|
||||
}
|
||||
smsHome(body);
|
||||
}
|
||||
@@ -287,7 +284,7 @@ public class RideService extends Service
|
||||
* let them know we are starting
|
||||
*/
|
||||
public void phoneStart() {
|
||||
smsWithLocation("I'm starting my ride");
|
||||
smsWithLocation(getString(R.string.ride_start_sms));
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +292,7 @@ public class RideService extends Service
|
||||
* let them know we are stopping
|
||||
*/
|
||||
public void phoneStop() {
|
||||
smsWithLocation("I'm done with my ride");
|
||||
smsWithLocation(getString(R.string.ride_stop_sms));
|
||||
}
|
||||
|
||||
|
||||
@@ -305,8 +302,6 @@ public class RideService extends Service
|
||||
public void smsWithLocation(String body) {
|
||||
if(currentValues.containsKey("LAT") && currentValues.containsKey("LON")) {
|
||||
body = body + "\n https://www.google.com/maps/place/" + currentValues.get("LAT") + "," + currentValues.get("LON");
|
||||
} else {
|
||||
body = body + ".";
|
||||
}
|
||||
|
||||
smsHome(body);
|
||||
@@ -317,7 +312,7 @@ public class RideService extends Service
|
||||
* let a love one know where you are at about every 10 min
|
||||
*/
|
||||
public void phoneHome() {
|
||||
smsWithLocation("I'm riding:");
|
||||
smsWithLocation(getString(R.string.riding_ok_sms));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,19 +21,20 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.text.InputType;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class StartActivity extends FragmentActivity
|
||||
{
|
||||
Intent rsi;
|
||||
public static final String PREFS_NAME = "RideLogger";
|
||||
public static final String RIDER_NAME = "RiderName";
|
||||
public static final String EMERGENCY_NUMBER = "EmergencyNumbuer";
|
||||
public static final String DETECT_CRASH = "DetectCrash";
|
||||
public static final String PHONE_HOME = "PhoneHome";
|
||||
public static final String PAIRED_ANTS = "PairedAnts";
|
||||
public static final String PREFS_NAME = "RideLogger";
|
||||
public static final String RIDER_NAME = "RiderName";
|
||||
public static final String EMERGENCY_NUMBER = "EmergencyNumbuer";
|
||||
public static final String DETECT_CRASH = "DetectCrash";
|
||||
public static final String PHONE_HOME = "PhoneHome";
|
||||
public static final String PAIRED_ANTS = "PairedAnts";
|
||||
public static final String PHONE_HOME_PERIOD = "PhoneHomePeriod";
|
||||
|
||||
SharedPreferences settings;
|
||||
MultiDeviceSearch mSearch;
|
||||
|
||||
@@ -46,66 +47,92 @@ public class StartActivity extends FragmentActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
rsi = new Intent(this, RideService.class);
|
||||
settings = getSharedPreferences(PREFS_NAME, 0);
|
||||
final String riderName = settings.getString(RIDER_NAME, "");
|
||||
|
||||
|
||||
|
||||
if(riderName == "") {
|
||||
final Runnable setupAntRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setupAnt();
|
||||
}
|
||||
};
|
||||
|
||||
final Runnable setupPhoneHomeRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
promptDialogCheckBox(
|
||||
getString(R.string.emergency_contact_dialog_title),
|
||||
getString(R.string.emergency_contact_dialog_note),
|
||||
PHONE_HOME,
|
||||
setupAntRunnable
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
final Runnable setupDetectCrashRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
promptDialogCheckBox(
|
||||
getString(R.string.crash_detection_dialog_title),
|
||||
getString(R.string.crash_detection_dialog_note),
|
||||
DETECT_CRASH,
|
||||
setupPhoneHomeRunnable
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Runnable setupEmergencyContactRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
promptDialogInput(
|
||||
getString(R.string.emergency_contact_number_dialog_title),
|
||||
getString(R.string.emergency_contact_number_dialog_note),
|
||||
EMERGENCY_NUMBER,
|
||||
setupDetectCrashRunnable
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
promptDialogInput(
|
||||
getString(R.string.gc_rider_name_dialog_title),
|
||||
getString(R.string.gc_rider_name_dialog_note),
|
||||
RIDER_NAME,
|
||||
setupEmergencyContactRunnable
|
||||
);
|
||||
if(settings.getString(RIDER_NAME, "") == "") {
|
||||
setupSettings();
|
||||
} else {
|
||||
toggleRide();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void setupSettings() {
|
||||
final Runnable askAntRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Runnable setupAntRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setupAnt();
|
||||
}
|
||||
};
|
||||
|
||||
final Runnable skipAntRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toggleRide();
|
||||
}
|
||||
};
|
||||
|
||||
promptDialogBoolean(getString(R.string.ant_setup_title), getString(R.string.ant_setup_note), setupAntRunnable, skipAntRunnable);
|
||||
}
|
||||
};
|
||||
|
||||
final Runnable setupPhoneHomePeriod = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
promptDialogPhone(
|
||||
getString(R.string.sms_period_dialog_title),
|
||||
getString(R.string.sms_period_dialog_note),
|
||||
PHONE_HOME_PERIOD,
|
||||
askAntRunnable
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
final Runnable setupPhoneHomeRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
promptDialogBoolean(
|
||||
getString(R.string.emergency_contact_dialog_title),
|
||||
getString(R.string.emergency_contact_dialog_note),
|
||||
PHONE_HOME,
|
||||
setupPhoneHomePeriod
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
final Runnable setupDetectCrashRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
promptDialogBoolean(
|
||||
getString(R.string.crash_detection_dialog_title),
|
||||
getString(R.string.crash_detection_dialog_note),
|
||||
DETECT_CRASH,
|
||||
setupPhoneHomeRunnable
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Runnable setupEmergencyContactRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
promptDialogPhone(
|
||||
getString(R.string.emergency_contact_number_dialog_title),
|
||||
getString(R.string.emergency_contact_number_dialog_note),
|
||||
EMERGENCY_NUMBER,
|
||||
setupDetectCrashRunnable
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
promptDialogInput(
|
||||
getString(R.string.gc_rider_name_dialog_title),
|
||||
getString(R.string.gc_rider_name_dialog_note),
|
||||
RIDER_NAME,
|
||||
setupEmergencyContactRunnable
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TextBox Dialog Prompt
|
||||
@@ -117,8 +144,10 @@ public class StartActivity extends FragmentActivity
|
||||
public void promptDialogInput(String title, String message, final String settingSaveKey, final Runnable callBack) {
|
||||
// Set up the input
|
||||
final EditText input = new EditText(this);
|
||||
|
||||
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
|
||||
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
input.setText(settings.getString(settingSaveKey, ""));
|
||||
|
||||
OnClickListener positiveClick = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
@@ -146,6 +175,7 @@ public class StartActivity extends FragmentActivity
|
||||
final EditText input = new EditText(this);
|
||||
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
|
||||
input.setInputType(InputType.TYPE_CLASS_PHONE);
|
||||
input.setText(settings.getString(settingSaveKey, ""));
|
||||
|
||||
OnClickListener positiveClick = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
@@ -160,27 +190,85 @@ public class StartActivity extends FragmentActivity
|
||||
promptDialog(title, message, input, positiveClick);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checkbox dialog prompt
|
||||
* Boolean dialog prompt
|
||||
* @param title
|
||||
* @param message
|
||||
* @param settingSaveKey
|
||||
* @param callBack
|
||||
* @param positiveCallback
|
||||
*/
|
||||
public void promptDialogCheckBox(String title, String message, final String settingSaveKey, final Runnable callBack) {
|
||||
final CheckBox input = new CheckBox(this);
|
||||
OnClickListener positiveClick = new DialogInterface.OnClickListener() {
|
||||
public void promptDialogBoolean(String title, String message, Runnable positiveCallback, Runnable negativeCallback) {
|
||||
promptDialogBoolean(title, message, null, positiveCallback, negativeCallback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Boolean dialog prompt
|
||||
* @param title
|
||||
* @param message
|
||||
* @param settingSaveKey
|
||||
* @param positiveCallback
|
||||
*/
|
||||
public void promptDialogBoolean(String title, String message, String settingSaveKey, Runnable positiveCallback) {
|
||||
promptDialogBoolean(title, message, settingSaveKey, positiveCallback, positiveCallback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Boolean dialog prompt
|
||||
* @param title
|
||||
* @param message
|
||||
* @param settingSaveKey
|
||||
* @param positiveCallback
|
||||
*/
|
||||
public void promptDialogBoolean(String title, String message, Runnable positiveCallback, Runnable negativeCallback, String positiveButtonLabel, String negativeButtonLabel) {
|
||||
promptDialogBoolean(title, message, null, positiveCallback, negativeCallback, positiveButtonLabel, negativeButtonLabel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Boolean dialog prompt
|
||||
* @param title
|
||||
* @param message
|
||||
* @param settingSaveKey
|
||||
* @param positiveCallback
|
||||
*/
|
||||
public void promptDialogBoolean(String title, String message, String settingSaveKey, Runnable positiveCallback, Runnable negativeCallback) {
|
||||
promptDialogBoolean(title, message, settingSaveKey, positiveCallback, negativeCallback, getString(R.string.boolean_dialog_yes), getString(R.string.boolean_dialog_no));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Boolean dialog prompt
|
||||
* @param title
|
||||
* @param message
|
||||
* @param settingSaveKey
|
||||
* @param positiveCallback
|
||||
* @param negativeCallback
|
||||
*/
|
||||
public void promptDialogBoolean(String title, String message, final String settingSaveKey, final Runnable positiveCallback, final Runnable negativeCallback, String positiveButtonLabel, String negativeButtonLabel) {
|
||||
OnClickListener positiveClick = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if(input.isChecked()) {
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean(settingSaveKey, true).commit();
|
||||
callBack.run();
|
||||
}
|
||||
if(settingSaveKey != null) {
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean(settingSaveKey, true).commit();
|
||||
}
|
||||
positiveCallback.run();
|
||||
}
|
||||
};
|
||||
|
||||
promptDialog(title, message, input, positiveClick);
|
||||
OnClickListener negativeClick = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if(settingSaveKey != null) {
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean(settingSaveKey, false).commit();
|
||||
}
|
||||
negativeCallback.run();
|
||||
}
|
||||
};
|
||||
|
||||
promptDialog(title, message, null, positiveClick, positiveButtonLabel, negativeClick, negativeButtonLabel);
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +285,7 @@ public class StartActivity extends FragmentActivity
|
||||
View view,
|
||||
OnClickListener positiveClick
|
||||
) {
|
||||
promptDialog(title, message, view, positiveClick, null);
|
||||
promptDialog(title, message, view, positiveClick, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,19 +302,30 @@ public class StartActivity extends FragmentActivity
|
||||
String message,
|
||||
View view,
|
||||
OnClickListener positiveClick,
|
||||
String positiveLabel
|
||||
String positiveLabel,
|
||||
OnClickListener negativeClick,
|
||||
String negativeLabel
|
||||
) {
|
||||
if(positiveLabel == null) positiveLabel = getString(R.string.save_setting_button);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
|
||||
// 2. Chain together various setter methods to set the dialog characteristics
|
||||
AlertDialog dialog = builder
|
||||
.setMessage(message)
|
||||
builder.setMessage(message)
|
||||
.setTitle(title)
|
||||
.setView(view)
|
||||
.setPositiveButton(positiveLabel, positiveClick)
|
||||
.create();
|
||||
.setPositiveButton(positiveLabel, positiveClick);
|
||||
|
||||
if(view != null) {
|
||||
builder.setView(view);
|
||||
}
|
||||
|
||||
if(negativeClick != null) {
|
||||
if(negativeLabel == null) negativeLabel = getString(R.string.skip_setting_button);
|
||||
|
||||
builder.setNegativeButton(negativeLabel, negativeClick);
|
||||
}
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
|
||||
// 3. Get the AlertDialog from create()
|
||||
dialog.show();
|
||||
@@ -296,7 +395,7 @@ public class StartActivity extends FragmentActivity
|
||||
}
|
||||
})
|
||||
// Set the action buttons
|
||||
.setPositiveButton(getString(R.string.save_setting_button), new DialogInterface.OnClickListener() {
|
||||
.setPositiveButton(getString(R.string.ant_pair_dialog_button_label), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
ArrayList<String> ids = new ArrayList<String>();
|
||||
@@ -308,7 +407,6 @@ public class StartActivity extends FragmentActivity
|
||||
editor.putStringSet(PAIRED_ANTS, new HashSet<String>(ids));
|
||||
editor.commit();
|
||||
toggleRide();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -320,6 +418,7 @@ public class StartActivity extends FragmentActivity
|
||||
protected void onDestroy() {
|
||||
if(mSearch != null) mSearch.close();
|
||||
super.onDestroy();
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
@@ -338,9 +437,51 @@ public class StartActivity extends FragmentActivity
|
||||
*/
|
||||
protected void toggleRide() {
|
||||
if(!isServiceRunning(RideService.class)) {
|
||||
startRide();
|
||||
final Runnable startAndCloseRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startRide();
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
final Runnable settingsRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setupSettings();
|
||||
}
|
||||
};
|
||||
|
||||
promptDialogBoolean(
|
||||
getString(R.string.ride_start_title),
|
||||
getString(R.string.ride_start_note),
|
||||
startAndCloseRunnable,
|
||||
settingsRunnable,
|
||||
getString(R.string.start_and_close),
|
||||
getString(R.string.edit_settings)
|
||||
);
|
||||
} else {
|
||||
stopRide();
|
||||
final Runnable viewRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {}
|
||||
};
|
||||
|
||||
final Runnable stopRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
stopRide();
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
promptDialogBoolean(
|
||||
getString(R.string.ride_stop_title),
|
||||
getString(R.string.ride_stop_note),
|
||||
stopRunnable,
|
||||
viewRunnable,
|
||||
getString(R.string.stop_and_close),
|
||||
getString(R.string.view)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import com.ridelogger.RideService;
|
||||
import com.ridelogger.StartActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
@@ -62,23 +63,23 @@ public class Sensors extends Base<Object>
|
||||
mSensorManager.registerListener(luxListner, mLight, 3000000);
|
||||
}
|
||||
if(mAccel != null) {
|
||||
accelListner = new SensorEventListener() {
|
||||
private boolean crashed = false;
|
||||
private Timer timer = new Timer();
|
||||
private double[] St = new double[3];
|
||||
|
||||
@Override
|
||||
public final void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("ms2x", reduceNumberToString(event.values[0]));
|
||||
map.put("ms2y", reduceNumberToString(event.values[1]));
|
||||
map.put("ms2z", reduceNumberToString(event.values[2]));
|
||||
alterCurrentData(map);
|
||||
|
||||
if(context.detectCrash) {
|
||||
if(context.settings.getBoolean(StartActivity.DETECT_CRASH, false)) {
|
||||
accelListner = new SensorEventListener() {
|
||||
private boolean crashed = false;
|
||||
private Timer timer = new Timer();
|
||||
private double[] St = new double[3];
|
||||
|
||||
@Override
|
||||
public final void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("ms2x", reduceNumberToString(event.values[0]));
|
||||
map.put("ms2y", reduceNumberToString(event.values[1]));
|
||||
map.put("ms2z", reduceNumberToString(event.values[2]));
|
||||
alterCurrentData(map);
|
||||
|
||||
if(St.length == 0) {
|
||||
St[0] = event.values[0];
|
||||
St[1] = event.values[1];
|
||||
@@ -94,16 +95,7 @@ public class Sensors extends Base<Object>
|
||||
if(amag > CRASHMAGNITUDE && !crashed) {
|
||||
crashed = true;
|
||||
context.phoneCrash(amag);
|
||||
timer.schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
crashed = false;
|
||||
}
|
||||
},
|
||||
180000
|
||||
); //in three min reset
|
||||
|
||||
|
||||
if(context.currentValues.containsKey("KPH")) {
|
||||
timer.schedule(
|
||||
new TimerTask() {
|
||||
@@ -113,16 +105,43 @@ public class Sensors extends Base<Object>
|
||||
// confirm the crash
|
||||
if(1.0 > Double.parseDouble(context.currentValues.get("KPH"))) {
|
||||
context.phoneCrashConfirm();
|
||||
} else {
|
||||
crashed = false;
|
||||
context.phoneHome();
|
||||
}
|
||||
}
|
||||
},
|
||||
5000
|
||||
); //in five sec reset
|
||||
} else {
|
||||
timer.schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
crashed = false;
|
||||
}
|
||||
},
|
||||
180000
|
||||
); //in three min reset
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
} else {
|
||||
accelListner = new SensorEventListener() {
|
||||
@Override
|
||||
public final void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
|
||||
@Override
|
||||
public final void onSensorChanged(SensorEvent event) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("ms2x", reduceNumberToString(event.values[0]));
|
||||
map.put("ms2y", reduceNumberToString(event.values[1]));
|
||||
map.put("ms2z", reduceNumberToString(event.values[2]));
|
||||
alterCurrentData(map);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user