@Override public void run() { int timeMax = 1000 * 60; while (!MainActivity.openProgram && timeMax > MainActivity.timeSleep) { MainActivity.timeSleep += 500; service.setTimeSleep(MainActivity.timeSleep); System.out.println("time: " + MainActivity.timeSleep); try { Thread.sleep(MainActivity.timeSleep); } catch (InterruptedException e) { e.printStackTrace(); } } service.setTimeSleep(MainActivity.timeSleepStart); }
@Override public void run() { while (!Thread.interrupted()) { if (!service.getBuffer().isEmpty()) { runOnUiThread( new Runnable() { @Override public void run() { Iterator<Message> it = service.getBuffer().iterator(); while (it.hasNext()) { Message message = it.next(); messages.add(message); boolean messageIsDisplay = false; boolean isGroup = message.getIsGroup(); if (!isGroup && message.getIdFriend() == toID && MainActivity.isChatPrivate) { if (isAMap(message.getText())) { try { showMap(message); messageIsDisplay = true; } catch (JSONException e) { e.printStackTrace(); } } else { if ((!message.getIsGroup() && MainActivity.isChatPrivate)) { showMessage(message); messageIsDisplay = true; } } ringtone.play(); } else { saveDBMessages(); } if (!MainActivity.openProgram || !messageIsDisplay) { showNotification(message); } it.remove(); } } }); } try { Thread.sleep(MainActivity.timeSleep); } catch (InterruptedException e) { e.printStackTrace(); } if (!MainActivity.openProgram && MainActivity.timeSleep == MainActivity.timeSleepStart) { MainActivity.timeSleep++; Thread threadOutTime = new Thread(runThreadTimeOut); threadOutTime.start(); } } }