Add original project.

This commit is contained in:
Hyperling 2025-01-04 12:42:10 -07:00
parent c3edbd1c33
commit c8f5e839c3
36 changed files with 1511 additions and 0 deletions

42
.gitignore vendored
View File

@ -33,3 +33,45 @@ google-services.json
# Android Profiling # Android Profiling
*.hprof *.hprof
## Suggested ^^
## From TicTacToe project for good measure. vv
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Log/OS Files
*.log
# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json
# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml
# Keystore files
*.jks
*.keystore
# Google Services (e.g. APIs or Firebase)
google-services.json
# Android Profiling
*.hprof
/app/debug/output-metadata.json
# Ha!
keystore/*
release

1
app/.gitignore vendored Executable file
View File

@ -0,0 +1 @@
/build

26
app/build.gradle Executable file
View File

@ -0,0 +1,26 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.hyperling.apps.example_sqlite_addressbook"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}

17
app/proguard-rules.pro vendored Executable file
View File

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/ling/WDBlue/Programming/Java/Android/android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -0,0 +1,13 @@
package com.hyperling.apps.example_sqlite_addressbook;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hyperling.apps.example_sqlite_addressbook">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,154 @@
package com.hyperling.apps.example_sqlite_addressbook;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
/**
* Created by ling on 12/13/15.
*/
public class AddEditFragment extends Fragment {
public interface AddEditFragmentListener {
public void onAddEditCompleted(long rowID);
}
private AddEditFragmentListener listener;
private long rowID;
private Bundle contactInfoBundle;
private EditText etName;
private EditText etPhone;
private EditText etEmail;
private EditText etStreet;
private EditText etCity;
private EditText etState;
private EditText etZip;
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
listener = (AddEditFragmentListener) activity;
}
@Override
public void onDetach(){
super.onDetach();
listener = null;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
super.onCreateView(inflater, container, savedInstanceState);
setRetainInstance(true);
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_add_edit, container, false);
etName = (EditText) view.findViewById(R.id.et_name);
etPhone = (EditText) view.findViewById(R.id.et_phone);
etEmail = (EditText) view.findViewById(R.id.et_email);
etStreet = (EditText) view.findViewById(R.id.et_street);
etCity = (EditText) view.findViewById(R.id.et_city);
etState = (EditText) view.findViewById(R.id.et_state);
etZip = (EditText) view.findViewById(R.id.et_zip);
contactInfoBundle = getArguments();
if (contactInfoBundle != null){
rowID = contactInfoBundle.getLong(MainActivity.ROW_ID);
etName.setText(contactInfoBundle.getString("name"));
etPhone.setText(contactInfoBundle.getString("phone"));
etEmail.setText(contactInfoBundle.getString("email"));
etStreet.setText(contactInfoBundle.getString("street"));
etCity.setText(contactInfoBundle.getString("city"));
etState.setText(contactInfoBundle.getString("state"));
etZip.setText(contactInfoBundle.getString("zip"));
}
Button btnSave = (Button) view.findViewById(R.id.btn_save);
btnSave.setOnClickListener(saveButtonClicked);
return view;
}
View.OnClickListener saveButtonClicked = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (etName.getText().toString().trim().length() > 0){
AsyncTask<Object, Object, Object> saveContactTask = new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... params) {
saveContact();
return null;
}
@Override
protected void onPostExecute(Object results){
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
listener.onAddEditCompleted(rowID);
}
};
saveContactTask.execute((Object[]) null);
}
else{
DialogFragment errorSaving = new DialogFragment(){
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.error_create_contact);
builder.setPositiveButton(R.string.msg_confirm_ok_button, null);
return builder.create();
}
};
errorSaving.show(getFragmentManager(), "Error saving contact");
}
}
};
private void saveContact(){
DatabaseConnector databaseConnector = new DatabaseConnector(getActivity());
if (contactInfoBundle == null) {
rowID = databaseConnector.insertContact(
etName.getText().toString(),
etPhone.getText().toString(),
etEmail.getText().toString(),
etStreet.getText().toString(),
etCity.getText().toString(),
etState.getText().toString(),
etZip.getText().toString()
);
}
else{
databaseConnector.updateContact(
rowID,
etName.getText().toString(),
etPhone.getText().toString(),
etEmail.getText().toString(),
etStreet.getText().toString(),
etCity.getText().toString(),
etState.getText().toString(),
etZip.getText().toString()
);
}
}
}

