1 /* 2 * Copyright (C) 2021 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 17 package com.android.car.settings.wifi; 18 19 import android.car.drivingstate.CarUxRestrictions; 20 import android.car.drivingstate.CarUxRestrictionsManager; 21 import android.content.Context; 22 23 import androidx.annotation.NonNull; 24 25 import com.android.car.settings.R; 26 import com.android.car.settings.common.FragmentController; 27 import com.android.wifitrackerlib.WifiEntry; 28 29 import java.util.List; 30 31 /** 32 * Renders a list of no more than a specified number of {@link WifiEntry} as a list of preferences. 33 */ 34 public class LimitedWifiEntryListPreferenceController extends WifiEntryListPreferenceController 35 implements CarUxRestrictionsManager.OnUxRestrictionsChangedListener { 36 37 private int mMaxWifiEntryCount; 38 LimitedWifiEntryListPreferenceController(@onNull Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)39 public LimitedWifiEntryListPreferenceController(@NonNull Context context, String preferenceKey, 40 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 41 super(context, preferenceKey, fragmentController, uxRestrictions); 42 mMaxWifiEntryCount = getContext().getResources().getInteger( 43 R.integer.limited_wifi_entry_list_count); 44 } 45 46 @Override fetchWifiEntries()47 protected List<WifiEntry> fetchWifiEntries() { 48 List<WifiEntry> wifiEntries = super.fetchWifiEntries(); 49 50 if (wifiEntries.size() > mMaxWifiEntryCount) { 51 wifiEntries.subList(mMaxWifiEntryCount, wifiEntries.size()).clear(); 52 } 53 54 return wifiEntries; 55 } 56 } 57