List of usage examples for android.text.format Time Time
public Time()
From source file:com.lottodroid.widgets.wikiarticle.WikiarticleHelper.java
/** * Build the page title where it is located today's featured article, like * "Wikipedia:Today's_featured_article/March_21,_2009". It uses the actual date * /*from w w w . j a va 2 s . c o m*/ * @param context The context of the application * @return Today's page resource */ public static String buildTodayPageTitle(Context context) { // Pick out month names from resources Resources res = context.getResources(); String[] monthNames = res.getStringArray(R.array.month_names); // Find current month and day Time today = new Time(); today.setToNow(); // Build today's page title, like "Wikipedia:Today's_featured_article/March_21,_2009" String pageName = res.getString(R.string.template_wotd_title, monthNames[today.month], today.monthDay, today.year); return pageName; }
From source file:com.example.volunteerhandbook.GcmIntentService.java
void makeNoise() { boolean toRing = false; String fileName = MainActivity.getFileHeader() + ProfilePage.getTableName(); SharedPreferences mem = getSharedPreferences(fileName, Context.MODE_PRIVATE); String sRing = mem.getString(ProfileActivity.CURRENT_RINGTON, "--");//, String); if (sRing.charAt(0) == '-') return;/*from www. j a v a2 s . co m*/ Uri ringUri = Uri.parse(sRing);//, String); String t0 = mem.getString(ProfileActivity.NO_NOISE_START, "--");//, noNoiseStart); String t1 = mem.getString(ProfileActivity.NO_NOISE_END, "--");//, noNoiseEnd); String[] sT0 = t0.split(":"); int h0 = Integer.parseInt(sT0[0]); int m0 = Integer.parseInt(sT0[1]); sT0 = t1.split(":"); int h1 = Integer.parseInt(sT0[0]); int m1 = Integer.parseInt(sT0[1]); Time tm = new Time(); int iNow = tm.hour * 60 + tm.minute; int iU = h1 * 60 + m1; int iL = h0 * 60 + m0; if (h1 < h0) { toRing = (iNow > iU && iNow < iL); } else toRing = (iNow > iU || iNow < iL); //android.os.Debug.waitForDebugger(); if (toRing) { noise = RingtoneManager.getRingtone(getApplicationContext(), ringUri); noise.play(); } else noise = null; }
From source file:com.dgsd.android.ShiftTracker.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.settings) { startActivity(new Intent(this, SettingsActivity.class)); } else if (item.getItemId() == R.id.go_to) { if (mGoToFragment != null && mGoToFragment.isResumed()) { //We're showing already! return true; }/*from w w w .ja va 2 s. co m*/ final int centerJd = mWeekPagerAdapter.getJulianDayForPosition(mWeekPagerAdapter.getCenterPosition()); final int count = mWeekPagerAdapter.getCount() * 7; final Time time = new Time(); time.setJulianDay(centerJd - (count / 2)); final long min = time.toMillis(true); time.setJulianDay(centerJd + (count / 2)); final long max = time.toMillis(true); mGoToFragment = DatePickerFragment.newInstance("Go to date..", min, max, -1); mGoToFragment.setOnDateSelectedListener(this); mGoToFragment.show(getSupportFragmentManager(), null); } else if (item.getItemId() == R.id.get_full_version) { Uri uri = Uri.parse("market://details?id=com.dgsd.android.ShiftTracker"); startActivity(new Intent(Intent.ACTION_VIEW, uri)); } else if (item.getItemId() == R.id.stats) { final int selectedItem = getSupportActionBar().getSelectedNavigationIndex(); if (StApp.isFreeApp(this)) { if (mLinkToPaidAppFragment == null || !mLinkToPaidAppFragment.isResumed()) { mLinkToPaidAppFragment = LinkToPaidAppFragment .newInstance(getString(R.string.summary_unavailable_message)); mLinkToPaidAppFragment.show(getSupportFragmentManager(), null); } } else { if (mHoursAndIncomeFragment == null || !mHoursAndIncomeFragment.isResumed()) { final int jd; if (selectedItem == NAV_INDEX_MONTH) jd = mMonthPagerAdapter.getSelectedJulianDay(mPager.getCurrentItem()); else if (selectedItem == NAV_INDEX_WEEK) jd = mWeekPagerAdapter.getJulianDayForPosition(mPager.getCurrentItem()) + 6; else jd = TimeUtils.getCurrentJulianDay(); mHoursAndIncomeFragment = HoursAndIncomeSummaryFragment.newInstance(jd); mHoursAndIncomeFragment.show(getSupportFragmentManager(), null); } } } return super.onOptionsItemSelected(item); }
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 {/* www . j a va 2s. 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()); 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: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 {//from w w w. jav a 2 s .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()); // 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(); } }
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 w w w .j a v a2 s. com * @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:com.example.mihai.inforoute.app.ForecastFragment.java
public static String getFormattedMonthDay(Context context, long dateInMillis) { Time time = new Time(); time.setToNow();// w ww .j a v a2s. co m SimpleDateFormat dbDateFormat = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd"); String monthDayString = monthDayFormat.format(dateInMillis); return monthDayString; }
From source file:org.tomdroid.Note.java
public Time getLastChangeDate() { Time time = new Time(); time.parse3339(lastChangeDate); return time; }
From source file:com.election.US.basicsyncadapter.EntryListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mAdapter = new SimpleCursorAdapter(getActivity(), // Current context android.R.layout.simple_list_item_activated_2, // Layout for individual rows null, // Cursor FROM_COLUMNS, // Cursor columns to use TO_FIELDS, // Layout fields to use 0 // No flags );/*w ww . ja v a2 s . com*/ mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int i) { if (i == COLUMN_PUBLISHED) { // Convert timestamp to human-readable date Time t = new Time(); t.set(cursor.getLong(i)); ((TextView) view).setText(t.format("%Y-%m-%d %H:%M")); return true; } else { // Let SimpleCursorAdapter handle other fields automatically return false; } } }); setListAdapter(mAdapter); setEmptyText(getText(R.string.loading)); getLoaderManager().initLoader(0, null, this); }