Example usage for java.text DateFormat getTimeInstance

List of usage examples for java.text DateFormat getTimeInstance

Introduction

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

Prototype

public static final DateFormat getTimeInstance() 

Source Link

Document

Gets the time formatter with the default formatting style for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.nextgis.maplibui.formcontrol.DateTime.java

@Override
public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor,
        SharedPreferences preferences) throws JSONException {
    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);

    if (!ControlHelper.isEnabled(fields, mFieldName)) {
        setEnabled(false);/*from  w  w  w. j  a v  a2 s .  co  m*/
        getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_ATOP);
    }

    if (attributes.has(JSON_DATE_TYPE_KEY)) {
        mPickerType = attributes.getInt(JSON_DATE_TYPE_KEY);
    }

    switch (mPickerType) {

    case 0:
        mDateFormat = (SimpleDateFormat) DateFormat.getDateInstance();
        mPickerType = GeoConstants.FTDate;
        break;

    case 1:
        mDateFormat = (SimpleDateFormat) DateFormat.getTimeInstance();
        mPickerType = GeoConstants.FTTime;
        break;

    default:
        mPickerType = FTDateTime;
    case 2:
        mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance();
        mPickerType = GeoConstants.FTDateTime;
        break;
    }

    long timestamp = System.currentTimeMillis();
    if (ControlHelper.hasKey(savedState, mFieldName)) {
        timestamp = savedState.getLong(ControlHelper.getSavedStateKey(mFieldName));
    } else if (null != featureCursor) { // feature exists
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0) {
            timestamp = featureCursor.getLong(column);
        }
    } else { // new feature
        if (attributes.has(JSON_TEXT_KEY) && !TextUtils.isEmpty(attributes.getString(JSON_TEXT_KEY).trim())) {
            String defaultValue = attributes.getString(JSON_TEXT_KEY);
            timestamp = parseDateTime(defaultValue, mPickerType);
        }

        if (mIsShowLast) {
            timestamp = preferences.getLong(mFieldName, timestamp);
        }
    }

    mCalendar.setTimeInMillis(timestamp);
    setText(mDateFormat.format(mCalendar.getTime()));
    setSingleLine(true);
    setFocusable(false);
    setOnClickListener(getDateUpdateWatcher(mPickerType));

    String pattern = mDateFormat.toLocalizedPattern();
    setHint(pattern);
}

From source file:com.cardiograph.view.BLEActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//ww w.  j  av a2  s  . c o m
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    service_init();

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mBtAdapter.isEnabled()) {
                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                if (btnConnectDisconnect.getText().equals("Connect")) {

                    //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices

                    Intent newIntent = new Intent(BLEActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {
                    //Disconnect button pressed
                    if (mDevice != null) {
                        mService.disconnect();

                    }
                }
            }
        }
    });
    // Handler Send button  
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                mService.writeRXCharacteristic(value);
                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Set initial UI state

}

From source file:com.wordpress.bennthomsen.bleuart.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from   w w  w.  ja v a2 s .co m*/
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    service_init();

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mBtAdapter.isEnabled()) {
                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                if (btnConnectDisconnect.getText().equals("Connect")) {

                    //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices

                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {
                    //Disconnect button pressed
                    if (mDevice != null) {
                        mService.disconnect();

                    }
                }
            }
        }
    });
    // Handler Send button
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                mService.writeRXCharacteristic(value);
                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Set initial UI state

}

From source file:com.scytulip.nrfUARTbackrec.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*  w  ww.  j ava  2s  .  c o m*/
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    btnDwnd = (Button) findViewById(R.id.dlButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    service_init();

    mBackData = new BackRecData(getApplicationContext());

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mBtAdapter.isEnabled()) {
                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                if (btnConnectDisconnect.getText().equals("Connect")) {

                    //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices

                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {
                    //Disconnect button pressed
                    if (mDevice != null) {
                        mService.disconnect();

                    }
                }
            }
        }
    });
    // Handler Send button  
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                mService.writeRXCharacteristic(value);
                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Handler Download Button
    btnDwnd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                mService.writeRXCharacteristic("T".getBytes("UTF-8"));
            } catch (Exception e) {
                Log.i(TAG, e.toString());
            }

        }
    });

    // Set initial UI state

}

From source file:com.bdb.weather.display.RainPlot.java