View File

@ -0,0 +1,123 @@
package com.hyperling.apps.example_sqlite_addressbook;
import android.app.Activity;
import android.app.ListFragment;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
/**
* Created by ling on 12/13/15.
*/
public class ContactListFragment extends ListFragment {
public interface ContactListFragmentListener{
public void onContactSelected(long rowID);
public void onAddContact();
}
private ContactListFragmentListener listener;
private ListView contactListView;
private CursorAdapter contactAdapter;
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
listener = (ContactListFragmentListener) activity;
}
@Override
public void onDetach(){
super.onDetach();
listener = null;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceBundle){
super.onViewCreated(view, savedInstanceBundle);
setRetainInstance(true);
setHasOptionsMenu(true);
setEmptyText(getResources().getString(R.string.no_contacts));
contactListView = getListView();
contactListView.setOnItemClickListener(viewContactListener);
contactListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
String[] from = new String[] {"name"};
int[] to = new int[] {android.R.id.text1};
contactAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_1, null, from, to, 0);
setListAdapter(contactAdapter);
}
AdapterView.OnItemClickListener viewContactListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listener.onContactSelected(id);
}
};
@Override
public void onResume(){
super.onResume();
new GetContactsTask().execute((Object[]) null);
}
private class GetContactsTask extends AsyncTask<Object, Object, Cursor>{
DatabaseConnector databaseConnector = new DatabaseConnector(getActivity());
@Override
protected Cursor doInBackground(Object... params){
databaseConnector.open();
return databaseConnector.getAllContacts();
}
@Override
protected void onPostExecute(Cursor result){
contactAdapter.changeCursor(result);
databaseConnector.close();
}
}
@Override
public void onStop(){
Cursor cursor = contactAdapter.getCursor();
contactAdapter.changeCursor(null);
if (cursor != null){
cursor.close();
}
super.onStop();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_contact_list_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.action_add:
listener.onAddContact();
return true;
}
return super.onOptionsItemSelected(item);
}
public void updateContactList(){
new GetContactsTask().execute((Object[]) null);
}
}

View File

@ -0,0 +1,107 @@
package com.hyperling.apps.example_sqlite_addressbook;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by ling on 12/13/15.
*/
public class DatabaseConnector extends Object {
private static final String DATABASE_NAME = "user_contacts";
private SQLiteDatabase database;
private DatabaseOpenHelper databaseOpenHelper;
public DatabaseConnector(Context context){
databaseOpenHelper = new DatabaseOpenHelper(context, DATABASE_NAME, null, 1);
}
public void open() throws SQLException{
database = databaseOpenHelper.getWritableDatabase();
}
public void close(){
if (database != null){
database.close();
}
}
public long insertContact(String name, String phone, String email, String street, String city, String state, String zip){
ContentValues newContact = new ContentValues();
newContact.put("name", name);
newContact.put("phone", phone);
newContact.put("email", email);
newContact.put("street", street);
newContact.put("city", city);
newContact.put("state", state);
newContact.put("zip", zip);
open();
long rowID = database.insert("contacts", null, newContact);
close();
return rowID;
}
public void updateContact(long id, String name, String phone, String email, String street, String city, String state, String zip){
ContentValues editContact = new ContentValues();
editContact.put("name", name);
editContact.put("phone", phone);
editContact.put("email", email);
editContact.put("street", street);
editContact.put("city", city);
editContact.put("state", state);
editContact.put("zip", zip);
open();
database.update("contacts", editContact, "_id=" + id, null);
close();
}
public Cursor getAllContacts(){
return database.query("contacts", new String[] {"_id"}, null, null, null, null, "name");
}
public Cursor getOneContact(long id){
return database.query("contacts", null, "_id=" + id, null, null, null, null);
}
public void deleteContact(long id){
open();
database.delete("contacts", "_id=" + id, null);
close();
}
private class DatabaseOpenHelper extends SQLiteOpenHelper{
public DatabaseOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db){
String createQuery =
"CREATE TABLE contacts" +
"(" +
"_id integer primary key autoincrement," +
"name TEXT," +
"phone TEXT," +
"email TEXT," +
"street TEXT," +
"city TEXT," +
"state TEXT," +
"zip TEXT" +
");";
db.execSQL(createQuery);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
// Do nothing
return;
}
}
}

View File

