• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.emergency.preferences;
17 
18 import android.content.Context;
19 import androidx.preference.Preference;
20 import androidx.preference.PreferenceViewHolder;
21 
22 import android.util.AttributeSet;
23 import android.view.View;
24 
25 import com.android.emergency.R;
26 import com.android.emergency.util.PreferenceUtils;
27 
28 /**
29  * Sets a listener to be called the contacts when tapping on the preference.
30  */
31 public class ViewEmergencyContactsPreference extends EmergencyContactsPreference {
ViewEmergencyContactsPreference(Context context, AttributeSet attrs)32     public ViewEmergencyContactsPreference(Context context, AttributeSet attrs) {
33         super(context, attrs);
34     }
35 
36     @Override
onBindViewHolder(PreferenceViewHolder holder)37     public void onBindViewHolder(PreferenceViewHolder holder) {
38         super.onBindViewHolder(holder);
39         // Hide preference title if has at least one medical info preference is set.
40         if (PreferenceUtils.hasAtLeastOnePreferenceSet(getContext())) {
41             View preferenceCategoryTitle = holder.findViewById(R.id.emergency_preference_category);
42             preferenceCategoryTitle.setVisibility(View.GONE);
43         }
44     }
45 
46     @Override
onBindContactView(final ContactPreference contactPreference)47     protected void onBindContactView(final ContactPreference contactPreference) {
48         contactPreference
49                 .setOnPreferenceClickListener(
50                         new Preference.OnPreferenceClickListener() {
51                             @Override
52                             public boolean onPreferenceClick(Preference preference) {
53                                 contactPreference.callContact();
54                                 return true;
55                             }
56                         }
57                 );
58     }
59 }
60