Files
MoGoEagleEye/libraries/mogo-map-api/src/main/java/com/mogo/map/MogoBaseMapView.java
2020-08-27 14:00:49 +08:00

116 lines
2.7 KiB
Java

package com.mogo.map;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import com.mogo.utils.logger.Logger;
/**
* @author congtaowang
* @since 2019-12-18
* <p>
* 对地图的基本抽象
*/
public abstract class MogoBaseMapView extends FrameLayout implements ILifeCycle {
private static final String TAG = "MogoBaseMapView";
private IMogoMapView mMapView;
public MogoBaseMapView( Context context ) {
this( context, null );
}
public MogoBaseMapView( Context context, @Nullable AttributeSet attrs ) {
this( context, attrs, 0 );
}
public MogoBaseMapView( Context context, @Nullable AttributeSet attrs, int defStyleAttr ) {
super( context, attrs, defStyleAttr );
init( context );
}
protected void init( Context context ) {
mMapView = createMapView( context );
if ( mMapView != null ) {
final View mapView = mMapView.getMapView();
if ( mapView != null ) {
addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) );
MogoMap.getInstance().init( context, getMap() );
} else {
Logger.e( TAG, "create MapView instance failed." );
}
} else {
Logger.e( TAG, "create IMogoMapView instance failed." );
}
}
/**
* 创建地图实例
*
* @param context
* @return
*/
protected abstract IMogoMapView createMapView( Context context );
@Override
public void onCreate( Bundle bundle ) {
if ( mMapView != null ) {
mMapView.onCreate( bundle );
}
}
@Override
public void onResume() {
if ( mMapView != null ) {
mMapView.onResume();
}
}
@Override
public void onPause() {
if ( mMapView != null ) {
mMapView.onPause();
}
}
@Override
public void onDestroy() {
if ( mMapView != null ) {
mMapView.onDestroy();
}
}
@Override
public void onSaveInstanceState( Bundle outState ) {
if ( mMapView != null ) {
mMapView.onSaveInstanceState( outState );
}
}
@Override
public void onLowMemory() {
if ( mMapView != null ) {
mMapView.onLowMemory();
}
}
public IMogoMap getMap() {
if ( mMapView != null ) {
return mMapView.getMap();
}
return null;
}
public IMogoMapView getMapView() {
return mMapView;
}
}