Android Open Source - notepad Confirmation Dialog Fragment






From Project

Back to project page notepad.

License

The source code is released under:

MIT License

If you think the Android project notepad 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.mick88.notepad;
// w w w.  ja va  2 s .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.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.ContextThemeWrapper;

public class ConfirmationDialogFragment extends DialogFragment
{
  Bundle bundle;
  
  public interface ConfirmationDialogListener
  {
    public void onYesClicked(DialogFragment dialog, Bundle bundle);
    public void onNoClicked(DialogFragment dialog, Bundle bundle);
  }
  
  static ConfirmationDialogListener listener;
  
  @Override
  public void setArguments(Bundle bundle)
  {
    this.bundle.putAll(bundle);
    super.setArguments(bundle);
  }
  
  public ConfirmationDialogFragment()
  {
    this.bundle=new Bundle();
  }
  
  public static ConfirmationDialogFragment newInstance(Activity activity, String question, int id)
  {
    
    try
    {
      listener = (ConfirmationDialogListener)activity;
    }
    catch (ClassCastException e)
    {
      throw new ClassCastException(activity.toString()+" must implement ConfirmationDialogListener");
    }
    ConfirmationDialogFragment dialog = new ConfirmationDialogFragment();
    Bundle bundle = new Bundle();
    bundle.putInt("dialogId", id);
    bundle.putString("text", question);
    dialog.setArguments(bundle);
    return dialog;
  }
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState)
  {
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog));    
    
    builder.setMessage(bundle.getString("text"));
    builder.setTitle(R.string.app_name);
    
    builder.setPositiveButton(getString(android.R.string.yes), new OnClickListener()
    {      
      public void onClick(DialogInterface dialog, int which)
      {
        listener.onYesClicked(ConfirmationDialogFragment.this, bundle);
        
      }
    });
    builder.setNegativeButton(getString(android.R.string.no), new OnClickListener()
    {
      
      public void onClick(DialogInterface dialog, int which)
      {
        listener.onNoClicked(ConfirmationDialogFragment.this, bundle);
        
      }
    });
    
    return builder.create();
  }
}




Java Source Code List

com.mick88.notepad.ConfirmationDialogFragment.java
com.mick88.notepad.NotepadApplication.java
com.mick88.notepad.note_edit.NoteEditActivity.java
com.mick88.notepad.note_list.LinkListDialog.java
com.mick88.notepad.note_list.NotepadListActivity.java
com.mick88.notepad.notes.NoteManager.java
com.mick88.notepad.notes.Note.java