悦享送 v3.5.1版本的 MD5 值为:111dc8a16f422da8b2f1cf208abae9ea
以下内容为反编译后的 BaseDialog.java 源代码,内容仅作参考
package com.kongzue.dialogx.interfaces;
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentManager;
import com.kongzue.dialogx.DialogX;
import com.kongzue.dialogx.R;
import com.kongzue.dialogx.dialogs.PopTip;
import com.kongzue.dialogx.impl.ActivityLifecycleImpl;
import com.kongzue.dialogx.impl.DialogFragmentImpl;
import com.kongzue.dialogx.util.TextInfo;
import com.kongzue.dialogx.util.WindowUtil;
import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public abstract class BaseDialog {
private static WeakReference<Activity> contextWeakReference;
private static WeakReference<FrameLayout> rootFrameLayout;
private static List<BaseDialog> runningDialogList;
protected boolean cancelable;
private WeakReference<View> dialogView;
protected long enterAnimDuration;
protected long exitAnimDuration;
protected boolean isShow;
protected OnBackPressedListener onBackPressedListener;
protected WeakReference<Activity> ownActivity;
protected WeakReference<DialogFragmentImpl> ownDialogFragmentImpl;
protected int backgroundColor = -1;
protected DialogXStyle style = DialogX.globalStyle;
protected DialogX.THEME theme = DialogX.globalTheme;
protected boolean autoShowInputKeyboard = DialogX.autoShowInputKeyboard;
public enum BOOLEAN {
TRUE,
FALSE
}
public abstract String dialogKey();
public abstract boolean isCancelable();
public abstract void restartDialog();
protected abstract void shutdown();
public static void init(Context context) {
if (context == null) {
context = ActivityLifecycleImpl.getTopActivity();
}
if (context instanceof Activity) {
initActivityContext((Activity) context);
}
ActivityLifecycleImpl.init(context, new ActivityLifecycleImpl.onActivityResumeCallBack() {
@Override
public void getActivity(Activity activity) {
BaseDialog.initActivityContext(activity);
}
});
}
public static void initActivityContext(Activity activity) {
try {
contextWeakReference = new WeakReference<>(activity);
rootFrameLayout = new WeakReference<>((FrameLayout) activity.getWindow().getDecorView());
} catch (Exception unused) {
error("DialogX.init: 初始化异常,找不到Activity的根布局");
}
}
public static void log(Object o) {
if (DialogX.DEBUGMODE) {
Log.i(">>>", o.toString());
}
}
protected static void error(Object o) {
if (DialogX.DEBUGMODE) {
Log.e(">>>", o.toString());
}
}
public static void onActivityResume(Activity activity) {
if (runningDialogList != null) {
CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList(runningDialogList);
for (int size = copyOnWriteArrayList.size() - 1; size >= 0; size--) {
BaseDialog baseDialog = (BaseDialog) copyOnWriteArrayList.get(size);
if (baseDialog.getActivity() == activity && baseDialog.isShow && baseDialog.getDialogView() != null) {
View findViewById = baseDialog.getDialogView().findViewById(R.id.box_root);
if ((findViewById instanceof DialogXBaseRelativeLayout) && ((DialogXBaseRelativeLayout) findViewById).isBaseFocusable()) {
findViewById.requestFocus();
return;
}
}
}
}
}
public static void requestDialogFocus() {
if (getContext() instanceof Activity) {
onActivityResume((Activity) getContext());
}
}
public static void show(final View view) {
final BaseDialog baseDialog;
if (view == null || (baseDialog = (BaseDialog) view.getTag()) == null) {
return;
}
if (baseDialog.isShow) {
if (baseDialog.getDialogView() != null) {
baseDialog.getDialogView().setVisibility(0);
return;
}
error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
return;
}
baseDialog.ownActivity = new WeakReference<>(contextWeakReference.get());
baseDialog.dialogView = new WeakReference<>(view);
log(baseDialog.dialogKey() + ".show");
addDialogToRunningList(baseDialog);
int i = AnonymousClass8.$SwitchMap$com$kongzue$dialogx$DialogX$IMPL_MODE[DialogX.implIMPLMode.ordinal()];
if (i == 1) {
runOnMain(new Runnable() {
@Override
public void run() {
WindowUtil.show((Activity) BaseDialog.contextWeakReference.get(), view, !(baseDialog instanceof PopTip));
}
});
return;
}
if (i == 2) {
DialogFragmentImpl dialogFragmentImpl = new DialogFragmentImpl(baseDialog, view);
dialogFragmentImpl.show(getSupportFragmentManager(contextWeakReference.get()), "DialogX");
baseDialog.ownDialogFragmentImpl = new WeakReference<>(dialogFragmentImpl);
} else {
WeakReference<FrameLayout> weakReference = rootFrameLayout;
if (weakReference == null || weakReference.get() == null) {
return;
}
runOnMain(new Runnable() {
@Override
public void run() {
if (view.getParent() != BaseDialog.rootFrameLayout.get()) {
((FrameLayout) BaseDialog.rootFrameLayout.get()).addView(view);
return;
}
BaseDialog.error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
}
});
}
}
static class AnonymousClass8 {
static final int[] $SwitchMap$com$kongzue$dialogx$DialogX$IMPL_MODE;
static {
int[] iArr = new int[DialogX.IMPL_MODE.values().length];
$SwitchMap$com$kongzue$dialogx$DialogX$IMPL_MODE = iArr;
try {
iArr[DialogX.IMPL_MODE.WINDOW.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$kongzue$dialogx$DialogX$IMPL_MODE[DialogX.IMPL_MODE.DIALOG_FRAGMENT.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
private static FragmentManager getSupportFragmentManager(Activity activity) {
if (activity instanceof AppCompatActivity) {
return ((AppCompatActivity) activity).getSupportFragmentManager();
}
return null;
}
public static void show(final Activity activity, final View view) {
final BaseDialog baseDialog;
if (activity == null || view == null || (baseDialog = (BaseDialog) view.getTag()) == null) {
return;
}
if (baseDialog.getDialogView() != null) {
baseDialog.getDialogView().setVisibility(0);
}
if (baseDialog.isShow) {
error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
return;
}
if (activity.isDestroyed()) {
error(((BaseDialog) view.getTag()).dialogKey() + ".show ERROR: activity is Destroyed.");
return;
}
baseDialog.ownActivity = new WeakReference<>(activity);
baseDialog.dialogView = new WeakReference<>(view);
log(baseDialog + ".show");
addDialogToRunningList(baseDialog);
int i = AnonymousClass8.$SwitchMap$com$kongzue$dialogx$DialogX$IMPL_MODE[DialogX.implIMPLMode.ordinal()];
if (i == 1) {
runOnMain(new Runnable() {
@Override
public void run() {
WindowUtil.show(activity, view, !(baseDialog instanceof PopTip));
}
});
return;
}
if (i == 2) {
DialogFragmentImpl dialogFragmentImpl = new DialogFragmentImpl(baseDialog, view);
dialogFragmentImpl.show(getSupportFragmentManager(activity), "DialogX");
baseDialog.ownDialogFragmentImpl = new WeakReference<>(dialogFragmentImpl);
} else {
final FrameLayout frameLayout = (FrameLayout) activity.getWindow().getDecorView();
if (frameLayout == null) {
return;
}
runOnMain(new Runnable() {
@Override
public void run() {
if (view.getParent() == BaseDialog.rootFrameLayout.get()) {
BaseDialog.error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
return;
}
frameLayout.addView(view);
}
});
}
}
public static void dismiss(final View dialogView) {
if (dialogView == null) {
return;
}
BaseDialog baseDialog = (BaseDialog) dialogView.getTag();
log(baseDialog.dialogKey() + ".dismiss");
removeDialogToRunningList(baseDialog);
WeakReference<View> weakReference = baseDialog.dialogView;
if (weakReference != null) {
weakReference.clear();
}
int i = AnonymousClass8.$SwitchMap$com$kongzue$dialogx$DialogX$IMPL_MODE[DialogX.implIMPLMode.ordinal()];
if (i == 1) {
runOnMain(new Runnable() {
@Override
public void run() {
WindowUtil.dismiss(dialogView);
}
});
return;
}
if (i == 2) {
WeakReference<DialogFragmentImpl> weakReference2 = baseDialog.ownDialogFragmentImpl;
if (weakReference2 == null || weakReference2.get() == null) {
return;
}
baseDialog.ownDialogFragmentImpl.get().dismiss();
return;
}
runOnMain(new Runnable() {
@Override
public void run() {
if (dialogView.getParent() == null || !(dialogView.getParent() instanceof ViewGroup)) {
if (BaseDialog.rootFrameLayout == null) {
return;
} else {
((FrameLayout) BaseDialog.rootFrameLayout.get()).removeView(dialogView);
}
} else {
((ViewGroup) dialogView.getParent()).removeView(dialogView);
}
BaseDialog.requestDialogFocus();
}
});
}
private static void addDialogToRunningList(BaseDialog baseDialog) {
if (runningDialogList == null) {
runningDialogList = new CopyOnWriteArrayList();
}
runningDialogList.add(baseDialog);
}
private static void removeDialogToRunningList(BaseDialog baseDialog) {
List<BaseDialog> list = runningDialogList;
if (list != null) {
list.remove(baseDialog);
}
}
public static Context getContext() {
WeakReference<Activity> weakReference = contextWeakReference;
if (weakReference == null) {
init(null);
WeakReference<Activity> weakReference2 = contextWeakReference;
if (weakReference2 == null) {
return null;
}
return weakReference2.get();
}
return weakReference.get();
}
public static void cleanContext() {
WeakReference<Activity> weakReference = contextWeakReference;
if (weakReference != null) {
weakReference.clear();
}
contextWeakReference = null;
System.gc();
}
public BaseDialog() {
this.cancelable = true;
this.enterAnimDuration = -1L;
this.exitAnimDuration = -1L;
this.cancelable = DialogX.cancelable;
this.enterAnimDuration = DialogX.enterAnimDuration;
this.exitAnimDuration = DialogX.exitAnimDuration;
}
public View createView(int layoutId) {
if (getContext() == null) {
error("DialogX 未初始化。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
return null;
}
return LayoutInflater.from(getContext()).inflate(layoutId, (ViewGroup) null);
}
public boolean isShow() {
return this.isShow;
}
public DialogXStyle getStyle() {
return this.style;
}
public DialogX.THEME getTheme() {
return this.theme;
}
public void useTextInfo(TextView textView, TextInfo textInfo) {
if (textInfo == null || textView == null) {
return;
}
if (textInfo.getFontSize() > 0) {
textView.setTextSize(1, textInfo.getFontSize());
}
if (textInfo.getFontColor() != 1) {
textView.setTextColor(textInfo.getFontColor());
}
if (textInfo.getGravity() != -1) {
textView.setGravity(textInfo.getGravity());
}
textView.getPaint().setFakeBoldText(textInfo.isBold());
}
public void showText(TextView textView, CharSequence text) {
if (textView == null) {
return;
}
if (isNull(text)) {
textView.setVisibility(8);
textView.setText("");
} else {
textView.setVisibility(0);
textView.setText(text);
}
}
protected View createHorizontalSplitView(int color) {
View view = new View(getContext());
view.setBackgroundColor(color);
view.setLayoutParams(new LinearLayout.LayoutParams(-1, 1));
return view;
}
protected View createVerticalSplitView(int color, int height) {
View view = new View(getContext());
view.setBackgroundColor(color);
view.setLayoutParams(new LinearLayout.LayoutParams(1, dip2px(height)));
return view;
}
public static boolean isNull(String s) {
return s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s);
}
public static boolean isNull(CharSequence c) {
String valueOf = String.valueOf(c);
return c == null || valueOf.trim().isEmpty() || "null".equals(valueOf) || "(null)".equals(valueOf);
}
public Resources getResources() {
return getContext() == null ? Resources.getSystem() : getContext().getResources();
}
public int dip2px(float dpValue) {
return (int) ((dpValue * getContext().getResources().getDisplayMetrics().density) + 0.5f);
}
public boolean isLightTheme() {
return this.theme == DialogX.THEME.AUTO ? getContext() == null ? this.theme == DialogX.THEME.LIGHT : (getContext().getApplicationContext().getResources().getConfiguration().uiMode & 48) == 16 : this.theme == DialogX.THEME.LIGHT;
}
public static FrameLayout getRootFrameLayout() {
WeakReference<FrameLayout> weakReference = rootFrameLayout;
if (weakReference == null) {
error("DialogX 未初始化。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
return null;
}
return weakReference.get();
}
public void tintColor(View view, int color) {
if (Build.VERSION.SDK_INT >= 21) {
view.setBackgroundTintList(ColorStateList.valueOf(color));
}
}
public void beforeShow() {
if (getContext() == null) {
init(null);
if (getContext() == null) {
error("DialogX 未初始化。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
return;
}
}
View currentFocus = ((Activity) getContext()).getCurrentFocus();
if (currentFocus != null) {
((InputMethodManager) getContext().getSystemService("input_method")).hideSoftInputFromWindow(currentFocus.getWindowToken(), 2);
}
}
public String getString(int titleResId) {
if (getContext() == null) {
error("DialogX 未初始化。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
return null;
}
return getContext().getString(titleResId);
}
public int getColor(int backgroundRes) {
if (getContext() == null) {
error("DialogX 未初始化。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
return ViewCompat.MEASURED_STATE_MASK;
}
return getResources().getColor(backgroundRes);
}
public static void runOnMain(Runnable runnable) {
if (!DialogX.autoRunOnUIThread) {
runnable.run();
}
new Handler(Looper.getMainLooper()).post(runnable);
}
protected static void runOnMainDelay(Runnable runnable, long delay) {
if (!DialogX.autoRunOnUIThread) {
runnable.run();
}
new Handler(Looper.getMainLooper()).postDelayed(runnable, delay);
}
public View getDialogView() {
WeakReference<View> weakReference = this.dialogView;
if (weakReference == null) {
return null;
}
return weakReference.get();
}
public Activity getActivity() {
WeakReference<Activity> weakReference = this.ownActivity;
if (weakReference == null) {
return null;
}
return weakReference.get();
}
protected void cleanActivityContext() {
WeakReference<Activity> weakReference = this.ownActivity;
if (weakReference != null) {
weakReference.clear();
}
this.ownActivity = null;
}
public static void cleanAll() {
if (runningDialogList != null) {
Iterator it = new CopyOnWriteArrayList(runningDialogList).iterator();
while (it.hasNext()) {
BaseDialog baseDialog = (BaseDialog) it.next();
if (baseDialog.isShow()) {
baseDialog.shutdown();
}
baseDialog.cleanActivityContext();
runningDialogList.remove(baseDialog);
}
}
}
public static void recycleDialog(Activity activity) {
WeakReference<View> weakReference;
WeakReference<DialogFragmentImpl> weakReference2;
int i = AnonymousClass8.$SwitchMap$com$kongzue$dialogx$DialogX$IMPL_MODE[DialogX.implIMPLMode.ordinal()];
if (i != 1) {
if (i == 2) {
if (runningDialogList != null) {
Iterator it = new CopyOnWriteArrayList(runningDialogList).iterator();
while (it.hasNext()) {
BaseDialog baseDialog = (BaseDialog) it.next();
if (baseDialog.getActivity() == activity && (weakReference2 = baseDialog.ownDialogFragmentImpl) != null && weakReference2.get() != null) {
baseDialog.ownDialogFragmentImpl.get().dismiss();
}
}
}
} else if (runningDialogList != null) {
Iterator it2 = new CopyOnWriteArrayList(runningDialogList).iterator();
while (it2.hasNext()) {
BaseDialog baseDialog2 = (BaseDialog) it2.next();
if (baseDialog2.getActivity() == activity) {
baseDialog2.cleanActivityContext();
runningDialogList.remove(baseDialog2);
}
}
}
} else if (runningDialogList != null) {
Iterator it3 = new CopyOnWriteArrayList(runningDialogList).iterator();
while (it3.hasNext()) {
BaseDialog baseDialog3 = (BaseDialog) it3.next();
if (baseDialog3.getActivity() == activity && (weakReference = baseDialog3.dialogView) != null) {
WindowUtil.dismiss(weakReference.get());
}
}
}
if (activity == getContext()) {
cleanContext();
}
}
public static List<BaseDialog> getRunningDialogList() {
return runningDialogList == null ? new ArrayList() : new CopyOnWriteArrayList(runningDialogList);
}
public void imeShow(EditText editText, boolean show) {
if (getContext() == null) {
return;
}
InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService("input_method");
if (show) {
inputMethodManager.showSoftInput(editText, 0);
} else {
inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
}
}