コード例 #1
0
 /**
  * Convert a cursor object from database to a user object
  *
  * @param cursor the result of a query to the database
  * @return the user object
  */
 public static Notification parse(Cursor cursor) {
   Notification notification = new Notification();
   notification.setId(cursor.getInt(0));
   notification.setUserFrom(cursor.getString(0));
   notification.setUserTo(User.parse(cursor));
   notification.setMessage(cursor.getString(1));
   notification.setType(TYPE.fromValue(cursor.getInt(0)));
   return notification;
 }
コード例 #2
0
  /**
   * Convert a json object from rest service to a user object
   *
   * @param token the token got by the rest service
   * @return the user object
   */
  public static Notification parse(JSONObject token) {
    try {
      Notification notification = new Notification();
      notification.setId(token.getInt("id"));
      notification.setUserFrom(token.getString("source"));
      notification.setMessage(token.getString("content"));
      notification.setType(stringToType(token.getString("type")));
      notification.setRead(token.getBoolean("read"));
      return notification;

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }
  }
コード例 #3
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    // Si la vue n'est pas recyclée
    if (convertView == null) {

      // On récupère le layout
      convertView = inflater.inflate(R.layout.item_notification, null);

      holder = new ViewHolder();
      // On place les widgets de notre layout dans le holder
      holder.username = (TextView) convertView.findViewById(R.id.username);
      holder.message = (TextView) convertView.findViewById(R.id.message);
      holder.type = (ImageView) convertView.findViewById(R.id.type);

      // puis on insère le holder en tant que tag dans le layout
      convertView.setTag(holder);

    } else {

      // Si on recycle la vue, on récupère son holder en tag
      holder = (ViewHolder) convertView.getTag();
    }

    // Dans tous les cas, on récupère la notification concerné.
    Notification notification = (Notification) getItem(position);
    // Si cet élément existe vraiment…
    if (notification != null) {
      // On place dans le holder les informations sur la notification.
      holder.username.setText(notification.getUserFrom());
      holder.message.setText(adaptString(notification.getMessage()));
      if (notification.getType().equals(TYPE.INFO)) {
        holder.type.setImageResource(R.drawable.info);
      } else if (notification.getType().equals(TYPE.FUEL)) {
        holder.type.setImageResource(R.drawable.fuel);
      } else if (notification.getType().equals(TYPE.INVITATION)) {
        holder.type.setImageResource(R.drawable.invitation);
      }
    }
    return convertView;
  }