List of usage examples for java.util TimerTask TimerTask
protected TimerTask()
From source file:com.microsoft.tfs.client.common.ui.controls.generic.html.HTMLEditor.java
private void showToolTip() { // Calculate size and position final Point size = toolTipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT); final Point position = new Point(getDisplay().getCursorLocation().x, getDisplay().getCursorLocation().y + 20); // Ensure it will be on the screen if (position.x + size.x > getDisplay().getBounds().width) { position.x = getDisplay().getBounds().width - size.x; }// w w w.j ava 2s.c o m if (position.y + size.y > getDisplay().getBounds().height) { position.y = getDisplay().getBounds().height - size.y; } toolTipShell.setBounds(position.x, position.y, size.x, size.y); log.trace("Showing tool tip"); //$NON-NLS-1$ toolTipShell.setVisible(true); // Schedule a timer to hide the tooltip toolTipShellTimer = new Timer(); toolTipShellTimer.schedule(new TimerTask() { @Override public void run() { getDisplay().asyncExec(new Runnable() { @Override public void run() { log.trace("Tool tip timer fired"); //$NON-NLS-1$ hideToolTip(); } }); } }, TableTooltipLabelManager.getPlatformDefaultTooltipTimeout()); }
From source file:org.apache.unomi.services.services.SegmentServiceImpl.java
private void initializeTimer() { segmentTimer = new Timer(); TimerTask task = new TimerTask() { @Override/*from w ww. ja va 2 s . com*/ public void run() { for (Metadata metadata : rulesService.getRuleMetadatas()) { Rule rule = rulesService.getRule(metadata.getId()); for (Action action : rule.getActions()) { if (action.getActionTypeId().equals("setEventOccurenceCountAction")) { Condition pastEventCondition = (Condition) action.getParameterValues() .get("pastEventCondition"); if (pastEventCondition.containsParameter("numberOfDays")) { updateExistingProfilesForPastEventCondition(rule.getCondition(), pastEventCondition); } } } } } }; segmentTimer.scheduleAtFixedRate(task, getDay(1).getTime(), taskExecutionPeriod); task = new TimerTask() { @Override public void run() { allSegments = getAllSegmentDefinitions(); allScoring = getAllScoringDefinitions(); } }; segmentTimer.scheduleAtFixedRate(task, 0, 1000); }
From source file:com.xpple.jahoqy.adapter.MessageAdapter.java
/** * ?/*from w w w.j ava 2 s. 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.gizwits.smartlight.activity.MainListActivity.java
/** * Inits the events.//from w w w . j a v a2 s.c om */ 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:com.aibasis.parent.adapter.MessageAdapter.java
/** * ?// w w w .j a va 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 == 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.lfv.lanzius.application.Controller.java
public synchronized void start() { try {/*from w w w. j av a 2 s.c om*/ long t = System.currentTimeMillis(); while (!semStopFinished && (System.currentTimeMillis() < (t + TIMEOUT_STARTSTOP))) wait(100); } catch (InterruptedException ex) { } if (state == CLIENT_STATE_CONNECTED) { view = null; audioRecorder = null; log.info("Starting session"); radioState = RADIO_STATE_IDLE; phoneState = PHONE_STATE_IDLE; phoneActive = false; radioEncoding = false; radioDecoding = false; radioDecodingList.clear(); log.debug("Downloading data model for terminal " + properties.getTerminalId() + " from http://" + properties.getServerAddress() + ":" + properties.getServerHttpPort()); // Get configuration document from server String url = "http://" + properties.getServerAddress() + ":" + properties.getServerHttpPort() + "/xml/info?terminal=" + properties.getTerminalId(); try { SAXBuilder builder = new SAXBuilder(); if (Config.CLIENT_SERVERLESS) model = builder.build(new java.io.File("data/development/client_inforequest.xml")); else model = builder.build(new URL(url)); } catch (Exception ex) { log.error("Failed to get or parse the configuration document from " + url.toString(), ex); log.debug("Waiting for start session packet from server"); ex.printStackTrace(); return; } if (!validateModel()) { log.error("Invalid data model, validation failed!"); log.debug("Waiting for start session packet from server"); return; } // Document is valid state = CLIENT_STATE_STARTED; log.debug("Data model passed validation test"); // Add extra nodes model.getRootElement().addContent(new Element("TalkButton")); model.getRootElement().addContent(new Element("HookButton")); Element e1 = new Element("Settings"); Element e2 = new Element("Name"); e2.setText("SETTINGS"); e1.addContent(e2); e1.setAttribute("hfac", "0.4"); model.getRootElement().addContent(e1); // Inactivate all phone peers initially Iterator iter1 = model.getRootElement().getChild("RoleSetup").getChildren().iterator(); while (iter1.hasNext()) { Element er = (Element) iter1.next(); Iterator iter2 = er.getChild("PhonePeers").getChildren().iterator(); while (iter2.hasNext()) { Element err = (Element) iter2.next(); err.setAttribute("active", "false"); } } // Clear encoder = null; distributor = null; decoderPhone = null; decoderForward = null; monitorEncoder = null; monitorDistributor = null; // Get codec type String codec = DomTools.getChildText(model.getRootElement(), "Codec", "null", true); // Encoder if (codec.startsWith("jspeex")) { // Parse out the quality from the string "jspeex:<quality 1-10>" int quality = 6; int idx = codec.indexOf(':'); if (idx > 0) { try { quality = Integer.parseInt(codec.substring(idx + 1)); } catch (Exception ex) { log.warn("Parse error in string " + codec + ", should be \"jspeex:<quality 1-10>\", defaulting to 6!"); } if (quality < 1 || quality > 10) { log.warn("Out of range error in string " + codec + ", should be \"jspeex:<quality 1-10>\", defaulting to 6!"); quality = 6; } } encoder = new JSpeexEncoder(inputMixer, quality); monitorEncoder = new JSpeexEncoder(inputMixer, quality); } else { encoder = new NullEncoder(inputMixer); monitorEncoder = new NullEncoder(inputMixer); } // Main distributor distributor = new Distributor(properties.getTerminalId(), bundle, networkManager.getSender()); encoder.setPacketDistributor(distributor); // Monitor distributor monitorDistributor = new Distributor(properties.getTerminalId(), bundle, networkManager.getSender()); monitorEncoder.setPacketDistributor(monitorDistributor); // Start encoders AudioFormat audioFormats[] = encoder.getSupportedAudioFormats(); int usedAudioFormat = -1; // Find which audio format to use for (int i = 0; i < audioFormats.length; i++) { try { encoder.startModule(i); log.debug("Using input audio format " + audioFormats[i]); usedAudioFormat = i; break; } catch (Exception ex) { log.warn("Could not open the input device for format " + audioFormats[i] + "!"); } } if (usedAudioFormat < 0) { log.error("Unable to start, the input sound device is unavailable!"); stop(false, false); return; } MixingDataLine monitorDataLine = null; if (usedAudioFormat > 0) { log.warn("Unable to open the monitor data line, supports mono only!"); monitorEncoder = null; monitorDistributor = null; } else { // Create a mixing data line for the monitor monitorDataLine = new MixingDataLine(); try { // Start monitor encoder with the same format as the main encoder monitorEncoder.startModule(monitorDataLine, 0); } catch (Exception ex) { log.warn("Unable to open the monitor data line, monitoring has been disabled!", ex); monitorDataLine = null; monitorEncoder = null; monitorDistributor = null; } } // Pass a monitor channel to the encoder if (monitorDataLine != null) { encoder.setMonitorChannel(monitorDataLine.getMixerChannel()); } // Create decoders and packet dispatchers if (codec.startsWith("jspeex")) { decoderPhone = new JSpeexDecoder(outputMixer, CHANNEL_PHONE); decoderForward = new JSpeexDecoder(outputMixer, CHANNEL_FORWARD); } else { decoderPhone = new NullDecoder(outputMixer, CHANNEL_PHONE); decoderForward = new NullDecoder(outputMixer, CHANNEL_FORWARD); } // Add decoders as packet receiver handlers packetReceiver.addDataPacketDispatcher(CHANNEL_PHONE, decoderPhone); packetReceiver.addDataPacketDispatcher(CHANNEL_FORWARD, decoderForward); // Pass monitor channel to decoders if (monitorDataLine != null) { decoderPhone.setMonitorChannel(monitorDataLine.getMixerChannel()); decoderForward.setMonitorChannel(monitorDataLine.getMixerChannel()); } Iterator iter = model.getRootElement().getChild("ChannelSetup").getChildren().iterator(); while (iter.hasNext()) { Element ec = (Element) iter.next(); int channelId = DomTools.getAttributeInt(ec, "id", 0, true); if (channelId > 0) { AudioDecoder decoder; if (codec.startsWith("jspeex")) { decoder = new JSpeexDecoder(outputMixer, channelId); } else { decoder = new NullDecoder(outputMixer, channelId); } // Add decoder as packet receiver handler packetReceiver.addDataPacketDispatcher(channelId, decoder); // Pass monitor channel to decoder if (monitorDataLine != null) { decoder.setMonitorChannel(monitorDataLine.getMixerChannel()); } } } // Go through the decoders and create output lines for them audioFormats = null; usedAudioFormat = -1; iter = packetReceiver.getDataPacketDispatcherCollection().iterator(); while (iter.hasNext()) { AudioDecoder decoder = (AudioDecoder) iter.next(); // First iteration, find which audio format to use if (usedAudioFormat < 0) { audioFormats = decoder.getSupportedAudioFormats(); for (int i = 0; i < audioFormats.length; i++) { try { decoder.startModule(i); log.debug("Using output audio format " + audioFormats[i]); usedAudioFormat = i; break; } catch (Exception ex) { log.warn("Could not open the output device for format " + audioFormats[i] + "!"); } } if (usedAudioFormat < 0) { log.error("Unable to start, the output sound device is unavailable!"); stop(false, false); return; } } // The format to use is known, just start the module else { try { decoder.startModule(usedAudioFormat); } catch (LineUnavailableException ex) { log.error("Could not open the output device for format " + audioFormats[usedAudioFormat] + "!"); stop(false, false); return; } } // Add listeners for all radio // Also add to volume list if (decoder.getDecoderId() > CHANNEL_RADIO_START) { decoder.addListener(this); volumeRadioList.add(decoder); } } // Create a recorder audioRecorder = new AudioRecorder(audioFormats[usedAudioFormat], true); // Join channels Collection<Integer> c = new LinkedList<Integer>(); // Common bundle.addChannel(new ClientChannel(CHANNEL_COMMON)); c.add(CHANNEL_COMMON); iter = model.getRootElement().getChild("ChannelSetup").getChildren().iterator(); while (iter.hasNext()) { Element ec = (Element) iter.next(); int channelId = DomTools.getAttributeInt(ec, "id", 0, true); if (channelId > 0) { ClientChannel channel = new ClientChannel(channelId); bundle.addChannel(channel); c.add(channelId); // Also store the channel element.. channel.setElement(ec); // ..and the decoder for fast access AudioDecoder decoder = (AudioDecoder) packetReceiver.getDataPacketDispatcher(channelId); channel.setDecoder(decoder); // finally, add the recorder if the channel has recordable="true" if (DomTools.getAttributeBoolean(ec, "recordable", false, false)) { decoder.setAudioRecorder(audioRecorder); decoder.addListener(audioRecorder); // to get stop events for injecting silence } } } networkManager.sessionConnect(c); // Immediately open all channels with state rxtx or rx iter = bundle.getChannelCollection().iterator(); while (iter.hasNext()) { ClientChannel channel = (ClientChannel) iter.next(); if (!DomTools.getAttributeString(channel.getElement(), "state", "off", false).equals("off")) { packetReceiver.openChannel(channel.getId()); } } // Force all settings Settings settings = Settings.getInstance(); settingsValueChanged(Settings.ID_MASTER_VOLUME, settings.getMasterVolume()); settingsValueChanged(Settings.ID_SIGNAL_VOLUME, settings.getSignalVolume()); settingsValueChanged(Settings.ID_CHPRIO_VOLUME, settings.getChprioVolume()); settingsValueChanged(Settings.ID_RAPASS_VOLUME, settings.getRapassVolume()); settingsValueChanged(Settings.ID_CHPRIO_CHOICE, settings.getChprioChoice()); settingsValueChanged(Settings.ID_WATONE_CHOICE, settings.getWatoneChoice()); // Create view String style = properties.getUserInterfaceStyle().toLowerCase(); if (!(style.equals("full") || style.equals("slim-phone") || style.equals("slim-horiz") || style.equals("slim-vert") || style.equals("none"))) { log.warn("Invalid user interface style (" + style + ") defaulting to full!"); style = "full"; properties.setUserInterfaceStyle(style); } if (!Config.CLIENT_SIZE_FULLSCREEN || !style.equals("full")) JFrame.setDefaultLookAndFeelDecorated(true); log.debug("Creating view with style: " + style); if (properties.getUserInterfaceStyle().equalsIgnoreCase("full")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { view = new FullView(Controller.getInstance(), properties); view.setModel(model); view.setVisible(true); view.toFront(); if (peripheralLink != null) peripheralLink.setView(view); } }); } else if (properties.getUserInterfaceStyle().equalsIgnoreCase("none")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { view = new FullView(Controller.getInstance(), properties); view.setModel(model); view.setVisible(false); view.toFront(); if (peripheralLink != null) peripheralLink.setView(view); } }); } else if (properties.getUserInterfaceStyle().equalsIgnoreCase("slim-phone")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { view = new PhoneOnlyView(Controller.getInstance(), properties); view.setModel(model); view.setVisible(true); view.toFront(); if (peripheralLink != null) peripheralLink.setView(view); } }); } else { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { view = new SlimView(Controller.getInstance(), properties); view.setModel(model); view.setVisible(true); view.toFront(); if (peripheralLink != null) peripheralLink.setView(view); } }); } // Start the push to talk interfaces if (properties.getEventDeviceName().length() > 0) { eventSwitch.start(); } if (properties.getFootSwitchInterface().length() > 0) { if (footSwitch != null) { try { footSwitch.start(); } catch (UnsatisfiedLinkError err) { log.error("UnsatisfiedLinkError: " + err.getMessage()); log.warn("Missing ftsw library (ftsw.dll or libftsw.so)"); if (!properties.getFootSwitchInterface().equalsIgnoreCase("ftdi")) log.warn("Missing rxtxSerial library (rxtxSerial.dll or librxtxSerial.so)"); log.warn("The footswitch has been disabled!"); footSwitch = null; } catch (NoClassDefFoundError err) { log.warn("Missing ftsw library (ftsw.dll or libftsw.so)"); if (!properties.getFootSwitchInterface().equalsIgnoreCase("ftdi")) log.warn("Missing rxtxSerial library (rxtxSerial.dll or librxtxSerial.so)"); log.warn("The footswitch has been disabled!"); footSwitch = null; } catch (NoSuchPortException ex) { log.warn("The serial port " + properties.getFootSwitchInterface() + " does not exist, the footswitch has been disabled!"); footSwitch = null; } catch (PortInUseException ex) { log.warn("The serial port " + properties.getFootSwitchInterface() + " is already in use, the footswitch has been disabled!"); footSwitch = null; } } } sleep(25); dbgListThreads(); // The system is not allowed to be stopped immediately after start if (timer != null) { semStartFinished = false; timer.schedule(new TimerTask() { public void run() { Controller c = Controller.getInstance(); synchronized (c) { semStartFinished = true; c.notifyAll(); } } }, DELAY_STARTSTOP); } if (autoTesterEnabled && autoTester != null) { autoTester.startTester(model); } } }
From source file:com.oakesville.mythling.MediaActivity.java
private void tick() { if (timer != null) timer.cancel();/*from w ww. ja va 2 s.c om*/ timer = new Timer(); timer.schedule(new TimerTask() { public void run() { countdownDialog.setProgress(10 - count); if (count == 10) { countdownDialog.dismiss(); stopTimer(); } else { count++; tick(); } } }, 1000); }
From source file:com.easemob.chatui.adapter.MessageAdapter.java
/** * ?//from w ww . j a v a 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), Toast.LENGTH_SHORT).show(); timer.cancel(); } } }); } }, 0, 500); break; default: // ??? sendMsgInBackground(message, holder); } }
From source file:it.polimi.geinterface.GroupEntityManager.java
/** * Method used to evaluate a {@link MessageType#CHECK_OUT} message received. If its valid bit is set to * <code>true</code>, method checks for a possible {@link GroupEvent#ENTITY_CHECK_OUT} event; if it is * <code>false</code>, it sets the {@link Timer} to wait for the corresponding * {@link MessageType#PROPERTIES_UPDATE} message. * @param e - {@link Entity} that sent the {@link MessageType#CHECK_OUT} message * @param valid_bit - valid boolean field of the message * @param logId - used only for logging/* w w w . j av a 2 s . c om*/ */ private void evaluateCheckOut(final Entity e, final boolean valid_bit, final String logId) { if (groupSubscriptionList.size() == 0) return; scheduler.schedule(new Runnable() { @Override public void run() { for (Subscription s : groupSubscriptionList) { if (s.getG1().evaluate(e)) { if (!valid_bit) { if (waitingForCheckInTasks.containsKey(e.getEntityID())) return; TimerTask task = new TimerTask() { @Override public void run() { Log.w(TAG, "Timeout CheckIn per " + e.getEntityID()); waitingForCheckInTasks.remove(e.getEntityID()); evaluateCheckOut(e, true, ""); } }; waitingForCheckInTasks.put(e.getEntityID(), task); checkInTimer.schedule(task, CHECK_IN_AFTER_PROP_UPDATE_DELAY); Log.d(TAG, "Timeout checkIn registrato per " + e.getEntityID()); return; } else { long timestamp = Calendar.getInstance().getTimeInMillis() + LoggerService.NTP_DELAY; getSubscriptionCallback().handleGroupEvent(s, GroupEvent.ENTITY_CHECK_OUT, e, s.getG1()); //logging if (!logId.equals("")) { JSONObject status = LogMessageUtils.buildStatus(proximitySubscriptionList.size(), groupSubscriptionList.size(), geofenceSubscriptionList.size()); String log = LogMessageUtils.buildEventLog(logId, selfEntity.getEntityID(), Type.DEVICE, GroupEvent.ENTITY_CHECK_OUT.name(), status, timestamp); LoggerService.writeToFile(appCtx, log); } } } } } }); }
From source file:cn.ucai.superwechat.adapter.MessageAdapter.java
/** * ?// w w w.ja v a2 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); } }