List of usage examples for android.text.format DateFormat format
public static CharSequence format(CharSequence inFormat, Calendar inDate)
From source file:com.todoroo.astrid.timers.TimerControlSet.java
private void updateChronometer() { timerButton.setImageResource(timerActive() ? R.drawable.ic_pause_24dp : R.drawable.ic_play_arrow_24dp); long elapsed = this.elapsed.getTimeDurationInSeconds() * 1000L; if (timerActive()) { chronometer.setVisibility(View.VISIBLE); elapsed += DateUtilities.now() - timerStarted; chronometer.setBase(SystemClock.elapsedRealtime() - elapsed); if (elapsed > DateUtilities.ONE_DAY) { chronometer.setOnChronometerTickListener(cArg -> { long t = SystemClock.elapsedRealtime() - cArg.getBase(); cArg.setText(DateFormat.format("d'd' h:mm", t)); //$NON-NLS-1$ });//from w w w. j a v a2 s .co m } chronometer.start(); } else { chronometer.setVisibility(View.GONE); chronometer.stop(); } }
From source file:net.fabiszewski.ulogger.GpxExportService.java
/** * Write <trkseg> tag//from w w w. jav a 2 s . co m * * @param serializer XmlSerializer * @throws IOException IO exception * @throws IllegalArgumentException Xml illegal argument * @throws IllegalStateException Xml illegal state */ private void writePositions(@NonNull XmlSerializer serializer) throws IOException, IllegalArgumentException, IllegalStateException { Cursor cursor = db.getPositions(); // suppress as it requires target api 19 //noinspection TryFinallyCanBeTryWithResources try { serializer.startTag(null, "trkseg"); while (cursor.moveToNext()) { serializer.startTag(null, "trkpt"); serializer.attribute(null, "lat", cursor.getString(cursor.getColumnIndex(DbContract.Positions.COLUMN_LATITUDE))); serializer.attribute(null, "lon", cursor.getString(cursor.getColumnIndex(DbContract.Positions.COLUMN_LONGITUDE))); if (!cursor.isNull(cursor.getColumnIndex(DbContract.Positions.COLUMN_ALTITUDE))) { writeTag(serializer, "ele", cursor.getString(cursor.getColumnIndex(DbContract.Positions.COLUMN_ALTITUDE))); } long timestamp = cursor.getLong(cursor.getColumnIndex(DbContract.Positions.COLUMN_TIME)); String time = DateFormat.format("yyyy-MM-ddThh:mm:ss", timestamp * 1000).toString(); writeTag(serializer, "time", time); writeTag(serializer, "name", cursor.getString(cursor.getColumnIndex(DbContract.Positions._ID))); serializer.endTag(null, "trkpt"); } serializer.endTag(null, "trkseg"); } finally { cursor.close(); } }
From source file:planets.position.Position.java
private void updateDisplay() { gc = new GregorianCalendar(mYear, mMonth, mDay, mHour, mMinute, 0); dateButton.setText(DateFormat.format("M/dd/yyyy", gc)); timeButton.setText(DateFormat.format("h:mm aa", gc)); computeLocation();//w ww . j a va 2 s . co m }
From source file:com.better.alarm.presenter.alert.AlarmAlertReceiver.java
private String formatTimeString() { String format = android.text.format.DateFormat.is24HourFormat(mContext) ? DM24 : DM12; Calendar calendar = alarm.getSnoozedTime(); String timeString = (String) DateFormat.format(format, calendar); return timeString; }
From source file:com.adarshahd.indianrailinfo.donate.TrainEnquiry.java
@Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mCal.set(Calendar.getInstance().get(Calendar.YEAR), monthOfYear, dayOfMonth); mBtnDate.setText(DateFormat.format("dd MMM yyyy", mCal)); }
From source file:cn.edu.nuc.seeworld.fg.ColorFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == CAMERA && resultCode == Activity.RESULT_OK && null != data) { String sdState = Environment.getExternalStorageState(); if (!sdState.equals(Environment.MEDIA_MOUNTED)) { return; }/*from w ww .j a va 2 s .co m*/ String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg"; Bundle bundle = data.getExtras(); //???? Bitmap bitmap = (Bitmap) bundle.get("data"); FileOutputStream fout = null; File file = new File("/sdcard/pintu/"); file.mkdirs(); String filename = file.getPath() + name; try { fout = new FileOutputStream(filename); pic_path = filename; bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fout); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { fout.flush(); fout.close(); } catch (IOException e) { e.printStackTrace(); } } pic_imageView.setImageBitmap(bitmap); pic_imageView.setVisibility(View.VISIBLE); } if (requestCode == PHOTO && resultCode == Activity.RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumns = { MediaStore.Images.Media.DATA }; Cursor c = this.getActivity().getContentResolver().query(selectedImage, filePathColumns, null, null, null); c.moveToFirst(); int columnIndex = c.getColumnIndex(filePathColumns[0]); String picturePath = c.getString(columnIndex); c.close(); //? Log.d("SEEWORLDTAG", picturePath); Bitmap bitmap = BitmapFactory.decodeFile(picturePath); pic_path = picturePath; pic_imageView.setImageBitmap(bitmap); pic_imageView.setVisibility(View.VISIBLE); } }
From source file:org.jnegre.android.osmonthego.service.ExportService.java
private File getDestinationFile() { File externalStorage = Environment.getExternalStorageDirectory(); String dirName = getApplicationInfo().packageName; File dir = new File(externalStorage, dirName); String fileName = DateFormat.format("'onthego-'yyyy-MM-dd_H-m'.osm'", new Date()).toString(); return new File(dir, fileName); }
From source file:it.unipr.ce.dsg.gamidroid.activities.SensorDataViewActivity.java
/** * Method to process the JSon descriptor of the resource the node looked * for, when it is received.//from ww w . ja v a2 s . c om */ private void processSearchedResource(String jsonDescriptor) { System.out.println("\n--- Processing the sensor's data...\n"); try { JSONObject obj = new JSONObject(jsonDescriptor); String name = obj.getString("name"); // JSONObject subjectObj = obj.getJSONObject("subject"); JSONObject locationObj = obj.getJSONObject("location"); if (name.equalsIgnoreCase(temperatureMessageType)) { // final String subjectValue = subjectObj.getString("value"); JSONObject locationValue = new JSONObject(locationObj.getString("value")); JSONObject building = locationValue.getJSONObject("building"); final String buildingValue = building.getString("value"); JSONObject room = locationValue.getJSONObject("room"); final String roomValue = room.getString("value"); JSONObject floor = locationValue.getJSONObject("floor"); final String floorValue = floor.getString("value"); JSONObject sensor = locationValue.getJSONObject("sensor"); final String sensorValue = sensor.getString("value"); if (sensorValue.equalsIgnoreCase(sensorName)) { runOnUiThread(new Runnable() { public void run() { if (!stopThread) { TextView textBuilding = (TextView) findViewById(R.id.textAddress); TextView textFloor = (TextView) findViewById(R.id.textFloor); TextView textRoom = (TextView) findViewById(R.id.textRoom); TextView textSensor = (TextView) findViewById(R.id.textSensor); TextView textTemperature = (TextView) findViewById(R.id.textTemperature); textBuilding.setText("Address: " + buildingValue); textFloor.setText("Floor: " + floorValue); textRoom.setText("Room: " + roomValue); textSensor.setText("Sensor: " + sensorValue); // textTemperature.setText("Temperature: " + subjectValue); // graphViewSeries.appendData(new GraphViewData(currentX++, Double.parseDouble(subjectValue)), true, MAX_DATA_COUNT); int min = 26; int max = 30; double randomValue = min + (int) (Math.random() * ((max - min) + 1)); String randomValueString = "" + randomValue; textTemperature.setText("Temperature: " + randomValueString); int length = hLabels.length; length++; String[] localLabels = new String[length]; for (int i = 0; i < length - 1; i++) { localLabels[i] = hLabels[i]; } Date d = new Date(); String s = (String) DateFormat.format("H:m:s ", d.getTime()); System.out.println(s); localLabels[length - 1] = s; hLabels = localLabels; //hLabels[length]=s; graphView.setHorizontalLabels(hLabels); graphViewSeries.appendData(new GraphViewData(currentX++, randomValue), false, MAX_DATA_COUNT); } } }); } } } catch (JSONException e) { e.printStackTrace(); } }
From source file:planets.position.ViewWhatsUp.java
private void onTaskCompleted(long time) { Log.i(TAG, "Activity " + this + " has been notified the task is complete."); // Remove the dialog if it is visible. FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment prev = getSupportFragmentManager().findFragmentByTag("calcDialogView"); if (prev != null) { ft.remove(prev);//from w w w .j a va 2s .co m } ft.commitAllowingStateLoss(); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); viewDate.setText("What's up on " + DateFormat.format("MMM d @ hh:mm aa", cal)); planetsList.setVisibility(View.VISIBLE); fillData(filter); }
From source file:com.cloverstudio.spika.CameraCropActivity.java
public void startCamera() { // Check if camera exists if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) { Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show(); finish();/* w w w . j av a 2s . c o m*/ } else { try { long date = System.currentTimeMillis(); String filename = DateFormat.format("yyyy-MM-dd_kk.mm.ss", date).toString() + ".jpg"; _path = this.getExternalCacheDir() + "/" + filename; File file = new File(_path); // File file = new File(getFileDir(getBaseContext()), filename); Uri outputFileUri = Uri.fromFile(file); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, CAMERA); } catch (Exception ex) { Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show(); finish(); } } }