import android.content.Context;
import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
public class AlertWindow {
public AlertWindow(Context context, String content, String btnStr, ActionCallback actionCallback) {
initWindow(context,content,btnStr,actionCallback);
}
private WindowManager mWindowManager;
private WindowManager.LayoutParams layoutParams;
private Context mContext;
private boolean addTag=false;
private View view;
private EverScrollTextView everScrollTextView;
private Button i_know;
private LinearLayout out_view_lin;
private void initWindow(Context context,String content,String btnStr, ActionCallback actionCallback){
mContext=context;
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
layoutParams = new WindowManager.LayoutParams( 2024 );
layoutParams.gravity= Gravity.BOTTOM;
layoutParams.format= PixelFormat.RGBA_8888;
layoutParams.x = 0;
layoutParams.y = 0;
layoutParams.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN;
view = LayoutInflater.from(context).inflate(R.layout.__448_alert_window, null);
everScrollTextView=(EverScrollTextView) view.findViewById(R.id.alert_content);
everScrollTextView.setText(content);
i_know=(Button) view.findViewById(R.id.i_know);
i_know.setText(btnStr);
i_know.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actionCallback.toDo(null);
hide();
}
});
out_view_lin=(LinearLayout) view.findViewById(R.id.out_view_lin);
out_view_lin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hide();
}
});
}
private void hide(){
BaseUtil.INSTANCE.runUi(()->{
if (addTag){
mWindowManager.removeView(view);
addTag=false;
}
return null;
});
}
public void show(){
BaseUtil.INSTANCE.runUi(()->{
if (!addTag){
mWindowManager.addView(view,layoutParams);
addTag=true;
}
return null;
});
}
}