Merge "[Large screen] Check if it's in 2-pane before 2-pane deep link flow" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ea216fd2f3
@@ -58,6 +58,7 @@ import androidx.preference.PreferenceManager;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.Settings.WifiSettingsActivity;
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||
import com.android.settings.activityembedding.SplitStateObserver;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.core.OnActivityResultListener;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
@@ -255,11 +256,8 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
// Should happen before any call to getIntent()
|
||||
getMetaData();
|
||||
final Intent intent = getIntent();
|
||||
if (shouldShowTwoPaneDeepLink(intent)) {
|
||||
launchHomepageForTwoPaneDeepLink(intent);
|
||||
finishAndRemoveTask();
|
||||
return;
|
||||
}
|
||||
|
||||
registerSplitStateObserverForTwoPaneDeepLink();
|
||||
|
||||
final FeatureFactory factory = FeatureFactory.getFactory(this);
|
||||
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
|
||||
@@ -364,6 +362,29 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void registerSplitStateObserverForTwoPaneDeepLink() {
|
||||
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final SplitStateObserver splitStateObserver = new SplitStateObserver(this /* activity*/,
|
||||
true /* listenOnce */,
|
||||
splitInfos -> {
|
||||
if (!splitInfos.isEmpty()) {
|
||||
// It's already in 2-pane and no need to go 2-pane deep link flow.
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldShowTwoPaneDeepLink(getIntent())) {
|
||||
launchHomepageForTwoPaneDeepLink(getIntent());
|
||||
finishAndRemoveTask();
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
getLifecycle().addObserver(splitStateObserver);
|
||||
}
|
||||
|
||||
private boolean isSubSettings(Intent intent) {
|
||||
return this instanceof SubSettings ||
|
||||
intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
|
||||
@@ -413,10 +434,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
}
|
||||
|
||||
private boolean shouldShowTwoPaneDeepLink(Intent intent) {
|
||||
if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only starts trampoline for deep links. Should return false for all the cases that
|
||||
// Settings app starts SettingsActivity or SubSetting by itself.
|
||||
if (intent.getAction() == null) {
|
||||
@@ -434,11 +451,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
return false;
|
||||
}
|
||||
|
||||
if (intent.getBooleanExtra(SettingsHomepageActivity.EXTRA_IS_FROM_SETTINGS_HOMEPAGE,
|
||||
/* defaultValue */ false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TextUtils.equals(intent.getAction(), Intent.ACTION_CREATE_SHORTCUT)) {
|
||||
// Returns false to show full screen for Intent.ACTION_CREATE_SHORTCUT because
|
||||
// - Launcher startActivityForResult for Intent.ACTION_CREATE_SHORTCUT and activity
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.activityembedding;
|
||||
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.util.Consumer;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.window.embedding.SplitController;
|
||||
import androidx.window.embedding.SplitInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** A lifecycle-aware observer listens to active split state. */
|
||||
public class SplitStateObserver implements LifecycleObserver, Consumer<List<SplitInfo>> {
|
||||
|
||||
private final Activity mActivity;
|
||||
private final boolean mListenOnce;
|
||||
private final SplitStateListener mListener;
|
||||
private final SplitController mSplitController;
|
||||
|
||||
public SplitStateObserver(@NonNull Activity activity, boolean listenOnce,
|
||||
@NonNull SplitStateListener listener) {
|
||||
mActivity = activity;
|
||||
mListenOnce = listenOnce;
|
||||
mListener = listener;
|
||||
mSplitController = SplitController.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start lifecycle event.
|
||||
*/
|
||||
@OnLifecycleEvent(ON_START)
|
||||
public void onStart() {
|
||||
mSplitController.addSplitListener(mActivity, ContextCompat.getMainExecutor(mActivity),
|
||||
this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop lifecycle event.
|
||||
*/
|
||||
@OnLifecycleEvent(ON_STOP)
|
||||
public void onStop() {
|
||||
mSplitController.removeSplitListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(List<SplitInfo> splitInfos) {
|
||||
if (mListenOnce) {
|
||||
mSplitController.removeSplitListener(this);
|
||||
}
|
||||
mListener.onSplitInfoChanged(splitInfos);
|
||||
}
|
||||
|
||||
/** This interface makes as class that it wants to listen to {@link SplitInfo} changes. */
|
||||
public interface SplitStateListener {
|
||||
|
||||
/** Receive a set of split info change */
|
||||
void onSplitInfoChanged(List<SplitInfo> splitInfos);
|
||||
}
|
||||
}
|
@@ -63,10 +63,6 @@ public class SettingsHomepageActivity extends FragmentActivity implements
|
||||
|
||||
private static final String TAG = "SettingsHomepageActivity";
|
||||
|
||||
// Additional extra of Settings#ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
|
||||
// Put true value to the intent when startActivity for a deep link intent from this Activity.
|
||||
public static final String EXTRA_IS_FROM_SETTINGS_HOMEPAGE = "is_from_settings_homepage";
|
||||
|
||||
// Additional extra of Settings#ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
|
||||
// Set & get Uri of the Intent separately to prevent failure of Intent#ParseUri.
|
||||
public static final String EXTRA_SETTINGS_LARGE_SCREEN_DEEP_LINK_INTENT_DATA =
|
||||
@@ -268,11 +264,11 @@ public class SettingsHomepageActivity extends FragmentActivity implements
|
||||
// Sender of intent may want to send intent extra data to the destination of targetIntent.
|
||||
targetIntent.replaceExtras(intent);
|
||||
|
||||
targetIntent.putExtra(EXTRA_IS_FROM_SETTINGS_HOMEPAGE, true);
|
||||
targetIntent.putExtra(SettingsActivity.EXTRA_IS_FROM_SLICE, false);
|
||||
|
||||
targetIntent.setData(intent.getParcelableExtra(
|
||||
SettingsHomepageActivity.EXTRA_SETTINGS_LARGE_SCREEN_DEEP_LINK_INTENT_DATA));
|
||||
|
||||
// Set 2-pane pair rule for the deep link page.
|
||||
ActivityEmbeddingRulesController.registerTwoPanePairRule(this,
|
||||
getDeepLinkComponent(),
|
||||
|
Reference in New Issue
Block a user