|
@@ -60,7 +60,7 @@ import static com.kongzue.dialogx.DialogX.DEBUGMODE;
|
|
* @createTime: 2020/9/22 14:10
|
|
* @createTime: 2020/9/22 14:10
|
|
*/
|
|
*/
|
|
public abstract class BaseDialog implements LifecycleOwner {
|
|
public abstract class BaseDialog implements LifecycleOwner {
|
|
-
|
|
|
|
|
|
+
|
|
private static Thread uiThread;
|
|
private static Thread uiThread;
|
|
private static WeakReference<Activity> activityWeakReference;
|
|
private static WeakReference<Activity> activityWeakReference;
|
|
protected WeakReference<Activity> ownActivity;
|
|
protected WeakReference<Activity> ownActivity;
|
|
@@ -73,13 +73,13 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
private WeakReference<DialogListBuilder> dialogListBuilder;
|
|
private WeakReference<DialogListBuilder> dialogListBuilder;
|
|
protected LifecycleRegistry lifecycle = new LifecycleRegistry(this);
|
|
protected LifecycleRegistry lifecycle = new LifecycleRegistry(this);
|
|
|
|
|
|
- public enum BUTTON_SELECT_RESULT{
|
|
|
|
|
|
+ public enum BUTTON_SELECT_RESULT {
|
|
NONE, //未做出选择
|
|
NONE, //未做出选择
|
|
BUTTON_OK, //选择了确定按钮
|
|
BUTTON_OK, //选择了确定按钮
|
|
BUTTON_CANCEL, //选择了取消按钮
|
|
BUTTON_CANCEL, //选择了取消按钮
|
|
BUTTON_OTHER //选择了其他按钮
|
|
BUTTON_OTHER //选择了其他按钮
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static void init(Context context) {
|
|
public static void init(Context context) {
|
|
if (context == null) {
|
|
if (context == null) {
|
|
context = ActivityLifecycleImpl.getTopActivity();
|
|
context = ActivityLifecycleImpl.getTopActivity();
|
|
@@ -94,7 +94,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static void initActivityContext(Activity activity) {
|
|
private static void initActivityContext(Activity activity) {
|
|
if (ActivityLifecycleImpl.isExemptActivities(activity)) {
|
|
if (ActivityLifecycleImpl.isExemptActivities(activity)) {
|
|
return;
|
|
return;
|
|
@@ -107,19 +107,19 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
error("DialogX.init: 初始化异常,找不到Activity的根布局");
|
|
error("DialogX.init: 初始化异常,找不到Activity的根布局");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static void log(Object o) {
|
|
protected static void log(Object o) {
|
|
if (DEBUGMODE) {
|
|
if (DEBUGMODE) {
|
|
Log.i(">>>", o.toString());
|
|
Log.i(">>>", o.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static void error(Object o) {
|
|
protected static void error(Object o) {
|
|
if (DEBUGMODE) {
|
|
if (DEBUGMODE) {
|
|
Log.e(">>>", o.toString());
|
|
Log.e(">>>", o.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static void onActivityResume(Activity activity) {
|
|
public static void onActivityResume(Activity activity) {
|
|
if (runningDialogList != null) {
|
|
if (runningDialogList != null) {
|
|
CopyOnWriteArrayList<BaseDialog> copyOnWriteList = new CopyOnWriteArrayList<>(runningDialogList);
|
|
CopyOnWriteArrayList<BaseDialog> copyOnWriteList = new CopyOnWriteArrayList<>(runningDialogList);
|
|
@@ -137,15 +137,13 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static void requestDialogFocus() {
|
|
private static void requestDialogFocus() {
|
|
- if (getTopActivity() instanceof Activity) {
|
|
|
|
- onActivityResume((Activity) getTopActivity());
|
|
|
|
- }
|
|
|
|
|
|
+ onActivityResume(getTopActivity());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public abstract void restartDialog();
|
|
public abstract void restartDialog();
|
|
-
|
|
|
|
|
|
+
|
|
protected static void show(final View view) {
|
|
protected static void show(final View view) {
|
|
if (view == null) {
|
|
if (view == null) {
|
|
return;
|
|
return;
|
|
@@ -160,23 +158,22 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
|
|
error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- baseDialog.ownActivity = new WeakReference<>(getTopActivity());
|
|
|
|
baseDialog.dialogView = new WeakReference<>(view);
|
|
baseDialog.dialogView = new WeakReference<>(view);
|
|
-
|
|
|
|
|
|
+
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
publicWindowInsets(baseDialog.getRootFrameLayout().getRootWindowInsets());
|
|
publicWindowInsets(baseDialog.getRootFrameLayout().getRootWindowInsets());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
log(baseDialog.dialogKey() + ".show");
|
|
log(baseDialog.dialogKey() + ".show");
|
|
-
|
|
|
|
|
|
+
|
|
addDialogToRunningList(baseDialog);
|
|
addDialogToRunningList(baseDialog);
|
|
switch (baseDialog.dialogImplMode) {
|
|
switch (baseDialog.dialogImplMode) {
|
|
case WINDOW:
|
|
case WINDOW:
|
|
- WindowUtil.show(getTopActivity(), view, !(baseDialog instanceof NoTouchInterface));
|
|
|
|
|
|
+ WindowUtil.show(baseDialog.getOwnActivity(), view, !(baseDialog instanceof NoTouchInterface));
|
|
break;
|
|
break;
|
|
case DIALOG_FRAGMENT:
|
|
case DIALOG_FRAGMENT:
|
|
DialogFragmentImpl dialogFragment = new DialogFragmentImpl(baseDialog, view);
|
|
DialogFragmentImpl dialogFragment = new DialogFragmentImpl(baseDialog, view);
|
|
- dialogFragment.show(getSupportFragmentManager(getTopActivity()), "DialogX");
|
|
|
|
|
|
+ dialogFragment.show(getSupportFragmentManager(baseDialog.getOwnActivity()), "DialogX");
|
|
baseDialog.ownDialogFragmentImpl = new WeakReference<>(dialogFragment);
|
|
baseDialog.ownDialogFragmentImpl = new WeakReference<>(dialogFragment);
|
|
break;
|
|
break;
|
|
case FLOATING_ACTIVITY:
|
|
case FLOATING_ACTIVITY:
|
|
@@ -187,6 +184,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
@Override
|
|
@Override
|
|
public void run(Activity activity) {
|
|
public void run(Activity activity) {
|
|
baseDialog.floatingWindowActivity = new WeakReference<>((DialogXFloatingWindowActivity) activity);
|
|
baseDialog.floatingWindowActivity = new WeakReference<>((DialogXFloatingWindowActivity) activity);
|
|
|
|
+ baseDialog.floatingWindowActivity.get().setFromActivity(baseDialog.getOwnActivity());
|
|
final FrameLayout activityRootView = (FrameLayout) activity.getWindow().getDecorView();
|
|
final FrameLayout activityRootView = (FrameLayout) activity.getWindow().getDecorView();
|
|
if (activityRootView == null) {
|
|
if (activityRootView == null) {
|
|
return;
|
|
return;
|
|
@@ -207,21 +205,21 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
DialogXFloatingWindowActivity dialogXFloatingWindowActivity = DialogXFloatingWindowActivity.getDialogXFloatingWindowActivity();
|
|
DialogXFloatingWindowActivity dialogXFloatingWindowActivity = DialogXFloatingWindowActivity.getDialogXFloatingWindowActivity();
|
|
- if (dialogXFloatingWindowActivity != null && dialogXFloatingWindowActivity.isSameFrom(getTopActivity().hashCode())) {
|
|
|
|
|
|
+ if (dialogXFloatingWindowActivity != null && dialogXFloatingWindowActivity.isSameFrom(baseDialog.getOwnActivity().hashCode())) {
|
|
dialogXFloatingWindowActivity.showDialogX(baseDialog.dialogKey());
|
|
dialogXFloatingWindowActivity.showDialogX(baseDialog.dialogKey());
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
Intent intent = new Intent(getContext(), DialogXFloatingWindowActivity.class);
|
|
Intent intent = new Intent(getContext(), DialogXFloatingWindowActivity.class);
|
|
- if (getTopActivity() == null) {
|
|
|
|
|
|
+ if (baseDialog.getOwnActivity() == null) {
|
|
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
|
|
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
|
|
}
|
|
}
|
|
intent.putExtra("dialogXKey", baseDialog.dialogKey());
|
|
intent.putExtra("dialogXKey", baseDialog.dialogKey());
|
|
- intent.putExtra("fromActivityUiStatus", getTopActivity() == null ? 0 : getTopActivity().getWindow().getDecorView().getSystemUiVisibility());
|
|
|
|
|
|
+ intent.putExtra("fromActivityUiStatus", baseDialog.getOwnActivity() == null ? 0 : baseDialog.getOwnActivity().getWindow().getDecorView().getSystemUiVisibility());
|
|
intent.putExtra("from", getContext().hashCode());
|
|
intent.putExtra("from", getContext().hashCode());
|
|
getContext().startActivity(intent);
|
|
getContext().startActivity(intent);
|
|
int version = Integer.valueOf(Build.VERSION.SDK_INT);
|
|
int version = Integer.valueOf(Build.VERSION.SDK_INT);
|
|
- if (version > 5 && getTopActivity() != null) {
|
|
|
|
- getTopActivity().overridePendingTransition(0, 0);
|
|
|
|
|
|
+ if (version > 5 && baseDialog.getOwnActivity() != null) {
|
|
|
|
+ baseDialog.getOwnActivity().overridePendingTransition(0, 0);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
@@ -245,20 +243,20 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static FragmentManager getSupportFragmentManager(Activity activity) {
|
|
private static FragmentManager getSupportFragmentManager(Activity activity) {
|
|
return (activity instanceof AppCompatActivity) ? ((AppCompatActivity) activity).getSupportFragmentManager() : null;
|
|
return (activity instanceof AppCompatActivity) ? ((AppCompatActivity) activity).getSupportFragmentManager() : null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static Map<String, ActivityRunnable> waitRunDialogX;
|
|
private static Map<String, ActivityRunnable> waitRunDialogX;
|
|
-
|
|
|
|
|
|
+
|
|
public static ActivityRunnable getActivityRunnable(String dialogXKey) {
|
|
public static ActivityRunnable getActivityRunnable(String dialogXKey) {
|
|
if (dialogXKey == null) {
|
|
if (dialogXKey == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
return waitRunDialogX.get(dialogXKey);
|
|
return waitRunDialogX.get(dialogXKey);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static void show(final Activity activity, final View view) {
|
|
protected static void show(final Activity activity, final View view) {
|
|
if (activity == null || view == null) {
|
|
if (activity == null || view == null) {
|
|
return;
|
|
return;
|
|
@@ -281,14 +279,14 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
baseDialog.ownActivity = new WeakReference<>(activity);
|
|
baseDialog.ownActivity = new WeakReference<>(activity);
|
|
baseDialog.dialogView = new WeakReference<>(view);
|
|
baseDialog.dialogView = new WeakReference<>(view);
|
|
-
|
|
|
|
|
|
+
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
publicWindowInsets(baseDialog.getRootFrameLayout().getRootWindowInsets());
|
|
publicWindowInsets(baseDialog.getRootFrameLayout().getRootWindowInsets());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
log(baseDialog + ".show");
|
|
log(baseDialog + ".show");
|
|
addDialogToRunningList(baseDialog);
|
|
addDialogToRunningList(baseDialog);
|
|
-
|
|
|
|
|
|
+
|
|
switch (baseDialog.dialogImplMode) {
|
|
switch (baseDialog.dialogImplMode) {
|
|
case WINDOW:
|
|
case WINDOW:
|
|
WindowUtil.show(activity, view, !(baseDialog instanceof NoTouchInterface));
|
|
WindowUtil.show(activity, view, !(baseDialog instanceof NoTouchInterface));
|
|
@@ -306,6 +304,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
@Override
|
|
@Override
|
|
public void run(Activity activity) {
|
|
public void run(Activity activity) {
|
|
baseDialog.floatingWindowActivity = new WeakReference<>((DialogXFloatingWindowActivity) activity);
|
|
baseDialog.floatingWindowActivity = new WeakReference<>((DialogXFloatingWindowActivity) activity);
|
|
|
|
+ baseDialog.floatingWindowActivity.get().setFromActivity(baseDialog.getOwnActivity());
|
|
final FrameLayout activityRootView = (FrameLayout) activity.getWindow().getDecorView();
|
|
final FrameLayout activityRootView = (FrameLayout) activity.getWindow().getDecorView();
|
|
if (activityRootView == null) {
|
|
if (activityRootView == null) {
|
|
return;
|
|
return;
|
|
@@ -362,7 +361,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static void dismiss(final View dialogView) {
|
|
protected static void dismiss(final View dialogView) {
|
|
if (dialogView == null) {
|
|
if (dialogView == null) {
|
|
return;
|
|
return;
|
|
@@ -373,7 +372,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
if (baseDialog.dialogView != null) {
|
|
if (baseDialog.dialogView != null) {
|
|
baseDialog.dialogView.clear();
|
|
baseDialog.dialogView.clear();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
switch (baseDialog.dialogImplMode) {
|
|
switch (baseDialog.dialogImplMode) {
|
|
case WINDOW:
|
|
case WINDOW:
|
|
WindowUtil.dismiss(dialogView);
|
|
WindowUtil.dismiss(dialogView);
|
|
@@ -414,20 +413,20 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
baseDialog.getDialogListBuilder().showNext();
|
|
baseDialog.getDialogListBuilder().showNext();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static void addDialogToRunningList(BaseDialog baseDialog) {
|
|
private static void addDialogToRunningList(BaseDialog baseDialog) {
|
|
if (runningDialogList == null) {
|
|
if (runningDialogList == null) {
|
|
runningDialogList = new CopyOnWriteArrayList<>();
|
|
runningDialogList = new CopyOnWriteArrayList<>();
|
|
}
|
|
}
|
|
runningDialogList.add(baseDialog);
|
|
runningDialogList.add(baseDialog);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private static void removeDialogToRunningList(BaseDialog baseDialog) {
|
|
private static void removeDialogToRunningList(BaseDialog baseDialog) {
|
|
if (runningDialogList != null) {
|
|
if (runningDialogList != null) {
|
|
runningDialogList.remove(baseDialog);
|
|
runningDialogList.remove(baseDialog);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static Activity getTopActivity() {
|
|
public static Activity getTopActivity() {
|
|
if (activityWeakReference == null) {
|
|
if (activityWeakReference == null) {
|
|
init(null);
|
|
init(null);
|
|
@@ -438,7 +437,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
return activityWeakReference.get();
|
|
return activityWeakReference.get();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static Context getContext() {
|
|
public static Context getContext() {
|
|
Activity activity = getTopActivity();
|
|
Activity activity = getTopActivity();
|
|
if (activity == null) {
|
|
if (activity == null) {
|
|
@@ -451,11 +450,11 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
return activity;
|
|
return activity;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static Context getApplicationContext() {
|
|
public static Context getApplicationContext() {
|
|
return ActivityLifecycleImpl.getApplicationContext();
|
|
return ActivityLifecycleImpl.getApplicationContext();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 自动执行,不建议自行调用此方法
|
|
* 自动执行,不建议自行调用此方法
|
|
*
|
|
*
|
|
@@ -468,9 +467,9 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
activityWeakReference = null;
|
|
activityWeakReference = null;
|
|
System.gc();
|
|
System.gc();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected abstract void shutdown();
|
|
protected abstract void shutdown();
|
|
-
|
|
|
|
|
|
+
|
|
protected boolean cancelable = true;
|
|
protected boolean cancelable = true;
|
|
protected boolean isShow;
|
|
protected boolean isShow;
|
|
protected DialogXStyle style;
|
|
protected DialogXStyle style;
|
|
@@ -484,7 +483,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
protected int minWidth;
|
|
protected int minWidth;
|
|
protected int minHeight;
|
|
protected int minHeight;
|
|
protected int[] screenPaddings = new int[4];
|
|
protected int[] screenPaddings = new int[4];
|
|
-
|
|
|
|
|
|
+
|
|
public BaseDialog() {
|
|
public BaseDialog() {
|
|
cancelable = DialogX.cancelable;
|
|
cancelable = DialogX.cancelable;
|
|
style = DialogX.globalStyle;
|
|
style = DialogX.globalStyle;
|
|
@@ -493,9 +492,9 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
exitAnimDuration = DialogX.exitAnimDuration;
|
|
exitAnimDuration = DialogX.exitAnimDuration;
|
|
autoShowInputKeyboard = DialogX.autoShowInputKeyboard;
|
|
autoShowInputKeyboard = DialogX.autoShowInputKeyboard;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public abstract boolean isCancelable();
|
|
public abstract boolean isCancelable();
|
|
-
|
|
|
|
|
|
+
|
|
public View createView(int layoutId) {
|
|
public View createView(int layoutId) {
|
|
if (getApplicationContext() == null) {
|
|
if (getApplicationContext() == null) {
|
|
error("DialogX 未初始化(E3)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
error("DialogX 未初始化(E3)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
@@ -503,19 +502,19 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
return LayoutInflater.from(getApplicationContext()).inflate(layoutId, null);
|
|
return LayoutInflater.from(getApplicationContext()).inflate(layoutId, null);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public boolean isShow() {
|
|
public boolean isShow() {
|
|
return isShow;
|
|
return isShow;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public DialogXStyle getStyle() {
|
|
public DialogXStyle getStyle() {
|
|
return style;
|
|
return style;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public DialogX.THEME getTheme() {
|
|
public DialogX.THEME getTheme() {
|
|
return theme;
|
|
return theme;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static void useTextInfo(TextView textView, TextInfo textInfo) {
|
|
public static void useTextInfo(TextView textView, TextInfo textInfo) {
|
|
if (textInfo == null) {
|
|
if (textInfo == null) {
|
|
return;
|
|
return;
|
|
@@ -542,10 +541,10 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
} else {
|
|
} else {
|
|
textView.setMaxLines(Integer.MAX_VALUE);
|
|
textView.setMaxLines(Integer.MAX_VALUE);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
textView.getPaint().setFakeBoldText(textInfo.isBold());
|
|
textView.getPaint().setFakeBoldText(textInfo.isBold());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected void showText(TextView textView, CharSequence text) {
|
|
protected void showText(TextView textView, CharSequence text) {
|
|
if (textView == null) {
|
|
if (textView == null) {
|
|
return;
|
|
return;
|
|
@@ -558,14 +557,14 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
textView.setText(text);
|
|
textView.setText(text);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static boolean isNull(String s) {
|
|
public static boolean isNull(String s) {
|
|
if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) {
|
|
if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static boolean isNull(CharSequence c) {
|
|
public static boolean isNull(CharSequence c) {
|
|
String s = String.valueOf(c);
|
|
String s = String.valueOf(c);
|
|
if (c == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) {
|
|
if (c == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) {
|
|
@@ -573,19 +572,19 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public Resources getResources() {
|
|
public Resources getResources() {
|
|
if (getApplicationContext() == null) {
|
|
if (getApplicationContext() == null) {
|
|
return Resources.getSystem();
|
|
return Resources.getSystem();
|
|
}
|
|
}
|
|
return getApplicationContext().getResources();
|
|
return getApplicationContext().getResources();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public int dip2px(float dpValue) {
|
|
public int dip2px(float dpValue) {
|
|
final float scale = getResources().getDisplayMetrics().density;
|
|
final float scale = getResources().getDisplayMetrics().density;
|
|
return (int) (dpValue * scale + 0.5f);
|
|
return (int) (dpValue * scale + 0.5f);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public boolean isLightTheme() {
|
|
public boolean isLightTheme() {
|
|
if (theme == DialogX.THEME.AUTO) {
|
|
if (theme == DialogX.THEME.AUTO) {
|
|
if (getApplicationContext() == null) {
|
|
if (getApplicationContext() == null) {
|
|
@@ -595,16 +594,16 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
return theme == DialogX.THEME.LIGHT;
|
|
return theme == DialogX.THEME.LIGHT;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public FrameLayout getRootFrameLayout() {
|
|
public FrameLayout getRootFrameLayout() {
|
|
Activity activity = getOwnActivity();
|
|
Activity activity = getOwnActivity();
|
|
if (activity == null) {
|
|
if (activity == null) {
|
|
- activity = getTopActivity();
|
|
|
|
|
|
+ activity = getOwnActivity();
|
|
}
|
|
}
|
|
rootFrameLayout = new WeakReference<>((FrameLayout) activity.getWindow().getDecorView());
|
|
rootFrameLayout = new WeakReference<>((FrameLayout) activity.getWindow().getDecorView());
|
|
return rootFrameLayout.get();
|
|
return rootFrameLayout.get();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void tintColor(View view, int color) {
|
|
public void tintColor(View view, int color) {
|
|
if (view == null) {
|
|
if (view == null) {
|
|
return;
|
|
return;
|
|
@@ -613,20 +612,21 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
view.setBackgroundTintList(ColorStateList.valueOf(color));
|
|
view.setBackgroundTintList(ColorStateList.valueOf(color));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 此标记用于拦截重复 dismiss 指令导致的关闭动画抖动异常
|
|
* 此标记用于拦截重复 dismiss 指令导致的关闭动画抖动异常
|
|
*/
|
|
*/
|
|
protected boolean dismissAnimFlag;
|
|
protected boolean dismissAnimFlag;
|
|
protected boolean preShow;
|
|
protected boolean preShow;
|
|
-
|
|
|
|
|
|
+
|
|
protected void beforeShow() {
|
|
protected void beforeShow() {
|
|
preShow = true;
|
|
preShow = true;
|
|
dismissAnimFlag = false;
|
|
dismissAnimFlag = false;
|
|
- if (getTopActivity() == null) {
|
|
|
|
|
|
+ ownActivity = new WeakReference<>(getTopActivity());
|
|
|
|
+ if (getOwnActivity() == null) {
|
|
//尝试重新获取 activity
|
|
//尝试重新获取 activity
|
|
init(null);
|
|
init(null);
|
|
- if (getTopActivity() == null) {
|
|
|
|
|
|
+ if (getOwnActivity() == null) {
|
|
error("DialogX 未初始化(E5)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
error("DialogX 未初始化(E5)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -634,27 +634,27 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
if (style.styleVer != DialogXStyle.styleVer) {
|
|
if (style.styleVer != DialogXStyle.styleVer) {
|
|
error("DialogX 所引用的 Style 不符合当前适用版本:" + DialogXStyle.styleVer + " 引入的 Style(" + style.getClass().getSimpleName() + ") 版本" + style.styleVer);
|
|
error("DialogX 所引用的 Style 不符合当前适用版本:" + DialogXStyle.styleVer + " 引入的 Style(" + style.getClass().getSimpleName() + ") 版本" + style.styleVer);
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (dialogImplMode != DialogX.IMPL_MODE.VIEW && getTopActivity() instanceof LifecycleOwner) {
|
|
|
|
- Lifecycle lifecycle = ((LifecycleOwner) getTopActivity()).getLifecycle();
|
|
|
|
|
|
+
|
|
|
|
+ if (dialogImplMode != DialogX.IMPL_MODE.VIEW && getOwnActivity() instanceof LifecycleOwner) {
|
|
|
|
+ Lifecycle lifecycle = ((LifecycleOwner) getOwnActivity()).getLifecycle();
|
|
lifecycle.addObserver(new LifecycleEventObserver() {
|
|
lifecycle.addObserver(new LifecycleEventObserver() {
|
|
@Override
|
|
@Override
|
|
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
|
|
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
|
|
if (event == Lifecycle.Event.ON_DESTROY) {
|
|
if (event == Lifecycle.Event.ON_DESTROY) {
|
|
- recycleDialog(getTopActivity());
|
|
|
|
|
|
+ recycleDialog(getOwnActivity());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
//Hide IME
|
|
//Hide IME
|
|
- View view = (BaseDialog.getTopActivity()).getCurrentFocus();
|
|
|
|
|
|
+ View view = getOwnActivity().getCurrentFocus();
|
|
if (view != null) {
|
|
if (view != null) {
|
|
- InputMethodManager imm = (InputMethodManager) BaseDialog.getTopActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
|
+ InputMethodManager imm = (InputMethodManager) getOwnActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
|
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected String getString(int titleResId) {
|
|
protected String getString(int titleResId) {
|
|
if (getApplicationContext() == null) {
|
|
if (getApplicationContext() == null) {
|
|
error("DialogX 未初始化(E6)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
error("DialogX 未初始化(E6)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
@@ -662,7 +662,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
return getResources().getString(titleResId);
|
|
return getResources().getString(titleResId);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected int getColor(int backgroundRes) {
|
|
protected int getColor(int backgroundRes) {
|
|
if (getApplicationContext() == null) {
|
|
if (getApplicationContext() == null) {
|
|
error("DialogX 未初始化(E7)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
error("DialogX 未初始化(E7)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
|
|
@@ -670,13 +670,13 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
return getResources().getColor(backgroundRes);
|
|
return getResources().getColor(backgroundRes);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public enum BOOLEAN {
|
|
public enum BOOLEAN {
|
|
TRUE, FALSE
|
|
TRUE, FALSE
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public abstract String dialogKey();
|
|
public abstract String dialogKey();
|
|
-
|
|
|
|
|
|
+
|
|
protected static void runOnMain(Runnable runnable) {
|
|
protected static void runOnMain(Runnable runnable) {
|
|
if (!DialogX.autoRunOnUIThread || (getUiThread() != null && Thread.currentThread() == getUiThread())) {
|
|
if (!DialogX.autoRunOnUIThread || (getUiThread() != null && Thread.currentThread() == getUiThread())) {
|
|
runnable.run();
|
|
runnable.run();
|
|
@@ -684,18 +684,18 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
runOnMain(runnable, true);
|
|
runOnMain(runnable, true);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static Thread getUiThread() {
|
|
protected static Thread getUiThread() {
|
|
if (uiThread == null) {
|
|
if (uiThread == null) {
|
|
uiThread = Looper.getMainLooper().getThread();
|
|
uiThread = Looper.getMainLooper().getThread();
|
|
}
|
|
}
|
|
return uiThread;
|
|
return uiThread;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static void runOnMain(Runnable runnable, boolean needWaitMainLooper) {
|
|
protected static void runOnMain(Runnable runnable, boolean needWaitMainLooper) {
|
|
getMainHandler().post(runnable);
|
|
getMainHandler().post(runnable);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static void runOnMainDelay(Runnable runnable, long delay) {
|
|
protected static void runOnMainDelay(Runnable runnable, long delay) {
|
|
if (delay < 0) {
|
|
if (delay < 0) {
|
|
return;
|
|
return;
|
|
@@ -705,25 +705,25 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
getMainHandler().postDelayed(runnable, delay);
|
|
getMainHandler().postDelayed(runnable, delay);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public View getDialogView() {
|
|
public View getDialogView() {
|
|
if (dialogView == null) {
|
|
if (dialogView == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
return dialogView.get();
|
|
return dialogView.get();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public Activity getOwnActivity() {
|
|
public Activity getOwnActivity() {
|
|
return ownActivity == null ? null : ownActivity.get();
|
|
return ownActivity == null ? null : ownActivity.get();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected void cleanActivityContext() {
|
|
protected void cleanActivityContext() {
|
|
if (ownActivity != null) {
|
|
if (ownActivity != null) {
|
|
ownActivity.clear();
|
|
ownActivity.clear();
|
|
}
|
|
}
|
|
ownActivity = null;
|
|
ownActivity = null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static void cleanAll() {
|
|
public static void cleanAll() {
|
|
if (runningDialogList != null) {
|
|
if (runningDialogList != null) {
|
|
CopyOnWriteArrayList<BaseDialog> copyOnWriteList = new CopyOnWriteArrayList<>(runningDialogList);
|
|
CopyOnWriteArrayList<BaseDialog> copyOnWriteList = new CopyOnWriteArrayList<>(runningDialogList);
|
|
@@ -736,7 +736,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static void recycleDialog(Activity activity) {
|
|
public static void recycleDialog(Activity activity) {
|
|
switch (DialogX.implIMPLMode) {
|
|
switch (DialogX.implIMPLMode) {
|
|
case WINDOW:
|
|
case WINDOW:
|
|
@@ -760,7 +760,7 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case FLOATING_ACTIVITY:
|
|
case FLOATING_ACTIVITY:
|
|
-
|
|
|
|
|
|
+
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
if (runningDialogList != null) {
|
|
if (runningDialogList != null) {
|
|
@@ -778,36 +778,36 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
cleanContext();
|
|
cleanContext();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static List<BaseDialog> getRunningDialogList() {
|
|
public static List<BaseDialog> getRunningDialogList() {
|
|
if (runningDialogList == null) {
|
|
if (runningDialogList == null) {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
return new CopyOnWriteArrayList<>(runningDialogList);
|
|
return new CopyOnWriteArrayList<>(runningDialogList);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected void imeShow(EditText editText, boolean show) {
|
|
protected void imeShow(EditText editText, boolean show) {
|
|
- if (getTopActivity() == null) {
|
|
|
|
|
|
+ if (getOwnActivity() == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- InputMethodManager imm = (InputMethodManager) getTopActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
|
+ InputMethodManager imm = (InputMethodManager) getOwnActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
if (show) {
|
|
if (show) {
|
|
imm.showSoftInput(editText, InputMethodManager.RESULT_UNCHANGED_SHOWN);
|
|
imm.showSoftInput(editText, InputMethodManager.RESULT_UNCHANGED_SHOWN);
|
|
} else {
|
|
} else {
|
|
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
|
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public DialogX.IMPL_MODE getDialogImplMode() {
|
|
public DialogX.IMPL_MODE getDialogImplMode() {
|
|
return dialogImplMode;
|
|
return dialogImplMode;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected static WindowInsets windowInsets;
|
|
protected static WindowInsets windowInsets;
|
|
-
|
|
|
|
|
|
+
|
|
public static WindowInsets publicWindowInsets() {
|
|
public static WindowInsets publicWindowInsets() {
|
|
return windowInsets;
|
|
return windowInsets;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static void publicWindowInsets(WindowInsets windowInsets) {
|
|
public static void publicWindowInsets(WindowInsets windowInsets) {
|
|
if (windowInsets != null) {
|
|
if (windowInsets != null) {
|
|
BaseDialog.windowInsets = windowInsets;
|
|
BaseDialog.windowInsets = windowInsets;
|
|
@@ -825,13 +825,13 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected void bindFloatingActivity(DialogXFloatingWindowActivity activity) {
|
|
protected void bindFloatingActivity(DialogXFloatingWindowActivity activity) {
|
|
floatingWindowActivity = new WeakReference<>(activity);
|
|
floatingWindowActivity = new WeakReference<>(activity);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
static WeakReference<Handler> mMainHandler;
|
|
static WeakReference<Handler> mMainHandler;
|
|
-
|
|
|
|
|
|
+
|
|
private static Handler getMainHandler() {
|
|
private static Handler getMainHandler() {
|
|
if (mMainHandler != null && mMainHandler.get() != null) {
|
|
if (mMainHandler != null && mMainHandler.get() != null) {
|
|
return mMainHandler.get();
|
|
return mMainHandler.get();
|
|
@@ -839,66 +839,66 @@ public abstract class BaseDialog implements LifecycleOwner {
|
|
mMainHandler = new WeakReference<>(new Handler(Looper.getMainLooper()));
|
|
mMainHandler = new WeakReference<>(new Handler(Looper.getMainLooper()));
|
|
return mMainHandler.get();
|
|
return mMainHandler.get();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public DialogListBuilder getDialogListBuilder() {
|
|
public DialogListBuilder getDialogListBuilder() {
|
|
if (dialogListBuilder == null) {
|
|
if (dialogListBuilder == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
return dialogListBuilder.get();
|
|
return dialogListBuilder.get();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void setDialogListBuilder(DialogListBuilder dialogListBuilder) {
|
|
public void setDialogListBuilder(DialogListBuilder dialogListBuilder) {
|
|
this.dialogListBuilder = new WeakReference<>(dialogListBuilder);
|
|
this.dialogListBuilder = new WeakReference<>(dialogListBuilder);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void cleanDialogList() {
|
|
public void cleanDialogList() {
|
|
this.dialogListBuilder = null;
|
|
this.dialogListBuilder = null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public boolean isPreShow() {
|
|
public boolean isPreShow() {
|
|
return preShow;
|
|
return preShow;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public abstract <D extends BaseDialog> D show();
|
|
public abstract <D extends BaseDialog> D show();
|
|
-
|
|
|
|
|
|
+
|
|
protected void onDialogShow() {
|
|
protected void onDialogShow() {
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected void onDialogInit() {
|
|
protected void onDialogInit() {
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected void onDialogRefreshUI() {
|
|
protected void onDialogRefreshUI() {
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@NonNull
|
|
@NonNull
|
|
@Override
|
|
@Override
|
|
public Lifecycle getLifecycle() {
|
|
public Lifecycle getLifecycle() {
|
|
return lifecycle;
|
|
return lifecycle;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public int getMaxWidth() {
|
|
public int getMaxWidth() {
|
|
if (maxWidth == 0) {
|
|
if (maxWidth == 0) {
|
|
return DialogX.dialogMaxWidth;
|
|
return DialogX.dialogMaxWidth;
|
|
}
|
|
}
|
|
return maxWidth;
|
|
return maxWidth;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public int getMaxHeight() {
|
|
public int getMaxHeight() {
|
|
if (maxHeight == 0) {
|
|
if (maxHeight == 0) {
|
|
return DialogX.dialogMaxHeight;
|
|
return DialogX.dialogMaxHeight;
|
|
}
|
|
}
|
|
return maxHeight;
|
|
return maxHeight;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public int getMinWidth() {
|
|
public int getMinWidth() {
|
|
if (minWidth == 0) {
|
|
if (minWidth == 0) {
|
|
return DialogX.dialogMinWidth;
|
|
return DialogX.dialogMinWidth;
|
|
}
|
|
}
|
|
return minWidth;
|
|
return minWidth;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public int getMinHeight() {
|
|
public int getMinHeight() {
|
|
- if (minWidth == 0) {
|
|
|
|
|
|
+ if (minHeight == 0) {
|
|
return DialogX.dialogMinHeight;
|
|
return DialogX.dialogMinHeight;
|
|
}
|
|
}
|
|
return minHeight;
|
|
return minHeight;
|