抽离导航中的悬浮按钮逻辑
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
package com.mogo.module.widgets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.Gravity;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.module.common.wm.WindowManagerView;
|
||||
import com.mogo.utils.LaunchUtils;
|
||||
import com.mogo.utils.ResourcesHelper;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/5
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class AutoNaviIntentHandler {
|
||||
|
||||
private static final String TAG = "AutoNaviIntentHandler";
|
||||
|
||||
private static volatile AutoNaviIntentHandler sInstance;
|
||||
|
||||
private AutoNaviIntentHandler() {
|
||||
}
|
||||
|
||||
public static AutoNaviIntentHandler getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( AutoNaviIntentHandler.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new AutoNaviIntentHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private WindowManagerView mWindowManagerView;
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
public void handle( Context context, Intent intent ) {
|
||||
int keyType = intent.getIntExtra( "KEY_TYPE", 0 );
|
||||
switch ( keyType ) {
|
||||
case 10021:
|
||||
closeEntrance();
|
||||
break;
|
||||
case 10019:
|
||||
int extraState = intent.getIntExtra( "EXTRA_STATE", -1 );
|
||||
switch ( extraState ) {
|
||||
case 3:
|
||||
syncAutoNaviNavingStatus( context );
|
||||
break;
|
||||
case 4:
|
||||
closeEntrance();
|
||||
break;
|
||||
case 8:
|
||||
showEntrance( context );
|
||||
break;
|
||||
case 9:
|
||||
closeEntrance();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过查询高德地图状态后再显示
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void preShowEntrance( Context context ) {
|
||||
syncAutoNaviForgroundStatus( context );
|
||||
}
|
||||
|
||||
private void showEntrance( Context context ) {
|
||||
if ( mWindowManagerView == null ) {
|
||||
mWindowManagerView = new WindowManagerView.Builder( AbsMogoApplication.getApp() )
|
||||
.contentView( R.layout.module_widgets_app_entrance )
|
||||
.size( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT )
|
||||
.gravity( Gravity.LEFT | Gravity.TOP )
|
||||
.position( ResourcesHelper.getDimensionPixelSize( context, R.dimen.module_widgets_app_entrance_x ), ResourcesHelper.getDimensionPixelSize( AbsMogoApplication.getApp(), R.dimen.module_widgets_app_entrance_y ) )
|
||||
.showInWindowManager();
|
||||
mWindowManagerView.attachTouchEvent( view -> {
|
||||
try {
|
||||
if ( DebugConfig.isLauncher() ) {
|
||||
MogoWidgetManger.getInstance().getApis().getLauncherApi().backToLauncher( context );
|
||||
} else {
|
||||
LaunchUtils.launchByPkg( context, "com.mogo.launcher.app" );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
} );
|
||||
}
|
||||
try {
|
||||
mWindowManagerView.show();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
public void closeEntrance() {
|
||||
if ( mWindowManagerView == null ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
mWindowManagerView.dismiss();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
public void syncAutoNaviForgroundStatus( Context context ) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction( "AUTONAVI_STANDARD_BROADCAST_RECV" );
|
||||
intent.putExtra( "KEY_TYPE", 12404 );
|
||||
intent.putExtra( "EXTRA_REQUEST_AUTO_STATE", 0 );
|
||||
context.sendBroadcast( intent );
|
||||
}
|
||||
|
||||
public void syncAutoNaviNavingStatus( Context context ) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction( "AUTONAVI_STANDARD_BROADCAST_RECV" );
|
||||
intent.putExtra( "KEY_TYPE", 12404 );
|
||||
intent.putExtra( "EXTRA_REQUEST_AUTO_STATE", 1 );
|
||||
context.sendBroadcast( intent );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.mogo.module.widgets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.map.navi.IMogoNaviListener2;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.intent.IMogoIntentListener;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/8/12
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class MogoWidgetManger implements IMogoNaviListener2, IMogoIntentListener, IMogoStatusChangedListener {
|
||||
|
||||
// 接受其他app发给高德的广播
|
||||
public static final String ACTION_AUTO_NAVI_RECEIVER = "AUTONAVI_STANDARD_BROADCAST_RECV";
|
||||
// 接受高德发过来的广播
|
||||
public static final String ACTION_AUTO_NAVI_SEND = "AUTONAVI_STANDARD_BROADCAST_SEND";
|
||||
|
||||
private static final String TAG = "MogoWidgetManger";
|
||||
|
||||
private static volatile MogoWidgetManger sInstance;
|
||||
|
||||
private MogoWidgetManger() {
|
||||
}
|
||||
|
||||
public static MogoWidgetManger getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( MogoWidgetManger.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new MogoWidgetManger();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private IMogoServiceApis mApis;
|
||||
private Context mContext;
|
||||
|
||||
public IMogoServiceApis getApis() {
|
||||
return mApis;
|
||||
}
|
||||
|
||||
public void init( Context context ) {
|
||||
mContext = context;
|
||||
mApis = ARouter.getInstance().navigation( IMogoServiceApis.class );
|
||||
initMapStatusListener();
|
||||
initStatusListener();
|
||||
initIntentListener();
|
||||
AutoNaviIntentHandler.getInstance().syncAutoNaviForgroundStatus( mContext );
|
||||
}
|
||||
|
||||
private void initMapStatusListener() {
|
||||
mApis.getRegisterCenterApi().registerMogoNaviListener( TAG, this );
|
||||
}
|
||||
|
||||
private void initIntentListener() {
|
||||
mApis.getIntentManagerApi().registerIntentListener( ACTION_AUTO_NAVI_RECEIVER, this );
|
||||
mApis.getIntentManagerApi().registerIntentListener( ACTION_AUTO_NAVI_SEND, this );
|
||||
}
|
||||
|
||||
private void initStatusListener() {
|
||||
mApis.getStatusManagerApi().registerStatusChangedListener( TAG, StatusDescriptor.MAIN_PAGE_RESUME, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopNavi() {
|
||||
AutoNaviIntentHandler.getInstance().closeEntrance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartNavi() {
|
||||
AutoNaviIntentHandler.getInstance().preShowEntrance( mContext );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntentReceived( String intentStr, Intent intent ) {
|
||||
AutoNaviIntentHandler.getInstance().handle( mContext, intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged( StatusDescriptor descriptor, boolean isTrue ) {
|
||||
if ( descriptor == StatusDescriptor.MAIN_PAGE_RESUME ) {
|
||||
if ( isTrue ) {
|
||||
AutoNaviIntentHandler.getInstance().closeEntrance();
|
||||
} else {
|
||||
AutoNaviIntentHandler.getInstance().syncAutoNaviForgroundStatus( mContext );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.mogo.module.widgets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/8/12
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = MogoWidgetsProvider.PATH )
|
||||
class MogoWidgetsProvider implements IMogoModuleProvider {
|
||||
|
||||
private static final String TAG = "MogoWidgetsProvider";
|
||||
|
||||
public static final String PATH = "/widgets/provider";
|
||||
public static final String NAME = "MogoWidgetProvider";
|
||||
|
||||
@Override
|
||||
public Fragment createFragment( Context context, Bundle data ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView( Context context ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoModuleLifecycle getCardLifecycle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMapListener getMapListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return ModuleType.TYPE_SERVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoNaviListener getNaviListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoLocationListener getLocationListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMarkerClickListener getMarkerClickListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppPackage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
Logger.d( TAG, "init." );
|
||||
UiThreadHandler.postDelayed( () -> {
|
||||
MogoWidgetManger.getInstance().init( context );
|
||||
}, 5500 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user