diff --git a/app/build.gradle b/app/build.gradle index 9fa3526b19..011d1620a1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -266,7 +266,6 @@ dependencies { exclude group: 'com.mogo.module', module: 'module-share' } implementation rootProject.ext.dependencies.moduletanluapi - implementation rootProject.ext.dependencies.mogomonitor implementation rootProject.ext.dependencies.mogomodulewidgets } else { diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/Back2LauncherFragment.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/Back2LauncherFragment.java deleted file mode 100644 index 68a9943451..0000000000 --- a/modules/mogo-module-back/src/main/java/com/mogo/module/back/Back2LauncherFragment.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.mogo.module.back; - -import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import com.mogo.utils.logger.Logger; - -/** - * @author congtaowang - * @since 2020-02-26 - *

- * 描述 - */ -public class Back2LauncherFragment extends Fragment { - - private static final String TAG = "Back2LauncherFragment"; - - @Override - public void onCreate( @Nullable Bundle savedInstanceState ) { - super.onCreate( savedInstanceState ); - BackToMainHomeManager.addMainHomeView(); - Logger.d( TAG, "addMainHomeView" ); - } - - @Override - public void onDestroy() { - super.onDestroy(); - BackToMainHomeManager.removeMainHomeView(); - Logger.d( TAG, "removeMainHomeView" ); - } -} diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToLauncherModuleProvider.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToLauncherModuleProvider.java index a92fcecdee..c03d6944b3 100644 --- a/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToLauncherModuleProvider.java +++ b/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToLauncherModuleProvider.java @@ -49,46 +49,11 @@ public class BackToLauncherModuleProvider implements IMogoModuleProvider { return BackToLauncherConst.MODULE_NAME; } - @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 ) { if ( CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X ) { diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToMainHomeManager.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToMainHomeManager.java index db17ed40fc..ea748c53fe 100644 --- a/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToMainHomeManager.java +++ b/modules/mogo-module-back/src/main/java/com/mogo/module/back/BackToMainHomeManager.java @@ -1,28 +1,20 @@ package com.mogo.module.back; -import android.content.Context; import android.content.Intent; -import android.graphics.PixelFormat; -import android.os.Build; import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; import android.view.WindowManager; import com.mogo.commons.AbsMogoApplication; -import com.mogo.module.back.utils.WindowManagerViewHelper; +import com.mogo.module.common.wm.WindowManagerView; import com.mogo.service.IMogoServiceApis; import com.mogo.service.fragmentmanager.IMogoFragmentManager; import com.mogo.service.statusmanager.IMogoStatusManager; -import com.mogo.utils.AppUtils; import com.mogo.utils.logger.Logger; public class BackToMainHomeManager { private static final String TAG = "BackToMainHomeManager"; - private static View mBackView; - private static IMogoFragmentManager mFragmentManager; private static IMogoStatusManager mStatusManager; private static IMogoServiceApis mApis; @@ -45,7 +37,7 @@ public class BackToMainHomeManager { return; } - Intent intent2 = new Intent( ); + Intent intent2 = new Intent(); // 是否发自系统消息 intent2.putExtra( "isHomeKeyDown", false ); mApis.getIntentManagerApi().invoke( Intent.ACTION_CLOSE_SYSTEM_DIALOGS, intent2 ); @@ -58,40 +50,34 @@ public class BackToMainHomeManager { AbsMogoApplication.getApp().startActivity( intent ); } + private static WindowManagerView mWindowManagerView; + public static void addMainHomeView() { Logger.d( "BackToMainHomeManager", "addMainHomeView" ); - if ( mBackView != null ) WindowManagerViewHelper.removeView( mBackView ); - mBackView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.mogo_module_back_home_back_layout, null ); - final Context context = mBackView.getContext(); - if ( context == null || context.getApplicationContext() == null ) { - return; + + if ( mWindowManagerView == null ) { + mWindowManagerView = new WindowManagerView.Builder( AbsMogoApplication.getApp() ) + .contentView( R.layout.mogo_module_back_home_back_layout ) + .position( AbsMogoApplication.getApp().getResources().getDimensionPixelOffset( R.dimen.module_back_main_home_icon_left ), + AbsMogoApplication.getApp().getResources().getDimensionPixelOffset( R.dimen.module_back_main_home_icon_top ) ) + .size( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT ) + .gravity( Gravity.LEFT | Gravity.TOP ) + .showInWindowManager(); + mWindowManagerView.attachTouchEvent( view -> { + backToLauncher(); + } ); } - WindowManager windowManager = ( WindowManager ) context.getApplicationContext().getSystemService( Context.WINDOW_SERVICE ); - if ( windowManager == null ) { - return; + try { + mWindowManagerView.show(); + } catch ( Exception e ) { + e.printStackTrace(); } - mBackView.setOnClickListener( view -> { - backToLauncher(); - } ); - WindowManager.LayoutParams params = new WindowManager.LayoutParams(); - params.height = WindowManager.LayoutParams.WRAP_CONTENT; - params.width = WindowManager.LayoutParams.WRAP_CONTENT; - params.x = AbsMogoApplication.getApp().getResources().getDimensionPixelOffset( R.dimen.module_back_main_home_icon_left ); - params.y = AbsMogoApplication.getApp().getResources().getDimensionPixelOffset( R.dimen.module_back_main_home_icon_top ); - params.gravity = Gravity.LEFT | Gravity.CENTER; - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) { - params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; - } else { - params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; - } - params.format = PixelFormat.RGBA_8888; - params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; - windowManager.addView( mBackView, params ); - WindowManagerViewHelper.attachMovementEvent( mBackView, params ); } public static void removeMainHomeView() { - WindowManagerViewHelper.removeView( mBackView ); + if ( mWindowManagerView != null ) { + mWindowManagerView.dismiss(); + } } } diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/Utils.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/Utils.java deleted file mode 100644 index ace6e4bdae..0000000000 --- a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/Utils.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mogo.module.back.utils; - -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; - -import com.mogo.commons.AbsMogoApplication; - -public class Utils { - public static boolean isActivityExits( String packageName, String classStr ) { - Intent intent = new Intent(); - intent.setClassName( packageName, classStr ); - ResolveInfo resolveInfo = AbsMogoApplication.getApp().getPackageManager().resolveActivity( intent, PackageManager.MATCH_DEFAULT_ONLY ); - if ( resolveInfo != null ) { - return true; - } else { - return false; - } - } -} diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowManagerViewHelper.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowManagerViewHelper.java deleted file mode 100644 index ff03d5ab96..0000000000 --- a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowManagerViewHelper.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.mogo.module.back.utils; - -import android.content.Context; -import android.graphics.PixelFormat; -import android.os.Build; -import android.view.Gravity; -import android.view.MotionEvent; -import android.view.View; -import android.view.WindowManager; - -/** - * @author congtaowang - * @since 2019-04-30 - *

- * 向 window manager 添加 view - */ -public class WindowManagerViewHelper { - - public static void addView( View view ) { - - final Context context = view.getContext(); - if ( context == null || context.getApplicationContext() == null ) { - return; - } - WindowManager windowManager = ( WindowManager ) context.getApplicationContext().getSystemService( Context.WINDOW_SERVICE ); - if ( windowManager == null ) { - return; - } - WindowManager.LayoutParams params = new WindowManager.LayoutParams(); - params.height = WindowManager.LayoutParams.WRAP_CONTENT; - params.width = WindowManager.LayoutParams.WRAP_CONTENT; - params.gravity = Gravity.LEFT | Gravity.CENTER; - params.type = getFitWindowParamsType(); - params.format = PixelFormat.RGBA_8888; - params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; - windowManager.addView( view, params ); - - attachMovementEvent( view, params ); - } - - private static int getFitWindowParamsType() { - int type; - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 ) { - // Need request permission. - type = WindowManager.LayoutParams.TYPE_PHONE; - } else if ( Build.MODEL.equalsIgnoreCase( "MI 5" ) ) { - // MI 5 phone not display crawler dot in android 7.0 - type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; - } else { - // It's will be dismissed automatically 3s after showing in Android 25. - type = WindowManager.LayoutParams.TYPE_TOAST; - } - return type; - } - - public static void removeView( View view ) { - if ( view == null || view.getContext() == null || view.getContext().getApplicationContext() == null ) { - return; - } - WindowManager windowManager = ( WindowManager ) view.getContext().getApplicationContext().getSystemService( Context.WINDOW_SERVICE ); - if ( windowManager == null ) { - return; - } - windowManager.removeViewImmediate( view ); - DispatchTouchEventWrapper.getInstance().release(); - - } - - public static void attachMovementEvent( View view, WindowManager.LayoutParams params ) { - if ( view == null ) { - return; - } - view.setOnTouchListener( ( v, event ) -> { - DispatchTouchEventWrapper.getInstance() - .attach( view, params ) - .handle( event ); - return false; - } ); - } - - static class DispatchTouchEventWrapper { - - private WindowViewHandler mWindowViewHandler; - - int mActionDownX = -1; - int mActionDownY = -1; - - /** - * Flag whether move after touch down. - */ - boolean mMoveFlag = false; - - private static volatile DispatchTouchEventWrapper INST; - - private DispatchTouchEventWrapper() { - } - - public static DispatchTouchEventWrapper getInstance() { - if ( INST == null ) { - synchronized ( DispatchTouchEventWrapper.class ) { - if ( INST == null ) { - INST = new DispatchTouchEventWrapper(); - } - } - } - return INST; - } - - public DispatchTouchEventWrapper attach( View windowView, WindowManager.LayoutParams params ) { - if ( mWindowViewHandler == null || mWindowViewHandler.getWindowView() != windowView ) { - mWindowViewHandler = new WindowViewHandler.DefaultHandler( windowView, params ); - } - return this; - } - - public boolean handle( MotionEvent event ) { - switch ( event.getAction() & MotionEvent.ACTION_MASK ) { - case MotionEvent.ACTION_DOWN: - if ( onActionDown( event ) ) { - return true; - } - break; - case MotionEvent.ACTION_MOVE: - if ( onActionMove( event ) ) { - return true; - } - break; - case MotionEvent.ACTION_UP: - if ( onActionUp( event ) ) { - return true; - } - break; - } - return false; - } - - private boolean onActionDown( MotionEvent event ) { - mActionDownX = ( ( int ) event.getRawX() ); - mActionDownY = ( ( int ) event.getRawY() ); - if ( mWindowViewHandler != null ) { - mWindowViewHandler.recordNewPosition(); - return true; - } - return false; - } - - private boolean onActionMove( MotionEvent event ) { - - if ( Math.abs( event.getRawX() - mActionDownX ) >= 20 - || Math.abs( event.getRawY() - mActionDownY ) >= 20 ) { - mMoveFlag = true; - } - - if ( isLastDownValueLegal() ) { - moveWindowView( event ); - return true; - } - return false; - } - - private boolean onActionUp( MotionEvent event ) { - if ( isClickEventLike() ) { - if ( mWindowViewHandler != null ) { - mWindowViewHandler.performClickLike(); - } - } else { - if ( mWindowViewHandler != null ) { - mWindowViewHandler.moveToEdge(); - mWindowViewHandler.recordNewPosition(); - } - } - mMoveFlag = false; - clearLastDownAxisValue(); - return true; - } - - private void clearLastDownAxisValue() { - mActionDownX = mActionDownY = -1; - } - - private boolean isLastDownValueLegal() { - return mActionDownX != -1 && mActionDownY != -1; - } - - private void moveWindowView( MotionEvent event ) { - if ( mWindowViewHandler != null ) { - mWindowViewHandler.move( event, mActionDownX, mActionDownY ); - } - } - - /** - * Simulate click event just like set {@link View.OnClickListener} - * - * @return - */ - private boolean isClickEventLike() { - System.out.println( mMoveFlag ); - return isLastDownValueLegal() && !mMoveFlag; - } - - public void release() { - if ( mWindowViewHandler != null ) { - mWindowViewHandler.release(); - } - mWindowViewHandler = null; - mActionDownX = -1; - mActionDownY = -1; - mMoveFlag = false; - INST = null; - } - } - -} diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewHandler.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewHandler.java deleted file mode 100644 index bbd48717cd..0000000000 --- a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewHandler.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.mogo.module.back.utils; - -import android.content.Context; -import android.view.MotionEvent; -import android.view.View; -import android.view.WindowManager; - -import com.mogo.commons.AbsMogoApplication; -import com.mogo.utils.WindowUtils; - - -/** - * Created by congtaowang on 2017/6/20. - */ - -public interface WindowViewHandler { - - View getWindowView(); - - void recordNewPosition(); - - void move(MotionEvent event, int downX, int downY); - - void release(); - - void moveToEdge(); - - void performClickLike(); - - class DefaultHandler implements WindowViewHandler { - - protected View mWindowView; - - protected int mWindowViewLeft = -1; - protected int mWindowViewTop = -1; - - private WindowManager.LayoutParams mParams; - - public DefaultHandler( View windowView, WindowManager.LayoutParams params ) { - this.mWindowView = windowView; - mParams = params; - } - - @Override - public View getWindowView() { - return mWindowView; - } - - @Override - public void recordNewPosition() { - mWindowViewLeft = mParams.x; - mWindowViewTop = mParams.y; - } - - @Override - public void move( MotionEvent event, int downX, int downY ) { - move( ( ( int ) ( event.getRawX() - downX ) ), - ( ( int ) ( event.getRawY() - downY ) ) ); - } - - private void move( int distanceX, int distanceY ) { - if ( mWindowView == null ) { - return; - } - mParams.x = mWindowViewLeft + distanceX; - mParams.y = mWindowViewTop + distanceY; - WindowManager wm = ( ( WindowManager ) mWindowView.getContext().getSystemService( Context.WINDOW_SERVICE ) ); - - if ( wm == null ) { - return; - } - - if ( mWindowView instanceof WindowViewUIController ) { - if ( mParams.x > WindowUtils.getScreenWidth( AbsMogoApplication.getApp() ) / 2 ) { - ( ( WindowViewUIController ) mWindowView ).rightMode(); - } else { - ( ( WindowViewUIController ) mWindowView ).leftMode(); - } - } - - wm.updateViewLayout( mWindowView, alignLayoutParamsBoundary( mParams ) ); - } - - @Override - public void moveToEdge() { - if ( mWindowView == null ) { - return; - } - WindowManager wm = ( ( WindowManager ) mWindowView.getContext().getSystemService( Context.WINDOW_SERVICE ) ); - - if ( mParams.x > WindowUtils.getScreenWidth( AbsMogoApplication.getApp() ) / 2 ) { - mParams.x = WindowUtils.getScreenWidth( AbsMogoApplication.getApp() ) - mWindowView.getMeasuredWidth(); - } else { - mParams.x = 0; - } - - wm.updateViewLayout( mWindowView, alignLayoutParamsBoundary( mParams ) ); - } - - protected WindowManager.LayoutParams alignLayoutParamsBoundary( WindowManager.LayoutParams params ) { - return params; - } - - @Override - public void performClickLike() { - if ( mWindowView instanceof WindowViewUIController ) { - ( ( WindowViewUIController ) mWindowView ).performClickLike(); - } - } - - @Override - public void release() { - mWindowView = null; - mWindowViewLeft = -1; - mWindowViewTop = -1; - } - } - -} diff --git a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewUIController.java b/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewUIController.java deleted file mode 100644 index e329cdea68..0000000000 --- a/modules/mogo-module-back/src/main/java/com/mogo/module/back/utils/WindowViewUIController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mogo.module.back.utils; - -/** - * @author congtaowang - * @since 2019-05-12 - *

- * 描述 - */ -public interface WindowViewUIController { - - void leftMode(); - - void rightMode(); - - void performClickLike(); -} diff --git a/modules/mogo-module-back/src/main/res/values-xhdpi/dimens.xml b/modules/mogo-module-back/src/main/res/values-xhdpi/dimens.xml index bd57c0f8ae..e0b0d888aa 100644 --- a/modules/mogo-module-back/src/main/res/values-xhdpi/dimens.xml +++ b/modules/mogo-module-back/src/main/res/values-xhdpi/dimens.xml @@ -1,8 +1,8 @@ 140px - 0px - 190px + 30px + 230px diff --git a/modules/mogo-module-back/src/main/res/values/dimens.xml b/modules/mogo-module-back/src/main/res/values/dimens.xml index dfab5dd86c..a50305933f 100644 --- a/modules/mogo-module-back/src/main/res/values/dimens.xml +++ b/modules/mogo-module-back/src/main/res/values/dimens.xml @@ -1,7 +1,7 @@ 80px - 0px - 100px + 16px + 140px \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml index 446c7541b0..222f293173 100644 --- a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml +++ b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_extensions.xml @@ -12,6 +12,7 @@ android:gravity="center" android:paddingStart="@dimen/module_ext_weather_container_paddingLeft" android:paddingEnd="@dimen/module_ext_weather_container_paddingRight" + android:layout_marginEnd="@dimen/module_ext_msg_marginRight" android:visibility="invisible" app:layout_constraintRight_toLeftOf="@+id/module_ext_id_msg" app:layout_constraintTop_toTopOf="parent" diff --git a/services/mogo-service-api/src/main/java/com/mogo/service/module/IMogoModuleProvider.java b/services/mogo-service-api/src/main/java/com/mogo/service/module/IMogoModuleProvider.java index 59dad0341e..524010759b 100644 --- a/services/mogo-service-api/src/main/java/com/mogo/service/module/IMogoModuleProvider.java +++ b/services/mogo-service-api/src/main/java/com/mogo/service/module/IMogoModuleProvider.java @@ -51,7 +51,10 @@ public interface IMogoModuleProvider extends IProvider { * * @return */ - IMogoModuleLifecycle getCardLifecycle(); + @Deprecated + default IMogoModuleLifecycle getCardLifecycle() { + return null; + } /** * 地图监听对象 @@ -60,7 +63,9 @@ public interface IMogoModuleProvider extends IProvider { * @return */ @Deprecated - IMogoMapListener getMapListener(); + default IMogoMapListener getMapListener() { + return null; + } /** * 是哪种类型的提供者 @@ -78,7 +83,9 @@ public interface IMogoModuleProvider extends IProvider { * @return */ @Deprecated - IMogoNaviListener getNaviListener(); + default IMogoNaviListener getNaviListener() { + return null; + } /** * 定位变化监听:此接口接受地图定位信息 @@ -87,7 +94,9 @@ public interface IMogoModuleProvider extends IProvider { * @return */ @Deprecated - IMogoLocationListener getLocationListener(); + default IMogoLocationListener getLocationListener() { + return null; + } /** * marker 点击回调 @@ -96,19 +105,27 @@ public interface IMogoModuleProvider extends IProvider { * @return */ @Deprecated - IMogoMarkerClickListener getMarkerClickListener(); + default IMogoMarkerClickListener getMarkerClickListener() { + return null; + } /** * 获取模块对应 app 的包名 * * @return */ - String getAppPackage(); + @Deprecated + default String getAppPackage() { + return ""; + } /** * 获取对应模块 app 名称 * * @return */ - String getAppName(); + @Deprecated + default String getAppName() { + return ""; + } }