fix: 修复点击拍摄视频程序崩溃的问题
This commit is contained in:
parent
39d660f5cb
commit
8fc6ed7d2a
@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion '29.0.2'
|
||||
// ndkVersion '23.0.7123448'
|
||||
ndkVersion '21.1.6352462'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.navinfo.outdoor"
|
||||
|
@ -71,8 +71,10 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activity.LoginActivity"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity android:name=".activity.HomeActivity"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity android:name=".activity.WebActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
|
@ -22,6 +22,7 @@ import android.widget.TextView;
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.navinfo.outdoor.util.TecentLocationUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@ -124,4 +125,9 @@ public class HomeActivity extends BaseActivity{
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
package com.navinfo.outdoor.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.base.BaseActivity;
|
||||
|
||||
@ -64,6 +67,8 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ public class MainActivity extends BaseActivity {
|
||||
public void onFinish() {
|
||||
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
MainActivity.this.finish();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.base.BaseActivity;
|
||||
|
||||
import com.navinfo.outdoor.util.MyTecentLocationSource;
|
||||
import com.navinfo.outdoor.util.NetWorkUtils;
|
||||
import com.navinfo.outdoor.util.SdkFolderCreate;
|
||||
import com.navinfo.outdoor.util.ToastUtil;
|
||||
@ -43,18 +44,17 @@ import com.otaliastudios.cameraview.VideoResult;
|
||||
import com.otaliastudios.cameraview.controls.Engine;
|
||||
import com.otaliastudios.cameraview.controls.Mode;
|
||||
|
||||
import com.otaliastudios.cameraview.size.AspectRatio;
|
||||
import com.otaliastudios.cameraview.size.SizeSelectors;
|
||||
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.LocationSource;
|
||||
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
|
||||
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
|
||||
import com.tencent.tencentmap.mapsdk.maps.MapView;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TextureMapView;
|
||||
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;
|
||||
|
||||
|
||||
@ -69,27 +69,25 @@ import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import static com.tencent.mapsdk.internal.aaa.getContext;
|
||||
import static com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE;
|
||||
|
||||
|
||||
public class PictureActivity extends BaseActivity implements View.OnClickListener {
|
||||
private static final CameraLogger LOG = CameraLogger.create("Picture");
|
||||
private CameraView camera;
|
||||
private ImageButton capturePicture;
|
||||
// private ImageButton capturePicture;
|
||||
private long captureTime = 0;
|
||||
private android.widget.Button btnSwitch;
|
||||
private TencentMap tencentMap;
|
||||
private MyLocationStyle locationStyle;
|
||||
// private OnLocationChangedListener locationChangedListener;
|
||||
private MapView ivMap;
|
||||
private Button captureVideo;
|
||||
private TextureMapView ivMap;
|
||||
private Button captureVideo, stopVideo;
|
||||
private Button btnVideo;
|
||||
private ImageView ivPic;
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
EventBus.getDefault().register(this);
|
||||
return R.layout.activity_picture;
|
||||
}
|
||||
|
||||
@ -97,7 +95,7 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
ivMap = (MapView) findViewById(R.id.iv_map);
|
||||
ivMap = (TextureMapView) findViewById(R.id.iv_map);
|
||||
ivPic = findViewById(R.id.iv_pic);
|
||||
btnVideo = findViewById(R.id.btn_video);
|
||||
btnVideo.setOnClickListener(this::onClick);
|
||||
@ -111,13 +109,14 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
camera.setOnClickListener(this::onClick);
|
||||
captureVideo = findViewById(R.id.capuretVideo);
|
||||
captureVideo.setOnClickListener(this::onClick);
|
||||
|
||||
stopVideo = findViewById(R.id.btn_stop_video);
|
||||
stopVideo.setOnClickListener(this::onClick);
|
||||
//拍照权限
|
||||
camera.setLifecycleOwner(this);
|
||||
camera.setEngine(Engine.CAMERA1);
|
||||
|
||||
//设置拍照的宽高
|
||||
//camera.setVideoSize(SizeSelectors.or(SizeSelectors.maxHeight(1000), SizeSelectors.smallest(), SizeSelectors.aspectRatio(AspectRatio.of(1, 1), 0)));
|
||||
// camera.setVideoSize(SizeSelectors.or(SizeSelectors.maxHeight(Integer.parseInt(getIntent().getStringExtra("pic"))), SizeSelectors.aspectRatio(AspectRatio.of(1, 1), 0)));
|
||||
SdkFolderCreate.mkdirs(Constant.PICTURE_FOLDER);
|
||||
//获取地图
|
||||
tencentMap = ivMap.getMap();
|
||||
@ -125,6 +124,8 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
UiSettings uiSettings = tencentMap.getUiSettings();
|
||||
//设置logo的大小
|
||||
uiSettings.setLogoScale(0.7f);
|
||||
// uiSettings.setAllGesturesEnabled(false);
|
||||
setLocMarkerStyle(); // 设置当前位置显示样式
|
||||
|
||||
//相机预览监听
|
||||
camera.addCameraListener(new CameraListener() {
|
||||
@ -209,8 +210,10 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
String format = formatter.format(calendar.getTime());
|
||||
//文件
|
||||
File file = new File(Constant.PICTURE_FOLDER, format + ".mp4");
|
||||
camera.takeVideo(file, 15000);
|
||||
camera.takeVideo(file);
|
||||
break;
|
||||
case R.id.btn_stop_video:
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,15 +235,17 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
* 设置定位图标样式
|
||||
*/
|
||||
private void setLocMarkerStyle() {
|
||||
tencentMap.setLocationSource(new MyTecentLocationSource(this));
|
||||
tencentMap.setMyLocationEnabled(true);
|
||||
|
||||
locationStyle = new MyLocationStyle();
|
||||
locationStyle = locationStyle.myLocationType(LOCATION_TYPE_LOCATION_ROTATE);
|
||||
//创建图标
|
||||
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location));
|
||||
locationStyle.icon(bitmapDescriptor);
|
||||
//设置定位圆形区域的边框宽度;
|
||||
locationStyle.fillColor(getResources().getColor(android.R.color.transparent));
|
||||
locationStyle.strokeWidth(1);
|
||||
//设置圆区域的颜色
|
||||
// locationStyle.fillColor(R.color.colormap);
|
||||
// locationStyle.anchor(1000,2000);
|
||||
tencentMap.setMyLocationStyle(locationStyle);
|
||||
}
|
||||
|
||||
@ -288,7 +293,26 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
camera.destroy();
|
||||
if (EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMessageMainThread(Message msg) {
|
||||
switch (msg.what) {
|
||||
case Constant.EVENT_WHAT_LOCATION_CHANGE: // 用户位置更新
|
||||
if (tencentMap!=null) {
|
||||
CameraUpdate cameraSigma =
|
||||
CameraUpdateFactory.newCameraPosition(new CameraPosition(
|
||||
new LatLng(Constant.currentLocation.getLatitude(),Constant.currentLocation.getLongitude()), //中心点坐标,地图目标经纬度
|
||||
16, //目标缩放级别
|
||||
0, //目标倾斜角
|
||||
0)); //目标旋转角 0~360° (正北方为0)
|
||||
tencentMap.animateCamera(cameraSigma);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import com.tencent.map.geolocation.TencentLocation;
|
||||
import com.tencent.tencentmap.mapsdk.maps.MapView;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||
|
||||
/**
|
||||
* 常量
|
||||
@ -45,6 +46,7 @@ public class Constant {
|
||||
//message word 值
|
||||
public static final int TREASURE_FRAGMENT = 100;//抽屉界面的展示和隐藏
|
||||
public static final int TREASURE_WORD = 0;//poi 对地图页面marker 的一个展示
|
||||
public static final int CAPACITY_EVALUATION_PAGE = 1;//能力测评的页数
|
||||
public static final int POI_WORD = 2;//地图页面marker 的经纬都回传
|
||||
public static final int FILTER_LIST = 4;//筛选列表所有数据地图显示
|
||||
public static final int FILTER_LIST_ITEM = 5;//点击筛选的item
|
||||
@ -63,13 +65,13 @@ public class Constant {
|
||||
public static final int MAIN_OTHER = 23;//其他的Fragment 对地图页面marker 的一个展示
|
||||
public static final int OTHER_WORD = 25;//地图页面marker 的经纬都回传
|
||||
public static final int CHARGING_STATION_PILE = 26;//跳转到充电桩 传给数据
|
||||
public static final int CAPACITY_EVALUATION_PAGE = 1;//能力测评的页数
|
||||
public static final int JOB_SEARCH_WORD = 28;//任务搜索的网络数据
|
||||
public static final int JOB_SEARCH_POI_WORD = 29;//任务搜索的本地数据
|
||||
public static final int GATHER_GET_MAP = 30;//地图点击marker 后弹窗点击开始采集
|
||||
public static final int HOME_MINE = 32;//点击我的实时监听刷新
|
||||
public static final int HOME_TREASURE = 33;//点击寻宝实时监听刷新
|
||||
public static final int JOB_WORD_MONITOR=34;//筛选条件的刷新
|
||||
public static final int EVENT_WHAT_LOCATION_CHANGE = 35; // 定位位置更新的Event的What值
|
||||
|
||||
public static String USER_ATTESTATION_NAME; //实名认证姓名 银行卡
|
||||
public static int NUMBER = 200; //任务个数
|
||||
@ -80,10 +82,7 @@ public class Constant {
|
||||
* 用户当前位置
|
||||
*/
|
||||
public static TencentLocation currentLocation;
|
||||
public static TencentLocation markerCurrentLocation;
|
||||
public static double markerLatitude;
|
||||
|
||||
public static double markerLongitude;
|
||||
public static LatLng markerLatlng;
|
||||
//marker 图标
|
||||
|
||||
public static BitmapDescriptor POI_ICON = BitmapDescriptorFactory.fromResource(R.drawable.poi_icons);
|
||||
|
@ -9,9 +9,12 @@ import com.lzy.okgo.cookie.CookieJarImpl;
|
||||
import com.lzy.okgo.cookie.store.DBCookieStore;
|
||||
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
|
||||
import com.lzy.okgo.model.HttpHeaders;
|
||||
import com.navinfo.outdoor.util.SdkFolderCreate;
|
||||
import com.navinfo.outdoor.util.TecentLocationUtils;
|
||||
import com.umeng.commonsdk.UMConfigure;
|
||||
import com.umeng.umcrash.UMCrash;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -36,6 +39,13 @@ public class UserApplication extends Application {
|
||||
UMCrash.generateCustomLog(e,"UmengException");
|
||||
|
||||
initOkGo();
|
||||
|
||||
// 初始化应用目录
|
||||
File baseFolder = new File(Constant.BASE_FOLDER); // 数据库文件夹路径
|
||||
if (!baseFolder.exists()) {
|
||||
SdkFolderCreate.mkdirs(baseFolder.getAbsolutePath());
|
||||
}
|
||||
TecentLocationUtils.getInstance(this).startLocation(this);
|
||||
}
|
||||
|
||||
public static UserApplication getUserApplication() {
|
||||
@ -81,5 +91,4 @@ public class UserApplication extends Application {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
|
||||
break;
|
||||
|
||||
case R.id.tv_pictures:
|
||||
Intent intent = new Intent(getContext(), PicturesActivity.class);
|
||||
Intent intent = new Intent(getContext(), PictureActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
|
||||
break;
|
||||
|
||||
case R.id.tv_pictures:
|
||||
Intent intent = new Intent(getContext(), PicturesActivity.class);
|
||||
Intent intent = new Intent(getContext(), PictureActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
|
||||
|
@ -52,28 +52,21 @@ import com.navinfo.outdoor.room.PoiDatabase;
|
||||
import com.navinfo.outdoor.room.PoiEntity;
|
||||
import com.navinfo.outdoor.util.Geohash;
|
||||
import com.navinfo.outdoor.util.GeometryTools;
|
||||
import com.navinfo.outdoor.util.MyTecentLocationSource;
|
||||
import com.navinfo.outdoor.util.NetWorkUtils;
|
||||
import com.navinfo.outdoor.util.ToastUtil;
|
||||
import com.sothree.slidinguppanel.ScrollableViewHelper;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
|
||||
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.Projection;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMapContext;
|
||||
import com.tencent.tencentmap.mapsdk.maps.UiSettings;
|
||||
import com.tencent.tencentmap.mapsdk.maps.interfaces.Removable;
|
||||
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.LatLngBounds;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
|
||||
@ -97,16 +90,13 @@ import okhttp3.OkHttpClient;
|
||||
* 寻宝的Fragment
|
||||
* 2021-5-25
|
||||
*/
|
||||
public class TreasureFragment extends BaseFragment implements View.OnClickListener, LocationSource, TencentLocationListener {
|
||||
public class TreasureFragment extends BaseFragment implements View.OnClickListener {
|
||||
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;
|
||||
private ImageView ivSubmit;
|
||||
private ImageView ivRefish;
|
||||
@ -189,7 +179,6 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
//启用3d视图
|
||||
tencentMap.setBuilding3dEffectEnable(true);
|
||||
|
||||
tencentMap.setOnCameraChangeListener(cameraChangeListener);
|
||||
//获取地图UI 设置对象
|
||||
UiSettings uiSettings = tencentMap.getUiSettings();
|
||||
//设置logo的大小
|
||||
@ -288,19 +277,6 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
});
|
||||
}
|
||||
|
||||
private TencentMap.OnCameraChangeListener cameraChangeListener = new TencentMap.OnCameraChangeListener() {
|
||||
@Override
|
||||
public void onCameraChange(CameraPosition cameraPosition) { // 地图移动中
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraChangeFinished(CameraPosition cameraPosition) { // 地图移动结束
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private void initList(TencentLocation tencentLocation) {
|
||||
int task_type=Constant.TASK_TYPE;
|
||||
int limit_type=Constant.LIMIT_TTPE;
|
||||
@ -779,17 +755,17 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
//移动地图
|
||||
CameraUpdate cameraSigma =
|
||||
CameraUpdateFactory.newCameraPosition(new CameraPosition(
|
||||
new LatLng(Constant.markerLatitude, Constant.markerLongitude), //中心点坐标,地图目标经纬度
|
||||
Constant.markerLatlng, //中心点坐标,地图目标经纬度
|
||||
tencentMap.getCameraPosition().zoom, //目标缩放级别
|
||||
tencentMap.getCameraPosition().tilt, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
|
||||
tencentMap.getCameraPosition().bearing)); //目标旋转角 0~360° (正北方为0)
|
||||
tencentMap.animateCamera(cameraSigma, new TencentMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onFinish() {
|
||||
screenPosition = tencentMap.getProjection().toScreenLocation(new LatLng(Constant.markerLatitude, Constant.markerLongitude));
|
||||
screenPosition = tencentMap.getProjection().toScreenLocation(Constant.markerLatlng);
|
||||
sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
|
||||
//创建Marker对象之前,设置属性
|
||||
LatLng position = new LatLng(Constant.markerLatitude, Constant.markerLongitude);
|
||||
LatLng position = Constant.markerLatlng;
|
||||
marker = tencentMap.addMarker(new MarkerOptions(position));
|
||||
marker.setFixingPoint(screenPosition.x, screenPosition.y);
|
||||
}
|
||||
@ -805,8 +781,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
LatLng latLng = tencentMap.getProjection().fromScreenLocation(screenPosition);
|
||||
marker.setPosition(latLng);
|
||||
marker.setFixingPointEnable(false);
|
||||
Constant.markerLatitude = latLng.latitude;
|
||||
Constant.markerLongitude = latLng.longitude;
|
||||
Constant.markerLatlng = latLng;
|
||||
Message obtain = Message.obtain();
|
||||
obtain.what = aInt;
|
||||
obtain.obj = latLng;
|
||||
@ -821,7 +796,8 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
* 设置定位图标样式
|
||||
*/
|
||||
private void setLocMarkerStyle() {
|
||||
locationStyle = new MyLocationStyle();
|
||||
locationStyle= new MyLocationStyle();
|
||||
locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
|
||||
//创建图标
|
||||
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location));
|
||||
locationStyle.icon(bitmapDescriptor);
|
||||
@ -837,16 +813,10 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
* 定位的一些初始化设置
|
||||
*/
|
||||
private void initLocation() {
|
||||
//用于访问腾讯定位服务的类, 周期性向客户端提供位置更新
|
||||
locationManager = TencentLocationManager.getInstance(getContext());
|
||||
//设置坐标系
|
||||
locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02);
|
||||
//创建定位请求
|
||||
locationRequest = TencentLocationRequest.create();
|
||||
//设置定位周期(位置监听器回调周期)为3s
|
||||
// locationRequest.setInterval(3000);
|
||||
//地图上设置定位数据源
|
||||
tencentMap.setLocationSource(this);
|
||||
tencentMap.setLocationSource(new MyTecentLocationSource(getActivity()));
|
||||
//设置当前位置可见
|
||||
tencentMap.setMyLocationEnabled(true);
|
||||
//设置定位图标样式
|
||||
@ -1082,63 +1052,6 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
|
||||
Constant.currentLocation = tencentLocation;
|
||||
Constant.markerCurrentLocation = tencentLocation;
|
||||
Constant.markerLatitude = tencentLocation.getLatitude();
|
||||
Constant.markerLongitude = tencentLocation.getLongitude();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusUpdate(String s, int i, String s1) {
|
||||
//GPS, WiFi, Radio 等状态发生变化
|
||||
Log.v("State changed", s + "===" + s1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
getActivity().finish();
|
||||
@ -1151,16 +1064,16 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
* @return
|
||||
*/
|
||||
public LatLng getMapCenterPoint() {
|
||||
int left = treasureMap.getLeft();
|
||||
int top = treasureMap.getTop();
|
||||
int right = treasureMap.getRight();
|
||||
int bottom = treasureMap.getBottom();
|
||||
// 获得屏幕点击的位置
|
||||
int x = (int) (treasureMap.getX() + (right - left) / 2);
|
||||
int y = (int) (treasureMap.getY() + (bottom - top) / 2);
|
||||
Projection projection = tencentMap.getProjection();
|
||||
LatLng pt = projection.fromScreenLocation(new Point(x, y));
|
||||
return pt;
|
||||
// int left = treasureMap.getLeft();
|
||||
// int top = treasureMap.getTop();
|
||||
// int right = treasureMap.getRight();
|
||||
// int bottom = treasureMap.getBottom();
|
||||
// // 获得屏幕点击的位置
|
||||
// int x = (int) (treasureMap.getX() + (right - left) / 2);
|
||||
// int y = (int) (treasureMap.getY() + (bottom - top) / 2);
|
||||
// Projection projection = tencentMap.getProjection();
|
||||
// LatLng pt = projection.fromScreenLocation(new Point(x, y));
|
||||
return tencentMap.getCameraPosition().target;
|
||||
}
|
||||
|
||||
}
|
@ -10,6 +10,9 @@ import androidx.room.migration.Migration;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.util.SdkFolderCreate;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Database(entities = {PoiEntity.class,ChargingPileEntity.class}, version = 1, exportSchema = false)
|
||||
public abstract class PoiDatabase extends RoomDatabase {
|
||||
@ -23,6 +26,10 @@ public abstract class PoiDatabase extends RoomDatabase {
|
||||
return instance;
|
||||
}
|
||||
private static PoiDatabase create(final Context context) {
|
||||
File dbFolder = new File(Constant.POI_DAO); // 数据库文件夹路径
|
||||
if (!dbFolder.exists()) {
|
||||
SdkFolderCreate.mkdirs(dbFolder.getAbsolutePath());
|
||||
}
|
||||
return Room.databaseBuilder(context, PoiDatabase.class, Constant.POI_DAO+DB_NAME)
|
||||
.addMigrations(migration_1_2)
|
||||
.addMigrations(migration_2_3)
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
import android.content.Context;
|
||||
import com.tencent.tencentmap.mapsdk.maps.LocationSource;
|
||||
|
||||
|
||||
/**
|
||||
* 腾讯地图的当前位置数据源
|
||||
* */
|
||||
public class MyTecentLocationSource implements LocationSource{
|
||||
private OnLocationChangedListener locationChangedListener;
|
||||
private Context mContext;
|
||||
/**
|
||||
* 初始化locationSource,务必在MapActivity界面中调用,保证传入的Context在整个应用生命周期中不会被销毁
|
||||
* */
|
||||
public MyTecentLocationSource(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate(OnLocationChangedListener onLocationChangedListener) {
|
||||
locationChangedListener = onLocationChangedListener;
|
||||
TecentLocationUtils.getInstance(mContext).getLocationChangedListenerList().add(onLocationChangedListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
if (locationChangedListener!=null) {
|
||||
TecentLocationUtils.getInstance(mContext).getLocationChangedListenerList().remove(locationChangedListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
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.LocationSource;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TecentLocationUtils implements TencentLocationListener{
|
||||
private TencentLocationManager locationManager;
|
||||
private TencentLocationRequest locationRequest;
|
||||
private List<LocationSource.OnLocationChangedListener> locationChangedListenerList;
|
||||
private boolean isLocationStart; // 标识是否已经启动定位
|
||||
|
||||
private static TecentLocationUtils instance;
|
||||
|
||||
public static TecentLocationUtils getInstance(Context mContext) {
|
||||
if (instance == null) {
|
||||
instance = new TecentLocationUtils(mContext);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public TecentLocationUtils(Context mContext) {
|
||||
init(mContext);
|
||||
}
|
||||
|
||||
private void init(Context mContext) {
|
||||
locationChangedListenerList = new ArrayList<>();
|
||||
//用于访问腾讯定位服务的类, 周期性向客户端提供位置更新
|
||||
locationManager = TencentLocationManager.getInstance(mContext);
|
||||
//设置坐标系
|
||||
locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02);
|
||||
//创建定位请求
|
||||
locationRequest = TencentLocationRequest.create();
|
||||
locationRequest.setInterval(2000); // 每2秒返回一次地址数据
|
||||
}
|
||||
|
||||
public void startLocation(Context mContext) { // 启动定位服务
|
||||
if (locationManager == null) {
|
||||
this.init(mContext);
|
||||
}
|
||||
if (!isLocationStart) {
|
||||
int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper());
|
||||
isLocationStart = true;
|
||||
switch (err) {
|
||||
case 1:
|
||||
ToastUtil.showShort(mContext, Constant.GET_ERR_MESSAGE1);
|
||||
break;
|
||||
case 2:
|
||||
ToastUtil.showShort(mContext, Constant.GET_ERR_MESSAGE2);
|
||||
break;
|
||||
case 3:
|
||||
ToastUtil.showShort(mContext, Constant.GET_ERR_MESSAGE3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopLocation() { // 停止定位服务
|
||||
if (isLocationStart) {
|
||||
locationManager.removeUpdates(this);
|
||||
locationManager = null;
|
||||
locationRequest = null;
|
||||
locationChangedListenerList.clear();
|
||||
locationChangedListenerList = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现位置监听
|
||||
*
|
||||
* @param tencentLocation
|
||||
* @param i
|
||||
* @param s
|
||||
*/
|
||||
@Override
|
||||
public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
|
||||
if (i == TencentLocation.ERROR_OK) {
|
||||
Location location = new Location(tencentLocation.getProvider());
|
||||
//设置经纬度以及精度
|
||||
location.setLatitude(tencentLocation.getLatitude());
|
||||
location.setLongitude(tencentLocation.getLongitude());
|
||||
location.setAccuracy(tencentLocation.getAccuracy());
|
||||
if (locationChangedListenerList!=null) {
|
||||
for (LocationSource.OnLocationChangedListener locationChangedListener:locationChangedListenerList) {
|
||||
locationChangedListener.onLocationChanged(location);
|
||||
}
|
||||
}
|
||||
Constant.currentLocation = tencentLocation;
|
||||
Message currentLocationMsg = Message.obtain();
|
||||
currentLocationMsg.what = Constant.EVENT_WHAT_LOCATION_CHANGE;
|
||||
currentLocationMsg.obj = Constant.currentLocation;
|
||||
EventBus.getDefault().post(currentLocationMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusUpdate(String s, int i, String s1) {
|
||||
//GPS, WiFi, Radio 等状态发生变化
|
||||
Log.v("State changed", s + "===" + s1);
|
||||
}
|
||||
|
||||
public List<LocationSource.OnLocationChangedListener> getLocationChangedListenerList() {
|
||||
return locationChangedListenerList;
|
||||
}
|
||||
}
|
@ -14,10 +14,14 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
|
||||
<com.tencent.tencentmap.mapsdk.maps.MapView
|
||||
<com.tencent.tencentmap.mapsdk.maps.TextureMapView
|
||||
android:id="@+id/iv_map"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="183dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintWidth_percent="0.4"
|
||||
app:layout_constraintWidth_default="percent"
|
||||
app:layout_constraintHeight_percent="0.4"
|
||||
app:layout_constraintHeight_default="percent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
@ -28,6 +32,7 @@
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:text="切换"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<Button
|
||||
|
Loading…
x
Reference in New Issue
Block a user