Example usage for java.text DateFormat SHORT

List of usage examples for java.text DateFormat SHORT

Introduction

In this page you can find the example usage for java.text DateFormat SHORT.

Prototype

int SHORT

To view the source code for java.text DateFormat SHORT.

Click Source Link

Document

Constant for short style pattern.

Usage

From source file:com.glanznig.beepme.view.ViewSampleFragment.java

private void populateFields() {

    if (sampleId != 0L) {
        Sample s = new SampleTable(getActivity().getApplicationContext()).getSampleWithTags(sampleId);

        TextView timestamp = (TextView) getView().findViewById(R.id.view_sample_timestamp);
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
        timestamp.setText(dateFormat.format(s.getTimestamp()));

        TextView title = (TextView) getView().findViewById(R.id.view_sample_title);
        if (s.getTitle() != null && s.getTitle().length() > 0) {
            title.setText(s.getTitle());
        } else {// w w  w .jav a2 s.co  m
            title.setText(getString(R.string.sample_untitled));
        }

        TextView description = (TextView) getView().findViewById(R.id.view_sample_description);
        if (s.getDescription() != null && s.getDescription().length() > 0) {
            description.setTextSize(14);
            description.setText(s.getDescription());
        } else {
            description.setTextSize(12);
            // not editable any more
            if ((Calendar.getInstance().getTimeInMillis() - s.getTimestamp().getTime()) >= 24 * 60 * 60
                    * 1000) {
                description.setText(getString(R.string.sample_no_description));
            } else {
                description.setText(getString(R.string.sample_no_description_editable));
            }
        }

        boolean hasKeywordTags = false;

        FlowLayout keywordHolder = (FlowLayout) getView().findViewById(R.id.view_sample_keyword_container);
        keywordHolder.removeAllViews();

        Iterator<Tag> i = s.getTags().iterator();
        Tag tag = null;

        while (i.hasNext()) {
            tag = i.next();
            if (tag.getVocabularyId() == 1) {

                TextView view = new TextView(getView().getContext());
                view.setText(tag.getName());

                final float scale = getResources().getDisplayMetrics().density;
                int textPaddingLeftRight = 6;
                int textPaddingTopBottom = 2;

                view.setPadding((int) (textPaddingLeftRight * scale + 0.5f),
                        (int) (textPaddingTopBottom * scale + 0.5f),
                        (int) (textPaddingLeftRight * scale + 0.5f),
                        (int) (textPaddingTopBottom * scale + 0.5f));
                view.setBackgroundColor(getResources().getColor(R.color.bg_keyword));

                keywordHolder.addView(view);
                hasKeywordTags = true;
            }
        }

        TextView noKeywordsView = (TextView) getView().findViewById(R.id.view_sample_no_keywords);
        if (!hasKeywordTags) {
            keywordHolder.setVisibility(View.GONE);
            noKeywordsView.setVisibility(View.VISIBLE);
            // not editable any more (after 1 day)
            if ((Calendar.getInstance().getTimeInMillis() - s.getTimestamp().getTime()) >= 24 * 60 * 60
                    * 1000) {
                noKeywordsView.setText(getString(R.string.sample_no_keywords));
            } else {
                noKeywordsView.setText(getString(R.string.sample_no_keywords_editable));
            }
        } else {
            noKeywordsView.setVisibility(View.GONE);
            keywordHolder.setVisibility(View.VISIBLE);
        }

        photoView = (SamplePhotoView) getView().findViewById(R.id.view_sample_photo);
        photoView.setRights(false, false); // read only
        DisplayMetrics metrics = getView().getContext().getResources().getDisplayMetrics();

        int thumbnailSize;
        if (!isLandscape()) {
            photoView.setFrameWidth(LayoutParams.MATCH_PARENT);
            thumbnailSize = (int) (metrics.widthPixels / metrics.density + 0.5f);
        } else {
            thumbnailSize = (int) (metrics.heightPixels / metrics.density + 0.5f);
        }

        String thumbnailUri = PhotoUtils.getThumbnailUri(s.getPhotoUri(), thumbnailSize);
        if (thumbnailUri != null) {
            File thumb = new File(thumbnailUri);
            if (thumb.exists()) {
                ImgLoadHandler handler = new ImgLoadHandler(photoView);
                PhotoUtils.getAsyncBitmap(getView().getContext(), thumbnailUri, handler);
            } else {
                Handler handler = new Handler(this);
                PhotoUtils.generateThumbnails(getView().getContext(), s.getPhotoUri(), handler);
            }
        } else {
            photoView.unsetPhoto();
        }
    }
}

