top of page

Contact Diary App to Save Contacts, Call and Message them - Android App Assignment Help

Updated: Dec 25, 2021



Introduction:

This Blog Explains how to design an Android APK which can manage contact information using some database. The contact table should contain information like first name, house number, street, town, country, etc. APK should allow the user to input a contact, delete a contact, edit a contact. Using APK user can make a call and message the given contact.

You can see the requirements in the video above for more clarifications. It is recommended that you try it yourself before giving it a read.


Programming Concepts Used:


Recycler View:

RecyclerView makes it easy to efficiently display large sets of data. You supply the data and define how each item looks, and the RecyclerView library dynamically creates the elements when they're needed.As the name implies, RecyclerView recycles those individual elements. When an item scrolls off the screen, RecyclerView doesn't destroy its view. Instead, RecyclerView reuses the view for new items that have scrolled onscreen.This reuse vastly improves performance, improving your app's responsiveness and reducing power consumption.

In contact list APK Recycler View is used to display contacts name and a contact icon beside.



package com.example.contactlist;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> implements Filterable {
    private Context context;

    Activity activity;
    private ArrayList temp;
    private ArrayList id_list, familyList, nameList, townList, streetList, countryList, houseNumberList, postcodeList, telephoneList, nameCardList;
    public CustomAdapter(Activity activity, Context context, ArrayList id_list, ArrayList familyList,
                  ArrayList nameList, ArrayList townList, ArrayList streetList, ArrayList countryList, ArrayList houseNumberList,
                  ArrayList postcodeList, ArrayList telephoneList, ArrayList nameCardList){
        this.activity = activity;
        this.context = context;
         this.id_list = id_list;
        this.nameList = nameList;
        this.familyList = familyList;
        this.townList = townList;
        this.streetList = streetList;
        this.countryList = countryList;
        this.houseNumberList = houseNumberList;
        this.postcodeList = postcodeList;
        this.telephoneList = telephoneList;
        this.nameCardList = nameCardList;
        temp = new ArrayList(nameList);
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.row, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
         //holder.family.setText(String.valueOf(familyList.get(position)));
          holder.name.setText(String.valueOf(nameList.get(position)));
        //holder.mobile.setText(String.valueOf(telephoneList.get(position)));
        holder.mainLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, UpdateActivity.class);
                intent.putExtra("id", String.valueOf(id_list.get(position)));
                intent.putExtra("fam", String.valueOf(familyList.get(position)));
                intent.putExtra("firs", String.valueOf(nameList.get(position)));
                intent.putExtra("house", String.valueOf(houseNumberList.get(position)));
                intent.putExtra("stree", String.valueOf(streetList.get(position)));
                intent.putExtra("tow", String.valueOf(townList.get(position)));
                intent.putExtra("countr", String.valueOf(countryList.get(position)));
                intent.putExtra("pin", String.valueOf(postcodeList.get(position)));
                intent.putExtra("tele", String.valueOf(telephoneList.get(position)));
                intent.putExtra("nameCa", String.valueOf(nameCardList.get(position)));

                 //context.startActivity(intent);


                activity.startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    public int getItemCount() {
        return nameList.size();
    }

    @Override
    public Filter getFilter() {
        return filter;
    }
    Filter filter = new Filter(){
       //Will Run On Background Thread
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            List<String> filteredList = new ArrayList<>();
            if(constraint.toString().isEmpty()){
                filteredList.addAll(temp);
            }
            else{
                for(Object name : temp){
                   if(name.toString().toLowerCase().contains(constraint.toString().toLowerCase())){
                       filteredList.add(name.toString());
                   }
                }
            }
            FilterResults filterResults = new FilterResults();
            filterResults.values = filteredList;
            return filterResults;
        }
        //Will Run On UI Thread
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            Log.i("Results: ", results.values.toString());
             nameList.clear();
            Log.i("Name List: ", nameList.toString());
             //nameList.addAll((Collection<? extends String>) results.values);
            nameList.addAll((List) results.values);
             notifyDataSetChanged();
        }
    };

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        LinearLayout mainLayout;
        ImageView image;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.name);
            image = itemView.findViewById(R.id.imageView3);
            mainLayout = itemView.findViewById(R.id.mainLayout);

        }
    }
}


Custom Adapter:

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set. We have created our custom adapter for the APK which uses Recycler Adapter and Recycler View View holder.


It contains three methods:

onCreateViewHolder, onBindViewHolder and getItemCount().

-> OnCreateViewHolder creates a view and returns it.

-> onBindViewHolder() associates the data with the view holder for a given position in the RecyclerView.

-> getItemCount() returns to number of data items available for displaying.



Database Helper:

You create a subclass implementing onCreate(SQLiteDatabase),

onUpgrade(SQLiteDatabase, int, int) and optionally onOpen(SQLiteDatabase), and this class takes care of opening the database if it exists, creating it if it does not, and upgrading it as necessary.Transactions are used to make sure the database is always in a sensible state. This class makes it easy for ContentProvider implementations to defer opening and upgrading the database until first use, to avoid blocking application startup with long-running database upgrades.

-> onCreate(SQLiteDatabase db)

Called when the database is created for the first time.

-> onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

Called when the database needs to be upgraded.

-> onOpen(SQLiteDatabase db)

Called when the database has been opened.



Search View:

Android SearchView provides user interface to search query submitted over search provider. SearchView widget can be implemented over ToolBar/ActionBar or inside a layout.


Methods of Search View:

-> public boolean onQueryTextSubmit(String query): It searches the query on the submission of content over SearchView editor. It is case dependent.


-> public boolean onQueryTextChange(String newText): It searches the query at the time of text change over SearchView editor.

Implementing Search View in contact list apk requires to implement filterable in custom adapter to get filter.



It uses two methods:

protected FilterResults performFiltering(CharSequence constraint): This method performs filtering and return FilterResults, It runs in background thread.


void publishResults(CharSequence constraint, FilterResults results) : This method publishes filtered results on UI thread.



Add Contact Activity:

We can fill details of a contact and save in this activity.



Update Contact Activity:

We can update contact details in this activity, and can delete contact as well.



Message Activity:

We can send message to the contact specified in the update activity by tapping the message icon.




Call Activity:

This activity is called when user taps the phone icon in the update activity.





If you are looking for Android Assignment Help or Homework Help? Codersarts Android assignment help expert will provides best quality plagiarism free solution at affordable price. We are available 24 * 7 online to assist you. You may chat with us through website chat or email or can fill contact form.
2 comments
bottom of page