| | |
| | | package com.lotaai.canguiayw.view; |
| | | |
| | | import android.content.DialogInterface; |
| | | import android.os.Bundle; |
| | | import android.os.CountDownTimer; |
| | | import android.view.Gravity; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | |
| | | import com.lotaai.canguiayw.R; |
| | | |
| | | public class TipDialog extends DialogFragment { |
| | | private CountDownTimer timer; |
| | | @Nullable |
| | | @Override |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | |
| | | super.onViewCreated(view, savedInstanceState); |
| | | TextView tvMsg = view.findViewById(R.id.tv_msg); |
| | | tvMsg.setText(getArguments().getString("msg")); |
| | | view.findViewById(R.id.tv_action).setOnClickListener(new View.OnClickListener() { |
| | | final TextView tvAction = view.findViewById(R.id.tv_action); |
| | | tvAction.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (callback!=null) |
| | |
| | | dismissAllowingStateLoss(); |
| | | } |
| | | }); |
| | | boolean isCountdown = getArguments().getBoolean("isCountdown", false); |
| | | if (isCountdown){ |
| | | timer = new CountDownTimer(5000,1000){ |
| | | @Override |
| | | public void onTick(long l) { |
| | | tvAction.setText(((l/1000)+1)+"S"); |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | dismissAllowingStateLoss(); |
| | | } |
| | | }; |
| | | timer.start(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onDismiss(@NonNull DialogInterface dialog) { |
| | | super.onDismiss(dialog); |
| | | if (timer!=null) |
| | | timer.cancel(); |
| | | } |
| | | |
| | | public interface ExitCallback { |