// Path: ClassExamples/AddressBookActiveAndroid/app/src/main/java/com/deitel/addressbook/models/Contact.java
// @Table(name = "contacts")
// public class Contact extends Model {
// 
//     @Column(name = "name")
//     public String name;
// 
//     @Column(name = "phone")
//     public String phone;
// 
//     @Column(name = "email")
//     public String email;
// 
//     @Column(name = "street")
//     public String street;
// 
//     @Column(name = "city")
//     public String city;
// 
//     @Column(name = "state")
//     public String state;
// 
//     @Column(name = "zip")
//     public String zip;
// 
// }
// 
// Path: ClassExamples/AddressBookActiveAndroid/app/src/main/java/com/deitel/addressbook/util/AsyncTaskLoaderExample.java
// public abstract class AsyncTaskLoaderExample<T> extends AsyncTaskLoader<T> {
//     T mData;
// 
//     public AsyncTaskLoaderExample(Context context) {
//         super(context);
//     }
// 
//     @Override
//     public void deliverResult(final T data) {
//         Log.d("AppLog", "deliverResult");
//         if (isReset()) {
//             // An async query came in while the loader is stopped.  We don't need the result.
//             if (data != null) {
//                 onReleaseResources(data);
//             }
//         }
//         T oldData = mData;
//         mData = data;
//         if (isStarted()) {
//             // If the Loader is currently started, we can immediately
//             // deliver its results.
//             super.deliverResult(data);
//         }
//         // At this point we can release the resources associated with
//         // 'oldData' if needed; now that the new result is delivered we
//         // know that it is no longer in use.
//         if (oldData != null) {
//             onReleaseResources(oldData);
//         }
//     }
//     @Override
//     protected void onStartLoading() {
//         Log.d("AppLog", "onStartLoading");
//         super.onStartLoading();
//         if (mData != null) {
//             // If we currently have a result available, deliver it
//             // immediately.
//             deliverResult(mData);
//         }
//         // check if config changed
//         if (takeContentChanged() || mData == null) {// || configChange) {
//             // If the data has changed since the last time it was loaded
//             // or is not currently available, start a load.
//             forceLoad();
//         }
//     }
//     @Override
//     protected void onStopLoading() {
//         Log.d("AppLog", "onStopLoading");
//         // Attempt to cancel the current load task if possible.
//         cancelLoad();
//     }
//     @Override
//     public void onCanceled(T data) {
//         super.onCanceled(data);
//         Log.d("AppLog", "onCanceled:" + data);
//         // At this point we can release the resources associated with 'data' if needed.
//         onReleaseResources(data);
//     }
//     @Override
//     protected void onReset() {
//         super.onReset();
//         Log.d("AppLog", "onReset");
//         // Ensure the loader is stopped
//         onStopLoading();
//         // At this point we can release the resources associated with 'data' if needed.
//         if (mData != null) {
//             onReleaseResources(mData);
//             mData = null;
//         }
//     }
//     protected void onReleaseResources(T data) {
//         Log.d("AppLog", "onReleaseResources");
//         //  nothing to do.
//     }
// }


