Example usage for android.text.format Time Time

List of usage examples for android.text.format Time Time

Introduction

In this page you can find the example usage for android.text.format Time Time.

Prototype

public Time() 

Source Link

Document

Construct a Time object in the default timezone.

Usage

From source file:com.example.android.sunshine.app.Utility.java

/**
 * Converts db date format to the format "Month day", e.g "June 24".
 * @param context Context to use for resource localization
 * @param dateInMillis The db formatted date string, expected to be of the form specified
 *                in Utility.DATE_FORMAT
 * @return The day in the form of a string formatted "December 6"
 *//*from  w w w  . ja v  a2  s. c om*/
public static String getFormattedMonthDay(Context context, long dateInMillis) {
    Time time = new Time();
    time.setToNow();
    SimpleDateFormat dbDateFormat = new SimpleDateFormat(Utility.DATE_FORMAT);
    SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd");
    String monthDayString = monthDayFormat.format(dateInMillis);
    return monthDayString;
}

From source file:shetye.prathamesh.notifyme.Utilities.java

public void createWhenDialog(final Context context, final Activity parentActivity, final Notif note,
        final boolean back) {
    mDialog = new Dialog(context);
    mDialog.setContentView(R.layout.datetimepicker_dialog);
    mDialog.setTitle("When to Notify??");
    mDialogOKBtn = (Button) mDialog.findViewById(R.id.btn_ok);
    mDialogOKBtn.setOnClickListener(new View.OnClickListener() {
        @Override/*w ww. java  2s  .c  o  m*/
        public void onClick(View v) {
            note.setNotification_when(getSelectedTime());
            DatabaseHelper.getInstance(context).addNotif(note);
            setZoneInTimer(context, note);
            mDialog.dismiss();
            if (parentActivity != null) {
                if (back) {
                    parentActivity.finishAfterTransition();
                } else {
                    ((Notifications) parentActivity).refreshNotifications();
                }
            }
        }
    });
    mDialogOKBtn.setEnabled(false);
    mDialogCancelBtn = (Button) mDialog.findViewById(R.id.btn_cancel);
    mDialogCancelBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mDialog.dismiss();
            if (parentActivity != null) {
                parentActivity.finishAfterTransition();
            }
        }
    });
    mTimeBtn = (Button) mDialog.findViewById(R.id.btntimeset);
    mDateBtn = (Button) mDialog.findViewById(R.id.btndateset);
    final Time dtNow = new Time();
    dtNow.setToNow();
    mSelectedHours = dtNow.hour;
    mSelectedMinutes = dtNow.minute;
    mSelectedYear = dtNow.year;
    mSelectedMonth = dtNow.month;
    mSelectedDay = dtNow.monthDay;
    updateBtnText(dtNow, false, context);
    Time selectedTime = new Time();
    selectedTime.set(0, mSelectedMinutes, mSelectedHours, mSelectedDay, mSelectedMonth, mSelectedYear);
    mPastDateSelected = true;
    mTimeBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TimePickerDialog timePickerDialog = new TimePickerDialog(context,
                    new TimePickerDialog.OnTimeSetListener() {
                        @Override
                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                            Time selectedTime = new Time();
                            mSelectedHours = hourOfDay;
                            mSelectedMinutes = minute;
                            selectedTime.set(0, mSelectedMinutes, mSelectedHours, mSelectedDay, mSelectedMonth,
                                    mSelectedYear);
                            if (Time.compare(selectedTime, dtNow) <= 0) {
                                mPastDateSelected = true;
                            } else {
                                mPastDateSelected = false;
                            }
                            updateBtnText(selectedTime, true, context);
                        }
                    }, mSelectedHours, mSelectedMinutes, false);
            timePickerDialog.show();
        }
    });
    mDateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DatePickerDialog datePickerDialog = new DatePickerDialog(context,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int yy, int mm, int dd) {
                            Time selectedTime = new Time();
                            mSelectedYear = yy;
                            mSelectedMonth = mm;
                            mSelectedDay = dd;
                            selectedTime.set(0, mSelectedMinutes, mSelectedHours, mSelectedDay, mSelectedMonth,
                                    mSelectedYear);
                            if (Time.compare(selectedTime, dtNow) <= 0) {
                                mPastDateSelected = true;
                            } else {
                                mPastDateSelected = false;
                            }
                            updateBtnText(selectedTime, false, context);
                        }
                    }, mSelectedYear, mSelectedMonth, mSelectedDay);
            datePickerDialog.show();
        }
    });
    mDialog.show();
}

From source file:org.tomdroid.Note.java

public void setLastChangeDate() {
    Time now = new Time();
    now.setToNow();
    String time = now.format3339(false);
    setLastChangeDate(time);
}

From source file:com.example.mihai.inforoute.app.ForecastFragment.java

public static String getDayName(Context context, long dateInMillis) {
    // If the date is today, return the localized version of "Today" instead of the actual
    // day name./*from  w  ww.j  av a  2  s.c  om*/

    Time t = new Time();
    t.setToNow();
    int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff);
    int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff);
    if (julianDay == currentJulianDay) {
        return context.getString(R.string.today);
    } else if (julianDay == currentJulianDay + 1) {
        return context.getString(R.string.tomorrow);
    } else {
        Time time = new Time();
        time.setToNow();
        // Otherwise, the format is just the day of the week (e.g "Wednesday".
        SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE");
        return dayFormat.format(dateInMillis);
    }
}

