Commit ce4a1f78 authored by 赵鹏翔's avatar 赵鹏翔

code format

parent 06ab4a0f
package com.miya.fastcashier.log;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import com.blankj.utilcode.util.SizeUtils;
import com.miya.fastcashier.R;
import com.miya.print.utils.QRCodeUtil;
import androidx.annotation.NonNull;
public class CustomImageCenterDialog extends Dialog{
private TextView tvOk;
private TextView tvHint;
private ImageView ivContent;
boolean isFullScreen;
private String mImageContent;
private String mHintContentText;
private String mConfirmContent;
private Bitmap mQrCodeBitmap;
/**
* 设置是否全屏显示
*
* @param isFullScreen
* @return
*/
public CustomImageCenterDialog setFullScreen(boolean isFullScreen) {
this.isFullScreen = isFullScreen;
return this;
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (isFullScreen) {
setFullScreen();
}
}
/**
* 隐藏虚拟按键,并且全屏
*/
protected void setFullScreen() {
//隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION//暂时不需要hideNavigation
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
}
public CustomImageCenterDialog(@NonNull Context context) {
super(context, R.style.CommonDialog);
initWindows();
setCanceledOnTouchOutside(false);
setContentView(R.layout.dialog_center_image);
setCancelable(true);
initView();
}
private void initView() {
tvOk = findViewById(R.id.tvOk);
tvHint = findViewById(R.id.tvSubContent);
ivContent = findViewById(R.id.ivContent);
}
public CustomImageCenterDialog setQrContent(String msg) {
mImageContent = msg;
return this;
}
public CustomImageCenterDialog setConfirmContent(String msg) {
mConfirmContent = msg;
return this;
}
public CustomImageCenterDialog setHintContent(String msg) {
mHintContentText = msg;
return this;
}
/**
* 创建dialog
*
* @return
*/
public CustomImageCenterDialog build() {
if (!TextUtils.isEmpty(mConfirmContent)){
tvOk.setText(mConfirmContent);
}
if (!TextUtils.isEmpty(mHintContentText)){
tvHint.setText(mHintContentText);
}
if (!TextUtils.isEmpty(mImageContent)){
mQrCodeBitmap = QRCodeUtil.createQRCodeBitmap(mImageContent, SizeUtils.dp2px(300));
ivContent.setImageBitmap(mQrCodeBitmap);
}
tvOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mQrCodeBitmap != null) {
mQrCodeBitmap.recycle();
}
dismiss();
}
});
if (isFullScreen) {
setFullScreen();
}
return this;
}
/**
* 初始化对话框(供子类选择调用)
*/
protected void initWindows() {
Window win = this.getWindow();
win.requestFeature(Window.FEATURE_NO_TITLE);
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
// lp.windowAnimations = R.style.LightInAndOutStyle;
lp.gravity = Gravity.CENTER;
win.setAttributes(lp);
win.setBackgroundDrawableResource(android.R.color.transparent);
}
}
package com.miya.fastcashier.log
import android.app.Dialog
import android.content.Context
import com.miya.fastcashier.R
import android.widget.TextView
import android.graphics.Bitmap
import com.miya.fastcashier.log.CustomImageCenterDialog
import android.os.Build
import android.view.WindowManager
import android.text.TextUtils
import com.miya.print.utils.QRCodeUtil
import com.blankj.utilcode.util.SizeUtils
import android.view.Gravity
import android.view.View
import android.view.Window
import android.widget.ImageView
class CustomImageCenterDialog(context: Context) : Dialog(context, R.style.CommonDialog) {
private var tvOk: TextView? = null
private var tvHint: TextView? = null
private var ivContent: ImageView? = null
private var isFullScreen = false
private var mImageContent: String? = null
private var mHintContentText: String? = null
private var mConfirmContent: String? = null
private var mQrCodeBitmap: Bitmap? = null
init {
initWindows()
setCanceledOnTouchOutside(false)
setContentView(R.layout.dialog_center_image)
setCancelable(true)
initView()
}
protected fun initWindows() {
val win = this.window
win!!.requestFeature(Window.FEATURE_NO_TITLE)
win.decorView.setPadding(0, 0, 0, 0)
val lp = win.attributes
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.MATCH_PARENT
// lp.windowAnimations = R.style.LightInAndOutStyle;
lp.gravity = Gravity.CENTER
win.attributes = lp
win.setBackgroundDrawableResource(android.R.color.transparent)
}
private fun initView() {
tvOk = findViewById(R.id.tvOk)
tvHint = findViewById(R.id.tvSubContent)
ivContent = findViewById(R.id.ivContent)
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (isFullScreen) {
setFullScreen()
}
}
/**
* 隐藏虚拟按键,并且全屏
*/
protected fun setFullScreen() {
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
val v = this.window!!.decorView
v.systemUiVisibility = View.GONE
} else if (Build.VERSION.SDK_INT >= 19) {
//for new api versions.
val decorView = window!!.decorView
val uiOptions =
(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION//暂时不需要hideNavigation
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
decorView.systemUiVisibility = uiOptions
window!!.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
}
}
/**
* 设置是否全屏显示
*
* @param isFullScreen
* @return
*/
fun setFullScreenStatus(isFullScreen: Boolean): CustomImageCenterDialog {
this.isFullScreen = isFullScreen
return this
}
fun setQrContent(msg: String?): CustomImageCenterDialog {
mImageContent = msg
return this
}
fun setConfirmContent(msg: String?): CustomImageCenterDialog {
mConfirmContent = msg
return this
}
fun setHintContent(msg: String?): CustomImageCenterDialog {
mHintContentText = msg
return this
}
/**
* 创建dialog
*
* @return
*/
fun build(): CustomImageCenterDialog {
if (!TextUtils.isEmpty(mConfirmContent)) {
tvOk!!.text = mConfirmContent
}
if (!TextUtils.isEmpty(mHintContentText)) {
tvHint!!.text = mHintContentText
}
if (!TextUtils.isEmpty(mImageContent)) {
mQrCodeBitmap = QRCodeUtil.createQRCodeBitmap(mImageContent, SizeUtils.dp2px(300f))
ivContent!!.setImageBitmap(mQrCodeBitmap)
}
tvOk!!.setOnClickListener {
if (mQrCodeBitmap != null) {
mQrCodeBitmap!!.recycle()
}
dismiss()
}
if (isFullScreen) {
setFullScreen()
}
return this
}
}
\ No newline at end of file
......@@ -335,7 +335,7 @@ public class LFilePickerActivity extends BaseActivity {
mCustomImageCenterDialog = new CustomImageCenterDialog(this);
}
mCustomImageCenterDialog.setOnDismissListener(dialog -> LFilePickerActivity.this.finish());
mCustomImageCenterDialog.setFullScreen(true)
mCustomImageCenterDialog.setFullScreenStatus(true)
.setHintContent("请将日志二维码拍照保存")
.setQrContent(mQrCodeEncodeMsg)
.build().show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment