add mogoaction api
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -15,7 +15,6 @@
|
||||
<option value="$PROJECT_DIR$/foudations/mogo-connection" />
|
||||
<option value="$PROJECT_DIR$/foudations/mogo-utils" />
|
||||
<option value="$PROJECT_DIR$/libraries" />
|
||||
<option value="$PROJECT_DIR$/libraries/card-library" />
|
||||
<option value="$PROJECT_DIR$/libraries/map-amap" />
|
||||
<option value="$PROJECT_DIR$/libraries/mogo-map" />
|
||||
<option value="$PROJECT_DIR$/libraries/mogo-map-api" />
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
package com.yarolegovich.discretescrollview;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by yarolegovich on 28-Apr-17.
|
||||
*/
|
||||
|
||||
public class InfiniteScrollAdapter<T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T>
|
||||
implements DiscreteScrollLayoutManager.InitialPositionProvider {
|
||||
|
||||
private static final int CENTER = Integer.MAX_VALUE / 2;
|
||||
private static final int RESET_BOUND = 100;
|
||||
|
||||
public static <T extends RecyclerView.ViewHolder> InfiniteScrollAdapter<T> wrap(
|
||||
@NonNull RecyclerView.Adapter<T> adapter) {
|
||||
return new InfiniteScrollAdapter<>(adapter);
|
||||
}
|
||||
|
||||
private RecyclerView.Adapter<T> wrapped;
|
||||
private DiscreteScrollLayoutManager layoutManager;
|
||||
|
||||
public InfiniteScrollAdapter(@NonNull RecyclerView.Adapter<T> wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
this.wrapped.registerAdapterDataObserver(new DataSetChangeDelegate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
wrapped.onAttachedToRecyclerView(recyclerView);
|
||||
if (recyclerView instanceof DiscreteScrollView) {
|
||||
layoutManager = (DiscreteScrollLayoutManager) recyclerView.getLayoutManager();
|
||||
} else {
|
||||
String msg = recyclerView.getContext().getString(R.string.dsv_ex_msg_adapter_wrong_recycler);
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
wrapped.onDetachedFromRecyclerView(recyclerView);
|
||||
layoutManager = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull T onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return wrapped.onCreateViewHolder(parent, viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull T holder, int position) {
|
||||
if (isResetRequired(position)) {
|
||||
int resetPosition = CENTER + mapPositionToReal(layoutManager.getCurrentPosition());
|
||||
setPosition(resetPosition);
|
||||
return;
|
||||
}
|
||||
wrapped.onBindViewHolder(holder, mapPositionToReal(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return wrapped.getItemViewType(mapPositionToReal(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return isInfinite() ? Integer.MAX_VALUE : wrapped.getItemCount();
|
||||
}
|
||||
|
||||
public int getRealItemCount() {
|
||||
return wrapped.getItemCount();
|
||||
}
|
||||
|
||||
public int getRealCurrentPosition() {
|
||||
return getRealPosition(layoutManager.getCurrentPosition());
|
||||
}
|
||||
|
||||
public int getRealPosition(int position) {
|
||||
return mapPositionToReal(position);
|
||||
}
|
||||
|
||||
public int getClosestPosition(int position) {
|
||||
ensureValidPosition(position);
|
||||
int adapterCurrent = layoutManager.getCurrentPosition();
|
||||
int current = mapPositionToReal(adapterCurrent);
|
||||
if (position == current) {
|
||||
return adapterCurrent;
|
||||
}
|
||||
int delta = position - current;
|
||||
int target = adapterCurrent + delta;
|
||||
int wraparoundTarget = adapterCurrent + (position > current ?
|
||||
delta - wrapped.getItemCount() :
|
||||
wrapped.getItemCount() + delta);
|
||||
int distance = Math.abs(adapterCurrent - target);
|
||||
int wraparoundDistance = Math.abs(adapterCurrent - wraparoundTarget);
|
||||
if (distance == wraparoundDistance) {
|
||||
//Scroll to the right feels more natural, so prefer it
|
||||
return target > adapterCurrent ? target : wraparoundTarget;
|
||||
} else {
|
||||
return distance < wraparoundDistance ? target : wraparoundTarget;
|
||||
}
|
||||
}
|
||||
|
||||
private int mapPositionToReal(int position) {
|
||||
if (position < CENTER) {
|
||||
int rem = (CENTER - position) % wrapped.getItemCount();
|
||||
return rem == 0 ? 0 : wrapped.getItemCount() - rem;
|
||||
} else {
|
||||
return (position - CENTER) % wrapped.getItemCount();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isResetRequired(int requestedPosition) {
|
||||
return isInfinite()
|
||||
&& (requestedPosition <= RESET_BOUND
|
||||
|| requestedPosition >= (Integer.MAX_VALUE - RESET_BOUND));
|
||||
}
|
||||
|
||||
private void ensureValidPosition(int position) {
|
||||
if (position >= wrapped.getItemCount()) {
|
||||
throw new IndexOutOfBoundsException(String.format(Locale.US,
|
||||
"requested position is outside adapter's bounds: position=%d, size=%d",
|
||||
position, wrapped.getItemCount()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInfinite() {
|
||||
return wrapped.getItemCount() > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInitialPosition() {
|
||||
return isInfinite() ? CENTER : 0;
|
||||
}
|
||||
|
||||
private void setPosition(int position) {
|
||||
layoutManager.scrollToPosition(position);
|
||||
}
|
||||
|
||||
//TODO: handle proper data set change notifications
|
||||
private class DataSetChangeDelegate extends RecyclerView.AdapterDataObserver {
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
setPosition(getInitialPosition());
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeRemoved(int positionStart, int itemCount) {
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeInserted(int positionStart, int itemCount) {
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
|
||||
onChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeChanged(int positionStart, int itemCount) {
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {
|
||||
notifyItemRangeChanged(0, getItemCount(), payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,11 +504,11 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
*/
|
||||
private void mockTouchEvent() {
|
||||
long downTime = SystemClock.uptimeMillis();
|
||||
long eventTime = SystemClock.uptimeMillis() + 100;
|
||||
long eventTime = downTime + 1;
|
||||
int metaState = 0;
|
||||
MotionEvent motionEvent = MotionEvent.obtain( downTime, eventTime, MotionEvent.ACTION_DOWN, 0, 0, metaState );
|
||||
mMapView.dispatchTouchEvent( motionEvent );
|
||||
MotionEvent upEvent = MotionEvent.obtain( downTime + 100, eventTime + 100, MotionEvent.ACTION_UP, 0, 0, metaState );
|
||||
MotionEvent upEvent = MotionEvent.obtain( downTime + 1, eventTime + 2, MotionEvent.ACTION_UP, 0, 0, metaState );
|
||||
mMapView.dispatchTouchEvent( upEvent );
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ public class BnHooker implements InvocationHandler {
|
||||
Field field = AMap.class.getDeclaredField( "a" );
|
||||
field.setAccessible( true );
|
||||
host = field.get( map );
|
||||
Object object = Proxy.newProxyInstance( BnHooker.class.getClassLoader(),
|
||||
Object object = Proxy.newProxyInstance(
|
||||
BnHooker.class.getClassLoader(),
|
||||
new Class[]{com.amap.api.col.n3.ft.a.class, IAMapDelegate.class, IAMapListener.class},
|
||||
this
|
||||
);
|
||||
|
||||
@@ -57,7 +57,7 @@ import java.util.List;
|
||||
*/
|
||||
public class MainActivity extends MvpActivity< MainView, MainPresenter > implements MainView,
|
||||
IMogoLocationListener,
|
||||
IMogoMarkerClickListener, IMogoIntentListener, IMogoCardChangedListener {
|
||||
IMogoMarkerClickListener{
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
@@ -91,7 +91,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
private int mCurrentPosition = 0;
|
||||
|
||||
private ViewPager.OnPageChangeListener mOnPageChangeListener;
|
||||
private IMogoIntentManager mMogoIntentManager;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -246,7 +245,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
|
||||
mMogoCardManager = mServiceApis.getCardManagerApi();
|
||||
|
||||
mMogoCardManager.registerCardChangedListener(TAG,this);
|
||||
mMogoFragmentManager = mServiceApis.getFragmentManagerApi();
|
||||
mMogoFragmentManager.init( this, R.id.module_main_id_search_fragment );
|
||||
mMogoFragmentManager.registerMainFragmentStackTransactionListener( ( size ) -> {
|
||||
@@ -257,19 +255,10 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
}
|
||||
} );
|
||||
|
||||
mMogoIntentManager = mServiceApis.getIntentManagerApi();
|
||||
mMogoStatusManager = mServiceApis.getStatusManagerApi();
|
||||
registerVoiceCmd();
|
||||
Log.i( "timer", "cost " + ( System.currentTimeMillis() - start ) + "ms" );
|
||||
}
|
||||
|
||||
private void registerVoiceCmd() {
|
||||
|
||||
for ( String cmd : VoiceConstants.sCmds ) {
|
||||
mMogoIntentManager.registerIntentListener( cmd, this );
|
||||
}
|
||||
}
|
||||
|
||||
private void startLocation() {
|
||||
mLocationClient = mMogoMapService.getSingletonLocationClient( getApplicationContext() );
|
||||
mLocationClient.addLocationListener( this );
|
||||
@@ -391,62 +380,4 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mMogoFragmentManager = null;
|
||||
AIAssist.getInstance( this ).release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntentReceived( String intentStr, Intent intent ) {
|
||||
if ( TextUtils.isEmpty( intentStr ) ) {
|
||||
return;
|
||||
}
|
||||
int currentItem = mCardsContainer.getCurrentItem();
|
||||
int cardSize = mCardModulesAdapter.getCount();
|
||||
|
||||
switch ( intentStr ) {
|
||||
case VoiceConstants.COMMAND_ZHIDAO_SWITCHCARD:
|
||||
|
||||
String data = intent.getStringExtra( "data" );
|
||||
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject( data );
|
||||
|
||||
String card = jsonObject.getString( "card" );
|
||||
|
||||
if ( TextUtils.equals( "多媒体", card ) ) {
|
||||
mCardsContainer.setCurrentItem( 1 );
|
||||
|
||||
} else if ( TextUtils.equals( "探路", card ) ) {
|
||||
mCardsContainer.setCurrentItem( 3 );
|
||||
|
||||
|
||||
} else if ( TextUtils.equals( "在线车辆", card ) ) {
|
||||
mCardsContainer.setCurrentItem( 5 );
|
||||
|
||||
}
|
||||
} catch ( JSONException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case VoiceConstants.COMMAND_ZHIDAO_SWITCHCARD_NEXT:
|
||||
currentItem++;
|
||||
mCardsContainer.setCurrentItem( currentItem / cardSize );
|
||||
|
||||
break;
|
||||
|
||||
case VoiceConstants.COMMAND_ZHIDAO_SWITCHCARD_PREVIOUS:
|
||||
currentItem--;
|
||||
if ( currentItem < 0 ) {
|
||||
currentItem += cardSize;
|
||||
}
|
||||
mCardsContainer.setCurrentItem( currentItem / cardSize );
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onSwitched(int position, String moduleName) {
|
||||
mCardsContainer.setCurrentItem( position );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.mogo.map.uicontroller.EnumMapUI;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.service.marker.MapMarkerManager;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
import com.mogo.module.service.network.RefreshModel;
|
||||
import com.mogo.module.service.receiver.MogoReceiver;
|
||||
@@ -37,15 +38,21 @@ import com.mogo.module.service.refresh.CustomRefreshStrategy;
|
||||
import com.mogo.module.service.refresh.RefreshObject;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.MogoAction;
|
||||
import com.mogo.service.module.IMogoActionManager;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -93,6 +100,8 @@ public class MogoServices implements IMogoMapListener,
|
||||
|
||||
private IMogoMapUIController mUiController;
|
||||
|
||||
private IMogoCardManager mCardManager;
|
||||
|
||||
/**
|
||||
* 是否已计算出地图显示状态
|
||||
*/
|
||||
@@ -118,6 +127,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
private IMogoMapService mMogoMapService;
|
||||
private IMogoStatusManager mStatusManager;
|
||||
private IMogoIntentManager mIntentManager;
|
||||
private IMogoActionManager mFlipContentManager;
|
||||
|
||||
/**
|
||||
* 地图视图初始化
|
||||
@@ -248,7 +258,6 @@ public class MogoServices implements IMogoMapListener,
|
||||
mStatusManager.registerStatusChangedListener( ServiceConst.TYPE, StatusDescriptor.SEARCH_UI, this );
|
||||
mStatusManager.registerStatusChangedListener( ServiceConst.TYPE, StatusDescriptor.ADAS_UI, this );
|
||||
|
||||
//TODO 初始化地图地图绘制大而全的Marker
|
||||
MarkerServiceHandler.init( mContext );
|
||||
registerAIReceiver( context );
|
||||
|
||||
@@ -264,6 +273,9 @@ public class MogoServices implements IMogoMapListener,
|
||||
mIntentManager.registerIntentListener( Intent.ACTION_POWER_DISCONNECTED, this );
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_NWD_ACC, this );
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_VOICE_UI, this );
|
||||
mIntentManager.registerIntentListener( ServiceConst.COMMAND_NEXT, this );
|
||||
mIntentManager.registerIntentListener( ServiceConst.COMMAND_PREVIOUS, this );
|
||||
mIntentManager.registerIntentListener( ServiceConst.COMMAND_SWITCH_CARD, this );
|
||||
|
||||
initWorkThread();
|
||||
}
|
||||
@@ -679,6 +691,25 @@ public class MogoServices implements IMogoMapListener,
|
||||
} else if ( TextUtils.equals( val, MogoReceiver.VALUE_SHOW ) ) {
|
||||
mStatusManager.setVoiceUIShow( TAG, true );
|
||||
}
|
||||
} else if ( ServiceConst.COMMAND_NEXT.equals( command ) ) {
|
||||
mFlipContentManager.invoke( MapMarkerManager.getInstance().getCurrentModuleName(), MogoAction.Next );
|
||||
} else if ( ServiceConst.COMMAND_PREVIOUS.equals( command ) ) {
|
||||
mFlipContentManager.invoke( MapMarkerManager.getInstance().getCurrentModuleName(), MogoAction.Prev );
|
||||
} else if ( ServiceConst.COMMAND_SWITCH_CARD.equals( command ) ) {
|
||||
String data = intent.getStringExtra( "data" );
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject( data );
|
||||
String card = jsonObject.getString( "card" );
|
||||
if ( TextUtils.equals( "多媒体", card ) ) {
|
||||
mCardManager.switch2( ServiceConst.CARD_TYPE_SHARE_MUSIC, true );
|
||||
} else if ( TextUtils.equals( "探路", card ) ) {
|
||||
mCardManager.switch2( ServiceConst.CARD_TYPE_ROAD_CONDITION, true );
|
||||
} else if ( TextUtils.equals( "在线车辆", card ) ) {
|
||||
mCardManager.switch2( ServiceConst.CARD_TYPE_USER_DATA, true );
|
||||
}
|
||||
} catch ( JSONException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,4 +108,20 @@ public class ServiceConst {
|
||||
public static final int MSG_REQUEST_DATA = 0x201;
|
||||
|
||||
|
||||
/**
|
||||
* 切换上一张卡片
|
||||
*/
|
||||
public static final String COMMAND_PREVIOUS = "com.zhidao.desk.switchCard.previous";
|
||||
|
||||
/**
|
||||
* 切换下一张卡片
|
||||
*/
|
||||
public static final String COMMAND_NEXT = "com.zhidao.desk.switchCard.next";
|
||||
|
||||
/**
|
||||
* 查看多媒体卡片、探路卡片
|
||||
*/
|
||||
public static final String COMMAND_SWITCH_CARD = "com.zhidao.desk.switchCard";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mogo.module.service.flipcontent;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.module.MogoAction;
|
||||
import com.mogo.service.module.IMogoActionListener;
|
||||
import com.mogo.service.module.IMogoActionManager;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-12
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = MogoServicePaths.PATH_ACTION_APIS )
|
||||
public class MogoActionManager implements IMogoActionManager {
|
||||
|
||||
@Override
|
||||
public void registerActionListener( String biz, IMogoActionListener listener ) {
|
||||
MogoFlipContentHandler.getInstance().registerActionListener( biz, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterActionListener( String biz, IMogoActionListener listener ) {
|
||||
MogoFlipContentHandler.getInstance().unregisterActionListener( biz, listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke( String biz, MogoAction action ) {
|
||||
MogoFlipContentHandler.getInstance().invoke( biz, action );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
MogoFlipContentHandler.getInstance().init( context );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.mogo.module.service.flipcontent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.service.module.MogoAction;
|
||||
import com.mogo.service.module.IMogoActionListener;
|
||||
import com.mogo.service.module.IMogoActionManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-12
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MogoFlipContentHandler implements IMogoActionManager {
|
||||
|
||||
private MogoFlipContentHandler() {
|
||||
// private constructor
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
private static final MogoFlipContentHandler INSTANCE = new MogoFlipContentHandler();
|
||||
}
|
||||
|
||||
public static MogoFlipContentHandler getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private Map< String, List< IMogoActionListener > > mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void registerActionListener( String biz, IMogoActionListener listener ) {
|
||||
if ( TextUtils.isEmpty( biz ) || listener == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !mListeners.containsKey( biz ) ) {
|
||||
mListeners.put( biz, new ArrayList<>() );
|
||||
}
|
||||
mListeners.get( biz ).add( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterActionListener( String biz, IMogoActionListener listener ) {
|
||||
if ( TextUtils.isEmpty( biz ) || listener == null ) {
|
||||
return;
|
||||
}
|
||||
if ( mListeners.containsKey( biz ) ) {
|
||||
mListeners.get( biz ).remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke( String biz, MogoAction action ) {
|
||||
if ( !mListeners.containsKey( biz ) ) {
|
||||
return;
|
||||
}
|
||||
List< IMogoActionListener > listeners = mListeners.get( biz );
|
||||
if ( listeners != null ) {
|
||||
Iterator< IMogoActionListener > iterator = listeners.iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoActionListener listener = iterator.next();
|
||||
if ( listener != null ) {
|
||||
listener.onActionDone( action );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -752,4 +752,8 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
|
||||
}
|
||||
ThreadPoolService.execute( runnable );
|
||||
}
|
||||
|
||||
public String getCurrentModuleName() {
|
||||
return mCurrentModuleName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.imageloader.IMogoImageloader;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoActionManager;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
import com.mogo.service.module.IMogoSettingManager;
|
||||
@@ -138,4 +139,11 @@ public interface IMogoServiceApis extends IProvider {
|
||||
* @return
|
||||
*/
|
||||
IMogoADASController getAdasControllerApi();
|
||||
|
||||
/**
|
||||
* 内容翻页
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IMogoActionManager getFlipContentManager();
|
||||
}
|
||||
|
||||
@@ -142,4 +142,10 @@ public class MogoServicePaths {
|
||||
* 接口集合
|
||||
*/
|
||||
public static final String PATH_SERVICE_APIS = "/mogoservice/apis";
|
||||
|
||||
/**
|
||||
* 动作指令
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String PATH_ACTION_APIS = "/mogoaction/api";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mogo.service.module;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-12
|
||||
* <p>
|
||||
* 翻页回调
|
||||
*/
|
||||
public interface IMogoActionListener {
|
||||
|
||||
/**
|
||||
* 执行动作
|
||||
*
|
||||
* @param action
|
||||
*/
|
||||
void onActionDone( MogoAction action );
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mogo.service.module;
|
||||
|
||||
import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-12
|
||||
* <p>
|
||||
* 基础动作指令控制
|
||||
*/
|
||||
public interface IMogoActionManager extends IProvider {
|
||||
|
||||
/**
|
||||
* 注册动作监听回调
|
||||
*
|
||||
* @param biz 具体业务
|
||||
* @param listener 回调
|
||||
*/
|
||||
void registerActionListener( String biz, IMogoActionListener listener );
|
||||
|
||||
/**
|
||||
* 取消动作翻页回调
|
||||
*
|
||||
* @param biz 具体业务
|
||||
* @param listener 回调
|
||||
*/
|
||||
void unregisterActionListener( String biz, IMogoActionListener listener );
|
||||
|
||||
/**
|
||||
* 回调
|
||||
*
|
||||
* @param biz 业务
|
||||
* @param action 动作
|
||||
*/
|
||||
void invoke( String biz, MogoAction action );
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mogo.service.module;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-12
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public enum MogoAction {
|
||||
|
||||
/**
|
||||
* 上一个
|
||||
*/
|
||||
Prev,
|
||||
|
||||
/**
|
||||
* 下一个
|
||||
*/
|
||||
Next
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.mogo.service.impl.intent.IntentManager;
|
||||
import com.mogo.service.impl.singleton.SingletonsHolder;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.service.module.IMogoActionManager;
|
||||
import com.mogo.service.module.IMogoRegisterCenter;
|
||||
import com.mogo.service.module.IMogoSearchManager;
|
||||
import com.mogo.service.module.IMogoSettingManager;
|
||||
@@ -129,6 +130,11 @@ public class MogoServiceApis implements IMogoServiceApis {
|
||||
return getApiInstance( IMogoADASController.class, MogoServicePaths.PATH_ADAS_CONTROLLER );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoActionManager getFlipContentManager() {
|
||||
return getApiInstance( IMogoActionManager.class, MogoServicePaths.PATH_ACTION_APIS );
|
||||
}
|
||||
|
||||
private static < T extends IProvider > T getApiInstance( Class< T > clazz, String path ) {
|
||||
T inst = SingletonsHolder.get( clazz );
|
||||
if ( inst == null ) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.intent.IMogoIntentManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -26,25 +27,6 @@ public class IntentManager implements IMogoIntentManager {
|
||||
|
||||
private static volatile IntentManager sInstance;
|
||||
|
||||
public static final int MSG_COMMAND_RECEIVED = 2000;
|
||||
|
||||
|
||||
private Handler mHandler = new Handler( Looper.getMainLooper() ) {
|
||||
@Override
|
||||
public void handleMessage( @NonNull Message msg ) {
|
||||
super.handleMessage( msg );
|
||||
if ( msg.what == MSG_COMMAND_RECEIVED ) {
|
||||
MsgObject object = ( ( MsgObject ) msg.obj );
|
||||
List< IMogoIntentListener > listeners = mListeners.get( object.getCommand() );
|
||||
if ( listeners != null && !listeners.isEmpty() ) {
|
||||
for ( IMogoIntentListener listener : listeners ) {
|
||||
listener.onIntentReceived( object.getCommand(), object.getIntent() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private IntentManager() {
|
||||
}
|
||||
|
||||
@@ -63,7 +45,6 @@ public class IntentManager implements IMogoIntentManager {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
|
||||
private Map< String, List< IMogoIntentListener > > mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
@@ -91,9 +72,15 @@ public class IntentManager implements IMogoIntentManager {
|
||||
|
||||
@Override
|
||||
public void invoke( String command, Intent intent ) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = MSG_COMMAND_RECEIVED;
|
||||
msg.obj = new MsgObject( command, intent );
|
||||
mHandler.sendMessage( msg );
|
||||
List< IMogoIntentListener > listeners = mListeners.get( command );
|
||||
if ( listeners != null && !listeners.isEmpty() ) {
|
||||
Iterator< IMogoIntentListener > iterator = listeners.iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoIntentListener listener = iterator.next();
|
||||
if ( listener != null ) {
|
||||
listener.onIntentReceived( command, intent );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.mogo.service.impl.intent;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-13
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MsgObject {
|
||||
|
||||
private final String mCommand;
|
||||
private final Intent mIntent;
|
||||
|
||||
public MsgObject( String command, Intent intent ) {
|
||||
this.mCommand = command;
|
||||
this.mIntent = intent;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return mCommand;
|
||||
}
|
||||
|
||||
public Intent getIntent() {
|
||||
return mIntent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user