package safeluck.drive.evaluation.customview;
|
|
import android.app.Dialog;
|
import android.graphics.Bitmap;
|
import android.graphics.BitmapFactory;
|
import android.graphics.Color;
|
import android.graphics.drawable.ColorDrawable;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.os.Looper;
|
import android.os.Message;
|
import android.util.Log;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.Button;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
|
import androidx.annotation.NonNull;
|
import androidx.annotation.Nullable;
|
import androidx.appcompat.app.AlertDialog;
|
import androidx.fragment.app.DialogFragment;
|
|
import java.nio.charset.Charset;
|
|
import safeluck.drive.evaluation.R;
|
import safeluck.drive.evaluation.util.QRCodeUtil;
|
|
/**
|
* @ProjectName: DriveJudge
|
* @Package: safeluck.drive.evaluation.customview
|
* @ClassName: LoadProgressDialog
|
* @Description: java类作用描述
|
* @Author: 李占伟
|
* @CreateDate: 2020-04-16 09:57
|
* @UpdateUser: 更新者
|
* @UpdateDate: 2020-04-16 09:57
|
* @UpdateRemark: 更新说明
|
* @Version: 1.0
|
*/
|
|
public class QRCodeDialog extends DialogFragment {
|
private static final String TAG = "QRCodeDialog";
|
private String message="正在加载...";
|
private boolean canCancel= false;
|
private ImageView iv_qrCode;
|
private Button btn;
|
private Bitmap qrBitmap;
|
private Bitmap logobitmap;
|
|
|
private Handler handler = new Handler(Looper.getMainLooper()){
|
@Override
|
public void handleMessage(Message msg) {
|
super.handleMessage(msg);
|
if (msg.what==1)
|
dismiss();
|
}
|
};
|
@Nullable
|
@Override
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
if (getDialog() != null) {
|
Window window = getDialog().getWindow();
|
|
if (window != null) {
|
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
|
|
getDialog().setOnShowListener(dialog -> {
|
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
|
hideBottomUIMenu();
|
});
|
}
|
}
|
View view = inflater.inflate(R.layout.layout_dialog_qrcode,container,false);
|
initView(view);
|
setCancelable(canCancel);
|
|
Message message = Message.obtain();
|
message.what = 1;
|
handler.sendMessageDelayed(message,25*1000);
|
return view;
|
}
|
|
private void initView(View view) {
|
Bundle bundle =getArguments();
|
message = bundle.getString("tittle");
|
Log.i(TAG,"meesage="+message);
|
btn = view.findViewById(R.id.btn_qr_sure);
|
iv_qrCode =view.findViewById(R.id.iv_qr_code);
|
logobitmap = BitmapFactory.decodeResource(getResources(),R.drawable.anyunlog);
|
qrBitmap = QRCodeUtil.createQRCodeBitmap(message,640,640,"UTF-8","H",
|
"1", Color.BLACK,Color.WHITE,logobitmap,0.2f,null);
|
iv_qrCode.setImageBitmap(qrBitmap);
|
btn.setOnClickListener(v -> {
|
dismiss();
|
});
|
}
|
|
|
public static QRCodeDialog newInstance(String message){
|
QRCodeDialog fragment = new QRCodeDialog();
|
Bundle bundle = new Bundle();
|
bundle.putString("tittle", message);
|
Log.i(TAG,"messae="+message);
|
fragment.setArguments(bundle);
|
return fragment;
|
}
|
|
|
/**
|
* 隐藏虚拟按键,并且全屏
|
*/
|
protected void hideBottomUIMenu() {
|
//隐藏虚拟按键,并且全屏
|
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
|
View v = this.getDialog().getWindow().getDecorView();
|
v.setSystemUiVisibility(View.GONE);
|
} else if (Build.VERSION.SDK_INT >= 19) {
|
//for new api versions.
|
View decorView = getDialog().getWindow().getDecorView();
|
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
|
decorView.setSystemUiVisibility(uiOptions);
|
}
|
}
|
}
|