예제 #1
0
  @Override
  public View getView(final int position, View reuse, ViewGroup parent) {
    // TODO Auto-generated method stub
    if (reuse != null) {

      message = (TextView) reuse.findViewById(R.id.msg_read_body);
      postedBy = (TextView) reuse.findViewById(R.id.msg_read_posted_by);
      // postedDate = (TextView)reuse.findViewById(R.id.msg_read_posted_date);

      final Message msg = msgList.get(position);

      // Refreshing Values

      postedBy.setText(msg.getPostedFrom());
      // postedDate.setText(msg.getPostedDate());
      message.setText(msg.getMessage());

      return reuse;
    } else {
      ViewGroup item = getViewGroup(reuse, parent);
      message = (TextView) item.findViewById(R.id.msg_read_body);
      postedBy = (TextView) item.findViewById(R.id.msg_read_posted_by);
      // postedDate = (TextView)item.findViewById(R.id.msg_read_posted_date);

      final Message msg = msgList.get(position);

      // Refreshing Values
      postedBy.setText(msg.getPostedFrom());
      // postedDate.setText(msg.getPostedDate());
      message.setText(msg.getMessage());
      return item;
    }
  }
예제 #2
0
파일: Searcher.java 프로젝트: okamilex/sp
 public void searchAll() {
   boolean thereIsMessage = false;
   System.out.println("search for:");
   String forSearch;
   forSearch = "";
   boolean incorrectExpression = false;
   try {
     forSearch = reader.readLine();
   } catch (IOException e) {
     System.out.println("Can't read this");
   }
   for (Message it : messageList) {
     if (it.getAuthor().equals(forSearch)) {
       System.out.println(it.toString());
       thereIsMessage = true;
       continue;
     }
     if (it.getMessage().contains(forSearch)) {
       System.out.println(it.toString());
       thereIsMessage = true;
       continue;
     }
     try {
       Pattern p = Pattern.compile(forSearch);
       Matcher m = p.matcher(it.getMessage());
       if (m.find()) {
         thereIsMessage = true;
         System.out.println(it.toString());
       }
     } catch (PatternSyntaxException e) {
       if (!incorrectExpression) {
         System.out.println("Incorrect expression: \n" + e.getMessage());
         incorrectExpression = true;
       }
     }
   }
   if (!thereIsMessage) {
     System.out.println("There isn't any message from this author");
     logWriter.write(
         (new Date()).toString()
             + " | "
             + "Search by all: "
             + forSearch
             + " |Nothing was found "
             + ""
             + "\n");
   } else {
     logWriter.write(
         (new Date()).toString()
             + " | "
             + "Search by all: "
             + forSearch
             + " |Successfully "
             + ""
             + "\n");
   }
 }
    @Override
    public int compare(final Message msg1, final Message msg2) {
      int ret;

      ret = msg1.getDomain().compareTo(msg2.getDomain());
      if (ret != 0) return ret;
      ret = msg1.getKeyword().compareTo(msg2.getKeyword());
      if (ret != 0) return ret;
      return msg1.getMessage().compareTo(msg2.getMessage());
    }
 @SuppressLint("ResourceAsColor")
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View view = convertView;
   ViewHolder holder = new ViewHolder();
   // Setting image for stamp
   if (view == null) {
     holder = new ViewHolder();
     view = mLayoutInflater.inflate(R.layout.item, null);
     holder.txtSender = (TextView) view.findViewById(R.id.txt_sender);
     holder.txtMessage = (TextView) view.findViewById(R.id.txt_message);
     holder.wrapper = (LinearLayout) view.findViewById(R.id.wrapper);
     view.setTag(holder);
   } else {
     holder = (ViewHolder) view.getTag();
   }
   Message message = mMessages.get(position);
   if (message == null) return view;
   holder.txtMessage.setText("");
   //		holder.txtSender.setText("");
   holder.txtSender.setText(message.getSender() + ":");
   if (message.isMine()) {
     holder.txtSender.setVisibility(View.INVISIBLE);
   } else {
     holder.txtSender.setVisibility(View.VISIBLE);
   }
   holder.txtMessage.setText(message.getMessage());
   holder.txtMessage.setBackgroundResource(
       message.isMine() ? R.drawable.bubble_green : R.drawable.bubble_yellow);
   holder.wrapper.setGravity(message.isMine() ? Gravity.RIGHT : Gravity.LEFT);
   return view;
 }
 @Override
 public String then() {
   System.out.println(message.getMessage());
   message.setMessage("oodbyte cruel world");
   message.setStatus(Message.GOODBYE);
   return null;
 }
  @SuppressLint("InflateParams")
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    /**
     * The following list not implemented reusable list items as list items are showing incorrect
     * data Add the solution if you have one
     */
    Message m = messagesItems.get(position);

    LayoutInflater mInflater =
        (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    // Identifying the message owner
    if (messagesItems.get(position).isSelf()) {
      // message belongs to you, so load the right aligned layout
      convertView = mInflater.inflate(R.layout.message_right, null);
    } else {
      // message belongs to other person, load the left aligned layout
      convertView = mInflater.inflate(R.layout.message_left, null);
    }

    TextView lblFrom = (TextView) convertView.findViewById(R.id.lblMsgFrom);
    TextView txtMsg = (TextView) convertView.findViewById(R.id.txtMsg);

    txtMsg.setText(m.getMessage());
    lblFrom.setText(m.getFromName());

    return convertView;
  }
