List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?//from w w w. j ava 2 s . c om * * @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.gizwits.smartlight.activity.MainListActivity.java
@Override public void onResume() { super.onResume(); refreshMenu();/*from w ww . j a va 2 s . c om*/ //? Log.d(TAG, "centralControlsetListener"); centralControlDevice = (XPGWifiCentralControlDevice) mXpgWifiDevice; centralControlDevice.setListener(xpgWifiCentralControlDeviceListener); mCenter.cSetXPGWifiCentralControlDevice(centralControlDevice); mCenter.cSetDid(centralControlDevice.getDid()); // bottomClose(); ledList.clear(); ControllerList.clear(); showItemDevices.clear(); //First get group information then subdeviceList mCenter.cGetGroups(setmanager.getUid(), setmanager.getToken(), Configs.PRODUCT_KEY_Sub);//? mCenter.cGetSubDevicesList(centralControlDevice);//?? mCenter.cGetAllScenes(setmanager.getUid(), setmanager.getToken(), Configs.PRODUCT_KEY_Sub);//? // // bottomClose(); // ledList.clear(); // ControllerList.clear(); // showItemDevices.clear(); //3??Loadding getStatusProgress.show(); final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { // TODO Auto-generated method stub getStatusProgress.cancel(); timer.cancel(); } }, 3000); }
From source file:de.blizzy.backup.restore.RestoreDialog.java
private void startSearchTimer(final String text) { synchronized (this) { if (searchTimerTask != null) { searchTimerTask.cancel();//ww w . ja v a2 s. c o m } searchTimerTask = new TimerTask() { @Override public void run() { if (StringUtils.isNotBlank(text)) { runSearchAsync(text); } else { final Shell shell = getShell(); final Display display = shell.getDisplay(); if (!display.isDisposed()) { display.asyncExec(new Runnable() { @Override public void run() { if (!display.isDisposed() && !shell.isDisposed()) { Backup backup = (Backup) ((IStructuredSelection) backupsViewer .getSelection()).getFirstElement(); try { showBackup(backup); } catch (DataAccessException e) { BackupPlugin.getDefault().logError("error while showing backup", e); //$NON-NLS-1$ } } } }); } } } }; timer.schedule(searchTimerTask, 1000L); } }
From source file:com.halseyburgund.rwframework.core.RWService.java
private void startQueueTimer() { if (mQueueTimer != null) { stopQueueTimer();/*w w w.j a va 2s.c om*/ } if (D) { Log.d(TAG, "Starting queue processing", null); } mQueueTimer = new Timer(); TimerTask task = new TimerTask() { public void run() { queueCheck(); } }; mQueueTimer.scheduleAtFixedRate(task, 0, configuration.getQueueCheckIntervalSec() * 1000); }
From source file:com.delphix.session.test.ServiceTest.java
@Test public void testLoginAborted() { // Create the session ClientConfig spec = initServiceSpec(new HelloService(helloService)); // Connect to an invalid address try {//from w w w .ja v a 2 s. c o m List<TransportAddress> addresses = new ArrayList<TransportAddress>(); addresses.add(new TransportAddress(InetAddress.getByName("169.0.0.1"))); spec.setAddresses(addresses); } catch (UnknownHostException e) { fail("failed to get invalid address", e); } final ClientNexus client = clientManager.create(spec); // Schedule a timer to close the nexus before it is established Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { client.close(); } }, 1000); Throwable t = loginFail(client); assertTrue(t instanceof LoginAbortedException); timer.cancel(); }
From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer.java
/** * Wakeup server. This method returns after actual connection status is changed or timeout. * Used by jelly.//ww w . ja v a 2 s.c om * * @return connection status. */ public JSONObject doWakeup() { Timer timer = new Timer(); try { startConnection(); final CountDownLatch responseLatch = new CountDownLatch(RESPONSE_COUNT); timer.schedule(new TimerTask() { @Override public void run() { if (gerritConnectionListener != null && gerritConnectionListener.isConnected()) { responseLatch.countDown(); } } }, RESPONSE_INTERVAL_MS, RESPONSE_INTERVAL_MS); if (responseLatch.await(RESPONSE_TIMEOUT_S, TimeUnit.SECONDS)) { timeoutWakeup = false; setConnectionResponse(START_SUCCESS); } else { timeoutWakeup = true; throw new InterruptedException("time out."); } } catch (Exception ex) { setConnectionResponse(START_FAILURE); logger.error("Could not start connection. ", ex); } timer.cancel(); JSONObject obj = new JSONObject(); String status = "down"; if (gerritConnectionListener != null) { if (gerritConnectionListener.isConnected()) { status = "up"; } } obj.put("status", status); return obj; }
From source file:cn.hbm.superwechat.adapter.MessageAdapter.java
/** * ?/*from ww w .j a va2s. c om*/ * * @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(); 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.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java
/** * ?/*from ww w . j a v a 2 s . co 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:com.mdground.screen.activity.MainActivity.java
private void startPageSwitch() { if (timer != null) { timer.cancel();//from ww w. j a va 2 s . co m } timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { if (currentPage >= getTotalPage(totalNum)) { currentPage = 1; } else { currentPage++; } handler.obtainMessage(CHANGE_PAGE).sendToTarget(); } }; timer.schedule(task, 10000, 10000); }
From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer.java
/** * Server to sleep. This method returns actual connection status is changed or timeout. * Used by jelly.//from ww w.ja v a 2 s. c o m * * @return connection status. */ public JSONObject doSleep() { Timer timer = new Timer(); try { stopConnection(); final CountDownLatch responseLatch = new CountDownLatch(RESPONSE_COUNT); timer.schedule(new TimerTask() { @Override public void run() { if (gerritConnectionListener == null || !gerritConnectionListener.isConnected()) { responseLatch.countDown(); } } }, RESPONSE_INTERVAL_MS, RESPONSE_INTERVAL_MS); if (responseLatch.await(RESPONSE_TIMEOUT_S, TimeUnit.SECONDS)) { setConnectionResponse(STOP_SUCCESS); } else { throw new InterruptedException("time out."); } } catch (Exception ex) { setConnectionResponse(STOP_FAILURE); logger.error("Could not stop connection. ", ex); } timer.cancel(); JSONObject obj = new JSONObject(); String status = "down"; if (gerritConnectionListener != null) { if (gerritConnectionListener.isConnected()) { status = "up"; } } obj.put("status", status); return obj; }