List of usage examples for android.text.format Time setToNow
public void setToNow()
From source file:eu.inmite.apps.smsjizdenka.activity.MainActivity.java
private void addTestingTicket() { Ticket ticket = new Ticket(); if (Locale.getDefault().toString().startsWith("en")) { ticket.setCity("Prague"); } else {/*from w w w . j av a 2 s.c o m*/ ticket.setCity("Praha"); } ticket.setCityId(1); ticket.setHash("bhAJpWP9B / 861418"); ticket.setStatus(TicketProvider.Tickets.STATUS_DELIVERED); ticket.setText( "DP hl.m.Prahy, a.s., Jizdenka prestupni 32,- Kc, Platnost od: 29.8.11 8:09 do: 29.8.11 9:39. Pouze v pasmu P. WzL9n3JuQ /" + " " + "169605"); int second = 1000; int minute = 60 * second; int hour = 60 * minute; int day = 24 * hour; Time time = new Time(); time.setToNow(); ticket.setOrdered(time); Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.SECOND, 0); long nowFullMinute = calendar.getTimeInMillis(); time.set(nowFullMinute); ticket.setValidFrom(time); Time time2 = new Time(); time2.set(nowFullMinute + 12 * minute); ticket.setValidTo(time2); SmsReceiverService.call(c, ticket); }
From source file:it.sasabz.android.sasabus.fragments.OrarioFragment.java
/** * This method gets the next departure time and returns the * index of this element//from ww w. j a va2 s . co m * @param c is the cursor to the list_view * @return the index of the next departure time */ private int getNextTimePosition(Vector<Passaggio> list) { int count = list.size(); if (count == 0) { return -1; } else if (count == 1) { return 0; } else { int i = 0; boolean found = false; while (i <= count - 2 && !found) { Time currentTime = new Time(); Time sasaTime = new Time(); Time sasaTimeNext = new Time(); currentTime.setToNow(); sasaTime = list.get(i).getOrario(); sasaTimeNext = list.get(i + 1).getOrario(); if (sasaTime.after(currentTime) || sasaTime.equals(currentTime) || sasaTime.before(currentTime) && (sasaTimeNext.equals(currentTime) || sasaTimeNext.after(currentTime))) { found = true; } else { i++; } } return i; } }
From source file:org.privatenotes.Note.java
/** * Updates the content and sets last-change-date to now and flags the note as "not in sync with server". */// w w w. ja v a 2s .c om public void changeXmlContent(String xmlContent) { this.xmlContent = xmlContent; Time time = new Time(); time.setToNow(); setLastChangeDate(time); isSynced(false); }
From source file:it.sasabz.android.sasabus.fragments.WayFragment.java
/** * This method gets the next departure time and returns the * index of this element//from w w w . j a v a 2 s. c o m * @param c is the cursor to the list_view * @return the index of the next departure time */ private int getNextTimePosition(Vector<Passaggio> list) { int count = 0; if (list != null) { count = list.size(); } if (count == 0) { return -1; } else if (count == 1) { return 0; } else { int i = 0; boolean found = false; while (i <= count - 2 && !found) { Time currentTime = new Time(); Time sasaTime = new Time(); Time sasaTimeNext = new Time(); currentTime.setToNow(); sasaTime = list.get(i).getOrario(); sasaTimeNext = list.get(i + 1).getOrario(); if (sasaTime.after(currentTime) || sasaTime.equals(currentTime) || sasaTime.before(currentTime) && (sasaTimeNext.equals(currentTime) || sasaTimeNext.after(currentTime))) { found = true; } else { i++; } } return i; } }
From source file:com.readystatesoftware.ghostlog.ServerlessLogScreen.java
@Override public void onLogShare() { StringBuffer sb = new StringBuffer(); for (LogLine line : mLogBufferFiltered) { sb.append(line.getRaw());//from w w w . ja va2 s . c o m sb.append("\n"); } Time now = new Time(); now.setToNow(); String ts = now.format3339(false); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, sb.toString()); shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_subject) + " " + ts); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(shareIntent); }
From source file:com.example.mihai.inforoute.app.FetchWeatherTask.java
private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try {/* w w w .j a va 2s . co m*/ JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + " Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:uk.org.openseizuredetector.OsdUtil.java
/** * Write data to SD card - writes to data log file unless alarm=true, * in which case writes to alarm log file. *//* w w w . ja v a 2 s .c o m*/ public void writeToLogFile(String fname, String msgStr) { Log.v(TAG, "writeToLogFile(" + fname + "," + msgStr + ")"); //showToast("Logging " + msgStr); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d"); fname = fname + "_" + dateStr + ".txt"; // Open output directory on SD Card. if (isExternalStorageWritable()) { try { FileWriter of = new FileWriter(getDataStorageDir().toString() + "/" + fname, true); if (msgStr != null) { String dateTimeStr = tnow.format("%Y-%m-%d %H:%M:%S"); Log.v(TAG, "writing msgStr"); of.append(dateTimeStr + ", " + tnow.toMillis(true) + ", " + msgStr + "<br/>\n"); } of.close(); } catch (Exception ex) { Log.e(TAG, "writeToLogFile - error " + ex.toString()); showToast("ERROR Writing to Log File"); } } else { Log.e(TAG, "ERROR - Can not Write to External Folder"); } }
From source file:com.readystatesoftware.ghostlog.LogService.java
@Override public void onLogShare() { StringBuffer sb = new StringBuffer(); for (LogLine line : mLogBufferFiltered) { sb.append(line.getRaw());/*w w w .ja v a 2 s . c om*/ sb.append("\n"); } Time now = new Time(); now.setToNow(); String ts = now.format3339(false); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, sb.toString()); shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_subject) + " " + ts); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareIntent); }
From source file:dk.larsbak.sunshine.ForecastFragment.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us./*from w w w . j a v a 2s . co m*/ */ private String[] getWeatherDataFromJson(String forecastJsonStr, int numDays) throws JSONException { // These are the names of the JSON objects that need to be extracted. final String OWM_LIST = "list"; final String OWM_WEATHER = "weather"; final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_DESCRIPTION = "main"; JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); String[] resultStrs = new String[numDays]; // Data is fetched in Celsius by default. // If user prefers to see in Fahrenheit, convert the values here. // We do this rather than fetching in Fahrenheit so that the user can // change this option without us having to re-fetch the data once // we start storing the values in a database. SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); String unitType = sharedPrefs.getString(getString(R.string.pref_units_key), getString(R.string.pref_units_metric)); for (int i = 0; i < weatherArray.length(); i++) { // For now, using the format "Day, description, hi/low" String day; String description; String highAndLow; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // The date/time is returned as a long. We need to convert that // into something human-readable, since most people won't read "1400356800" as // "this saturday". long dateTime; // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); day = getReadableDateString(dateTime); // description is in a child array called "weather", which is 1 element long. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); double high = temperatureObject.getDouble(OWM_MAX); double low = temperatureObject.getDouble(OWM_MIN); highAndLow = formatHighLows(high, low, unitType); resultStrs[i] = day + " - " + description + " - " + highAndLow; } for (String s : resultStrs) { Log.v(LOG_TAG, "Forecast entry: " + s); } return resultStrs; }
From source file:com.example.spatidar.sunshine.FetchWeatherTask.java
private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try {/*ww w. j a v a2s. com*/ JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { // Student: call bulkInsert to add the weatherEntries to the database here ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + " Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }