1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.dialer.app.list;
import static android.Manifest.permission.CALL_PHONE;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v13.app.FragmentCompat;
import com.android.contacts.common.list.ContactEntryListAdapter;
import com.android.dialer.app.R;
import com.android.dialer.callintent.CallInitiationType;
import com.android.dialer.common.LogUtil;
import com.android.dialer.database.DialerDatabaseHelper;
import com.android.dialer.smartdial.SmartDialCursorLoader;
import com.android.dialer.util.PermissionsUtil;
import com.android.dialer.widget.EmptyContentView;
import java.util.Arrays;
/** Implements a fragment to load and display SmartDial search results. */
public class SmartDialSearchFragment extends SearchFragment
implements EmptyContentView.OnEmptyViewActionButtonClickedListener,
FragmentCompat.OnRequestPermissionsResultCallback {
private static final int CALL_PHONE_PERMISSION_REQUEST_CODE = 1;
private final BroadcastReceiver mSmartDialUpdatedReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LogUtil.i("SmartDialSearchFragment.onReceive", "smart dial update broadcast received");
reloadData();
}
};
/** Creates a SmartDialListAdapter to display and operate on search results. */
@Override
protected ContactEntryListAdapter createListAdapter() {
SmartDialNumberListAdapter adapter = new SmartDialNumberListAdapter(getActivity());
adapter.setUseCallableUri(super.usesCallableUri());
adapter.setQuickContactEnabled(true);
adapter.setShowEmptyListForNullQuery(getShowEmptyListForNullQuery());
// Set adapter's query string to restore previous instance state.
adapter.setQueryString(getQueryString());
adapter.setListener(this);
return adapter;
}
/** Creates a SmartDialCursorLoader object to load query results. */
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// Smart dialing does not support Directory Load, falls back to normal search instead.
if (id == getDirectoryLoaderId()) {
return super.onCreateLoader(id, args);
} else {
final SmartDialNumberListAdapter adapter = (SmartDialNumberListAdapter) getAdapter();
SmartDialCursorLoader loader = new SmartDialCursorLoader(super.getContext());
loader.setShowEmptyListForNullQuery(getShowEmptyListForNullQuery());
adapter.configureLoader(loader);
return loader;
}
}
@Override
public boolean getShowEmptyListForNullQuery() {
return true;
}
@Override
protected void setupEmptyView() {
if (mEmptyView != null && getActivity() != null) {
if (!PermissionsUtil.hasPermission(getActivity(), CALL_PHONE)) {
mEmptyView.setImage(R.drawable.empty_contacts);
mEmptyView.setActionLabel(R.string.permission_single_turn_on);
mEmptyView.setDescription(R.string.permission_place_call);
mEmptyView.setActionClickedListener(this);
} else {
mEmptyView.setImage(EmptyContentView.NO_IMAGE);
mEmptyView.setActionLabel(EmptyContentView.NO_LABEL);
mEmptyView.setDescription(EmptyContentView.NO_LABEL);
}
}
}
@Override
public void onStart() {
super.onStart();
LogUtil.i("SmartDialSearchFragment.onStart", "registering smart dial update receiver");
getActivity()
.registerReceiver(
mSmartDialUpdatedReceiver,
new IntentFilter(DialerDatabaseHelper.ACTION_SMART_DIAL_UPDATED));
}
@Override
public void onStop() {
super.onStop();
LogUtil.i("SmartDialSearchFragment.onStop", "unregistering smart dial update receiver");
getActivity().unregisterReceiver(mSmartDialUpdatedReceiver);
}
@Override
public void onEmptyViewActionButtonClicked() {
final Activity activity = getActivity();
if (activity == null) {
return;
}
String[] deniedPermissions =
PermissionsUtil.getPermissionsCurrentlyDenied(
getContext(), PermissionsUtil.allPhoneGroupPermissionsUsedInDialer);
if (deniedPermissions.length > 0) {
LogUtil.i(
"SmartDialSearchFragment.onEmptyViewActionButtonClicked",
"Requesting permissions: " + Arrays.toString(deniedPermissions));
FragmentCompat.requestPermissions(
this, deniedPermissions, CALL_PHONE_PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(
int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == CALL_PHONE_PERMISSION_REQUEST_CODE) {
setupEmptyView();
}
}
@Override
protected CallInitiationType.Type getCallInitiationType(boolean isRemoteDirectory) {
return CallInitiationType.Type.SMART_DIAL;
}
public boolean isShowingPermissionRequest() {
return mEmptyView != null && mEmptyView.isShowingContent();
}
@Override
public void setShowEmptyListForNullQuery(boolean show) {
if (getAdapter() != null) {
((SmartDialNumberListAdapter) getAdapter()).setShowEmptyListForNullQuery(show);
}
super.setShowEmptyListForNullQuery(show);
}
}
|