Android Open Source - UK-Weather-repo Shared Prefs Helper






From Project

Back to project page UK-Weather-repo.

License

The source code is released under:

Apache License

If you think the Android project UK-Weather-repo 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.haringeymobile.ukweather.utils;
//  w  ww.ja  va  2s .co m
import com.haringeymobile.ukweather.WeatherInfoType;
import com.haringeymobile.ukweather.database.CityTable;

import android.app.Activity;
import android.content.Context;

public class SharedPrefsHelper {

  public static final String SHARED_PREFS_KEY = "com.haringeymobile.ukweather.PREFERENCE_FILE_KEY";

  private static final String LAST_SELECTED_CITY_ID = "city id";
  private static final String LAST_SELECTED_WEATHER_INFO_TYPE = "weather info type";

  /** Obtains the ID of the city that was last queried by the user. */
  public static int getCityIdFromSharedPrefs(Context context) {
    return context.getSharedPreferences(SHARED_PREFS_KEY,
        Activity.MODE_PRIVATE).getInt(LAST_SELECTED_CITY_ID,
        CityTable.CITY_ID_DOES_NOT_EXIST);
  }

  /**
   * Saves the specified city ID.
   * 
   * @param cityId
   *            OpenWeatherMap city ID
   */
  public static void putCityIdIntoSharedPrefs(Context context, int cityId) {
    context.getSharedPreferences(SHARED_PREFS_KEY, Activity.MODE_PRIVATE)
        .edit().putInt(LAST_SELECTED_CITY_ID, cityId).apply();
  }

  /** Obtains the {@link WeatherInfoType} for the last user's query. */
  public static WeatherInfoType getLastWeatherInfoTypeFromSharedPrefs(
      Context context) {
    int lastSelectedWeatherInfoTypeId = context.getSharedPreferences(
        SHARED_PREFS_KEY, Activity.MODE_PRIVATE).getInt(
        LAST_SELECTED_WEATHER_INFO_TYPE,
        WeatherInfoType.CURRENT_WEATHER.getId());
    return WeatherInfoType.getTypeById(lastSelectedWeatherInfoTypeId);
  }

  /**
   * Saves the {@link WeatherInfoType} that was last queried by the user.
   * 
   * @param weatherInfoType
   *            a kind of weather information
   */
  public static void putLastWeatherInfoTypeIntoSharedPrefs(Context context,
      WeatherInfoType weatherInfoType) {
    context.getSharedPreferences(SHARED_PREFS_KEY, Activity.MODE_PRIVATE)
        .edit()
        .putInt(LAST_SELECTED_WEATHER_INFO_TYPE,
            weatherInfoType.getId()).apply();
  }

}




Java Source Code List

com.astuetz.PagerSlidingTabStrip.java
com.haringeymobile.ukweather.AboutActivity.java
com.haringeymobile.ukweather.BaseCityCursorAdapter.java
com.haringeymobile.ukweather.BaseCityListFragmentWithButtons.java
com.haringeymobile.ukweather.CityListFragmentWithUtilityButtons.java
com.haringeymobile.ukweather.CityListFragmentWithWeatherButtons.java
com.haringeymobile.ukweather.CityManagementActivity.java
com.haringeymobile.ukweather.CitySearchResultsDialog.java
com.haringeymobile.ukweather.CityUtilitiesCursorAdapter.java
com.haringeymobile.ukweather.CityWeatherCursorAdapter.java
com.haringeymobile.ukweather.DeleteCityDialog.java
com.haringeymobile.ukweather.GetAvailableCitiesTask.java
com.haringeymobile.ukweather.MainActivity.java
com.haringeymobile.ukweather.SettingsActivityPreHoneycomb.java
com.haringeymobile.ukweather.SettingsActivity.java
com.haringeymobile.ukweather.SettingsFragment.java
com.haringeymobile.ukweather.WeatherCurrentInfoFragment.java
com.haringeymobile.ukweather.WeatherDailyWeatherForecastChildFragment.java
com.haringeymobile.ukweather.WeatherForecastParentFragment.java
com.haringeymobile.ukweather.WeatherInfoActivity.java
com.haringeymobile.ukweather.WeatherInfoFragment.java
com.haringeymobile.ukweather.WeatherInfoType.java
com.haringeymobile.ukweather.WeatherThreeHourlyForecastChildFragment.java
com.haringeymobile.ukweather.WorkerFragmentToRetrieveJsonString.java
com.haringeymobile.ukweather.data.InitialCity.java
com.haringeymobile.ukweather.data.JsonFetcher.java
com.haringeymobile.ukweather.data.OpenWeatherMapUrl.java
com.haringeymobile.ukweather.data.objects.CityCurrentWeather.java
com.haringeymobile.ukweather.data.objects.CityDailyWeatherForecast.java
com.haringeymobile.ukweather.data.objects.CityInfo.java
com.haringeymobile.ukweather.data.objects.CityThreeHourlyWeatherForecast.java
com.haringeymobile.ukweather.data.objects.Clouds.java
com.haringeymobile.ukweather.data.objects.Coordinates.java
com.haringeymobile.ukweather.data.objects.NumericParameters.java
com.haringeymobile.ukweather.data.objects.Rain.java
com.haringeymobile.ukweather.data.objects.SearchResponseForDailyForecastQuery.java
com.haringeymobile.ukweather.data.objects.SearchResponseForFindQuery.java
com.haringeymobile.ukweather.data.objects.SearchResponseForThreeHourlyForecastQuery.java
com.haringeymobile.ukweather.data.objects.SystemParameters.java
com.haringeymobile.ukweather.data.objects.TemperatureScale.java
com.haringeymobile.ukweather.data.objects.Temperature.java
com.haringeymobile.ukweather.data.objects.WeatherInformation.java
com.haringeymobile.ukweather.data.objects.Weather.java
com.haringeymobile.ukweather.data.objects.WindSpeedMeasurementUnit.java
com.haringeymobile.ukweather.data.objects.Wind.java
com.haringeymobile.ukweather.database.CityTable.java
com.haringeymobile.ukweather.database.DatabaseHelper.java
com.haringeymobile.ukweather.database.GeneralDatabaseService.java
com.haringeymobile.ukweather.database.SqlOperation.java
com.haringeymobile.ukweather.database.WeatherContentProvider.java
com.haringeymobile.ukweather.utils.AsyncTaskWithProgressBar.java
com.haringeymobile.ukweather.utils.GlobalConstants.java
com.haringeymobile.ukweather.utils.MiscMethods.java
com.haringeymobile.ukweather.utils.SharedPrefsHelper.java