Code example for Dialog

Methods: getWindow, requestWindowFeature, setContentView

0
	private IBeanFactory<SocializeButton> buttonFactory;
	private Drawables drawables;
 
	public Dialog build(Activity context, View contentView, boolean includeCloseButton) {
		 
		final Dialog dialog = new Dialog(contentView.getContext(), android.R.style.Theme_Dialog);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		 
		if(includeCloseButton) {
			 
			Drawable viewBg = drawables.getDrawable("action_bar_button.png", true, false, true);
			 
			LinearLayout layout = new LinearLayout(context);
			layout.setOrientation(LinearLayout.VERTICAL);
			 
			LinearLayout.LayoutParams master = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
			 
			layout.setLayoutParams(master);
			 
			LinearLayout toolbar = new LinearLayout(context);
			 
			LinearLayout.LayoutParams toolbarParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, displayUtils.getDIP(44));
			 
			toolbar.setLayoutParams(toolbarParams);
			toolbar.setGravity(Gravity.CENTER_VERTICAL|Gravity.RIGHT);
 
			CompatUtils.setBackgroundDrawable(toolbar, viewBg);
 
			SocializeButton button = buttonFactory.getBean();
			button.setOnClickListener(new OnClickListener() {
				@Override 
				public void onClick(View v) {
					dialog.dismiss();
				} 
			}); 
			 
			toolbar.addView(button);
			layout.addView(toolbar);
			layout.addView(contentView);
			 
			dialog.setContentView(layout);
		} 
		else { 
			dialog.setContentView(contentView);
		} 
		 
		ColorDrawable cd = new ColorDrawable(Color.BLACK);
		dialog.getWindow().setBackgroundDrawable(cd);
		dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
 
		// Register to prevent window leakage 
		DialogRegistration.register(contentView.getContext(), dialog);
		 
		return dialog;
	} 
 
	public void setDisplayUtils(DisplayUtils displayUtils) {