private void createChartElements() {
    String unitString = Depth.getDefaultUnit().toString();
    rateDomain = String.format(RAIN_RATE_DOMAIN_PREFIX, unitString);
    rainPlot = new XYPlot();
    rainPlot.setRangeAxis(RainRangeAxis.create());
    rainRatePlot = new XYPlot();
    rainRatePlot.setRangeAxis(RainRangeAxis.create());

    plot = new CombinedDomainXYPlot();
    plot.setDomainAxis(new DateAxis("Time"));

    plot.add(rainRatePlot);//from   ww w . j ava 2s.com
    plot.add(rainPlot);

    chart = new JFreeChart(plot);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    chartViewer = new ChartViewer(chart);
    chartViewer.setMaxHeight(10000);
    chartViewer.setMaxWidth(10000);
    chartViewer.setMinHeight(200);
    chartViewer.setMinWidth(400);

    rainDataset = new TimeSeriesCollection();
    rainSeries = new TimeSeries(RAIN_DOMAIN);
    rainDataset.addSeries(rainSeries);
    rainPlot.setDataset(rainDataset);

    rainRateDataset = new TimeSeriesCollection();
    rainRateSeries = new TimeSeries(rateDomain);
    rainRateDataset.addSeries(rainRateSeries);
    rainRatePlot.setDataset(rainRateDataset);

    XYToolTipGenerator ttg = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            DateFormat.getTimeInstance(), Depth.getDefaultFormatter());

    XYBarRenderer renderer = new XYBarRenderer();
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setBasePaint(Color.BLUE);
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setBaseToolTipGenerator(ttg);
    plot.setRenderer(renderer);

    XYItemRenderer rateRenderer = new XYLineAndShapeRenderer(true, false);
    rateRenderer.setBasePaint(Color.RED);
    rateRenderer.setSeriesPaint(0, Color.RED);
    rateRenderer.setBaseToolTipGenerator(ttg);
    rainRatePlot.setRenderer(rateRenderer);
}

From source file:com.moneydance.modules.features.importlist.util.Preferences.java

public static DateFormat getTimeFormatter() {
    return DateFormat.getTimeInstance();
}

From source file:com.nextgis.maplibui.control.DateTime.java

@Override
public void init(Field field, Bundle savedState, Cursor featureCursor) {
    if (null != field) {
        mFieldName = field.getName();//from   w  ww. j  a  v  a2 s .  c  o  m
    }

    switch (mPickerType) {

    case GeoConstants.FTDate:
        mDateFormat = (SimpleDateFormat) DateFormat.getDateInstance();
        break;

    case GeoConstants.FTTime:
        mDateFormat = (SimpleDateFormat) DateFormat.getTimeInstance();
        break;

    default:
        mPickerType = GeoConstants.FTDateTime;
    case GeoConstants.FTDateTime:
        mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance();
        break;
    }

    String text = "";

    if (ControlHelper.hasKey(savedState, mFieldName)) {
        mValue = savedState.getLong(ControlHelper.getSavedStateKey(mFieldName));
    } else if (null != featureCursor) {
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0) {
            mValue = featureCursor.getLong(column);
        }
    }

    if (null != mValue) {
        text = getText();
    }

    setText(text);
    setSingleLine(true);
    setFocusable(false);
    setOnClickListener(getDateUpdateWatcher(mPickerType));

    String pattern = mDateFormat.toLocalizedPattern();
    setHint(pattern);
}

From source file:com.sdingba.su.lanya.MainActivity.java

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

    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBtAdapter == null) {
        //            Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        Toast.makeText(this, " Bluetooth is not available------Bluetooth ??", Toast.LENGTH_LONG)
                .show();// ww  w . jav  a2 s  . c o m
        finish();
        return;
    }
    //        showMessage("??");

    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    service_init();

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!mBtAdapter.isEnabled()) {
                //                      mBtAdapter.isEnabled()  == null ??
                //
                //                    showMessage("mBtAdapter.isEnabled() = "+mBtAdapter.isEnabled());
                //mBtAdapter.isEnabled()::::Return true if Bluetooth is currently enabled and ready for use.
                //Equivalent to: getBluetoothState() == STATE_ON

                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                //TODO   BUG
                //// TODO: 16-6-5  ???   ?

                //   Connect ?? listView
                showMessage(" ??" + mState + "    "
                        + "    21 = UART_PROFILE_DISCONNECTED ; 20 = connection");
                if (btnConnectDisconnect.getText().equals("Connect")) {
                    //Connect button pressed, open DeviceListActivity
                    // class, with popup windows that scan for devices
                    // showMessage(" =-=======-= ");
                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {

                    showMessage(" ******** ");
                    //Disconnect button pressed
                    if (mDevice != null) {
                        mService.disconnect();
                    }
                }
            }
        }
    });

    //// TODO: 16-6-13 ]   ? ?

    //??
    // Handler Send button
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                mService.writeRXCharacteristic(value);

                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);

                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);

                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Set initial UI state

}

From source file:com.powehnko.ifroglabbt_ap_pins.MainActivity.java

private void FunSendString(String message) {
    //EditText editText = (EditText) findViewById(R.id.sendText);
    // String message = editText.getText().toString();
    byte[] value;
    try {/*from   ww  w  . jav a 2  s .co m*/
        //send data to service
        value = message.getBytes("UTF-8");
        mService.writeRXCharacteristic(value);
        //Update the log with time stamp
        String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
        listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
        messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
        //    edtMessage.setText("");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}