Android Open Source - growthpush-android Event






From Project

Back to project page growthpush-android.

License

The source code is released under:

Apache License

If you think the Android project growthpush-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.growthpush.model;
/*  w  w w  . j ava  2s.c  o  m*/
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.growthpush.GrowthPush;

/**
 * Created by Shigeru Ogawa on 13/08/12.
 */
public class Event extends Model {

  private int goalId;
  private String name;
  private long timeStamp;
  private long clientId;
  private String value;

  public Event() {
    super();
  }

  public Event(String name, String value) {
    this();
    setName(name);
    setValue(value);
  }

  public Event save(GrowthPush growthPush) {

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("clientId", growthPush.getClient().getId());
    params.put("code", growthPush.getClient().getCode());
    params.put("name", name);
    params.put("value", value);

    JSONObject jsonObject = post("events", params);
    if (jsonObject != null)
      setJsonObject(jsonObject);

    return this;

  }

  public int getGoalId() {
    return goalId;
  }

  public void setGoalId(int goalId) {
    this.goalId = goalId;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public long getTimeStamp() {
    return timeStamp;
  }

  public void setTimeStamp(long timeStamp) {
    this.timeStamp = timeStamp;
  }

  public long getClientId() {
    return clientId;
  }

  public void setClientId(long clientId) {
    this.clientId = clientId;
  }

  public String getValue() {
    return value;
  }

  public void setValue(String value) {
    this.value = value;
  }

  private void setJsonObject(JSONObject jsonObject) {

    try {
      if (jsonObject.has("goalId"))
        setGoalId(jsonObject.getInt("goalId"));
      if (jsonObject.has("timestamp"))
        setTimeStamp(jsonObject.getLong("timestamp"));
      if (jsonObject.has("clientId"))
        setClientId(jsonObject.getLong("clientId"));
      if (jsonObject.has("value"))
        setValue(jsonObject.getString("value"));
    } catch (JSONException e) {
      throw new IllegalArgumentException("Failed to parse JSON.");
    }

  }

}




Java Source Code List

com.growthpush.BroadcastReceiver.java
com.growthpush.GrowthPushException.java
com.growthpush.GrowthPush.java
com.growthpush.Logger.java
com.growthpush.Preference.java
com.growthpush.Thread.java
com.growthpush.bridge.ExternalFrameworkBridge.java
com.growthpush.bridge.ExternalFrameworkBroadcastReceiver.java
com.growthpush.growthpushsample.MainActivity.java
com.growthpush.handler.BaseReceiveHandler.java
com.growthpush.handler.DefaultReceiveHandler.java
com.growthpush.handler.OnlyAlertReceiveHandler.java
com.growthpush.handler.OnlyNotificationReceiveHandler.java
com.growthpush.handler.ReceiveHandler.java
com.growthpush.model.ClientStatus.java
com.growthpush.model.Client.java
com.growthpush.model.Environment.java
com.growthpush.model.Error.java
com.growthpush.model.Event.java
com.growthpush.model.Model.java
com.growthpush.model.Tag.java
com.growthpush.utils.DeviceUtils.java
com.growthpush.utils.IOUtils.java
com.growthpush.utils.PermissionUtils.java
com.growthpush.utils.SystemUtils.java
com.growthpush.view.AlertActivity.java
com.growthpush.view.AlertFragment.java
com.growthpush.view.DialogCallback.java