From source file:ca.mudar.snoozy.ui.widget.HistoryCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);

    /*//from ww w .j a v  a 2 s.com
     Get current cursor values
      */
    final boolean isPowerOn = (1 == cursor.getInt(HistoryQuery.IS_POWER_ON));
    final long timestamp = cursor.getLong(HistoryQuery.TIME_STAMP);
    final boolean isFirst = (1 == cursor.getInt(HistoryQuery.IS_FIRST));
    final boolean isLast = (1 == cursor.getInt(HistoryQuery.IS_LAST));
    final int batteryLevel = cursor.getInt(HistoryQuery.BATTERY_LEVEL);

    /*
     Prepare the data
      */
    final String sPowerStatus = mResources.getString(
            isPowerOn ? R.string.history_item_power_connected : R.string.history_item_power_disconnected);
    final String sBatteryLevel = String.format(mResources.getString(R.string.history_item_battery_level),
            batteryLevel);
    final int resPowerStatusColor = mResources
            .getColor(isPowerOn ? R.color.card_row_highlight_color : R.color.card_row_color);

    String sTimestamp;
    String sDay;

    if (DateUtils.isToday(timestamp)) {
        sDay = mResources.getString(R.string.history_item_day_today);
        sTimestamp = (String) DateUtils.formatSameDayTime(timestamp, mMillis, 0, DateFormat.SHORT);
        //            sTimestamp = (String) DateUtils.getRelativeTimeSpanString(timestamp,now, 0, 0);
    } else {
        sDay = (String) DateUtils.getRelativeTimeSpanString(timestamp, mMillis, DateUtils.DAY_IN_MILLIS,
                DateUtils.FORMAT_ABBREV_RELATIVE);
        //            sDay = sDay.substring(0,1).toUpperCase() + sDay.substring(1);
        sTimestamp = mTimeFormat.format(new Date(timestamp));
    }
    sDay = sDay.substring(0, 1).toUpperCase() + sDay.substring(1);

    /*
     Set UI values
     */
    ((TextView) view.findViewById(R.id.history_is_power_on)).setText(sPowerStatus);
    ((TextView) view.findViewById(R.id.history_is_power_on)).setTextColor(resPowerStatusColor);
    ((TextView) view.findViewById(R.id.history_timestamp)).setText(sTimestamp);
    ((TextView) view.findViewById(R.id.history_battery_level)).setText(sBatteryLevel);

    if (isFirst && isLast) {
        ((TextView) view.findViewById(R.id.history_day)).setText(sDay);

        view.findViewById(R.id.history_header).setVisibility(View.VISIBLE);

        view.setBackgroundResource(R.drawable.bg_cards_top_bottom);
    } else if (isLast) {
        ((TextView) view.findViewById(R.id.history_day)).setText(sDay);

        view.findViewById(R.id.history_header).setVisibility(View.VISIBLE);

        view.setBackgroundResource(R.drawable.bg_cards_top);
    } else if (isFirst) {
        view.findViewById(R.id.history_header).setVisibility(View.GONE);

        view.setBackgroundResource(R.drawable.bg_cards_bottom);
    } else {
        view.findViewById(R.id.history_header).setVisibility(View.GONE);

        view.setBackgroundResource(R.drawable.bg_cards_middle);
    }
}

From source file:us.mn.state.health.lims.common.util.validator.DateValidator.java

