Skip to content

Commit de60b4a

Browse files
committed
新增 getWindowViewWidth 方法来代替 getWindowContentWidth 方法
新增 getWindowViewHeight 方法来代替 getWindowContentHeight 方法
1 parent e8174e3 commit de60b4a

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ easyWindow.setWindowParams(@NonNull WindowManager.LayoutParams params);
325325
// 重新设置 WindowManager 对象
326326
easyWindow.setWindowManager(@NonNull WindowManager windowManager);
327327

328-
// 获取当前窗口内容宽度
329-
easyWindow.getWindowContentWidth();
330-
// 获取当前窗口内容高度
331-
easyWindow.getWindowContentHeight();
328+
// 获取当前窗口视图宽度
329+
easyWindow.getWindowViewWidth();
330+
// 获取当前窗口视图高度
331+
easyWindow.getWindowViewHeight();
332332

333333
// 设置可见性状态给 View
334334
easyWindow.setVisibilityByView(@IdRes int viewId, int visibility);

app/src/main/java/com/hjq/window/demo/SemiStealthWindow.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ private void hideHalfView(int gravity) {
9898
return;
9999
}
100100

101-
int viewWidth = getWindowContentWidth();
102-
int viewHeight = getWindowContentHeight();
101+
int viewWidth = getWindowViewWidth();
102+
int viewHeight = getWindowViewHeight();
103103

104104
// 创建一个矩形来定义裁剪区域
105105
Rect clipBounds = new Rect();
@@ -110,7 +110,7 @@ private void hideHalfView(int gravity) {
110110
WindowManager.LayoutParams windowParams = getWindowParams();
111111
windowDraggableRule.updateLocation(windowParams.x - viewWidth / 2f, windowParams.y, true);
112112
} else {
113-
int offSet = getWindowContentWidth() / 2; //用小球来做偏移
113+
int offSet = getWindowViewWidth() / 2; //用小球来做偏移
114114
clipBounds.set(offSet, 0, viewWidth, viewHeight);
115115
// 设置画板偏移
116116
windowRootLayout.setTranslationX(-offSet);
@@ -204,7 +204,7 @@ private boolean isTopShow() {
204204
if (isLeftShow()) {
205205
return windowParams.x > windowParams.y;
206206
} else {
207-
return getScreenWidth() - windowParams.x - getWindowContentWidth() > windowParams.y;
207+
return getScreenWidth() - windowParams.x - getWindowViewWidth() > windowParams.y;
208208
}
209209
}
210210

@@ -222,7 +222,7 @@ private int getScreenWidth() {
222222
* 悬浮球是否靠左显示
223223
*/
224224
private boolean isLeftShow(){
225-
return (getWindowParams().x + getWindowContentWidth() / 2f) < getScreenWidth() / 2f;
225+
return (getWindowParams().x + getWindowViewWidth() / 2f) < getScreenWidth() / 2f;
226226
}
227227

228228
/** {@link OnWindowDraggingListener} */

library/src/main/java/com/hjq/window/EasyWindow.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,16 @@ public View getContentView() {
12581258
}
12591259

12601260
/**
1261-
* 获取当前窗口内容宽度
1261+
* @deprecated 该 API 已经过时,随时会被删除,请尽早迁移到 {@link #getWindowTag()}
12621262
*/
12631263
public int getWindowContentWidth() {
1264+
return getWindowViewWidth();
1265+
}
1266+
1267+
/**
1268+
* 获取当前窗口视图的宽度
1269+
*/
1270+
public int getWindowViewWidth() {
12641271
ViewGroup windowRootLayout = getRootLayout();
12651272
if (windowRootLayout == null) {
12661273
return 0;
@@ -1269,9 +1276,16 @@ public int getWindowContentWidth() {
12691276
}
12701277

12711278
/**
1272-
* 获取当前窗口内容高度
1279+
* @deprecated 该 API 已经过时,随时会被删除,请尽早迁移到 {@link #getWindowTag()}
12731280
*/
12741281
public int getWindowContentHeight() {
1282+
return getWindowViewHeight();
1283+
}
1284+
1285+
/**
1286+
* 获取当前窗口视图的高度
1287+
*/
1288+
public int getWindowViewHeight() {
12751289
ViewGroup windowRootLayout = getRootLayout();
12761290
if (windowRootLayout == null) {
12771291
return 0;

library/src/main/java/com/hjq/window/draggable/AbstractWindowDraggableRule.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,23 @@ public int getWindowHeight() {
229229
}
230230

231231
/**
232-
* 获取当前窗口内容宽度
232+
* 获取当前窗口视图的宽度
233233
*/
234-
public int getWindowContentWidth() {
234+
public int getWindowViewWidth() {
235235
if (mEasyWindow == null) {
236236
return 0;
237237
}
238-
return mEasyWindow.getWindowContentWidth();
238+
return mEasyWindow.getWindowViewWidth();
239239
}
240240

241241
/**
242-
* 获取当前窗口内容高度
242+
* 获取当前窗口视图的高度
243243
*/
244-
public int getWindowContentHeight() {
244+
public int getWindowViewHeight() {
245245
if (mEasyWindow == null) {
246246
return 0;
247247
}
248-
return mEasyWindow.getWindowContentHeight();
248+
return mEasyWindow.getWindowViewHeight();
249249
}
250250

251251
/**
@@ -499,8 +499,8 @@ public void updateLocation(int x, int y, boolean allowMoveToScreenNotch) {
499499
return;
500500
}
501501

502-
int viewWidth = getWindowContentWidth();
503-
int viewHeight = getWindowContentHeight();
502+
int viewWidth = getWindowViewWidth();
503+
int viewHeight = getWindowViewHeight();
504504

505505
int windowWidth = getWindowWidth();
506506
int windowHeight = getWindowHeight();

library/src/main/java/com/hjq/window/draggable/SpringBackWindowDraggableRule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void dispatchSpringBackViewToScreenEdge(float rawX, float rawY) {
139139
} else {
140140
// 回弹到屏幕右边(注意减去 View 宽度,因为 View 坐标系是从屏幕左上角开始算的)
141141
// 如果在最右边向右移动就会产生负数,这里需要处理掉,因为坐标没有负数这一说
142-
endX = Math.max((float) screenWidth - getWindowContentWidth(), 0);
142+
endX = Math.max((float) screenWidth - getWindowViewWidth(), 0);
143143
}
144144
float y = rawMoveY - mViewDownY;
145145
if (!equalsWithRelativeTolerance(startX, endX)) {
@@ -160,7 +160,7 @@ public void dispatchSpringBackViewToScreenEdge(float rawX, float rawY) {
160160
} else {
161161
// 回弹到屏幕底部(注意减去 View 高度,因为 View 坐标系是从屏幕左上角开始算的)
162162
// 如果在最底部向下移动就会产生负数,这里需要处理掉,因为坐标没有负数这一说
163-
endY = Math.max((float) screenHeight - getWindowContentHeight(), 0);
163+
endY = Math.max((float) screenHeight - getWindowViewHeight(), 0);
164164
}
165165
if (!equalsWithRelativeTolerance(startY, endY)) {
166166
// 从移动的点回弹到边界上

0 commit comments

Comments
 (0)