1 /* 2 * Copyright 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 package com.android.settings.location; 17 18 import android.content.Context; 19 import android.os.Bundle; 20 import android.view.Menu; 21 import android.view.MenuInflater; 22 import android.view.MenuItem; 23 24 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 import com.android.settings.dashboard.profileselector.ProfileSelectFragment; 28 import com.android.settings.search.BaseSearchIndexProvider; 29 import com.android.settingslib.search.SearchIndexable; 30 31 /** Dashboard Fragment to display all recent location access (apps), sorted by recency. */ 32 @SearchIndexable 33 public class RecentLocationAccessSeeAllFragment extends DashboardFragment { 34 private static final String TAG = "RecentLocAccessSeeAll"; 35 public static final String PATH = 36 "com.android.settings.location.RecentLocationAccessSeeAllFragment"; 37 38 private static final int MENU_SHOW_SYSTEM = Menu.FIRST + 1; 39 private static final int MENU_HIDE_SYSTEM = Menu.FIRST + 2; 40 private static final String EXTRA_SHOW_SYSTEM = "show_system"; 41 42 private boolean mShowSystem = false; 43 private MenuItem mShowSystemMenu; 44 private MenuItem mHideSystemMenu; 45 private RecentLocationAccessSeeAllPreferenceController mController; 46 47 @Override getMetricsCategory()48 public int getMetricsCategory() { 49 return MetricsEvent.RECENT_LOCATION_REQUESTS_ALL; 50 } 51 52 @Override onAttach(Context context)53 public void onAttach(Context context) { 54 super.onAttach(context); 55 final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE); 56 57 mController = use(RecentLocationAccessSeeAllPreferenceController.class); 58 mController.init(this); 59 if (profileType != 0) { 60 mController.setProfileType(profileType); 61 } 62 } 63 64 @Override onCreate(Bundle savedInstanceState)65 public void onCreate(Bundle savedInstanceState) { 66 super.onCreate(savedInstanceState); 67 if (savedInstanceState != null) { 68 mShowSystem = savedInstanceState.getBoolean(EXTRA_SHOW_SYSTEM, mShowSystem); 69 } 70 if (mController != null) { 71 mController.setShowSystem(mShowSystem); 72 } 73 } 74 75 @Override onSaveInstanceState(Bundle outState)76 public void onSaveInstanceState(Bundle outState) { 77 super.onSaveInstanceState(outState); 78 outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem); 79 } 80 81 @Override getPreferenceScreenResId()82 protected int getPreferenceScreenResId() { 83 return R.xml.location_recent_access_see_all; 84 } 85 86 @Override getLogTag()87 protected String getLogTag() { 88 return TAG; 89 } 90 91 @Override onOptionsItemSelected(MenuItem menuItem)92 public boolean onOptionsItemSelected(MenuItem menuItem) { 93 switch (menuItem.getItemId()) { 94 case MENU_SHOW_SYSTEM: 95 case MENU_HIDE_SYSTEM: 96 mShowSystem = menuItem.getItemId() == MENU_SHOW_SYSTEM; 97 updateMenu(); 98 if (mController != null) { 99 mController.setShowSystem(mShowSystem); 100 } 101 return true; 102 default: 103 return super.onOptionsItemSelected(menuItem); 104 } 105 } 106 updateMenu()107 private void updateMenu() { 108 mShowSystemMenu.setVisible(!mShowSystem); 109 mHideSystemMenu.setVisible(mShowSystem); 110 } 111 112 @Override onCreateOptionsMenu(Menu menu, MenuInflater inflater)113 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 114 super.onCreateOptionsMenu(menu, inflater); 115 mShowSystemMenu = menu.add(Menu.NONE, MENU_SHOW_SYSTEM, Menu.NONE, 116 R.string.menu_show_system); 117 mHideSystemMenu = menu.add(Menu.NONE, MENU_HIDE_SYSTEM, Menu.NONE, 118 R.string.menu_hide_system); 119 updateMenu(); 120 } 121 122 /** 123 * For Search. 124 */ 125 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 126 new BaseSearchIndexProvider(R.xml.location_recent_access_see_all); 127 } 128