Update new API for checking the embedding status

Test: Make sure behavior is correct as it was in
search flow, higlight flow, regular settings flow, split screen flow.
Bug: 204399167

Change-Id: I7fc29c8cdbfc6682963591f4ff805070bea4ca22
This commit is contained in:
Tsung-Mao Fang
2022-01-12 12:03:52 +08:00
parent 40dde37a07
commit 13a76eb84e
5 changed files with 14 additions and 22 deletions

Binary file not shown.

View File

@@ -16,10 +16,7 @@
package com.android.settings.activityembedding; package com.android.settings.activityembedding;
import android.app.Activity;
import android.app.ActivityTaskManager;
import android.content.Context; import android.content.Context;
import android.graphics.Rect;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.FeatureFlagUtils; import android.util.FeatureFlagUtils;
import android.util.Log; import android.util.Log;
@@ -65,13 +62,4 @@ public class ActivityEmbeddingUtils {
return isFlagEnabled && isSplitSupported; return isFlagEnabled && isSplitSupported;
} }
/** Whether the screen meets two-pane resolution. */
public static boolean isTwoPaneResolution(Activity activity) {
final Rect currentTaskBounds =
ActivityTaskManager.getInstance().getTaskBounds(activity.getTaskId());
return currentTaskBounds.width() >= getMinCurrentScreenSplitWidthPx(activity)
&& currentTaskBounds.height() >= getMinSmallestScreenSplitWidthPx(activity);
}
} }

View File

@@ -42,6 +42,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.window.embedding.SplitController;
import androidx.window.embedding.SplitRule; import androidx.window.embedding.SplitRule;
import com.android.settings.R; import com.android.settings.R;
@@ -85,8 +86,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements
private View mTwoPaneSuggestionView; private View mTwoPaneSuggestionView;
private CategoryMixin mCategoryMixin; private CategoryMixin mCategoryMixin;
private Set<HomepageLoadedListener> mLoadedListeners; private Set<HomepageLoadedListener> mLoadedListeners;
private SplitController mSplitController;
private boolean mIsEmbeddingActivityEnabled; private boolean mIsEmbeddingActivityEnabled;
private boolean mIsTwoPaneLastTime; private boolean mIsTwoPane;
/** A listener receiving homepage loaded events. */ /** A listener receiving homepage loaded events. */
public interface HomepageLoadedListener { public interface HomepageLoadedListener {
@@ -149,7 +151,8 @@ public class SettingsHomepageActivity extends FragmentActivity implements
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.settings_homepage_container); setContentView(R.layout.settings_homepage_container);
mIsEmbeddingActivityEnabled = ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this); mIsEmbeddingActivityEnabled = ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this);
mIsTwoPaneLastTime = ActivityEmbeddingUtils.isTwoPaneResolution(this); mSplitController = SplitController.getInstance();
mIsTwoPane = mSplitController.isActivityEmbedded(this);
final View appBar = findViewById(R.id.app_bar_container); final View appBar = findViewById(R.id.app_bar_container);
appBar.setMinimumHeight(getSearchBoxHeight()); appBar.setMinimumHeight(getSearchBoxHeight());
@@ -213,9 +216,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
final boolean isTwoPane = ActivityEmbeddingUtils.isTwoPaneResolution(this); final boolean newTwoPaneState = mSplitController.isActivityEmbedded(this);
if (mIsTwoPaneLastTime != isTwoPane) { if (mIsTwoPane != newTwoPaneState) {
mIsTwoPaneLastTime = isTwoPane; mIsTwoPane = newTwoPaneState;
updateHomepageAppBar(); updateHomepageAppBar();
updateHomepageBackground(); updateHomepageBackground();
} }
@@ -254,7 +257,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
} }
final Window window = getWindow(); final Window window = getWindow();
final int color = ActivityEmbeddingUtils.isTwoPaneResolution(this) final int color = mIsTwoPane
? Utils.getColorAttrDefaultColor(this, com.android.internal.R.attr.colorSurface) ? Utils.getColorAttrDefaultColor(this, com.android.internal.R.attr.colorSurface)
: Utils.getColorAttrDefaultColor(this, android.R.attr.colorBackground); : Utils.getColorAttrDefaultColor(this, android.R.attr.colorBackground);
@@ -416,7 +419,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
if (!mIsEmbeddingActivityEnabled) { if (!mIsEmbeddingActivityEnabled) {
return; return;
} }
if (ActivityEmbeddingUtils.isTwoPaneResolution(this)) { if (mIsTwoPane) {
findViewById(R.id.homepage_app_bar_regular_phone_view).setVisibility(View.GONE); findViewById(R.id.homepage_app_bar_regular_phone_view).setVisibility(View.GONE);
findViewById(R.id.homepage_app_bar_two_pane_view).setVisibility(View.VISIBLE); findViewById(R.id.homepage_app_bar_two_pane_view).setVisibility(View.VISIBLE);
} else { } else {

View File

@@ -33,6 +33,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.window.embedding.SplitController;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
@@ -144,7 +145,7 @@ public class TopLevelSettings extends DashboardFragment implements
if (mFirstStarted) { if (mFirstStarted) {
mFirstStarted = false; mFirstStarted = false;
} else if (mIsEmbeddingActivityEnabled && isOnlyOneActivityInTask() } else if (mIsEmbeddingActivityEnabled && isOnlyOneActivityInTask()
&& !ActivityEmbeddingUtils.isTwoPaneResolution(getActivity())) { && !SplitController.getInstance().isActivityEmbedded(getActivity())) {
// Set default highlight menu key for 1-pane homepage since it will show the placeholder // Set default highlight menu key for 1-pane homepage since it will show the placeholder
// page once changing back to 2-pane. // page once changing back to 2-pane.
Log.i(TAG, "Set default menu key"); Log.i(TAG, "Set default menu key");

View File

@@ -31,10 +31,10 @@ import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceGroupAdapter; import androidx.preference.PreferenceGroupAdapter;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.window.embedding.SplitController;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.homepage.SettingsHomepageActivity; import com.android.settings.homepage.SettingsHomepageActivity;
/** /**
@@ -255,6 +255,6 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
} }
private boolean isHighlightNeeded() { private boolean isHighlightNeeded() {
return ActivityEmbeddingUtils.isTwoPaneResolution(mHomepageActivity); return SplitController.getInstance().isActivityEmbedded(mHomepageActivity);
} }
} }