import android.app.Activity;
import android.app.ListFragment;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Loader;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import com.activeandroid.query.Select;
import com.deitel.addressbook.models.Contact;
import com.deitel.addressbook.util.AsyncTaskLoaderExample;
import java.util.List;
      return new AsyncTaskLoaderExample<List<Contact>>(getActivity()) {
          @Override
          public List<Contact> loadInBackground() {
              return new Select().from(Contact.class).orderBy("name asc").execute();
          }
      };
   }

   @Override
   public void onLoadFinished(Loader<List<Contact>> loader, List<Contact> data) {
       setListAdapter(new ContactAdapter(getActivity(), android.R.layout.simple_list_item_1, data));
   }

   @Override
   public void onLoaderReset(Loader<List<Contact>> loader) {
       setListAdapter(null);
   }

   // update data set
   public void updateContactList()
   {
      getLoaderManager().restartLoader(0, new Bundle(), this);
   }


    public class ContactAdapter extends ArrayAdapter<Contact> {
        int resourceId;

        Context context;

// Path: ClassExamples/AddressBookActiveAndroid/app/src/main/java/com/deitel/addressbook/models/Contact.java
// @Table(name = "contacts")
// public class Contact extends Model {
// 
//     @Column(name = "name")
//     public String name;
// 
//     @Column(name = "phone")
//     public String phone;
// 
//     @Column(name = "email")
//     public String email;
// 
//     @Column(name = "street")
//     public String street;
// 
//     @Column(name = "city")
//     public String city;
// 
//     @Column(name = "state")
//     public String state;
// 
//     @Column(name = "zip")
//     public String zip;
// 
// }
// 
// Path: ClassExamples/AddressBookActiveAndroid/app/src/main/java/com/deitel/addressbook/util/AsyncTaskLoaderExample.java
// public abstract class AsyncTaskLoaderExample<T> extends AsyncTaskLoader<T> {
//     T mData;
// 
//     public AsyncTaskLoaderExample(Context context) {
//         super(context);
//     }
// 
//     @Override
//     public void deliverResult(final T data) {
//         Log.d("AppLog", "deliverResult");
//         if (isReset()) {
//             // An async query came in while the loader is stopped.  We don't need the result.
//             if (data != null) {
//                 onReleaseResources(data);
//             }
//         }
//         T oldData = mData;
//         mData = data;
//         if (isStarted()) {
//             // If the Loader is currently started, we can immediately
//             // deliver its results.
//             super.deliverResult(data);
//         }
//         // At this point we can release the resources associated with
//         // 'oldData' if needed; now that the new result is delivered we
//         // know that it is no longer in use.
//         if (oldData != null) {
//             onReleaseResources(oldData);
//         }
//     }
//     @Override
//     protected void onStartLoading() {
//         Log.d("AppLog", "onStartLoading");
//         super.onStartLoading();
//         if (mData != null) {
//             // If we currently have a result available, deliver it
//             // immediately.
//             deliverResult(mData);
//         }
//         // check if config changed
//         if (takeContentChanged() || mData == null) {// || configChange) {
//             // If the data has changed since the last time it was loaded
//             // or is not currently available, start a load.
//             forceLoad();
//         }
//     }
//     @Override
//     protected void onStopLoading() {
//         Log.d("AppLog", "onStopLoading");
//         // Attempt to cancel the current load task if possible.
//         cancelLoad();
//     }
//     @Override
//     public void onCanceled(T data) {
//         super.onCanceled(data);
//         Log.d("AppLog", "onCanceled:" + data);
//         // At this point we can release the resources associated with 'data' if needed.
//         onReleaseResources(data);
//     }
//     @Override
//     protected void onReset() {
//         super.onReset();
//         Log.d("AppLog", "onReset");
//         // Ensure the loader is stopped
//         onStopLoading();
//         // At this point we can release the resources associated with 'data' if needed.
//         if (mData != null) {
//             onReleaseResources(mData);
//             mData = null;
//         }
//     }
//     protected void onReleaseResources(T data) {
//         Log.d("AppLog", "onReleaseResources");
//         //  nothing to do.
//     }
// }


// Path: ClassExamples/AddressBookActiveAndroid/app/src/main/java/com/deitel/addressbook/ContactListFragment.java
import android.app.Activity;
import android.app.ListFragment;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Loader;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import com.activeandroid.query.Select;
import com.deitel.addressbook.models.Contact;
import com.deitel.addressbook.util.AsyncTaskLoaderExample;
import java.util.List;

      return new AsyncTaskLoaderExample<List<Contact>>(getActivity()) {
          @Override
          public List<Contact> loadInBackground() {
              return new Select().from(Contact.class).orderBy("name asc").execute();
          }
      };
   }

   @Override
   public void onLoadFinished(Loader<List<Contact>> loader, List<Contact> data) {
       setListAdapter(new ContactAdapter(getActivity(), android.R.layout.simple_list_item_1, data));
   }

   @Override
   public void onLoaderReset(Loader<List<Contact>> loader) {
       setListAdapter(null);
   }

   // update data set
   public void updateContactList()
   {
      getLoaderManager().restartLoader(0, new Bundle(), this);
   }


    public class ContactAdapter extends ArrayAdapter<Contact> {
        int resourceId;

        Context context;

        public ContactAdapter(Context context, int resource, List<Contact> objects) {