From source file:idea.ruan.oksun.FetchWeatherTask.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.//  w  w w .  j a v  a 2s  . c o m
 */
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 {
        JSONObject forecastJson = new JSONObject(forecastJsonStr);

        JSONObject coords = forecastJson.getJSONObject("city").getJSONObject("coord");

        PreferenceManager.getDefaultSharedPreferences(mContext).edit()
                .putString(mContext.getString(R.string.current_location_coords),
                        coords.getString("lat") + "," + coords.getString("lon"))
                .apply();

        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<>(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(WeatherContract.WeatherEntry.COLUMN_LOC_KEY, locationId);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DATE, dateTime);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_HUMIDITY, humidity);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_PRESSURE, pressure);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WIND_SPEED, windSpeed);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DEGREES, windDirection);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP, high);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP, low);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC, description);
            weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID, weatherId);

            cVVector.add(weatherValues);
        }

        int inserted = 0;

        if (cVVector.size() > 0) {

            ContentValues[] cvArray = new ContentValues[cVVector.size()];

            cVVector.toArray(cvArray);

            inserted = mContext.getContentResolver().bulkInsert(WeatherContract.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:securityantennas.viwer.android.mogaworks.securityantenna.FeedListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    int loader_id = getArguments().getInt(ARG_SECTION_NUMBER);
    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
    );//from   w  w w.  j a va2  s  .  c o  m
    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(loader_id, null, this);
}

From source file:com.catchnotes.api.CatchAPI.java

/** 
 * Constructor./*from www.ja  v a  2 s . co m*/
 * 
 * @param appName The name of your application.
 * @param context Android context.
 */
public CatchAPI(String appName, Context context) {
    source = appName;
    mContext = context;
    String version = "x.xx";

    try {
        PackageInfo info = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
        version = info.versionName;
    } catch (Exception e) {
    }

    StringBuilder locale = new StringBuilder(5);
    String language = Locale.getDefault().getLanguage();

    if (language != null) {
        locale.append(language);
        String country = Locale.getDefault().getCountry();

        if (country != null) {
            locale.append('-');
            locale.append(country);
        }
    }

    userAgent = appName + '/' + version + " (Android; " + Build.VERSION.RELEASE + "; " + Build.BRAND + "; "
            + Build.MODEL + "; " + locale.toString() + ')';

    try {
        if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.ECLAIR_0_1) {
            // We can use Time & TimeFormatException on Android 2.0.1
            // (API level 6) or greater. It crashes the VM otherwise.
            timestamper = new Time();
        }
    } catch (Exception e) {
    }
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddHome.java

@Override
protected void onResume() {
    super.onResume();

    //Can't hurt to try and start the service just in case
    startService(new Intent(this, ZenossPoller.class));

    //User is about to see the list of events - no need for them to hang around
    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
            .cancel(Notifications.NOTIFICATION_POLLED_ALERTS);
    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
            .cancel(Notifications.NOTIFICATION_GCM_GENERIC);

    //Lets try and bind to our service (if it's alive)
    doBindService();/*from ww  w  .  j a va  2  s .  c  o  m*/

    //Might as well update GCM whilst we're here
    if (settings.contains(ZenossAPI.PREFERENCE_PUSHKEY)
            && !settings.getString(ZenossAPI.PREFERENCE_PUSHKEY, "").equals("")) {
        doGCMRegistration(settings.getString(ZenossAPI.PREFERENCE_PUSHKEY, ""));
    }

    //OnCreate checks the settings for various bits. If they aren't there it sets first run to true
    //Checking a single bool is a hell of a lot more lightweight than 3 Preferences each onResume !
    if (firstRun) {
        //We need to set this now as no doubt on resume gets called before onActivityResult
        firstRun = false;

        Intent SettingsIntent = new Intent(RhybuddHome.this, FirstRunSettings.class);
        SettingsIntent.putExtra("firstRun", true);
        //Test
        RhybuddHome.this.startActivityForResult(SettingsIntent, requestCode);
    } else {
        boolean lastCheckRequired = false;

        if (null != settings && settings.contains("lastCheck")) {
            Time now = new Time();
            now.setToNow();
            Long timesinceLastRefresh = (now.toMillis(true) - settings.getLong("lastCheck", 0));
            Log.e("timesinceLastRefresh", Long.toString(timesinceLastRefresh));
            if (timesinceLastRefresh > 900000) {
                lastCheckRequired = true;
            }
        }

        //If we've resumed from one of our own activities we probably don't want to do a full refresh
        //finishStart will force a full refresh if backgroundPolling isn't enabled
        //if(resumeOnResultPollAPI || lastCheckRequired)
        if (resumeOnResultPollAPI) {
            finishStart(false);
            //Refresh();
        } else {
            //Nice and fast for returning from within our own app
            DBGetThread();
            resumeOnResultPollAPI = true;
        }
    }
}

From source file:com.prashantpal.sunshine.app.FetchWeatherTask.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.// w w  w .  j  a  va 2 s.  c  o m
 */
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 {
        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();
        int inserted = 0;
        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);
        }

        // 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:com.example.riteden.sunshine.app.FetchWeatherTask.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  ww  w .j  a v  a2  s  .  c o  m
 */
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 {
        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) {
            ContentValues[] values = new ContentValues[cVVector.size()];
            cVVector.toArray(values);
            // Student: call bulkInsert to add the weatherEntries to the database here
            inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, values);
        }

        Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + " Inserted");

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    }
}