完善搜索UI
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.mogo.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-12
|
||||
* <p>
|
||||
* 读取asset文件
|
||||
*/
|
||||
public class AssetsUtils {
|
||||
|
||||
private static final String TAG = "amap.AssetsUtils";
|
||||
|
||||
public static byte[] read( Context context, String fileName ) {
|
||||
if ( context == null || TextUtils.isEmpty( fileName ) ) {
|
||||
return null;
|
||||
}
|
||||
byte[] buffer = null;
|
||||
try {
|
||||
InputStream is = context.getAssets().open( fileName );
|
||||
BufferedInputStream bis = new BufferedInputStream( is );
|
||||
buffer = new byte[is.available()];
|
||||
bis.read( buffer );
|
||||
bis.close();
|
||||
is.close();
|
||||
Log.d( TAG, "read assets success: " + fileName + " size=" + buffer.length );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/
|
||||
USERNAME=xintai
|
||||
PASSWORD=xintai2018
|
||||
# 编译模式: false - 依赖本地版本, true - 依赖 maven 版本
|
||||
RELEASE=true
|
||||
RELEASE=false
|
||||
# 模块版本
|
||||
DEMO_MODULE_MAP_VERSION=1.0.0-SNAPSHOT
|
||||
DEMO_MODULE_MAP2_VERSION=1.0.0-SNAPSHOT
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.module.common;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-02
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class TextWatcherAdapter implements TextWatcher {
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged( CharSequence s, int start, int count, int after ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged( CharSequence s, int start, int before, int count ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged( Editable s ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.mogo.module.map.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationClientOption;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class AMapLocationManager {
|
||||
|
||||
private static final String TAG = "AMapLocationManager";
|
||||
|
||||
private static final Set< AMapLocationListener > mLocationChangeListeners = new HashSet<>();
|
||||
private static final InternalLocationListener mInternalLocationListener = new InternalLocationListener();
|
||||
|
||||
private AMapLocationClient mLocationClient;
|
||||
|
||||
private static AMapLocation sLastKnowLocation = null;
|
||||
|
||||
private static volatile AMapLocationManager sInstance;
|
||||
|
||||
public static AMapLocationManager getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( AMapLocationManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new AMapLocationManager( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
stop();
|
||||
mLocationChangeListeners.clear();
|
||||
mLocationClient = null;
|
||||
sLastKnowLocation = null;
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private AMapLocationManager( Context context ) {
|
||||
if ( context == null ) {
|
||||
throw new NullPointerException( "context can't be null." );
|
||||
}
|
||||
mLocationClient = new AMapLocationClient( context.getApplicationContext() );
|
||||
mLocationClient.setLocationListener( mInternalLocationListener );
|
||||
}
|
||||
|
||||
private void setLocationOptions( long locateInterval ) {
|
||||
AMapLocationClientOption option = new AMapLocationClientOption();
|
||||
option.setLocationMode( AMapLocationClientOption.AMapLocationMode.Hight_Accuracy );
|
||||
option.setNeedAddress( true );
|
||||
option.setInterval( locateInterval );
|
||||
if ( mLocationClient != null ) {
|
||||
mLocationClient.setLocationOption( option );
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
start( 2000L );
|
||||
}
|
||||
|
||||
public synchronized void start( long locateInterval ) {
|
||||
if ( mLocationClient != null && mLocationClient.isStarted() ) {
|
||||
stop();
|
||||
}
|
||||
setLocationOptions( locateInterval );
|
||||
mLocationClient.startLocation();
|
||||
Log.d( TAG, "start location, location interval is " + locateInterval );
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
if ( mLocationClient != null ) {
|
||||
mLocationClient.stopLocation();
|
||||
}
|
||||
Log.d( TAG, "stop location" );
|
||||
}
|
||||
|
||||
public static AMapLocation getAMapLastKnowLocation() {
|
||||
return sLastKnowLocation;
|
||||
}
|
||||
|
||||
public static LatLng getLastKnowPoint() {
|
||||
final AMapLocation location = getAMapLastKnowLocation();
|
||||
if ( location != null ) {
|
||||
return new LatLng( location.getLatitude(), location.getLongitude() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addLocationListener( AMapLocationListener listener ) {
|
||||
if ( listener != null ) {
|
||||
synchronized ( mLocationChangeListeners ) {
|
||||
mLocationChangeListeners.add( listener );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLocationListener( AMapLocationListener listener ) {
|
||||
synchronized ( mLocationChangeListeners ) {
|
||||
mLocationChangeListeners.remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位SDK监听函数
|
||||
*/
|
||||
private static class InternalLocationListener implements AMapLocationListener {
|
||||
@Override
|
||||
public void onLocationChanged( AMapLocation aMapLocation ) {
|
||||
if ( aMapLocation == null ||
|
||||
aMapLocation.getLatitude() == 0.0D ||
|
||||
aMapLocation.getLongitude() == 0.0D ) {
|
||||
return;
|
||||
}
|
||||
sLastKnowLocation = aMapLocation.clone();
|
||||
synchronized ( mLocationChangeListeners ) {
|
||||
Iterator iterator = mLocationChangeListeners.iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
AMapLocationListener listener = ( AMapLocationListener ) iterator.next();
|
||||
listener.onLocationChanged( sLastKnowLocation );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mogo.module.map.location;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-09-27
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class LocationUtils {
|
||||
|
||||
public static float bearing( double lat1, double lon1, double lat2, double lon2 ) {
|
||||
|
||||
double longitude1 = lon1;
|
||||
double longitude2 = lon2;
|
||||
double latitude1 = Math.toRadians( lat1 );
|
||||
double latitude2 = Math.toRadians( lat2 );
|
||||
double longDiff = Math.toRadians( longitude2 - longitude1 );
|
||||
double y = Math.sin( longDiff ) * Math.cos( latitude2 );
|
||||
double x = Math.cos( latitude1 ) * Math.sin( latitude2 ) - Math.sin( latitude1 ) * Math.cos( latitude2 ) * Math
|
||||
.cos( longDiff );
|
||||
|
||||
double result = ( Math.toDegrees( Math.atan2( y, x ) ) + 360 ) % 360;
|
||||
if ( ( ( int ) result ) == ( ( int ) ( result + 0.5 ) ) ) {
|
||||
return ( ( int ) result );
|
||||
} else {
|
||||
return ( ( int ) result ) + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.mogo.module.map.location;
|
||||
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MyLocationUtils {
|
||||
|
||||
public static final long INTERVAL_FAST_SPEED = 2_000L;
|
||||
public static final long INTERVAL_MIDDLE_SPEED = 2_000L;
|
||||
public static final long INTERVAL_SLOW_SPEED = 10_000L;
|
||||
|
||||
/**
|
||||
* 前台快速定位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static MyLocationStyle wrapperAsFast( MyLocationStyle style ) {
|
||||
if ( style != null ) {
|
||||
style.interval( INTERVAL_FAST_SPEED );
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台慢速定位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static MyLocationStyle wrapperAsMiddleSpeed( MyLocationStyle style ) {
|
||||
if ( style != null ) {
|
||||
style.interval( INTERVAL_MIDDLE_SPEED );
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台慢速定位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static MyLocationStyle wrapperAsSlow( MyLocationStyle style ) {
|
||||
if ( style != null ) {
|
||||
style.interval( INTERVAL_SLOW_SPEED );
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,8 +43,13 @@ dependencies {
|
||||
implementation rootProject.ext.dependencies.room
|
||||
annotationProcessor rootProject.ext.dependencies.roomAnnotationProcessor
|
||||
implementation rootProject.ext.dependencies.roomRxjava
|
||||
implementation rootProject.ext.dependencies.androidxrecyclerview
|
||||
annotationProcessor rootProject.ext.dependencies.aroutercompiler
|
||||
implementation rootProject.ext.dependencies.jetbrainsannotationsjava5
|
||||
implementation rootProject.ext.dependencies.rxandroid
|
||||
// api project(path: ':modules:mogo-module-common')
|
||||
// api project(path: ':foudations:mogo-utils')
|
||||
// api project(path: ':modules:mogo-module-map')
|
||||
|
||||
if( Boolean.valueOf(RELEASE) ){
|
||||
implementation rootProject.ext.dependencies.mogomap
|
||||
@@ -60,7 +65,7 @@ dependencies {
|
||||
implementation project(":foudations:mogo-utils")
|
||||
api project(":foudations:mogo-commons")
|
||||
api project(':services:mogo-service-api')
|
||||
implementation project(':modules:mogo-module-common')
|
||||
api project(':modules:mogo-module-common')
|
||||
implementation project(':modules:mogo-module-map')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mogo.module.navi.bean;
|
||||
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.maps.model.CameraPosition;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.geocoder.RegeocodeAddress;
|
||||
import com.amap.api.services.help.Tip;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-02
|
||||
* <p>
|
||||
* 实体类操作工具
|
||||
*/
|
||||
public class EntityConvertUtils {
|
||||
|
||||
public static List< Tip > pois2Tips( List< SearchPoi > datums ) {
|
||||
final List< Tip > output = new ArrayList<>();
|
||||
if ( datums == null || datums.isEmpty() ) {
|
||||
return output;
|
||||
}
|
||||
for ( SearchPoi poi : datums ) {
|
||||
Tip tip = poi2Tip( poi );
|
||||
if ( tip != null ) {
|
||||
output.add( tip );
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static Tip poi2Tip( SearchPoi poi ) {
|
||||
if ( poi == null ) {
|
||||
return null;
|
||||
}
|
||||
Tip tip = new Tip();
|
||||
tip.setID( poi.pId );
|
||||
tip.setAdcode( poi.getAdCode() );
|
||||
tip.setAddress( poi.getAddress() );
|
||||
tip.setDistrict( poi.getDistrict() );
|
||||
tip.setName( poi.getName() );
|
||||
tip.setTypeCode( poi.getTypeCode() );
|
||||
tip.setPostion( new LatLonPoint( poi.getLat(), poi.getLng() ) );
|
||||
return tip;
|
||||
}
|
||||
|
||||
public static SearchPoi tipToPoi( Tip tip ) {
|
||||
if ( tip == null ) {
|
||||
return null;
|
||||
}
|
||||
double lat = 0.0;
|
||||
double lng = 0.0;
|
||||
if ( tip.getPoint() != null ) {
|
||||
lat = tip.getPoint().getLatitude();
|
||||
lng = tip.getPoint().getLongitude();
|
||||
}
|
||||
return new SearchPoi( tip.getPoiID(),
|
||||
tip.getName(),
|
||||
tip.getAddress(),
|
||||
lat,
|
||||
lng,
|
||||
tip.getDistrict(),
|
||||
tip.getAdcode(),
|
||||
tip.getTypeCode() );
|
||||
}
|
||||
|
||||
public static SearchPoi aMapLocation2Poi( AMapLocation location ) {
|
||||
if ( location == null || location.getErrorCode() != AMapLocation.LOCATION_SUCCESS ) {
|
||||
return null;
|
||||
}
|
||||
return new SearchPoi( System.currentTimeMillis() + "",
|
||||
location.getPoiName(),
|
||||
location.getAddress(),
|
||||
location.getLatitude(),
|
||||
location.getLongitude(),
|
||||
location.getDistrict(),
|
||||
location.getAdCode(),
|
||||
location.getCoordType() );
|
||||
}
|
||||
|
||||
public static SearchPoi geocodeAddress2Poi( RegeocodeAddress address, CameraPosition position ) {
|
||||
if ( address == null || position == null ) {
|
||||
return null;
|
||||
}
|
||||
return new SearchPoi( System.currentTimeMillis() + "",
|
||||
address.getFormatAddress(),
|
||||
address.getFormatAddress(),
|
||||
position.target.latitude,
|
||||
position.target.longitude,
|
||||
address.getDistrict(),
|
||||
address.getAdCode(),
|
||||
"" );
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.mogo.module.navi.bean;
|
||||
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
* 2019-08-15.
|
||||
*/
|
||||
@Entity
|
||||
public class POIInfo {
|
||||
@PrimaryKey
|
||||
@NotNull
|
||||
public String pId;
|
||||
private String name;
|
||||
private String address;
|
||||
private double lat;
|
||||
private double lot;
|
||||
|
||||
|
||||
public POIInfo(String pId, String name, String address, double lat, double lot) {
|
||||
this.pId = pId;
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.lat = lat;
|
||||
this.lot = lot;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(double lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public double getLot() {
|
||||
return lot;
|
||||
}
|
||||
|
||||
public void setLot(double lot) {
|
||||
this.lot = lot;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package com.mogo.module.navi.bean;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-02
|
||||
* <p>
|
||||
* 搜索地址表数据结构
|
||||
*/
|
||||
@Entity( tableName = DataConstants.T_SEARCH_POI )
|
||||
public class SearchPoi implements Parcelable {
|
||||
|
||||
public static final SearchPoi NULL = new SearchPoi( null,
|
||||
null,
|
||||
null,
|
||||
0.0,
|
||||
0.0,
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public String pId;
|
||||
private String name;
|
||||
private String address;
|
||||
private double lat;
|
||||
private double lng;
|
||||
private String district;
|
||||
private String adCode;
|
||||
private String typeCode;
|
||||
private String province;
|
||||
private String city;
|
||||
|
||||
|
||||
/**
|
||||
* 插入poi数据类型
|
||||
* <p>
|
||||
* {@link DataConstants#TYPE_COMPANY_ADDRESS}
|
||||
* {@link DataConstants#TYPE_HOME_ADDRESS}
|
||||
* {@link DataConstants#TYPE_POI}
|
||||
*/
|
||||
private int type;
|
||||
|
||||
/**
|
||||
* 数据记录时间,自动赋值
|
||||
*/
|
||||
private long time;
|
||||
|
||||
public SearchPoi( String pId,
|
||||
String name,
|
||||
String address,
|
||||
double lat,
|
||||
double lng,
|
||||
String district,
|
||||
String adCode,
|
||||
String typeCode ) {
|
||||
this( pId, name, address, lat, lng, district, adCode, typeCode, "", "", DataConstants.TYPE_POI );
|
||||
}
|
||||
|
||||
private SearchPoi( String pId,
|
||||
String name,
|
||||
String address,
|
||||
double lat,
|
||||
double lng,
|
||||
String district,
|
||||
String adCode,
|
||||
String typeCode,
|
||||
String province,
|
||||
String city,
|
||||
int type ) {
|
||||
this.pId = pId;
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.lat = lat;
|
||||
this.lng = lng;
|
||||
this.district = district;
|
||||
this.adCode = adCode;
|
||||
this.typeCode = typeCode;
|
||||
this.province = province;
|
||||
this.city = city;
|
||||
this.type = type;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getpId() {
|
||||
return pId;
|
||||
}
|
||||
|
||||
public void setpId( @NonNull String pId ) {
|
||||
this.pId = pId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName( String name ) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress( String address ) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat( double lat ) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public void setLng( double lng ) {
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
public String getDistrict() {
|
||||
return district;
|
||||
}
|
||||
|
||||
public void setDistrict( String district ) {
|
||||
this.district = district;
|
||||
}
|
||||
|
||||
public String getAdCode() {
|
||||
return adCode;
|
||||
}
|
||||
|
||||
public void setAdCode( String adCode ) {
|
||||
this.adCode = adCode;
|
||||
}
|
||||
|
||||
public String getTypeCode() {
|
||||
return typeCode;
|
||||
}
|
||||
|
||||
public void setTypeCode( String typeCode ) {
|
||||
this.typeCode = typeCode;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince( String province ) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity( String city ) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType( int type ) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime( long time ) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel( Parcel dest, int flags ) {
|
||||
dest.writeString( this.pId );
|
||||
dest.writeString( this.name );
|
||||
dest.writeString( this.address );
|
||||
dest.writeDouble( this.lat );
|
||||
dest.writeDouble( this.lng );
|
||||
dest.writeString( this.district );
|
||||
dest.writeString( this.adCode );
|
||||
dest.writeString( this.typeCode );
|
||||
dest.writeString( this.province );
|
||||
dest.writeString( this.city );
|
||||
dest.writeInt( this.type );
|
||||
dest.writeLong( this.time );
|
||||
}
|
||||
|
||||
protected SearchPoi( Parcel in ) {
|
||||
this.pId = in.readString();
|
||||
this.name = in.readString();
|
||||
this.address = in.readString();
|
||||
this.lat = in.readDouble();
|
||||
this.lng = in.readDouble();
|
||||
this.district = in.readString();
|
||||
this.adCode = in.readString();
|
||||
this.typeCode = in.readString();
|
||||
this.province = in.readString();
|
||||
this.city = in.readString();
|
||||
this.type = in.readInt();
|
||||
this.time = in.readLong();
|
||||
}
|
||||
|
||||
public static final Creator< SearchPoi > CREATOR = new Creator< SearchPoi >() {
|
||||
@Override
|
||||
public SearchPoi createFromParcel( Parcel source ) {
|
||||
return new SearchPoi( source );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchPoi[] newArray( int size ) {
|
||||
return new SearchPoi[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mogo.module.navi.constants;
|
||||
|
||||
import com.amap.api.navi.enums.PathPlanningStrategy;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-04
|
||||
* <p>
|
||||
* 地图基本参数配置
|
||||
*/
|
||||
public class AMapConstants {
|
||||
|
||||
/**
|
||||
* 初始化地图缩放级别
|
||||
*/
|
||||
public static final float AMAP_ZOOM_COMMON_LEVEL = 15.0f;
|
||||
|
||||
/**
|
||||
* 点击当前位置按钮的地图缩放级别
|
||||
*/
|
||||
public static final float AMAP_ZOOM_CURRENT_LOCATION_LEVEL = AMAP_ZOOM_COMMON_LEVEL;
|
||||
|
||||
public static final float AMPA_BEARING = 0.0f;
|
||||
|
||||
public static final int DEFAULT_ROUTE_STRATEGY = PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_DEFAULT;
|
||||
|
||||
public static final float AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED = 1f;
|
||||
public static final float AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED = 0.3f;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mogo.module.navi.constants;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-12
|
||||
* <p>
|
||||
* 自定义地图样式
|
||||
*/
|
||||
public class CustomMapStyle {
|
||||
|
||||
public static final String STYLE_ID = "e3e33a3423230b219494b40c4d71d93a";
|
||||
|
||||
public static final String ASSET_STYLE_DATA = "style.data";
|
||||
|
||||
public static final String ASSET_STYLE_EXTRA_DATA = "style_extra.data";
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.mogo.module.navi.dao;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import com.mogo.module.navi.bean.POIInfo;
|
||||
import io.reactivex.Flowable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
* 2019-08-15.
|
||||
*/
|
||||
@Dao
|
||||
public interface POIDao {
|
||||
|
||||
/**
|
||||
* 插入地址信息
|
||||
* @param poiInfos GEO信息
|
||||
* @return
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
List<Long> insert(POIInfo... poiInfos);
|
||||
|
||||
/**
|
||||
* 获取地址列表
|
||||
* @return
|
||||
*/
|
||||
@Query("SELECT * from poiinfo")
|
||||
Flowable<List<POIInfo>> load();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.mogo.module.navi.dao;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
import io.reactivex.Single;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-02
|
||||
* <p>
|
||||
* 搜索页面数据操作
|
||||
*/
|
||||
@Dao
|
||||
public interface SearchPoiDao {
|
||||
|
||||
@Insert( onConflict = OnConflictStrategy.REPLACE )
|
||||
List<Long> insert(SearchPoi... datums);
|
||||
|
||||
@Query( "SELECT * FROM " + DataConstants.T_SEARCH_POI + " WHERE type=" + DataConstants.TYPE_POI + " ORDER BY time DESC LIMIT :limit" )
|
||||
Single<List< SearchPoi >> getLastN(int limit);
|
||||
|
||||
@Query( "SELECT * FROM " + DataConstants.T_SEARCH_POI + " WHERE type=" + DataConstants.TYPE_POI )
|
||||
Single<List< SearchPoi >> getAll();
|
||||
|
||||
@Query( "SELECT * FROM " + DataConstants.T_SEARCH_POI + " WHERE type=" + DataConstants.TYPE_HOME_ADDRESS )
|
||||
Single<List< SearchPoi >> getHomeAddress();
|
||||
|
||||
@Query( "SELECT * FROM " + DataConstants.T_SEARCH_POI + " WHERE type=" + DataConstants.TYPE_COMPANY_ADDRESS )
|
||||
Single<List< SearchPoi >> getCompanyAddress();
|
||||
|
||||
@Delete
|
||||
int delete(SearchPoi poi);
|
||||
|
||||
@Delete
|
||||
int deleteAll(List<SearchPoi> list);
|
||||
}
|
||||
@@ -4,17 +4,17 @@ import android.content.Context;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import com.mogo.module.navi.database.bean.POIInfo;
|
||||
import com.mogo.module.navi.database.dao.POIDao;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.dao.SearchPoiDao;
|
||||
|
||||
/**
|
||||
* @author zyz
|
||||
* 2019-08-15.
|
||||
*/
|
||||
|
||||
@Database(entities = { POIInfo.class}, version = 1, exportSchema = false)
|
||||
@Database(entities = { SearchPoi.class}, version = 1, exportSchema = false)
|
||||
public abstract class AppDataBase extends RoomDatabase {
|
||||
public abstract POIDao poiDao();
|
||||
public abstract SearchPoiDao poiDao();
|
||||
|
||||
private static volatile AppDataBase INSTANCE;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.amap.api.services.help.Tip;
|
||||
import com.mogo.module.navi.R;
|
||||
import com.mogo.module.navi.ui.adapter.base.RecycleBaseAdapter;
|
||||
import com.mogo.module.navi.ui.adapter.base.RecycleViewHolder;
|
||||
import com.mogo.utils.OnItemClickedListener;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,10 @@ public class SearchPoiAdapter extends RecycleBaseAdapter<Tip> {
|
||||
public SearchPoiAdapter(Context context, List<Tip> list) {
|
||||
super(context, list, R.layout.item_search_poi);
|
||||
}
|
||||
private OnItemClickedListener< Tip > mOnItemClickedListener;
|
||||
private OnItemClickedListener< Tip > mOnDeleteAllClickedListener;
|
||||
private OnItemClickedListener< Tip > mOnActionButtonClickedListener;
|
||||
private boolean mShowDelete = false;
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
@@ -37,4 +42,29 @@ public class SearchPoiAdapter extends RecycleBaseAdapter<Tip> {
|
||||
public void setOnClickListener(View.OnClickListener onClickListener) {
|
||||
this.onClickListener = onClickListener;
|
||||
}
|
||||
public void setOnItemClickedListener( OnItemClickedListener< Tip > onItemClickedListener ) {
|
||||
this.mOnItemClickedListener = onItemClickedListener;
|
||||
}
|
||||
|
||||
public void setOnDeleteAllClickedListener( OnItemClickedListener< Tip > onDeleteAllClickedListener ) {
|
||||
this.mOnDeleteAllClickedListener = onDeleteAllClickedListener;
|
||||
}
|
||||
|
||||
public void setOnActionButtonClickedListener( OnItemClickedListener< Tip > onActionButtonClickedListener ) {
|
||||
this.mOnActionButtonClickedListener = onActionButtonClickedListener;
|
||||
}
|
||||
public void setShowDelete( boolean showDelete ) {
|
||||
this.mShowDelete = showDelete;
|
||||
}
|
||||
public void refresh( List< Tip > datums, boolean showDelete ) {
|
||||
//this.da = datums;
|
||||
setShowDelete( showDelete );
|
||||
setDatas(datums);
|
||||
//notifyDataSetChanged();
|
||||
}
|
||||
public void clear(){
|
||||
mOnItemClickedListener = null;
|
||||
mOnDeleteAllClickedListener = null;
|
||||
mOnActionButtonClickedListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,430 @@
|
||||
package com.mogo.module.navi.ui.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.UiSettings;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.CameraPosition;
|
||||
import com.amap.api.maps.model.CustomMapStyleOptions;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.amap.api.navi.AMapNaviViewOptions;
|
||||
import com.mogo.module.navi.R;
|
||||
import com.mogo.module.navi.constants.AMapConstants;
|
||||
import com.mogo.module.navi.constants.CustomMapStyle;
|
||||
import com.mogo.utils.AssetsUtils;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-27
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MapUIController {
|
||||
|
||||
private static final String TAG = "MapUIController";
|
||||
|
||||
private static volatile MapUIController sInstance;
|
||||
private int mLastZoomLevel;
|
||||
|
||||
private MapUIController() {
|
||||
}
|
||||
|
||||
public static MapUIController getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( MapUIController.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new MapUIController();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
mContext = null;
|
||||
mMapView = null;
|
||||
mAMap = null;
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private AMapNaviView mMapView;
|
||||
private AMap mAMap;
|
||||
|
||||
public synchronized void init( Context context, AMapNaviView mapView, AMap aMap ) {
|
||||
this.mContext = context;
|
||||
this.mMapView = mapView;
|
||||
this.mAMap = aMap;
|
||||
initMap();
|
||||
changeMyLocationVisibility( true );
|
||||
}
|
||||
|
||||
private boolean checkAMap() {
|
||||
return mAMap != null;
|
||||
}
|
||||
|
||||
private boolean checkAMapView() {
|
||||
return mMapView != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除所有导航mapView的默认UI
|
||||
*/
|
||||
private void initMap() {
|
||||
if ( mMapView != null ) {
|
||||
AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options != null ) {
|
||||
// 设置是否开启自动黑夜模式切换,默认为false,不自动切换
|
||||
options.setAutoNaviViewNightMode( false );
|
||||
// 设置6秒后是否自动锁车
|
||||
options.setAutoLockCar( true );
|
||||
// 设置路线上的摄像头气泡是否显示
|
||||
options.setCameraBubbleShow( true );
|
||||
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
|
||||
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
|
||||
// 设置自车的图片对象
|
||||
options.setCarBitmap( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.ic_amap_navi_cursor ) );
|
||||
// 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。
|
||||
options.setCompassEnabled( false );
|
||||
//设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
|
||||
options.setTrafficBarEnabled( false );
|
||||
// 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
|
||||
options.setTrafficLayerEnabled( false );
|
||||
// 设置导航界面是否显示路线全览按钮。
|
||||
options.setRouteListButtonShow( false );
|
||||
// 设置起点位图,须在画路前设置
|
||||
options.setStartPointBitmap( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.ic_current_location_cursor ) );
|
||||
// 设置终点位图,须在画路前设置
|
||||
options.setEndPointBitmap( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.ic_search_choice_point ) );
|
||||
// 设置导航状态下屏幕是否一直开启。
|
||||
options.setScreenAlwaysBright( true );
|
||||
// 设置交通播报是否打开(只适用于驾车导航,需要联网)。
|
||||
options.setTrafficInfoUpdateEnabled( true );
|
||||
// 设置摄像头播报是否打开(只适用于驾车导航)。
|
||||
options.setCameraInfoUpdateEnabled( true );
|
||||
// 设置菜单按钮是否在导航界面显示。
|
||||
options.setSettingMenuEnabled( false );
|
||||
// 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。
|
||||
options.setTrafficLine( true );
|
||||
// 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。
|
||||
options.setLeaderLineEnabled( -1 );
|
||||
// 设置导航界面UI是否显示。
|
||||
options.setLayoutVisible( false );
|
||||
// 设置是否自动画路
|
||||
options.setAutoDrawRoute( false );
|
||||
// 设置是否显示路口放大图(实景图)
|
||||
options.setRealCrossDisplayShow( false );
|
||||
// 设置是否显示路口放大图(路口模型图)
|
||||
options.setModeCrossDisplayShow( false );
|
||||
// 设置是否显示道路信息view
|
||||
options.setLaneInfoShow( false );
|
||||
// 设置是否自动改变缩放等级
|
||||
options.setAutoChangeZoom( false );
|
||||
// 设置是否自动全览模式,即在算路成功后自动进入全览模式
|
||||
options.setAutoDisplayOverview( false );
|
||||
// 设置路线转向箭头隐藏和显示
|
||||
options.setNaviArrowVisible( false );
|
||||
// 通过路线是否自动置灰,仅支持驾车导航
|
||||
options.setAfterRouteAutoGray( true );
|
||||
options.setPointToCenter( 0.5D, 0.5D );
|
||||
mMapView.setViewOptions( options );
|
||||
}
|
||||
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
|
||||
}
|
||||
|
||||
if ( mAMap != null ) {
|
||||
|
||||
mAMap.setTrafficEnabled( true );
|
||||
|
||||
UiSettings uiSettings = mAMap.getUiSettings();
|
||||
if ( uiSettings != null ) {
|
||||
//设置所有手势是否可用
|
||||
uiSettings.setAllGesturesEnabled( true );
|
||||
//设置指南针是否可见。
|
||||
uiSettings.setCompassEnabled( false );
|
||||
//设置是否以地图中心点缩放
|
||||
uiSettings.setGestureScaleByMapCenter( true );
|
||||
//设置室内地图楼层切换控件是否可见。
|
||||
uiSettings.setIndoorSwitchEnabled( true );
|
||||
//设置定位按钮是否可见。
|
||||
uiSettings.setMyLocationButtonEnabled( false );
|
||||
//设置旋转手势是否可用。
|
||||
uiSettings.setRotateGesturesEnabled( false );
|
||||
//设置比例尺控件是否可见
|
||||
uiSettings.setScaleControlsEnabled( false );
|
||||
//设置拖拽手势是否可用。
|
||||
uiSettings.setScrollGesturesEnabled( true );
|
||||
//设置倾斜手势是否可用。
|
||||
uiSettings.setTiltGesturesEnabled( true );
|
||||
//设置缩放按钮是否可见。
|
||||
uiSettings.setZoomControlsEnabled( false );
|
||||
//设置双指缩放手势是否可用。
|
||||
uiSettings.setZoomGesturesEnabled( true );
|
||||
}
|
||||
mAMap.setCustomMapStyle( new CustomMapStyleOptions()
|
||||
.setEnable( true )
|
||||
.setStyleId( CustomMapStyle.STYLE_ID )
|
||||
.setStyleData( AssetsUtils.read( mContext, CustomMapStyle.ASSET_STYLE_DATA ) )
|
||||
.setStyleExtraData( AssetsUtils.read( mContext, CustomMapStyle.ASSET_STYLE_EXTRA_DATA ) )
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制我的位置图层及定位回调能力
|
||||
*
|
||||
* @param visibility
|
||||
*/
|
||||
public void changeMyLocationVisibility( boolean visibility ) {
|
||||
if ( mAMap == null ) {
|
||||
return;
|
||||
}
|
||||
mAMap.setMyLocationEnabled( visibility );
|
||||
Log.d( TAG, visibility ? "开启定位" : "关闭定位" );
|
||||
if ( visibility ) {
|
||||
MyLocationStyle style = mAMap.getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER )
|
||||
.strokeWidth( 0 )
|
||||
.interval( 2_000L )
|
||||
.showMyLocation( visibility )
|
||||
.myLocationIcon( BitmapDescriptorFactory.fromResource( R.drawable.ic_current_location_cursor ) )
|
||||
.radiusFillColor( Color.TRANSPARENT );
|
||||
mAMap.setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导航模式:中心点偏下
|
||||
*/
|
||||
public void showNaviUI() {
|
||||
changeMyLocationVisibility( false );
|
||||
changeCarOverlayVisibility( true );
|
||||
changeRouteOverlayVisibility( false );
|
||||
if ( mMapView != null ) {
|
||||
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
|
||||
mMapView.post( () -> {
|
||||
AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options != null ) {
|
||||
Log.d( TAG, "中心点切换到页面偏下" );
|
||||
options.setPointToCenter( 0.5D, 0.6666666666666666D );
|
||||
mMapView.setViewOptions( options );
|
||||
if ( checkAMap() ) {
|
||||
mAMap.moveCamera( CameraUpdateFactory.zoomBy( 15 ) );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常地图模式:中心点居中
|
||||
*/
|
||||
public void showMapUI() {
|
||||
changeMyLocationVisibility( true );
|
||||
changeCarOverlayVisibility( false );
|
||||
changeRouteOverlayVisibility( false );
|
||||
if ( mMapView != null ) {
|
||||
AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options != null ) {
|
||||
Log.d( TAG, "中心点切换到页面中心" );
|
||||
options.setPointToCenter( 0.5D, 0.5D );
|
||||
mMapView.setViewOptions( options );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示规划UI样式:中心点右移
|
||||
*/
|
||||
public void showCalculateUI() {
|
||||
changeMyLocationVisibility( false );
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制自车marker
|
||||
*
|
||||
* @param visibility
|
||||
*/
|
||||
public void changeCarOverlayVisibility( boolean visibility ) {
|
||||
try {
|
||||
mMapView.setCarOverlayVisible( visibility );
|
||||
} catch ( Exception e ) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制导航路线图层
|
||||
*
|
||||
* @param visibility
|
||||
*/
|
||||
public void changeRouteOverlayVisibility( boolean visibility ) {
|
||||
try {
|
||||
mMapView.setRouteOverlayVisible( visibility );
|
||||
} catch ( Exception e ) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将地图移动到中心点,正北方向
|
||||
*
|
||||
* @param latlng
|
||||
*/
|
||||
public void moveCurrentPositionToCenter( LatLng latlng ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.animateCamera( CameraUpdateFactory.newCameraPosition( new CameraPosition.Builder()
|
||||
.tilt( mMapView.getLockTilt() )
|
||||
.zoom( mMapView.getLockZoom() )
|
||||
.target( latlng )
|
||||
.bearing( AMapConstants.AMPA_BEARING )
|
||||
.build() ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 改变地图缩放级别
|
||||
*
|
||||
* @param level
|
||||
*/
|
||||
public void changeCameraZoomLevel( float level, boolean animate ) {
|
||||
if ( checkAMap() ) {
|
||||
if ( animate ) {
|
||||
mAMap.animateCamera( CameraUpdateFactory.zoomTo( level ) );
|
||||
} else {
|
||||
mAMap.moveCamera( CameraUpdateFactory.zoomTo( level ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加marker
|
||||
*
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
public Marker addMarker( MarkerOptions options ) {
|
||||
return mAMap.addMarker( options );
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存上次地图缩放级别
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean storeMapZoomLevel() {
|
||||
if ( checkAMapView() ) {
|
||||
final AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options != null ) {
|
||||
mLastZoomLevel = options.getZoom();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 还原上次的缩放级别
|
||||
*/
|
||||
public void restoreMapZoomLevel() {
|
||||
if ( checkAMapView() ) {
|
||||
final AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options != null ) {
|
||||
options.setZoom( mLastZoomLevel );
|
||||
mMapView.setViewOptions( options );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 交通态势开关
|
||||
*
|
||||
* @param enable
|
||||
*/
|
||||
public void setTrafficEnabled( boolean enable ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setTrafficEnabled( enable );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缩放地图
|
||||
*
|
||||
* @param zoomIn 放大
|
||||
*/
|
||||
public void changeZoom( boolean zoomIn ) {
|
||||
if ( checkAMapView() ) {
|
||||
if ( zoomIn ) {
|
||||
mMapView.zoomIn();
|
||||
} else {
|
||||
mMapView.zoomOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置地图类型
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public void setMapType( int type ) {
|
||||
if ( checkAMap() ) {
|
||||
mAMap.setMapType( type );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导航样式:
|
||||
*
|
||||
* @param naviMode
|
||||
*/
|
||||
public void setNaviMode( int naviMode ) {
|
||||
if ( checkAMapView() ) {
|
||||
mMapView.setNaviMode( naviMode );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图倾斜度
|
||||
*
|
||||
* @param tile
|
||||
*/
|
||||
public void setTilt( int tile ) {
|
||||
if ( checkAMapView() ) {
|
||||
final AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
if ( options != null ) {
|
||||
options.setTilt( tile );
|
||||
mMapView.setViewOptions( options );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览全程
|
||||
*/
|
||||
public void displayOverview() {
|
||||
if ( checkAMapView() ) {
|
||||
mMapView.displayOverview();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭全程预览
|
||||
*/
|
||||
public void recoverLockMode() {
|
||||
if ( checkAMapView() ) {
|
||||
mMapView.recoverLockMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,13 @@ import com.amap.api.maps.model.animation.TranslateAnimation;
|
||||
import com.amap.api.services.geocoder.RegeocodeAddress;
|
||||
import com.amap.api.services.help.Tip;
|
||||
|
||||
import com.mogo.module.map.location.AMapLocationManager;
|
||||
import com.mogo.module.navi.R;
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.ui.adapter.SearchPoiAdapter;
|
||||
import com.mogo.module.navi.ui.base.BaseFragment;
|
||||
import com.mogo.module.navi.ui.base.MapUIController;
|
||||
import com.mogo.module.navi.ui.base.UiController;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
@@ -110,7 +114,7 @@ public class SearchFragment extends BaseFragment implements SearchView,
|
||||
public void onActivityCreated( @Nullable Bundle savedInstanceState ) {
|
||||
super.onActivityCreated( savedInstanceState );
|
||||
initViews();
|
||||
getLifecycle().addObserver( mSearchPresenter = new com.mogo.module.navi.database.ui.search.SearchPresenter( this ) );
|
||||
getLifecycle().addObserver( mSearchPresenter = new SearchPresenter( this ) );
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
@@ -241,7 +245,7 @@ public class SearchFragment extends BaseFragment implements SearchView,
|
||||
mCurrentLocation.setVisibility( View.GONE );
|
||||
mSearchResult.setVisibility( View.GONE );
|
||||
mActionButton.setVisibility( View.VISIBLE );
|
||||
mActionButton.setText( com.mogo.module.navi.database.ui.search.SearchUtils.getSearchTypeActionName( mSearchType ) );
|
||||
mActionButton.setText( SearchUtils.getSearchTypeActionName( mSearchType ) );
|
||||
mSearchBox.setCompoundDrawables( null, null, null, null );
|
||||
removeChoicePointMarker();
|
||||
mSearchBox.setTag( null );
|
||||
@@ -264,7 +268,7 @@ public class SearchFragment extends BaseFragment implements SearchView,
|
||||
mCurrentLocation.setVisibility( View.GONE );
|
||||
mSearchResult.setVisibility( View.GONE );
|
||||
mActionButton.setVisibility( View.VISIBLE );
|
||||
mActionButton.setText( com.mogo.module.navi.database.ui.search.SearchUtils.getSearchTypeActionName( mSearchType ) );
|
||||
mActionButton.setText( SearchUtils.getSearchTypeActionName( mSearchType ) );
|
||||
mSearchBox.setCompoundDrawables( null, null, null, null );
|
||||
showChoicePointMarker();
|
||||
mSearchBox.setTag( null );
|
||||
@@ -313,18 +317,18 @@ public class SearchFragment extends BaseFragment implements SearchView,
|
||||
|
||||
@Override
|
||||
public void onLocationChanged( AMapLocation aMapLocation ) {
|
||||
final String checkMsg = AMapUtils.getAMapLocationErrorMsg( aMapLocation );
|
||||
if ( AMapUtils.LOC_SUCCESS.equals( checkMsg ) ) {
|
||||
mLastAMapLocation = aMapLocation;
|
||||
MapUIController.getInstance().moveCurrentPositionToCenter( new LatLng( aMapLocation.getLatitude(), aMapLocation.getLongitude() ) );
|
||||
if ( mUiMode == SearchConstants.UI_MODE_MULTI_MY_LOCATION ) {
|
||||
showMyLocationAddress( aMapLocation );
|
||||
} else if ( mUiMode == SearchConstants.UI_MODE_MULTI_CHOICE_POINT ) {
|
||||
showChoicePointAddress( aMapLocation );// 显示当前中心点地址
|
||||
}
|
||||
} else {
|
||||
Toast.makeText( mContext, checkMsg, Toast.LENGTH_SHORT ).show();
|
||||
}
|
||||
//final String checkMsg = AMapUtils.getAMapLocationErrorMsg( aMapLocation );
|
||||
//if ( AMapUtils.LOC_SUCCESS.equals( checkMsg ) ) {
|
||||
// mLastAMapLocation = aMapLocation;
|
||||
// MapUIController.getInstance().moveCurrentPositionToCenter( new LatLng( aMapLocation.getLatitude(), aMapLocation.getLongitude() ) );
|
||||
// if ( mUiMode == SearchConstants.UI_MODE_MULTI_MY_LOCATION ) {
|
||||
// showMyLocationAddress( aMapLocation );
|
||||
// } else if ( mUiMode == SearchConstants.UI_MODE_MULTI_CHOICE_POINT ) {
|
||||
// showChoicePointAddress( aMapLocation );// 显示当前中心点地址
|
||||
// }
|
||||
//} else {
|
||||
// Toast.makeText( mContext, checkMsg, Toast.LENGTH_SHORT ).show();
|
||||
//}
|
||||
AMapLocationManager.getInstance( mContext ).removeLocationListener( this );
|
||||
AMapLocationManager.getInstance( mContext ).stop();
|
||||
}
|
||||
@@ -390,8 +394,7 @@ public class SearchFragment extends BaseFragment implements SearchView,
|
||||
}
|
||||
|
||||
if ( mPoiAdapter == null ) {
|
||||
mPoiAdapter = new SearchPoiAdapter( datums, com.mogo.module.navi.database.ui.search.SearchUtils
|
||||
.getSearchTypeActionName( mSearchType ) );
|
||||
mPoiAdapter = new SearchPoiAdapter(getContext(), datums );
|
||||
mPoiAdapter.setOnItemClickedListener( item -> {
|
||||
if ( mSearchType == SearchConstants.SEARCH_TYPE_COMMON ) {
|
||||
final Disposable disposable = mSearchPresenter.cacheSelectPoiItem( item ).subscribe( output -> {
|
||||
@@ -443,15 +446,15 @@ public class SearchFragment extends BaseFragment implements SearchView,
|
||||
mSearchBox.setText( address.getFormatAddress() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderErrorView() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderContentView() {
|
||||
|
||||
}
|
||||
//@Override
|
||||
//public void renderErrorView() {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//@Override
|
||||
//public void renderContentView() {
|
||||
//
|
||||
//}
|
||||
|
||||
// view interface end
|
||||
|
||||
@@ -502,7 +505,7 @@ public class SearchFragment extends BaseFragment implements SearchView,
|
||||
Toast.makeText( mContext, "未设置", Toast.LENGTH_SHORT ).show();
|
||||
return;
|
||||
}
|
||||
SearchPoiLiveData.getInstance().postValue( searchPoi );
|
||||
//SearchPoiLiveData.getInstance().postValue( searchPoi );
|
||||
exitSearch();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,14 @@ import com.amap.api.services.help.Inputtips;
|
||||
import com.amap.api.services.help.InputtipsQuery;
|
||||
import com.amap.api.services.help.Tip;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.module.common.TextWatcherAdapter;
|
||||
import com.mogo.module.navi.bean.EntityConvertUtils;
|
||||
import com.mogo.module.navi.bean.SearchPoi;
|
||||
import com.mogo.module.navi.constants.DataConstants;
|
||||
import com.mogo.module.navi.database.AppDataBase;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleEmitter;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
@@ -124,7 +129,7 @@ public class SearchPresenter extends Presenter< SearchView >
|
||||
return Single.create( emitter -> {
|
||||
SearchPoi poi = EntityConvertUtils.tipToPoi( tip );
|
||||
//ignore insert result
|
||||
final List<Long> output = AMapDatabase.getInstance( getContext() ).getSearchPoiDao().insert( poi );
|
||||
final List<Long> output = AppDataBase.getDatabase( getContext() ).poiDao().insert( poi );
|
||||
emitter.onSuccess( output );
|
||||
} ).subscribeOn( Schedulers.io() ).observeOn( AndroidSchedulers.mainThread() );
|
||||
}
|
||||
@@ -149,16 +154,16 @@ public class SearchPresenter extends Presenter< SearchView >
|
||||
}
|
||||
|
||||
private void deleteAllCachedPoiImpl() {
|
||||
final Disposable disposable = AMapDatabase.getInstance( getContext() )
|
||||
.getSearchPoiDao()
|
||||
final Disposable disposable = AppDataBase.getDatabase( getContext() )
|
||||
.poiDao()
|
||||
.getAll()
|
||||
.map( input -> {
|
||||
return AMapDatabase.getInstance( getContext() ).getSearchPoiDao().deleteAll( input );
|
||||
return AppDataBase.getDatabase( getContext() ).poiDao().deleteAll( input );
|
||||
} )
|
||||
.subscribeOn( Schedulers.io() )
|
||||
.observeOn( AndroidSchedulers.mainThread() )
|
||||
.subscribe( count -> {
|
||||
view.renderSearchPoiResult( null, false );
|
||||
mView.renderSearchPoiResult( null, false );
|
||||
} );
|
||||
mCompositeDisposable.add( disposable );
|
||||
}
|
||||
@@ -211,7 +216,7 @@ public class SearchPresenter extends Presenter< SearchView >
|
||||
|
||||
private void emitterCommonAddress( SingleEmitter<List<Long>> emitter, SearchPoi poi ) {
|
||||
String poiId = null;
|
||||
switch ( view.getSearchType() ) {
|
||||
switch ( mView.getSearchType() ) {
|
||||
case SearchConstants.SEARCH_TYPE_MULTI_HOME:
|
||||
poiId = DataConstants.POI_ID_HOME;
|
||||
break;
|
||||
@@ -228,20 +233,20 @@ public class SearchPresenter extends Presenter< SearchView >
|
||||
return;
|
||||
}
|
||||
poi.setpId( poiId );
|
||||
poi.setType( view.getSearchType() );
|
||||
poi.setType( mView.getSearchType() );
|
||||
//ignore insert result
|
||||
final List<Long> output = AMapDatabase.getInstance( getContext() ).getSearchPoiDao().insert( poi );
|
||||
final List<Long> output = AppDataBase.getDatabase( getContext() ).poiDao().insert( poi );
|
||||
notifyAIAssistCommonAddressChanged();
|
||||
emitter.onSuccess( output );
|
||||
}
|
||||
|
||||
private void notifyAIAssistCommonAddressChanged() {
|
||||
if ( view.getSearchType() == SearchConstants.SEARCH_TYPE_MULTI_HOME ) {
|
||||
AddressHelper.notifyHomeAddressChanged( getContext() );
|
||||
} else if ( view.getSearchType() == SearchConstants.SEARCH_TYPE_MULTI_COMPANY ) {
|
||||
AddressHelper.notifyCompanyAddressChanged( getContext() );
|
||||
|
||||
}
|
||||
//if ( view.getSearchType() == SearchConstants.SEARCH_TYPE_MULTI_HOME ) {
|
||||
// AddressHelper.notifyHomeAddressChanged( getContext() );
|
||||
//} else if ( view.getSearchType() == SearchConstants.SEARCH_TYPE_MULTI_COMPANY ) {
|
||||
// AddressHelper.notifyCompanyAddressChanged( getContext() );
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
private void startSearchPoiByPoint( CameraPosition position ) {
|
||||
@@ -260,9 +265,9 @@ public class SearchPresenter extends Presenter< SearchView >
|
||||
@Override
|
||||
public void onRegeocodeSearched( RegeocodeResult regeocodeResult, int resultID ) {
|
||||
if ( resultID == 1000 ) { // success
|
||||
view.renderChoicePointResult( regeocodeResult.getRegeocodeAddress() );
|
||||
mView.renderChoicePointResult( regeocodeResult.getRegeocodeAddress() );
|
||||
} else {
|
||||
view.renderChoicePointResult( null );
|
||||
mView.renderChoicePointResult( null );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,14 +279,14 @@ public class SearchPresenter extends Presenter< SearchView >
|
||||
@Override
|
||||
public void onDestroy( @NonNull LifecycleOwner owner ) {
|
||||
super.onDestroy( owner );
|
||||
if ( view.getSearchBox() != null ) {
|
||||
view.getSearchBox().removeTextChangedListener( watcherAdapter );
|
||||
if ( mView.getSearchBox() != null ) {
|
||||
mView.getSearchBox().removeTextChangedListener( watcherAdapter );
|
||||
}
|
||||
if ( mCompositeDisposable != null && !mCompositeDisposable.isDisposed() ) {
|
||||
mCompositeDisposable.dispose();
|
||||
mCompositeDisposable = null;
|
||||
}
|
||||
CameraChangedLiveData.getInstance().removeAllObserver();
|
||||
//CameraChangedLiveData.getInstance().removeAllObserver();
|
||||
mSearchEngine = null;
|
||||
mGeocodeSearch = null;
|
||||
mLastCameraPosition = null;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
137
modules/mogo-module-navi/src/main/res/layout/fragment_search.xml
Normal file
137
modules/mogo-module-navi/src/main/res/layout/fragment_search.xml
Normal file
@@ -0,0 +1,137 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout 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"
|
||||
style="@style/amap_fragment_container_padding_style"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.search.SearchFragment">
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/amap_search_search_box_width_container"
|
||||
android:layout_width="692dp"
|
||||
android:layout_height="81dp"
|
||||
android:background="@drawable/amap_white_shadow_bkg">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/amap_search_close"
|
||||
android:layout_width="@dimen/amap_search_back_size"
|
||||
android:layout_height="@dimen/amap_search_back_size"
|
||||
android:layout_alignTop="@+id/amap_search_search_box"
|
||||
android:layout_alignBottom="@+id/amap_search_search_box"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_back_dark" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/amap_search_search_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="58dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_toRightOf="@+id/amap_search_close"
|
||||
android:background="@color/transparent"
|
||||
android:drawableRight="@drawable/ic_search_unshadow"
|
||||
android:drawablePadding="15dp"
|
||||
android:ellipsize="end"
|
||||
android:hint="@string/navi_search_hint"
|
||||
android:maxLines="1"
|
||||
android:paddingTop="@dimen/amap_search_search_box_paddingLTop"
|
||||
android:paddingBottom="@dimen/amap_search_search_box_paddingBottom"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/black"
|
||||
android:textColorHint="#848484"
|
||||
android:textCursorDrawable="@drawable/amap_search_cursor_drawable"
|
||||
android:textSize="@dimen/amap_search_search_box_textSize"
|
||||
tools:text="@string/amap_long_text" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/amap_search_action_setting"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/amap_search_search_box"
|
||||
android:layout_alignBottom="@+id/amap_search_search_box"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginTop="8.5dp"
|
||||
android:layout_marginRight="7.5dp"
|
||||
android:layout_marginBottom="8.5dp"
|
||||
android:background="@drawable/amap_search_action_button_bkg"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="25dp"
|
||||
android:paddingRight="25dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20dp"
|
||||
android:visibility="gone"
|
||||
tools:text="设为家"
|
||||
tools:visibility="visible" />
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/amap_search_current_location_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/amap_search_search_box_width_container"
|
||||
android:layout_alignLeft="@+id/amap_search_search_box_width_container"
|
||||
android:layout_marginBottom="@dimen/amap_main_navi_current_location_marginBottom"
|
||||
android:src="@drawable/ic_current_location"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_goneMarginBottom="@dimen/amap_main_navi_current_location_goneMarginBottom" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/amap_search_poi_my_location"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/amap_search_current_location_tag"
|
||||
android:layout_alignBottom="@+id/amap_search_current_location_tag"
|
||||
android:background="@drawable/amap_white_shadow_bkg"
|
||||
android:drawableLeft="@drawable/ic_search_poi_location"
|
||||
android:drawablePadding="15.5dp"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="23.5dp"
|
||||
android:paddingRight="27.5dp"
|
||||
android:text="我的位置"
|
||||
android:textColor="#595959"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/amap_search_poi_choice_point"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/amap_search_current_location_tag"
|
||||
android:layout_alignBottom="@+id/amap_search_current_location_tag"
|
||||
android:layout_toRightOf="@+id/amap_search_poi_my_location"
|
||||
android:background="@drawable/amap_white_shadow_bkg"
|
||||
android:drawableLeft="@drawable/ic_search_poi_location"
|
||||
android:drawablePadding="15.5dp"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="23.5dp"
|
||||
android:paddingRight="27.5dp"
|
||||
android:text="地图选点"
|
||||
android:textColor="#595959"
|
||||
android:textSize="20dp" />
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/amap_search_current_location"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginBottom="@dimen/amap_main_navi_current_location_marginBottom"
|
||||
android:src="@drawable/ic_current_location" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/amap_search_poi_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/amap_search_search_box_width_container"
|
||||
android:layout_alignRight="@+id/amap_search_search_box_width_container"
|
||||
android:layout_marginBottom="@dimen/amap_main_navi_current_location_marginBottom"
|
||||
android:background="@drawable/amap_white_shadow_bkg"
|
||||
android:overScrollMode="never"
|
||||
android:visibility="invisible" />
|
||||
|
||||
</RelativeLayout>
|
||||
19
modules/mogo-module-navi/src/main/res/values/styles.xml
Normal file
19
modules/mogo-module-navi/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<resources>
|
||||
|
||||
<style name="amap_fragment_container_padding_style">
|
||||
<item name="android:paddingTop">25dp</item>
|
||||
<item name="android:paddingLeft">48dp</item>
|
||||
</style>
|
||||
|
||||
<style name="amap_fragment_container_margin_style">
|
||||
<item name="android:layout_marginTop">25dp</item>
|
||||
<item name="android:layout_marginLeft">48dp</item>
|
||||
<item name="android:background">@drawable/amap_white_shadow_bkg</item>
|
||||
</style>
|
||||
|
||||
<style name="amap_fragment_container_shadow_style">
|
||||
<item name="android:paddingTop">25dp</item>
|
||||
<item name="android:paddingLeft">48dp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user