1 /* 2 * Copyright (C) 2022 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.location; 18 19 import android.content.Context; 20 import android.os.Bundle; 21 22 import androidx.annotation.Nullable; 23 24 import com.android.car.settings.R; 25 import com.android.car.settings.common.SettingsFragment; 26 import com.android.car.ui.toolbar.MenuItem; 27 28 import java.util.Arrays; 29 import java.util.List; 30 31 /** All apps that have recently accessed location. */ 32 public class LocationRecentAccessViewAllFragment extends SettingsFragment { 33 34 private boolean mShowSystem = false; 35 private MenuItem mShowHideSystemMenu; 36 private LocationRecentAccessViewAllPreferenceController mController; 37 38 @Override getPreferenceScreenResId()39 protected int getPreferenceScreenResId() { 40 return R.xml.location_recent_accessed_view_all_fragment; 41 } 42 43 @Override onCreate(@ullable Bundle savedInstanceState)44 public void onCreate(@Nullable Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 mShowHideSystemMenu = 47 new MenuItem.Builder(getContext()) 48 .setTitle(R.string.show_system) 49 .setOnClickListener(i -> setShowSystem(!mShowSystem)) 50 .build(); 51 } 52 53 @Override onAttach(Context context)54 public void onAttach(Context context) { 55 super.onAttach(context); 56 mController = 57 use( 58 LocationRecentAccessViewAllPreferenceController.class, 59 R.string.pk_location_recently_accessed); 60 } 61 62 @Override getToolbarMenuItems()63 protected List<MenuItem> getToolbarMenuItems() { 64 return Arrays.asList(mShowHideSystemMenu); 65 } 66 setShowSystem(boolean showSystem)67 private void setShowSystem(boolean showSystem) { 68 if (showSystem != mShowSystem) { 69 mShowSystem = showSystem; 70 mController.setShowSystem(showSystem); 71 updateMenu(); 72 } 73 } 74 updateMenu()75 private void updateMenu() { 76 mShowHideSystemMenu.setTitle(mShowSystem ? R.string.hide_system : R.string.show_system); 77 } 78 } 79