package com.obsez.android.lib.filechooser;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.os.Bundle;
|
import android.util.DisplayMetrics;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.Button;
|
import android.widget.TextView;
|
public class FileDialog extends Dialog {
|
private Context context;
|
private String title;
|
private String leftBtnText;
|
private String rightBtnText;
|
private ClickListenerInterface clickListenerInterface;
|
public FileDialog(Context context, String title, String leftBtnText, String rightBtnText) {
|
super(context, R.style.ConfirmDialogStyle);
|
this.context = context;
|
this.title = title;
|
this.leftBtnText = leftBtnText;
|
this.rightBtnText = rightBtnText;
|
}
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
init();
|
}
|
public void init() {
|
LayoutInflater inflater = LayoutInflater.from(context);
|
View view = inflater.inflate(R.layout.confirm_dialog, null);
|
setContentView(view);
|
TextView tvTitle = view.findViewById(R.id.title);
|
Button tvConfirm = view.findViewById(R.id.leftBtn);
|
TextView tvCancel = view.findViewById(R.id.rightBit);
|
tvTitle.setText(title);
|
tvConfirm.setText(leftBtnText);
|
tvCancel.setText(rightBtnText);
|
tvConfirm.setOnClickListener(new clickListener());
|
tvCancel.setOnClickListener(new clickListener());
|
Window dialogWindow = getWindow();
|
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
|
DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
|
lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
|
dialogWindow.setAttributes(lp);
|
SystemUI.hideSystemUI(this);
|
SystemUI.initSystemUIListener(this);
|
}
|
public void show() {
|
try {
|
SystemUI.hideSystemUI(this);
|
super.show();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
public void setClickListener(ClickListenerInterface clickListenerInterface) {
|
this.clickListenerInterface = clickListenerInterface;
|
}
|
public interface ClickListenerInterface {
|
void doConfirm();
|
void doCancel();
|
}
|
private class clickListener implements View.OnClickListener {
|
public void onClick(View v) {
|
// int id = v.getId();
|
// switch (id) {
|
// case R.id.leftBtn:
|
// clickListenerInterface.doConfirm();
|
// break;
|
// case R.id.rightBit:
|
// clickListenerInterface.doCancel();
|
// break;
|
// }
|
}
|
}
|
}
|