Android Open Source - UK-Weather-repo Delete City Dialog






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;
/* w  w w . ja v a2s. co  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

/** A dialog asking for the city deletion confirmation. */
public class DeleteCityDialog extends DialogFragment {

  /** A listener for dialog's button clicks. */
  public interface OnDialogButtonClickedListener {

    /**
     * Reacts to the confirmation that the specified city should be deleted.
     * 
     * @param cityId
     *            OpenWeatherMap ID for the city to be deleted
     */
    void onCityRecordDeletionConfirmed(int cityId);

  }

  private static final String CITY_NAME = "city name";

  private Activity parentActivity;
  private OnDialogButtonClickedListener onDialogButtonClickedListener;

  /**
   * Creates a new dialog asking for the city deletion confirmation.
   * 
   * @param cityId
   *            OpenWeatherMap ID for the city to be deleted
   * @param cityName
   *            city name in the database
   * @return a new dialog fragment with the specified arguments
   */
  public static DeleteCityDialog newInstance(int cityId, String cityName) {
    DeleteCityDialog dialogFragment = new DeleteCityDialog();
    Bundle b = new Bundle();
    b.putInt(CityManagementActivity.CITY_ID, cityId);
    b.putString(CITY_NAME, cityName);
    dialogFragment.setArguments(b);
    return dialogFragment;
  }

  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
    parentActivity = getActivity();
    try {
      onDialogButtonClickedListener = (OnDialogButtonClickedListener) activity;
    } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString()
          + " must implement OnDialogButtonClickedListener");
    }
  }

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

  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    String title = getDialogTitle();
    OnClickListener dialogOnClickListener = getDialogOnClickListener();
    CharSequence positiveButtonText = parentActivity.getResources()
        .getString(android.R.string.ok);
    return new AlertDialog.Builder(parentActivity)
        .setIcon(R.drawable.discard)
        .setTitle(title)
        .setPositiveButton(positiveButtonText, dialogOnClickListener)
        .create();
  }

  /**
   * Obtains the city deletion dialog title.
   * 
   * @return text asking for the city deletion confirmation
   */
  private String getDialogTitle() {
    Resources res = parentActivity.getResources();
    final String cityName = getArguments().getString(CITY_NAME);
    String title = res.getString(R.string.dialog_title_delete_city_part_1)
        + " " + cityName + " "
        + res.getString(R.string.dialog_title_delete_city_part_2);
    return title;
  }

  /**
   * Obtains a listener for dialog's button clicks.
   * 
   * @return a listener to handle button clicks
   */
  private OnClickListener getDialogOnClickListener() {
    OnClickListener dialogOnClickListener = new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface dialog, int whichButton) {
        onDialogButtonClickedListener
            .onCityRecordDeletionConfirmed(getArguments().getInt(
                CityManagementActivity.CITY_ID));
      }

    };
    return dialogOnClickListener;
  }

}




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