Android Open Source - QCircle-Design-Template Q Circle Dialog






From Project

Back to project page QCircle-Design-Template.

License

The source code is released under:

QCircle Design Template Library Project Contributor License Agreement By making a contribution to this QCircle Design Template Library Project (??Project??), I accept and agree to the following term...

If you think the Android project QCircle-Design-Template 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.lge.qcircle.template;
/* ww  w. ja  v a2  s.  c om*/
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * The {@code QCircleDialog} class provides a Dialog for Quick Circle.<P>
 * It cannot be instantiated by a constructor.
 * Use {@link com.lge.qcircle.template.QCircleDialog.Builder} instead.<P>
 * Created by Yoav.
 * @author Yoav Sternberg
 */
public class QCircleDialog {
  Activity activity;
  QCircleTemplate activityTemplate;
  // Dialog properties
  String title;
  String text;
  String positiveButtonText;
  String negativeButtonText;
  Drawable image;
  View.OnClickListener positiveButtonListener;
  View.OnClickListener negativeButtonListener;
  DialogMode mode;
  View templateLayout;

    /**
     * private constructor.
     * @param builder
     */
  private QCircleDialog(Builder builder) {
    this.title = builder.title;
    this.text = builder.text;
    this.positiveButtonText = builder.positiveButtonText;
    this.negativeButtonText = builder.negativeButtonText;
    this.image = builder.image;
    this.positiveButtonListener = builder.positiveButtonListener;
    this.negativeButtonListener = builder.negativeButtonListener;
    this.mode = builder.mode;
  }

    /**
     * The {@code QCircleDialog.Builder} class is a builder to create a Dialog for Quick Circle.
     * @author Yoav Sternberg
     */
  public static class Builder {
    private String title = null;
    private String text;
    private String positiveButtonText;
    private String negativeButtonText;
    private Drawable image = null;
    private View.OnClickListener positiveButtonListener;
    private View.OnClickListener negativeButtonListener = null;
    private QCircleDialog.DialogMode mode = DialogMode.Ok;

        /**
         * sets title of the Dialog.<P>
         *
         * @param title text of the title. It will be displayed on the top of the dialog.
         * @return a Builder with title text
         */
    public Builder setTitle(String title) {
      this.title = title;
      return this;
    }

        /**
         * sets main text of the dialog.<P>
         * @param text main text. It will be displayed on the middle of the dialog.
         * @return a Builder with main text
         */
    public Builder setText(String text) {
      this.text = text;
      return this;
    }

        /**
         * sets main image of the dialog.<P>
         *
         * @param image main image as a Drawable. It will be displayed on the bottom of the main text.
         * @return a Builder with main image
         */
    public Builder setImage(Drawable image) {
      this.image = image;
      return this;
    }

        /**
         * sets a listener for positive button.
         * @param positiveButtonListener    lister to set
         * @return a Builder with the listener for positive button
         */
    public Builder setPositiveButtonListener(View.OnClickListener positiveButtonListener) {
      this.positiveButtonListener = positiveButtonListener;
      return this;
    }

        /**
         * sets a listener for negative button.
         * @param negativeButtonListener    listener to set
         * @return a Builder with the listener for negative button
         */
    public Builder setNegativeButtonListener(View.OnClickListener negativeButtonListener) {
      this.negativeButtonListener = negativeButtonListener;
      return this;
    }

        /**
         * sets a mode fot eh dialog.
         * @param mode  dialog mode. see {@link com.lge.qcircle.template.QCircleDialog.DialogMode}.
         * @return a Builder with the dialog mode.
         */
    public Builder setMode(QCircleDialog.DialogMode mode) {
      this.mode = mode;
      return this;
    }

        /**
         * sets a text for positive button.
         * @param positiveButtonText    text for positive button
         */
    public void setPositiveButtonText(String positiveButtonText) {
      this.positiveButtonText = positiveButtonText;
    }

