Android Open Source - DivisionByZero Confirm Dialog






From Project

Back to project page DivisionByZero.

License

The source code is released under:

Apache License

If you think the Android project DivisionByZero 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.ggstudios.divisionbyzero;
// w ww  . j ava2s  .c om
import com.ggstudios.divisionbyzero.Button.OnClickListener;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;

public class ConfirmDialog extends BaseDialog {
  private static final String TAG = "ConfirmDialog";

  private static final float DIALOG_WIDTH = 10f;
  private static final float MARGIN = 0.5f;
  private static final float BUTTON_HEIGHT = 1.2f;
  
  private Label lblTitle, lblMsg;
  
  private String title, msg;
  
  private int buttonCount = 0;
  private boolean positiveExist = false, neutralExist = false, negativeExist = false;
  private Button btnPositive, btnNegative, btnNeutral;
  private String positiveText, neutralText, negativeText;
  private OnClickListener posListener, neuListener, negListener;
  
  private boolean built = false;
  
  private boolean titleExist = false;
  
  private RectF bound = new RectF();
  
  public ConfirmDialog() {
    super();
  }
  
  public void setTitle(String title) {
    this.title = title;
    
    titleExist = true;
    
    if(built) {
      lblTitle.setText(title);
    }
  } 
  
  public void setMessage(String message) {
    this.msg = message;
    
    if(built) {
      lblMsg.setText(title);
    }
  }
  
  public void setPositive(String text, OnClickListener listener) {
    if(!positiveExist){
      positiveExist = true;
      buttonCount++;
    }
    
    positiveText = text;
    posListener = listener;
    
    if(built) {
      btnPositive.setText(text);
      btnPositive.setOnClickListener(listener);
    }
  }
  
  public void setNeutral(String text, OnClickListener listener) {
    if(!neutralExist){
      neutralExist = true;
      buttonCount++;
    }
    
    neutralText = text;
    neuListener = listener;
    
    if(built) {
      btnNeutral.setText(text);
      btnNeutral.setOnClickListener(listener);
    }
  }
  
  public void setNegative(String text, OnClickListener listener) {
    if(!negativeExist){
      negativeExist = true;
      buttonCount++;
    }
    
    negativeText = text;
    negListener = listener;
    
    if(built) {
      btnNegative.setText(text);
      btnNegative.setOnClickListener(listener);
    }
  }
  
  public void build() {
    final float margin = MARGIN * Core.SDP;
    this.w = DIALOG_WIDTH * Core.SDP;
    
    setBackgroundTexture(R.drawable.panel);
    
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setTextSize(Core.SDP_H * 1.1f);
    paint.setAntiAlias(true);
    
    float l = margin;
    float t = margin;
    
    if(titleExist) {
      lblTitle = new Label(l, t, paint, title, w - (margin * 2));
      t += lblTitle.h;
    }
    lblMsg = new Label(l, t, paint, msg, w - (margin * 2));
    t += lblMsg.h;
    
    float btnH = BUTTON_HEIGHT * Core.SDP;
    float btnW = (w - margin * 2) / (buttonCount);

    this.h = t + btnH + margin * 2;
    
    t = h - margin - btnH;

    // let's match the dialog button placement with the version of the os...
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      // ICS and above button placement: Neg - Neu - Pos
      
      if(negativeExist) {
        btnNegative = new Button(l, t, btnW - margin / 2f, btnH, R.drawable.custom_button_bg, negativeText, paint);
        btnNegative.setOnClickListener(negListener);
        l += btnW;
      }
      
      if(neutralExist) {
        btnNeutral = new Button(l, t, btnW - margin / 2f, btnH, R.drawable.custom_button_bg, neutralText, paint);
        btnNeutral.setOnClickListener(neuListener);
        l += btnW;
      }
      
      if(positiveExist) {
        btnPositive = new Button(l + margin / 2f, t, btnW - margin / 2f, btnH, R.drawable.custom_button_bg, positiveText, paint);
        btnPositive.setOnClickListener(posListener);
      }
    } else {
      if(positiveExist) {
        btnPositive = new Button(l, t, btnW - margin / 2f, btnH, R.drawable.custom_button_bg, positiveText, paint);
        btnPositive.setOnClickListener(posListener);
        l += btnW;
      }
      
      if(neutralExist) {
        btnNeutral = new Button(l, t, btnW - margin / 2f, btnH, R.drawable.custom_button_bg, neutralText, paint);
        btnNeutral.setOnClickListener(neuListener);
        l += btnW;
      }
      
      if(negativeExist) {
        btnNegative = new Button(l + margin / 2f, t, btnW - margin / 2f, btnH, R.drawable.custom_button_bg, negativeText, paint);
        btnNegative.setOnClickListener(negListener);
      }
    }
    
    refresh();
    
    built = true;
    
    x = (Core.canvasWidth - w) / 2f;
    y = (Core.canvasHeight - h) / 2f;
    