@ -0,0 +1,200 @@
package com.hyperling.apps.example_sqlite_addressbook;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.DialogInterface;
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.TextView;
/**
* Created by ling on 12/13/15.
*/
public class DetailsFragment extends Fragment {
public interface DetailsFragmentListener{
public void onContactDeleted();
public void onEditContact(Bundle arguments);
}
private DetailsFragmentListener listener;
private long rowID = -1;
private TextView tvName;
private TextView tvPhone;
private TextView tvEmail;
private TextView tvStreet;
private TextView tvCity;
private TextView tvState;
private TextView tvZip;
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
listener = (DetailsFragmentListener) activity;
}
@Override
public void onDetach(){
super.onDetach();
listener = null;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
super.onCreateView(inflater, container, savedInstanceState);
setRetainInstance(true);
if (savedInstanceState != null){
rowID = savedInstanceState.getLong(MainActivity.ROW_ID);
}
else{
Bundle arguments = getArguments();
if (arguments != null){
rowID = arguments.getLong(MainActivity.ROW_ID);
}
}
View view = inflater.inflate(R.layout.fragment_details, container, false);
setHasOptionsMenu(true);
tvName = (TextView) view.findViewById(R.id.tv_name);
tvPhone = (TextView) view.findViewById(R.id.tv_phone);
tvEmail = (TextView) view.findViewById(R.id.tv_email);
tvStreet = (TextView) view.findViewById(R.id.tv_street);
tvCity = (TextView) view.findViewById(R.id.tv_city);
tvState = (TextView) view.findViewById(R.id.tv_state);
tvZip = (TextView) view.findViewById(R.id.tv_zip);
return view;
}
@Override
public void onResume(){
super.onResume();
new LoadContactTask().execute(rowID);
}
@Override
public void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
outState.putLong(MainActivity.ROW_ID, rowID);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_details_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.action_edit:
Bundle arguments = new Bundle();
arguments.putLong(MainActivity.ROW_ID, rowID);
arguments.putCharSequence("name", tvName.getText());
arguments.putCharSequence("phone", tvPhone.getText());
arguments.putCharSequence("email", tvEmail.getText());
arguments.putCharSequence("street", tvStreet.getText());
arguments.putCharSequence("city", tvCity.getText());
arguments.putCharSequence("state", tvState.getText());
arguments.putCharSequence("zip", tvZip.getText());
return true;
case R.id.action_delete:
deleteContact();
return true;
}
return super.onOptionsItemSelected(item);
}
private class LoadContactTask extends AsyncTask<Long, Object, Cursor>{
DatabaseConnector databaseConnector = new DatabaseConnector(getActivity());
@Override
protected Cursor doInBackground(Long... params){
databaseConnector.open();
return databaseConnector.getOneContact(params[0]);
}
@Override
protected void onPostExecute(Cursor result){
super.onPostExecute(result);
result.moveToFirst();
int iName = result.getColumnIndex("name");
int iPhone = result.getColumnIndex("phone");
int iEmail = result.getColumnIndex("email");
int iStreet = result.getColumnIndex("street");
int iCity = result.getColumnIndex("city");
int iState = result.getColumnIndex("state");
int iZip = result.getColumnIndex("zip");
tvName.setText(result.getString(iName));
tvPhone.setText(result.getString(iPhone));
tvEmail.setText(result.getString(iEmail));
tvStreet.setText(result.getString(iStreet));
tvCity.setText(result.getString(iCity));
tvState.setText(result.getString(iState));
tvZip.setText(result.getString(iZip));
result.close();
databaseConnector.close();
}
private void deleteContact(){
confirmDelete.show(getFragmentManager(), "confirm delete");
}
private DialogFragment confirmDelete = new DialogFragment(){
@Override
public Dialog onCreateDialog(Bundle bundle){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.msg_confirm_title);
builder.setMessage(R.string.msg_confirm_text);
builder.setPositiveButton(R.string.msg_confirm_ok_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final DatabaseConnector databaseConnector = new DatabaseConnector(getActivity());
AsyncTask<Long, Object, Cursor> deleteTask = new AsyncTask<Long, Object, Cursor>() {
@Override
protected Cursor doInBackground(Long... params) {
databaseConnector.deleteContact(params[0]);
return null;
}
@Override
protected void onPostExecute(Object result) {
listener.onContactDeleted();
}
};
deleteTask.execute(new Long[]{rowID});
}
});
builder.setNegativeButton(R.string.msg_confirm_cancel_button, null);
return builder.create();
}
};
}
}

