Skip to content

Commit

Permalink
fix(joystick):fix joystick history ui Scale when open search
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Oct 16, 2022
1 parent 02e060f commit 60d4a9d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 77 deletions.
149 changes: 75 additions & 74 deletions app/src/main/java/com/zcshou/joystick/JoyStick.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,80 @@ public void onFinish() {
}
}

private void processDirection(boolean auto, double angle, double r) {
if (r <= 0) {
mTimer.cancel();
isMove = false;
} else {
mAngle = angle;
mR = r;
if (auto) {
if (!isMove) {
mTimer.start();
isMove = true;
}
} else {
mTimer.cancel();
isMove = false;
// 注意:这里的 x y 与 圆中角度的对应问题(以 X 轴正向为 0 度)且转换为 km
disLng = mSpeed * (double)(DivGo / 1000) * mR * Math.cos(mAngle * 2 * Math.PI / 360) / 1000;// 注意安卓中的三角函数使用的是弧度
disLat = mSpeed * (double)(DivGo / 1000) * mR * Math.sin(mAngle * 2 * Math.PI / 360) / 1000;// 注意安卓中的三角函数使用的是弧度
mListener.onMoveInfo(mSpeed, disLng, disLat);
}
}
}

private class JoyStickOnTouchListener implements OnTouchListener {
private int x;
private int y;

@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x = (int) event.getRawX();
y = (int) event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int nowX = (int) event.getRawX();
int nowY = (int) event.getRawY();
int movedX = nowX - x;
int movedY = nowY - y;
x = nowX;
y = nowY;
switch (mCurWin) {
case WINDOW_TYPE_MAP:
mWindowParamMap.x = mWindowParamMap.x + movedX;
mWindowParamMap.y = mWindowParamMap.y + movedY;
mWindowManager.updateViewLayout(view, mWindowParamMap);
break;
case WINDOW_TYPE_HISTORY:
mWindowParamHistory.x = mWindowParamHistory.x + movedX;
mWindowParamHistory.y = mWindowParamHistory.y + movedY;
mWindowManager.updateViewLayout(view, mWindowParamHistory);
break;
case WINDOW_TYPE_JOYSTICK:
mWindowParamJoyStick.x = mWindowParamJoyStick.x + movedX;
mWindowParamJoyStick.y = mWindowParamJoyStick.y + movedY;
mWindowManager.updateViewLayout(view, mWindowParamJoyStick);
break;
}
break;
case MotionEvent.ACTION_UP:
view.performClick();
break;
default:
break;
}
return false;
}
}

public interface JoyStickClickListener {
void onMoveInfo(double speed, double disLng, double disLat);
void onPositionInfo(double lng, double lat);
}

@SuppressLint({"InflateParams", "ClickableViewAccessibility"})
private void initJoyStickMapView() {
mMapLayout = (FrameLayout)inflater.inflate(R.layout.joystick_map, null);
Expand Down Expand Up @@ -576,6 +650,7 @@ private void markBaiduMap(LatLng latLng) {
mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
}


@SuppressLint({"InflateParams", "ClickableViewAccessibility"})
private void initHistoryView() {
mHistoryLayout = (FrameLayout)inflater.inflate(R.layout.joystick_history, null);
Expand Down Expand Up @@ -749,78 +824,4 @@ private void showHistory(List<Map<String, Object>> list) {
}
}
}

private void processDirection(boolean auto, double angle, double r) {
if (r <= 0) {
mTimer.cancel();
isMove = false;
} else {
mAngle = angle;
mR = r;
if (auto) {
if (!isMove) {
mTimer.start();
isMove = true;
}
} else {
mTimer.cancel();
isMove = false;
// 注意:这里的 x y 与 圆中角度的对应问题(以 X 轴正向为 0 度)且转换为 km
disLng = mSpeed * (double)(DivGo / 1000) * mR * Math.cos(mAngle * 2 * Math.PI / 360) / 1000;// 注意安卓中的三角函数使用的是弧度
disLat = mSpeed * (double)(DivGo / 1000) * mR * Math.sin(mAngle * 2 * Math.PI / 360) / 1000;// 注意安卓中的三角函数使用的是弧度
mListener.onMoveInfo(mSpeed, disLng, disLat);
}
}
}

private class JoyStickOnTouchListener implements OnTouchListener {
private int x;
private int y;

@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x = (int) event.getRawX();
y = (int) event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int nowX = (int) event.getRawX();
int nowY = (int) event.getRawY();
int movedX = nowX - x;
int movedY = nowY - y;
x = nowX;
y = nowY;
switch (mCurWin) {
case WINDOW_TYPE_MAP:
mWindowParamMap.x = mWindowParamMap.x + movedX;
mWindowParamMap.y = mWindowParamMap.y + movedY;
mWindowManager.updateViewLayout(view, mWindowParamMap);
break;
case WINDOW_TYPE_HISTORY:
mWindowParamHistory.x = mWindowParamHistory.x + movedX;
mWindowParamHistory.y = mWindowParamHistory.y + movedY;
mWindowManager.updateViewLayout(view, mWindowParamHistory);
break;
case WINDOW_TYPE_JOYSTICK:
mWindowParamJoyStick.x = mWindowParamJoyStick.x + movedX;
mWindowParamJoyStick.y = mWindowParamJoyStick.y + movedY;
mWindowManager.updateViewLayout(view, mWindowParamJoyStick);
break;
}
break;
case MotionEvent.ACTION_UP:
view.performClick();
break;
default:
break;
}
return false;
}
}

public interface JoyStickClickListener {
void onMoveInfo(double speed, double disLng, double disLat);
void onPositionInfo(double lng, double lat);
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/joystick_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_width="300dp"
android:layout_height="500dp"
android:minHeight="340dp"
android:minWidth="340dp"
Expand All @@ -25,7 +25,7 @@
android:layout_marginEnd="40dp"
android:iconifiedByDefault="true"
app:showAsAction="collapseActionView|ifRoom"
android:queryHint="请输入搜索内容" />
android:queryHint="@string/app_search_tips" />

<ImageButton
android:id="@+id/joystick_his_close"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/joystick_map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:layout_marginEnd="40dp"
android:iconifiedByDefault="true"
app:showAsAction="collapseActionView|ifRoom"
android:queryHint="请输入搜索内容" />
android:queryHint="@string/app_search_tips" />

<ImageButton
android:id="@+id/map_close"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<string name="app_error_longitude">经度超出限制!\n取值:-180.0 ~ 180.0</string>
<string name="app_error_latitude">纬度超出限制!\n取值:-90.0 ~ 90.0</string>
<string name="app_search_null">没有匹配结果,请重新搜索</string>
<string name="app_search_tips">请输入查找内容</string>
<string name="app_location_ok">位置已传送</string>
<string name="app_location_copy">位置已复制到剪切板</string>
<string name="app_location_save">位置已保存</string>
Expand Down

0 comments on commit 60d4a9d

Please sign in to comment.