List of usage examples for java.util Timer cancel
public void cancel()
From source file:com.gizwits.smartlight.activity.MainListActivity.java
/** * Inits the events./*from w w w . j a v a 2s.com*/ */ private void initEvents() { ivMenu.setOnClickListener(this); tvTitle.setOnClickListener(this); llFooter.setOnClickListener(this); tvEditSceneName.setOnClickListener(this); iftttButton.setOnClickListener(this); iftttButton.setClickable(false); // etGroup.setOnClickListener(this); //For lightness moveStep1 = (float) (((float) screenWidth / (float) 254) * 0.8); //For Hue moveStep2 = (float) (((float) screenWidth / (float) 65279) * 0.8); //For saturation moveStep3 = (float) (((float) screenWidth / (float) 254) * 0.8); lvDevice.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (!mAdapter.getItem(position).isOnline()) return; if (mAdapter.getChoosedPos() == position) { mView.toggle(); return; } mAdapter.setChoosedPos(position); mXpgWifiDevice = bindlist.get(position); loginDevice(mXpgWifiDevice); } }); sbLightness.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: sbLightness.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_CANCEL: sbLightness.getParent().requestDisallowInterceptTouchEvent(false); break; } return false; } }); sbLightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub mLightness = seekBar.getProgress(); text_light.layout((int) (mLightness * moveStep1), 20, screenWidth, 80); text_light.setText(Integer.toString(mLightness)); if (!selectGroup.equals("") && selectGroup != null) { mCenter.cLightnessGroup(selectGroup, seekBar.getProgress()); } else { mCenter.cLightness(selectSubDevice, seekBar.getProgress()); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub } }); sbSaturation.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: sbSaturation.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_CANCEL: sbSaturation.getParent().requestDisallowInterceptTouchEvent(false); break; } return false; } }); sbSaturation.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub mSaturation = seekBar.getProgress(); text_saturation.layout((int) (mSaturation * moveStep3), 20, screenWidth, 80); text_saturation.setText(Integer.toString(mSaturation)); if (!selectGroup.equals("") && selectGroup != null) { mCenter.cSaturationGroup(selectGroup, seekBar.getProgress()); } else { mCenter.cSaturation(selectSubDevice, seekBar.getProgress()); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub } }); sbColor.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: sbColor.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_CANCEL: sbColor.getParent().requestDisallowInterceptTouchEvent(false); break; } return false; } }); sbColor.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub mHue = seekBar.getProgress(); text_hue.layout((int) (mHue * moveStep2), 20, screenWidth, 80); text_hue.setText(Integer.toString(mHue)); if (!selectGroup.equals("") && selectGroup != null) { mCenter.cColorGroup(selectGroup, seekBar.getProgress()); } else { mCenter.cColor(selectSubDevice, seekBar.getProgress()); } } @Override public void onProgressChanged(SeekBar arg0, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar bar) { } }); alpha_bg.setOnClickListener(this); ivEdit.setOnClickListener(this); sclContent.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub if (position == list.size() - 1) { Intent intent = new Intent(MainListActivity.this, EditGroupActivity.class); intent.putStringArrayListExtra("ledList", GroupDevice.getAllName(ledList)); intent.putExtra("did", "" + centralControlDevice.getDid()); startActivity(intent); } } }); sclContent.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshableListView listView) { // TODO Auto-generated method stub Log.i(TAG, "slip down to refresh........."); mCenter.cGetGroups(setmanager.getUid(), setmanager.getToken(), Configs.PRODUCT_KEY_Sub);//? mCenter.cGetSubDevicesList(centralControlDevice); final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { // TODO Auto-generated method stub runOnUiThread(new Runnable() { public void run() { sclContent.completeRefreshing(); } }); timer.cancel(); } }, 2000); } }); btnSwitch.setOnClickListener(this); addSceneButton.setOnClickListener(this); sceneListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { Object o = sceneListView.getItemAtPosition(position); scene obj_itemDetails = (scene) o; Log.i(TAG, "click now is " + obj_itemDetails.getName() + " " + obj_itemDetails.getValue()); } }); }
From source file:cn.ucai.superwechat.adapter.MessageAdapter.java
/** * ?//from w w w.ja v a 2 s . 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(cn.ucai.superwechat.R.string.Have_downloaded); String st2 = context.getResources().getString(cn.ucai.superwechat.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(cn.ucai.superwechat.R.string.send_fail) + activity .getString(cn.ucai.superwechat.R.string.connect_failuer_toast), Toast.LENGTH_SHORT).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // ??? sendMsgInBackground(message, holder); } }
From source file:com.easemob.chatui.adapter.MessageAdapter.java
/** * ?/*from w w w. j av 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 == 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), Toast.LENGTH_SHORT).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // ??? sendMsgInBackground(message, holder); } }
From source file:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?/*from ww w .j av a 2s . 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:cn.hbm.superwechat.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", 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:password.pwm.util.localdb.LocalDBUtility.java
public void exportLocalDB(final OutputStream outputStream, final Appendable debugOutput, final boolean showLineCount) throws PwmOperationalException, IOException { if (outputStream == null) { throw new PwmOperationalException(PwmError.ERROR_UNKNOWN, "outputFileStream for exportLocalDB cannot be null"); }//from ww w .ja va 2 s. com final int totalLines; if (showLineCount) { writeStringToOut(debugOutput, "counting records in LocalDB..."); exportLineCounter = 0; for (final LocalDB.DB loopDB : LocalDB.DB.values()) { if (loopDB.isBackup()) { exportLineCounter += localDB.size(loopDB); } } totalLines = exportLineCounter; writeStringToOut(debugOutput, " total lines: " + totalLines); } else { totalLines = 0; } exportLineCounter = 0; writeStringToOut(debugOutput, "export beginning"); final long startTime = System.currentTimeMillis(); final Timer statTimer = new Timer(true); statTimer.schedule(new TimerTask() { @Override public void run() { if (showLineCount) { final float percentComplete = (float) exportLineCounter / (float) totalLines; final String percentStr = DecimalFormat.getPercentInstance().format(percentComplete); writeStringToOut(debugOutput, "exported " + exportLineCounter + " records, " + percentStr + " complete"); } else { writeStringToOut(debugOutput, "exported " + exportLineCounter + " records"); } } }, 30 * 1000, 30 * 1000); try (CSVPrinter csvPrinter = JavaHelper .makeCsvPrinter(new GZIPOutputStream(outputStream, GZIP_BUFFER_SIZE))) { csvPrinter.printComment(PwmConstants.PWM_APP_NAME + " " + PwmConstants.SERVLET_VERSION + " LocalDB export on " + JavaHelper.toIsoDate(new Date())); for (final LocalDB.DB loopDB : LocalDB.DB.values()) { if (loopDB.isBackup()) { csvPrinter.printComment("Export of " + loopDB.toString()); final LocalDB.LocalDBIterator<String> localDBIterator = localDB.iterator(loopDB); try { while (localDBIterator.hasNext()) { final String key = localDBIterator.next(); final String value = localDB.get(loopDB, key); csvPrinter.printRecord(loopDB.toString(), key, value); exportLineCounter++; } } finally { localDBIterator.close(); } csvPrinter.flush(); } } csvPrinter.printComment("export completed at " + JavaHelper.toIsoDate(new Date())); } catch (IOException e) { writeStringToOut(debugOutput, "IO error during localDB export: " + e.getMessage()); } finally { statTimer.cancel(); } writeStringToOut(debugOutput, "export complete, exported " + exportLineCounter + " records in " + TimeDuration.fromCurrent(startTime).asLongString()); }
From source file:com.shengtao.chat.chatUI.adapter.MessageAdapter.java
/** * ?/*from w w w . ja v a2s . c om*/ * * @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(string.Have_downloaded); String st2 = context.getResources().getString(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(string.send_fail) + activity.getString(string.connect_failuer_toast), 0).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // ??? sendMsgInBackground(message, holder); } }
From source file:cn.ucai.superwechat.adapter.MessageAdapter.java
/** * ?//from ww w. j av a2 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", 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(cn.ucai.superwechat.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(cn.ucai.superwechat.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(cn.ucai.superwechat.R.string.send_fail) + activity .getString(cn.ucai.superwechat.R.string.connect_failuer_toast), Toast.LENGTH_SHORT).show(); timer.cancel(); } } }); } }, 0, 500); break; default: sendPictureMessage(message, holder); } }
From source file:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?/*from w ww. ja v a 2s . 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); } }
From source file:Model.RaptorUCIEngine.java
/** * Connects to the engine. After this method is invoked the engine name, * engine author, and options will be populated in this object. * //from w ww .j a v a 2 s .co m * @return true if connection was successful, false otherwise. */ public boolean connect() { if (isConnected()) { return true; } resetConnectionState(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { logger.error("The engine could not load before timeout of 15 sec!"); disconnect(); } }, CONNECTION_TIMEOUT); try { process = new ProcessBuilder(processPath).directory(new File(new File(processPath).getParent())) .start(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { if (process != null) { logger.info("Destroying UCI Engine"); process.destroy(); } } }); in = new BufferedReader(new InputStreamReader(process.getInputStream()), 10000); out = new PrintWriter(process.getOutputStream()); send("uci"); String currentLine = null; while ((currentLine = readLine()) != null) { if (currentLine.startsWith("id")) { parseIdLine(currentLine); } else if (currentLine.startsWith("option ")) { parseOptionLine(currentLine); } else if (currentLine.startsWith("uciok")) { break; } else { } } sendAllNonDefaultOptions(); isReady(); timer.cancel(); return true; } catch (Throwable t) { disconnect(); return false; } }