Android Open Source - DroidSweeper Field View






From Project

Back to project page DroidSweeper.

License

The source code is released under:

MIT License

If you think the Android project DroidSweeper 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 de.nisble.droidsweeper.gui.grid;
/*from   ww  w  . j  a va2  s.co  m*/
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import de.nisble.droidsweeper.game.Field;
import de.nisble.droidsweeper.game.Position;
import de.nisble.droidsweeper.game.jni.FieldListener;
import de.nisble.droidsweeper.game.jni.FieldStatus;
import de.nisble.droidsweeper.game.jni.MineSweeperMatrix;
import de.nisble.droidsweeper.utilities.LogDog;

/** A FieldView is an ImageView responsible for showing the {@link FieldStatus
 * status} of a single field on the {@link GameGridView game grid}. It implements
 * the {@link FieldListener} interface and can therefore be registered in
 * {@link MineSweeperMatrix#setFieldListener(FieldListener)}. The
 * {@link FieldListener#onStatusChanged(FieldStatus, int)} is than directly
 * called from native code, causing this widget to change its appearance.
 * @author Moritz Nisbl moritz.nisble@gmx.de */
public class FieldView extends ImageView implements FieldListener {
  private static final String CLASSNAME = FieldView.class.getSimpleName();

  private Field mField = null;

  private void init() {
    mField = new Field(new Position(), FieldStatus.HIDDEN, 0);
    setImageDrawable(FieldDrawables.getDrawable(mField.STATUS, 0));
  }

  /** Constructor. */
  public FieldView(Context context) {
    this(context, null);
  }

  /** Constructor. */
  public FieldView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  /** Constructor. */
  public FieldView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
  }

  @Override
  public Position getPosition() {
    return mField.POSITION;
  }

  /** @return The current {@link FieldStatus}. */
  public FieldStatus getFieldStatus() {
    return mField.STATUS;
  }

  /** Reset the internal {@link FieldStatus} to {@link FieldStatus#HIDDEN
   * HIDDEN}, load the corresponding {@link FieldDrawables image} and the
   * {@link Position} to the given one.
   * @param p The new {@link Position}. */
  public void reset(Position p) {
    mField = new Field(p, FieldStatus.HIDDEN, 0);
    setImageDrawable(FieldDrawables.getDrawable(mField.STATUS, 0));
  }

  /* (non-Javadoc)
   * @see
   * de.nisble.droidsweeper.binding.FieldListener#onStatusChanged(de.nisble
   * .droidsweeper.binding.FieldStatus, int)
   * This method is directly called from native code. */
  @Override
  public void onStatusChanged(FieldStatus status, int adjacentBombs) {
    LogDog.d(CLASSNAME, "Changing status of " + mField.POSITION.toString() + " to " + status.toString());
    mField = new Field(mField.POSITION, status, adjacentBombs);
    setImageDrawable(FieldDrawables.getDrawable(status, adjacentBombs));
  }
}




Java Source Code List

de.nisble.droidsweeper.config.ApplicationConfig.java
de.nisble.droidsweeper.config.Constants.java
de.nisble.droidsweeper.config.GameConfig.java
de.nisble.droidsweeper.config.Level.java
de.nisble.droidsweeper.game.Field.java
de.nisble.droidsweeper.game.GameObserver.java
de.nisble.droidsweeper.game.Game.java
de.nisble.droidsweeper.game.Position.java
de.nisble.droidsweeper.game.database.DSDBAdapter.java
de.nisble.droidsweeper.game.database.DSDBContract.java
de.nisble.droidsweeper.game.database.DSDBGameEntry.java
de.nisble.droidsweeper.game.database.DSDBHelper.java
de.nisble.droidsweeper.game.jni.FieldListener.java
de.nisble.droidsweeper.game.jni.FieldStatus.java
de.nisble.droidsweeper.game.jni.GameStatus.java
de.nisble.droidsweeper.game.jni.MatrixObserver.java
de.nisble.droidsweeper.game.jni.MineSweeperMatrix.java
de.nisble.droidsweeper.game.replay.PlayerObserver.java
de.nisble.droidsweeper.game.replay.Player.java
de.nisble.droidsweeper.game.replay.Recorder.java
de.nisble.droidsweeper.game.replay.Replay.java
de.nisble.droidsweeper.game.replay.TimeStep.java
de.nisble.droidsweeper.gui.DroidSweeperActivity.java
de.nisble.droidsweeper.gui.HighScoreActivity.java
de.nisble.droidsweeper.gui.HighScoreListAdapter.java
de.nisble.droidsweeper.gui.SettingsActivity.java
de.nisble.droidsweeper.gui.grid.FieldDrawables.java
de.nisble.droidsweeper.gui.grid.FieldView.java
de.nisble.droidsweeper.gui.grid.GameGridView.java
de.nisble.droidsweeper.utilities.LogDog.java
de.nisble.droidsweeper.utilities.Timer.java