ViewEmergencyInfoFragment.java revision 5874835f1edc1cac42eb4b3aa5fe437e8fd53c78
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 */ 16package com.android.emergency.view; 17 18import android.app.Fragment; 19import android.os.Bundle; 20import android.preference.Preference; 21import android.preference.PreferenceFragment; 22 23import com.android.emergency.PreferenceKeys; 24import com.android.emergency.R; 25import com.android.emergency.ReloadablePreferenceInterface; 26 27import java.util.ArrayList; 28import java.util.List; 29 30/** 31 * Fragment that displays personal and medical information. 32 */ 33public class ViewEmergencyInfoFragment extends PreferenceFragment { 34 /** A list with all the preferences. */ 35 private final List<Preference> mPreferences = new ArrayList<Preference>(); 36 37 @Override 38 public void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 addPreferencesFromResource(R.xml.view_emergency_info); 41 42 for (String preferenceKey : PreferenceKeys.KEYS_EMERGENCY_INFO) { 43 Preference preference = findPreference(preferenceKey); 44 mPreferences.add(preference); 45 } 46 } 47 48 @Override 49 public void onResume() { 50 super.onResume(); 51 for (Preference preference : mPreferences) { 52 ReloadablePreferenceInterface reloadablePreference = 53 (ReloadablePreferenceInterface) preference; 54 reloadablePreference.reloadFromPreference(); 55 if (reloadablePreference.isNotSet()) { 56 getPreferenceScreen().removePreference(preference); 57 } else { 58 // Note: this preference won't be added it if it already exists. 59 getPreferenceScreen().addPreference(preference); 60 } 61 } 62 } 63 64 public static Fragment newInstance() { 65 return new ViewEmergencyInfoFragment(); 66 } 67} 68