diff options
author | Chiao Cheng <chiaocheng@google.com> | 2012-09-19 13:37:41 -0700 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2012-09-21 10:18:05 -0700 |
commit | a1593e6ed73bd928594929ea40dbe6c84fc0d4b6 (patch) | |
tree | f81ffdd067a82ca0de1807a09f7745edb57ccf56 | |
parent | b8a1bc628d8ab6c48571e1e23dcb26ced7096adf (diff) |
[cherrypick] Reset call filter when a call is placed or received.
Created a receiver which will reset the call filter. Remove
the receiver when filter is not used.
Bug: 7164046
Change-Id: I17fa005a70369d777afc12567643d38176977d7a
-rw-r--r-- | src/com/android/dialer/calllog/CallLogFragment.java | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index faf2b52dc..a59be8546 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -32,6 +32,8 @@ import android.provider.CallLog; import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.telephony.PhoneNumberUtils; +import android.telephony.PhoneStateListener; +import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -91,6 +93,9 @@ public class CallLogFragment extends ListFragment private final Handler mHandler = new Handler(); + private TelephonyManager mTelephonyManager; + private PhoneStateListener mPhoneStateListener; + private class CustomContentObserver extends ContentObserver { public CustomContentObserver() { super(mHandler); @@ -220,8 +225,6 @@ public class CallLogFragment extends ListFragment new ContactInfoHelper(getActivity(), currentCountryIso)); setListAdapter(mAdapter); getListView().setItemsCanFocus(true); - - updateFilterHeader(); } /** @@ -303,6 +306,7 @@ public class CallLogFragment extends ListFragment mAdapter.changeCursor(null); getActivity().getContentResolver().unregisterContentObserver(mCallLogObserver); getActivity().getContentResolver().unregisterContentObserver(mContactsObserver); + unregisterPhoneCallReceiver(); } @Override @@ -348,34 +352,37 @@ public class CallLogFragment extends ListFragment return true; case R.id.show_outgoing_only: + // We only need the phone call receiver when there is an active call type filter. + // Not many people may use the filters so don't register the receiver until now . + registerPhoneCallReceiver(); mCallLogQueryHandler.fetchCalls(Calls.OUTGOING_TYPE); - mCallTypeFilter = Calls.OUTGOING_TYPE; - updateFilterHeader(); + updateFilterTypeAndHeader(Calls.OUTGOING_TYPE); return true; case R.id.show_incoming_only: + registerPhoneCallReceiver(); mCallLogQueryHandler.fetchCalls(Calls.INCOMING_TYPE); - mCallTypeFilter = Calls.INCOMING_TYPE; - updateFilterHeader(); + updateFilterTypeAndHeader(Calls.INCOMING_TYPE); return true; case R.id.show_missed_only: + registerPhoneCallReceiver(); mCallLogQueryHandler.fetchCalls(Calls.MISSED_TYPE); - mCallTypeFilter = Calls.MISSED_TYPE; - updateFilterHeader(); + updateFilterTypeAndHeader(Calls.MISSED_TYPE); return true; case R.id.show_voicemails_only: + registerPhoneCallReceiver(); mCallLogQueryHandler.fetchCalls(Calls.VOICEMAIL_TYPE); - mCallTypeFilter = Calls.VOICEMAIL_TYPE; - updateFilterHeader(); + updateFilterTypeAndHeader(Calls.VOICEMAIL_TYPE); mShowingVoicemailOnly = true; return true; case R.id.show_all_calls: + // Filter is being turned off, receiver no longer needed. + unregisterPhoneCallReceiver(); mCallLogQueryHandler.fetchCalls(CallLogQueryHandler.CALL_TYPE_ALL); - mCallTypeFilter = CallLogQueryHandler.CALL_TYPE_ALL; - updateFilterHeader(); + updateFilterTypeAndHeader(CallLogQueryHandler.CALL_TYPE_ALL); mShowingVoicemailOnly = false; return true; @@ -384,8 +391,10 @@ public class CallLogFragment extends ListFragment } } - private void updateFilterHeader() { - switch (mCallTypeFilter) { + private void updateFilterTypeAndHeader(int filterType) { + mCallTypeFilter = filterType; + + switch (filterType) { case CallLogQueryHandler.CALL_TYPE_ALL: mFilterStatusView.setVisibility(View.GONE); break; @@ -532,4 +541,31 @@ public class CallLogFragment extends ListFragment serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_NOTIFICATIONS); getActivity().startService(serviceIntent); } + + /** + * Register a phone call filter to reset the call type when a phone call is place. + */ + private void registerPhoneCallReceiver() { + mTelephonyManager = (TelephonyManager) getActivity().getSystemService( + Context.TELEPHONY_SERVICE); + mPhoneStateListener = new PhoneStateListener() { + @Override + public void onCallStateChanged(int state, String incomingNumber) { + if (state == TelephonyManager.CALL_STATE_OFFHOOK || + state == TelephonyManager.CALL_STATE_RINGING) { + updateFilterTypeAndHeader(CallLogQueryHandler.CALL_TYPE_ALL); + } + } + }; + mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); + } + + /** + * Un-registers the phone call receiver. + */ + private void unregisterPhoneCallReceiver() { + if (mPhoneStateListener != null) { + mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); + } + } } |