Add two APIs in SettingsLibActivityEmbedding

Add two APIs

1. isActivityEmbedded() knows whether current activity is
embedded in the Settings app or not.
2. shouldHideBackButton knows whether current activity is
suggested to show back button or not.

Bug: 219000314
Test: Use the api in Settings app, and behavior is correct.
Change-Id: If1d29a8d9bdb896b179275e13de649872a5b94fe
This commit is contained in:
Tsung-Mao Fang
2022-02-11 22:10:43 +08:00
parent c610c3b333
commit 5641d01a98
3 changed files with 35 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ android_library {
static_libs: [
"androidx.annotation_annotation",
"androidx.core_core",
"windowExtLib",
"SettingsLibUtils",
],
sdk_version: "system_current",

View File

@@ -16,8 +16,14 @@
package com.android.settingslib.activityembedding;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.core.os.BuildCompat;
import androidx.window.embedding.SplitController;
import com.android.settingslib.utils.BuildCompatUtils;
@@ -44,6 +50,33 @@ public class ActivityEmbeddingUtils {
return false;
}
/**
* Whether current activity is embedded in the Settings app or not.
*/
public static boolean isActivityEmbedded(Activity activity) {
return SplitController.getInstance().isActivityEmbedded(activity);
}
/**
* Whether current activity is suggested to show back button or not.
*/
public static boolean shouldHideBackButton(Activity activity, boolean isSecondaryLayerPage) {
if (!BuildCompat.isAtLeastT()) {
return false;
}
if (!isSecondaryLayerPage) {
return false;
}
final String shouldHideBackButton = Settings.Global.getString(activity.getContentResolver(),
"settings_hide_secondary_page_back_button_in_two_pane");
if (TextUtils.isEmpty(shouldHideBackButton)
|| TextUtils.equals("true", shouldHideBackButton)) {
return isActivityEmbedded(activity);
}
return false;
}
private ActivityEmbeddingUtils() {
}
}

View File

@@ -48,7 +48,6 @@ android_library {
"SettingsLibCollapsingToolbarBaseActivity",
"SettingsLibTwoTargetPreference",
"SettingsLibSettingsTransition",
"SettingsLibActivityEmbedding",
"SettingsLibButtonPreference",
"setupdesign",
],