This commit is contained in:
wangcongtao
2019-12-24 20:07:25 +08:00
parent fea6d0bc61
commit 42fca28aae
19 changed files with 393 additions and 35 deletions

View File

@@ -30,6 +30,7 @@ import com.mogo.map.search.poisearch.IMogoPoiSearch;
import com.mogo.map.search.poisearch.IMogoPoiSearchListener;
import com.mogo.map.search.poisearch.MogoPoiResult;
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.module.IMogoModuleLifecycle;
import com.mogo.service.map.IMogoMapService;
@@ -45,7 +46,7 @@ import java.util.Random;
* @author congtaowang
* @since 2019-12-24
* <p>
* 描述
* 描述:demo测试各种接口
*/
public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView > >
@@ -63,6 +64,7 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
private Bitmap mMarkerIcon;
private Bitmap mClickedMarkerIcon;
private TextView mLocInfo;
private TextView mLoc;
private IMogoMarker mLastClickedMarker;
@@ -71,6 +73,8 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
private IMogoPoiSearch mPoiSearch;
private IMogoLocationClient mLocationClient;
private DemoInfoWindowAdapter mDemoInfoWindowAdapter;
@Override
protected int getLayoutId() {
return R.layout.demo_module_card_view;
@@ -84,9 +88,19 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
mPoiSearch.setPoiSearchListener( this );
mLocationClient = mMapService.getSingletonLocationClient( getContext() );
mLocationClient.addLocationListener( this );
mLocationClient.start( 1_000L );
mLocInfo = findViewById( R.id.demo_module_id_loc_info );
mLoc = findViewById( R.id.demo_module_id_loc );
mLoc.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick( View v ) {
mLocationClient.start( 1_000L );
}
}
);
mDemoInfoWindowAdapter = new DemoInfoWindowAdapter( getContext() );
mMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher );
mClickedMarkerIcon = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher_round );
@@ -94,12 +108,12 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
mAddMarker.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
IMogoMapService ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
MogoMarkerOptions options = new MogoMarkerOptions()
.icon( mMarkerIcon )
.latitude( 39.974525d )
.longitude( 116.41733d );
IMogoMarker marker = ims.addMarker( options );
IMogoMarker marker = mMapService.addMarker( DemoConstants.TAG, options );
marker.setInfoWindowAdapter( mDemoInfoWindowAdapter );
marker.setOnMarkerClickListener( DemoCardViewFragment.this );
}
} );
@@ -107,22 +121,29 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
mAddMarkers.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
IMogoMapService ims = ( IMogoMapService ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_MAP ).navigation();
ArrayList< MogoMarkerOptions > optionsList = new ArrayList<>();
for ( int i = 0; i < 10; i++ ) {
MogoMarkerOptions options = new MogoMarkerOptions()
.icon( mMarkerIcon )
.latitude( 39.974525d + new Random().nextDouble() )
.longitude( 116.41733d + new Random().nextDouble() );
List< IMogoMarker > iMogoMarkers = ims.addMarkers( new ArrayList<>( Arrays.asList( options ) ), true );
for ( IMogoMarker iMogoMarker : iMogoMarkers ) {
iMogoMarker.setOnMarkerClickListener( DemoCardViewFragment.this );
}
optionsList.add( options );
}
List< IMogoMarker > iMogoMarkers = mMapService.addMarkers( DemoConstants.TAG, optionsList, true );
for ( IMogoMarker iMogoMarker : iMogoMarkers ) {
iMogoMarker.setInfoWindowAdapter( mDemoInfoWindowAdapter );
iMogoMarker.setOnMarkerClickListener( DemoCardViewFragment.this );
}
}
} );
findViewById( R.id.demo_module_id_clear ).setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
mMapService.removeMarkers( DemoConstants.TAG );
}
} );
}
@Override
@@ -138,6 +159,8 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
}
marker.setIcon( mClickedMarkerIcon );
mLastClickedMarker = marker;
marker.showInfoWindow();
return true;
}
@@ -207,7 +230,15 @@ public class DemoCardViewFragment extends MvpFragment< IView, Presenter< IView >
@Override
public void onLocationChanged( MogoLocation location ) {
mLocationClient.stop();
Logger.i( TAG, location.toString() );
if ( mLocInfo != null ) {
if ( location.getErrCode() == 0 ) {
mLocInfo.setText( "当前位置:" + location.getAddress() );
} else {
mLocInfo.setText( location.getErrInfo() );
}
}
}
@Override

View File

@@ -37,7 +37,7 @@ public class DemoCardViewProvider implements IMogoModuleProvider {
@Override
public String getModuleName() {
return MogoModulePaths.PATH_MODULE_DEMO;
return DemoConstants.TAG;
}
@Override

View File

@@ -0,0 +1,14 @@
package com.mogo.demo.module.map;
import com.mogo.module.common.MogoModulePaths;
/**
* @author congtaowang
* @since 2019-12-24
* <p>
* 描述
*/
public class DemoConstants {
public static final String TAG = MogoModulePaths.PATH_MODULE_DEMO;
}

View File

@@ -0,0 +1,48 @@
package com.mogo.demo.module.map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.mogo.map.marker.IMogoInfoWindowAdapter;
import com.mogo.map.marker.IMogoMarker;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author congtaowang
* @since 2019-12-24
* <p>
* 描述
*/
public class DemoInfoWindowAdapter implements IMogoInfoWindowAdapter {
private Context mContext;
public DemoInfoWindowAdapter( Context mContext ) {
this.mContext = mContext;
}
@Override
public View getInfoWindow( IMogoMarker marker ) {
View view = LayoutInflater.from( mContext ).inflate( R.layout.demo_module_demo_info_window, null );
renderView( view, marker );
return view;
}
private void renderView( View view, final IMogoMarker marker ) {
final TextView time = view.findViewById( R.id.demo_module_id_iw_time );
Button refresh = view.findViewById( R.id.demo_module_id_iw_refresh );
time.setText( new SimpleDateFormat( "yyyyMMdd HHMMSS" ).format( new Date() ) );
refresh.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
marker.showInfoWindow();
}
} );
}
}

View File

@@ -6,7 +6,7 @@
android:background="#ff0000">
<TextView
android:id="@+id/demo_module_id_loc"
android:id="@+id/demo_module_id_loc_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
@@ -19,7 +19,6 @@
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="添加一个覆盖物"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@@ -28,9 +27,28 @@
android:id="@+id/demo_module_id_add_markers"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
android:layout_marginTop="50dp"
android:text="添加多个覆盖物"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/demo_module_id_loc"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="定位"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/demo_module_id_clear"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="清空覆盖物"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#ff0000">
<TextView
android:id="@+id/demo_module_id_iw_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/demo_module_id_iw_refresh"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="点击刷新当前时间"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>