Skip to content

Commit

Permalink
增加了启动模拟位置时检测WIFI
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Nov 8, 2020
1 parent 4fcb62b commit 84fd3fb
Show file tree
Hide file tree
Showing 12 changed files with 1,191 additions and 986 deletions.
45 changes: 28 additions & 17 deletions .project
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GoGoGo</name>
<comment>Project GoGoGo created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GoGoGo</name>
<comment>Project GoGoGo created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1604809825384</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
26 changes: 13 additions & 13 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=C\:/Program Files/Java/jdk-11.0.8
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=C\:/Program Files/Java/jdk-11.0.8
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
6 changes: 6 additions & 0 deletions app/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
34 changes: 34 additions & 0 deletions app/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1604809825395</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
2 changes: 2 additions & 0 deletions app/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ android {
applicationId "com.zcshou.gogogo"
minSdkVersion 21
targetSdkVersion 30
versionCode 107
versionName "1.0.7"
versionCode 108
versionName "1.0.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
ndkVersion '21.3.6528147'
buildTypes {
release {
minifyEnabled false
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
10 changes: 4 additions & 6 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"version": 1,
"version": 2,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.zcshou.gogogo",
"variantName": "release",
"variantName": "processReleaseResources",
"elements": [
{
"type": "SINGLE",
"filters": [],
"properties": [],
"versionCode": 107,
"versionName": "1.0.7",
"enabled": true,
"versionCode": 108,
"versionName": "1.0.8",
"outputFile": "app-release.apk"
}
]
Expand Down
124 changes: 87 additions & 37 deletions app/src/main/java/com/zcshou/gogogo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
Expand Down Expand Up @@ -64,14 +65,15 @@
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMapOptions;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
//import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
//import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
Expand Down Expand Up @@ -129,7 +131,7 @@ public class MainActivity extends BaseActivity
private boolean isGPSOpen = false;
private boolean isFirstLoc = true; // 是否首次定位

private static final long mTS = 1607472000;
private static final long mTS = 1609286400;

//位置历史
private SQLiteDatabase locHistoryDB;
Expand Down Expand Up @@ -657,6 +659,14 @@ public boolean isAllowMockLocation() {
return canMockPosition;
}

//WIFI是否开启
public boolean isWiFiEnabled() {
Context context = this.getApplicationContext();
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
return wifiManager.isWifiEnabled();
}

//WIFI是否可用
private boolean isWifiConnected() {
ConnectivityManager mConnectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
Expand Down Expand Up @@ -777,6 +787,27 @@ public void onClick(DialogInterface dialog, int which) {
.show();
}

//显示开启 WIFI 的提示
private void showWifiWarningDialog() {
new AlertDialog.Builder(MainActivity.this)
.setTitle("警告")//这里是表头的内容
.setMessage("由于实现原理的限制,如果开启 WIFI 将导致位置频繁闪回真实位置,使用数据流量可完美解决闪回的问题")//这里是中间显示的具体信息
.setPositiveButton("继续",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doGoLocation();
}
})
.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}

//显示输入经纬度的对话框
public void showInputLatLngDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
Expand Down Expand Up @@ -1102,6 +1133,17 @@ private void initBaiduMap() {
mBaiduMap = mMapView.getMap();
mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
mBaiduMap.setMyLocationEnabled(true);
// mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
//
// @Override
// public boolean onMarkerClick(Marker marker) {
// View markView = View.inflate(getApplicationContext(), layout.map_overlay, null);
// LatLng ll = marker.getPosition();
// InfoWindow mInfoWindow = new InfoWindow(BitmapDescriptorFactory.fromView(markView), ll, -47, null);
// mBaiduMap.showInfoWindow(mInfoWindow);
// return true;
// }
// });
initMapListener();
}

Expand Down Expand Up @@ -1606,6 +1648,46 @@ private List<Map<String, Object>> getSearchHistory() {
return data;
}

private void doGoLocation() {
if (!isMockServStart && !isServiceRun) {
Log.d("DEBUG", "Current Baidu LatLng: " + curMapLatLng.longitude + " " + curMapLatLng.latitude);
log.debug("Current Baidu LatLng: " + curMapLatLng.longitude + " " + curMapLatLng.latitude);

markSelectedPosition();

//start mock location service
Intent mockLocServiceIntent = new Intent(MainActivity.this, GoService.class);
mockLocServiceIntent.putExtra("CurLatLng", curLatLng);

//save record
recordGetPositionInfo();

//insert end
if (Build.VERSION.SDK_INT >= 26) {
startForegroundService(mockLocServiceIntent);
Log.d("DEBUG", "startForegroundService: GoService");
log.debug("startForegroundService: GoService");
} else {
startService(mockLocServiceIntent);
Log.d("DEBUG", "startService: GoService");
log.debug("startService: GoService");
}

isMockServStart = true;
// Snackbar.make(view, "位置模拟已开启", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
faBtnStart.hide();
faBtnStop.show();
//track
} else {
// Snackbar.make(view, "位置模拟已在运行", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
faBtnStart.hide();
faBtnStop.show();
isMockServStart = true;
}
}

private void startGoLocation() {
if (!isLimit && isNetworkAvailable()) { // 时间限制
//悬浮窗权限判断
Expand All @@ -1626,42 +1708,10 @@ private void startGoLocation() {
if (!isAllowMockLocation()) {
showEnableMockLocationDialog();
} else {
if (!isMockServStart && !isServiceRun) {
Log.d("DEBUG", "Current Baidu LatLng: " + curMapLatLng.longitude + " " + curMapLatLng.latitude);
log.debug("Current Baidu LatLng: " + curMapLatLng.longitude + " " + curMapLatLng.latitude);

markSelectedPosition();

//start mock location service
Intent mockLocServiceIntent = new Intent(MainActivity.this, GoService.class);
mockLocServiceIntent.putExtra("CurLatLng", curLatLng);

//save record
recordGetPositionInfo();

//insert end
if (Build.VERSION.SDK_INT >= 26) {
startForegroundService(mockLocServiceIntent);
Log.d("DEBUG", "startForegroundService: GoService");
log.debug("startForegroundService: GoService");
} else {
startService(mockLocServiceIntent);
Log.d("DEBUG", "startService: GoService");
log.debug("startService: GoService");
}

isMockServStart = true;
// Snackbar.make(view, "位置模拟已开启", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
faBtnStart.hide();
faBtnStop.show();
//track
if (isWiFiEnabled()) {
showWifiWarningDialog();
} else {
// Snackbar.make(view, "位置模拟已在运行", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
faBtnStart.hide();
faBtnStop.show();
isMockServStart = true;
doGoLocation();
}
}
}
Expand Down
Loading

0 comments on commit 84fd3fb

Please sign in to comment.