예제 #7
0
 /**
  * Simple annotated class that demonstrate how {@link org.atmosphere.config.managed.Encoder} and {@link org.atmosphere.config.managed.Decoder
  * can be used.
  *
  * @param message an instance of {@link Message}
  * @return
  * @throws IOException
  */
 @org.atmosphere.config.service.Message(
     encoders = {JacksonEncoder.class},
     decoders = {JacksonDecoder.class})
 public Message onMessage(Message message) throws IOException {
   logger.info("{} just send {}", message.getAuthor(), message.getMessage());
   return message;
 }
예제 #8
0
    @Override
    public void run() {
      try {
        Message msgToSend = messages.take();

        Client[] copyOfClients;
        synchronized (clients) {
          copyOfClients = new Client[clients.size()];
          for (int i = 0; i < copyOfClients.length; i++) {
            copyOfClients[i] = clients.take();
            clients.add(copyOfClients[i]);
          }
        }

        for (int i = 0; i < copyOfClients.length; i++) {
          BufferedWriter writer = copyOfClients[i].getWriter();
          writer.write(msgToSend.getMessage());
          writer.newLine();
          writer.flush();
        }
        pool.submit(this);
      } catch (InterruptedException | IOException e) {
        e.printStackTrace();
      }
      pool.execute(this);
    }
