Skip to content

Commit

Permalink
0.0.50.beta20 pre
Browse files Browse the repository at this point in the history
- BottomDialog 提供了对外暴露的 boxBody(对话框内容布局外层)实例;
- WindowUtil 提供了额外自定义WindowManager.LayoutParams的接口:

```java
WindowUtil.windowSettings = new WindowUtil.WindowSettings() {
    @OverRide
    public WindowManager.LayoutParams overrideWindowLayoutParamsInterface(Context context, View dialogView, WindowManager.LayoutParams originWindowLayoutParams) {
        //处理 originWindowLayoutParams...
        return originWindowLayoutParams;
    }
};
```

- 修复Window模式下,多层Dialog触摸事件逐级向下层传递的问题;
  • Loading branch information
kongzue committed Sep 9, 2024
1 parent f4f6774 commit 2f658f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
Expand Down Expand Up @@ -1105,4 +1106,15 @@ protected static boolean isActivityDestroyed(Activity activity) {
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && activity.isDestroyed())
|| (activity instanceof LifecycleOwner && ((LifecycleOwner) activity).getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED);
}

public boolean dispatchTouchEvent(MotionEvent event) {
if (getDialogView()==null){
if (ownActivity!=null && ownActivity.get()!=null){
return ownActivity.get().dispatchTouchEvent(event);
}else{
return false;
}
}
return getDialogView().dispatchTouchEvent(event);
}
}
14 changes: 12 additions & 2 deletions DialogX/src/main/java/com/kongzue/dialogx/util/WindowUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@
public class WindowUtil {

public abstract static class WindowSettings {

//自定义window参数
public abstract WindowManager.LayoutParams overrideWindowLayoutParamsInterface(Context context, View dialogView, WindowManager.LayoutParams originWindowLayoutParams);

//自定义根布局
public abstract ViewGroup overrideRootView(Context context);
}

//自定义window设置
public static WindowSettings windowSettings;

public static void show(Activity activity, View dialogView, boolean touchEnable) {
Expand Down Expand Up @@ -63,7 +69,11 @@ private static void showNow(Activity activity, View dialogView, boolean touchEna
activity.startActivity(intent);
return;
}
FrameLayout rootLayout = new FrameLayout(activity);
ViewGroup customRootView = null;
if (windowSettings != null) {
customRootView = windowSettings.overrideRootView(activity);
}
ViewGroup rootLayout = customRootView == null ? new FrameLayout(activity) : customRootView;
if (dialogView.getParent() != null) {
((ViewGroup) dialogView.getParent()).removeView(dialogView);
}
Expand Down Expand Up @@ -97,7 +107,7 @@ public boolean onTouch(View v, MotionEvent event) {
if (baseDialog.getDialogView() == null) {
return false;
}
return baseDialog.getOwnActivity().dispatchTouchEvent(event);
return baseDialog.dispatchTouchEvent(event);
}
}
return activity.dispatchTouchEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
Expand All @@ -36,6 +37,7 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -1562,4 +1564,10 @@ protected void onDestroy() {
super.onDestroy();
log("MainActivity#onDestroy");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
super.onCreate(savedInstanceState);
}
}

0 comments on commit 2f658f4

Please sign in to comment.