导航显示按钮
This commit is contained in:
@@ -29,6 +29,11 @@ class DialogImpl implements IWindowManagerView {
|
||||
return dialog.isShowing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTouchEvent(OnViewClickListener listener) {
|
||||
// do nothings.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
dialog.show();
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
package com.mogo.module.common.wm;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
interface IWindowManagerView {
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param params contentView包装类
|
||||
*/
|
||||
void init(WindowManagerView.WMViewParams params);
|
||||
void init( WindowManagerView.WMViewParams params );
|
||||
|
||||
/**
|
||||
* 是否显示
|
||||
*
|
||||
* @return true - 显示中
|
||||
*/
|
||||
boolean isShowing();
|
||||
|
||||
/**
|
||||
* 支持手势拖动,该操作只支持触发点击操作
|
||||
*/
|
||||
void handleTouchEvent(OnViewClickListener listener);
|
||||
|
||||
/**
|
||||
* 显示
|
||||
*/
|
||||
@@ -22,4 +31,8 @@ interface IWindowManagerView {
|
||||
* 隐藏
|
||||
*/
|
||||
void hide();
|
||||
|
||||
interface OnViewClickListener {
|
||||
void onClick( View view );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,9 @@ package com.mogo.module.common.wm;
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.mogo.module.common.utils.CarSeries;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
|
||||
/**
|
||||
* 采用windowManager实现接口
|
||||
*/
|
||||
@@ -19,10 +16,13 @@ class WindowManagerImpl implements IWindowManagerView {
|
||||
private WindowManagerView.WMViewParams mParams;
|
||||
private boolean isShowing;
|
||||
|
||||
private float mLastX, mLastY;
|
||||
private int mOldOffsetX, mOldOffsetY;
|
||||
|
||||
@Override
|
||||
public void init(WindowManagerView.WMViewParams params) {
|
||||
public void init( WindowManagerView.WMViewParams params ) {
|
||||
mParams = params;
|
||||
mWindowManager = (WindowManager) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE );
|
||||
mWindowManager = ( WindowManager ) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE );
|
||||
mLayoutParams = new WindowManager.LayoutParams();
|
||||
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
|
||||
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
@@ -35,8 +35,8 @@ class WindowManagerImpl implements IWindowManagerView {
|
||||
|
||||
mLayoutParams.width = mParams.mWidth;
|
||||
mLayoutParams.height = mParams.mHeight;
|
||||
mLayoutParams.x = mParams.mX;
|
||||
mLayoutParams.y = mParams.mY;
|
||||
mOldOffsetX = mLayoutParams.x = mParams.mX;
|
||||
mOldOffsetY = mLayoutParams.y = mParams.mY;
|
||||
mLayoutParams.dimAmount = 0.5f;
|
||||
}
|
||||
|
||||
@@ -45,18 +45,46 @@ class WindowManagerImpl implements IWindowManagerView {
|
||||
return isShowing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTouchEvent(OnViewClickListener listener) {
|
||||
mParams.mContentView.setOnTouchListener( ( v, event ) -> {
|
||||
final int action = event.getAction();
|
||||
float x = event.getX();
|
||||
float y = event.getY();
|
||||
if ( action == MotionEvent.ACTION_DOWN ) {
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
} else if ( action == MotionEvent.ACTION_MOVE ) {
|
||||
mLayoutParams.x += ( int ) ( x - mLastX ) / 3; // 减小偏移量,防止过度抖动
|
||||
mLayoutParams.y += ( int ) ( y - mLastY ) / 3; // 减小偏移量,防止过度抖动
|
||||
mWindowManager.updateViewLayout( mParams.mContentView, mLayoutParams );
|
||||
} else if ( action == MotionEvent.ACTION_UP ) {
|
||||
int newOffsetX = mLayoutParams.x;
|
||||
int newOffsetY = mLayoutParams.y;
|
||||
// 只要按钮一动位置不是很大,就认为是点击事件
|
||||
if ( Math.abs( mOldOffsetX - newOffsetX ) <= 20
|
||||
&& Math.abs( mOldOffsetY - newOffsetY ) <= 20 ) {
|
||||
listener.onClick( mParams.mContentView );
|
||||
}
|
||||
mOldOffsetX = newOffsetX;
|
||||
mOldOffsetY = newOffsetY;
|
||||
}
|
||||
return true;
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
if(!isShowing){
|
||||
if ( !isShowing ) {
|
||||
isShowing = true;
|
||||
mWindowManager.addView(mParams.mContentView,mLayoutParams);
|
||||
mWindowManager.addView( mParams.mContentView, mLayoutParams );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
if (isShowing && mParams != null) {
|
||||
mWindowManager.removeView(mParams.mContentView);
|
||||
if ( isShowing && mParams != null ) {
|
||||
mWindowManager.removeView( mParams.mContentView );
|
||||
isShowing = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ public class WindowManagerView {
|
||||
return mParams.mContentView.findViewById( id );
|
||||
}
|
||||
|
||||
public void attachTouchEvent( IWindowManagerView.OnViewClickListener listener ) {
|
||||
mManagerView.handleTouchEvent(listener);
|
||||
}
|
||||
|
||||
public void show() {
|
||||
mManagerView.show();
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
@@ -12,8 +10,6 @@ import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.module.common.wm.WindowManagerView;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.R;
|
||||
import com.mogo.module.service.receiver.MogoReceiver;
|
||||
import com.mogo.utils.AppUtils;
|
||||
import com.mogo.utils.LaunchUtils;
|
||||
import com.mogo.utils.ResourcesHelper;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
@@ -96,11 +92,10 @@ class AutoNaviIntentHandler implements IntentHandler {
|
||||
mWindowManagerView = new WindowManagerView.Builder( AbsMogoApplication.getApp() )
|
||||
.contentView( R.layout.module_service_app_entrance )
|
||||
.size( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT )
|
||||
.gravity( Gravity.LEFT | Gravity.TOP )
|
||||
.position( ResourcesHelper.getDimensionPixelSize( context, R.dimen.module_services_app_entrance_x ), ResourcesHelper.getDimensionPixelSize( AbsMogoApplication.getApp(), R.dimen.module_services_app_entrance_y ) )
|
||||
.gravity( Gravity.LEFT|Gravity.TOP )
|
||||
.showInWindowManager();
|
||||
View root = mWindowManagerView.findViewById( R.id.module_service_app_entrance_root );
|
||||
root.setOnClickListener( view -> {
|
||||
mWindowManagerView.attachTouchEvent( view -> {
|
||||
try {
|
||||
if ( DebugConfig.isLauncher() ) {
|
||||
MarkerServiceHandler.getLauncher().backToLauncher( context );
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/module_service_app_entrance_padding"
|
||||
android:layout_width="@dimen/module_service_app_entrance_size"
|
||||
android:layout_height="@dimen/module_service_app_entrance_size"
|
||||
android:gravity="center"
|
||||
android:text="@string/module_service_app_entrance_text"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="@dimen/module_service_app_entrance_textSize" />
|
||||
|
||||
@@ -22,9 +22,12 @@
|
||||
<dimen name="module_service_content_minWidth">64px</dimen>
|
||||
<dimen name="module_service_id_marker_content_paddingRight">6.5px</dimen>
|
||||
<dimen name="module_service_id_marker_content_paddingRight_widthoutCall">10px</dimen>
|
||||
<dimen name="module_service_app_entrance_textSize">19px</dimen>
|
||||
<dimen name="module_service_app_entrance_textSize">20px</dimen>
|
||||
<dimen name="module_service_app_entrance_padding">15px</dimen>
|
||||
<dimen name="module_services_app_entrance_corner_size">2px</dimen>
|
||||
<dimen name="module_services_app_entrance_y">24px</dimen>
|
||||
<dimen name="module_services_app_entrance_x">498px</dimen>
|
||||
<dimen name="module_services_app_entrance_y">112px</dimen>
|
||||
<dimen name="module_services_app_entrance_x">929px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingTop">10px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingLeft">15px</dimen>
|
||||
<dimen name="module_service_app_entrance_size">71px</dimen>
|
||||
</resources>
|
||||
@@ -22,9 +22,12 @@
|
||||
<dimen name="module_service_content_minWidth">64px</dimen>
|
||||
<dimen name="module_service_id_marker_content_paddingRight">6.5px</dimen>
|
||||
<dimen name="module_service_id_marker_content_paddingRight_widthoutCall">10px</dimen>
|
||||
<dimen name="module_service_app_entrance_textSize">19px</dimen>
|
||||
<dimen name="module_service_app_entrance_textSize">20px</dimen>
|
||||
<dimen name="module_service_app_entrance_padding">15px</dimen>
|
||||
<dimen name="module_services_app_entrance_corner_size">2px</dimen>
|
||||
<dimen name="module_services_app_entrance_y">24px</dimen>
|
||||
<dimen name="module_services_app_entrance_x">498px</dimen>
|
||||
<dimen name="module_services_app_entrance_y">112px</dimen>
|
||||
<dimen name="module_services_app_entrance_x">929px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingTop">10px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingLeft">15px</dimen>
|
||||
<dimen name="module_service_app_entrance_size">71px</dimen>
|
||||
</resources>
|
||||
@@ -27,4 +27,7 @@
|
||||
<dimen name="module_services_app_entrance_corner_size">4px</dimen>
|
||||
<dimen name="module_services_app_entrance_y">48px</dimen>
|
||||
<dimen name="module_services_app_entrance_x">1000px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingTop">10px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingLeft">15px</dimen>
|
||||
<dimen name="module_service_app_entrance_size">71px</dimen>
|
||||
</resources>
|
||||
@@ -27,4 +27,7 @@
|
||||
<dimen name="module_services_app_entrance_corner_size">4px</dimen>
|
||||
<dimen name="module_services_app_entrance_y">48px</dimen>
|
||||
<dimen name="module_services_app_entrance_x">1000px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingTop">10px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingLeft">15px</dimen>
|
||||
<dimen name="module_service_app_entrance_size">71px</dimen>
|
||||
</resources>
|
||||
@@ -27,4 +27,7 @@
|
||||
<dimen name="module_services_app_entrance_corner_size">4px</dimen>
|
||||
<dimen name="module_services_app_entrance_y">48px</dimen>
|
||||
<dimen name="module_services_app_entrance_x">1000px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingTop">10px</dimen>
|
||||
<dimen name="module_service_app_entrance_paddingLeft">15px</dimen>
|
||||
<dimen name="module_service_app_entrance_size">71px</dimen>
|
||||
</resources>
|
||||
@@ -1,4 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">mogo-module-service</string>
|
||||
<string name="module_service_app_entrance_text">切换辅助驾驶模式</string>
|
||||
<string name="module_service_app_entrance_text">辅助\n驾驶</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user