正在查看: 公务员之家 v1.0.1 应用的 OnBindView.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 公务员之家 v1.0.1 应用的 OnBindView.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.kongzue.dialogx.interfaces;
import android.app.Activity;
import android.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.kongzue.dialogx.DialogX;
import com.kongzue.dialogx.util.views.ExtendChildLayoutParamsFrameLayout;
import java.util.Random;
public abstract class OnBindView<D> {
View customView;
private Fragment fragment;
private int fragmentParentId = -1;
int layoutResId;
private android.app.Fragment supportFragment;
private Runnable waitBindRunnable;
public abstract void onBind(D d, View view);
public void onFragmentBind(D d, View view, android.app.Fragment fragment, FragmentManager fragmentManager) {
}
public void onFragmentBind(D d, View view, Fragment fragment, androidx.fragment.app.FragmentManager fragmentManager) {
}
public OnBindView(int i) {
if (BaseDialog.getTopActivity() == null) {
DialogX.error("DialogX.init: 初始化异常,context 为 null 或未初始化,详情请查看 https://github.com/kongzue/DialogX/wiki");
} else {
this.layoutResId = i;
this.customView = LayoutInflater.from(BaseDialog.getTopActivity()).inflate(i, (ViewGroup) new RelativeLayout(BaseDialog.getTopActivity()), false);
}
}
public OnBindView(final int i, boolean z) {
if (BaseDialog.getTopActivity() == null) {
DialogX.error("DialogX.init: 初始化异常,context 为 null 或未初始化,详情请查看 https://github.com/kongzue/DialogX/wiki");
return;
}
this.layoutResId = i;
if (z) {
new Thread() {
@Override
public void run() {
super.run();
synchronized (OnBindView.this) {
OnBindView.this.customView = LayoutInflater.from(BaseDialog.getTopActivity()).inflate(i, (ViewGroup) new RelativeLayout(BaseDialog.getTopActivity()), false);
if (OnBindView.this.waitBindRunnable != null) {
OnBindView.this.waitBindRunnable.run();
OnBindView.this.waitBindRunnable = null;
}
}
}
}.start();
} else {
this.customView = LayoutInflater.from(BaseDialog.getTopActivity()).inflate(i, (ViewGroup) new RelativeLayout(BaseDialog.getTopActivity()), false);
}
}
public OnBindView(View view) {
this.customView = view;
}
public int getFragmentParentId() {
if (this.fragmentParentId == -1) {
this.fragmentParentId = createFragmentParentId();
}
return this.fragmentParentId;
}
private int createFragmentParentId() {
this.fragmentParentId = new Random().nextInt();
if (BaseDialog.getTopActivity().findViewById(this.fragmentParentId) != null) {
return createFragmentParentId();
}
return this.fragmentParentId;
}
public OnBindView(Fragment fragment) {
if (BaseDialog.getTopActivity() == null) {
return;
}
ExtendChildLayoutParamsFrameLayout extendChildLayoutParamsFrameLayout = new ExtendChildLayoutParamsFrameLayout(BaseDialog.getTopActivity());
this.customView = extendChildLayoutParamsFrameLayout;
extendChildLayoutParamsFrameLayout.setId(getFragmentParentId());
this.fragment = fragment;
this.supportFragment = null;
}
public OnBindView(android.app.Fragment fragment) {
if (BaseDialog.getTopActivity() == null) {
return;
}
ExtendChildLayoutParamsFrameLayout extendChildLayoutParamsFrameLayout = new ExtendChildLayoutParamsFrameLayout(BaseDialog.getTopActivity());
this.customView = extendChildLayoutParamsFrameLayout;
extendChildLayoutParamsFrameLayout.setId(getFragmentParentId());
this.supportFragment = fragment;
this.fragment = null;
}
public int getLayoutResId() {
return this.layoutResId;
}
public OnBindView<D> setLayoutResId(int i) {
this.layoutResId = i;
return this;
}
public View getCustomView() {
if (this.customView == null) {
this.customView = LayoutInflater.from(BaseDialog.getTopActivity()).inflate(this.layoutResId, (ViewGroup) new RelativeLayout(BaseDialog.getTopActivity()), false);
}
return this.customView;
}
public OnBindView<D> setCustomView(View view) {
this.customView = view;
return this;
}
public void clean() {
this.layoutResId = 0;
this.customView = null;
}
@Deprecated
public void bindParent(ViewGroup viewGroup) {
if (getCustomView() == null) {
waitBind(viewGroup, null);
return;
}
if (getCustomView().getParent() != null) {
if (getCustomView().getParent() == viewGroup) {
return;
} else {
((ViewGroup) getCustomView().getParent()).removeView(getCustomView());
}
}
ViewGroup.LayoutParams layoutParams = viewGroup.getLayoutParams();
if (layoutParams == null) {
layoutParams = new RelativeLayout.LayoutParams(-1, -2);
}
viewGroup.addView(getCustomView(), layoutParams);
}
public void bindParent(ViewGroup viewGroup, final BaseDialog baseDialog) {
if (getCustomView() == null) {
waitBind(viewGroup, null);
return;
}
if (getCustomView().getParent() != null) {
if (getCustomView().getParent() == viewGroup) {
return;
} else {
((ViewGroup) getCustomView().getParent()).removeView(getCustomView());
}
}
ViewGroup.LayoutParams layoutParams = getCustomView().getLayoutParams();
if (layoutParams == null) {
layoutParams = new RelativeLayout.LayoutParams(-1, -2);
}
viewGroup.addView(getCustomView(), layoutParams);
onBind(baseDialog, getCustomView());
if (this.fragment == null && this.supportFragment == null) {
return;
}
if (baseDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW) {
BaseDialog.error(baseDialog.dialogKey() + "非 VIEW 实现模式不支持 fragment 作为子布局显示。\n其原因为 Window 中不存在 FragmentManager,无法对子布局中的 fragment 进行管理。");
} else {
getCustomView().post(new Runnable() {
@Override
public void run() {
if (OnBindView.this.fragment != null && (OnBindView.this.getCustomView() instanceof FrameLayout) && (baseDialog.getOwnActivity() instanceof AppCompatActivity)) {
AppCompatActivity ownActivity = baseDialog.getOwnActivity();
FragmentTransaction beginTransaction = ownActivity.getSupportFragmentManager().beginTransaction();
beginTransaction.add(OnBindView.this.getFragmentParentId(), OnBindView.this.fragment);
beginTransaction.commit();
OnBindView onBindView = OnBindView.this;
onBindView.onFragmentBind((OnBindView) baseDialog, onBindView.getCustomView(), OnBindView.this.fragment, ownActivity.getSupportFragmentManager());
}
if (OnBindView.this.supportFragment != null && (OnBindView.this.getCustomView() instanceof FrameLayout) && (baseDialog.getOwnActivity() instanceof Activity)) {
Activity ownActivity2 = baseDialog.getOwnActivity();
android.app.FragmentTransaction beginTransaction2 = ownActivity2.getFragmentManager().beginTransaction();
beginTransaction2.add(OnBindView.this.getFragmentParentId(), OnBindView.this.supportFragment);
beginTransaction2.commit();
OnBindView onBindView2 = OnBindView.this;
onBindView2.onFragmentBind((OnBindView) baseDialog, onBindView2.getCustomView(), OnBindView.this.supportFragment, ownActivity2.getFragmentManager());
}
}
});
}
}
private void waitBind(final ViewGroup viewGroup, final BaseDialog baseDialog) {
this.waitBindRunnable = new Runnable() {
@Override
public void run() {
if (OnBindView.this.getCustomView() == null) {
BaseDialog baseDialog2 = baseDialog;
if (baseDialog2 == null) {
OnBindView.this.bindParent(viewGroup);
} else {
OnBindView.this.bindParent(viewGroup, baseDialog2);
}
}
}
};
}
}