Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1078ca33 authored by Danesh M's avatar Danesh M
Browse files

T9 Dialer : Update upon contact info changes

Refresh the local storage of contact info if contact info is updated
while dialer is still active.

Patchset 2 : cleanup
Patchset 3 : Move unregister to onResume (Can't rely on activty being present)

Change-Id: I6ab4fe199ebc67c318217ab20aa1718a02fcbcaa
parent 9e879a4a
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -34,6 +35,7 @@ import android.media.AudioManager;
import android.media.ToneGenerator;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
@@ -42,6 +44,7 @@ import android.provider.Contacts.Intents.Insert;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.provider.Contacts.PhonesColumns;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneStateListener;
@@ -147,6 +150,7 @@ public class DialpadFragment extends Fragment
    private T9Adapter mT9AdapterTop;
    private ViewSwitcher mT9Flipper;
    private LinearLayout mT9Top;
    private boolean mContactsUpdated;

    /**
     * Regular expression prohibiting manual phone call. Can be empty, which means "no rule".
@@ -260,6 +264,13 @@ public class DialpadFragment extends Fragment
                R.string.config_prohibited_phone_number_regexp);
    }

    private ContentObserver mContactObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            mContactsUpdated = true;
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
        View fragmentView = inflater.inflate(R.layout.dialpad_fragment, container, false);
@@ -522,13 +533,25 @@ public class DialpadFragment extends Fragment
    public void onResume() {
        super.onResume();

        if (sT9Search == null && isT9On()) {
        if ((sT9Search == null && isT9On()) || mContactsUpdated) {
            Thread loadContacts = new Thread(new Runnable() {
                public void run () {
                    sT9Search = new T9Search(getActivity());
                }
            });
            loadContacts.start();
            if (mContactsUpdated) {
                mContactsUpdated = false;
                onLongClick(mDelete);
                mT9Adapter = null;
                mT9AdapterTop = null;
                mT9ListTop.setAdapter(mT9AdapterTop);
                mT9List.setAdapter(mT9Adapter);
            }
        }

        if (isT9On()) {
            getActivity().getContentResolver().unregisterContentObserver(mContactObserver);
        }

        hideT9();
@@ -615,6 +638,10 @@ public class DialpadFragment extends Fragment
        // TODO: I wonder if we should not check if the AsyncTask that
        // lookup the last dialed number has completed.
        mLastNumberDialed = EMPTY_NUMBER;  // Since we are going to query again, free stale number.
        if (isT9On()) {
            getActivity().getContentResolver().registerContentObserver(
                    ContactsContract.Contacts.CONTENT_URI, true, mContactObserver);
        }
    }

    @Override