List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date firstTime, long period)
From source file:maimeng.yodian.app.client.android.chat.adapter.MessageAdapter.java
/** * ?// www . j av a 2 s . c o m * * @param message * @param holder * @param position * @param convertView */ private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) { VideoMessageBody videoBody = (VideoMessageBody) message.getBody(); // final File image=new File(PathUtil.getInstance().getVideoPath(), // videoBody.getFileName()); String localThumb = videoBody.getLocalThumb(); holder.iv.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { activity.startActivityForResult( new Intent(activity, ContextMenu.class).putExtra("position", position).putExtra("type", EMMessage.Type.VIDEO.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU, new Bundle()); return true; } }); if (localThumb != null) { showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message); } if (videoBody.getLength() > 0) { String time = DateUtils.toTimeBySecond(videoBody.getLength()); holder.timeLength.setText(time); } holder.playBtn.setImageResource(R.mipmap.video_download_btn_nor); if (message.direct == EMMessage.Direct.RECEIVE) { if (videoBody.getVideoFileLength() > 0) { String size = TextFormater.getDataSize(videoBody.getVideoFileLength()); holder.size.setText(size); } } else { if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) { String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length()); holder.size.setText(size); } } if (message.direct == EMMessage.Direct.RECEIVE) { // System.err.println("it is receive msg"); if (message.status == EMMessage.Status.INPROGRESS) { // System.err.println("!!!! back receive"); holder.iv.setImageResource(R.mipmap.default_image); showDownloadImageProgress(message, holder); } else { // System.err.println("!!!! not back receive, show image directly"); holder.iv.setImageResource(R.mipmap.default_image); if (localThumb != null) { showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message); } } return; } holder.pb.setTag(position); // until here ,deal with send video msg switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); break; case FAIL: holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_FAIL); // message.setProgress(0); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), Toast.LENGTH_SHORT).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // sendMsgInBackground(message, holder); sendPictureMessage(message, holder); } }
From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java
/** * ?/* www.j a va 2s . c o m*/ * * @param message * @param holder * @param position * @param convertView */ private void handleFileMessage(final EMMessage message, final ViewHolder holder, int position, View convertView) { final NormalFileMessageBody fileMessageBody = (NormalFileMessageBody) message.getBody(); final String filePath = fileMessageBody.getLocalUrl(); holder.tv_file_name.setText(fileMessageBody.getFileName()); holder.tv_file_size.setText(TextFormater.getDataSize(fileMessageBody.getFileSize())); holder.ll_container.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { File file = new File(filePath); // if (file != null && file.exists()) { // // // FileUtils.openFile(file, (Activity) context); // } else { // // // context.startActivity(new Intent(context, // ShowNormalFileActivity.class).putExtra("msgbody", // fileMessageBody)); // } // if (message.direct == EMMessage.Direct.RECEIVE && // !message.isAcked) { // try { // EMChatManager.getInstance().ackMessageRead(message.getFrom(), // message.getMsgId()); // message.isAcked = true; // } catch (EaseMobException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } } }); if (message.direct == EMMessage.Direct.RECEIVE) { // ? System.err.println("it is receive msg"); File file = new File(filePath); if (file != null && file.exists()) { holder.tv_file_download_state.setText(""); } else { holder.tv_file_download_state.setText(""); } return; } // until here, deal with send voice msg switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.INVISIBLE); break; case FAIL: holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // ??? sendMsgInBackground(message, holder); } }
From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java
/** * ?/*from w w w. ja va 2 s . c o m*/ * * @param message * @param holder * @param position * @param convertView */ private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) { VideoMessageBody videoBody = (VideoMessageBody) message.getBody(); // final File image=new File(PathUtil.getInstance().getVideoPath(), // videoBody.getFileName()); String localThumb = videoBody.getLocalThumb(); holder.iv.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { activity.startActivityForResult(new Intent(activity, ContextMenu.class) .putExtra("position", position).putExtra("type", EMMessage.Type.VIDEO.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU); return true; } }); if (localThumb != null) { showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message); } if (videoBody.getLength() > 0) { String time = DateUtils.toTimeBySecond(videoBody.getLength()); holder.timeLength.setText(time); } holder.playBtn.setImageResource(R.drawable.video_download_btn_nor); if (message.direct == EMMessage.Direct.RECEIVE) { if (videoBody.getVideoFileLength() > 0) { String size = TextFormater.getDataSize(videoBody.getVideoFileLength()); holder.size.setText(size); } } else { if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) { String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length()); holder.size.setText(size); } } if (message.direct == EMMessage.Direct.RECEIVE) { // System.err.println("it is receive msg"); if (message.status == EMMessage.Status.INPROGRESS) { // System.err.println("!!!! back receive"); holder.iv.setImageResource(R.drawable.default_image); showDownloadImageProgress(message, holder); } else { // System.err.println("!!!! not back receive, show image directly"); holder.iv.setImageResource(R.drawable.default_image); if (localThumb != null) { showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message); } } return; } holder.pb.setTag(position); // until here ,deal with send video msg switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); break; case FAIL: holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_FAIL); // message.setProgress(0); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), Toast.LENGTH_SHORT).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // sendMsgInBackground(message, holder); sendPictureMessage(message, holder); } }
From source file:gate.util.reporting.DocTimeReporter.java
/** * Calls store, calculate and printReport for generating the actual report. *//* w w w . j a v a 2 s .c o m*/ private void generateReport() throws BenchmarkReportInputFileFormatException, BenchmarkReportFileAccessException { Timer timer = null; try { TimerTask task = new FileWatcher(getBenchmarkFile()) { @Override protected void onChange(File file) { throw new BenchmarkReportExecutionException( getBenchmarkFile() + " file has been modified while generating the report."); } }; timer = new Timer(); // repeat the check every second timer.schedule(task, new Date(), 1000); if (reportFile == null) { reportFile = new File(System.getProperty("java.io.tmpdir"), "report." + ((printMedia.equals(MEDIA_HTML)) ? "html" : "txt")); } splitBenchmarkFile(getBenchmarkFile(), reportFile); if (validEntries == 0) { if (logicalStart != null) { throw new BenchmarkReportInputFileFormatException("No valid log entries present in " + getBenchmarkFile() + " does not contain a marker named " + logicalStart + "."); } else { throw new BenchmarkReportInputFileFormatException( "No valid log entries present in " + getBenchmarkFile().getAbsolutePath()); } } File dir = temporaryDirectory; // Folder already exists; then delete all files in the temporary folder if (dir.isDirectory()) { File files[] = dir.listFiles(); for (int count = 0; count < files.length; count++) { File inFile = files[count]; Object report2Container1 = store(inFile); Object report2Container2 = calculate(report2Container1); printReport(report2Container2, reportFile); } if (files.length > 0 && files[0].exists()) { if (!files[0].delete()) { System.err.println(files[0] + " was not possible to delete."); } } } } finally { if (timer != null) { timer.cancel(); } } }
From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java
/** * ?//from w w w.ja va 2 s . c o m * * @param message * @param holder * @param position * @param convertView */ private void handleImageMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) { holder.pb.setTag(position); holder.iv.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { activity.startActivityForResult((new Intent(activity, ContextMenu.class)) .putExtra("position", position).putExtra("type", EMMessage.Type.IMAGE.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU); return true; } }); // ?? if (message.direct == EMMessage.Direct.RECEIVE) { // "it is receive msg"; if (message.status == EMMessage.Status.INPROGRESS) { // "!!!! back receive"; holder.iv.setImageResource(R.drawable.default_image); showDownloadImageProgress(message, holder); // downloadImage(message, holder); } else { // "!!!! not back receive, show image directly"); holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.iv.setImageResource(R.drawable.default_image); ImageMessageBody imgBody = (ImageMessageBody) message.getBody(); if (imgBody.getLocalUrl() != null) { // String filePath = imgBody.getLocalUrl(); String remotePath = imgBody.getRemoteUrl(); String filePath = ImageUtils.getImagePath(remotePath); String thumbRemoteUrl = imgBody.getThumbnailUrl(); String thumbnailPath = ImageUtils.getThumbnailImagePath(thumbRemoteUrl); showImageView(thumbnailPath, holder.iv, filePath, imgBody.getRemoteUrl(), message); } } return; } // ??? // process send message // send pic, show the pic directly ImageMessageBody imgBody = (ImageMessageBody) message.getBody(); String filePath = imgBody.getLocalUrl(); if (filePath != null && new File(filePath).exists()) { showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, null, message); } else { showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, IMAGE_DIR, message); } switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.GONE); break; case FAIL: holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: holder.staus_iv.setVisibility(View.GONE); holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_FAIL); // message.setProgress(0); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show(); timer.cancel(); } } }); } }, 0, 500); break; default: sendPictureMessage(message, holder); } }
From source file:org.kurento.test.functional.recorder.BaseRecorder.java
protected void checkRecordingFile(String recordingFile, String browserName, Color[] expectedColors, long playTime, String expectedVideoCodec, String expectedAudioCodec) throws InterruptedException { // Checking continuity of the audio Timer gettingStats = new Timer(); final CountDownLatch errorContinuityAudiolatch = new CountDownLatch(1); waitForFileExists(recordingFile);/* ww w . jav a 2 s . c om*/ MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, recordingFile).build(); WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build(); playerEp.connect(webRtcEp); // Playing the recording WebRtcTestPage checkPage = getPage(browserName); checkPage.setThresholdTime(checkPage.getThresholdTime() * 2); checkPage.subscribeEvents("playing"); checkPage.initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); final CountDownLatch eosLatch = new CountDownLatch(1); playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { eosLatch.countDown(); } }); playerEp.play(); // Assertions in recording final String messageAppend = "[played file with media pipeline]"; Assert.assertTrue("Not received media in the recording (timeout waiting playing event) " + messageAppend, checkPage.waitForEvent("playing")); checkPage.activatePeerConnectionInboundStats("webRtcPeer.peerConnection"); gettingStats.schedule(new CheckAudioTimerTask(errorContinuityAudiolatch, checkPage), 100, 200); for (Color color : expectedColors) { Assert.assertTrue("The color of the recorded video should be " + color + " " + messageAppend, checkPage.similarColorAt(color, 50, 50)); } Assert.assertTrue("Not received EOS event in player", eosLatch.await(checkPage.getTimeout(), TimeUnit.SECONDS)); gettingStats.cancel(); double currentTime = checkPage.getCurrentTime(); Assert.assertTrue("Error in play time in the recorded video (expected: " + playTime + " sec, real: " + currentTime + " sec) " + messageAppend, checkPage.compare(playTime, currentTime)); Assert.assertTrue("Check audio. There were more than 2 seconds without receiving packets", errorContinuityAudiolatch.getCount() == 1); AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec); AssertMedia.assertDuration(recordingFile, TimeUnit.SECONDS.toMillis(playTime), TimeUnit.SECONDS.toMillis(checkPage.getThresholdTime())); mp.release(); }
From source file:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?//from www. java 2s . co m * * @param message * @param holder * @param position * @param convertView */ private void handleFileMessage(final EMMessage message, final ViewHolder holder, int position, View convertView) { final NormalFileMessageBody fileMessageBody = (NormalFileMessageBody) message.getBody(); final String filePath = fileMessageBody.getLocalUrl(); holder.tv_file_name.setText(fileMessageBody.getFileName()); holder.tv_file_size.setText(TextFormater.getDataSize(fileMessageBody.getFileSize())); holder.ll_container.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { File file = new File(filePath); if (file != null && file.exists()) { // FileUtils.openFile(file, (Activity) context); } else { // context.startActivity( new Intent(context, ShowNormalFileActivity.class).putExtra("msgbody", fileMessageBody)); } if (message.direct == Direct.RECEIVE && !message.isAcked && message.getChatType() != ChatType.GroupChat && message.getChatType() != ChatType.ChatRoom) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); message.isAcked = true; } catch (EaseMobException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); String st1 = context.getResources().getString(R.string.Have_downloaded); String st2 = context.getResources().getString(R.string.Did_not_download); if (message.direct == Direct.RECEIVE) { // ? EMLog.d(TAG, "it is receive msg"); File file = new File(filePath); if (file != null && file.exists()) { holder.tv_file_download_state.setText(st1); } else { holder.tv_file_download_state.setText(st2); } return; } // until here, deal with send voice msg switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.INVISIBLE); break; case FAIL: holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // ??? sendMsgInBackground(message, holder); } }
From source file:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?// w ww.j a v a 2 s . c o m * * @param message * @param holder * @param position * @param convertView */ private void handleImageMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) { holder.pb.setTag(position); holder.iv.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { activity.startActivityForResult((new Intent(activity, ContextMenu.class)) .putExtra("position", position).putExtra("type", Type.IMAGE.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU); return true; } }); // ?? if (message.direct == Direct.RECEIVE) { // "it is receive msg"; if (message.status == EMMessage.Status.INPROGRESS) { // "!!!! back receive"; holder.iv.setImageResource(R.drawable.default_image); showDownloadImageProgress(message, holder); // downloadImage(message, holder); } else { // "!!!! not back receive, show image directly"); holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.iv.setImageResource(R.drawable.default_image); ImageMessageBody imgBody = (ImageMessageBody) message.getBody(); if (imgBody.getLocalUrl() != null) { // String filePath = imgBody.getLocalUrl(); String remotePath = imgBody.getRemoteUrl(); String filePath = ImageUtils.getImagePath(remotePath); String thumbRemoteUrl = imgBody.getThumbnailUrl(); if (TextUtils.isEmpty(thumbRemoteUrl) && !TextUtils.isEmpty(remotePath)) { thumbRemoteUrl = remotePath; } String thumbnailPath = ImageUtils.getThumbnailImagePath(thumbRemoteUrl); showImageView(thumbnailPath, holder.iv, filePath, imgBody.getRemoteUrl(), message); } } return; } // ??? // process send message // send pic, show the pic directly ImageMessageBody imgBody = (ImageMessageBody) message.getBody(); String filePath = imgBody.getLocalUrl(); if (filePath != null && new File(filePath).exists()) { showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, null, message); } else { showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, IMAGE_DIR, message); } switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.GONE); break; case FAIL: holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: holder.staus_iv.setVisibility(View.GONE); holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_FAIL); // message.setProgress(0); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show(); timer.cancel(); } } }); } }, 0, 500); break; default: sendPictureMessage(message, holder); } }
From source file:com.aibasis.parent.adapter.MessageAdapter.java
/** * ?//from w w w. jav a 2s.c o m * * @param message * @param holder * @param position * @param convertView */ private void handleFileMessage(final EMMessage message, final ViewHolder holder, int position, View convertView) { final NormalFileMessageBody fileMessageBody = (NormalFileMessageBody) message.getBody(); final String filePath = fileMessageBody.getLocalUrl(); holder.tv_file_name.setText(fileMessageBody.getFileName()); holder.tv_file_size.setText(TextFormater.getDataSize(fileMessageBody.getFileSize())); holder.ll_container.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { File file = new File(filePath); if (file != null && file.exists()) { // FileUtils.openFile(file, (Activity) context); } else { // context.startActivity( new Intent(context, ShowNormalFileActivity.class).putExtra("msgbody", fileMessageBody)); } if (message.direct == EMMessage.Direct.RECEIVE && !message.isAcked && message.getChatType() != ChatType.GroupChat && message.getChatType() != ChatType.ChatRoom) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); message.isAcked = true; } catch (EaseMobException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); String st1 = context.getResources().getString(R.string.Have_downloaded); String st2 = context.getResources().getString(R.string.Did_not_download); if (message.direct == EMMessage.Direct.RECEIVE) { // ? EMLog.d(TAG, "it is receive msg"); File file = new File(filePath); if (file != null && file.exists()) { holder.tv_file_download_state.setText(st1); } else { holder.tv_file_download_state.setText(st2); } return; } // until here, deal with send voice msg switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.INVISIBLE); break; case FAIL: holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.INVISIBLE); holder.tv.setVisibility(View.INVISIBLE); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // ??? sendMsgInBackground(message, holder); } }
From source file:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?//w w w .ja v a 2 s . c o m * * @param message * @param holder * @param position * @param convertView */ private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) { VideoMessageBody videoBody = (VideoMessageBody) message.getBody(); // final File image=new File(PathUtil.getInstance().getVideoPath(), // videoBody.getFileName()); String localThumb = videoBody.getLocalThumb(); holder.iv.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { activity.startActivityForResult(new Intent(activity, ContextMenu.class) .putExtra("position", position).putExtra("type", Type.VIDEO.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU); return true; } }); if (localThumb != null) { showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message); } if (videoBody.getLength() > 0) { String time = DateUtils.toTimeBySecond(videoBody.getLength()); holder.timeLength.setText(time); } holder.playBtn.setImageResource(R.drawable.video_download_btn_nor); if (message.direct == Direct.RECEIVE) { if (videoBody.getVideoFileLength() > 0) { String size = TextFormater.getDataSize(videoBody.getVideoFileLength()); holder.size.setText(size); } } else { if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) { String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length()); holder.size.setText(size); } } if (message.direct == Direct.RECEIVE) { // System.err.println("it is receive msg"); if (message.status == EMMessage.Status.INPROGRESS) { // System.err.println("!!!! back receive"); holder.iv.setImageResource(R.drawable.default_image); showDownloadImageProgress(message, holder); } else { // System.err.println("!!!! not back receive, show image directly"); holder.iv.setImageResource(R.drawable.default_image); if (localThumb != null) { showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message); } } return; } holder.pb.setTag(position); // until here ,deal with send video msg switch (message.status) { case SUCCESS: holder.pb.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); break; case FAIL: holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); holder.staus_iv.setVisibility(View.VISIBLE); break; case INPROGRESS: if (timers.containsKey(message.getMsgId())) return; // set a timer final Timer timer = new Timer(); timers.put(message.getMsgId(), timer); timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { holder.pb.setVisibility(View.VISIBLE); holder.tv.setVisibility(View.VISIBLE); holder.tv.setText(message.progress + "%"); if (message.status == EMMessage.Status.SUCCESS) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS); timer.cancel(); } else if (message.status == EMMessage.Status.FAIL) { holder.pb.setVisibility(View.GONE); holder.tv.setVisibility(View.GONE); // message.setSendingStatus(Message.SENDING_STATUS_FAIL); // message.setProgress(0); holder.staus_iv.setVisibility(View.VISIBLE); Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // sendMsgInBackground(message, holder); sendPictureMessage(message, holder); } }