Support highlighting the menu entry for Search results

1. Add a receiver to monitor the search state
2. Shoe/hide the menu highlight in the listener
3. Highlight the menu entry in SearchResultTrampoline
4. Enable/disable the receiver in SettingsInitialize

Bug: 205781792
Test: manual, robotest
Change-Id: Ia04901f504172f4f0c7b4b2ea7eda5f3713f676d
This commit is contained in:
Jason Chiu
2021-11-11 14:24:37 +08:00
parent 9ae7fa254e
commit 3af73364ba
10 changed files with 155 additions and 47 deletions

View File

@@ -33,8 +33,6 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.homepage.TopLevelSettings;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.search.SearchIndexableResources;
@@ -108,18 +106,8 @@ public interface SearchFeatureProvider {
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
.logSettingsTileClick(KEY_HOMEPAGE_SEARCH_BAR, pageId);
if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) {
final TopLevelSettings fragment = (TopLevelSettings) activity
.getSupportFragmentManager().findFragmentById(R.id.main_content);
if (fragment != null) {
fragment.disableMenuHighlight();
}
activity.startActivity(intent);
} else {
final Bundle bundle = ActivityOptions.makeSceneTransitionAnimation(activity)
.toBundle();
activity.startActivity(intent, bundle);
}
final Bundle bundle = ActivityOptions.makeSceneTransitionAnimation(activity).toBundle();
activity.startActivity(intent, bundle);
});
}

View File

@@ -28,9 +28,11 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsApplication;
import com.android.settings.SubSettings;
import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.overlay.FeatureFactory;
import java.net.URISyntaxException;
@@ -99,12 +101,20 @@ public class SearchResultTrampoline extends Activity {
// navigation behavior.
ActivityEmbeddingRulesController.registerSubSettingsPairRule(this,
false /* clearTop */);
// TODO: pass menu key to homepage
intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
// Pass menu key to homepage
final SettingsHomepageActivity homeActivity =
((SettingsApplication) getApplicationContext()).getHomeActivity();
if (homeActivity != null) {
homeActivity.getMainFragment().setHighlightMenuKey(highlightMenuKey);
}
} else {
// Two-pane case
startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey));
startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
// Done.

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.search;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import com.android.settings.SettingsApplication;
import com.android.settings.homepage.SettingsHomepageActivity;
/**
* A broadcast receiver that monitors the search state to show/hide the menu highlight
*/
public class SearchStateReceiver extends BroadcastReceiver {
private static final String TAG = "SearchStateReceiver";
private static final String ACTION_SEARCH_START = "com.android.settings.SEARCH_START";
private static final String ACTION_SEARCH_EXIT = "com.android.settings.SEARCH_EXIT";
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
Log.w(TAG, "Null intent");
return;
}
final SettingsHomepageActivity homeActivity =
((SettingsApplication) context.getApplicationContext()).getHomeActivity();
if (homeActivity == null) {
return;
}
final String action = intent.getAction();
Log.d(TAG, "action: " + action);
if (TextUtils.equals(ACTION_SEARCH_START, action)) {
homeActivity.getMainFragment().setMenuHighlightShowed(false);
} else if (TextUtils.equals(ACTION_SEARCH_EXIT, action)) {
homeActivity.getMainFragment().setMenuHighlightShowed(true);
}
}
}