| | |
| | | package com.hdl.photovoltaic.widget; |
| | | |
| | | import android.app.Activity; |
| | | import android.app.Dialog; |
| | | import android.content.Context; |
| | | import android.os.Bundle; |
| | |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | import androidx.constraintlayout.widget.ConstraintSet; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.databinding.LoadingConfirmInputBinding; |
| | | import com.hdl.photovoltaic.utils.KeyboardStateObserverUtils; |
| | | |
| | | /** |
| | | * 输入确认框 |
| | |
| | | public class ConfirmationInputDialog extends Dialog { |
| | | |
| | | public ConfirmationInputDialog(@NonNull Context context) { |
| | | super(context, R.style.Custom_AlertDialog); |
| | | super(context, R.style.Custom_Dialog); |
| | | this.mContext = context; |
| | | } |
| | | |
| | |
| | | private onYesOnclickListener yesOnclickListener;//确定按钮被点击了的监听器 |
| | | private LoadingConfirmInputBinding viewBinding; |
| | | private String titleStr, yesStr, noStr; |
| | | |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | initData(); |
| | | //初始化界面控件的事件 |
| | | initEvent(); |
| | | //在界面中使用 |
| | | KeyboardStateObserverUtils.getKeyboardStateObserver((Activity) mContext).setKeyboardVisibilityListener(new KeyboardStateObserverUtils.OnKeyboardVisibilityListener() { |
| | | @Override |
| | | public void onKeyboardShow(int h) { |
| | | ConstraintSet cs = new ConstraintSet(); |
| | | cs.clone(viewBinding.loadingParentCl); |
| | | // (viewBinding.loadingConfirmationRl.getTop()-dip2px(h)) |
| | | |
| | | cs.connect(R.id.loading_confirmation_rl, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, px2dip(h));// |
| | | //应用约束 |
| | | cs.applyTo(viewBinding.loadingParentCl); |
| | | |
| | | |
| | | // FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) viewBinding.loadingParentCl.getLayoutParams(); |
| | | // lp.bottomMargin = px2dip(h); |
| | | // viewBinding.loadingParentCl.setLayoutParams(lp); |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | |
| | | public void onKeyboardHide(int h) { |
| | | ConstraintSet cs = new ConstraintSet(); |
| | | cs.clone(viewBinding.loadingParentCl); |
| | | cs.connect(R.id.loading_confirmation_rl, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, px2dip(h));// |
| | | //应用约束 |
| | | cs.applyTo(viewBinding.loadingParentCl); |
| | | } |
| | | |
| | | }); |
| | | |
| | | |
| | | } |
| | |
| | | return; |
| | | } |
| | | titleStr = title; |
| | | if (viewBinding != null) { |
| | | viewBinding.loadingConfirmationTitleTv.setText(titleStr); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | yesStr = confirm; |
| | | |
| | | if (viewBinding != null) { |
| | | viewBinding.dialogConfirmTv.setText(yesStr); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | } |
| | | noStr = cancel; |
| | | |
| | | if (viewBinding != null) { |
| | | viewBinding.dialogCancelTv.setText(noStr); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * 初始化界面控件的显示数据 |
| | | */ |
| | | private void initData() { |
| | | if (viewBinding == null) { |
| | | return; |
| | | } |
| | | //如果用户自定了title和message |
| | | if (!TextUtils.isEmpty(titleStr)) { |
| | | viewBinding.loadingConfirmationTitleTv.setText(titleStr); |
| | |
| | | void Confirm(String str); |
| | | } |
| | | |
| | | /** |
| | | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) |
| | | */ |
| | | private int dip2px(float dpValue) { |
| | | if (mContext == null) { |
| | | return 0; |
| | | } |
| | | final float scale = mContext.getResources().getDisplayMetrics().density; |
| | | return (int) (dpValue * scale + 0.5f); |
| | | } |
| | | |
| | | /** |
| | | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp |
| | | */ |
| | | private int px2dip(float pxValue) { |
| | | final float scale = mContext.getResources().getDisplayMetrics().density; |
| | | return (int) (pxValue / scale + 0.5f); |
| | | } |
| | | |
| | | } |