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.settings.search; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.text.TextUtils; 23 import android.util.FeatureFlagUtils; 24 import android.util.Log; 25 26 import com.android.settings.SettingsApplication; 27 import com.android.settings.core.FeatureFlags; 28 import com.android.settings.homepage.SettingsHomepageActivity; 29 30 /** 31 * A broadcast receiver that monitors the search state to show/hide the menu highlight 32 */ 33 public class SearchStateReceiver extends BroadcastReceiver { 34 35 private static final String TAG = "SearchStateReceiver"; 36 private static final String ACTION_SEARCH_START = "com.android.settings.SEARCH_START"; 37 private static final String ACTION_SEARCH_EXIT = "com.android.settings.SEARCH_EXIT"; 38 39 @Override onReceive(Context context, Intent intent)40 public void onReceive(Context context, Intent intent) { 41 if (FeatureFlagUtils.isEnabled(context, FeatureFlags.SETTINGS_SEARCH_ALWAYS_EXPAND)) { 42 // Not needed to show/hide the highlight when search is full screen 43 return; 44 } 45 46 if (intent == null) { 47 Log.w(TAG, "Null intent"); 48 return; 49 } 50 51 final SettingsHomepageActivity homeActivity = 52 ((SettingsApplication) context.getApplicationContext()).getHomeActivity(); 53 if (homeActivity == null) { 54 return; 55 } 56 57 final String action = intent.getAction(); 58 Log.d(TAG, "action: " + action); 59 if (TextUtils.equals(ACTION_SEARCH_START, action)) { 60 homeActivity.getMainFragment().setMenuHighlightShowed(false); 61 } else if (TextUtils.equals(ACTION_SEARCH_EXIT, action)) { 62 homeActivity.getMainFragment().setMenuHighlightShowed(true); 63 } 64 } 65 } 66