        /**
         * sets a text for negative button.
         * @param negativeButtonText    text for negative button
         */
    public void setNegativeButtonText(String negativeButtonText) {
      this.negativeButtonText = negativeButtonText;
    }

        /**
         * creates a dialog.<P>
         * It should be called when setting of the dialog is done by the Builder.
         * @return  a dialog created by the Builder.
         */
    public QCircleDialog create() {
      return new QCircleDialog(this);
    }
  }

  /**
   * Show the dialog
   *
   * @param activity         The activity
   * @param activityTemplate The template that the activity uses
   */
  public void show(final Activity activity, QCircleTemplate activityTemplate) {
    this.activity = activity;
    this.activityTemplate = activityTemplate;
    RelativeLayout layout = (RelativeLayout) activityTemplate.getLayoutById(TemplateTag.CONTENT).getParent();
    final QCircleTemplate template = new QCircleTemplate(activity);
    template.setTitle(title == null ? "" : title, Color.WHITE, activity.getResources().getColor(
        mode == DialogMode.Error ? R.color.dialog_title_background_color_error : R.color.dialog_title_background_color_regular));
    template.setTitleTextSize(17);
    RelativeLayout dialogLayout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.qcircle_dialog_layout, layout, false);
    if (text != null) {
      ((TextView) dialogLayout.findViewById(R.id.text)).setText(text);
    }
    if (image != null) {
      ((ImageView) dialogLayout.findViewById(R.id.image)).setImageDrawable(image);
    }
    switch (mode) {
      case YesNo:
        Button negativeButton = (Button) dialogLayout.findViewById(R.id.negative);
        if (negativeButtonText != null) {
          negativeButton.setText(negativeButtonText);
        }
        negativeButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (negativeButtonListener != null) negativeButtonListener.onClick(v);
            hide();
          }
        });
      case Ok:
        Button positiveButton = (Button) dialogLayout.findViewById(R.id.positive);
        if (positiveButtonText != null) {
          positiveButton.setText(positiveButtonText);
        }
        positiveButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (positiveButtonListener != null) positiveButtonListener.onClick(v);
            hide();
          }
        });
        break;
      case Error:
        @SuppressLint("CutPasteId")
        Button errorButton = (Button) dialogLayout.findViewById(R.id.positive);
        if (negativeButtonText != null) {
          errorButton.setText(negativeButtonText);
        }
        errorButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (negativeButtonListener != null) negativeButtonListener.onClick(v);
//            template.unregisterReceiver();
            activity.finish();
          }
        });
        break;

    }
    if (mode != DialogMode.YesNo)
      dialogLayout.findViewById(R.id.negative).setVisibility(View.GONE);
    template.getLayoutById(TemplateTag.CONTENT).addView(dialogLayout);
    layout.addView(templateLayout = template.getView());

  }

    /**
     * hides the dialog.
     */
  public void hide() {
    ((RelativeLayout) activityTemplate.getLayoutById(TemplateTag.CONTENT).getParent()).removeView(templateLayout);
    templateLayout = null;
  }

    /**
     * The {@code DialogMode} enumerates modes which are
     * supported by {@link com.lge.qcircle.template.QCircleDialog}.
     */
  public enum DialogMode {
    /**
     * A dialog with yes and no buttons.
     */
    YesNo,
    /**
     * A dialog with ok button only.
     */
    Ok,
    /**
     * An error dialog. Shows only back button, which finish the activity.
     */
    Error
  }
}




Java Source Code List

com.lge.qcircle.template.QCircleBackButton.java
com.lge.qcircle.template.QCircleDialog.java
com.lge.qcircle.template.QCircleTemplate.java
com.lge.qcircle.template.QCircleTitle.java
com.lge.qcircle.template.TemplateTag.java
com.lge.qcircle.template.TemplateType.java
com.lge.qcircle.template.sample.SimpleCircle.FullActivity.java
com.lge.qcircle.template.sample.SimpleCircle.MainActivity.java
com.lge.qcircle.template.sample.beanbirdInCircle.QCircleActivity.java