添加无优先级悬浮窗接口
This commit is contained in:
@@ -14,31 +14,36 @@ import com.mogo.service.windowview.IMogoWindowManager;
|
||||
* <p>
|
||||
* 根据优先级控制显示 window view.
|
||||
*/
|
||||
@Route( path = MogoServicePaths.PATH_WINDOW_MANAGER )
|
||||
@Route(path = MogoServicePaths.PATH_WINDOW_MANAGER)
|
||||
public class MogoWindowManager implements IMogoWindowManager {
|
||||
|
||||
@Override
|
||||
public void addView( View view, int x, int y, boolean movable ) {
|
||||
WindowViewHandler.addView( view, x, y, movable );
|
||||
public void addView(View view, int x, int y, boolean movable) {
|
||||
WindowViewHandler.addView(view, x, y, movable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView( int priority, View view, int x, int y, boolean movable ) {
|
||||
WindowViewHandler.addView( view, priority, x, y, movable );
|
||||
public void addView(View view, FrameLayout.LayoutParams params, boolean movable) {
|
||||
WindowViewHandler.addView(view, params, movable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView( int priority, View view, FrameLayout.LayoutParams params, boolean movable ) {
|
||||
WindowViewHandler.addView( view, priority, params, movable );
|
||||
public void addView(int priority, View view, int x, int y, boolean movable) {
|
||||
WindowViewHandler.addView(view, priority, x, y, movable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeView( View view ) {
|
||||
WindowViewHandler.removeView( view );
|
||||
public void addView(int priority, View view, FrameLayout.LayoutParams params, boolean movable) {
|
||||
WindowViewHandler.addView(view, priority, params, movable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
public void removeView(View view) {
|
||||
WindowViewHandler.removeView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class WindowViewHandler {
|
||||
|
||||
public static FrameLayout sFloatingLayout = null;
|
||||
|
||||
public static void init( FrameLayout frameLayout ) {
|
||||
public static void init(FrameLayout frameLayout) {
|
||||
sFloatingLayout = frameLayout;
|
||||
}
|
||||
|
||||
@@ -49,20 +49,39 @@ public class WindowViewHandler {
|
||||
* @param y
|
||||
* @param movable
|
||||
*/
|
||||
public static void addView( View view, int x, int y, boolean movable ) {
|
||||
if ( view == null ) {
|
||||
public static void addView(View view, int x, int y, boolean movable) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sFloatingLayout == null ) {
|
||||
Logger.e( TAG, "no floating frame. " );
|
||||
if (sFloatingLayout == null) {
|
||||
Logger.e(TAG, "no floating frame. ");
|
||||
return;
|
||||
}
|
||||
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT );
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.leftMargin = x;
|
||||
params.topMargin = y;
|
||||
sFloatingLayout.addView( view, params );
|
||||
sFloatingLayout.addView(view, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加view到布局,优先级大的展示
|
||||
*
|
||||
* @param view
|
||||
* @param params
|
||||
* @param movable
|
||||
*/
|
||||
public static void addView(View view, FrameLayout.LayoutParams params, boolean movable) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sFloatingLayout == null) {
|
||||
Logger.e(TAG, "no floating frame. ");
|
||||
return;
|
||||
}
|
||||
sFloatingLayout.addView(view, params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,27 +93,27 @@ public class WindowViewHandler {
|
||||
* @param y
|
||||
* @param movable
|
||||
*/
|
||||
public static void addView( View view, int priority, int x, int y, boolean movable ) {
|
||||
if ( view == null ) {
|
||||
public static void addView(View view, int priority, int x, int y, boolean movable) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sFloatingLayout == null ) {
|
||||
Logger.e( TAG, "no floating frame. " );
|
||||
if (sFloatingLayout == null) {
|
||||
Logger.e(TAG, "no floating frame. ");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sView == view ) {
|
||||
Logger.w( TAG, "改布局已添加且没有移除,不操作" );
|
||||
if (sView == view) {
|
||||
Logger.w(TAG, "改布局已添加且没有移除,不操作");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sView != null ) {
|
||||
if ( priority < sPriority ) {
|
||||
Logger.w( TAG, "过滤低优先级布局" );
|
||||
if (sView != null) {
|
||||
if (priority < sPriority) {
|
||||
Logger.w(TAG, "过滤低优先级布局");
|
||||
return;
|
||||
}
|
||||
sFloatingLayout.removeView( sView );
|
||||
sFloatingLayout.removeView(sView);
|
||||
}
|
||||
sView = view;
|
||||
sMovable = movable;
|
||||
@@ -112,27 +131,27 @@ public class WindowViewHandler {
|
||||
* @param params
|
||||
* @param movable
|
||||
*/
|
||||
public static void addView( View view, int priority, FrameLayout.LayoutParams params, boolean movable ) {
|
||||
if ( view == null ) {
|
||||
public static void addView(View view, int priority, FrameLayout.LayoutParams params, boolean movable) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sFloatingLayout == null ) {
|
||||
Logger.e( TAG, "no floating frame. " );
|
||||
if (sFloatingLayout == null) {
|
||||
Logger.e(TAG, "no floating frame. ");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sView == view ) {
|
||||
Logger.w( TAG, "改布局已添加且没有移除,不操作" );
|
||||
if (sView == view) {
|
||||
Logger.w(TAG, "改布局已添加且没有移除,不操作");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sView != null ) {
|
||||
if ( priority < sPriority ) {
|
||||
Logger.w( TAG, "过滤低优先级布局" );
|
||||
if (sView != null) {
|
||||
if (priority < sPriority) {
|
||||
Logger.w(TAG, "过滤低优先级布局");
|
||||
return;
|
||||
}
|
||||
sFloatingLayout.removeView( sView );
|
||||
sFloatingLayout.removeView(sView);
|
||||
}
|
||||
sView = view;
|
||||
sMovable = movable;
|
||||
@@ -141,15 +160,15 @@ public class WindowViewHandler {
|
||||
addView();
|
||||
}
|
||||
|
||||
public static void removeView( View view ) {
|
||||
if ( sFloatingLayout == null ) {
|
||||
public static void removeView(View view) {
|
||||
if (sFloatingLayout == null) {
|
||||
return;
|
||||
}
|
||||
if ( view == null ) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
sFloatingLayout.removeView( view );
|
||||
if ( sView == view ) {
|
||||
sFloatingLayout.removeView(view);
|
||||
if (sView == view) {
|
||||
sView = null;
|
||||
sPriority = Integer.MIN_VALUE;
|
||||
sMovable = false;
|
||||
@@ -158,28 +177,29 @@ public class WindowViewHandler {
|
||||
}
|
||||
|
||||
private static void addView() {
|
||||
if ( sView == null ) {
|
||||
if (sView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FrameLayout.LayoutParams params = sParams;
|
||||
if ( params == null ) {
|
||||
params = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT );
|
||||
if (params == null) {
|
||||
params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.leftMargin = sX;
|
||||
params.topMargin = sY;
|
||||
}
|
||||
sFloatingLayout.addView( sView, params );
|
||||
sFloatingLayout.addView(sView, params);
|
||||
}
|
||||
|
||||
public static void attachMovementEvent( View view, WindowManager.LayoutParams params ) {
|
||||
if ( view == null ) {
|
||||
public static void attachMovementEvent(View view, WindowManager.LayoutParams params) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
view.setOnTouchListener( ( v, event ) -> {
|
||||
view.setOnTouchListener((v, event) -> {
|
||||
DispatchTouchEventWrapper.getInstance()
|
||||
.attach( view, params )
|
||||
.handle( event );
|
||||
.attach(view, params)
|
||||
.handle(event);
|
||||
return false;
|
||||
} );
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,17 @@ public interface IMogoWindowManager extends IProvider {
|
||||
* @param y 左上角y坐标
|
||||
* @param movable 是否可移动(无效)
|
||||
*/
|
||||
void addView( View view, int x, int y, boolean movable );
|
||||
void addView(View view, int x, int y, boolean movable);
|
||||
|
||||
|
||||
/**
|
||||
* 向window中添加指定的布局,不考虑优先级
|
||||
*
|
||||
* @param view 添加的实例
|
||||
* @param params 布局参数
|
||||
* @param movable 是否可移动(无效)
|
||||
*/
|
||||
void addView(View view, FrameLayout.LayoutParams params, boolean movable);
|
||||
|
||||
/**
|
||||
* 向window中添加指定的布局,优先级大的展示
|
||||
@@ -33,7 +43,7 @@ public interface IMogoWindowManager extends IProvider {
|
||||
* @param y 左上角y坐标
|
||||
* @param movable 是否可移动(无效)
|
||||
*/
|
||||
void addView( int priority, View view, int x, int y, boolean movable );
|
||||
void addView(int priority, View view, int x, int y, boolean movable);
|
||||
|
||||
/**
|
||||
* 向window中添加指定的布局,优先级大的展示
|
||||
@@ -43,12 +53,12 @@ public interface IMogoWindowManager extends IProvider {
|
||||
* @param params 布局参数
|
||||
* @param movable 是否可移动(无效)
|
||||
*/
|
||||
void addView( int priority, View view, FrameLayout.LayoutParams params, boolean movable );
|
||||
void addView(int priority, View view, FrameLayout.LayoutParams params, boolean movable);
|
||||
|
||||
/**
|
||||
* 移除对应的 view
|
||||
*
|
||||
* @param view
|
||||
*/
|
||||
void removeView( View view );
|
||||
void removeView(View view);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user