Android Open Source - android-weather-demo-application Modal Dialog Fragment






From Project

Back to project page android-weather-demo-application.

License

The source code is released under:

GNU General Public License

If you think the Android project android-weather-demo-application 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 org.openweathermap.fragment;
//from  ww  w  . j  a va 2s .co  m
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.ink.weather.R;

/**
 * Displays a dialog with an option to include a message or 
 * an "OK" button if the EXTRA_BUTTON_TYPE and EXTRA_DIALOG_TEXT 
 * extras are provided. The class could be extend to include more button types.
 * @author samkirton
 */
public class ModalDialogFragment extends DialogFragment implements OnClickListener, OnKeyListener {
  private Button uiOkButton;
  private TextView uiActivityDialogTextView;
  
  private int mButtonType;
  private boolean mIsBlocking;
  
  public static final int BUTTON_TYPE_OK = 1000;
  public static final int BUTTON_TYPE_BLOCKING = 1001;
  public static final String EXTRA_BUTTON_TYPE = "EXTRA_BUTTON_TYPE";
  public static final String EXTRA_DIALOG_TEXT = "EXTRA_DIALOG_TEXT";
  public static final String EXTRA_CANCEL_OPERATION = "EXTRA_CANCEL_OPERATION";
  
  public boolean isBlocking() {
    return mIsBlocking;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(STYLE_NORMAL, R.style.Dialog);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_modal_dialog, container, false);
    uiOkButton = (Button)view.findViewById(R.id.fragment_dialog_ok_button);
    uiActivityDialogTextView = (TextView)view.findViewById(R.id.activity_dialog_textview);
    return view;
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Bundle intent = getArguments();
    
    String dialogText = intent.getString(EXTRA_DIALOG_TEXT);
    mButtonType = intent.getInt(EXTRA_BUTTON_TYPE, BUTTON_TYPE_OK);
    uiActivityDialogTextView.setText(dialogText);
    
    // show the button type that has been requested
    if (mButtonType == BUTTON_TYPE_OK) {
      uiOkButton.setVisibility(View.VISIBLE);
      uiOkButton.setOnClickListener(this);
    }  else if (mButtonType == BUTTON_TYPE_BLOCKING) {
      mIsBlocking = true;
    }
    
    // setup the dialog key listener for blocking dialogs
    getDialog().setOnKeyListener(this);
  }
  
  /**
   * Close the dialog and send a cancel result back to the host activity
   */
  private void button_Click(int buttonType) {
    dismiss();
  }

  
  @Override
  public void onClick(View v) {
    button_Click(mButtonType);
  }

  @Override
  public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    // When the dialog is open and it is in blocking mode, the back button
    // should be disabled
    if (keyCode == KeyEvent.KEYCODE_BACK && mIsBlocking)
      return true;
       
    return false;
  }
}




Java Source Code List

org.openweathermap.WeatherApplication.java
org.openweathermap.activity.MainActivity.java
org.openweathermap.activity.base.BaseActivity.java
org.openweathermap.adapter.CityAdapter.java
org.openweathermap.adapter.ForecastAdapter.java
org.openweathermap.asynctask.GetCitiesAsyncTask.java
org.openweathermap.asynctask.GetLastCityAsyncTask.java
org.openweathermap.asynctask.SaveForecastAsyncTask.java
org.openweathermap.asynctask.SearchCitiesAsyncTask.java
org.openweathermap.asynctask.base.BaseAsyncTask.java
org.openweathermap.asynctask.base.BaseResponse.java
org.openweathermap.asynctask.base.IParam.java
org.openweathermap.asynctask.param.SaveForecastParam.java
org.openweathermap.asynctask.param.SearchCitiesParam.java
org.openweathermap.asynctask.response.GetCitiesResponse.java
org.openweathermap.asynctask.response.GetLastCityResponse.java
org.openweathermap.asynctask.response.SaveForecastResponse.java
org.openweathermap.dto.CityDTO.java
org.openweathermap.dto.CoordDTO.java
org.openweathermap.dto.DayDTO.java
org.openweathermap.dto.ResultDTO.java
org.openweathermap.dto.TempDTO.java
org.openweathermap.dto.WeatherDTO.java
org.openweathermap.dto.base.IDTO.java
org.openweathermap.fragment.ForecastFragment.java
org.openweathermap.fragment.ModalDialogFragment.java
org.openweathermap.fragment.SelectCountryFragment.java
org.openweathermap.sql.SQLInitProvider.java
org.openweathermap.sql.model.CityModel.java
org.openweathermap.sql.model.IconModel.java
org.openweathermap.sql.model.WeatherModel.java
org.openweathermap.utils.DateHelper.java
org.openweathermap.utils.RESTProvider.java
org.openweathermap.utils.ReflectionHelper.java
org.openweathermap.utils.ResourceHelper.java
org.openweathermap.utils.StringHelper.java
org.openweathermap.view.CityListItemView.java
org.openweathermap.view.DateDisplayView.java
org.openweathermap.view.ViewPagerFade.java
org.openweathermap.view.ViewPagerIndicatorView.java
org.openweathermap.view.WeatherDataRowView.java
org.openweathermap.volley.callback.VolleyResponseCallback.java
org.openweathermap.volley.provider.VolleyImageLoader.java
org.openweathermap.volley.provider.VolleyRequest.java