List of usage examples for java.text DateFormat getTimeInstance
public static final DateFormat getTimeInstance()
From source file:in.rade.armud.armudclient.MainActivity.java
/** * Callback that fires when the location changes. *///from w w w .j a va 2s.c o m @Override public void onLocationChanged(Location location) { mCurrentLocation = location; Log.d("onLocationChanged", "Accuracy: " + mCurrentLocation.getAccuracy()); //increase threshold by one meter every ten seconds, until the threshold has been increased by 20 meters float timeBasedThresholdAugment = (System.currentTimeMillis() - mRoomArrivalTime) / 3000; timeBasedThresholdAugment = timeBasedThresholdAugment > 20 ? 20 : timeBasedThresholdAugment; if (mCurrentLocation.getAccuracy() < mAccuracyThresh + timeBasedThresholdAugment) { mLastUpdateTime = DateFormat.getTimeInstance().format(new Date()); mLatestLocAccuracy = mCurrentLocation.getAccuracy(); Log.d("onLocationChanged", "talk with mud"); talkwithMUD(mCurrentLocation); //client.send("location 72.012 23.231"); updateUI(); Toast.makeText(this, getResources().getString(R.string.location_updated_message), Toast.LENGTH_SHORT) .show(); } }
From source file:tw.com.geminihsu.app01.fragment.Fragment_Client_Service_test.java
@Override public void onLocationChanged(Location location) { if (location != null) { String strLocation = DateFormat.getTimeInstance().format(location.getTime()) + "\n" + "Latitude=" + location.getLatitude() + "\n" + "Longitude=" + location.getLongitude(); Log.e("TAG", strLocation); if (getLocation) { setMapView(location.getLongitude(), location.getLatitude()); getLocation = false;/* w w w.java 2 s . c o m*/ getCurrentAddress(location.getLongitude(), location.getLatitude()); } } }
From source file:com.teeptrak.controller.MainActivity.java
public void onSendBtnClicked(final View v) { String message = mSendMsg.getText().toString(); byte[] value; try {/*from w w w . j av a 2 s . c o m*/ //Send Data to Service value = message.getBytes("UTF-8"); mUartService.writeRXCharacteristic(value); //Update the log with time stamp String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); mMsgListAdapter.add("[" + currentDateTimeString + "] TX: " + message); mMsgList.smoothScrollToPosition(mMsgListAdapter.getCount() - 1); mSendMsg.setText(""); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.example.mego.adas.main.CarFragment.java
/** * methods used to refresh Ui state and organize the data *///from w ww . j av a 2 s . co m public void refreshUI() { //make sure there data before ~ if (endOfLineIndex > 0) { //if it start with # we know that we looking for if (recDataString.charAt(0) == '#') { //get the value from the string between indices String readValueAfterSub = recDataString.substring(1, recDataString.length() - 1); int oldCounter = 0; //create an array that will hold the sensors value ArrayList<String> sensorsValueList = new ArrayList<>(); for (int newCounter = 0; newCounter < readValueAfterSub.length(); newCounter++) { if (readValueAfterSub.charAt(newCounter) == '+') { sensorsValueList.add(readValueAfterSub.substring(oldCounter, newCounter)); oldCounter = newCounter + 1; } } for (int counter = 0; counter < sensorsValueList.size(); counter++) { //get the sensors values sensorsValues.setTemperatureSensorValue(Integer.parseInt(sensorsValueList.get(0))); tempSensorValue = sensorsValues.getTemperatureSensorValue(); tempPublishProcessor.onNext(tempSensorValue); //Temperature in Fahrenheit tempSensorInFahrenheit = (int) AdasUtils.celsiusToFahrenheit(tempSensorValue); sensorsValues.setLdrSensorValue(Integer.parseInt(sensorsValueList.get(1))); ldrSensorValue = sensorsValues.getLdrSensorValue(); ldrPublishProcessor.onNext(ldrSensorValue); sensorsValues.setPotSensorValue(Integer.parseInt(sensorsValueList.get(2))); potSensorValue = sensorsValues.getPotSensorValue(); potPublishProcessor.onNext(potSensorValue); accidentState = (Integer.parseInt(sensorsValueList.get(3))); if (NetworkUtil.isAvailableInternetConnection(getContext())) { accidentStateDatabaseReference.setValue(accidentState); } if (accidentState == 1) { accidentNotificationFlag++; if (accidentNotificationFlag == 1 && !NetworkUtil.isAvailableInternetConnection(getContext())) { NotificationUtils.showAccidentNotification(getContext()); } if (accidentNotificationFlag == 1) { //send a new accident with the current data,time ,longitude and latitude String currentDate = DateFormat.getDateInstance().format(new Date()); String currentTime = DateFormat.getTimeInstance().format(new Date()); Accident accident = new Accident(currentDate, currentTime, "Accident", longitude, latitude, null); if (NetworkUtil.isAvailableInternetConnection(getContext())) { accidentsDatabaseReference.push().setValue(accident); } } } else if (accidentState == 0) { accidentNotificationFlag = 0; } lDRSensorValueTextView.setText( String.format(getString(R.string.current_progress_bar_update), ldrSensorValue + "")); if (isFahrenheit) { tempSensorValueTextView.setText(String.format( getString(R.string.current_progress_bar_update), tempSensorInFahrenheit + "")); } else { tempSensorValueTextView.setText(String .format(getString(R.string.current_progress_bar_update), tempSensorValue + "")); } potSensorValueTextView.setText( String.format(getString(R.string.current_progress_bar_update), potSensorValue + "")); } if (NetworkUtil.isAvailableInternetConnection(getContext())) { //send data to Firebase SensorsValues sensorsValuesSend = new SensorsValues(tempSensorValue, ldrSensorValue, potSensorValue); sensorsValuesDatabaseReference.setValue(sensorsValuesSend); } if (tempSensorValue >= 40) { tempSensorValueTextView.setTextColor(getResources().getColor(R.color.red)); tempTextView.setTextColor(getResources().getColor(R.color.red)); } else { tempSensorValueTextView.setTextColor(getResources().getColor(R.color.colorPrimary)); tempTextView.setTextColor(getResources().getColor(R.color.colorPrimary)); } if (ldrSensorValue >= 800) { lDRSensorValueTextView.setTextColor(getResources().getColor(R.color.red)); ldrTextView.setTextColor(getResources().getColor(R.color.red)); } else { lDRSensorValueTextView.setTextColor(getResources().getColor(R.color.colorPrimary)); ldrTextView.setTextColor(getResources().getColor(R.color.colorPrimary)); } if (potSensorValue >= 800) { potSensorValueTextView.setTextColor(getResources().getColor(R.color.red)); potTextView.setTextColor(getResources().getColor(R.color.red)); } else { potSensorValueTextView.setTextColor(getResources().getColor(R.color.colorPrimary)); potTextView.setTextColor(getResources().getColor(R.color.colorPrimary)); } } //clear all string data recDataString.delete(0, recDataString.length()); } }
From source file:com.teeptrak.controller.MainActivity.java
public void onDatBtnClicked(final View v) { String message = "DAT"; byte[] value; try {//w w w. j ava 2 s . c o m //Send data to service value = message.getBytes("UTF-8"); mUartService.writeRXCharacteristic(value); //Update the log with time stamp String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); mMsgListAdapter.add("[" + currentDateTimeString + "] TX: " + message); mMsgList.smoothScrollToPosition(mMsgListAdapter.getCount() - 1); mSendMsg.setText(""); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.zpci.firstsignhairclipdemo.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); }/*from ww w . j a va2 s .c o m*/ break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; case REQUEST_DIAG_CMD: if (resultCode == Activity.RESULT_OK) { byte[] value = data.getByteArrayExtra("cmd"); Log.d(TAG, "Diag command request success. length = " + value.length + ", 0x" + Integer.toHexString(value[0] & 0xff) + ", " + value[0]); if (value[0] == (byte) 0x05) { //alarm arm/disarm if (value[1] == (byte) 0x00) { armed = true; alarmsent = false; adStream.reset(); // reset audio data buffer expectedAudioSamples = ALARMAUDIOSAMPLES; // set to default number of samples SensorStream.reset(); // reset sensor data buffer expectedSensorSamples = ALARMSENSORSAMPLES; // set to default } else armed = false; } try { mService.writeRXCharacteristic(value); } catch (Exception e) { Log.e(TAG, e.toString()); } ; //Update the log with time stamp and message sent String msg = ""; for (int i = 0; i < value.length; i++) { msg = msg + "0x" + Integer.toHexString(value[i] & 0xff) + " "; } String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); listAdapter.add("[" + currentDateTimeString + "] TX: " + msg); messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); } else { Log.d(TAG, "Diag command request result fail"); } break; default: Log.e(TAG, "bad activity result request code"); break; } }
From source file:com.javielinux.utils.Utils.java
public static String timeFromTweet(Context cnt, Date timeTweet) { if (Integer.parseInt(Utils.getPreference(cnt).getString("prf_date_format", "1")) == 1) { return diffDate(new Date(), timeTweet); } else {/* ww w. j a v a 2 s. c om*/ Date now = new Date(); if (now.getDay() == timeTweet.getDay() && now.getMonth() == timeTweet.getMonth() && now.getYear() == timeTweet.getYear()) { return DateFormat.getTimeInstance().format(timeTweet); } else { return DateFormat.getDateInstance().format(timeTweet); } } }
From source file:org.sakaiproject.evaluation.logic.EvalEmailsLogicImpl.java
/** * INTERNAL METHOD<br/>// ww w . j a va 2 s. c om * @param endTime * @param startTime * @return */ protected String calculateElapsedTimeMessage(Date endTime, Date startTime) { long elapsedTime = endTime.getTime() - startTime.getTime(); long milliseconds = elapsedTime % 1000L; long seconds = elapsedTime / 1000L; StringBuilder buf = new StringBuilder(); buf.append(seconds); buf.append("."); if (milliseconds < 10) { buf.append("00"); } else if (milliseconds < 100) { buf.append("0"); } buf.append(milliseconds); buf.append(" seconds from "); DateFormat df = DateFormat.getTimeInstance(); buf.append(df.format(startTime)); buf.append(" to "); buf.append(df.format(endTime)); String msg = buf.toString(); return msg; }