Android Open Source - Gamework Message






From Project

Back to project page Gamework.

License

The source code is released under:

Apache License

If you think the Android project Gamework 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 cz.robyer.gamework.scenario.message;
//from   w w  w.  j av  a 2s.  c o  m
import java.io.IOException;
import java.io.InputStream;

import android.util.Log;
import cz.robyer.gamework.game.GameEvent;
import cz.robyer.gamework.game.GameEvent.EventType;
import cz.robyer.gamework.game.GameHandler;
import cz.robyer.gamework.scenario.IdentificableObject;

/**
 * Represents in-game message.
 * @author Robert P?sel
 */
public class Message extends IdentificableObject {
  protected String tag;
  protected String title;
  protected String value;
  protected MessageStatus status;
  protected long received;
  
  public static enum MessageStatus {NONE, UNREAD, READ, DELETED}
  
  /**
   * Class constructor
   * @param id - identificator of message
   * @param title - title of message
   * @param value - text or path to file with content of message
   */
  public Message(String id, String tag, String title, String value, boolean def) {
    super(id);
    this.title = title;
    this.tag = (tag == null ? "" : tag);
    this.value = value;
    this.status = def ? MessageStatus.UNREAD : MessageStatus.NONE;
  }
  
  /**
   * Sets status of this message.
   * @param status to be set
   */
  public void setStatus(MessageStatus status) {
    this.status = status;
  }
  
  /**
   * Returns actual status of this message.
   * @return actual status
   */
  public MessageStatus getStatus() {
    return status;
  }
  
  /**
   * Returns tag of this message.
   * @return tag
   */
  public String getTag() {
    return tag;
  }
  
  /**
   * Returns title of this message
   * @return title
   */
  public String getTitle() {
    return title;
  }
  
  /**
   * Returns content of text file in assets, which path is represented by value.
   * @return text of message
   */
  public String getContent() {
    InputStream stream = null;
    String content = null;
    try {
      stream = getContext().getAssets().open(value);
      int size = stream.available();
            byte[] buffer = new byte[size];
            stream.read(buffer);
            content = new String(buffer);
    } catch (IOException e) {
      Log.e(TAG, String.format("Can't load file '%s'", value));
    } finally {
      try {
            if (stream != null)
              stream.close();
          } catch (IOException ioe) {
            Log.e(TAG, ioe.getMessage(), ioe);
          }
    }
    return content;
  }
  
  /**
   * Return time when this message was received.
   * @return long timestamp
   */
  public long getReceived() {
    return received;
  }
  
  /**
   * Returns value of this message.
   * @return value
   */
  public String getValue() {
    return value;
  }
  
  /**
   * Checks if this message is received and not deleted.
   * @return true if message is visible, false otherwise
   */
  public boolean isVisible() {
    return (status != MessageStatus.NONE) && (status != MessageStatus.DELETED);
  }
  
  /**
   * Receive this message - marks as unread if not visible yet.
   */
  public void activate() {
    if (status == MessageStatus.NONE) {
      GameHandler handler = getScenario().getHandler();
      
      status = MessageStatus.UNREAD;
      received = handler.getGameTime();
      handler.broadcastEvent(new GameEvent(EventType.UPDATED_MESSAGES, id));
    }
  }
  
}




Java Source Code List

cz.robyer.gamework.app.activity.BaseActivity.java
cz.robyer.gamework.app.activity.BaseGameActivity.java
cz.robyer.gamework.app.activity.GameInventoryActivity.java
cz.robyer.gamework.app.activity.GameMapActivity.java
cz.robyer.gamework.app.activity.GameMessagesActivity.java
cz.robyer.gamework.app.activity.GameObjectivesActivity.java
cz.robyer.gamework.app.activity.GameToolsActivity.java
cz.robyer.gamework.app.activity.HelpActivity.java
cz.robyer.gamework.app.activity.MainActivity.java
cz.robyer.gamework.app.activity.MessageActivity.java
cz.robyer.gamework.app.game.GameService.java
cz.robyer.gamework.app.service.JavaScriptHandler.java
cz.robyer.gamework.app.service.MessageAdapter.java
cz.robyer.gamework.constants.Constants.java
cz.robyer.gamework.game.GameEventBroadcaster.java
cz.robyer.gamework.game.GameEventListener.java
cz.robyer.gamework.game.GameEvent.java
cz.robyer.gamework.game.GameHandler.java
cz.robyer.gamework.game.GameService.java
cz.robyer.gamework.game.GameStatus.java
cz.robyer.gamework.scenario.BaseObject.java
cz.robyer.gamework.scenario.HookableObject.java
cz.robyer.gamework.scenario.IdentificableObject.java
cz.robyer.gamework.scenario.ScenarioInfo.java
cz.robyer.gamework.scenario.Scenario.java
cz.robyer.gamework.scenario.area.Area.java
cz.robyer.gamework.scenario.area.MultiPointArea.java
cz.robyer.gamework.scenario.area.PointArea.java
cz.robyer.gamework.scenario.area.SoundArea.java
cz.robyer.gamework.scenario.helper.EventHookable.java
cz.robyer.gamework.scenario.helper.ScannerHookable.java
cz.robyer.gamework.scenario.helper.TimeHookable.java
cz.robyer.gamework.scenario.hook.Condition.java
cz.robyer.gamework.scenario.hook.Hook.java
cz.robyer.gamework.scenario.message.Message.java
cz.robyer.gamework.scenario.parser.XmlScenarioParser.java
cz.robyer.gamework.scenario.reaction.ActivityReaction.java
cz.robyer.gamework.scenario.reaction.EventReaction.java
cz.robyer.gamework.scenario.reaction.MessageReaction.java
cz.robyer.gamework.scenario.reaction.MultiReaction.java
cz.robyer.gamework.scenario.reaction.Reaction.java
cz.robyer.gamework.scenario.reaction.ReferenceReaction.java
cz.robyer.gamework.scenario.reaction.SoundReaction.java
cz.robyer.gamework.scenario.reaction.VariableReaction.java
cz.robyer.gamework.scenario.reaction.VibrateReaction.java
cz.robyer.gamework.scenario.variable.BooleanVariable.java
cz.robyer.gamework.scenario.variable.DecimalVariable.java
cz.robyer.gamework.scenario.variable.Variable.java
cz.robyer.gamework.utils.GPoint.java
cz.robyer.gamework.utils.Log.java
cz.robyer.gamework.utils.Utils.java