List of usage examples for java.text DateFormat SHORT
int SHORT
To view the source code for java.text DateFormat SHORT.
Click Source Link
From source file:edu.ku.brc.util.DateConverter.java
/** * /*from w ww. j a v a2 s . c om*/ */ public DateConverter() { String currentFormat = AppPreferences.getRemote().get("ui.formatting.scrdateformat", null); if (currentFormat.startsWith("MM") || currentFormat.startsWith("mm")) { preferMonthDay = true; } else if (currentFormat.startsWith("DD") || currentFormat.startsWith("dd")) { preferMonthDay = false; } else { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); //for default locale; SHORT -> completely numeric Calendar result = new GregorianCalendar(); result.set(2000, 3, 1); String dtstr = df.format(result.getTime()); int moIdx = dtstr.indexOf("4"); int dayIdx = dtstr.indexOf("1"); preferMonthDay = moIdx < dayIdx; } //System.out.println(df.) //preferMonthDay = /*loc == Locale.CANADA || */loc == Locale.US; }
From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { final CharSequence displayContents = resultHandler.getDisplayContents(); // if (copyToClipboard && !resultHandler.areContentsSecure()) { // ClipboardInterface.setText(displayContents, this); // }//www . ja v a 2s .com SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) { // resultHandler.handleButtonPress(resultHandler.getDefaultButtonID()); // return; // } statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); } else { barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp()))); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } final TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); final String baseUrl = "http://qrk.kuaipai.cn/loganal/base/scan/show-json-advert.action?code="; new Thread(new Runnable() { @Override public void run() { HttpGet get = new HttpGet(baseUrl + displayContents); Log.e(TAG, "full url = " + baseUrl + displayContents); HttpClient client = new DefaultHttpClient(); try { HttpResponse response = client.execute(get); String json = EntityUtils.toString(response.getEntity(), "UTF-8"); JSONObject jsonObject = new JSONObject(json); NetScanResult result = new NetScanResult(); result.name = jsonObject.getString("name"); result.url = jsonObject.getString("img"); Message message = new Message(); message.obj = result; message.what = 1; mNetHandler.sendMessage(message); } catch (Exception e) { mNetHandler.sendEmptyMessage(-1); e.printStackTrace(); } } }).start(); // contentsTextView.setText(displayContents); int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); // if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean( // PreferencesActivity.KEY_SUPPLEMENTAL, true)) { // SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, // resultHandler.getResult(), // historyManager, // this); // } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } }
From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { //- ------------------------------------------------------- // String text = rawResult.getText(); if (text != null && StringUtils.isUrl(text)) { if (text.contains("scan_login")) { statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); showConfirmLogin(text);/*from w ww .ja v a 2 s . co m*/ return; } if (text.contains("oschina.net")) { UIHelper.showUrlRedirect(CaptureActivity.this, text); finish(); return; } } try { BarCode2 bc = BarCode2.parse(text); int type = bc.getType(); switch (type) { case BarCode2.SIGN_IN:// handleSignIn(bc); return; default: break; } } catch (JSONException e) { e.printStackTrace(); } //- ------------------------------------------------------- // CharSequence displayContents = resultHandler.getDisplayContents(); if (copyToClipboard && !resultHandler.areContentsSecure()) { ClipboardInterface.setText(displayContents, this); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) { resultHandler.handleButtonPress(resultHandler.getDefaultButtonID()); return; } statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.app_icon)); } else { barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp()))); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); contentsTextView.setText(displayContents); int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) { //SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, // resultHandler.getResult(), // historyManager, // this); } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } }
From source file:com.farmerbb.notepad.activity.MainActivity.java
@Override public String loadNoteDate(String filename) { Date lastModified = new Date(Long.parseLong(filename)); return (DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(lastModified)); }
From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java
/** * Handle toggling of starred checkbox.//from w w w . java 2 s. co m */ private void onCheckedChanged(boolean wasFavorite) { int message = R.string.toast_favorites_added; if (wasFavorite) { /** * Remove from favorites. */ String[] args = new String[] { Integer.toString(mIdPost) }; mHandler.startDelete(FavoritesToggleQuery._TOKEN, null, Posts.CONTENT_STARRED_URI, Favorites.ID_POST + "=?", args); message = R.string.toast_favorites_removed; } else { /** * Add to favorites */ final ContentValues values = new ContentValues(); values.put(Favorites.ID_POST, mIdPost); if ((mFavoriteLabel != null) && (mFavoriteLabel.length() > 0)) { values.put(Favorites.LABEL, mFavoriteLabel); } else { String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new Date()); values.put(Favorites.LABEL, timestamp); } mHandler.startInsert(Posts.CONTENT_STARRED_URI, values); } parkingApp.showToastText(message, Toast.LENGTH_LONG); }
From source file:ca.uvic.cs.tagsea.statistics.svn.jobs.SVNCommentScanningJob.java
private String getDateString() { Date d = new Date(System.currentTimeMillis()); DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT); String key = format.format(d); key = key.replace('/', '-'); key = key.replace('\\', '\\'); key = key.replace(' ', '_'); key = key.replace(':', '_'); key = key.replace(';', '.'); return key;/*from ww w . jav a 2s . c o m*/ }
From source file:de.blizzy.backup.settings.SettingsDialog.java
private void updateExplanationLabel() { DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, dailyTime.getHours()); c.set(Calendar.MINUTE, dailyTime.getMinutes()); scheduleExplanationLabel.setText("- " + (runHourlyRadio.getSelection() ? //$NON-NLS-1$ Messages.ScheduleExplanation_HourlyBackups : NLS.bind(Messages.ScheduleExplanation_DailyBackups, timeFormat.format(c.getTime()))) + "\n" + //$NON-NLS-1$ (runHourlyRadio.getSelection() ? "- " + //$NON-NLS-1$ NLS.bind(Messages.ScheduleExplanation_HourlyBackupsKeepTime, Integer.valueOf(BackupPlugin.KEEP_HOURLIES_DAYS)) + "\n" : //$NON-NLS-1$ "") //$NON-NLS-1$ + "- " + NLS.bind(Messages.ScheduleExplanation_DailyBackupsKeepTime, Integer.valueOf(BackupPlugin.KEEP_DAILIES_DAYS)) + "\n" + //$NON-NLS-1$ "- " + (maxAgeDaysRadio.getSelection() ? //$NON-NLS-1$ NLS.bind(Messages.ScheduleExplanation_WeeklyBackupsKeepDays, Integer.valueOf(maxAgeDaysSpinner.getSelection())) : Messages.ScheduleExplanation_WeeklyBackupsNoAge) + "\n" + //$NON-NLS-1$ "- " + //$NON-NLS-1$ NLS.bind(Messages.ScheduleExplanation_WeeklyBackupsKeepDisk, Integer.valueOf(maxDiskFillRateSpinner.getSelection())) +/*from w w w.j ava 2s. com*/ // compensate for missing line (!runHourlyRadio.getSelection() ? "\n " : "")); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java
private String doConvertToString(Map<String, Object> context, Object value) { String result = null;//from ww w . j a v a 2 s . co m if (value instanceof int[]) { int[] x = (int[]) value; List<Integer> intArray = new ArrayList<Integer>(x.length); for (int aX : x) { intArray.add(Integer.valueOf(aX)); } result = StringUtils.join(intArray, ", "); } else if (value instanceof long[]) { long[] x = (long[]) value; List<Long> longArray = new ArrayList<Long>(x.length); for (long aX : x) { longArray.add(Long.valueOf(aX)); } result = StringUtils.join(longArray, ", "); } else if (value instanceof double[]) { double[] x = (double[]) value; List<Double> doubleArray = new ArrayList<Double>(x.length); for (double aX : x) { doubleArray.add(new Double(aX)); } result = StringUtils.join(doubleArray, ", "); } else if (value instanceof boolean[]) { boolean[] x = (boolean[]) value; List<Boolean> booleanArray = new ArrayList<Boolean>(x.length); for (boolean aX : x) { booleanArray.add(new Boolean(aX)); } result = StringUtils.join(booleanArray, ", "); } else if (value instanceof Date) { DateFormat df = null; if (value instanceof java.sql.Time) { df = DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale(context)); } else if (value instanceof java.sql.Timestamp) { SimpleDateFormat dfmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, getLocale(context)); df = new SimpleDateFormat(dfmt.toPattern() + MILLISECOND_FORMAT); } else { df = DateFormat.getDateInstance(DateFormat.SHORT, getLocale(context)); } result = df.format(value); } else if (value instanceof String[]) { result = StringUtils.join((String[]) value, ", "); } return result; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * Sets all the axis formatting options. This includes the colors and fonts to use on * the axis as well as the color to use when drawing the axis line. * * @param axis the axis to format/* w w w . ja v a2 s . c o m*/ * @param labelFont the font to use for the axis label * @param labelColor the color of the axis label * @param tickLabelFont the font to use for each tick mark value label * @param tickLabelColor the color of each tick mark value label * @param tickLabelMask formatting mask for the label. If the axis is a NumberAxis then * the mask should be <code>java.text.DecimalFormat</code> mask, and * if it is a DateAxis then the mask should be a * <code>java.text.SimpleDateFormat</code> mask. * @param verticalTickLabels flag to draw tick labels at 90 degrees * @param lineColor color to use when drawing the axis line and any tick marks */ protected void configureAxis(Axis axis, JRFont labelFont, Color labelColor, JRFont tickLabelFont, Color tickLabelColor, String tickLabelMask, Boolean verticalTickLabels, Color lineColor, boolean isRangeAxis, Comparable<?> axisMinValue, Comparable<?> axisMaxValue) { axis.setLabelFont(fontUtil.getAwtFont(getFont(labelFont), getLocale())); axis.setTickLabelFont(fontUtil.getAwtFont(getFont(tickLabelFont), getLocale())); if (labelColor != null) { axis.setLabelPaint(labelColor); } if (tickLabelColor != null) { axis.setTickLabelPaint(tickLabelColor); } if (lineColor != null) { axis.setAxisLinePaint(lineColor); axis.setTickMarkPaint(lineColor); } TimeZone timeZone = chartContext.getTimeZone(); if (axis instanceof DateAxis && timeZone != null) { // used when no mask is set ((DateAxis) axis).setTimeZone(timeZone); } // FIXME use locale for formats if (tickLabelMask != null) { if (axis instanceof NumberAxis) { NumberFormat fmt = NumberFormat.getInstance(getLocale()); if (fmt instanceof DecimalFormat) { ((DecimalFormat) fmt).applyPattern(tickLabelMask); } ((NumberAxis) axis).setNumberFormatOverride(fmt); } else if (axis instanceof DateAxis) { DateFormat fmt; if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT")) { fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale()); } else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM")) { fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale()); } else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG")) { fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale()); } else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL")) { fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale()); } else { fmt = new SimpleDateFormat(tickLabelMask, getLocale()); } if (timeZone != null) { fmt.setTimeZone(timeZone); } ((DateAxis) axis).setDateFormatOverride(fmt); } // ignore mask for other axis types. } if (verticalTickLabels != null && axis instanceof ValueAxis) { ((ValueAxis) axis).setVerticalTickLabels(verticalTickLabels); } setAxisBounds(axis, isRangeAxis, axisMinValue, axisMaxValue); }
From source file:org.glom.web.server.ReportGenerator.java
/** * @param x// ww w. j ava 2 s.co m * @param libglomLayoutItemField * @return */ private JRDesignTextField createFieldValueElement(final Position pos, final LayoutItemField libglomLayoutItemField) { final JRDesignTextField textField = new JRDesignTextField(); // Make sure this field starts at the right of the previous field, // because JasperReports uses absolute positioning. textField.setY(pos.y); textField.setX(pos.x); textField.setWidth(width); // No data will be shown without this. // This only stretches vertically, but that is better than // nothing. textField.setStretchWithOverflow(true); textField.setHeight(height); // We must specify _some_ height. final JRDesignExpression expression = createFieldExpression(libglomLayoutItemField); textField.setExpression(expression); if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_NUMERIC) { // Numeric formatting: final Formatting formatting = libglomLayoutItemField.getFormattingUsed(); final NumericFormat numericFormat = formatting.getNumericFormat(); final DecimalFormat format = new DecimalFormat(); format.setMaximumFractionDigits(numericFormat.getDecimalPlaces()); format.setGroupingUsed(numericFormat.getUseThousandsSeparator()); // TODO: Use numericFormat.get_currency_symbol(), possibly via format.setCurrency(). textField.setPattern(format.toPattern()); } else if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_DATE) { // Date formatting // TODO: Use a 4-digit-year short form, somehow. try // We use a try block because getDateInstance() is not guaranteed to return a SimpleDateFormat. { final SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.ROOT); textField.setPattern(format.toPattern()); } catch (final Exception ex) { Log.info("ReportGenerator: The cast of SimpleDateFormat failed."); } } else if (libglomLayoutItemField.getGlomType() == GlomFieldType.TYPE_TIME) { // Time formatting try // We use a try block because getDateInstance() is not guaranteed to return a SimpleDateFormat. { final SimpleDateFormat format = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, Locale.ROOT); textField.setPattern(format.toPattern()); } catch (final Exception ex) { Log.info("ReportGenerator: The cast of SimpleDateFormat failed."); } } return textField; }