Ejemplo n.º 1
0
  public void setStatusFromConfig() {
    // TODO: only call this when carbons changed, not on every presence change
    CarbonManager.getInstanceFor(mXMPPConnection).sendCarbonsEnabled(mConfig.messageCarbons);

    Presence presence = new Presence(Presence.Type.available);
    Mode mode = Mode.valueOf(mConfig.statusMode);
    presence.setMode(mode);
    presence.setStatus(mConfig.statusMessage);
    presence.setPriority(mConfig.priority);
    mXMPPConnection.sendPacket(presence);
    mConfig.presence_required = false;
  }
Ejemplo n.º 2
0
  public void setStatusFromConfig() {
    CarbonManager.getInstanceFor(extXMPPConnection)
        .sendCarbonsEnabled(configuration.messageCarbons);

    Presence presence = new Presence(Presence.Type.available);
    Mode mode = Mode.valueOf(configuration.statusMode);
    presence.setMode(mode);
    presence.setStatus(configuration.statusMessage);
    presence.setPriority(configuration.priority);
    extXMPPConnection.sendPacket(presence);
    configuration.presence_required = false;
  }
 /** {@inheritDoc} */
 @Override
 public void changeStatusAndPriority(int status, String msg, int priority) {
   Presence pres = new Presence(Presence.Type.available);
   String m;
   if (msg != null) m = msg;
   else m = mPreviousStatus;
   pres.setStatus(m);
   mPreviousStatus = m;
   Presence.Mode mode = Status.getPresenceModeFromStatus(status);
   if (mode != null) {
     pres.setMode(mode);
     mPreviousMode = status;
   } else {
     pres.setMode(Status.getPresenceModeFromStatus(mPreviousMode));
   }
   int p = priority;
   if (priority < SMACK_PRIORITY_MIN) p = SMACK_PRIORITY_MIN;
   if (priority > SMACK_PRIORITY_MAX) p = SMACK_PRIORITY_MAX;
   mPreviousPriority = p;
   pres.setPriority(p);
   mAdaptee.sendPacket(pres);
   updateNotification(m);
 }
Ejemplo n.º 4
0
  /**
   * Parses a presence packet.
   *
   * @param parser the XML parser, positioned at the start of a presence packet.
   * @return a Presence packet.
   * @throws Exception if an exception occurs while parsing the packet.
   */
  public static Presence parsePresence(XmlPullParser parser) throws Exception {
    Presence.Type type = Presence.Type.available;
    String typeString = parser.getAttributeValue("", "type");
    if (typeString != null && !typeString.equals("")) {
      try {
        type = Presence.Type.valueOf(typeString);
      } catch (IllegalArgumentException iae) {
        System.err.println("Found invalid presence type " + typeString);
      }
    }
    Presence presence = new Presence(type);
    presence.setTo(parser.getAttributeValue("", "to"));
    presence.setFrom(parser.getAttributeValue("", "from"));
    String id = parser.getAttributeValue("", "id");
    presence.setPacketID(id == null ? Packet.ID_NOT_AVAILABLE : id);

    String language = getLanguageAttribute(parser);
    if (language != null && !"".equals(language.trim())) {
      presence.setLanguage(language);
    }
    presence.setPacketID(id == null ? Packet.ID_NOT_AVAILABLE : id);

    // Parse sub-elements
    boolean done = false;
    while (!done) {
      int eventType = parser.next();
      if (eventType == XmlPullParser.START_TAG) {
        String elementName = parser.getName();
        String namespace = parser.getNamespace();
        if (elementName.equals("status")) {
          presence.setStatus(parser.nextText());
        } else if (elementName.equals("priority")) {
          try {
            int priority = Integer.parseInt(parser.nextText());
            presence.setPriority(priority);
          } catch (NumberFormatException nfe) {
            // Ignore.
          } catch (IllegalArgumentException iae) {
            // Presence priority is out of range so assume priority to be zero
            presence.setPriority(0);
          }
        } else if (elementName.equals("show")) {
          String modeText = parser.nextText();
          try {
            presence.setMode(Presence.Mode.valueOf(modeText));
          } catch (IllegalArgumentException iae) {
            System.err.println("Found invalid presence mode " + modeText);
          }
        } else if (elementName.equals("error")) {
          presence.setError(parseError(parser));
        } else if (elementName.equals("properties") && namespace.equals(PROPERTIES_NAMESPACE)) {
          Map<String, Object> properties = parseProperties(parser);
          // Set packet properties.
          for (String name : properties.keySet()) {
            presence.setProperty(name, properties.get(name));
          }
        }
        // Otherwise, it must be a packet extension.
        else {
          try {
            presence.addExtension(
                PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
          } catch (Exception e) {
            System.err.println("Failed to parse extension packet in Presence packet.");
          }
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        if (parser.getName().equals("presence")) {
          done = true;
        }
      }
    }
    return presence;
  }