mirror of
https://github.com/ZCShou/GoGoGo.git
synced 2026-06-05 21:00:50 +08:00
feat(main): add settings for altitude
This commit is contained in:
parent
c2805c2ba9
commit
004c0789af
@ -85,6 +85,22 @@ public class FragmentSettings extends PreferenceFragmentCompat {
|
||||
});
|
||||
}
|
||||
|
||||
EditTextPreference pfAltitude = findPreference("setting_altitude");
|
||||
if (pfAltitude != null) {
|
||||
pfAltitude.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> getResources().getString(R.string.setting_current_value) + preference.getText());
|
||||
pfAltitude.setOnBindEditTextListener(editText -> {
|
||||
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
|
||||
Selection.setSelection(editText.getText(), editText.length());
|
||||
});
|
||||
pfAltitude.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if (newValue.toString().trim().length() == 0) {
|
||||
GoUtils.DisplayToast(this.getContext(),getResources().getString(R.string.app_error_input_null));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
SwitchPreferenceCompat pLog = findPreference("setting_log_off");
|
||||
if (pLog != null) {
|
||||
pLog.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
||||
@ -116,6 +116,7 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
|
||||
/* 对外 */
|
||||
public static final String LAT_MSG_ID = "LAT_VALUE";
|
||||
public static final String LNG_MSG_ID = "LNG_VALUE";
|
||||
public static final String ALT_MSG_ID = "ALT_VALUE";
|
||||
|
||||
public static final String POI_NAME = "POI_NAME";
|
||||
public static final String POI_ADDRESS = "POI_ADDRESS";
|
||||
@ -1018,6 +1019,8 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
|
||||
double[] latLng = MapUtils.bd2wgs(mMarkLatLngMap.longitude, mMarkLatLngMap.latitude);
|
||||
serviceGoIntent.putExtra(LNG_MSG_ID, latLng[0]);
|
||||
serviceGoIntent.putExtra(LAT_MSG_ID, latLng[1]);
|
||||
double alt = Double.parseDouble(sharedPreferences.getString("setting_altitude", "55.0"));
|
||||
serviceGoIntent.putExtra(ALT_MSG_ID, alt);
|
||||
|
||||
startForegroundService(serviceGoIntent);
|
||||
XLog.d("startForegroundService: ServiceGo");
|
||||
@ -1057,7 +1060,8 @@ public class MainActivity extends BaseActivity implements SensorEventListener {
|
||||
mButtonStart.setImageResource(R.drawable.ic_position);
|
||||
} else {
|
||||
double[] latLng = MapUtils.bd2wgs(mMarkLatLngMap.longitude, mMarkLatLngMap.latitude);
|
||||
mServiceBinder.setPosition(latLng[0], latLng[1]);
|
||||
double alt = Double.parseDouble(sharedPreferences.getString("setting_altitude", "55.0"));
|
||||
mServiceBinder.setPosition(latLng[0], latLng[1], alt);
|
||||
Snackbar.make(v, "已传送到新位置", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
|
||||
|
||||
@ -72,6 +72,7 @@ public class JoyStick extends View {
|
||||
private GoUtils.TimeCount mTimer;
|
||||
private boolean isMove;
|
||||
private double mSpeed = 1.2; /* 默认的速度,单位 m/s */
|
||||
private double mAltitude = 55.0;
|
||||
private double mAngle = 0;
|
||||
private double mR = 0;
|
||||
private double disLng = 0;
|
||||
@ -149,9 +150,10 @@ public class JoyStick extends View {
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentPosition(double lng, double lat) {
|
||||
public void setCurrentPosition(double lng, double lat, double alt) {
|
||||
double[] lngLat = MapUtils.wgs2bd09(lng, lat);
|
||||
mCurMapLngLat = new LatLng(lngLat[1], lngLat[0]);
|
||||
mAltitude = alt;
|
||||
|
||||
resetBaiduMap();
|
||||
}
|
||||
@ -425,7 +427,7 @@ public class JoyStick extends View {
|
||||
|
||||
public interface JoyStickClickListener {
|
||||
void onMoveInfo(double speed, double disLng, double disLat, double angle);
|
||||
void onPositionInfo(double lng, double lat);
|
||||
void onPositionInfo(double lng, double lat, double alt);
|
||||
}
|
||||
|
||||
|
||||
@ -542,7 +544,7 @@ public class JoyStick extends View {
|
||||
mMarkMapLngLat = null;
|
||||
|
||||
double[] lngLat = MapUtils.bd2wgs(mCurMapLngLat.longitude, mCurMapLngLat.latitude);
|
||||
mListener.onPositionInfo(lngLat[0], lngLat[1]);
|
||||
mListener.onPositionInfo(lngLat[0], lngLat[1], mAltitude);
|
||||
|
||||
resetBaiduMap();
|
||||
|
||||
@ -727,7 +729,7 @@ public class JoyStick extends View {
|
||||
String wgs84Longitude = wgs84latLngStr[0].substring(wgs84latLngStr[0].indexOf(':') + 1);
|
||||
String wgs84Latitude = wgs84latLngStr[1].substring(wgs84latLngStr[1].indexOf(':') + 1);
|
||||
|
||||
mListener.onPositionInfo(Double.parseDouble(wgs84Longitude), Double.parseDouble(wgs84Latitude));
|
||||
mListener.onPositionInfo(Double.parseDouble(wgs84Longitude), Double.parseDouble(wgs84Latitude), mAltitude);
|
||||
|
||||
// 注意这里在选择位置之后需要刷新地图
|
||||
String bdLatLng = (String) ((TextView) view.findViewById(R.id.BDLatLngText)).getText();
|
||||
|
||||
@ -35,9 +35,11 @@ public class ServiceGo extends Service {
|
||||
// 定位相关变量
|
||||
public static final double DEFAULT_LAT = 36.667662;
|
||||
public static final double DEFAULT_LNG = 117.027707;
|
||||
public static final double DEFAULT_ALT = 55.0D;
|
||||
public static final float DEFAULT_BEA = 0.0F;
|
||||
private double mCurLat = DEFAULT_LAT;
|
||||
private double mCurLng = DEFAULT_LNG;
|
||||
private double mCurAlt = DEFAULT_ALT;
|
||||
private float mCurBea = DEFAULT_BEA;
|
||||
private double mSpeed = 1.2; /* 默认的速度,单位 m/s */
|
||||
private static final int HANDLER_MSG_ID = 0;
|
||||
@ -86,8 +88,9 @@ public class ServiceGo extends Service {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
mCurLng = intent.getDoubleExtra(MainActivity.LNG_MSG_ID, DEFAULT_LNG);
|
||||
mCurLat = intent.getDoubleExtra(MainActivity.LAT_MSG_ID, DEFAULT_LAT);
|
||||
mCurAlt = intent.getDoubleExtra(MainActivity.ALT_MSG_ID, DEFAULT_ALT);
|
||||
|
||||
mJoyStick.setCurrentPosition(mCurLng, mCurLat);
|
||||
mJoyStick.setCurrentPosition(mCurLng, mCurLat, mCurAlt);
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
@ -160,9 +163,10 @@ public class ServiceGo extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositionInfo(double lng, double lat) {
|
||||
public void onPositionInfo(double lng, double lat, double alt) {
|
||||
mCurLng = lng;
|
||||
mCurLat = lat;
|
||||
mCurAlt = alt;
|
||||
}
|
||||
});
|
||||
mJoyStick.show();
|
||||
@ -233,7 +237,7 @@ public class ServiceGo extends Service {
|
||||
// 尽可能模拟真实的 GPS 数据
|
||||
Location loc = new Location(LocationManager.GPS_PROVIDER);
|
||||
loc.setAccuracy(Criteria.ACCURACY_FINE); // 设定此位置的估计水平精度,以米为单位。
|
||||
loc.setAltitude(55.0D); // 设置高度,在 WGS 84 参考坐标系中的米
|
||||
loc.setAltitude(mCurAlt); // 设置高度,在 WGS 84 参考坐标系中的米
|
||||
loc.setBearing(mCurBea); // 方向(度)
|
||||
loc.setLatitude(mCurLat); // 纬度(度)
|
||||
loc.setLongitude(mCurLng); // 经度(度)
|
||||
@ -288,7 +292,7 @@ public class ServiceGo extends Service {
|
||||
// 尽可能模拟真实的 NETWORK 数据
|
||||
Location loc = new Location(LocationManager.NETWORK_PROVIDER);
|
||||
loc.setAccuracy(Criteria.ACCURACY_COARSE); // 设定此位置的估计水平精度,以米为单位。
|
||||
loc.setAltitude(55.0D); // 设置高度,在 WGS 84 参考坐标系中的米
|
||||
loc.setAltitude(mCurAlt); // 设置高度,在 WGS 84 参考坐标系中的米
|
||||
loc.setBearing(mCurBea); // 方向(度)
|
||||
loc.setLatitude(mCurLat); // 纬度(度)
|
||||
loc.setLongitude(mCurLng); // 经度(度)
|
||||
@ -319,12 +323,13 @@ public class ServiceGo extends Service {
|
||||
}
|
||||
|
||||
public class ServiceGoBinder extends Binder {
|
||||
public void setPosition(double lng, double lat) {
|
||||
public void setPosition(double lng, double lat, double alt) {
|
||||
mLocHandler.removeMessages(HANDLER_MSG_ID);
|
||||
mCurLng = lng;
|
||||
mCurLat = lat;
|
||||
mCurAlt = alt;
|
||||
mLocHandler.sendEmptyMessage(HANDLER_MSG_ID);
|
||||
mJoyStick.setCurrentPosition(mCurLng, mCurLat);
|
||||
mJoyStick.setCurrentPosition(mCurLng, mCurLat, mCurAlt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +63,8 @@
|
||||
<string name="setting_run_default">3.6</string>
|
||||
<string name="setting_bike">驾驶速度(米/秒)</string>
|
||||
<string name="setting_bike_default">10.0</string>
|
||||
<string name="setting_altitude">海拔高度(米)</string>
|
||||
<string name="setting_altitude_default">55.0</string>
|
||||
<string name="setting_group_log">记录</string>
|
||||
<string name="setting_log_off">关闭日志</string>
|
||||
<string name="setting_pos_history">历史记录有效期(天)</string>
|
||||
|
||||
@ -34,6 +34,14 @@
|
||||
app:defaultValue="@string/setting_bike_default"
|
||||
app:summary="@string/setting_bike_default"
|
||||
app:iconSpaceReserved="false"/>
|
||||
|
||||
<EditTextPreference
|
||||
app:key="setting_altitude"
|
||||
app:title="@string/setting_altitude"
|
||||
app:defaultValue="@string/setting_altitude_default"
|
||||
app:summary="@string/setting_altitude_default"
|
||||
app:iconSpaceReserved="false"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
||||
Loading…
Reference in New Issue
Block a user