    bound.left = 0;
    bound.top = 0;
    bound.right = w;
    bound.bottom = h;
  }
  
  @Override
  public void draw(float offX, float offY) {
    super.draw(0, 0);
    if(titleExist)
      lblTitle.draw(x, y);
    lblMsg.draw(x, y);
    
    btnPositive.draw(x, y);
    btnNegative.draw(x, y);
  }
  
  @Override
  public void refresh() {
    super.refresh();
    if(titleExist)
      lblTitle.refresh();
    lblMsg.refresh();
    
    if(positiveExist)
      btnPositive.refresh();
    if(neutralExist)
      btnNeutral.refresh();
    if(negativeExist)
      btnNegative.refresh();
  }
  
  @Override
  public boolean onTouchEvent(int action, float unusedX, float unusedY) {
    final float x = Core.originalTouchX - this.x;
    final float y = Core.originalTouchY - this.y;
    
    return btnPositive.onTouchEvent(action, x, y) ||
        btnNegative.onTouchEvent(action, x, y) ||
        bound.contains(x, y);
  }
}




Java Source Code List

com.ggstudios.divisionbyzero.ActivityAbout.java
com.ggstudios.divisionbyzero.ActivityLevelSelection.java
com.ggstudios.divisionbyzero.ActivityMainMenu.java
com.ggstudios.divisionbyzero.ActivitySettings.java
com.ggstudios.divisionbyzero.ActivitySplashScreen.java
com.ggstudios.divisionbyzero.ApplicationMain.java
com.ggstudios.divisionbyzero.BaseActivity.java
com.ggstudios.divisionbyzero.BaseDialog.java
com.ggstudios.divisionbyzero.BulletManager.java
com.ggstudios.divisionbyzero.Bullet.java
com.ggstudios.divisionbyzero.Button.java
com.ggstudios.divisionbyzero.Circle.java
com.ggstudios.divisionbyzero.ClickableCollection.java
com.ggstudios.divisionbyzero.Clickable.java
com.ggstudios.divisionbyzero.ConfirmDialog.java
com.ggstudios.divisionbyzero.Core.java
com.ggstudios.divisionbyzero.CustomGLSurfaceView.java
com.ggstudios.divisionbyzero.DialogManager.java
com.ggstudios.divisionbyzero.DrawableCollection.java
com.ggstudios.divisionbyzero.DrawableString.java
com.ggstudios.divisionbyzero.Drawable.java
com.ggstudios.divisionbyzero.EndDialog.java
com.ggstudios.divisionbyzero.Event.java
com.ggstudios.divisionbyzero.ExplosionGenerator.java
com.ggstudios.divisionbyzero.ExtrasManager.java
com.ggstudios.divisionbyzero.FontManager.java
com.ggstudios.divisionbyzero.GameRenderer.java
com.ggstudios.divisionbyzero.GameUpdater.java
com.ggstudios.divisionbyzero.Game.java
com.ggstudios.divisionbyzero.Grid.java
com.ggstudios.divisionbyzero.Hud.java
com.ggstudios.divisionbyzero.InGameMenu.java
com.ggstudios.divisionbyzero.InfoDialog.java
com.ggstudios.divisionbyzero.Label.java
com.ggstudios.divisionbyzero.LevelManager.java
com.ggstudios.divisionbyzero.LevelMap.java
com.ggstudios.divisionbyzero.LineGuide.java
com.ggstudios.divisionbyzero.MainActivity.java
com.ggstudios.divisionbyzero.Map.java
com.ggstudios.divisionbyzero.MessageDialog.java
com.ggstudios.divisionbyzero.ParticleEngine.java
com.ggstudios.divisionbyzero.PathFinder.java
com.ggstudios.divisionbyzero.PauseMenu.java
com.ggstudios.divisionbyzero.PictureBox.java
com.ggstudios.divisionbyzero.Player.java
com.ggstudios.divisionbyzero.PopupMenu.java
com.ggstudios.divisionbyzero.Rectangle.java
com.ggstudios.divisionbyzero.Shader.java
com.ggstudios.divisionbyzero.SpawnManager.java
com.ggstudios.divisionbyzero.SpriteAnimation.java
com.ggstudios.divisionbyzero.SpriteManager.java
com.ggstudios.divisionbyzero.Sprite.java
com.ggstudios.divisionbyzero.Statbar.java
com.ggstudios.divisionbyzero.StateManager.java
com.ggstudios.divisionbyzero.TargetRectangle.java
com.ggstudios.divisionbyzero.TextureManager.java
com.ggstudios.divisionbyzero.TowerInfoDialog.java
com.ggstudios.divisionbyzero.TowerLibrary.java
com.ggstudios.divisionbyzero.TowerManager.java
com.ggstudios.divisionbyzero.TowerMenu.java
com.ggstudios.divisionbyzero.Tower.java
com.ggstudios.divisionbyzero.UpdatableCollection.java
com.ggstudios.divisionbyzero.Updatable.java
com.ggstudios.divisionbyzero.UpgradeDialog.java
com.ggstudios.divisionbyzero.Utils.java
com.ggstudios.divisionbyzero.VBO.java
com.ggstudios.divisionbyzero.WaveControlDialog.java
com.ggstudios.divisionbyzero.WaveControlHud.java
com.ggstudios.divisionbyzero.ZoomControl.java
com.ggstudios.utils.BitmapUtils.java
com.ggstudios.utils.BufferUtils.java
com.ggstudios.utils.DebugLog.java
com.ggstudios.utils.ShaderUtils.java
com.ggstudios.widget.LevelMapBackground.java
fix.android.opengl.GLES20.java