예제 #9
0
 /**
  * Deliver a message to the group.
  *
  * @message the message to send
  * @return true if it was successfully sent to all members
  */
 public synchronized boolean deliverMessage(Message message) {
   boolean rv = true;
   /*
    * deliver to the output queues of all the group members
    *
    * synchronization: called within the monitor
    */
   // message.groupid=this.gid;
   for (BaseUser c : m_members) {
     ChatUser cu = (ChatUser) c;
     if (cu.isActive()) {
       try {
         System.out.println("sending to: " + cu.getUserName());
         cu.write(message);
       } catch (Exception e) {
         e.printStackTrace();
       }
       // rv = c.deliverMessage(message) && rv;
     } else {
       // rv = false;
       try {
         server.db.sendOfflineGroupMessage(
             cu.userid, this.gid, message.getSrc(), message.getMessage());
       } catch (SQLException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }
   }
   return rv;
 }
예제 #10
0
  public String getMessage() {
    if (messageBean != null) {
      message = messageBean.getMessage();
    }

    return message;
  }
 @Override
 public void error(Message message) {
   out.format("   File \"%s\", line %d:%d\n", "<stdin>", message.getLine(), message.getPosition());
   out.println("     " + message.currentLine());
   for (int n = 0; n < message.getPosition() + 4; n++) {
     out.print(" ");
   }
   out.println("^");
   out.format(
       message.getType().toString() + ": " + message.getMessage() + "\n\n", message.getArgs());
 }
예제 #12
0
 protected final void logMessage(final Message message) {
   final BotEvent event = message.getEvent();
   final String sender = getNick();
   final String channel = event.getChannel();
   if (!channel.equals(sender)) {
     if (channelDao.isLogged(channel)) {
       logsDao.logMessage(
           Logs.Type.MESSAGE, sender, message.getDestination(), message.getMessage());
     }
   }
 }
예제 #13
0
  public List<Message> deleteMessage(String message) {
    List<Message> list = new ArrayList<>();

    message = message.toLowerCase();

    for (Message item : messages) {
      if (item.getMessage().toLowerCase().equals(message)) {
        list.remove(item);
      }
    }
    return list;
  }
예제 #14
0
  @Override
  public void run() {
    for (int i = 0; i < 1000; i++) {
      Message message;
      try {
        while ((message = bqueue.take()).getMessage() != "exit") {

          System.out.println("Consumer: " + message.getMessage());
        }
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
예제 #15
0
  /** 处理接收到得用户信息 */
  private void receiveServerMsg() {
    try {

      ObjectInputStream serverInput = new ObjectInputStream(socket.getInputStream());
      Object object = serverInput.readObject();
      // 判断对方是否在线
      if (object == null) { // type为3表示用户不在线,转离线消息
        ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
        Message m = new Message();
        m.setType(3);
        m.setSendIP(myIP);
        m.setMessage(sendMsgTextField.getText().trim());
        m.setReceiveIP(destinationIP);
        output.writeObject(m);
        chartTextArea.append("对方不在线,信息已经转入离线信息。\n");
      } else {
        // 用户收到的是正常的聊天信息
        if (object instanceof Message) {
          Message m = (Message) object;
          /*String destinationIP = m.getSendIP();
          new Client(destinationIP, serverIP, PORT, table);*/
          chartTextArea.append(m.getSendIP() + ":\n" + m.getMessage() + "\n");
        }
        // 用户收到的是更新在线用户的信息
        else {
          @SuppressWarnings("unchecked")
          List<String> onlineIP = (List<String>) object;

          System.out.println("friend list:" + onlineIP.toString());

          // 将在线用户加入到界面中显示
          String[] tableHeads = new String[] {"在线用户"};
          DefaultTableModel dtm = (DefaultTableModel) friendTable.getModel();
          dtm.setColumnIdentifiers(tableHeads);

          for (int i = 0; i < onlineIP.size(); i++) {
            Vector<String> onlineIPVector = new Vector<String>();
            onlineIPVector.add(onlineIP.get(i));
            dtm.addRow(onlineIPVector);
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }
예제 #16
0
파일: Searcher.java 프로젝트: okamilex/sp
  public void searchByRegularExpression() {
    boolean thereIsMessage = false;
    boolean incorrectExpression = false;
    System.out.println("Input: regular expression");

    String expression;
    expression = "";
    try {
      expression = reader.readLine();
    } catch (IOException e) {
      System.out.println("Can't read this");
    }

    for (Message it : messageList) {
      try {
        Pattern p = Pattern.compile(expression);
        Matcher m = p.matcher(it.getMessage());
        if (m.find()) {
          thereIsMessage = true;
          System.out.println(it.toString());
        }
      } catch (PatternSyntaxException e) {
        System.out.println("Incorrect expression: \n" + e.getMessage());
        incorrectExpression = true;
      }
    }
    if ((!thereIsMessage) && (!incorrectExpression)) {
      System.out.println("There isn't any message with this regular expression");
      logWriter.write(
          (new Date()).toString()
              + " | "
              + "Search By Regular Expression: "
              + expression
              + " |There isn't any message with this regular expression "
              + ""
              + "\n");
    } else {
      logWriter.write(
          (new Date()).toString()
              + " | "
              + "Search By Regular Expression: "
              + expression
              + " |Successfully "
              + ""
              + "\n");
    }
  }
  public static void getmessage() {
    List<Message> messagelist = dbmsg.getindividualuserid(senderid);

    if (messagelist.size() > 0) {
      amList.clear();
      Message messages;
      for (Message msg : messagelist) {
        messages = new Message();
        String fname = msg.getFname();
        String lname = msg.getLname();
        String tstamp = msg.getTimestamp();
        String message = msg.getMessage();
        String me = msg.getIsmine();
        String msgtype = "";

        if (msg.getMsgtype() != null) {

          msgtype = msg.getMsgtype();

        } else {
          msgtype = "";
        }
        messages.setMessage(message);
        messages.setFname(fname);
        messages.setLname(lname);
        messages.setTimestamp(tstamp);
        messages.setIsmine(me);
        messages.setMsgtype(msgtype);

        amList.add(messages);
      }

      txtalert.setVisibility(View.INVISIBLE);

      AwesomeAdapter adapter = new AwesomeAdapter(context, amList);
      adapter.notifyDataSetChanged();
      list.setAdapter(adapter);
      list.setSelection(amList.size() - 1);
    }
    int seencount = dbmsg.getunseeenindividual(senderid, "no");
    if (seencount > 0) {
      dbmsg.updateindividualseen(senderid);
    }
    cancelnotification();
  }
예제 #18
0
  void printMessages() {

    StringBuilder sb = new StringBuilder();

    sb.append(groupName);
    sb.append(" のメッセージは\n");

    if (messages == null) {
      sb.append("存在しません\n");
    } else {
      for (Message message : messages) {
        sb.append(message.getMessage());
        sb.append("\n");
      }
    }

    System.out.print(sb.toString());
  }
예제 #19
0
  /**
   * Publishes the given message from Publisher
   *
   * @param publisherName The given Publisher object
   * @param messageDetails Message to be published
   * @return Returns true if the subscription of the type <b>type</b> was removed successfully else
   *     returns false
   */
  public boolean publishMessage(Publisher publisherName, Message messageDetails) {

    if (publisherName != null && messageDetails != null) {

      NewPublisher publisher = publisherName.getPublisher();
      if (!publishers.contains(publisher)) {

        return false;
      }

      for (Subscriber sub : subscriberMap.keySet()) {

        if (subscriberMap
            .get(sub)
            .contains(messageDetails.getMessage().getMetadata().getMessageType())) {

          sub.getSubscriber().receivedMessage(messageDetails);
        }
      }
    }
    return false;
  }
예제 #20
0
파일: Searcher.java 프로젝트: okamilex/sp
  public void searchByKeyWord() {
    boolean thereIsMessage = false;
    System.out.println("Input: key word");

    String keyWord;
    keyWord = "";
    try {
      keyWord = reader.readLine();
    } catch (IOException e) {
      System.out.println("Can't read this");
    }
    logWriter.write("Search By Key Word: " + keyWord + " |Successfully " + "" + "\n");
    for (Message it : messageList) {
      if (it.getMessage().contains(keyWord)) {
        System.out.println(it.toString());
        thereIsMessage = true;
      }
    }
    if (!thereIsMessage) {
      System.out.println("There isn't any message with this word");
      logWriter.write(
          (new Date()).toString()
              + " | "
              + "Search By Key Word: "
              + keyWord
              + " |There isn't any message with this word "
              + ""
              + "\n");
    } else {
      logWriter.write(
          (new Date()).toString()
              + " | "
              + "Search By Key Word: "
              + keyWord
              + " |Successfully "
              + ""
              + "\n");
    }
  }
예제 #21
0
 private void sendMessage(final Message message) throws IOException {
   exec(
       connection.publish(
           message.getTopic(), message.getMessage().getBytes(), AT_LEAST_ONCE, false));
 }
예제 #22
0
 @Override
 public void insertMessage(Message message) throws Exception {
   final String SQL = property.getSql("insertMessage", message.getUserinfo_test_id());
   jdbcTemplate.update(SQL, new Object[] {message.getMessage()});
 }
예제 #23
0
 public void sendMessage(Message newMsg) {
   adapter1.add(newMsg);
   msg.setText("");
   getMessage(new Message(newMsg.getMessage(), destinatar));
 }
예제 #24
0
 void postAction(final Message message) {
   sendAction(message.getDestination(), message.getMessage());
   logMessage(message);
 }
예제 #25
0
 public void update(Message message) {
   this.consumed.add(message);
   System.out.println(this + " consumed '" + message.getMessage() + "'");
 }
예제 #26
0
 /**
  * Broadcast the received message object to all suspended response. Do not write back the message
  * to the calling connection.
  *
  * @param message a {@link Message}
  * @return a {@link Response}
  */
 @Broadcast(writeEntity = false)
 @POST
 @Produces("application/json")
 public Response broadcast(Message message) {
   return new Response(message.getAuthor(), message.getMessage());
 }
예제 #27
0
 public static void appendInput(Message msg) {
   String musername = msg.getUsername();
   String chatmessage = msg.getMessage();
   show_areaS.append(musername + ": " + chatmessage + "\n");
   show_areaS.selectAll();
 }
예제 #28
0
 @Override
 public void onBindViewHolder(ViewHolder viewHolder, int position) {
   Message message = mMessages.get(position);
   viewHolder.setMessage(message.getMessage());
   viewHolder.setUsername(message.getUsername());
 }
    @SuppressWarnings("deprecation")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      Message message1 = (Message) this.getItem(position);

      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false);
        holder.message = (EmojiconTextView) convertView.findViewById(R.id.message_text);
        holder.thumb = (FetchableImageView) convertView.findViewById(R.id.thumb);
        holder.message.setPadding(10, 10, 10, 10);
        convertView.setTag(holder);
      } else holder = (ViewHolder) convertView.getTag();
      if (message1.getMsgtype().equalsIgnoreCase("text")) {
        holder.message.setVisibility(View.VISIBLE);
        holder.thumb.setVisibility(View.GONE);

        holder.message.setText(message1.getMessage());
        LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
        if (message1.getIsmine().equals("yes")) {
          holder.message.setBackgroundResource(R.drawable.message_you);
          holder.message.setPadding(15, 15, 15, 15);
          lp.gravity = Gravity.RIGHT;
          lp.leftMargin = 50;
          lp.rightMargin = 20;
        }
        // If not mine then it is from sender to show orange background and
        // align to left
        else {
          holder.message.setBackgroundResource(R.drawable.message_from);
          holder.message.setPadding(15, 15, 15, 15);
          lp.gravity = Gravity.LEFT;
          lp.rightMargin = 50;
          lp.leftMargin = 20;
        }
        holder.message.setLayoutParams(lp);
        holder.message.setTextColor(mContext.getResources().getColor(R.color.Black));
      } else {
        LayoutParams lp1 = (LayoutParams) holder.thumb.getLayoutParams();
        holder.message.setVisibility(View.GONE);
        holder.thumb.setVisibility(View.VISIBLE);
        holder.thumb.setPadding(15, 15, 15, 15);
        if (message1.getMsgtype().equals("video")) {

          holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_video);
          final String url = DataManager.FILE_PATH + message1.getMessage().toString();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(Uri.parse(url), "video/*");
                  mContext.startActivity(intent);
                }
              });
        } else if (message1.getMsgtype().equals("audio")) {
          holder.thumb.setImage(message1.getMessage(), R.drawable.placeholder_audio);
          final String url = DataManager.FILE_PATH + message1.getMessage();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Uri myUri = Uri.parse(url);
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(myUri, "audio/*");
                  mContext.startActivity(intent);
                }
              });
        } else if (message1.getMsgtype().equals("photo")) {
          holder.thumb.setImage(
              DataManager.FILE_PATH + message1.getMessage(), R.drawable.placeholder_image);
          final String url = DataManager.FILE_PATH + message1.getMessage();
          holder.thumb.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.setDataAndType(Uri.parse(url), "image/*");
                  mContext.startActivity(intent);
                }
              });
        }
        if (message1.getIsmine().equals("yes")) {
          holder.thumb.setBackgroundResource(R.drawable.message_you);
          holder.thumb.setPadding(15, 15, 15, 15);
          lp1.gravity = Gravity.RIGHT;
          lp1.topMargin = 10;
          lp1.bottomMargin = 10;
          lp1.leftMargin = 50;
          lp1.rightMargin = 20;
        }
        // If not mine then it is from sender to show orange background and
        // align to left
        else {
          holder.thumb.setBackgroundResource(R.drawable.message_from);
          holder.thumb.setPadding(15, 15, 15, 15);
          lp1.gravity = Gravity.LEFT;
          lp1.topMargin = 10;
          lp1.bottomMargin = 10;
          lp1.rightMargin = 50;
          lp1.leftMargin = 20;
        }
        holder.thumb.setLayoutParams(lp1);
      }
      return convertView;
    }
예제 #30
0
 public void message(Message msg) {
   PrintStream os = msg.getType().getOstrm();
   os.println(msg.getMessage());
   os.flush();
 }