/** 
 * &lt;p&gt;Checks if the field is a valid date.  The &lt;code&gt;Locale&lt;/code&gt; is 
 * used with &lt;code&gt;java.text.DateFormat&lt;/code&gt;.  The setLenient method 
 * is set to &lt;code&gt;false&lt;/code&gt; for all.&lt;/p&gt; 
 * //from   w  w  w. j  a  v a2 s. c  o  m
 * @param value The value validation is being performed on. 
 * @param locale The locale to use for the date format, defaults to the default 
 * system default if null. 
*/
public boolean isValid(String value, Locale locale) {
    if (value == null) {
        return false;
    }
    //System.out.println("value & locale " + value + " " + locale);

    DateFormat formatter = null;
    if (locale != null) {
        formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    } else {
        formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
    }
    formatter.setLenient(false);
    try {
        formatter.parse(value);
    } catch (ParseException e) {
        //bugzilla 2154
        LogEvent.logError("DateValidator", "isValid()", e.toString());
        return false;
    }
    return true;
}

From source file:DateTimeEditor.java

public DateTimeEditor() {
    m_timeOrDateType = DATETIME;
    m_lengthStyle = DateFormat.SHORT;
    init();
}

From source file:com.androidformenhancer.internal.impl.DatePickerDialogSupportFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();//from www.j ava  2s .c om
    int id = args.getInt(ARG_TARGET_VIEW_RES_ID);
    View v = getActivity().findViewById(id);
    if (v == null || !(v instanceof TextView)) {
        throw new IllegalArgumentException("Target view must be valid TextView: " + v);
    }
    final TextView tv = (TextView) v;
    if (TextUtils.isEmpty(tv.getText())) {
        int defaultMessageId = args.getInt(ARG_DEFAULT_MESSAGE_RES_ID);
        tv.setText(getActivity().getString(defaultMessageId));
    }

    DatePickerDialog.OnDateSetListener callBack = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar c = Calendar.getInstance(Locale.getDefault());
            c.set(Calendar.YEAR, year);
            c.set(Calendar.MONTH, monthOfYear);
            c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            tv.setText(DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(c.getTime()));
        }
    };
    Calendar c = Calendar.getInstance();
    final Dialog dialog = new DatePickerDialog(getActivity(), callBack, c.get(Calendar.YEAR),
            c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)) {
    };
    return dialog;
}

From source file:Main.java

public Main() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);/* ww  w  .  j  a  v  a2s  .  c om*/
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JSpinner defaultSpinner = new JSpinner();
    addRow("Default", defaultSpinner);

    JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5));
    addRow("Bounded", boundedSpinner);

    String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts));
    addRow("List", listSpinner);

    JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) {
        public Object getNextValue() {
            return super.getPreviousValue();
        }

        public Object getPreviousValue() {
            return super.getNextValue();
        }
    });
    addRow("Reverse List", reverseListSpinner);

    JSpinner dateSpinner = new JSpinner(new SpinnerDateModel());
    addRow("Date", dateSpinner);

    JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel());
    String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern();
    betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern));
    addRow("Better Date", betterDateSpinner);

    JSpinner timeSpinner = new JSpinner(new SpinnerDateModel());
    pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern();
    timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern));
    addRow("Time", timeSpinner);

    JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat"));
    addRow("Word permutations", permSpinner);
}

From source file:com.robestone.hudson.compactcolumns.CompactColumnsTest.java

public void testDateTimeFormats() {
    doTestDateTimeFormats(Locale.US, DateFormat.SHORT, DateFormat.SHORT, "6/24/10 2:56 PM");
    doTestDateTimeFormats(Locale.US, DateFormat.MEDIUM, DateFormat.SHORT, "Jun 24, 2010 2:56 PM");
    doTestDateTimeFormats(Locale.GERMAN, DateFormat.SHORT, DateFormat.SHORT, "24.06.10 14:56");
}

