Android Open Source - Books Scan Or Manual Dialog Fragment

From Project

Back to project page Books.


The source code is released under:

Apache License

If you think the Android project Books 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.contender.books;
import android.content.DialogInterface;
import android.os.Bundle;
//from www . j a  v  a2  s  .c  o  m
 * Implements the ScanOrManualDialogFragment dialog used by {@link MainView}
 * <p>
 * Inquires if the user wants to add a new book by scanning its barcode or 
 * entering all information manually.
 * @author Paul Klinkenberg
public class ScanOrManualDialogFragment extends DialogFragment {

  /* The activity that creates an instance of this dialog fragment must
   * implement this interface in order to receive event callbacks.
   * Each method passes the DialogFragment in case the host needs to query it. */
  public interface ScanOrManualDialogListener {
    public void onDialogScanClick(DialogFragment dialog);
    public void onDialogManualClick(DialogFragment dialog);

  // Use this instance of the interface to deliver action events
  ScanOrManualDialogListener mListener;

  public void onAttach(Activity activity) {
    // Verify that the host activity implements the callback interface
    try {
      mListener = (ScanOrManualDialogListener) activity;
    } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString() + " must implement ScanOrManualDialogListener");

  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(R.string.dialog_scan, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
    builder.setNegativeButton(R.string.dialog_manual, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
        // Delete entry

    // Create the AlertDialog object and return it
    return builder.create();


Java Source Code List