Android Open Source - UK-Weather-repo Base City List Fragment With Buttons






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;
/*from w ww  .ja  v  a  2s. co m*/
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;

import com.haringeymobile.ukweather.database.CityTable;
import com.haringeymobile.ukweather.database.WeatherContentProvider;

/** A fragment containing a list of cities with clickable buttons. */
public abstract class BaseCityListFragmentWithButtons extends ListFragment
    implements LoaderCallbacks<Cursor>, OnClickListener {

  /** Columns in the database that will be displayed in a list row. */
  protected static final String[] COLUMNS_TO_DISPLAY = new String[] { CityTable.COLUMN_NAME };
  /**
   * Resource IDs of views that will display the data mapped from the
   * database.
   */
  protected static final int[] TO = new int[] { R.id.city_name_in_list_row_text_view };
  /** Loader ID. */
  private static final int LOADER_ALL_CITY_RECORDS = 0;

  protected Activity parentActivity;
  protected BaseCityCursorAdapter cursorAdapter;

  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
    parentActivity = activity;
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_city_list, container, false);
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    prepareCityList();
    getLoaderManager().initLoader(LOADER_ALL_CITY_RECORDS, null, this);
  }

  /** Prepares the list view to load and display data. */
  private void prepareCityList() {
    cursorAdapter = getCityCursorAdapter();
    setListAdapter(cursorAdapter);
    setListViewForClicks();
  }

  /**
   * Obtains a concrete adapter with specific button set.
   * 
   * @return an adapter with specific functionality
   */
  protected abstract BaseCityCursorAdapter getCityCursorAdapter();

  /**
   * Enables the buttons contained by the list items gain focus and react to
   * clicks.
   */
  private void setListViewForClicks() {
    ListView listView = getListView();
    listView.setItemsCanFocus(true);
    listView.setFocusable(false);
    listView.setFocusableInTouchMode(false);
    listView.setClickable(false);
  }

  @Override
  public void onResume() {
    super.onResume();
    // Starts a new or restarts an existing Loader in this manager
    getLoaderManager().restartLoader(0, null, this);
  }

  @Override
  public void onDetach() {
    super.onDetach();
    parentActivity = null;
  }

  @Override
  public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = null;
    String selection = null;
    String[] selectionArgs = null;
    String sortOrder = CityTable.COLUMN_LAST_OVERALL_QUERY_TIME + " DESC";

    CursorLoader cursorLoader = new CursorLoader(parentActivity,
        WeatherContentProvider.CONTENT_URI_CITY_RECORDS, projection,
        selection, selectionArgs, sortOrder);
    return cursorLoader;
  }

  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    cursorAdapter.swapCursor(data);
    // Jump to the top of the list
    ListView listView = getListView();
    if (listView != null) {
      listView.setSelection(0);
    }
  }

  @Override
  public void onLoaderReset(Loader<Cursor> loader) {
    cursorAdapter.swapCursor(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