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