|
|
@@ -3,15 +3,20 @@ package com.jdzh.jdzhandroid.util.Dialog; |
|
|
|
import android.app.Activity; |
|
|
|
import android.app.Dialog; |
|
|
|
import android.content.Context; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.Window; |
|
|
|
import android.widget.ArrayAdapter; |
|
|
|
import android.widget.Button; |
|
|
|
import android.widget.RadioButton; |
|
|
|
import android.widget.RelativeLayout; |
|
|
|
import android.widget.Spinner; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.viewbinding.ViewBinding; |
|
|
|
|
|
|
|
import com.jdzh.jdzhandroid.Enum.DialogButton; |
|
|
|
import com.jdzh.jdzhandroid.Enum.SiloChannel; |
|
|
|
import com.jdzh.jdzhandroid.Interface.IFuncT; |
|
|
@@ -23,6 +28,7 @@ import com.jdzh.jdzhandroid.Sqlite.DAO.BPA_BatchingDao; |
|
|
|
import com.jdzh.jdzhandroid.Sqlite.Model.BPA_Batching; |
|
|
|
import com.jdzh.jdzhandroid.Sqlite.SqliteHelper; |
|
|
|
import com.jdzh.jdzhandroid.databinding.MaterialEditDialogLayoutBinding; |
|
|
|
import com.jdzh.jdzhandroid.databinding.SiloSelectDialogLayoutBinding; |
|
|
|
import com.jdzh.jdzhandroid.util.AlertDialogUtil; |
|
|
|
import com.jdzh.jdzhandroid.util.GlobalContext; |
|
|
|
import com.jdzh.jdzhandroid.util.ToastUtil; |
|
|
@@ -43,66 +49,128 @@ import java.util.concurrent.atomic.AtomicReference; |
|
|
|
*/ |
|
|
|
public class DialogManager { |
|
|
|
|
|
|
|
// private static Context DialogUtil.getContext(); |
|
|
|
// |
|
|
|
// private static Activity DialogUtil.getActivity(); |
|
|
|
// |
|
|
|
// public static void Init(Context context,Activity activity){ |
|
|
|
// DialogUtil.getContext() = context; |
|
|
|
// DialogUtil.getActivity()=activity; |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
public static void showDialog(BPA_Batching batching, IFuncT<OperateResultT<BPA_Batching>> action){ |
|
|
|
if(GlobalContext.getContext()==null) return; |
|
|
|
try{ |
|
|
|
AtomicReference<DialogView>dview=new AtomicReference<>(); |
|
|
|
dview.set(new DialogView(GlobalContext.getContext(), R.layout.material_edit_dialog_layout , R.style.CustomDialog)); |
|
|
|
if(isDialogEmpty(dview.get())){ |
|
|
|
dview.set(new DialogView(GlobalContext.getActivity(), R.layout.material_edit_dialog_layout, R.style.CustomDialog)); |
|
|
|
} |
|
|
|
if (dview != null) { |
|
|
|
if (!dview.get().isShowing()) { |
|
|
|
|
|
|
|
dview.get().setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 |
|
|
|
TextView materialName = dview.get().findViewById(R.id.materialName); |
|
|
|
Spinner channelNames = dview.get().findViewById(R.id.channelNames); |
|
|
|
Button ok = (Button)dview.get().findViewById(R.id.btn_ok); |
|
|
|
Button cancel = (Button)dview.get().findViewById(R.id.btn_cancel); |
|
|
|
AtomicBoolean isEdit=new AtomicBoolean(false); |
|
|
|
if(batching!=null){ |
|
|
|
public static void showDialog(){ |
|
|
|
DialogView.createDailog( R.layout.silo_select_dialog_layout,v->{ |
|
|
|
v.setCanceledOnTouchOutside(true);//禁用触摸其它区域关闭弹框 |
|
|
|
SiloSelectDialogLayoutBinding binding=SiloSelectDialogLayoutBinding.inflate(v.getLayoutInflater()); |
|
|
|
v.setContentView(binding.getRoot()); |
|
|
|
binding.liquidRb1.setText("123"); |
|
|
|
binding.liquidGroup.setOnCheckedChangeListener((group,id)->{ |
|
|
|
RadioButton rb = v.findViewById(id); |
|
|
|
if( rb!=null && rb.isChecked()){ |
|
|
|
binding.powderGroup1.clearCheck(); |
|
|
|
binding.powderGroup2.clearCheck(); |
|
|
|
binding.powderGroup3.clearCheck(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
binding.powderGroup1.setOnCheckedChangeListener((group,id)->{ |
|
|
|
RadioButton rb = v.findViewById(id); |
|
|
|
if(rb!=null && rb.isChecked()){ |
|
|
|
binding.liquidGroup.clearCheck(); |
|
|
|
binding.powderGroup2.clearCheck(); |
|
|
|
binding.powderGroup3.clearCheck(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
binding.powderGroup2.setOnCheckedChangeListener((group,id)->{ |
|
|
|
RadioButton rb = v.findViewById(id); |
|
|
|
if(rb!=null && rb.isChecked()){ |
|
|
|
binding.powderGroup1.clearCheck(); |
|
|
|
binding.liquidGroup.clearCheck(); |
|
|
|
binding.powderGroup3.clearCheck(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
binding.powderGroup3.setOnCheckedChangeListener((group,id)->{ |
|
|
|
RadioButton rb = v.findViewById(id); |
|
|
|
if(rb!=null && rb.isChecked()){ |
|
|
|
binding.powderGroup1.clearCheck(); |
|
|
|
binding.powderGroup2.clearCheck(); |
|
|
|
binding.liquidGroup.clearCheck(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// String[] names = GlobalContext.getResources().getStringArray(R.array.siloChannel); |
|
|
|
// List<String> names = Arrays.asList(GlobalContext.getResources().getStringArray(R.array.siloChannel)); |
|
|
|
List<String> names = SiloChannel.getNames(); |
|
|
|
int index = names.indexOf(batching.getSiloChannelNum()); |
|
|
|
if(index>=0){ |
|
|
|
channelNames.setSelection(index); |
|
|
|
} |
|
|
|
materialName.setText(batching.getName()); |
|
|
|
Object obj = channelNames.getSelectedItem(); |
|
|
|
isEdit.set(true); |
|
|
|
} |
|
|
|
ok.setOnClickListener(view->{ |
|
|
|
BPA_Batching batching1 = new BPA_Batching(materialName.getText().toString(),channelNames.getSelectedItem().toString()); |
|
|
|
if(action!=null){ |
|
|
|
if(action.Run(OperateResultT.CreateSuccess(batching1))) hide(dview.get()); |
|
|
|
}else hide(dview.get()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
cancel.setOnClickListener(view->{ |
|
|
|
if(action!=null)action.Run(OperateResultT.CreateFailedT("取消当前操作")); |
|
|
|
hide(dview.get()); |
|
|
|
}); |
|
|
|
dview.get().show(); |
|
|
|
public static void showDialog(BPA_Batching batching, IFuncT<OperateResultT<BPA_Batching>> action){ |
|
|
|
DialogView.createDailog(R.layout.material_edit_dialog_layout,v->{ |
|
|
|
v.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 |
|
|
|
MaterialEditDialogLayoutBinding binding = MaterialEditDialogLayoutBinding.inflate(v.getLayoutInflater()); |
|
|
|
v.setContentView(binding.getRoot()); |
|
|
|
AtomicBoolean isEdit=new AtomicBoolean(false); |
|
|
|
if(batching!=null){ |
|
|
|
// List<String> names = Arrays.asList(GlobalContext.getResources().getStringArray(R.array.siloChannel)); |
|
|
|
List<String> names = SiloChannel.getNames(); |
|
|
|
int index = names.indexOf(batching.getSiloChannelNum()); |
|
|
|
if(index>=0){ |
|
|
|
binding.channelNames.setSelection(index); |
|
|
|
} |
|
|
|
binding.materialName.setText(batching.getName()); |
|
|
|
Object obj = binding.channelNames.getSelectedItem(); |
|
|
|
isEdit.set(true); |
|
|
|
} |
|
|
|
}catch(Exception e){ |
|
|
|
MessageLog.ShowError("打开弹框异常:"+e.toString()); |
|
|
|
} |
|
|
|
binding.btnOk.setOnClickListener(view->{ |
|
|
|
BPA_Batching batching1 = new BPA_Batching(binding.materialName.getText().toString(),binding.channelNames.getSelectedItem().toString()); |
|
|
|
if(action!=null){ |
|
|
|
if(action.Run(OperateResultT.CreateSuccess(batching1))) v.hide(); |
|
|
|
}else v.hide(); |
|
|
|
}); |
|
|
|
|
|
|
|
binding.btnCancel.setOnClickListener(view->{ |
|
|
|
if(action!=null)action.Run(OperateResultT.CreateFailedT("取消当前操作")); |
|
|
|
v.hide(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// if(GlobalContext.getContext()==null) return; |
|
|
|
// try{ |
|
|
|
// AtomicReference<DialogView>dview=new AtomicReference<>(); |
|
|
|
// dview.set(new DialogView(GlobalContext.getContext(), R.layout.material_edit_dialog_layout , R.style.CustomDialog)); |
|
|
|
// if(isDialogEmpty(dview.get())){ |
|
|
|
// dview.set(new DialogView(GlobalContext.getActivity(), R.layout.material_edit_dialog_layout, R.style.CustomDialog)); |
|
|
|
// } |
|
|
|
// if (dview != null) { |
|
|
|
// if (!dview.get().isShowing()) { |
|
|
|
// |
|
|
|
// dview.get().setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 |
|
|
|
// TextView materialName = dview.get().findViewById(R.id.materialName); |
|
|
|
// Spinner channelNames = dview.get().findViewById(R.id.channelNames); |
|
|
|
// Button ok = (Button)dview.get().findViewById(R.id.btn_ok); |
|
|
|
// Button cancel = (Button)dview.get().findViewById(R.id.btn_cancel); |
|
|
|
// AtomicBoolean isEdit=new AtomicBoolean(false); |
|
|
|
// if(batching!=null){ |
|
|
|
// List<String> names = Arrays.asList(GlobalContext.getResources().getStringArray(R.array.siloChannel)); |
|
|
|
// int index = names.indexOf(batching.getSiloChannelNum()); |
|
|
|
// if(index>=0){ |
|
|
|
// channelNames.setSelection(index); |
|
|
|
// } |
|
|
|
// materialName.setText(batching.getName()); |
|
|
|
// Object obj = channelNames.getSelectedItem(); |
|
|
|
// isEdit.set(true); |
|
|
|
// } |
|
|
|
// ok.setOnClickListener(view->{ |
|
|
|
// BPA_Batching batching1 = new BPA_Batching(materialName.getText().toString(),channelNames.getSelectedItem().toString()); |
|
|
|
// if(action!=null){ |
|
|
|
// if(action.Run(OperateResultT.CreateSuccess(batching1))) hide(dview.get()); |
|
|
|
// }else hide(dview.get()); |
|
|
|
// }); |
|
|
|
// |
|
|
|
// cancel.setOnClickListener(view->{ |
|
|
|
// if(action!=null)action.Run(OperateResultT.CreateFailedT("取消当前操作")); |
|
|
|
// hide(dview.get()); |
|
|
|
// }); |
|
|
|
// dview.get().show(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// }catch(Exception e){ |
|
|
|
// MessageLog.ShowError("打开弹框异常:"+e.toString()); |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 判断Dialog的窗口令牌是否为空 |
|
|
|
* @param dialog |
|
|
@@ -120,55 +188,90 @@ public class DialogManager { |
|
|
|
* 对话框,自定义按钮,非阻塞 |
|
|
|
* */ |
|
|
|
private static void showDialog(String message, DialogButton btn, DialogType dt, IRunT<Boolean> action) { |
|
|
|
if(GlobalContext.getContext()==null) return; |
|
|
|
try{ |
|
|
|
AtomicReference<DialogView>dview=new AtomicReference<>(); |
|
|
|
dview.set(new DialogView(GlobalContext.getContext(), R.layout.dialog_layout, R.style.CustomDialog)); |
|
|
|
if(isDialogEmpty(dview.get())){ |
|
|
|
dview.set(new DialogView(GlobalContext.getActivity(), R.layout.dialog_layout, R.style.CustomDialog)); |
|
|
|
} |
|
|
|
if (dview != null) { |
|
|
|
if (!dview.get().isShowing()) { |
|
|
|
|
|
|
|
String btnName1="确定"; |
|
|
|
String btnName2="取消"; |
|
|
|
if(btn==DialogButton.YesNoCancel||btn==DialogButton.YesNo){ |
|
|
|
btnName1="是"; |
|
|
|
btnName2="否"; |
|
|
|
} |
|
|
|
|
|
|
|
dview.get().setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 |
|
|
|
RelativeLayout rlTitle = (RelativeLayout) dview.get().findViewById(R.id.rl_title); |
|
|
|
if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back); |
|
|
|
if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back); |
|
|
|
if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back); |
|
|
|
TextView Tv=(TextView)dview.get().findViewById(R.id.tv_Title); |
|
|
|
TextView Info=(TextView)dview.get().findViewById(R.id.tv_Info); |
|
|
|
Button ok = (Button)dview.get().findViewById(R.id.btn_ok); |
|
|
|
Button cancel = (Button)dview.get().findViewById(R.id.btn_cancel); |
|
|
|
|
|
|
|
Tv.setText(dt.toString()); |
|
|
|
Info.setText(message); |
|
|
|
ok.setText(btnName1); |
|
|
|
cancel.setText(btnName2); |
|
|
|
|
|
|
|
if(btn==DialogButton.OK)cancel.setVisibility(View.GONE); |
|
|
|
|
|
|
|
ok.setOnClickListener(view->{ |
|
|
|
if(action!=null)action.Run(true); |
|
|
|
hide(dview.get()); |
|
|
|
}); |
|
|
|
|
|
|
|
cancel.setOnClickListener(view->{ |
|
|
|
if(action!=null)action.Run(false); |
|
|
|
hide(dview.get()); |
|
|
|
}); |
|
|
|
dview.get().show(); |
|
|
|
} |
|
|
|
DialogView.createDailog(R.layout.dialog_layout,v->{ |
|
|
|
String btnName1="确定"; |
|
|
|
String btnName2="取消"; |
|
|
|
if(btn==DialogButton.YesNoCancel||btn==DialogButton.YesNo){ |
|
|
|
btnName1="是"; |
|
|
|
btnName2="否"; |
|
|
|
} |
|
|
|
}catch(Exception e){ |
|
|
|
MessageLog.ShowError("打开弹框异常:"+e.toString()); |
|
|
|
} |
|
|
|
v.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 |
|
|
|
RelativeLayout rlTitle = (RelativeLayout) v.findViewById(R.id.rl_title); |
|
|
|
if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back); |
|
|
|
if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back); |
|
|
|
if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back); |
|
|
|
TextView Tv=(TextView)v.findViewById(R.id.tv_Title); |
|
|
|
TextView Info=(TextView)v.findViewById(R.id.tv_Info); |
|
|
|
Button ok = (Button)v.findViewById(R.id.btn_ok); |
|
|
|
Button cancel = (Button)v.findViewById(R.id.btn_cancel); |
|
|
|
|
|
|
|
Tv.setText(dt.toString()); |
|
|
|
Info.setText(message); |
|
|
|
ok.setText(btnName1); |
|
|
|
cancel.setText(btnName2); |
|
|
|
|
|
|
|
if(btn==DialogButton.OK)cancel.setVisibility(View.GONE); |
|
|
|
|
|
|
|
ok.setOnClickListener(view->{ |
|
|
|
if(action!=null)action.Run(true); |
|
|
|
v.hide(); |
|
|
|
}); |
|
|
|
|
|
|
|
cancel.setOnClickListener(view->{ |
|
|
|
if(action!=null)action.Run(false); |
|
|
|
v.hide(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
// if(GlobalContext.getContext()==null) return; |
|
|
|
// try{ |
|
|
|
// AtomicReference<DialogView>dview=new AtomicReference<>(); |
|
|
|
// dview.set(new DialogView(GlobalContext.getContext(), R.layout.dialog_layout, R.style.CustomDialog)); |
|
|
|
// if(isDialogEmpty(dview.get())){ |
|
|
|
// dview.set(new DialogView(GlobalContext.getActivity(), R.layout.dialog_layout, R.style.CustomDialog)); |
|
|
|
// } |
|
|
|
// if (dview != null) { |
|
|
|
// if (!dview.get().isShowing()) { |
|
|
|
// |
|
|
|
// String btnName1="确定"; |
|
|
|
// String btnName2="取消"; |
|
|
|
// if(btn==DialogButton.YesNoCancel||btn==DialogButton.YesNo){ |
|
|
|
// btnName1="是"; |
|
|
|
// btnName2="否"; |
|
|
|
// } |
|
|
|
// |
|
|
|
// dview.get().setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 |
|
|
|
// RelativeLayout rlTitle = (RelativeLayout) dview.get().findViewById(R.id.rl_title); |
|
|
|
// if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back); |
|
|
|
// if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back); |
|
|
|
// if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back); |
|
|
|
// TextView Tv=(TextView)dview.get().findViewById(R.id.tv_Title); |
|
|
|
// TextView Info=(TextView)dview.get().findViewById(R.id.tv_Info); |
|
|
|
// Button ok = (Button)dview.get().findViewById(R.id.btn_ok); |
|
|
|
// Button cancel = (Button)dview.get().findViewById(R.id.btn_cancel); |
|
|
|
// |
|
|
|
// Tv.setText(dt.toString()); |
|
|
|
// Info.setText(message); |
|
|
|
// ok.setText(btnName1); |
|
|
|
// cancel.setText(btnName2); |
|
|
|
// |
|
|
|
// if(btn==DialogButton.OK)cancel.setVisibility(View.GONE); |
|
|
|
// |
|
|
|
// ok.setOnClickListener(view->{ |
|
|
|
// if(action!=null)action.Run(true); |
|
|
|
// hide(dview.get()); |
|
|
|
// }); |
|
|
|
// |
|
|
|
// cancel.setOnClickListener(view->{ |
|
|
|
// if(action!=null)action.Run(false); |
|
|
|
// hide(dview.get()); |
|
|
|
// }); |
|
|
|
// dview.get().show(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// }catch(Exception e){ |
|
|
|
// MessageLog.ShowError("打开弹框异常:"+e.toString()); |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -292,10 +395,11 @@ public class DialogManager { |
|
|
|
* @param action 执行回调 |
|
|
|
*/ |
|
|
|
public static void showInfo(String message, DialogButton btn, IRunT<Boolean> action) { |
|
|
|
if(GlobalContext.getActivity()==null&&!Util.IsMainThread())return; |
|
|
|
if(!Util.IsMainThread()) |
|
|
|
GlobalContext.getActivity().runOnUiThread(()->{showDialog(message,btn,DialogType.提示,action);}); |
|
|
|
else showDialog(message,btn,DialogType.提示,action); |
|
|
|
// if(GlobalContext.getActivity()==null&&!Util.IsMainThread())return; |
|
|
|
// if(!Util.IsMainThread()) |
|
|
|
// GlobalContext.getActivity().runOnUiThread(()->{showDialog(message,btn,DialogType.提示,action);}); |
|
|
|
// else showDialog(message,btn,DialogType.提示,action); |
|
|
|
showDialog(message,btn,DialogType.提示,action); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -305,10 +409,11 @@ public class DialogManager { |
|
|
|
* @param action 执行回调 |
|
|
|
*/ |
|
|
|
public static void showWarn(String message, DialogButton btn, IRunT<Boolean> action) { |
|
|
|
if(GlobalContext.getActivity()==null&&!Util.IsMainThread())return; |
|
|
|
if(!Util.IsMainThread()) |
|
|
|
GlobalContext.getActivity().runOnUiThread(()->{showDialog(message,btn,DialogType.警告,action);}); |
|
|
|
else showDialog(message,btn,DialogType.警告,action); |
|
|
|
// if(GlobalContext.getActivity()==null&&!Util.IsMainThread())return; |
|
|
|
// if(!Util.IsMainThread()) |
|
|
|
// GlobalContext.getActivity().runOnUiThread(()->{showDialog(message,btn,DialogType.警告,action);}); |
|
|
|
// else showDialog(message,btn,DialogType.警告,action); |
|
|
|
showDialog(message,btn,DialogType.警告,action); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -318,10 +423,11 @@ public class DialogManager { |
|
|
|
* @param action 执行回调 |
|
|
|
*/ |
|
|
|
public static void showError(String message, DialogButton btn, IRunT<Boolean> action) { |
|
|
|
if(GlobalContext.getActivity()==null&&!Util.IsMainThread())return; |
|
|
|
if(!Util.IsMainThread()) |
|
|
|
GlobalContext.getActivity().runOnUiThread(()->{showDialog(message,btn,DialogType.错误,action);}); |
|
|
|
else showDialog(message,btn,DialogType.错误,action); |
|
|
|
// if(GlobalContext.getActivity()==null&&!Util.IsMainThread())return; |
|
|
|
// if(!Util.IsMainThread()) |
|
|
|
// GlobalContext.getActivity().runOnUiThread(()->{showDialog(message,btn,DialogType.错误,action);}); |
|
|
|
// else showDialog(message,btn,DialogType.错误,action); |
|
|
|
showDialog(message,btn,DialogType.错误,action); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|