• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.dialer.list;
17 
18 import android.content.Context;
19 import android.content.res.Resources;
20 import android.database.Cursor;
21 import android.graphics.Color;
22 import android.view.View;
23 
24 import com.android.contacts.common.GeoUtil;
25 import com.android.contacts.common.list.ContactListItemView;
26 import com.android.dialer.R;
27 import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
28 
29 /**
30  * List adapter to display search results for adding a blocked number.
31  */
32 public class BlockedListSearchAdapter extends RegularSearchListAdapter {
33 
34     private Resources mResources;
35     private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
36 
BlockedListSearchAdapter(Context context)37     public BlockedListSearchAdapter(Context context) {
38         super(context);
39         mResources = context.getResources();
40         disableAllShortcuts();
41         setShortcutEnabled(SHORTCUT_BLOCK_NUMBER, true);
42 
43         mFilteredNumberAsyncQueryHandler =
44                 new FilteredNumberAsyncQueryHandler(context.getContentResolver());
45     }
46 
47     @Override
isChanged(boolean showNumberShortcuts)48     protected boolean isChanged(boolean showNumberShortcuts) {
49         return setShortcutEnabled(SHORTCUT_BLOCK_NUMBER, showNumberShortcuts || mIsQuerySipAddress);
50     }
51 
setViewBlocked(ContactListItemView view, Integer id)52     public void setViewBlocked(ContactListItemView view, Integer id) {
53         view.setTag(R.id.block_id, id);
54         final int textColor = mResources.getColor(R.color.blocked_number_block_color);
55         view.getDataView().setTextColor(textColor);
56         view.getLabelView().setTextColor(textColor);
57         //TODO: Add icon
58     }
59 
setViewUnblocked(ContactListItemView view)60     public void setViewUnblocked(ContactListItemView view) {
61         view.setTag(R.id.block_id, null);
62         final int textColor = mResources.getColor(R.color.dialtacts_secondary_text_color);
63         view.getDataView().setTextColor(textColor);
64         view.getLabelView().setTextColor(textColor);
65         //TODO: Remove icon
66     }
67 
68     @Override
bindView(View itemView, int partition, Cursor cursor, int position)69     protected void bindView(View itemView, int partition, Cursor cursor, int position) {
70         super.bindView(itemView, partition, cursor, position);
71 
72         final ContactListItemView view = (ContactListItemView) itemView;
73         // Reset view state to unblocked.
74         setViewUnblocked(view);
75 
76         final String number = getPhoneNumber(position);
77         final String countryIso = GeoUtil.getCurrentCountryIso(mContext);
78         final FilteredNumberAsyncQueryHandler.OnCheckBlockedListener onCheckListener =
79                 new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() {
80                     @Override
81                     public void onCheckComplete(Integer id) {
82                         if (id != null) {
83                             setViewBlocked(view, id);
84                         }
85                     }
86                 };
87         mFilteredNumberAsyncQueryHandler.isBlockedNumber(
88                 onCheckListener, number, countryIso);
89     }
90 }
91