************************************************************************ ItemDivider.java ************************************************************************ // ItemDivider.java // Class that defines dividers displayed between the RecyclerView items; // based on Google's sample implementation at bit.ly/DividerItemDecoration package at.htl.addressbook; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.support.v7.widget.RecyclerView; import android.view.View; class ItemDivider extends RecyclerView.ItemDecoration { private final Drawable divider; // constructor loads built-in Android list item divider public ItemDivider(Context context) { int[] attrs = {android.R.attr.listDivider}; divider = context.obtainStyledAttributes(attrs).getDrawable(0); } // draws the list item dividers onto the RecyclerView @Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { super.onDrawOver(c, parent, state); // calculate left/right x-coordinates for all dividers int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); // for every item but the last, draw a line below it for (int i = 0; i < parent.getChildCount() - 1; ++i) { View item = parent.getChildAt(i); // get ith list item // calculate top/bottom y-coordinates for current divider int top = item.getBottom() + ((RecyclerView.LayoutParams) item.getLayoutParams()).bottomMargin; int bottom = top + divider.getIntrinsicHeight(); // draw the divider with the calculated bounds divider.setBounds(left, top, right, bottom); divider.draw(c); } } } ************************************************************************ strings.xml ************************************************************************ AddressBook Edit Delete Name (Required) E-Mail Phone Street City State Zip Name: E-Mail: Phone: Street: City: State: Zip: Are You Sure? This will permanently delete the contact Cancel Delete Contact added successfully Contact was not added due to an error Contact updated Contact was not updated due to an error Invalid query Uri: Invalid insert Uri: Invalid update Uri: Invalid delete Uri: Insert failed: ************************************************************************ content_main.xml for tablets (!) ************************************************************************ ************************************************************************ fragment_details.xml ************************************************************************ ************************************************************************ fragment_details_menu.xml ************************************************************************ ************************************************************************ DatabaseDescription.java ************************************************************************ // DatabaseDescription.java // Describes the table name and column names for this app's database, // and other information required by the ContentProvider package at.htl.addressbook.data; import android.content.ContentUris; import android.net.Uri; import android.provider.BaseColumns; public class DatabaseDescription { // ContentProvider's name: typically the package name public static final String AUTHORITY = "at.htl.addressbook.data"; // base URI used to interact with the ContentProvider private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + AUTHORITY); // nested class defines contents of the contacts table public static final class Contact implements BaseColumns { public static final String TABLE_NAME = "contacts"; // table's name // Uri for the contacts table public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(TABLE_NAME).build(); // column names for contacts table's columns public static final String COLUMN_NAME = "name"; public static final String COLUMN_PHONE = "phone"; public static final String COLUMN_EMAIL = "email"; public static final String COLUMN_STREET = "street"; public static final String COLUMN_CITY = "city"; public static final String COLUMN_STATE = "state"; public static final String COLUMN_ZIP = "zip"; // creates a Uri for a specific contact public static Uri buildContactUri(long id) { return ContentUris.withAppendedId(CONTENT_URI, id); } } } ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************