Android Open Source - client-android Event






From Project

Back to project page client-android.

License

The source code is released under:

Apache License

If you think the Android project client-android 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.qmonix.sdk;
// www  . j av  a 2  s  .com
import org.json.JSONObject;
import org.json.JSONException;

import com.qmonix.sdk.utils.Utils;


/**
 * Single event class that holds it's tag name and a and a single value - it's fire time. Every
 * different logic event must have a unique tag name. Two different event objects might have the
 * same names but their collected information will be aggregated. Event tag name might be retrieved
 * by {@link #getTag getTag}. {@link #getTimeArised getTimeArised} returns event fire time.
 * <p>
 * {@link #toJson toJson} encodes event information to JSON object.
 *
 * @see EventDispatcher
 */
public class Event {

  private boolean fired = false;

  protected long timeArised;
  protected String tag;


  /**
   * Constructs new single event with a specified tag name and Unix time stamp when it was
   * fired.
   *
   * @param tag event tag name.
   * @param timeArised time when event was fired.
   */
  public Event(String tag, long timeArised) {
    if (tag == null) {
      throw new IllegalArgumentException("Tag name cannot be null.");
    }

    this.tag = tag;
    this.timeArised = timeArised;
  }

  /**
   * @return event tag name.
   */
  public String getTag() {
    return this.tag;
  }

  /**
   * Returns time when event was fired.
   *
   * @return event fire time.
   */
  public long getTimeArised() {
    return this.timeArised;
  }

  /**
   * Serializes event to JSON object which is ready to be encoded to event message. Event
   * fire time and tag name are used.
   *
   * @return event encoded in JSON format.
   * @throws JSONException if fails to encode event message to JSON object.
   */
  public JSONObject toJson() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("tag", this.getTag());
    json.put("whenArised", this.getTimeArised());

    return json;
  }
}




Java Source Code List

com.qmonix.sample.basic.MainActivity.java
com.qmonix.sdk.EventDispatchHandler.java
com.qmonix.sdk.EventDispatcher.java
com.qmonix.sdk.EventMessage.java
com.qmonix.sdk.Event.java
com.qmonix.sdk.FireableTimingEvent.java
com.qmonix.sdk.HttpEventDispatcher.java
com.qmonix.sdk.LogEventDispatcher.java
com.qmonix.sdk.QLog.java
com.qmonix.sdk.TimingEvent.java
com.qmonix.sdk.Tracker.java
com.qmonix.sdk.VolumeEvent.java
com.qmonix.sdk.helpers.HttpHelper.java
com.qmonix.sdk.helpers.exceptions.HttpHelperException.java
com.qmonix.sdk.utils.AsyncTaskResult.java
com.qmonix.sdk.utils.Utils.java