Android Open Source - UK-Weather-repo Base City Cursor Adapter






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;
// www.j a  v a  2  s  . com
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.haringeymobile.ukweather.database.CityTable;

/** An adapter to map the cities stored in the database to the city list. */
public abstract class BaseCityCursorAdapter extends SimpleCursorAdapter {

  /** The resource ID for a view corresponding to an even cursor position. */
  static final int BACKGROUND_RESOURCE_EVEN = R.drawable.clickable_blue;
  /** The resource ID for a view corresponding to an odd cursor position. */
  static final int BACKGROUND_RESOURCE_ODD = R.drawable.clickable_green;

  /** A listener for button clicks. */
  protected OnClickListener onClickListener;

  BaseCityCursorAdapter(Context context, int layout, Cursor c, String[] from,
      int[] to, int flags, OnClickListener onClickListener) {
    super(context, layout, c, from, to, flags);
    this.onClickListener = onClickListener;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    if (position % 2 == 1) {
      view.setBackgroundResource(BACKGROUND_RESOURCE_ODD);
    } else {
      view.setBackgroundResource(BACKGROUND_RESOURCE_EVEN);
    }
    return view;
  }

  /**
   * Obtains the Open Weather Map city ID for the specified list position.
   * 
   * @param position
   *            city list position
   * @return Open Weather Map city ID, or -1 if city list does not contain the
   *         specified position
   */
  int getCityId(int position) {
    Cursor cursor = getCursor();
    if (cursor.moveToPosition(position)) {
      return cursor.getInt(cursor
          .getColumnIndex(CityTable.COLUMN_CITY_ID));
    }
    return CityTable.CITY_ID_DOES_NOT_EXIST;
  }

  /**
   * Obtains the city name stored in the database for the specified list
   * position.
   * 
   * @param position
   *            city list position
   * @return city name, or null if city list does not contain the specified
   *         position
   */
  String getCityName(int position) {
    Cursor cursor = getCursor();
    if (cursor.moveToPosition(position)) {
      return cursor.getString(cursor
          .getColumnIndex(CityTable.COLUMN_NAME));
    }
    return null;
  }

}




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