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 
28 /** @deprecated Use {@link RecentLocationAccessSeeAllFragment} instead. */
29 @Deprecated
30 public class RecentLocationRequestSeeAllFragment extends DashboardFragment {
31     private static final String TAG = "RecentLocationReqAll";
32     public static final String PATH =
33             "com.android.settings.location.RecentLocationRequestSeeAllFragment";
34 
35     private static final int MENU_SHOW_SYSTEM = Menu.FIRST + 1;
36     private static final int MENU_HIDE_SYSTEM = Menu.FIRST + 2;
37 
38     private boolean mShowSystem = false;
39     private MenuItem mShowSystemMenu;
40     private MenuItem mHideSystemMenu;
41     private RecentLocationRequestSeeAllPreferenceController mController;
42 
43     @Override
getMetricsCategory()44     public int getMetricsCategory() {
45         return MetricsEvent.RECENT_LOCATION_REQUESTS_ALL;
46     }
47 
48     @Override
onAttach(Context context)49     public void onAttach(Context context) {
50         super.onAttach(context);
51         final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
52 
53         mController = use(RecentLocationRequestSeeAllPreferenceController.class);
54         mController.init(this);
55         if (profileType != 0) {
56             mController.setProfileType(profileType);
57         }
58     }
59 
60     @Override
getPreferenceScreenResId()61     protected int getPreferenceScreenResId() {
62         return R.xml.location_recent_requests_see_all;
63     }
64 
65     @Override
getLogTag()66     protected String getLogTag() {
67         return TAG;
68     }
69 
70     @Override
onOptionsItemSelected(MenuItem menuItem)71     public boolean onOptionsItemSelected(MenuItem menuItem) {
72         switch (menuItem.getItemId()) {
73             case MENU_SHOW_SYSTEM:
74             case MENU_HIDE_SYSTEM:
75                 mShowSystem = menuItem.getItemId() == MENU_SHOW_SYSTEM;
76                 updateMenu();
77                 if (mController != null) {
78                     mController.setShowSystem(mShowSystem);
79                 }
80                 return true;
81             default:
82                 return super.onOptionsItemSelected(menuItem);
83         }
84     }
85 
updateMenu()86     private void updateMenu() {
87         mShowSystemMenu.setVisible(!mShowSystem);
88         mHideSystemMenu.setVisible(mShowSystem);
89     }
90 
91     @Override
onCreateOptionsMenu(Menu menu, MenuInflater inflater)92     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
93         super.onCreateOptionsMenu(menu, inflater);
94         mShowSystemMenu = menu.add(Menu.NONE, MENU_SHOW_SYSTEM, Menu.NONE,
95                 R.string.menu_show_system);
96         mHideSystemMenu = menu.add(Menu.NONE, MENU_HIDE_SYSTEM, Menu.NONE,
97                 R.string.menu_hide_system);
98         updateMenu();
99     }
100 }
101