From source file:de.tobiasbielefeld.solitaire.ui.Statistics.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activty_statistics);

    int padding = (int) getResources().getDimension(R.dimen.statistics_table_padding);
    int textSize = getResources().getInteger(R.integer.statistics_text_size);
    boolean addedEntries = false;
    TableRow row;//from  w  ww. j a va  2  s  . co m

    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    tableLayout = (TableLayout) findViewById(R.id.statisticsTableHighScores);
    textWonGames = (TextView) findViewById(R.id.statisticsTextViewGamesWon);
    textWinPercentage = (TextView) findViewById(R.id.statisticsTextViewWinPercentage);

    loadData();

    for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it
        if (scores.get(i, 0) == 0) //if the score is zero, don't show it
            continue;

        if (!addedEntries)
            addedEntries = true;

        row = new TableRow(this);

        TextView textView1 = new TextView(this);
        TextView textView2 = new TextView(this);
        TextView textView3 = new TextView(this);
        TextView textView4 = new TextView(this);

        textView1.setText(String.format(Locale.getDefault(), "%s", scores.get(i, 0)));
        textView2.setText(String.format(Locale.getDefault(), "%02d:%02d:%02d", //add it to the view
                scores.get(i, 1) / 3600, (scores.get(i, 1) % 3600) / 60, (scores.get(i, 1) % 60)));

        textView3.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(scores.get(i, 2)));
        //textView4.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(scores.get(i,2)));
        textView4.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(scores.get(i, 2)));

        textView1.setPadding(padding, 0, padding, 0);
        textView2.setPadding(padding, 0, padding, 0);
        textView3.setPadding(padding, 0, padding, 0);
        textView4.setPadding(padding, 0, padding, 0);

        textView1.setTextSize(textSize);
        textView2.setTextSize(textSize);
        textView3.setTextSize(textSize);
        textView4.setTextSize(textSize);

        textView1.setGravity(Gravity.CENTER);
        textView2.setGravity(Gravity.CENTER);
        textView3.setGravity(Gravity.CENTER);
        textView4.setGravity(Gravity.CENTER);

        row.addView(textView1);
        row.addView(textView2);
        row.addView(textView3);
        row.addView(textView4);
        row.setGravity(Gravity.CENTER);
        tableLayout.addView(row);
    }
}

From source file:de.tobiasbielefeld.solitaire.ui.statistics.HighScoresFragment.java

/**
 * Loads the high score list/*from   w  ww  .j a  v a  2 s.co m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_statistics_tab2, container, false);

    //if the app got killed while the statistics are open and then the user restarts the app,
    //my helper classes aren't initialized so they can't be used. In this case, simply
    //close the statistics
    try {
        loadData();
    } catch (NullPointerException e) {
        getActivity().finish();
        return view;
    }

    TableLayout tableLayout = (TableLayout) view.findViewById(R.id.statisticsTableHighScores);
    TextView textNoEntries = (TextView) view.findViewById(R.id.statisticsTextNoEntries);

    if (scores.getHighScore(0, 0) != 0) {
        textNoEntries.setVisibility(View.GONE);
    }

    for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it
        if (scores.getHighScore(i, 0) == 0) { //if the score is zero, don't show it
            continue;
        }

        TableRow row = (TableRow) LayoutInflater.from(getContext()).inflate(R.layout.statistics_scores_row,
                null);

        TextView textView1 = (TextView) row.findViewById(R.id.row_cell_1);
        TextView textView2 = (TextView) row.findViewById(R.id.row_cell_2);
        TextView textView3 = (TextView) row.findViewById(R.id.row_cell_3);
        TextView textView4 = (TextView) row.findViewById(R.id.row_cell_4);

        textView1.setText(String.format(Locale.getDefault(), "%s %s", scores.getHighScore(i, 0), dollar));
        long time = scores.getHighScore(i, 1);
        textView2.setText(String.format(Locale.getDefault(), "%02d:%02d:%02d", time / 3600, (time % 3600) / 60,
                (time % 60)));
        textView3.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(scores.getHighScore(i, 2)));
        textView4.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(scores.getHighScore(i, 2)));

        tableLayout.addView(row);
    }

    return view;
}

From source file:org.olat.core.util.StringHelper.java

/**
 * @param date//from  w ww  .  j a  va 2 s.c  o  m
 * @param locale
 * @return formatted date
 */
public static String formatLocaleDate(long date, Locale locale) {
    if (date == -1)
        return "-";
    return DateFormat.getDateInstance(DateFormat.SHORT, locale).format(new Date(date));
}