List of usage examples for java.util Timer cancel
public void cancel()
From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java
/** * ?//from w w w. j a v a2 s.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 == 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.mibr.android.intelligentreminder.INeedToo.java
/** Called when the activity is first created. */ @Override//from www . j ava 2 s. c o m public void onCreate(Bundle savedInstanceState) { /* this was just a test if(mLocationManager==null) { mLocationManager=(android.location.LocationManager) getSystemService(Context.LOCATION_SERVICE); } */ // TabHost host=this.getTabHost(); // host.setOnTabChangedListener(new TabHost.OnTabChangeListener() { // // @Override // public void onTabChanged(String tabId) { // if(INeedToo.this._doingCreatingTabs==false) { // if(tabId.equals("tab1")) { // INeedToo.this._forceNonCompany=true; // } // } // } // }); super.onCreate(savedInstanceState); mLocationClient = new LocationClient(this, this, this); mLocationClient.connect(); try { if (getIntent().getAction() != null && getIntent().getAction().equals("doPrimitiveDeletedNeed")) { transmitNetwork(getIntent().getStringExtra("phoneid")); return; } } catch (Exception eieio) { return; } try { /* putExtra("needId",needId). putExtra("foreignNeedId",foreignNeedId). putExtra("phoneid",phoneid). putExtra("foreignLocationId",foreignLocationId) */ if (getIntent().getAction() != null && getIntent().getAction().equals("transmitNetworkDeletedThisNeedByOnBehalfOf")) { long needId = getIntent().getLongExtra("needId", -11); long foreignNeedId = getIntent().getLongExtra("foreignNeedId", -11); String phoneId = getIntent().getStringExtra("phoneid"); long foreignLocationId = getIntent().getLongExtra("foreignLocationId", -11); if (needId != -11 && foreignNeedId != -11 && foreignLocationId != -11 && isNothingNot(phoneId)) transmitNetworkDeletedThisNeedByOnBehalfOf(needId, foreignNeedId, phoneId, foreignLocationId); return; } } catch (Exception ei3) { return; } /*bbhbb 2011-03-26*/ /*bbhbb2013_05_01 isn't this being done below? * Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler("")); */ mHandler = new Handler(); doBindService(); mSingleton = this; ///////////mSingleton.log("onCreating_INeedToo", 1); if (getPackageName().toLowerCase().indexOf("trial") != -1 && !isSpecialPhone()) { if (!iveCheckedAuthorizationStatusForThisPhone) { doViewCount = true; iveCheckedAuthorizationStatusForThisPhone = true; final Timer jdTimer = new Timer("Registering"); jdTimer.schedule(new TimerTask() { public void run() { Thread thread = new Thread(new Runnable() { public void run() { Intent intent = new Intent(INeedToo.this, INeedWebService.class) .setAction("CheckStatus"); startService(intent); jdTimer.cancel(); } }); thread.setPriority(Thread.MIN_PRIORITY); thread.run(); } }, 3000, 1000 * 60 * 10); } } else { if (IS_ANDROID_VERSION) { if (!isSpecialPhone() || INeedToo.mSingleton.getPhoneId().toLowerCase().equals("20013fc135cd6097xx")) { final Timer jdTimer = new Timer("Licensing"); jdTimer.schedule(new TimerTask() { public void run() { Thread thread = new Thread(new Runnable() { public void run() { // Construct the LicenseCheckerCallback. The library calls this when done. mLicenseCheckerCallback = new MyLicenseCheckerCallback(); // Construct the LicenseChecker with a Policy. mChecker = new LicenseChecker(INeedToo.this, new ServerManagedPolicy(INeedToo.this, new AESObfuscator(SALT, getPackageName(), // "com.mibr.android.intelligentreminder", getDeviceId())), BASE64_PUBLIC_KEY // Your public licensing key. ); mChecker.checkAccess(mLicenseCheckerCallback); } }); thread.setPriority(Thread.MIN_PRIORITY); thread.run(); } }, 3000, 1000 * 60 * 10); } } } try { _logFilter = Integer .valueOf(getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getString("LoggingLevel", "3")); } catch (Exception e) { } if (!INeedLocationService.USING_LOCATION_SERVICES) { int logFilter = 3; try { logFilter = Integer .valueOf(getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getString("LoggingLevel", "3")); } catch (Exception e) { } Intent jdIntent = new Intent(this, INeedTimerServices.class).putExtra("logFilter", logFilter); getApplicationContext().startService(jdIntent); } Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler("")); if (INeedToo.mSingleton.getPhoneId().toLowerCase().equals("22a100000d9f25c5")) { DELAYPOSTTTS = 100; } // I don't need this because IHaveNeeds.onresume does it getApplicationContext().startService(new Intent(this, INeedLocationService.class)); if (!_doneSplashy) { _doneSplashy = true; if (!getVersionFile()) { stampVersion(); showDialog(DIALOG_SPLASH); } else { //showDialog(DIALOG_SPLASH); } } if (allItems != null) { whereImAtInAllItems++; if (whereImAtInAllItems < allItems.size()) { showDialog(DOING_SAMPLE_NEEDS_DIALOG); } else { allItems = null; } } setTitle(getHeading()); Bundle bundle = getIntent().getExtras(); if (bundle != null) { _initialTabIndex = bundle.getInt("initialtabindex", 0); _didContact = bundle.getBoolean("iscontact", false); if (_initialTabIndex == 1) { _doingLocationCompany = bundle.getString("doingcompany"); } else { _doingLocationCompany = null; } } else { _doingLocationCompany = null; } final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Need", getResources().getDrawable(R.drawable.status_bar2_blackwhite)) .setContent(new Intent(this, IHaveNeeds.class).putExtra("iscontact", this._didContact))); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("Location", (BitmapDrawable) getResources().getDrawable(android.R.drawable.ic_menu_mapmode)) .setContent( new Intent(this, IHaveLocations.class).putExtra("doingcompany", _doingLocationCompany))); Intent intent = new Intent(this, NeedMap.class).putExtra("doingcompany", _doingLocationCompany); tabHost.addTab(tabHost.newTabSpec("tab2a") .setIndicator("Map", (BitmapDrawable) getResources().getDrawable(R.drawable.ic_dialog_map)) .setContent(intent)); /* tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator( "History",(BitmapDrawable) getResources().getDrawable( R.drawable.chart)).setContent( new Intent(this, IHaveHistory.class))); */ tabHost.addTab(tabHost.newTabSpec("tab4") .setIndicator("System", (BitmapDrawable) getResources().getDrawable(R.drawable.status_bar1_blackwhite)) .setContent(new Intent(this, ListPlus.class))); /* tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator( "Need", scaleTo((BitmapDrawable) getResources().getDrawable( R.drawable.status_bar2_blackwhite), 36f)).setContent( new Intent(this, IHaveNeeds.class).putExtra("iscontact", this._didContact))); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator( "Location", scaleTo((BitmapDrawable) getResources().getDrawable( android.R.drawable.ic_menu_mapmode), 36f)).setContent( new Intent(this, IHaveLocations.class).putExtra("doingcompany", _doingLocationCompany))); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator( "History", scaleTo((BitmapDrawable) getResources().getDrawable( R.drawable.chart), 36f)).setContent( new Intent(this, IHaveHistory.class))); tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator( "System", scaleTo((BitmapDrawable) getResources().getDrawable( R.drawable.status_bar1_blackwhite), 31f)).setContent( new Intent(this, ListPlus.class))); */ tabHost.setCurrentTab(_initialTabIndex); boolean networkingOutbound = getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getBoolean("Networking_Outbound_Enabled", false); if (INeedWebService.mSingleton == null) { if (networkingOutbound) { enableTransmitting(); } if (getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE) .getBoolean("Networking_Inbound_Enabled", false)) { enableReceiving(); } } }
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.//from w w w. j a v a2 s. co m * * @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:maimeng.yodian.app.client.android.chat.adapter.MessageAdapter.java
/** * ?// ww w .jav a2 s . co 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, new Bundle()); return true; } }); // ?? if (message.direct == EMMessage.Direct.RECEIVE) { // "it is receive msg"; if (message.status == EMMessage.Status.INPROGRESS) { // "!!!! back receive"; holder.iv.setImageResource(R.mipmap.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.mipmap.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), Toast.LENGTH_SHORT).show(); timer.cancel(); } } }); } }, 0, 500); break; default: sendPictureMessage(message, holder); } }
From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java
/** * ?/*from www . j a va 2s . 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() { 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: sendPictureMessage(message, holder); } }
From source file:maimeng.yodian.app.client.android.chat.adapter.MessageAdapter.java
/** * ?/*from w ww. j a v a2 s . c om*/ * * @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.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java
/** * ?/*from w ww.jav 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); 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.fullteem.yueba.app.adapter.MessageAdapter.java
/** * ?//from w w w. j a v 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", 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:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?/* www . j ava 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 == 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.aibasis.parent.adapter.MessageAdapter.java
/** * ?/*from www. j ava2s .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 == 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); } }