Android Open Source - sunshine A Weather Data Parser






From Project

Back to project page sunshine.

License

The source code is released under:

Apache License

If you think the Android project sunshine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.zmb.sunshine.data;
/*from  www  .jav a2  s . c om*/
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

import com.zmb.sunshine.data.db.WeatherContract;

public abstract class AWeatherDataParser implements IWeatherDataParser {
    /**
     * Insert a location into the database if it doesn't already exist.
     *
     * @param locationSetting
     * @param cityName
     * @param lat
     * @param lon
     * @return the row ID of the specified location
     */
    protected long addLocation(Context c, String locationSetting, String cityName, double lat, double lon) {
        ContentResolver cr = c.getContentResolver();
        Cursor cursor = cr.query(
                WeatherContract.LocationEntry.CONTENT_URI,
                new String[] { WeatherContract.LocationEntry._ID },
                WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?",
                new String[] { locationSetting },
                null);
        try {
            if (cursor.moveToFirst()) {
                // the location was already in the database
                int locationId = cursor.getColumnIndex(WeatherContract.LocationEntry._ID);
                return cursor.getLong(locationId);
            } else {
                // location wasn't in database, must be added
                ContentValues values = new ContentValues();
                values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
                values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
                values.put(WeatherContract.LocationEntry.COLUMN_LATITUDE, lat);
                values.put(WeatherContract.LocationEntry.COLUMN_LONGITUDE,lon);
                Uri uri = cr.insert(WeatherContract.LocationEntry.CONTENT_URI, values);
                return ContentUris.parseId(uri);
            }
        } finally {
            cursor.close();
        }
    }
}




Java Source Code List

com.zmb.sunshine.ApplicationTest.java
com.zmb.sunshine.DetailActivity.java
com.zmb.sunshine.DetailFragment.java
com.zmb.sunshine.ForecastAdapter.java
com.zmb.sunshine.ForecastFragment.java
com.zmb.sunshine.MainActivity.java
com.zmb.sunshine.SettingsActivity.java
com.zmb.sunshine.SettingsFragment.java
com.zmb.sunshine.Sunshine.java
com.zmb.sunshine.data.AWeatherDataParser.java
com.zmb.sunshine.data.Convert.java
com.zmb.sunshine.data.DayForecast.java
com.zmb.sunshine.data.DayOfWeek.java
com.zmb.sunshine.data.IWeatherDataParser.java
com.zmb.sunshine.data.WeatherParseException.java
com.zmb.sunshine.data.WeatherProvider.java
com.zmb.sunshine.data.db.AndroidDatabaseManager.java
com.zmb.sunshine.data.db.WeatherContract.java
com.zmb.sunshine.data.db.WeatherDbHelper.java
com.zmb.sunshine.data.openweathermap.OpenWeatherMapParser.java
com.zmb.sunshine.data.worldweatheronline.WorldWeatherOnlineParser.java
com.zmb.sunshine.sync.DummyAuthenticatorService.java
com.zmb.sunshine.sync.DummyAuthenticator.java
com.zmb.sunshine.sync.SunshineSyncAdapter.java
com.zmb.sunshine.sync.SunshineSyncService.java
com.zmb.sunshine.widget.SunshineWidget.java
com.zmb.utils.IoUtils.java