10 changed files with 587 additions and 1 deletions
@ -0,0 +1,20 @@ |
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:width="100dp" |
|||
android:height="100dp" |
|||
android:viewportWidth="100" |
|||
android:viewportHeight="100"> |
|||
<path |
|||
android:pathData="M50,50m-50,0a50,50 0,1 1,100 0a50,50 0,1 1,-100 0" |
|||
android:strokeAlpha="0.6042626" |
|||
android:strokeWidth="1" |
|||
android:fillColor="#000000" |
|||
android:fillType="evenOdd" |
|||
android:strokeColor="#00000000" |
|||
android:fillAlpha="0.6042626"/> |
|||
<path |
|||
android:pathData="M28.17,39.17L52.42,61.31L52.42,68.41C52.42,71.35 48.53,72.78 46.34,70.64L34.42,60.83L28.21,60.83C25.52,60.83 23.33,58.65 23.33,55.96L23.33,44.04C23.33,41.36 25.49,39.19 28.17,39.17ZM33.69,30.69L33.91,30.87L72.25,65.87C73.61,67.11 73.7,69.22 72.46,70.58C71.29,71.87 69.33,72.02 67.97,70.98L67.75,70.79L29.42,35.79C28.06,34.55 27.96,32.45 29.21,31.09C30.38,29.8 32.34,29.64 33.69,30.69ZM65.13,29.53C65.14,29.54 65.15,29.54 65.16,29.55C65.52,29.76 65.82,29.94 66.07,30.11C71.96,33.99 75.99,40.15 76.67,47.21L76.67,51.48C76.3,55.3 74.96,58.85 72.87,61.92L69.02,58.41C70.64,55.68 71.53,52.58 71.53,49.35C71.53,43.34 68.44,37.77 63.34,34.28C63.14,34.14 62.89,33.99 62.6,33.81C61.46,33.13 61.06,31.66 61.71,30.5C62.39,29.29 63.92,28.86 65.13,29.53ZM61.52,37.76C61.58,37.8 61.63,37.84 61.68,37.88C62.05,38.17 62.35,38.44 62.59,38.67C65.36,41.44 66.98,45.23 66.97,49.24C66.97,51.38 66.52,53.46 65.67,55.35L61.66,51.69C61.86,50.9 61.97,50.08 61.97,49.24C61.97,46.88 61.13,44.63 59.66,42.87C59.45,42.61 59.12,42.3 58.68,41.92C57.65,41.04 57.45,39.53 58.2,38.41C58.94,37.31 60.43,37.02 61.52,37.76ZM52.42,31.59L52.42,43.26L41.53,33.32L46.35,29.36C48.53,27.22 52.42,28.65 52.42,31.59Z" |
|||
android:strokeWidth="1" |
|||
android:fillColor="#E2E0DE" |
|||
android:fillType="nonZero" |
|||
android:strokeColor="#00000000"/> |
|||
</vector> |
|||
@ -0,0 +1,13 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content"> |
|||
|
|||
<ImageView |
|||
android:id="@+id/iv_mute" |
|||
android:layout_width="40dp" |
|||
android:layout_height="40dp" |
|||
android:layout_marginEnd="4dp" |
|||
android:layout_marginTop="120dp" |
|||
android:src="@drawable/icon_mute" /> |
|||
</FrameLayout> |
|||
@ -0,0 +1,27 @@ |
|||
package com.lib.common.base.window; |
|||
|
|||
/** |
|||
* =================================================== |
|||
* Created by MackWu on 2021/7/27 14:55 |
|||
* <a href="mailto:wumengjiao828@163.com">Contact me</a> |
|||
* <a href="https://github.com/mackwu828">Follow me</a> |
|||
* =================================================== |
|||
*/ |
|||
public enum DisplayType { |
|||
|
|||
/** |
|||
* 显示和隐藏 |
|||
*/ |
|||
SHOW_AND_HIDE, |
|||
|
|||
/** |
|||
* 1px和全屏 |
|||
*/ |
|||
@Deprecated |
|||
ONE_PX_AND_MATCH_PARENT, |
|||
|
|||
/** |
|||
* 移到屏幕外 |
|||
*/ |
|||
OUT_OF_SCREEN, |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
package com.lib.common.base.window; |
|||
|
|||
/** |
|||
* =================================================== |
|||
* Created by MackWu on 2020/8/3 19:24 |
|||
* <a href="mailto:wumengjiao828@163.com">Contact me</a> |
|||
* <a href="https://github.com/mackwu828">Follow me</a> |
|||
* =================================================== |
|||
*/ |
|||
public interface IWindow { |
|||
|
|||
/** |
|||
* 获取布局id |
|||
*/ |
|||
int getLayoutId(); |
|||
|
|||
/** |
|||
* 类型 |
|||
* See {@link android.view.WindowManager.LayoutParams} |
|||
*/ |
|||
int getType(); |
|||
|
|||
/** |
|||
* 位置 |
|||
*/ |
|||
int getGravity(); |
|||
|
|||
/** |
|||
* flag |
|||
* |
|||
* @param isFocusable 是否有焦点 |
|||
*/ |
|||
int getFlag(boolean isFocusable); |
|||
|
|||
/** |
|||
* 宽 |
|||
*/ |
|||
int getWidth(); |
|||
|
|||
/** |
|||
* 高 |
|||
*/ |
|||
int getHeight(); |
|||
|
|||
/** |
|||
* 在屏幕外时的X坐标 |
|||
*/ |
|||
int getOutOfScreenX(); |
|||
|
|||
/** |
|||
* 在屏幕外时的Y坐标 |
|||
*/ |
|||
int getOutOfScreenY(); |
|||
|
|||
/** |
|||
* 显示类型。 |
|||
*/ |
|||
DisplayType getDisplayType(); |
|||
|
|||
/** |
|||
* 显示弹窗。 |
|||
*/ |
|||
void show(); |
|||
|
|||
/** |
|||
* 隐藏弹窗。 |
|||
*/ |
|||
void hide(); |
|||
|
|||
/** |
|||
* 是否显示 |
|||
*/ |
|||
boolean isShown(); |
|||
} |
|||
@ -0,0 +1,161 @@ |
|||
package com.lib.common.base.window.base; |
|||
|
|||
import android.content.Context; |
|||
import android.graphics.PixelFormat; |
|||
import android.os.Handler; |
|||
import android.os.Looper; |
|||
import android.view.Gravity; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.WindowManager; |
|||
|
|||
import com.lib.common.base.window.DisplayType; |
|||
import com.lib.common.base.window.IWindow; |
|||
import com.android.systemui.SystemUIApplication; |
|||
|
|||
/** |
|||
* =================================================== |
|||
* Created by MackWu on 2020/8/3 19:23 |
|||
* <a href="mailto:wumengjiao828@163.com">Contact me</a> |
|||
* <a href="https://github.com/mackwu828">Follow me</a> |
|||
* =================================================== |
|||
*/ |
|||
public abstract class BaseWindow implements IWindow { |
|||
|
|||
private boolean inited; |
|||
protected Context context; |
|||
protected WindowManager windowManager; |
|||
protected WindowManager.LayoutParams windowLayoutParams; |
|||
protected View view; |
|||
protected boolean isShown; |
|||
protected final Handler handler = new Handler(Looper.getMainLooper()); |
|||
|
|||
public BaseWindow() { |
|||
this(SystemUIApplication.getInstance()); |
|||
} |
|||
|
|||
public BaseWindow(Context context){ |
|||
this.context = context; |
|||
} |
|||
|
|||
public BaseWindow init(){ |
|||
if(!inited){ |
|||
inited=true; |
|||
this.windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
|||
this.windowLayoutParams = new WindowManager.LayoutParams(); |
|||
initView(); |
|||
initWindow(); |
|||
} |
|||
return this; |
|||
} |
|||
|
|||
protected abstract void onConfig(WindowManager.LayoutParams windowLayoutParams); |
|||
|
|||
protected void initView() { |
|||
this.view = LayoutInflater.from(context).inflate(getLayoutId(), null); |
|||
} |
|||
|
|||
protected void initWindow() { |
|||
windowLayoutParams.type = getType(); |
|||
windowLayoutParams.format = PixelFormat.TRANSLUCENT; |
|||
windowLayoutParams.gravity = getGravity(); |
|||
windowLayoutParams.flags = getFlag(true); |
|||
windowLayoutParams.width = getWidth(); |
|||
windowLayoutParams.height = getHeight(); |
|||
onConfig(this.windowLayoutParams); |
|||
windowManager.addView(view, windowLayoutParams); |
|||
hide(); |
|||
} |
|||
|
|||
@Override |
|||
public int getType() { |
|||
return WindowManager.LayoutParams.TYPE_APPLICATION; |
|||
} |
|||
|
|||
@Override |
|||
public int getGravity() { |
|||
return Gravity.BOTTOM | Gravity.END; |
|||
} |
|||
|
|||
@Override |
|||
public int getFlag(boolean isFocusable) { |
|||
return isFocusable |
|||
? WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
|||
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | |
|||
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | |
|||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
|||
: WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | |
|||
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | |
|||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
|||
} |
|||
|
|||
@Override |
|||
public int getWidth() { |
|||
return WindowManager.LayoutParams.MATCH_PARENT; |
|||
} |
|||
|
|||
@Override |
|||
public int getHeight() { |
|||
return WindowManager.LayoutParams.MATCH_PARENT; |
|||
} |
|||
|
|||
@Override |
|||
public int getOutOfScreenX() { |
|||
return -2000; |
|||
} |
|||
|
|||
@Override |
|||
public int getOutOfScreenY() { |
|||
return -2000; |
|||
} |
|||
|
|||
@Override |
|||
public DisplayType getDisplayType() { |
|||
return DisplayType.SHOW_AND_HIDE; |
|||
} |
|||
|
|||
@Override |
|||
public void show() { |
|||
isShown = true; |
|||
if (getDisplayType() == DisplayType.SHOW_AND_HIDE) { |
|||
view.setVisibility(View.VISIBLE); |
|||
} |
|||
if (getDisplayType() == DisplayType.OUT_OF_SCREEN) { |
|||
updateWindowPosition(0, 0, true); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void hide() { |
|||
isShown = false; |
|||
if (getDisplayType() == DisplayType.SHOW_AND_HIDE) { |
|||
view.setVisibility(View.GONE); |
|||
} |
|||
if (getDisplayType() == DisplayType.OUT_OF_SCREEN) { |
|||
updateWindowPosition(getOutOfScreenX(), getOutOfScreenY(), false); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public boolean isShown() { |
|||
return isShown; |
|||
} |
|||
|
|||
protected void updateWindowPosition(int x, int y, boolean isFocusable) { |
|||
windowLayoutParams = new WindowManager.LayoutParams(); |
|||
windowLayoutParams.type = getType(); |
|||
windowLayoutParams.format = PixelFormat.TRANSLUCENT; |
|||
windowLayoutParams.gravity = getGravity(); |
|||
windowLayoutParams.flags = getFlag(isFocusable); |
|||
windowLayoutParams.x = x; |
|||
windowLayoutParams.y = y; |
|||
windowLayoutParams.width = getWidth(); |
|||
windowLayoutParams.height = getHeight(); |
|||
windowManager.updateViewLayout(view, windowLayoutParams); |
|||
} |
|||
|
|||
public void remove(){ |
|||
windowManager.removeView(view); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
package com.lib.common.base.window.base; |
|||
|
|||
import android.view.View; |
|||
import android.view.WindowManager; |
|||
|
|||
/** |
|||
*/ |
|||
|
|||
public abstract class FloatView { |
|||
|
|||
abstract void setSize(int width, int height); |
|||
|
|||
abstract void setView(View view); |
|||
|
|||
abstract void setGravity(int gravity, int xOffset, int yOffset); |
|||
|
|||
public abstract FloatView init(); |
|||
|
|||
public abstract FloatView setFlag(int flag); |
|||
|
|||
abstract void dismiss(); |
|||
|
|||
public void updateXY(int x, int y) { |
|||
} |
|||
|
|||
void updateX(int x) { |
|||
} |
|||
|
|||
void updateY(int y) { |
|||
} |
|||
|
|||
public int getX() { |
|||
return 0; |
|||
} |
|||
|
|||
public int getY() { |
|||
return 0; |
|||
} |
|||
|
|||
public void updateViewLayout(WindowManager.LayoutParams windowLayoutParams) { |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,107 @@ |
|||
package com.lib.common.base.window.base; |
|||
|
|||
import android.content.Context; |
|||
import android.graphics.PixelFormat; |
|||
import android.view.View; |
|||
import android.view.WindowManager; |
|||
|
|||
/** |
|||
*/ |
|||
|
|||
public class FloatWindow extends FloatView { |
|||
|
|||
private final Context mContext; |
|||
|
|||
private final WindowManager mWindowManager; |
|||
private final WindowManager.LayoutParams mLayoutParams; |
|||
private View mView; |
|||
private int mX, mY; |
|||
private boolean isRemove = false; |
|||
|
|||
public FloatWindow(Context applicationContext, int windowType) { |
|||
mContext = applicationContext; |
|||
mWindowManager = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE); |
|||
mLayoutParams = new WindowManager.LayoutParams(); |
|||
mLayoutParams.type = windowType; |
|||
mLayoutParams.format = PixelFormat.TRANSLUCENT; |
|||
mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT; |
|||
mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; |
|||
mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | |
|||
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | |
|||
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | |
|||
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
|||
} |
|||
|
|||
@Override |
|||
public void setSize(int width, int height) { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void setView(View view) { |
|||
mView = view; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void setGravity(int gravity, int xOffset, int yOffset) { |
|||
mLayoutParams.gravity = gravity; |
|||
mLayoutParams.x = mX = xOffset; |
|||
mLayoutParams.y = mY = yOffset; |
|||
} |
|||
|
|||
@Override |
|||
public FloatView init() { |
|||
try { |
|||
mWindowManager.addView(mView, mLayoutParams); |
|||
} catch (Exception ignored) { |
|||
} |
|||
return this; |
|||
} |
|||
|
|||
@Override |
|||
public FloatView setFlag(int flag){ |
|||
mLayoutParams.flags = flag; |
|||
return this; |
|||
} |
|||
|
|||
@Override |
|||
public void dismiss() { |
|||
isRemove = true; |
|||
mWindowManager.removeView(mView); |
|||
} |
|||
|
|||
@Override |
|||
public void updateXY(int x, int y) { |
|||
if (isRemove) return; |
|||
mLayoutParams.x = mX = x; |
|||
mLayoutParams.y = mY = y; |
|||
mWindowManager.updateViewLayout(mView, mLayoutParams); |
|||
} |
|||
|
|||
@Override |
|||
void updateX(int x) { |
|||
if (isRemove) return; |
|||
mLayoutParams.x = mX = x; |
|||
mWindowManager.updateViewLayout(mView, mLayoutParams); |
|||
} |
|||
|
|||
@Override |
|||
void updateY(int y) { |
|||
if (isRemove) return; |
|||
mLayoutParams.y = mY = y; |
|||
mWindowManager.updateViewLayout(mView, mLayoutParams); |
|||
} |
|||
|
|||
@Override |
|||
public int getX() { |
|||
return mX; |
|||
} |
|||
|
|||
@Override |
|||
public int getY() { |
|||
return mY; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
package com.zeasn.whaleos.view; |
|||
|
|||
import android.view.Gravity; |
|||
import android.view.WindowManager; |
|||
|
|||
import com.lib.common.base.window.base.BaseWindow; |
|||
import com.android.systemui.R; |
|||
|
|||
public class MutePromptFloatWindow extends BaseWindow { |
|||
|
|||
public MutePromptFloatWindow() { |
|||
super(); |
|||
init(); |
|||
} |
|||
|
|||
@Override |
|||
protected void onConfig(WindowManager.LayoutParams windowLayoutParams) { |
|||
windowLayoutParams.flags = getFlag(false); |
|||
} |
|||
|
|||
@Override |
|||
public int getLayoutId() { |
|||
return R.layout.window_mute_prompt; |
|||
} |
|||
|
|||
@Override |
|||
public int getType() { |
|||
return WindowManager.LayoutParams.TYPE_SEARCH_BAR; |
|||
} |
|||
|
|||
@Override |
|||
public int getGravity() { |
|||
return Gravity.TOP | Gravity.END; |
|||
} |
|||
|
|||
@Override |
|||
public int getWidth() { |
|||
return WindowManager.LayoutParams.WRAP_CONTENT; |
|||
} |
|||
|
|||
@Override |
|||
public int getHeight() { |
|||
return WindowManager.LayoutParams.WRAP_CONTENT; |
|||
} |
|||
|
|||
@Override |
|||
public void show() { |
|||
super.show(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue