Merge "Topology pane in extended displays list" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
0f7bf3062a
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.connecteddevice.display
|
||||
|
||||
import com.android.settings.R
|
||||
|
||||
import android.content.Context
|
||||
|
||||
import androidx.preference.Preference
|
||||
|
||||
const val PREFERENCE_KEY = "display_topology_preference"
|
||||
|
||||
/**
|
||||
* DisplayTopologyPreference allows the user to change the display topology
|
||||
* when there is one or more extended display attached.
|
||||
*/
|
||||
class DisplayTopologyPreference(context : Context) : Preference(context) {
|
||||
init {
|
||||
layoutResource = R.layout.display_topology_preference
|
||||
|
||||
// Prevent highlight when hovering with mouse.
|
||||
isSelectable = false
|
||||
|
||||
key = PREFERENCE_KEY
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,8 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
|
||||
@Nullable
|
||||
private FooterPreference mFooterPreference;
|
||||
@Nullable
|
||||
private Preference mDisplayTopologyPreference;
|
||||
@Nullable
|
||||
private PreferenceCategory mDisplaysPreference;
|
||||
@Nullable
|
||||
private Injector mInjector;
|
||||
@@ -279,6 +281,14 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
|
||||
return mDisplaysPreference;
|
||||
}
|
||||
|
||||
@NonNull Preference getDisplayTopologyPreference(@NonNull Context context) {
|
||||
if (mDisplayTopologyPreference == null) {
|
||||
mDisplayTopologyPreference = new DisplayTopologyPreference(context);
|
||||
mDisplayTopologyPreference.setPersistent(false);
|
||||
}
|
||||
return mDisplayTopologyPreference;
|
||||
}
|
||||
|
||||
private void restoreState(@Nullable Bundle savedInstanceState) {
|
||||
if (savedInstanceState == null) {
|
||||
return;
|
||||
@@ -296,20 +306,16 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
|
||||
updateScreenForDisplayId(getDisplayIdArg(), screen, mInjector.getContext());
|
||||
}
|
||||
|
||||
private boolean okayToBypassDisplayListSelection() {
|
||||
if (mInjector != null && forceShowDisplayList(mInjector.getFlags())) {
|
||||
return false;
|
||||
}
|
||||
return !mPreviouslyShownListOfDisplays;
|
||||
}
|
||||
|
||||
private void updateScreenForDisplayId(final int displayId,
|
||||
@NonNull final PreferenceScreen screen, @NonNull Context context) {
|
||||
final boolean forceShowList = displayId == INVALID_DISPLAY
|
||||
&& mInjector != null && forceShowDisplayList(mInjector.getFlags());
|
||||
final var displaysToShow = getDisplaysToShow(displayId);
|
||||
if (displaysToShow.isEmpty() && displayId == INVALID_DISPLAY) {
|
||||
|
||||
if (!forceShowList && displaysToShow.isEmpty() && displayId == INVALID_DISPLAY) {
|
||||
showTextWhenNoDisplaysToShow(screen, context);
|
||||
} else if (displaysToShow.size() == 1
|
||||
&& ((displayId == INVALID_DISPLAY && okayToBypassDisplayListSelection())
|
||||
} else if (!forceShowList && displaysToShow.size() == 1
|
||||
&& ((displayId == INVALID_DISPLAY && !mPreviouslyShownListOfDisplays)
|
||||
|| displaysToShow.get(0).getDisplayId() == displayId)) {
|
||||
showDisplaySettings(displaysToShow.get(0), screen, context);
|
||||
} else if (displayId == INVALID_DISPLAY) {
|
||||
@@ -367,6 +373,11 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
|
||||
|
||||
private void showDisplaysList(@NonNull List<Display> displaysToShow,
|
||||
@NonNull PreferenceScreen screen, @NonNull Context context) {
|
||||
if (mInjector != null
|
||||
&& mInjector.getFlags().displayTopologyPaneInDisplayList()) {
|
||||
screen.addPreference(getDisplayTopologyPreference(context));
|
||||
}
|
||||
|
||||
var pref = getDisplaysListPreference(context);
|
||||
pref.setKey(DISPLAYS_LIST_PREFERENCE_KEY);
|
||||
pref.removeAll();
|
||||
|
||||
Reference in New Issue
Block a user