完成寻宝页面的地图展示
10
.idea/jarRepositories.xml
generated
@ -31,5 +31,15 @@
|
||||
<option name="name" value="maven" />
|
||||
<option name="url" value="https://jitpack.io" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven" />
|
||||
<option name="name" value="maven" />
|
||||
<option name="url" value="https://maven.aliyun.com/repository/apache-snapshots" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
2
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -22,9 +22,9 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
//efs {
|
||||
@ -54,8 +54,8 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
implementation 'com.umeng.umsdk:common:9.3.8'
|
||||
implementation 'com.umeng.umsdk:asms:1.2.2'
|
||||
implementation 'com.umeng.umsdk:common:9.3.8'
|
||||
implementation 'com.umeng.umsdk:asms:1.2.2'
|
||||
implementation 'com.umeng.umsdk:apm:1.2.0'
|
||||
|
||||
//状态栏侵染
|
||||
@ -65,7 +65,6 @@ dependencies {
|
||||
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
|
||||
|
||||
|
||||
|
||||
//网络框架
|
||||
implementation 'com.lzy.net:okgo:3.0.4'
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
@ -96,4 +95,12 @@ dependencies {
|
||||
implementation project(':xrecyclerview')
|
||||
|
||||
|
||||
//腾讯地图
|
||||
// 地图库
|
||||
implementation 'com.tencent.map:tencent-map-vector-sdk:4.4.2'
|
||||
// 地图组件库,包括小车平移、点聚合等组件功能,详见开发指南。
|
||||
implementation 'com.tencent.map:sdk-utilities:1.0.6'
|
||||
|
||||
//腾讯地图 定位
|
||||
implementation 'com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.2.6'
|
||||
}
|
@ -8,12 +8,38 @@
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<!-- <uses-sdk android:minSdkVersion="8"></uses-sdk>-->
|
||||
|
||||
<!--友盟检测bug-->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<!-- 腾讯地图 定位权限-->
|
||||
<!-- 通过GPS得到精确位置 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<!-- 通过网络得到粗略位置 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- 访问网络. 某些位置信息需要从网络服务器获取 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- 访问WiFi状态. 需要WiFi信息用于网络定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<!-- 修改WiFi状态. 发起WiFi扫描, 需要WiFi信息用于网络定位 -->
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<!-- 访问网络状态, 检测网络的可用性. 需要网络运营商相关信息用于网络定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!-- 访问网络的变化, 需要某些信息用于网络定位 -->
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<!-- 访问手机当前状态, 需要device id用于网络定位 -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<!-- 访问蓝牙状态,需要蓝牙信息用于网络定位 -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||
<!-- 支持A-GPS辅助定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
<!-- 用于 log 日志 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
|
||||
<application
|
||||
android:name="com.navinfo.outdoor.api.UserApplication"
|
||||
android:allowBackup="true"
|
||||
@ -23,6 +49,11 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
|
||||
<!-- 腾讯地图申请Key 定位-->
|
||||
<meta-data android:name="TencentMapSDK" android:value="EWWBZ-2PB62-6JXUL-CEX7G-N7UE6-XRB4V" />
|
||||
|
||||
|
||||
<meta-data
|
||||
android:name="design_width_in_dp"
|
||||
android:value="480" />
|
||||
|
28
app/src/main/java/com/navinfo/outdoor/api/Constant.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.navinfo.outdoor.api;
|
||||
|
||||
import com.tencent.map.geolocation.TencentLocation;
|
||||
|
||||
/**
|
||||
* 常量
|
||||
*/
|
||||
public class Constant {
|
||||
/**
|
||||
* 当前网络不可用
|
||||
*/
|
||||
public static final CharSequence NETWORK_UNAVAILABLE = "当前网络不可用,请检查网络设置";
|
||||
|
||||
/**
|
||||
* 位置权限
|
||||
*/
|
||||
public static final String SET_LOCATION_PERMISSION = "请在“设置”中给予“TengXunMap”位置权限,否则当前功能将不可使用";
|
||||
|
||||
|
||||
public static final String GET_ERR_MESSAGE1 = "设备缺少使用腾讯定位服务需要的基本条件";
|
||||
public static final String GET_ERR_MESSAGE2 = "manifest 中配置的 key 不正确";
|
||||
public static final String GET_ERR_MESSAGE3 = "自动加载libtencentloc.so失败";
|
||||
|
||||
/**
|
||||
* 用户当前位置
|
||||
*/
|
||||
public static TencentLocation currentLocation;
|
||||
}
|
@ -25,6 +25,7 @@ public class UserApplication extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
userApplication=this;
|
||||
//友盟 检测bug
|
||||
UMConfigure.init(this, "60b885bd6c421a3d97db55e6", "navinfo", UMConfigure.DEVICE_TYPE_PHONE, "");
|
||||
/**
|
||||
*设置组件化的Log开关
|
||||
|
@ -1,13 +1,65 @@
|
||||
package com.navinfo.outdoor.fragment;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.location.Location;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.base.BaseFragment;
|
||||
import com.navinfo.outdoor.util.NetWorkUtils;
|
||||
import com.navinfo.outdoor.util.ToastUtil;
|
||||
import com.tencent.map.geolocation.TencentLocation;
|
||||
import com.tencent.map.geolocation.TencentLocationListener;
|
||||
import com.tencent.map.geolocation.TencentLocationManager;
|
||||
import com.tencent.map.geolocation.TencentLocationRequest;
|
||||
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
|
||||
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
|
||||
import com.tencent.tencentmap.mapsdk.maps.LocationSource;
|
||||
import com.tencent.tencentmap.mapsdk.maps.MapView;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
|
||||
import com.tencent.tencentmap.mapsdk.maps.UiSettings;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
|
||||
|
||||
import static com.lzy.okgo.utils.HttpUtils.runOnUiThread;
|
||||
|
||||
/**
|
||||
* 寻宝的Fragment
|
||||
* 2021-5-25
|
||||
*/
|
||||
public class TreasureFragment extends BaseFragment {
|
||||
public class TreasureFragment extends BaseFragment implements View.OnClickListener, LocationSource, TencentLocationListener {
|
||||
private MapView treasureMap;
|
||||
private TencentMap tencentMap;
|
||||
private CheckBox cbMapType;
|
||||
private ImageView ivZoomAdd;
|
||||
private ImageView ivZoomDel;
|
||||
private TencentLocationManager locationManager;
|
||||
private TencentLocationRequest locationRequest;
|
||||
private MyLocationStyle locationStyle;
|
||||
private OnLocationChangedListener locationChangedListener;
|
||||
private ImageView ivLocation;
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.treasure_fragment;
|
||||
@ -16,10 +68,277 @@ public class TreasureFragment extends BaseFragment {
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
treasureMap = (MapView) findViewById(R.id.treasure_map);
|
||||
tencentMap = treasureMap.getMap();
|
||||
cbMapType = (CheckBox) findViewById(R.id.cb_map_type);
|
||||
//地图转换
|
||||
cbMapType.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
tencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE);
|
||||
} else {
|
||||
tencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL);
|
||||
}
|
||||
}
|
||||
});
|
||||
//地图放大
|
||||
ivZoomAdd = (ImageView) findViewById(R.id.iv_zoom_add);
|
||||
ivZoomAdd.setOnClickListener(this::onClick);
|
||||
//地图缩小
|
||||
ivZoomDel = (ImageView) findViewById(R.id.iv_zoom_del);
|
||||
ivZoomDel.setOnClickListener(this::onClick);
|
||||
//回到定位位置
|
||||
ivLocation = findViewById(R.id.iv_location);
|
||||
ivLocation.setOnClickListener(this::onClick);
|
||||
//样式
|
||||
tencentMap.setMapStyle(2);
|
||||
//启用3d视图
|
||||
tencentMap.setBuilding3dEffectEnable(true);
|
||||
//获取地图UI 设置对象
|
||||
UiSettings uiSettings = tencentMap.getUiSettings();
|
||||
//设置logo的大小
|
||||
uiSettings.setLogoScale(0.7f);
|
||||
//开启定位权限
|
||||
checkNetWork();
|
||||
}
|
||||
/**
|
||||
* 设置定位图标样式
|
||||
*/
|
||||
private void setLocMarkerStyle() {
|
||||
locationStyle = new MyLocationStyle();
|
||||
//创建图标
|
||||
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location));
|
||||
locationStyle.icon(bitmapDescriptor);
|
||||
//设置定位圆形区域的边框宽度;
|
||||
locationStyle.strokeWidth(1);
|
||||
//设置圆区域的颜色
|
||||
// locationStyle.fillColor(R.color.colormap);
|
||||
// locationStyle.anchor(1000,2000);
|
||||
tencentMap.setMyLocationStyle(locationStyle);
|
||||
}
|
||||
/**
|
||||
* 定位的一些初始化设置
|
||||
*/
|
||||
private void initLocation() {
|
||||
//用于访问腾讯定位服务的类, 周期性向客户端提供位置更新
|
||||
locationManager = TencentLocationManager.getInstance(getContext());
|
||||
//设置坐标系
|
||||
locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02);
|
||||
//创建定位请求
|
||||
locationRequest = TencentLocationRequest.create();
|
||||
//设置定位周期(位置监听器回调周期)为3s
|
||||
locationRequest.setInterval(3000);
|
||||
//地图上设置定位数据源
|
||||
tencentMap.setLocationSource(this);
|
||||
//设置当前位置可见
|
||||
tencentMap.setMyLocationEnabled(true);
|
||||
//设置定位图标样式
|
||||
setLocMarkerStyle();
|
||||
// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
|
||||
tencentMap.setMyLocationStyle(locationStyle);
|
||||
}
|
||||
private Bitmap getBitMap(int resourceId) {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
int newWidth = 55;
|
||||
int newHeight = 55;
|
||||
float widthScale = ((float) newWidth) / width;
|
||||
float heightScale = ((float) newHeight) / height;
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(widthScale, heightScale);
|
||||
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
treasureMap.onStart();
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
treasureMap.onResume();
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
treasureMap.onPause();
|
||||
}
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
treasureMap.onStop();
|
||||
}
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
treasureMap.onDestroy();
|
||||
}
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_zoom_add://放大
|
||||
CameraUpdate cameraUpdateIn = CameraUpdateFactory.zoomIn();
|
||||
tencentMap.animateCamera(cameraUpdateIn);
|
||||
break;
|
||||
case R.id.iv_zoom_del://缩小
|
||||
CameraUpdate cameraUpdateOut = CameraUpdateFactory.zoomOut();
|
||||
tencentMap.animateCamera(cameraUpdateOut);
|
||||
break;
|
||||
case R.id.iv_location://定位:
|
||||
Constant.currentLocation.getLongitude();
|
||||
CameraUpdate cameraSigma =
|
||||
CameraUpdateFactory.newCameraPosition(new CameraPosition(
|
||||
new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), //中心点坐标,地图目标经纬度
|
||||
19, //目标缩放级别
|
||||
0, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
|
||||
0)); //目标旋转角 0~360° (正北方为0)
|
||||
tencentMap.animateCamera(cameraSigma);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查网络状态
|
||||
*/
|
||||
private void checkNetWork() {
|
||||
if (NetWorkUtils.isNetworkAvailable(getContext())) { // 当前网络可用
|
||||
checkMyLocation();
|
||||
} else { // 当前网络不可用
|
||||
ToastUtil.showShort(getContext(), Constant.NETWORK_UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查所需权限
|
||||
*/
|
||||
private void checkMyLocation() {
|
||||
// 1.判断是否拥有定位的权限
|
||||
// 1.1 拥有权限进行相应操作
|
||||
// 1.2 没有权限申请权限
|
||||
// 1.2.1 Android 6.0 动态申请权限
|
||||
// 1.2.1.1 用户给予权限进行相应操作
|
||||
// 1.2.1.2 用户没有给予权限 作出相应提示
|
||||
// 1.2.2 某些5.0权限的手机执行相应操作
|
||||
String[] permission = {
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
};
|
||||
if (ContextCompat.checkSelfPermission(getContext(), permission[0]) == PackageManager.PERMISSION_GRANTED) { // 拥有权限
|
||||
//建立定位
|
||||
initLocation();
|
||||
} else { // 没有权限
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //6.0
|
||||
requestPermissions(permission, 0);
|
||||
} else {
|
||||
// 此处为某些5.0动态权限的手机
|
||||
//goSystemLocationActivity(); // TODO =======待删除======
|
||||
tipPermissionAlertDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 用户授权回调
|
||||
*
|
||||
* @param requestCode
|
||||
* @param permissions
|
||||
* @param grantResults
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
UserAuthorization(requestCode, grantResults);
|
||||
}
|
||||
/**
|
||||
* 用户授权情况
|
||||
*
|
||||
* @param requestCode
|
||||
* @param grantResults
|
||||
*/
|
||||
private void UserAuthorization(int requestCode, int[] grantResults) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // 拥有了授权
|
||||
checkMyLocation();
|
||||
} else {
|
||||
tipPermissionAlertDialog();
|
||||
}
|
||||
}
|
||||
private void tipPermissionAlertDialog() {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle("提示");
|
||||
builder.setMessage(Constant.SET_LOCATION_PERMISSION);
|
||||
builder.setPositiveButton("我知道了", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AlertDialog alertDialog = builder.show();
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
/**
|
||||
* 跳转系统定位页面
|
||||
*/
|
||||
private void goSystemLocationActivity() {
|
||||
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
||||
}
|
||||
@Override
|
||||
public void activate(OnLocationChangedListener onLocationChangedListener) {
|
||||
locationChangedListener = onLocationChangedListener;
|
||||
int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper());
|
||||
switch (err) {
|
||||
case 1:
|
||||
ToastUtil.showShort(getContext(), Constant.GET_ERR_MESSAGE1);
|
||||
break;
|
||||
case 2:
|
||||
ToastUtil.showShort(getContext(), Constant.GET_ERR_MESSAGE2);
|
||||
break;
|
||||
case 3:
|
||||
ToastUtil.showShort(getContext(), Constant.GET_ERR_MESSAGE3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void deactivate() {
|
||||
locationManager.removeUpdates(this);
|
||||
locationManager = null;
|
||||
locationRequest = null;
|
||||
locationChangedListener = null;
|
||||
}
|
||||
/**
|
||||
* 实现位置监听
|
||||
*
|
||||
* @param tencentLocation
|
||||
* @param i
|
||||
* @param s
|
||||
*/
|
||||
@Override
|
||||
public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
|
||||
if (i == TencentLocation.ERROR_OK && locationChangedListener != null) {
|
||||
Location location = new Location(tencentLocation.getProvider());
|
||||
//设置经纬度以及精度
|
||||
location.setLatitude(tencentLocation.getLatitude());
|
||||
location.setLongitude(tencentLocation.getLongitude());
|
||||
location.setAccuracy(tencentLocation.getAccuracy());
|
||||
locationChangedListener.onLocationChanged(location);
|
||||
Constant.currentLocation = tencentLocation;
|
||||
//显示回调的实时位置信息
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//打印tencentLocation的json字符串
|
||||
// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onStatusUpdate(String s, int i, String s1) {
|
||||
//GPS, WiFi, Radio 等状态发生变化
|
||||
Log.v("State changed", s + "===" + s1);
|
||||
}
|
||||
}
|
35
app/src/main/java/com/navinfo/outdoor/util/NetWorkUtils.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
/**
|
||||
* 项目名称:网络工具类
|
||||
* 创建人: mwb
|
||||
* 创建时间:2018/9/3 8:57
|
||||
*/
|
||||
public class NetWorkUtils {
|
||||
/**
|
||||
* 当前网络是否可用
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static boolean isNetworkAvailable(Context context) {
|
||||
ConnectivityManager connectivityManager =
|
||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if (connectivityManager != null) {
|
||||
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
|
||||
if (info != null && info.isConnected()) {
|
||||
// 当前网络是连接的
|
||||
if (info.getState() == NetworkInfo.State.CONNECTED) {
|
||||
// 当前所链接的网络可用
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
286
app/src/main/java/com/navinfo/outdoor/util/ToastUtil.java
Normal file
@ -0,0 +1,286 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* 项目名称:ToastUtil
|
||||
* 创建人:mwb
|
||||
* 创建时间:2018/9/3 9:25
|
||||
*/
|
||||
public class ToastUtil {
|
||||
private static boolean isShow = true;//默认显示
|
||||
private static Toast mToast = null;//全局唯一的Toast
|
||||
|
||||
/*private控制不应该被实例化*/
|
||||
private ToastUtil() {
|
||||
throw new UnsupportedOperationException("不能被实例化");
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局控制是否显示Toast
|
||||
*
|
||||
* @param isShowToast
|
||||
*/
|
||||
public static void controlShow(boolean isShowToast) {
|
||||
isShow = isShowToast;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消Toast显示
|
||||
*/
|
||||
public void cancelToast() {
|
||||
if (isShow && mToast != null) {
|
||||
mToast.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 短时间显示Toast
|
||||
*
|
||||
* @param context
|
||||
* @param message
|
||||
*/
|
||||
public static void showShort(Context context, CharSequence message) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
|
||||
} else {
|
||||
mToast.setText(message);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 短时间显示Toast
|
||||
*
|
||||
* @param context
|
||||
* @param resId 资源ID:getResources().getString(R.string.xxxxxx);
|
||||
*/
|
||||
public static void showShort(Context context, int resId) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
|
||||
} else {
|
||||
mToast.setText(resId);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 长时间显示Toast
|
||||
*
|
||||
* @param context
|
||||
* @param message
|
||||
*/
|
||||
public static void showLong(Context context, CharSequence message) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, message, Toast.LENGTH_LONG);
|
||||
} else {
|
||||
mToast.setText(message);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 长时间显示Toast
|
||||
*
|
||||
* @param context
|
||||
* @param resId 资源ID:getResources().getString(R.string.xxxxxx);
|
||||
*/
|
||||
public static void showLong(Context context, int resId) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
|
||||
} else {
|
||||
mToast.setText(resId);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义显示Toast时间
|
||||
*
|
||||
* @param context
|
||||
* @param message
|
||||
* @param duration 单位:毫秒
|
||||
*/
|
||||
public static void show(Context context, CharSequence message, int duration) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, message, duration);
|
||||
} else {
|
||||
mToast.setText(message);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义显示Toast时间
|
||||
*
|
||||
* @param context
|
||||
* @param resId 资源ID:getResources().getString(R.string.xxxxxx);
|
||||
* @param duration 单位:毫秒
|
||||
*/
|
||||
public static void show(Context context, int resId, int duration) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, resId, duration);
|
||||
} else {
|
||||
mToast.setText(resId);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Toast的View
|
||||
*
|
||||
* @param context
|
||||
* @param message
|
||||
* @param duration 单位:毫秒
|
||||
* @param view 显示自己的View
|
||||
*/
|
||||
public static void customToastView(Context context, CharSequence message, int duration, View view) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, message, duration);
|
||||
} else {
|
||||
mToast.setText(message);
|
||||
}
|
||||
if (view != null) {
|
||||
mToast.setView(view);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Toast的位置
|
||||
*
|
||||
* @param context
|
||||
* @param message
|
||||
* @param duration 单位:毫秒
|
||||
* @param gravity
|
||||
* @param xOffset
|
||||
* @param yOffset
|
||||
*/
|
||||
public static void customToastGravity(Context context, CharSequence message, int duration, int gravity, int xOffset, int yOffset) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, message, duration);
|
||||
} else {
|
||||
mToast.setText(message);
|
||||
}
|
||||
mToast.setGravity(gravity, xOffset, yOffset);
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义带图片和文字的Toast,最终的效果就是上面是图片,下面是文字
|
||||
*
|
||||
* @param context
|
||||
* @param message
|
||||
* @param iconResId 图片的资源id,如:R.drawable.icon
|
||||
* @param duration
|
||||
* @param gravity
|
||||
* @param xOffset
|
||||
* @param yOffset
|
||||
*/
|
||||
public static void showToastWithImageAndText(Context context, CharSequence message, int iconResId, int duration, int gravity, int xOffset, int yOffset) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, message, duration);
|
||||
} else {
|
||||
mToast.setText(message);
|
||||
}
|
||||
mToast.setGravity(gravity, xOffset, yOffset);
|
||||
LinearLayout toastView = (LinearLayout) mToast.getView();
|
||||
ImageView imageView = new ImageView(context);
|
||||
imageView.setImageResource(iconResId);
|
||||
toastView.addView(imageView, 0);
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Toast,针对类型CharSequence
|
||||
*
|
||||
* @param context
|
||||
* @param message
|
||||
* @param duration
|
||||
* @param view
|
||||
* @param isGravity true,表示后面的三个布局参数生效,false,表示不生效
|
||||
* @param gravity
|
||||
* @param xOffset
|
||||
* @param yOffset
|
||||
* @param isMargin true,表示后面的两个参数生效,false,表示不生效
|
||||
* @param horizontalMargin
|
||||
* @param verticalMargin
|
||||
*/
|
||||
public static void customToastAll(Context context, CharSequence message, int duration, View view, boolean isGravity, int gravity, int xOffset, int yOffset, boolean isMargin, float horizontalMargin, float verticalMargin) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, message, duration);
|
||||
} else {
|
||||
mToast.setText(message);
|
||||
}
|
||||
if (view != null) {
|
||||
mToast.setView(view);
|
||||
}
|
||||
if (isMargin) {
|
||||
mToast.setMargin(horizontalMargin, verticalMargin);
|
||||
}
|
||||
if (isGravity) {
|
||||
mToast.setGravity(gravity, xOffset, yOffset);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Toast,针对类型resId
|
||||
*
|
||||
* @param context
|
||||
* @param resId
|
||||
* @param duration
|
||||
* @param view :应该是一个布局,布局中包含了自己设置好的内容
|
||||
* @param isGravity true,表示后面的三个布局参数生效,false,表示不生效
|
||||
* @param gravity
|
||||
* @param xOffset
|
||||
* @param yOffset
|
||||
* @param isMargin true,表示后面的两个参数生效,false,表示不生效
|
||||
* @param horizontalMargin
|
||||
* @param verticalMargin
|
||||
*/
|
||||
public static void customToastAll(Context context, int resId, int duration, View view, boolean isGravity, int gravity, int xOffset, int yOffset, boolean isMargin, float horizontalMargin, float verticalMargin) {
|
||||
if (isShow) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(context, resId, duration);
|
||||
} else {
|
||||
mToast.setText(resId);
|
||||
}
|
||||
if (view != null) {
|
||||
mToast.setView(view);
|
||||
}
|
||||
if (isMargin) {
|
||||
mToast.setMargin(horizontalMargin, verticalMargin);
|
||||
}
|
||||
if (isGravity) {
|
||||
mToast.setGravity(gravity, xOffset, yOffset);
|
||||
}
|
||||
mToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
5
app/src/main/res/drawable/atlas_selector.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@mipmap/map_type" android:state_checked="false"/>
|
||||
<item android:drawable="@mipmap/map_type_select" android:state_checked="true"/>
|
||||
</selector>
|
5
app/src/main/res/drawable/foot_selector.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@mipmap/footprint" android:state_checked="false"/>
|
||||
<item android:drawable="@mipmap/footprint_select" android:state_checked="true"/>
|
||||
</selector>
|
BIN
app/src/main/res/drawable/location.png
Normal file
After Width: | Height: | Size: 484 B |
@ -1,18 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
<com.tencent.tencentmap.mapsdk.maps.MapView
|
||||
android:id="@+id/treasure_map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_launcher_foreground" />
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cb_map_type"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:background="@drawable/atlas_selector"
|
||||
android:button="@null"
|
||||
android:checked="false"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cb_foot_type"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:background="@drawable/foot_selector"
|
||||
android:button="@null"
|
||||
android:checked="false"
|
||||
app:layout_constraintRight_toRightOf="@id/cb_map_type"
|
||||
app:layout_constraintTop_toBottomOf="@id/cb_map_type" />
|
||||
<ImageView
|
||||
android:id="@+id/iv_submit"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:src="@mipmap/submit"
|
||||
app:layout_constraintLeft_toLeftOf="@id/cb_foot_type"
|
||||
app:layout_constraintTop_toTopOf="@id/iv_zoom_del"
|
||||
app:layout_constraintBottom_toBottomOf="@id/iv_refrish"
|
||||
/>
|
||||
<ImageView
|
||||
android:id="@+id/iv_filter"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:src="@mipmap/filter"
|
||||
android:layout_marginTop="15dp"
|
||||
app:layout_constraintLeft_toLeftOf="@id/cb_foot_type"
|
||||
app:layout_constraintTop_toBottomOf="@id/iv_submit"
|
||||
/>
|
||||
<ImageView
|
||||
android:id="@+id/iv_zoom_add"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@mipmap/zoom_add"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cb_foot_type" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_zoom_del"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@mipmap/zoom_del"
|
||||
app:layout_constraintLeft_toLeftOf="@id/iv_zoom_add"
|
||||
app:layout_constraintTop_toBottomOf="@id/iv_zoom_add" />
|
||||
<ImageView
|
||||
android:id="@+id/iv_refrish"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@mipmap/refresh"
|
||||
app:layout_constraintLeft_toLeftOf="@id/iv_zoom_del"
|
||||
app:layout_constraintTop_toBottomOf="@id/iv_zoom_del" />
|
||||
<ImageView
|
||||
android:id="@+id/iv_location"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@mipmap/mine_location"
|
||||
app:layout_constraintLeft_toLeftOf="@id/iv_refrish"
|
||||
app:layout_constraintTop_toBottomOf="@id/iv_refrish" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
BIN
app/src/main/res/mipmap-xxhdpi/filter.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/footprint.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/footprint_select.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/map_type.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/map_type_select.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/mine_location.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/refresh.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/submit.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/zoom_add.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/zoom_del.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
@ -3,6 +3,7 @@
|
||||
<color name="colorPrimary">#6200EE</color>
|
||||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorPrimaryBlue">#03A9F4</color>
|
||||
<color name="colormap">#CBC2C5C6</color>
|
||||
<color name="colorBlue">#2196F3</color>
|
||||
<color name="colorAccent">#03DAC5</color>
|
||||
<color name="colorBack">#000000</color>
|
||||
|
@ -3,8 +3,15 @@ buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
|
||||
//友盟 检测bug
|
||||
maven { url 'https://repo1.maven.org/maven2/' }
|
||||
//腾讯地图
|
||||
maven{
|
||||
url "https://oss.sonatype.org/content/groups/public"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
dependencies {
|
||||
@ -21,6 +28,7 @@ allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
|
||||
maven { url 'https://repo1.maven.org/maven2/' }
|
||||
|