Add menu to enable/disable vibration on approaching.
This commit is contained in:
parent
afbd353f71
commit
fd2947d9b8
|
|
@ -182,7 +182,10 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
textViewCurrentLocation.setVisibility(View.GONE);
|
||||
|
||||
if (serviceGps == null) {
|
||||
serviceGps = new ServiceGps((Vibrator) getSystemService(Context.VIBRATOR_SERVICE));
|
||||
serviceGps = new ServiceGps(
|
||||
(Vibrator) getSystemService(Context.VIBRATOR_SERVICE),
|
||||
PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||
);
|
||||
serviceGps.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -369,6 +372,9 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
|
||||
MenuItem vibrationObjectMenuItem = menu.findItem(R.id.action_active_vibration_object);
|
||||
vibrationObjectMenuItem.setChecked(serviceGps.isVibrationNearObjectEnabled());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -399,6 +405,12 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
Toast.makeText(ctx, "Aucune trace enregistré.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (id == R.id.action_active_vibration_object) {
|
||||
boolean checked = item.isChecked();
|
||||
item.setChecked(!checked);
|
||||
serviceGps.setVibrationNearObjectEnabled(!checked);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package fr.chteufleur.mytrackingdog.services;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
|
|
@ -36,6 +36,8 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
private static final String TAG = ServiceGps.class.getName();
|
||||
public static final String NOTIF_NEW_LOCATION = "fr.chteufleur.mytrackingdog.services.servicegps.newlocation";
|
||||
|
||||
private static final String PREF_VIBRATION_NEAR_OBJECT_ENABLED = "PREF_VIBRATION_NEAR_OBJECT_ENABLED";
|
||||
|
||||
private File lastExportedTrailFile = null;
|
||||
|
||||
private LocationManager locationManager;
|
||||
|
|
@ -43,9 +45,15 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
private String appName = "";
|
||||
|
||||
private final Traces traces = new Traces();
|
||||
private final SharedPreferences preferences;
|
||||
|
||||
public ServiceGps(Vibrator vibrator) {
|
||||
public ServiceGps(Vibrator vibrator, SharedPreferences preferences) {
|
||||
this.vibrator = vibrator;
|
||||
this.preferences = preferences;
|
||||
|
||||
if (preferences != null) {
|
||||
this.vibrationNearObjectEnabled = preferences.getBoolean(PREF_VIBRATION_NEAR_OBJECT_ENABLED, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLocationManager(LocationManager locationManager) {
|
||||
|
|
@ -99,8 +107,22 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
}
|
||||
|
||||
private final Vibrator vibrator;
|
||||
private boolean vibrationNearObjectEnabled = false;
|
||||
private boolean nearObjectVibration = false;
|
||||
|
||||
public void setVibrationNearObjectEnabled(boolean b) {
|
||||
this.vibrationNearObjectEnabled = b;
|
||||
if (preferences != null) {
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean(PREF_VIBRATION_NEAR_OBJECT_ENABLED, b);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVibrationNearObjectEnabled() {
|
||||
return this.vibrationNearObjectEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
Log.i(TAG, "onLocationChanged");
|
||||
|
|
@ -110,7 +132,7 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
notifyObservers(NOTIF_NEW_LOCATION);
|
||||
|
||||
if (isDogActivated()) {
|
||||
if (isNearObjects()) {
|
||||
if (vibrationNearObjectEnabled && isNearObjects()) {
|
||||
if (!nearObjectVibration) {
|
||||
nearObjectVibration = true;
|
||||
vibrate(1_000);
|
||||
|
|
|
|||
|
|
@ -12,4 +12,12 @@
|
|||
android:orderInCategory="100"
|
||||
android:title="@string/action_send_gpx_trail"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_active_vibration_object"
|
||||
android:checkable="true"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_active_vibration_object"
|
||||
app:showAsAction="never" />
|
||||
|
||||
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -10,4 +10,5 @@
|
|||
<string name="action_import_gpx">Import GPX</string>
|
||||
<string name="action_send_gpx_trail">Envoyer trace du traceur</string>
|
||||
<string name="action_send_to">Envoyer par</string>
|
||||
<string name="action_active_vibration_object">Active vibration objets</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue