summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSetup Wizard Team <android-setup-team-eng@google.com>2021-01-18 11:34:18 +0800
committerAlex Li <alexylli@google.com>2021-01-18 06:58:16 +0000
commit1566b59c3c4a54877291db2319f3a727b92c881f (patch)
tree8a3b15e3fb3eee736e6c1bfbe9a84f11906c1c68
parentaea92c40b741ad5936fff31158c19c79e8c7d270 (diff)
downloadsetupdesign-1566b59c3c4a54877291db2319f3a727b92c881f.tar.gz
Import updated Android Setupdesign Library 352327668
Copied from google3/third_party/java_src/android_libs/setupdesign Test: mm Bug:177789946 Included changes: - 352327668 Changes the description of check SDK method to BuildCompa... - 352325088 [BC][Stencil] Make a toast to warning that should use vec... - 351990541 enlarge content area for two-column layout - 351539435 change sdk version check to MessageWarning.isAtLeastS() s... - 351517939 Make the illustration keep playing when doing the transit... PiperOrigin-RevId: 352327668 Change-Id: I0f03a82b02dc5a8a8f6702628e6bcf4c58b57529
-rw-r--r--main/res/layout-land-v30/sud_glif_list_template_content_s.xml4
-rw-r--r--main/res/layout-land-v30/sud_glif_preference_template_content_s.xml4
-rw-r--r--main/res/layout-land-v30/sud_glif_recycler_template_content_s.xml4
-rw-r--r--main/res/layout-land-v30/sud_glif_template_content_s.xml4
-rw-r--r--main/res/values/attrs.xml1
-rw-r--r--main/src/com/google/android/setupdesign/GlifLayout.java4
-rw-r--r--main/src/com/google/android/setupdesign/GlifListLayout.java4
-rw-r--r--main/src/com/google/android/setupdesign/GlifPreferenceLayout.java6
-rw-r--r--main/src/com/google/android/setupdesign/GlifRecyclerLayout.java4
-rw-r--r--main/src/com/google/android/setupdesign/util/BuildCompatUtils.java66
-rw-r--r--main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java24
-rw-r--r--main/src/com/google/android/setupdesign/util/MessageWarning.java49
-rw-r--r--main/src/com/google/android/setupdesign/view/IllustrationVideoView.java29
13 files changed, 126 insertions, 77 deletions
diff --git a/main/res/layout-land-v30/sud_glif_list_template_content_s.xml b/main/res/layout-land-v30/sud_glif_list_template_content_s.xml
index 99b0cce..4e6a228 100644
--- a/main/res/layout-land-v30/sud_glif_list_template_content_s.xml
+++ b/main/res/layout-land-v30/sud_glif_list_template_content_s.xml
@@ -30,7 +30,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
@@ -55,7 +55,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
diff --git a/main/res/layout-land-v30/sud_glif_preference_template_content_s.xml b/main/res/layout-land-v30/sud_glif_preference_template_content_s.xml
index 1335afd..68a1171 100644
--- a/main/res/layout-land-v30/sud_glif_preference_template_content_s.xml
+++ b/main/res/layout-land-v30/sud_glif_preference_template_content_s.xml
@@ -29,7 +29,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
@@ -54,7 +54,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
diff --git a/main/res/layout-land-v30/sud_glif_recycler_template_content_s.xml b/main/res/layout-land-v30/sud_glif_recycler_template_content_s.xml
index 60ca5ef..59f2dfd 100644
--- a/main/res/layout-land-v30/sud_glif_recycler_template_content_s.xml
+++ b/main/res/layout-land-v30/sud_glif_recycler_template_content_s.xml
@@ -31,7 +31,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
@@ -56,7 +56,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
diff --git a/main/res/layout-land-v30/sud_glif_template_content_s.xml b/main/res/layout-land-v30/sud_glif_template_content_s.xml
index 0399e68..b9e490b 100644
--- a/main/res/layout-land-v30/sud_glif_template_content_s.xml
+++ b/main/res/layout-land-v30/sud_glif_template_content_s.xml
@@ -30,7 +30,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
@@ -55,7 +55,7 @@
<LinearLayout
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
diff --git a/main/res/values/attrs.xml b/main/res/values/attrs.xml
index 7262f70..83d10a7 100644
--- a/main/res/values/attrs.xml
+++ b/main/res/values/attrs.xml
@@ -132,6 +132,7 @@
<declare-styleable name="SudIllustrationVideoView">
<attr name="sudVideo" format="reference" />
+ <attr name="sudPauseVideoWhenFinished" format="boolean" />
</declare-styleable>
<declare-styleable name="SudGlifLayout">
diff --git a/main/src/com/google/android/setupdesign/GlifLayout.java b/main/src/com/google/android/setupdesign/GlifLayout.java
index a5aeea8..a461ee5 100644
--- a/main/src/com/google/android/setupdesign/GlifLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifLayout.java
@@ -46,9 +46,9 @@ import com.google.android.setupdesign.template.IllustrationProgressMixin;
import com.google.android.setupdesign.template.ProgressBarMixin;
import com.google.android.setupdesign.template.RequireScrollMixin;
import com.google.android.setupdesign.template.ScrollViewScrollHandlingDelegate;
+import com.google.android.setupdesign.util.BuildCompatUtils;
import com.google.android.setupdesign.util.DescriptionStyler;
import com.google.android.setupdesign.util.LayoutStyler;
-import com.google.android.setupdesign.util.MessageWarning;
import com.google.android.setupdesign.util.PartnerStyleHelper;
/**
@@ -192,7 +192,7 @@ public class GlifLayout extends PartnerCustomizationLayout {
protected View onInflateTemplate(LayoutInflater inflater, @LayoutRes int template) {
if (template == 0) {
// TODO : use "values-land-v31" folder for sud_glif_template_s directly.
- if (MessageWarning.isAtLeastS()) {
+ if (BuildCompatUtils.isAtLeastS()) {
template = R.layout.sud_glif_template_s;
} else {
template = R.layout.sud_glif_template;
diff --git a/main/src/com/google/android/setupdesign/GlifListLayout.java b/main/src/com/google/android/setupdesign/GlifListLayout.java
index 15aa14b..b906f41 100644
--- a/main/src/com/google/android/setupdesign/GlifListLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifListLayout.java
@@ -29,7 +29,7 @@ import android.widget.ListView;
import com.google.android.setupdesign.template.ListMixin;
import com.google.android.setupdesign.template.ListViewScrollHandlingDelegate;
import com.google.android.setupdesign.template.RequireScrollMixin;
-import com.google.android.setupdesign.util.MessageWarning;
+import com.google.android.setupdesign.util.BuildCompatUtils;
/**
* A GLIF themed layout with a ListView. {@code android:entries} can also be used to specify an
@@ -82,7 +82,7 @@ public class GlifListLayout extends GlifLayout {
protected View onInflateTemplate(LayoutInflater inflater, int template) {
if (template == 0) {
// TODO : use "values-land-v31" folder for sud_glif_list_template_s directly.
- if (MessageWarning.isAtLeastS()) {
+ if (BuildCompatUtils.isAtLeastS()) {
template = R.layout.sud_glif_list_template_s;
} else {
template = R.layout.sud_glif_list_template;
diff --git a/main/src/com/google/android/setupdesign/GlifPreferenceLayout.java b/main/src/com/google/android/setupdesign/GlifPreferenceLayout.java
index 166254c..d5c0f69 100644
--- a/main/src/com/google/android/setupdesign/GlifPreferenceLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifPreferenceLayout.java
@@ -24,7 +24,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.setupdesign.template.RecyclerMixin;
-import com.google.android.setupdesign.util.MessageWarning;
+import com.google.android.setupdesign.util.BuildCompatUtils;
/**
* A layout to be used with {@code PreferenceFragment} in v14 support library. This can be specified
@@ -101,7 +101,7 @@ public class GlifPreferenceLayout extends GlifRecyclerLayout {
if (template == 0) {
// TODO : use "values-land-v31" folder for sud_glif_preference_template_s
// directly.
- if (MessageWarning.isAtLeastS()) {
+ if (BuildCompatUtils.isAtLeastS()) {
template = R.layout.sud_glif_preference_template_s;
} else {
template = R.layout.sud_glif_preference_template;
@@ -118,7 +118,7 @@ public class GlifPreferenceLayout extends GlifRecyclerLayout {
RecyclerView recyclerView;
// TODO : use "layout-land-v31" folder for sud_glif_preference_recycler_view
// directly.
- if (MessageWarning.isAtLeastS()) {
+ if (BuildCompatUtils.isAtLeastS()) {
recyclerView =
(RecyclerView)
inflater.inflate(R.layout.sud_glif_preference_recycler_view_s, this, false);
diff --git a/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java b/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java
index 06c34bb..bb9ebb0 100644
--- a/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java
+++ b/main/src/com/google/android/setupdesign/GlifRecyclerLayout.java
@@ -30,7 +30,7 @@ import android.view.ViewGroup;
import com.google.android.setupdesign.template.RecyclerMixin;
import com.google.android.setupdesign.template.RecyclerViewScrollHandlingDelegate;
import com.google.android.setupdesign.template.RequireScrollMixin;
-import com.google.android.setupdesign.util.MessageWarning;
+import com.google.android.setupdesign.util.BuildCompatUtils;
/**
* A GLIF themed layout with a RecyclerView. {@code android:entries} can also be used to specify an
@@ -83,7 +83,7 @@ public class GlifRecyclerLayout extends GlifLayout {
protected View onInflateTemplate(LayoutInflater inflater, int template) {
if (template == 0) {
// TODO : use "values-land-v31" folder for sud_glif_recycler_template_s directly.
- if (MessageWarning.isAtLeastS()) {
+ if (BuildCompatUtils.isAtLeastS()) {
template = R.layout.sud_glif_recycler_template_s;
} else {
template = R.layout.sud_glif_recycler_template;
diff --git a/main/src/com/google/android/setupdesign/util/BuildCompatUtils.java b/main/src/com/google/android/setupdesign/util/BuildCompatUtils.java
new file mode 100644
index 0000000..7174455
--- /dev/null
+++ b/main/src/com/google/android/setupdesign/util/BuildCompatUtils.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2020 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.google.android.setupdesign.util;
+
+import android.os.Build;
+
+/**
+ * An util class to check whether the current OS version is higher or equal to sdk version of
+ * device.
+ */
+public final class BuildCompatUtils {
+
+ /**
+ * Implementation of BuildCompat.isAtLeast*() suitable for use in Setup
+ *
+ * <p>BuildCompat.isAtLeast*() can be changed by Android Release team, and once that is changed it
+ * may take weeks for that to propagate to stable/prerelease/experimental SDKs in Google3. Also it
+ * can be different in all these channels. This can cause random issues, especially with sidecars
+ * (i.e., the code running on R may not know that it runs on R).
+ *
+ * <p>This still should try using BuildCompat.isAtLeastR() as source of truth, but also checking
+ * for VERSION_SDK_INT and VERSION.CODENAME in case when BuildCompat implementation returned
+ * false. Note that both checks should be >= and not = to make sure that when Android version
+ * increases (i.e., from R to S), this does not stop working.
+ *
+ * <p>Supported configurations:
+ *
+ * <ul>
+ * <li>For current Android release: while new API is not finalized yet (CODENAME = "S", SDK_INT
+ * = 30|31)
+ * <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 31)
+ * <li>For next Android release (CODENAME = "T", SDK_INT = 30+)
+ * </ul>
+ *
+ * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available in all
+ * Google3 channels, because it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API
+ * finalization.
+ *
+ * @return Whether the current OS version is higher or equal to S.
+ */
+ public static boolean isAtLeastS() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
+ return false;
+ }
+ return (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 31)
+ || (Build.VERSION.CODENAME.length() == 1
+ && Build.VERSION.CODENAME.charAt(0) >= 'S'
+ && Build.VERSION.CODENAME.charAt(0) <= 'Z');
+ }
+
+ private BuildCompatUtils() {}
+}
diff --git a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
index 6407b5c..cdfebc5 100644
--- a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
+++ b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
@@ -16,9 +16,12 @@
package com.google.android.setupdesign.util;
+import static com.google.android.setupdesign.util.BuildCompatUtils.isAtLeastS;
+
import android.content.Context;
import android.graphics.drawable.VectorDrawable;
import android.os.Build;
+import android.util.Log;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
@@ -26,6 +29,7 @@ import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
@@ -40,8 +44,10 @@ import com.google.android.setupdesign.util.TextViewPartnerStyler.TextPartnerConf
*/
public final class HeaderAreaStyler {
+ private static final String TAG = "HeaderAreaStyler";
+
@VisibleForTesting
- static final String WARNING_TO_USE_DRAWABLE =
+ static final String WARN_TO_USE_DRAWABLE =
"To achieve scaling icon in SetupDesign lib, should use vector drawable icon!!";
/**
@@ -233,15 +239,15 @@ public final class HeaderAreaStyler {
imageView.getViewTreeObserver().removeOnPreDrawListener(this);
// TODO: Remove when Partners all used Drawable icon image and never use
- // un-drawable image in Setup.
- // Should set vector drawable icon rather than non-drawable icon(e.g. PNG)
- if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
- || !(imageView.getDrawable() instanceof VectorDrawable))
- && !(imageView.getDrawable() instanceof VectorDrawableCompat)) {
- // TODO : Use reflection to get ro.debuggable and show toast to warn.
- MessageWarning.makeWarning(WARNING_TO_USE_DRAWABLE);
+ if (isAtLeastS()
+ && !(imageView.getDrawable() instanceof VectorDrawable
+ || imageView.getDrawable() instanceof VectorDrawableCompat)) {
+ if (Build.TYPE.equals("userdebug") || Build.TYPE.equals("eng")) {
+ Toast.makeText(imageView.getContext(), WARN_TO_USE_DRAWABLE, Toast.LENGTH_LONG)
+ .show();
+ }
+ Log.w(TAG, WARN_TO_USE_DRAWABLE);
}
-
return true;
}
});
diff --git a/main/src/com/google/android/setupdesign/util/MessageWarning.java b/main/src/com/google/android/setupdesign/util/MessageWarning.java
deleted file mode 100644
index ca9a93b..0000000
--- a/main/src/com/google/android/setupdesign/util/MessageWarning.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2020 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.google.android.setupdesign.util;
-
-import android.os.Build;
-import android.util.Log;
-
-/** Utilities to warn developer in Android S later debug build. */
-public final class MessageWarning {
-
- private static final String TAG = "ToastWarning";
-
- /**
- * Shows the warning message.
- *
- * @param warningMsg The message to show for warning .
- */
- public static void makeWarning(String warningMsg) {
- if (isAtLeastS()) {
- Log.w(TAG, warningMsg);
- }
- }
-
- public static boolean isAtLeastS() {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
- return false;
- }
- return (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 31)
- || (Build.VERSION.CODENAME.length() == 1
- && Build.VERSION.CODENAME.charAt(0) >= 'S'
- && Build.VERSION.CODENAME.charAt(0) <= 'Z');
- }
-
- private MessageWarning() {}
-}
diff --git a/main/src/com/google/android/setupdesign/view/IllustrationVideoView.java b/main/src/com/google/android/setupdesign/view/IllustrationVideoView.java
index e8253a0..a64642f 100644
--- a/main/src/com/google/android/setupdesign/view/IllustrationVideoView.java
+++ b/main/src/com/google/android/setupdesign/view/IllustrationVideoView.java
@@ -38,6 +38,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.RawRes;
import androidx.annotation.VisibleForTesting;
import com.google.android.setupdesign.R;
+import com.google.android.setupdesign.util.BuildCompatUtils;
import java.io.IOException;
/**
@@ -76,6 +77,8 @@ public class IllustrationVideoView extends TextureView
private boolean prepared;
+ private boolean shouldPauseVideoWhenFinished = true;
+
/**
* The visibility of this view as set by the user. This view combines this with {@link
* #isMediaPlayerLoading} to determine the final visibility.
@@ -95,6 +98,15 @@ public class IllustrationVideoView extends TextureView
final TypedArray a =
context.obtainStyledAttributes(attrs, R.styleable.SudIllustrationVideoView);
final int videoResId = a.getResourceId(R.styleable.SudIllustrationVideoView_sudVideo, 0);
+
+ // TODO: remove the usage of BuildCompatUtils#isAtLeatestS if VERSION_CODE.S is
+ // support by system.
+ if (BuildCompatUtils.isAtLeastS()) {
+ boolean shouldPauseVideo =
+ a.getBoolean(R.styleable.SudIllustrationVideoView_sudPauseVideoWhenFinished, true);
+ setPauseVideoWhenFinished(shouldPauseVideo);
+ }
+
a.recycle();
setVideoResource(videoResId);
@@ -171,6 +183,15 @@ public class IllustrationVideoView extends TextureView
setVideoResource(resId, getContext().getPackageName());
}
+ /**
+ * Sets whether the video pauses during the screen transition.
+ *
+ * @param paused Whether the video pauses.
+ */
+ public void setPauseVideoWhenFinished(boolean paused) {
+ shouldPauseVideoWhenFinished = paused;
+ }
+
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
@@ -326,8 +347,12 @@ public class IllustrationVideoView extends TextureView
@Override
public void stop() {
- if (prepared && mediaPlayer != null) {
- mediaPlayer.pause();
+ if (shouldPauseVideoWhenFinished) {
+ if (prepared && mediaPlayer != null) {
+ mediaPlayer.pause();
+ }
+ } else {
+ // do not pause the media player.
}
}