Android Open Source - QustomDialog Qustom Dialog Builder






From Project

Back to project page QustomDialog.

License

The source code is released under:

Apache License

If you think the Android project QustomDialog listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.qustom.dialog;
//from w ww .  j ava  2s  .  c o  m
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.qustom.dialog.R;

public class QustomDialogBuilder extends AlertDialog.Builder{

  /** The custom_body layout */
  private View mDialogView;
  
  /** optional dialog title layout */
  private TextView mTitle;
  /** optional alert dialog image */
  private ImageView mIcon;
  /** optional message displayed below title if title exists*/
  private TextView mMessage;
  /** The colored holo divider. You can set its color with the setDividerColor method */
  private View mDivider;
  
    public QustomDialogBuilder(Context context) {
        super(context);

        mDialogView = View.inflate(context, R.layout.qustom_dialog_layout, null);
        setView(mDialogView);

        mTitle = (TextView) mDialogView.findViewById(R.id.alertTitle);
        mMessage = (TextView) mDialogView.findViewById(R.id.message);
        mIcon = (ImageView) mDialogView.findViewById(R.id.icon);
        mDivider = mDialogView.findViewById(R.id.titleDivider);
  }

    /** 
     * Use this method to color the divider between the title and content.
     * Will not display if no title is set.
     * 
     * @param colorString for passing "#ffffff"
     */
    public QustomDialogBuilder setDividerColor(String colorString) {
      mDivider.setBackgroundColor(Color.parseColor(colorString));
      return this;
    }
 
    @Override
    public QustomDialogBuilder setTitle(CharSequence text) {
        mTitle.setText(text);
        return this;
    }

    public QustomDialogBuilder setTitleColor(String colorString) {
      mTitle.setTextColor(Color.parseColor(colorString));
      return this;
    }

    @Override
    public QustomDialogBuilder setMessage(int textResId) {
        mMessage.setText(textResId);
        return this;
    }

    @Override
    public QustomDialogBuilder setMessage(CharSequence text) {
        mMessage.setText(text);
        return this;
    }

    @Override
    public QustomDialogBuilder setIcon(int drawableResId) {
        mIcon.setImageResource(drawableResId);
        return this;
    }

    @Override
    public QustomDialogBuilder setIcon(Drawable icon) {
        mIcon.setImageDrawable(icon);
        return this;
    }
    
    /**
     * This allows you to specify a custom layout for the area below the title divider bar
     * in the dialog. As an example you can look at example_ip_address_layout.xml and how
     * I added it in TestDialogActivity.java
     * 
     * @param resId  of the layout you would like to add
     * @param context
     */
    public QustomDialogBuilder setCustomView(int resId, Context context) {
      View customView = View.inflate(context, resId, null);
      ((FrameLayout)mDialogView.findViewById(R.id.customPanel)).addView(customView);
      return this;
    }
    
    @Override
    public AlertDialog show() {
      if (mTitle.getText().equals("")) mDialogView.findViewById(R.id.topPanel).setVisibility(View.GONE);
      return super.show();
    }

}




Java Source Code List

com.qustom.dialog.QustomDialogBuilder.java
com.qustom.dialog.TestDialogActivity.java