View File

@ -0,0 +1,120 @@
package com.hyperling.apps.example_sqlite_addressbook;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
implements ContactListFragment.ContactListFragmentListener,
DetailsFragment.DetailsFragmentListener,
AddEditFragment.AddEditFragmentListener{
public static final String ROW_ID = "row_id";
ContactListFragment contactListFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null){
return;
}
if (findViewById(R.id.fragmentContainer) != null){
contactListFragment = new ContactListFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.fragmentContainer, contactListFragment);
}
}
@Override
protected void onResume(){
super.onResume();
if (contactListFragment == null){
contactListFragment = (ContactListFragment) getFragmentManager().findFragmentById(R.id.contactListFragment);
}
}
@Override
public void onContactSelected(long rowID){
if (findViewById(R.id.fragmentContainer) != null){
displayContact(rowID, R.id.fragmentContainer);
}
else{
getFragmentManager().popBackStack();
displayContact(rowID, R.id.rightPaneContainer);
}
}
private void displayContact(long rowID, int viewID){
DetailsFragment detailsFragment = new DetailsFragment();
Bundle arguments = new Bundle();
arguments.putLong(ROW_ID, rowID);
detailsFragment.setArguments(arguments);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(viewID, detailsFragment);
transaction.addToBackStack(null);
transaction.commit();
}
@Override
public void onAddContact(){
if (findViewById(R.id.fragmentContainer) != null){
displayAddEditFragment(R.id.fragmentContainer, null);
}
else{
displayAddEditFragment(R.id.rightPaneContainer, null);
}
}
private void displayAddEditFragment(int viewID, Bundle arguments){
AddEditFragment addEditFragment = new AddEditFragment();
if (arguments != null){
addEditFragment.setArguments(arguments);
}
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(viewID, addEditFragment);
transaction.addToBackStack(null);
transaction.commit();
}
@Override
public void onContactDeleted(){
getFragmentManager().popBackStack();
if (findViewById(R.id.fragmentContainer) == null){
contactListFragment.updateContactList();
}
}
@Override
public void onEditContact(Bundle arguments){
if (findViewById(R.id.fragmentContainer) != null){
displayAddEditFragment(R.id.fragmentContainer, arguments);
}
else{
displayAddEditFragment(R.id.rightPaneContainer, arguments);
}
}
@Override
public void onAddEditCompleted(long rowID){
getFragmentManager().popBackStack();
if (findViewById(R.id.fragmentContainer) == null){
getFragmentManager().popBackStack();
contactListFragment.updateContactList();
displayContact(rowID, R.id.rightPaneContainer);
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<stroke android:width="1dp" android:color="#555"/>
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp"/>
</shape>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3">
<fragment
android:layout_width="0dp"
android:layout_height="match_parent"
android:name="com.hyperling.apps.example_sqlite_addressbook.ContactListFragment"
android:id="@+id/contactListFragment"
android:layout_weight="1"
android:layout_marginRight="@dimen/activity_horizontal_margin" />
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:id="@+id/rightPaneContainer"></FrameLayout>
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hyperling.apps.example_sqlite_addressbook.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragmentContainer"></FrameLayout>
</RelativeLayout>

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/addEditScrollView">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="1"
android:useDefaultMargins="true"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName|textCapWords"
android:id="@+id/et_name"
android:hint="Name (required)"
android:layout_column="0"
android:layout_row="1"
style="@style/ContactLabelTextView"
android:imeOptions="actionNext"
android:enabled="false"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:id="@+id/et_phone"
android:layout_column="0"
android:layout_row="2"
android:hint="Phone Number"
style="@style/ContactLabelTextView"
android:imeOptions="actionNext"
android:enabled="false"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:id="@+id/et_email"
android:hint="E-Mail Address"
android:layout_column="0"
android:layout_row="3"
style="@style/ContactLabelTextView"
android:imeOptions="actionNext"
android:enabled="false"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress|textCapWords"
android:id="@+id/et_street"
android:hint="Street Name"
android:layout_row="4"
android:layout_column="0"
style="@style/ContactLabelTextView"
android:imeOptions="actionNext"
android:enabled="false"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress|textCapWords"
android:id="@+id/et_city"
android:layout_column="0"
android:layout_row="5"
style="@style/ContactLabelTextView"
android:imeOptions="actionNext"
android:hint="City Name"
android:enabled="false"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress|textCapCharacters"
android:id="@+id/et_state"
style="@style/ContactLabelTextView"
android:imeOptions="actionNext"
android:hint="State Initials"
android:layout_column="0"
android:layout_row="6"
android:enabled="false"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:id="@+id/et_zip"
style="@style/ContactLabelTextView"
android:imeOptions="actionDone"
android:layout_column="0"
android:layout_row="7"
android:hint="Zip Code"
android:enabled="false"
android:ems="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Contact"
android:id="@+id/btn_save"
android:layout_gravity="center_horizontal"
android:layout_column="0"
android:layout_row="8" />
</GridLayout>
</ScrollView>

View File

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/detailsScrollView">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:useDefaultMargins="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:id="@+id/tvl_name"
android:layout_column="0"
android:layout_row="1"
style="@style/ContactLabelTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone:"
android:id="@+id/tvl_phone"
style="@style/ContactLabelTextView"
android:layout_column="0"
android:layout_row="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-Mail:"
android:id="@+id/tvl_email"
style="@style/ContactLabelTextView"
android:layout_column="0"
android:layout_row="3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Street:"
android:id="@+id/tvl_street"
style="@style/ContactLabelTextView"
android:layout_column="0"
android:layout_row="4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City:"
android:id="@+id/tvl_city"
style="@style/ContactLabelTextView"
android:layout_column="0"
android:layout_row="5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="State:"
android:id="@+id/tvl_state"
style="@style/ContactLabelTextView"
android:layout_column="0"
android:layout_row="6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zip:"
android:id="@+id/tvl_zip"
style="@style/ContactLabelTextView"
android:layout_row="7"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/tv_name"
android:layout_column="1"
android:layout_row="1"
style="@style/ContactTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/tv_phone"
android:layout_column="1"
android:layout_row="2"
style="@style/ContactTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/tv_email"
android:layout_column="1"
android:layout_row="3"
style="@style/ContactTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/tv_street"
android:layout_row="4"
android:layout_column="1"
style="@style/ContactTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/tv_city"
android:layout_column="1"
android:layout_row="5"
style="@style/ContactTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/tv_state"
style="@style/ContactTextView"
android:layout_column="1"
android:layout_row="6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/tv_zip"
style="@style/ContactTextView"
android:layout_column="1"
android:layout_row="7" />
</GridLayout>
</ScrollView>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_add"
android:orderInCategory="0"
android:title="Add Contact"
android:icon="@android:drawable/ic_menu_add"
app:showAsAction="ifRoom|withText"/>
</menu>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_edit"
android:orderInCategory="0"
android:title="Edit Contact"
android:icon="@android:drawable/ic_menu_edit"
app:showAsAction="ifRoom|withText"/>
<item android:id="@+id/action_delete"
android:orderInCategory="0"
android:title="Delete Contact"
android:icon="@android:drawable/ic_delete"
app:showAsAction="ifRoom|withText"/>
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@ -0,0 +1,9 @@
<resources>
<string name="app_name">Address Book</string>
<string name="no_contacts">No contacts have been added yet.</string>
<string name="msg_confirm_title">Are You Sure?</string>
<string name="msg_confirm_text">This will permanently delete the contact</string>
<string name="msg_confirm_ok_button">OK</string>
<string name="msg_confirm_cancel_button">Cancel</string>
<string name="error_create_contact">You must enter a contact name</string>
</resources>

View File

@ -0,0 +1,27 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="ContactLabelTextView">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">right|center_vertical</item>
</style>
<style name="ContactTextView">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">fill_horizontal</item>
<item name="android:textSize">16sp</item>
<item name="android:background">@drawable/textview_border</item>
</style>
</resources>

View File

@ -0,0 +1,15 @@
package com.hyperling.apps.example_sqlite_addressbook;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

23
build.gradle Executable file
View File

@ -0,0 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

18
gradle.properties Executable file
View File

@ -0,0 +1,18 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

BIN
gradle/wrapper/gradle-wrapper.jar vendored Executable file

Binary file not shown.

6
gradle/wrapper/gradle-wrapper.properties vendored Executable file
View File

@ -0,0 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip

160
gradlew vendored Executable file
View File

@ -0,0 +1,160 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored Executable file
View File

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

1
settings.gradle Executable file
View File

@ -0,0 +1 @@
include ':app'