Merge "Remove compose:runtime-dispatch" into androidx-main
diff --git a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
index c558ee6..930cf26 100644
--- a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
@@ -138,7 +138,7 @@
val WEAR_WATCHFACE_EDITOR = Version("1.0.0-alpha06")
val WEAR_WATCHFACE_STYLE = Version("1.0.0-alpha06")
val WEBKIT = Version("1.5.0-alpha01")
- val WINDOW = Version("1.0.0-alpha02")
+ val WINDOW = Version("1.0.0-alpha03")
val WINDOW_EXTENSIONS = Version("1.0.0-alpha01")
val WINDOW_SIDECAR = Version("0.1.0-alpha01")
val WORK = Version("2.5.0-rc01")
diff --git a/buildSrc/src/main/kotlin/androidx/build/metalava/MetalavaRunner.kt b/buildSrc/src/main/kotlin/androidx/build/metalava/MetalavaRunner.kt
index c1e5275..49cbaab 100644
--- a/buildSrc/src/main/kotlin/androidx/build/metalava/MetalavaRunner.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/metalava/MetalavaRunner.kt
@@ -110,7 +110,6 @@
// List of checks that have bugs, but should be enabled once fixed.
"GetterSetterNames", // b/135498039
"StaticUtils", // b/135489083
- "AllUpper", // b/135708486
"StartWithLower", // b/135710527
// The list of checks that are API lint warnings and are yet to be enabled
@@ -123,6 +122,7 @@
).joinToString(),
"--error",
listOf(
+ "AllUpper",
"MinMaxConstant",
"TopLevelBuilder",
"BuilderSetStyle",
diff --git a/car/app/app/api/current.txt b/car/app/app/api/current.txt
index c5595b3..4d1fad26 100644
--- a/car/app/app/api/current.txt
+++ b/car/app/app/api/current.txt
@@ -166,10 +166,9 @@
package androidx.car.app.model {
public final class Action {
- method public androidx.car.app.model.CarColor getBackgroundColor();
+ method public androidx.car.app.model.CarColor? getBackgroundColor();
method public androidx.car.app.model.CarIcon? getIcon();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public androidx.car.app.model.CarText? getTitle();
method public int getType();
method public boolean isStandard();
@@ -190,13 +189,7 @@
method public androidx.car.app.model.Action.Builder setTitle(CharSequence);
}
- public final class ActionList {
- method public static androidx.car.app.model.ActionList create(java.util.List<androidx.car.app.model.Action!>);
- method public java.util.List<androidx.car.app.model.Action!> getList();
- }
-
public final class ActionStrip {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method public androidx.car.app.model.Action? getFirstActionOfType(int);
}
@@ -256,7 +249,7 @@
method public static androidx.car.app.model.CarIconSpan create(androidx.car.app.model.CarIcon);
method public static androidx.car.app.model.CarIconSpan create(androidx.car.app.model.CarIcon, int);
method public int getAlignment();
- method public androidx.car.app.model.CarIcon getIcon();
+ method public androidx.car.app.model.CarIcon? getIcon();
field public static final int ALIGN_BASELINE = 1; // 0x1
field public static final int ALIGN_BOTTOM = 0; // 0x0
field public static final int ALIGN_CENTER = 2; // 0x2
@@ -306,7 +299,7 @@
public final class DistanceSpan extends androidx.car.app.model.CarSpan {
method public static androidx.car.app.model.DistanceSpan create(androidx.car.app.model.Distance);
- method public androidx.car.app.model.Distance getDistance();
+ method public androidx.car.app.model.Distance? getDistance();
}
public final class DurationSpan extends androidx.car.app.model.CarSpan {
@@ -317,16 +310,15 @@
public final class ForegroundCarColorSpan extends androidx.car.app.model.CarSpan {
method public static androidx.car.app.model.ForegroundCarColorSpan create(androidx.car.app.model.CarColor);
- method public androidx.car.app.model.CarColor getColor();
+ method public androidx.car.app.model.CarColor? getColor();
}
public final class GridItem implements androidx.car.app.model.Item {
method public androidx.car.app.model.CarIcon? getImage();
method public int getImageType();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public androidx.car.app.model.CarText? getText();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
method public boolean isLoading();
field public static final int IMAGE_TYPE_ICON = 1; // 0x1
field public static final int IMAGE_TYPE_LARGE = 2; // 0x2
@@ -369,9 +361,7 @@
method public java.util.List<androidx.car.app.model.Item!> getItems();
method public androidx.car.app.model.CarText? getNoItemsMessage();
method public androidx.car.app.model.OnItemVisibilityChangedDelegate? getOnItemVisibilityChangedDelegate();
- method @Deprecated public androidx.car.app.model.OnItemVisibilityChangedListenerWrapper? getOnItemsVisibilityChangedListener();
method public androidx.car.app.model.OnSelectedDelegate? getOnSelectedDelegate();
- method @Deprecated public androidx.car.app.model.OnSelectedListenerWrapper? getOnSelectedListener();
method public int getSelectedIndex();
}
@@ -416,12 +406,11 @@
}
public final class MessageTemplate implements androidx.car.app.model.Template {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method public androidx.car.app.model.CarText? getDebugMessage();
method public androidx.car.app.model.Action? getHeaderAction();
method public androidx.car.app.model.CarIcon? getIcon();
- method public androidx.car.app.model.CarText getMessage();
+ method public androidx.car.app.model.CarText? getMessage();
method public androidx.car.app.model.CarText? getTitle();
}
@@ -429,7 +418,6 @@
ctor public MessageTemplate.Builder(CharSequence);
method public androidx.car.app.model.MessageTemplate.Builder addAction(androidx.car.app.model.Action);
method public androidx.car.app.model.MessageTemplate build();
- method @Deprecated public androidx.car.app.model.MessageTemplate.Builder setActionList(java.util.List<androidx.car.app.model.Action!>);
method public androidx.car.app.model.MessageTemplate.Builder setDebugMessage(Throwable);
method public androidx.car.app.model.MessageTemplate.Builder setDebugMessage(String);
method public androidx.car.app.model.MessageTemplate.Builder setHeaderAction(androidx.car.app.model.Action);
@@ -453,10 +441,6 @@
method public void sendCheckedChange(boolean, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnCheckedChangeListenerWrapper {
- method @Deprecated public void onCheckedChange(boolean, androidx.car.app.OnDoneCallback);
- }
-
public interface OnClickDelegate {
method public boolean isParkedOnly();
method public void sendClick(androidx.car.app.OnDoneCallback);
@@ -466,29 +450,15 @@
method public void onClick();
}
- @Deprecated public interface OnClickListenerWrapper {
- method @Deprecated public boolean isParkedOnly();
- method @Deprecated public void onClick(androidx.car.app.OnDoneCallback);
- }
-
public interface OnItemVisibilityChangedDelegate {
method public void sendItemVisibilityChanged(int, int, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnItemVisibilityChangedListenerWrapper {
- method @Deprecated public void onItemVisibilityChanged(int, int, androidx.car.app.OnDoneCallback);
- }
-
public interface OnSelectedDelegate {
method public void sendSelected(int, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnSelectedListenerWrapper {
- method @Deprecated public void onSelected(int, androidx.car.app.OnDoneCallback);
- }
-
public final class Pane {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method @Deprecated public java.util.List<androidx.car.app.model.Row!> getRowList();
method public java.util.List<androidx.car.app.model.Row!> getRows();
@@ -500,14 +470,13 @@
method public androidx.car.app.model.Pane.Builder addAction(androidx.car.app.model.Action);
method public androidx.car.app.model.Pane.Builder addRow(androidx.car.app.model.Row);
method public androidx.car.app.model.Pane build();
- method @Deprecated public androidx.car.app.model.Pane.Builder setActionList(java.util.List<androidx.car.app.model.Action!>);
method public androidx.car.app.model.Pane.Builder setLoading(boolean);
}
public final class PaneTemplate implements androidx.car.app.model.Template {
method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.Action? getHeaderAction();
- method public androidx.car.app.model.Pane getPane();
+ method public androidx.car.app.model.Pane? getPane();
method public androidx.car.app.model.CarText? getTitle();
}
@@ -525,7 +494,7 @@
}
public final class Place {
- method public androidx.car.app.model.CarLocation getLocation();
+ method public androidx.car.app.model.CarLocation? getLocation();
method public androidx.car.app.model.PlaceMarker? getMarker();
}
@@ -577,12 +546,11 @@
public final class Row implements androidx.car.app.model.Item {
method public androidx.car.app.model.CarIcon? getImage();
- method public androidx.car.app.model.Metadata getMetadata();
+ method public androidx.car.app.model.Metadata? getMetadata();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public int getRowImageType();
method public java.util.List<androidx.car.app.model.CarText!> getTexts();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
method public androidx.car.app.model.Toggle? getToggle();
method public boolean isBrowsable();
method public androidx.car.app.model.Row row();
@@ -610,18 +578,12 @@
method public void sendSearchTextChanged(String, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface SearchCallbackWrapper {
- method @Deprecated public void onSearchSubmitted(String, androidx.car.app.OnDoneCallback);
- method @Deprecated public void onSearchTextChanged(String, androidx.car.app.OnDoneCallback);
- }
-
public final class SearchTemplate implements androidx.car.app.model.Template {
method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.Action? getHeaderAction();
method public String? getInitialSearchText();
method public androidx.car.app.model.ItemList? getItemList();
- method @Deprecated public androidx.car.app.model.SearchCallbackWrapper getSearchCallback();
- method public androidx.car.app.model.SearchCallbackDelegate getSearchCallbackDelegate();
+ method public androidx.car.app.model.SearchCallbackDelegate? getSearchCallbackDelegate();
method public String? getSearchHint();
method public boolean isLoading();
method public boolean isShowKeyboardByDefault();
@@ -647,8 +609,8 @@
public final class SectionedItemList {
method @Deprecated public static androidx.car.app.model.SectionedItemList create(androidx.car.app.model.ItemList, androidx.car.app.model.CarText);
method public static androidx.car.app.model.SectionedItemList create(androidx.car.app.model.ItemList, CharSequence);
- method public androidx.car.app.model.CarText getHeader();
- method public androidx.car.app.model.ItemList getItemList();
+ method public androidx.car.app.model.CarText? getHeader();
+ method public androidx.car.app.model.ItemList? getItemList();
}
public interface Template {
@@ -666,7 +628,7 @@
method public int getCurrentTaskStep();
method public String getId();
method public androidx.car.app.model.Template getTemplate();
- method public java.util.List<androidx.car.app.model.TemplateInfo!>? getTemplateInfosForScreenStack();
+ method public java.util.List<androidx.car.app.model.TemplateInfo!> getTemplateInfosForScreenStack();
method public boolean isRefresh();
method public void setCurrentTaskStep(int);
method public void setId(String);
@@ -677,8 +639,7 @@
}
public final class Toggle {
- method public androidx.car.app.model.OnCheckedChangeDelegate getOnCheckedChangeDelegate();
- method @Deprecated public androidx.car.app.model.OnCheckedChangeListenerWrapper getOnCheckedChangeListener();
+ method public androidx.car.app.model.OnCheckedChangeDelegate? getOnCheckedChangeDelegate();
method public boolean isChecked();
}
@@ -823,7 +784,7 @@
public final class MessageInfo implements androidx.car.app.navigation.model.NavigationTemplate.NavigationInfo {
method public androidx.car.app.model.CarIcon? getImage();
method public androidx.car.app.model.CarText? getText();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
}
public static final class MessageInfo.Builder {
@@ -835,7 +796,7 @@
}
public final class NavigationTemplate implements androidx.car.app.model.Template {
- method public androidx.car.app.model.ActionStrip getActionStrip();
+ method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.CarColor? getBackgroundColor();
method public androidx.car.app.navigation.model.TravelEstimate? getDestinationTravelEstimate();
method public androidx.car.app.navigation.model.NavigationTemplate.NavigationInfo? getNavigationInfo();
@@ -928,9 +889,9 @@
public final class TravelEstimate {
method public androidx.car.app.model.DateTimeWithZone? getArrivalTimeAtDestination();
- method public androidx.car.app.model.Distance getRemainingDistance();
- method public androidx.car.app.model.CarColor getRemainingDistanceColor();
- method public androidx.car.app.model.CarColor getRemainingTimeColor();
+ method public androidx.car.app.model.Distance? getRemainingDistance();
+ method public androidx.car.app.model.CarColor? getRemainingDistanceColor();
+ method public androidx.car.app.model.CarColor? getRemainingTimeColor();
method public long getRemainingTimeSeconds();
field public static final long REMAINING_TIME_UNKNOWN = -1L; // 0xffffffffffffffffL
}
diff --git a/car/app/app/api/public_plus_experimental_current.txt b/car/app/app/api/public_plus_experimental_current.txt
index c5595b3..4d1fad26 100644
--- a/car/app/app/api/public_plus_experimental_current.txt
+++ b/car/app/app/api/public_plus_experimental_current.txt
@@ -166,10 +166,9 @@
package androidx.car.app.model {
public final class Action {
- method public androidx.car.app.model.CarColor getBackgroundColor();
+ method public androidx.car.app.model.CarColor? getBackgroundColor();
method public androidx.car.app.model.CarIcon? getIcon();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public androidx.car.app.model.CarText? getTitle();
method public int getType();
method public boolean isStandard();
@@ -190,13 +189,7 @@
method public androidx.car.app.model.Action.Builder setTitle(CharSequence);
}
- public final class ActionList {
- method public static androidx.car.app.model.ActionList create(java.util.List<androidx.car.app.model.Action!>);
- method public java.util.List<androidx.car.app.model.Action!> getList();
- }
-
public final class ActionStrip {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method public androidx.car.app.model.Action? getFirstActionOfType(int);
}
@@ -256,7 +249,7 @@
method public static androidx.car.app.model.CarIconSpan create(androidx.car.app.model.CarIcon);
method public static androidx.car.app.model.CarIconSpan create(androidx.car.app.model.CarIcon, int);
method public int getAlignment();
- method public androidx.car.app.model.CarIcon getIcon();
+ method public androidx.car.app.model.CarIcon? getIcon();
field public static final int ALIGN_BASELINE = 1; // 0x1
field public static final int ALIGN_BOTTOM = 0; // 0x0
field public static final int ALIGN_CENTER = 2; // 0x2
@@ -306,7 +299,7 @@
public final class DistanceSpan extends androidx.car.app.model.CarSpan {
method public static androidx.car.app.model.DistanceSpan create(androidx.car.app.model.Distance);
- method public androidx.car.app.model.Distance getDistance();
+ method public androidx.car.app.model.Distance? getDistance();
}
public final class DurationSpan extends androidx.car.app.model.CarSpan {
@@ -317,16 +310,15 @@
public final class ForegroundCarColorSpan extends androidx.car.app.model.CarSpan {
method public static androidx.car.app.model.ForegroundCarColorSpan create(androidx.car.app.model.CarColor);
- method public androidx.car.app.model.CarColor getColor();
+ method public androidx.car.app.model.CarColor? getColor();
}
public final class GridItem implements androidx.car.app.model.Item {
method public androidx.car.app.model.CarIcon? getImage();
method public int getImageType();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public androidx.car.app.model.CarText? getText();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
method public boolean isLoading();
field public static final int IMAGE_TYPE_ICON = 1; // 0x1
field public static final int IMAGE_TYPE_LARGE = 2; // 0x2
@@ -369,9 +361,7 @@
method public java.util.List<androidx.car.app.model.Item!> getItems();
method public androidx.car.app.model.CarText? getNoItemsMessage();
method public androidx.car.app.model.OnItemVisibilityChangedDelegate? getOnItemVisibilityChangedDelegate();
- method @Deprecated public androidx.car.app.model.OnItemVisibilityChangedListenerWrapper? getOnItemsVisibilityChangedListener();
method public androidx.car.app.model.OnSelectedDelegate? getOnSelectedDelegate();
- method @Deprecated public androidx.car.app.model.OnSelectedListenerWrapper? getOnSelectedListener();
method public int getSelectedIndex();
}
@@ -416,12 +406,11 @@
}
public final class MessageTemplate implements androidx.car.app.model.Template {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method public androidx.car.app.model.CarText? getDebugMessage();
method public androidx.car.app.model.Action? getHeaderAction();
method public androidx.car.app.model.CarIcon? getIcon();
- method public androidx.car.app.model.CarText getMessage();
+ method public androidx.car.app.model.CarText? getMessage();
method public androidx.car.app.model.CarText? getTitle();
}
@@ -429,7 +418,6 @@
ctor public MessageTemplate.Builder(CharSequence);
method public androidx.car.app.model.MessageTemplate.Builder addAction(androidx.car.app.model.Action);
method public androidx.car.app.model.MessageTemplate build();
- method @Deprecated public androidx.car.app.model.MessageTemplate.Builder setActionList(java.util.List<androidx.car.app.model.Action!>);
method public androidx.car.app.model.MessageTemplate.Builder setDebugMessage(Throwable);
method public androidx.car.app.model.MessageTemplate.Builder setDebugMessage(String);
method public androidx.car.app.model.MessageTemplate.Builder setHeaderAction(androidx.car.app.model.Action);
@@ -453,10 +441,6 @@
method public void sendCheckedChange(boolean, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnCheckedChangeListenerWrapper {
- method @Deprecated public void onCheckedChange(boolean, androidx.car.app.OnDoneCallback);
- }
-
public interface OnClickDelegate {
method public boolean isParkedOnly();
method public void sendClick(androidx.car.app.OnDoneCallback);
@@ -466,29 +450,15 @@
method public void onClick();
}
- @Deprecated public interface OnClickListenerWrapper {
- method @Deprecated public boolean isParkedOnly();
- method @Deprecated public void onClick(androidx.car.app.OnDoneCallback);
- }
-
public interface OnItemVisibilityChangedDelegate {
method public void sendItemVisibilityChanged(int, int, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnItemVisibilityChangedListenerWrapper {
- method @Deprecated public void onItemVisibilityChanged(int, int, androidx.car.app.OnDoneCallback);
- }
-
public interface OnSelectedDelegate {
method public void sendSelected(int, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnSelectedListenerWrapper {
- method @Deprecated public void onSelected(int, androidx.car.app.OnDoneCallback);
- }
-
public final class Pane {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method @Deprecated public java.util.List<androidx.car.app.model.Row!> getRowList();
method public java.util.List<androidx.car.app.model.Row!> getRows();
@@ -500,14 +470,13 @@
method public androidx.car.app.model.Pane.Builder addAction(androidx.car.app.model.Action);
method public androidx.car.app.model.Pane.Builder addRow(androidx.car.app.model.Row);
method public androidx.car.app.model.Pane build();
- method @Deprecated public androidx.car.app.model.Pane.Builder setActionList(java.util.List<androidx.car.app.model.Action!>);
method public androidx.car.app.model.Pane.Builder setLoading(boolean);
}
public final class PaneTemplate implements androidx.car.app.model.Template {
method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.Action? getHeaderAction();
- method public androidx.car.app.model.Pane getPane();
+ method public androidx.car.app.model.Pane? getPane();
method public androidx.car.app.model.CarText? getTitle();
}
@@ -525,7 +494,7 @@
}
public final class Place {
- method public androidx.car.app.model.CarLocation getLocation();
+ method public androidx.car.app.model.CarLocation? getLocation();
method public androidx.car.app.model.PlaceMarker? getMarker();
}
@@ -577,12 +546,11 @@
public final class Row implements androidx.car.app.model.Item {
method public androidx.car.app.model.CarIcon? getImage();
- method public androidx.car.app.model.Metadata getMetadata();
+ method public androidx.car.app.model.Metadata? getMetadata();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public int getRowImageType();
method public java.util.List<androidx.car.app.model.CarText!> getTexts();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
method public androidx.car.app.model.Toggle? getToggle();
method public boolean isBrowsable();
method public androidx.car.app.model.Row row();
@@ -610,18 +578,12 @@
method public void sendSearchTextChanged(String, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface SearchCallbackWrapper {
- method @Deprecated public void onSearchSubmitted(String, androidx.car.app.OnDoneCallback);
- method @Deprecated public void onSearchTextChanged(String, androidx.car.app.OnDoneCallback);
- }
-
public final class SearchTemplate implements androidx.car.app.model.Template {
method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.Action? getHeaderAction();
method public String? getInitialSearchText();
method public androidx.car.app.model.ItemList? getItemList();
- method @Deprecated public androidx.car.app.model.SearchCallbackWrapper getSearchCallback();
- method public androidx.car.app.model.SearchCallbackDelegate getSearchCallbackDelegate();
+ method public androidx.car.app.model.SearchCallbackDelegate? getSearchCallbackDelegate();
method public String? getSearchHint();
method public boolean isLoading();
method public boolean isShowKeyboardByDefault();
@@ -647,8 +609,8 @@
public final class SectionedItemList {
method @Deprecated public static androidx.car.app.model.SectionedItemList create(androidx.car.app.model.ItemList, androidx.car.app.model.CarText);
method public static androidx.car.app.model.SectionedItemList create(androidx.car.app.model.ItemList, CharSequence);
- method public androidx.car.app.model.CarText getHeader();
- method public androidx.car.app.model.ItemList getItemList();
+ method public androidx.car.app.model.CarText? getHeader();
+ method public androidx.car.app.model.ItemList? getItemList();
}
public interface Template {
@@ -666,7 +628,7 @@
method public int getCurrentTaskStep();
method public String getId();
method public androidx.car.app.model.Template getTemplate();
- method public java.util.List<androidx.car.app.model.TemplateInfo!>? getTemplateInfosForScreenStack();
+ method public java.util.List<androidx.car.app.model.TemplateInfo!> getTemplateInfosForScreenStack();
method public boolean isRefresh();
method public void setCurrentTaskStep(int);
method public void setId(String);
@@ -677,8 +639,7 @@
}
public final class Toggle {
- method public androidx.car.app.model.OnCheckedChangeDelegate getOnCheckedChangeDelegate();
- method @Deprecated public androidx.car.app.model.OnCheckedChangeListenerWrapper getOnCheckedChangeListener();
+ method public androidx.car.app.model.OnCheckedChangeDelegate? getOnCheckedChangeDelegate();
method public boolean isChecked();
}
@@ -823,7 +784,7 @@
public final class MessageInfo implements androidx.car.app.navigation.model.NavigationTemplate.NavigationInfo {
method public androidx.car.app.model.CarIcon? getImage();
method public androidx.car.app.model.CarText? getText();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
}
public static final class MessageInfo.Builder {
@@ -835,7 +796,7 @@
}
public final class NavigationTemplate implements androidx.car.app.model.Template {
- method public androidx.car.app.model.ActionStrip getActionStrip();
+ method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.CarColor? getBackgroundColor();
method public androidx.car.app.navigation.model.TravelEstimate? getDestinationTravelEstimate();
method public androidx.car.app.navigation.model.NavigationTemplate.NavigationInfo? getNavigationInfo();
@@ -928,9 +889,9 @@
public final class TravelEstimate {
method public androidx.car.app.model.DateTimeWithZone? getArrivalTimeAtDestination();
- method public androidx.car.app.model.Distance getRemainingDistance();
- method public androidx.car.app.model.CarColor getRemainingDistanceColor();
- method public androidx.car.app.model.CarColor getRemainingTimeColor();
+ method public androidx.car.app.model.Distance? getRemainingDistance();
+ method public androidx.car.app.model.CarColor? getRemainingDistanceColor();
+ method public androidx.car.app.model.CarColor? getRemainingTimeColor();
method public long getRemainingTimeSeconds();
field public static final long REMAINING_TIME_UNKNOWN = -1L; // 0xffffffffffffffffL
}
diff --git a/car/app/app/api/restricted_current.txt b/car/app/app/api/restricted_current.txt
index c5595b3..4d1fad26 100644
--- a/car/app/app/api/restricted_current.txt
+++ b/car/app/app/api/restricted_current.txt
@@ -166,10 +166,9 @@
package androidx.car.app.model {
public final class Action {
- method public androidx.car.app.model.CarColor getBackgroundColor();
+ method public androidx.car.app.model.CarColor? getBackgroundColor();
method public androidx.car.app.model.CarIcon? getIcon();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public androidx.car.app.model.CarText? getTitle();
method public int getType();
method public boolean isStandard();
@@ -190,13 +189,7 @@
method public androidx.car.app.model.Action.Builder setTitle(CharSequence);
}
- public final class ActionList {
- method public static androidx.car.app.model.ActionList create(java.util.List<androidx.car.app.model.Action!>);
- method public java.util.List<androidx.car.app.model.Action!> getList();
- }
-
public final class ActionStrip {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method public androidx.car.app.model.Action? getFirstActionOfType(int);
}
@@ -256,7 +249,7 @@
method public static androidx.car.app.model.CarIconSpan create(androidx.car.app.model.CarIcon);
method public static androidx.car.app.model.CarIconSpan create(androidx.car.app.model.CarIcon, int);
method public int getAlignment();
- method public androidx.car.app.model.CarIcon getIcon();
+ method public androidx.car.app.model.CarIcon? getIcon();
field public static final int ALIGN_BASELINE = 1; // 0x1
field public static final int ALIGN_BOTTOM = 0; // 0x0
field public static final int ALIGN_CENTER = 2; // 0x2
@@ -306,7 +299,7 @@
public final class DistanceSpan extends androidx.car.app.model.CarSpan {
method public static androidx.car.app.model.DistanceSpan create(androidx.car.app.model.Distance);
- method public androidx.car.app.model.Distance getDistance();
+ method public androidx.car.app.model.Distance? getDistance();
}
public final class DurationSpan extends androidx.car.app.model.CarSpan {
@@ -317,16 +310,15 @@
public final class ForegroundCarColorSpan extends androidx.car.app.model.CarSpan {
method public static androidx.car.app.model.ForegroundCarColorSpan create(androidx.car.app.model.CarColor);
- method public androidx.car.app.model.CarColor getColor();
+ method public androidx.car.app.model.CarColor? getColor();
}
public final class GridItem implements androidx.car.app.model.Item {
method public androidx.car.app.model.CarIcon? getImage();
method public int getImageType();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public androidx.car.app.model.CarText? getText();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
method public boolean isLoading();
field public static final int IMAGE_TYPE_ICON = 1; // 0x1
field public static final int IMAGE_TYPE_LARGE = 2; // 0x2
@@ -369,9 +361,7 @@
method public java.util.List<androidx.car.app.model.Item!> getItems();
method public androidx.car.app.model.CarText? getNoItemsMessage();
method public androidx.car.app.model.OnItemVisibilityChangedDelegate? getOnItemVisibilityChangedDelegate();
- method @Deprecated public androidx.car.app.model.OnItemVisibilityChangedListenerWrapper? getOnItemsVisibilityChangedListener();
method public androidx.car.app.model.OnSelectedDelegate? getOnSelectedDelegate();
- method @Deprecated public androidx.car.app.model.OnSelectedListenerWrapper? getOnSelectedListener();
method public int getSelectedIndex();
}
@@ -416,12 +406,11 @@
}
public final class MessageTemplate implements androidx.car.app.model.Template {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method public androidx.car.app.model.CarText? getDebugMessage();
method public androidx.car.app.model.Action? getHeaderAction();
method public androidx.car.app.model.CarIcon? getIcon();
- method public androidx.car.app.model.CarText getMessage();
+ method public androidx.car.app.model.CarText? getMessage();
method public androidx.car.app.model.CarText? getTitle();
}
@@ -429,7 +418,6 @@
ctor public MessageTemplate.Builder(CharSequence);
method public androidx.car.app.model.MessageTemplate.Builder addAction(androidx.car.app.model.Action);
method public androidx.car.app.model.MessageTemplate build();
- method @Deprecated public androidx.car.app.model.MessageTemplate.Builder setActionList(java.util.List<androidx.car.app.model.Action!>);
method public androidx.car.app.model.MessageTemplate.Builder setDebugMessage(Throwable);
method public androidx.car.app.model.MessageTemplate.Builder setDebugMessage(String);
method public androidx.car.app.model.MessageTemplate.Builder setHeaderAction(androidx.car.app.model.Action);
@@ -453,10 +441,6 @@
method public void sendCheckedChange(boolean, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnCheckedChangeListenerWrapper {
- method @Deprecated public void onCheckedChange(boolean, androidx.car.app.OnDoneCallback);
- }
-
public interface OnClickDelegate {
method public boolean isParkedOnly();
method public void sendClick(androidx.car.app.OnDoneCallback);
@@ -466,29 +450,15 @@
method public void onClick();
}
- @Deprecated public interface OnClickListenerWrapper {
- method @Deprecated public boolean isParkedOnly();
- method @Deprecated public void onClick(androidx.car.app.OnDoneCallback);
- }
-
public interface OnItemVisibilityChangedDelegate {
method public void sendItemVisibilityChanged(int, int, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnItemVisibilityChangedListenerWrapper {
- method @Deprecated public void onItemVisibilityChanged(int, int, androidx.car.app.OnDoneCallback);
- }
-
public interface OnSelectedDelegate {
method public void sendSelected(int, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface OnSelectedListenerWrapper {
- method @Deprecated public void onSelected(int, androidx.car.app.OnDoneCallback);
- }
-
public final class Pane {
- method @Deprecated public java.util.List<androidx.car.app.model.Action!> getActionList();
method public java.util.List<androidx.car.app.model.Action!> getActions();
method @Deprecated public java.util.List<androidx.car.app.model.Row!> getRowList();
method public java.util.List<androidx.car.app.model.Row!> getRows();
@@ -500,14 +470,13 @@
method public androidx.car.app.model.Pane.Builder addAction(androidx.car.app.model.Action);
method public androidx.car.app.model.Pane.Builder addRow(androidx.car.app.model.Row);
method public androidx.car.app.model.Pane build();
- method @Deprecated public androidx.car.app.model.Pane.Builder setActionList(java.util.List<androidx.car.app.model.Action!>);
method public androidx.car.app.model.Pane.Builder setLoading(boolean);
}
public final class PaneTemplate implements androidx.car.app.model.Template {
method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.Action? getHeaderAction();
- method public androidx.car.app.model.Pane getPane();
+ method public androidx.car.app.model.Pane? getPane();
method public androidx.car.app.model.CarText? getTitle();
}
@@ -525,7 +494,7 @@
}
public final class Place {
- method public androidx.car.app.model.CarLocation getLocation();
+ method public androidx.car.app.model.CarLocation? getLocation();
method public androidx.car.app.model.PlaceMarker? getMarker();
}
@@ -577,12 +546,11 @@
public final class Row implements androidx.car.app.model.Item {
method public androidx.car.app.model.CarIcon? getImage();
- method public androidx.car.app.model.Metadata getMetadata();
+ method public androidx.car.app.model.Metadata? getMetadata();
method public androidx.car.app.model.OnClickDelegate? getOnClickDelegate();
- method @Deprecated public androidx.car.app.model.OnClickListenerWrapper? getOnClickListener();
method public int getRowImageType();
method public java.util.List<androidx.car.app.model.CarText!> getTexts();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
method public androidx.car.app.model.Toggle? getToggle();
method public boolean isBrowsable();
method public androidx.car.app.model.Row row();
@@ -610,18 +578,12 @@
method public void sendSearchTextChanged(String, androidx.car.app.OnDoneCallback);
}
- @Deprecated public interface SearchCallbackWrapper {
- method @Deprecated public void onSearchSubmitted(String, androidx.car.app.OnDoneCallback);
- method @Deprecated public void onSearchTextChanged(String, androidx.car.app.OnDoneCallback);
- }
-
public final class SearchTemplate implements androidx.car.app.model.Template {
method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.Action? getHeaderAction();
method public String? getInitialSearchText();
method public androidx.car.app.model.ItemList? getItemList();
- method @Deprecated public androidx.car.app.model.SearchCallbackWrapper getSearchCallback();
- method public androidx.car.app.model.SearchCallbackDelegate getSearchCallbackDelegate();
+ method public androidx.car.app.model.SearchCallbackDelegate? getSearchCallbackDelegate();
method public String? getSearchHint();
method public boolean isLoading();
method public boolean isShowKeyboardByDefault();
@@ -647,8 +609,8 @@
public final class SectionedItemList {
method @Deprecated public static androidx.car.app.model.SectionedItemList create(androidx.car.app.model.ItemList, androidx.car.app.model.CarText);
method public static androidx.car.app.model.SectionedItemList create(androidx.car.app.model.ItemList, CharSequence);
- method public androidx.car.app.model.CarText getHeader();
- method public androidx.car.app.model.ItemList getItemList();
+ method public androidx.car.app.model.CarText? getHeader();
+ method public androidx.car.app.model.ItemList? getItemList();
}
public interface Template {
@@ -666,7 +628,7 @@
method public int getCurrentTaskStep();
method public String getId();
method public androidx.car.app.model.Template getTemplate();
- method public java.util.List<androidx.car.app.model.TemplateInfo!>? getTemplateInfosForScreenStack();
+ method public java.util.List<androidx.car.app.model.TemplateInfo!> getTemplateInfosForScreenStack();
method public boolean isRefresh();
method public void setCurrentTaskStep(int);
method public void setId(String);
@@ -677,8 +639,7 @@
}
public final class Toggle {
- method public androidx.car.app.model.OnCheckedChangeDelegate getOnCheckedChangeDelegate();
- method @Deprecated public androidx.car.app.model.OnCheckedChangeListenerWrapper getOnCheckedChangeListener();
+ method public androidx.car.app.model.OnCheckedChangeDelegate? getOnCheckedChangeDelegate();
method public boolean isChecked();
}
@@ -823,7 +784,7 @@
public final class MessageInfo implements androidx.car.app.navigation.model.NavigationTemplate.NavigationInfo {
method public androidx.car.app.model.CarIcon? getImage();
method public androidx.car.app.model.CarText? getText();
- method public androidx.car.app.model.CarText getTitle();
+ method public androidx.car.app.model.CarText? getTitle();
}
public static final class MessageInfo.Builder {
@@ -835,7 +796,7 @@
}
public final class NavigationTemplate implements androidx.car.app.model.Template {
- method public androidx.car.app.model.ActionStrip getActionStrip();
+ method public androidx.car.app.model.ActionStrip? getActionStrip();
method public androidx.car.app.model.CarColor? getBackgroundColor();
method public androidx.car.app.navigation.model.TravelEstimate? getDestinationTravelEstimate();
method public androidx.car.app.navigation.model.NavigationTemplate.NavigationInfo? getNavigationInfo();
@@ -928,9 +889,9 @@
public final class TravelEstimate {
method public androidx.car.app.model.DateTimeWithZone? getArrivalTimeAtDestination();
- method public androidx.car.app.model.Distance getRemainingDistance();
- method public androidx.car.app.model.CarColor getRemainingDistanceColor();
- method public androidx.car.app.model.CarColor getRemainingTimeColor();
+ method public androidx.car.app.model.Distance? getRemainingDistance();
+ method public androidx.car.app.model.CarColor? getRemainingDistanceColor();
+ method public androidx.car.app.model.CarColor? getRemainingTimeColor();
method public long getRemainingTimeSeconds();
field public static final long REMAINING_TIME_UNKNOWN = -1L; // 0xffffffffffffffffL
}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/Action.java b/car/app/app/src/main/java/androidx/car/app/model/Action.java
index ef1b261..4bcb33f 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/Action.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/Action.java
@@ -127,10 +127,6 @@
private final CarIcon mIcon;
@Keep
private final CarColor mBackgroundColor;
- @SuppressWarnings("deprecation")
- @Keep
- @Nullable
- private final OnClickListenerWrapper mListener;
@Keep
@Nullable
private final OnClickDelegate mOnClickDelegate;
@@ -159,7 +155,7 @@
/**
* Returns the {@link CarColor} used for the background color of the action.
*/
- @NonNull
+ @Nullable
public CarColor getBackgroundColor() {
return mBackgroundColor;
}
@@ -176,17 +172,6 @@
}
/**
- * @deprecated use {@link #getOnClickDelegate} instead.
- */
- // TODO(b/177591476): remove after host references have been cleaned up.
- @SuppressWarnings("deprecation")
- @Deprecated
- @Nullable
- public OnClickListenerWrapper getOnClickListener() {
- return mListener;
- }
-
- /**
* Returns the {@link OnClickDelegate} that should be used for this action.
*/
@Nullable
@@ -228,7 +213,6 @@
mTitle = null;
mIcon = null;
mBackgroundColor = DEFAULT;
- mListener = null;
mOnClickDelegate = null;
mType = type;
}
@@ -237,7 +221,6 @@
mTitle = builder.mTitle;
mIcon = builder.mIcon;
mBackgroundColor = builder.mBackgroundColor;
- mListener = builder.mListener;
mOnClickDelegate = builder.mOnClickDelegate;
mType = builder.mType;
}
@@ -247,7 +230,6 @@
mTitle = null;
mIcon = null;
mBackgroundColor = DEFAULT;
- mListener = null;
mOnClickDelegate = null;
mType = TYPE_CUSTOM;
}
@@ -285,9 +267,6 @@
CarText mTitle;
@Nullable
CarIcon mIcon;
- @SuppressWarnings("deprecation")
- @Nullable
- OnClickListenerWrapper mListener;
@Nullable
OnClickDelegate mOnClickDelegate;
CarColor mBackgroundColor = DEFAULT;
@@ -341,9 +320,8 @@
* @throws NullPointerException if {@code listener} is {@code null}
*/
@NonNull
- @SuppressLint("ExecutorRegistration")
+ @SuppressLint({"MissingGetterMatchingBuilder", "ExecutorRegistration"})
public Builder setOnClickListener(@NonNull OnClickListener listener) {
- mListener = OnClickListenerWrapperImpl.create(requireNonNull(listener));
mOnClickDelegate = OnClickDelegateImpl.create(listener);
return this;
}
@@ -389,7 +367,7 @@
}
if ((mType == TYPE_APP_ICON || mType == TYPE_BACK)) {
- if (mListener != null) {
+ if (mOnClickDelegate != null) {
throw new IllegalStateException(
"An on-click listener can't be set on the standard back or app-icon "
+ "action");
@@ -415,7 +393,6 @@
*
* @throws NullPointerException if {@code icon} is {@code null}
*/
- @SuppressWarnings("deprecation")
Builder(@NonNull Action action) {
// Note: at the moment, the only standard actions that exist (APP_ICON and BACK) can't
// be customized with a title or a listener. For that reason, this constructor is not
@@ -424,7 +401,6 @@
mTitle = action.getTitle();
mIcon = action.getIcon();
mBackgroundColor = action.getBackgroundColor();
- mListener = action.getOnClickListener();
mOnClickDelegate = action.getOnClickDelegate();
mType = action.getType();
}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/ActionList.java b/car/app/app/src/main/java/androidx/car/app/model/ActionList.java
deleted file mode 100644
index 7a68796..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/ActionList.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import static java.util.Objects.requireNonNull;
-
-import androidx.annotation.Keep;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.car.app.utils.CollectionUtils;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Represents a simple list of {@link Action} models.
- *
- * <p>This model is intended for internal and host use only, as a transport artifact for
- * homogeneous lists of {@link Action} items.
- */
-public final class ActionList {
- @Keep
- private final List<Action> mList;
-
- /**
- * Returns the list of {@link Action}'s.
- */
- @NonNull
- public List<Action> getList() {
- return mList;
- }
-
- /**
- * Creates an {@link ActionList} instance based on the list of {@link Action}'s.
- */
- @NonNull
- public static ActionList create(@NonNull List<Action> list) {
- requireNonNull(list);
- for (Action action : list) {
- if (action == null) {
- throw new IllegalArgumentException("Disallowed null action found in action list");
- }
- }
- return new ActionList(list);
- }
-
- @Override
- @NonNull
- public String toString() {
- return mList.toString();
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(mList);
- }
-
- @Override
- public boolean equals(@Nullable Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof ActionList)) {
- return false;
- }
- ActionList otherActionList = (ActionList) other;
-
- return Objects.equals(mList, otherActionList.mList);
- }
-
- private ActionList(List<Action> list) {
- this.mList = CollectionUtils.unmodifiableCopy(list);
- }
-
- /** For serialization. */
- private ActionList() {
- mList = Collections.emptyList();
- }
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/ActionStrip.java b/car/app/app/src/main/java/androidx/car/app/model/ActionStrip.java
index 042d143..5f853ae 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/ActionStrip.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/ActionStrip.java
@@ -47,22 +47,10 @@
/**
* Returns the list of {@link Action}'s.
- *
- * @deprecated use {@link #getActions()} instead.
- */
- // TODO(b/177276260): remove once {@link #getActions()} is used in the host.
- @Deprecated
- @NonNull
- public List<Action> getActionList() {
- return getActions();
- }
-
- /**
- * Returns the list of {@link Action}'s.
*/
@NonNull
public List<Action> getActions() {
- return mActions;
+ return CollectionUtils.emptyIfNull(mActions);
}
/**
diff --git a/car/app/app/src/main/java/androidx/car/app/model/CarIconSpan.java b/car/app/app/src/main/java/androidx/car/app/model/CarIconSpan.java
index cd542c1..1c91d363 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/CarIconSpan.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/CarIconSpan.java
@@ -151,9 +151,9 @@
mAlignment = ALIGN_BASELINE;
}
- @NonNull
+ @Nullable
public CarIcon getIcon() {
- return requireNonNull(mIcon);
+ return mIcon;
}
@Alignment
diff --git a/car/app/app/src/main/java/androidx/car/app/model/CarText.java b/car/app/app/src/main/java/androidx/car/app/model/CarText.java
index d764b1c..7762286 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/CarText.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/CarText.java
@@ -78,8 +78,8 @@
*/
@NonNull
public CharSequence toCharSequence() {
- SpannableString spannableString = new SpannableString(mText);
- for (SpanWrapper spanWrapper : mSpans) {
+ SpannableString spannableString = new SpannableString(mText == null ? "" : mText);
+ for (SpanWrapper spanWrapper : CollectionUtils.emptyIfNull(mSpans)) {
spannableString.setSpan(
spanWrapper.getCarSpan(),
spanWrapper.getStart(),
diff --git a/car/app/app/src/main/java/androidx/car/app/model/DistanceSpan.java b/car/app/app/src/main/java/androidx/car/app/model/DistanceSpan.java
index ab42230..a931389 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/DistanceSpan.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/DistanceSpan.java
@@ -76,9 +76,9 @@
mDistance = null;
}
- @NonNull
+ @Nullable
public Distance getDistance() {
- return requireNonNull(mDistance);
+ return mDistance;
}
@NonNull
diff --git a/car/app/app/src/main/java/androidx/car/app/model/ForegroundCarColorSpan.java b/car/app/app/src/main/java/androidx/car/app/model/ForegroundCarColorSpan.java
index 01d8057..ca11229 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/ForegroundCarColorSpan.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/ForegroundCarColorSpan.java
@@ -50,7 +50,7 @@
@Keep
private final CarColor mCarColor;
- @NonNull
+ @Nullable
public CarColor getColor() {
return mCarColor;
}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/GridItem.java b/car/app/app/src/main/java/androidx/car/app/model/GridItem.java
index d987e82..b6552d3 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/GridItem.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/GridItem.java
@@ -85,10 +85,6 @@
@Keep
@GridItemImageType
private final int mImageType;
- @SuppressWarnings("deprecation")
- @Keep
- @Nullable
- private final OnClickListenerWrapper mOnClickListener;
@Keep
@Nullable
private final OnClickDelegate mOnClickDelegate;
@@ -99,9 +95,9 @@
}
/** Returns the title of the grid item. */
- @NonNull
+ @Nullable
public CarText getTitle() {
- return requireNonNull(mTitle);
+ return mTitle;
}
/** Returns the list of text below the title. */
@@ -123,20 +119,6 @@
}
/**
- * Returns the {@link OnClickListener} to be called back when the grid item is clicked, or
- * {@code null} if the grid item is non-clickable.
- *
- * @deprecated use {@link #getOnClickDelegate} instead.
- */
- // TODO(b/177591476): remove after host references have been cleaned up.
- @SuppressWarnings("deprecation")
- @Deprecated
- @Nullable
- public OnClickListenerWrapper getOnClickListener() {
- return mOnClickListener;
- }
-
- /**
* Returns the {@link OnClickDelegate} to be called back when the grid item is clicked, or
* {@code null} if the grid item is non-clickable.
*/
@@ -188,7 +170,6 @@
mText = builder.mText;
mImage = builder.mImage;
mImageType = builder.mImageType;
- mOnClickListener = builder.mOnClickListener;
mOnClickDelegate = builder.mOnClickDelegate;
}
@@ -199,7 +180,6 @@
mText = null;
mImage = null;
mImageType = IMAGE_TYPE_LARGE;
- mOnClickListener = null;
mOnClickDelegate = null;
}
@@ -213,9 +193,6 @@
CarIcon mImage;
@GridItemImageType
int mImageType = IMAGE_TYPE_LARGE;
- @SuppressWarnings("deprecation")
- @Nullable
- OnClickListenerWrapper mOnClickListener;
@Nullable
OnClickDelegate mOnClickDelegate;
boolean mIsLoading;
@@ -319,10 +296,8 @@
* @throws NullPointerException if {@code onClickListener} is {@code null}.
*/
@NonNull
- @SuppressLint("ExecutorRegistration")
+ @SuppressLint({"MissingGetterMatchingBuilder", "ExecutorRegistration"})
public Builder setOnClickListener(@NonNull OnClickListener onClickListener) {
- mOnClickListener =
- OnClickListenerWrapperImpl.create(requireNonNull(onClickListener));
mOnClickDelegate = OnClickDelegateImpl.create(onClickListener);
return this;
}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/ItemList.java b/car/app/app/src/main/java/androidx/car/app/model/ItemList.java
index dc5524a..0bd9c1f 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/ItemList.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/ItemList.java
@@ -75,17 +75,9 @@
private final int mSelectedIndex;
@Keep
private final List<Item> mItems;
- @SuppressWarnings("deprecation")
- @Keep
- @Nullable
- private final OnSelectedListenerWrapper mOnSelectedListener;
@Keep
@Nullable
private final OnSelectedDelegate mOnSelectedDelegate;
- @SuppressWarnings("deprecation")
- @Keep
- @Nullable
- private final OnItemVisibilityChangedListenerWrapper mOnItemVisibilityChangedListener;
@Keep
@Nullable
private final OnItemVisibilityChangedDelegate mOnItemVisibilityChangedDelegate;
@@ -99,21 +91,7 @@
}
/**
- * Returns the {@link OnSelectedListenerWrapper} to be called when when an item is selected
- * by the user, or {@code null} is the list is non-selectable.
- *
- * @deprecated use {@link #getOnSelectedDelegate()} instead.
- */
- // TODO(b/177591476): remove after host references have been cleaned up.
- @Deprecated
- @SuppressWarnings("deprecation")
- @Nullable
- public OnSelectedListenerWrapper getOnSelectedListener() {
- return mOnSelectedListener;
- }
-
- /**
- * Returns the {@link OnSelectedListenerWrapper} to be called when when an item is selected
+ * Returns the {@link OnSelectedDelegate} to be called when when an item is selected
* by the user, or {@code null} is the list is non-selectable.
*/
@Nullable
@@ -128,20 +106,6 @@
}
/**
- * Returns the {@link OnItemVisibilityChangedListenerWrapper} to be called when the visible
- * items in the list changes.
- *
- * @deprecated use {@link #getOnItemVisibilityChangedDelegate()} instead.
- */
- // TODO(b/177591476): remove after host references have been cleaned up.
- @Deprecated
- @SuppressWarnings("deprecation")
- @Nullable
- public OnItemVisibilityChangedListenerWrapper getOnItemsVisibilityChangedListener() {
- return mOnItemVisibilityChangedListener;
- }
-
- /**
* Returns the {@link OnItemVisibilityChangedDelegate} to be called when the visible
* items in the list changes.
*/
@@ -155,7 +119,7 @@
*/
@NonNull
public List<Item> getItems() {
- return mItems;
+ return CollectionUtils.emptyIfNull(mItems);
}
/**
@@ -167,7 +131,7 @@
@Deprecated
@NonNull
public List<Item> getItemList() {
- return mItems;
+ return CollectionUtils.emptyIfNull(mItems);
}
@Override
@@ -215,9 +179,7 @@
mSelectedIndex = builder.mSelectedIndex;
mItems = CollectionUtils.unmodifiableCopy(builder.mItems);
mNoItemsMessage = builder.mNoItemsMessage;
- mOnSelectedListener = builder.mOnSelectedListener;
mOnSelectedDelegate = builder.mOnSelectedDelegate;
- mOnItemVisibilityChangedListener = builder.mOnItemVisibilityChangedListener;
mOnItemVisibilityChangedDelegate = builder.mOnItemVisibilityChangedDelegate;
}
@@ -226,15 +188,13 @@
mSelectedIndex = 0;
mItems = Collections.emptyList();
mNoItemsMessage = null;
- mOnSelectedListener = null;
mOnSelectedDelegate = null;
- mOnItemVisibilityChangedListener = null;
mOnItemVisibilityChangedDelegate = null;
}
@Nullable
- static OnClickDelegate getOnClickListener(Item item) {
+ static OnClickDelegate getOnClickDelegate(Item item) {
if (item instanceof Row) {
return ((Row) item).getOnClickDelegate();
} else if (item instanceof GridItem) {
@@ -257,14 +217,8 @@
public static final class Builder {
final List<Item> mItems = new ArrayList<>();
int mSelectedIndex;
- @SuppressWarnings("deprecation")
- @Nullable
- OnSelectedListenerWrapper mOnSelectedListener;
@Nullable
OnSelectedDelegate mOnSelectedDelegate;
- @SuppressWarnings("deprecation")
- @Nullable
- OnItemVisibilityChangedListenerWrapper mOnItemVisibilityChangedListener;
@Nullable
OnItemVisibilityChangedDelegate mOnItemVisibilityChangedDelegate;
@Nullable
@@ -280,11 +234,9 @@
* @throws NullPointerException if {@code itemVisibilityChangedListener} is {@code null}
*/
@NonNull
- @SuppressLint("ExecutorRegistration")
+ @SuppressLint({"MissingGetterMatchingBuilder", "ExecutorRegistration"})
public Builder setOnItemsVisibilityChangedListener(
@NonNull OnItemVisibilityChangedListener itemVisibilityChangedListener) {
- mOnItemVisibilityChangedListener = OnItemVisibilityChangedListenerWrapperImpl.create(
- requireNonNull(itemVisibilityChangedListener));
mOnItemVisibilityChangedDelegate = OnItemVisibilityChangedDelegateImpl.create(
itemVisibilityChangedListener);
return this;
@@ -308,10 +260,8 @@
* @see #setSelectedIndex(int)
*/
@NonNull
- @SuppressLint("ExecutorRegistration")
+ @SuppressLint({"MissingGetterMatchingBuilder", "ExecutorRegistration"})
public Builder setOnSelectedListener(@NonNull OnSelectedListener onSelectedListener) {
- mOnSelectedListener =
- OnSelectedListenerWrapperImpl.create(requireNonNull(onSelectedListener));
mOnSelectedDelegate = OnSelectedDelegateImpl.create(onSelectedListener);
return this;
}
@@ -370,7 +320,7 @@
*/
@NonNull
public ItemList build() {
- if (mOnSelectedListener != null) {
+ if (mOnSelectedDelegate != null) {
int listSize = mItems.size();
if (listSize == 0) {
throw new IllegalStateException("A selectable list cannot be empty");
@@ -385,7 +335,7 @@
// Check that no items have disallowed elements if the list is selectable.
for (Item item : mItems) {
- if (getOnClickListener(item) != null) {
+ if (getOnClickDelegate(item) != null) {
throw new IllegalStateException(
"Items that belong to selectable lists can't have an "
+ "onClickListener. Use the OnSelectedListener of the list "
diff --git a/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java b/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java
index 75dd1e1..2adbe26 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java
@@ -98,12 +98,12 @@
@Deprecated
@NonNull
public List<SectionedItemList> getSectionLists() {
- return mSectionedLists;
+ return CollectionUtils.emptyIfNull(mSectionedLists);
}
@NonNull
public List<SectionedItemList> getSectionedLists() {
- return mSectionedLists;
+ return CollectionUtils.emptyIfNull(mSectionedLists);
}
@Nullable
diff --git a/car/app/app/src/main/java/androidx/car/app/model/MessageTemplate.java b/car/app/app/src/main/java/androidx/car/app/model/MessageTemplate.java
index 4e8fd51..bb1b0b2 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/MessageTemplate.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/MessageTemplate.java
@@ -71,9 +71,9 @@
return mHeaderAction;
}
- @NonNull
+ @Nullable
public CarText getMessage() {
- return Objects.requireNonNull(mMessage);
+ return mMessage;
}
@Nullable
@@ -86,19 +86,9 @@
return mIcon;
}
- /**
- * @deprecated use {@link #getActions()} instead.
- */
- // TODO(b/177276260): remove once {@link #getActions()} is used in the host.
- @Deprecated
- @NonNull
- public List<Action> getActionList() {
- return getActions();
- }
-
@NonNull
public List<Action> getActions() {
- return mActionList;
+ return CollectionUtils.emptyIfNull(mActionList);
}
@NonNull
@@ -262,29 +252,6 @@
}
/**
- * Sets a list of {@link Action}s to display along with the message.
- *
- * <p>Any actions above the maximum limit of 2 will be ignored.
- *
- * @throws NullPointerException if {@code actions} is {@code null}.
- * @deprecated use {@link #addAction(Action)} instead.
- */
- // TODO(b/177276260): remove once {@link #addAction(Action)} is used in the host.
- @Deprecated
- @NonNull
- public Builder setActionList(@NonNull List<Action> actions) {
- requireNonNull(actions);
- for (Action action : actions) {
- if (action == null) {
- throw new IllegalArgumentException(
- "Disallowed null action found in action list");
- }
- addAction(action);
- }
- return this;
- }
-
- /**
* Adds an {@link Action} to display along with the message.
*
* <p>Any actions above the maximum limit of 2 will be ignored.
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnCheckedChangeListenerWrapper.java b/car/app/app/src/main/java/androidx/car/app/model/OnCheckedChangeListenerWrapper.java
deleted file mode 100644
index 87cea60..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnCheckedChangeListenerWrapper.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import androidx.annotation.NonNull;
-import androidx.car.app.OnDoneCallback;
-
-/**
- * A host-side interface for reporting to clients that the checked state has changed.
- *
- * @deprecated use {@link OnCheckedChangeDelegate} instead.
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@Deprecated
-public interface OnCheckedChangeListenerWrapper {
- /**
- * Notifies that checked state has changed.
- *
- * @param isChecked the updated checked state.
- * @param callback the {@link OnDoneCallback} to trigger when the client finishes handling
- * the event.
- */
- void onCheckedChange(boolean isChecked, @NonNull OnDoneCallback callback);
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnCheckedChangeListenerWrapperImpl.java b/car/app/app/src/main/java/androidx/car/app/model/OnCheckedChangeListenerWrapperImpl.java
deleted file mode 100644
index d8fd6659..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnCheckedChangeListenerWrapperImpl.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import static androidx.annotation.RestrictTo.Scope.LIBRARY;
-
-import android.annotation.SuppressLint;
-import android.os.RemoteException;
-
-import androidx.annotation.Keep;
-import androidx.annotation.NonNull;
-import androidx.annotation.RestrictTo;
-import androidx.car.app.IOnDoneCallback;
-import androidx.car.app.OnDoneCallback;
-import androidx.car.app.model.Toggle.OnCheckedChangeListener;
-import androidx.car.app.utils.RemoteUtils;
-
-/**
- * Implementation class for {@link OnCheckedChangeListenerWrapper}.
- *
- * @hide
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@SuppressWarnings("deprecation")
-@RestrictTo(LIBRARY)
-public final class OnCheckedChangeListenerWrapperImpl implements OnCheckedChangeListenerWrapper {
-
- @Keep
- private final IOnCheckedChangeListener mStub;
-
- @Override
- public void onCheckedChange(boolean isChecked, @NonNull OnDoneCallback callback) {
- try {
- mStub.onCheckedChange(isChecked,
- RemoteUtils.createOnDoneCallbackStub(callback));
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-
- private OnCheckedChangeListenerWrapperImpl(@NonNull OnCheckedChangeListener listener) {
- mStub = new OnCheckedChangeListenerStub(listener);
- }
-
- /** For serialization. */
- private OnCheckedChangeListenerWrapperImpl() {
- mStub = null;
- }
-
- @NonNull
- // This listener relates to UI event and is expected to be triggered on the main thread.
- @SuppressLint("ExecutorRegistration")
- static OnCheckedChangeListenerWrapper create(@NonNull OnCheckedChangeListener listener) {
- return new OnCheckedChangeListenerWrapperImpl(listener);
- }
-
- @Keep // We need to keep these stub for Bundler serialization logic.
- private static class OnCheckedChangeListenerStub extends IOnCheckedChangeListener.Stub {
- private final OnCheckedChangeListener mListener;
-
- OnCheckedChangeListenerStub(OnCheckedChangeListener listener) {
- this.mListener = listener;
- }
-
- @Override
- public void onCheckedChange(boolean isChecked, IOnDoneCallback callback) {
- RemoteUtils.dispatchHostCall(
- () -> mListener.onCheckedChange(isChecked), callback,
- "onCheckedChange");
- }
- }
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnClickListenerWrapper.java b/car/app/app/src/main/java/androidx/car/app/model/OnClickListenerWrapper.java
deleted file mode 100644
index 3a2184d..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnClickListenerWrapper.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import androidx.annotation.NonNull;
-import androidx.car.app.OnDoneCallback;
-
-/**
- * A host-side interface for reporting click to clients.
- *
- * @deprecated use {@link OnClickDelegate} instead.
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@Deprecated
-public interface OnClickListenerWrapper {
- /**
- * Indicates if the click listener is for parked-only scenarios.
- */
- boolean isParkedOnly();
-
- /**
- * Notifies that a click happened.
- *
- * @param callback the {@link OnDoneCallback} to trigger when the client finishes handling
- * the event.
- */
- void onClick(@NonNull OnDoneCallback callback);
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnClickListenerWrapperImpl.java b/car/app/app/src/main/java/androidx/car/app/model/OnClickListenerWrapperImpl.java
deleted file mode 100644
index 845691f..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnClickListenerWrapperImpl.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import static androidx.annotation.RestrictTo.Scope.LIBRARY;
-
-import android.annotation.SuppressLint;
-import android.os.RemoteException;
-
-import androidx.annotation.Keep;
-import androidx.annotation.NonNull;
-import androidx.annotation.RestrictTo;
-import androidx.car.app.IOnDoneCallback;
-import androidx.car.app.OnDoneCallback;
-import androidx.car.app.utils.RemoteUtils;
-
-/**
- * Implementation class for {@link OnClickListenerWrapper} to allow IPC for click-related events.
- *
- * @hide
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@SuppressWarnings("deprecation")
-@RestrictTo(LIBRARY)
-public final class OnClickListenerWrapperImpl implements OnClickListenerWrapper {
-
- @Keep
- private final boolean mIsParkedOnly;
- @Keep
- private final IOnClickListener mListener;
-
- /**
- * Whether the click listener is for parked-only scenarios.
- */
- @Override
- public boolean isParkedOnly() {
- return mIsParkedOnly;
- }
-
- @Override
- public void onClick(@NonNull OnDoneCallback callback) {
- try {
- mListener.onClick(RemoteUtils.createOnDoneCallbackStub(callback));
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-
- @NonNull
- // This listener relates to UI event and is expected to be triggered on the main thread.
- @SuppressLint("ExecutorRegistration")
- static OnClickListenerWrapper create(@NonNull OnClickListener listener) {
- return new OnClickListenerWrapperImpl(
- listener,
- listener instanceof ParkedOnlyOnClickListener);
- }
-
- private OnClickListenerWrapperImpl(@NonNull OnClickListener listener,
- boolean isParkedOnly) {
- this.mListener = new OnClickListenerStub(listener);
- this.mIsParkedOnly = isParkedOnly;
- }
-
- /** For serialization. */
- private OnClickListenerWrapperImpl() {
- mListener = null;
- mIsParkedOnly = false;
- }
-
- @Keep // We need to keep these stub for Bundler serialization logic.
- private static class OnClickListenerStub extends IOnClickListener.Stub {
- private final OnClickListener mOnClickListener;
-
- OnClickListenerStub(OnClickListener onClickListener) {
- this.mOnClickListener = onClickListener;
- }
-
- @Override
- public void onClick(IOnDoneCallback callback) {
- RemoteUtils.dispatchHostCall(mOnClickListener::onClick, callback, "onClick");
- }
- }
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnItemVisibilityChangedListenerWrapper.java b/car/app/app/src/main/java/androidx/car/app/model/OnItemVisibilityChangedListenerWrapper.java
deleted file mode 100644
index 949c445..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnItemVisibilityChangedListenerWrapper.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import androidx.annotation.NonNull;
-import androidx.car.app.OnDoneCallback;
-
-/**
- * A host-side interface for reporting to clients that the visibility state has changed.
- *
- * @deprecated use {@link OnItemVisibilityChangedDelegate} instead.
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@Deprecated
-public interface OnItemVisibilityChangedListenerWrapper {
- /**
- * Notifies that the items in the list within the specified indices have become visible.
- *
- * <p>The start index is inclusive, and the end index is exclusive. For example, if only the
- * first item in a list is visible, the start and end indices would be 0 and 1,
- * respectively. If no items are visible, the indices will be set to -1.
- *
- * @param startIndex the index (inclusive) of the first visible element, or -1 if no items
- * are visible.
- * @param endIndex the index (exclusive) of the last visible element, or -1 if no items
- * are visible.
- * @param callback the {@link OnDoneCallback} to trigger when the client finishes handling
- * the event.
- */
- void onItemVisibilityChanged(int startIndex, int endIndex, @NonNull OnDoneCallback callback);
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnItemVisibilityChangedListenerWrapperImpl.java b/car/app/app/src/main/java/androidx/car/app/model/OnItemVisibilityChangedListenerWrapperImpl.java
deleted file mode 100644
index c1982f4..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnItemVisibilityChangedListenerWrapperImpl.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import static androidx.annotation.RestrictTo.Scope.LIBRARY;
-
-import android.annotation.SuppressLint;
-import android.os.RemoteException;
-
-import androidx.annotation.Keep;
-import androidx.annotation.NonNull;
-import androidx.annotation.RestrictTo;
-import androidx.car.app.IOnDoneCallback;
-import androidx.car.app.OnDoneCallback;
-import androidx.car.app.model.ItemList.OnItemVisibilityChangedListener;
-import androidx.car.app.utils.RemoteUtils;
-
-/**
- * Implementation class for {@link OnItemVisibilityChangedListenerWrapper}.
- *
- * @hide
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@SuppressWarnings("deprecation")
-@RestrictTo(LIBRARY)
-public final class OnItemVisibilityChangedListenerWrapperImpl implements
- OnItemVisibilityChangedListenerWrapper {
-
- @Keep
- private final IOnItemVisibilityChangedListener mStub;
-
- @Override
- public void onItemVisibilityChanged(int startIndex, int rightIndex,
- @NonNull OnDoneCallback callback) {
- try {
- mStub.onItemVisibilityChanged(startIndex, rightIndex,
- RemoteUtils.createOnDoneCallbackStub(callback));
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-
- private OnItemVisibilityChangedListenerWrapperImpl(
- @NonNull OnItemVisibilityChangedListener listener) {
- mStub = new OnItemVisibilityChangedListenerStub(listener);
- }
-
- /** For serialization. */
- private OnItemVisibilityChangedListenerWrapperImpl() {
- mStub = null;
- }
-
- @NonNull
- // This listener relates to UI event and is expected to be triggered on the main thread.
- @SuppressLint("ExecutorRegistration")
- static OnItemVisibilityChangedListenerWrapper create(
- @NonNull OnItemVisibilityChangedListener listener) {
- return new OnItemVisibilityChangedListenerWrapperImpl(listener);
- }
-
- /** Stub class for the {@link IOnItemVisibilityChangedListener} interface. */
- @Keep // We need to keep these stub for Bundler serialization logic.
- private static class OnItemVisibilityChangedListenerStub
- extends IOnItemVisibilityChangedListener.Stub {
- private final OnItemVisibilityChangedListener mListener;
-
- OnItemVisibilityChangedListenerStub(
- OnItemVisibilityChangedListener listener) {
- this.mListener = listener;
- }
-
- @Override
- public void onItemVisibilityChanged(
- int startIndexInclusive, int endIndexExclusive, IOnDoneCallback callback) {
- RemoteUtils.dispatchHostCall(
- () -> mListener.onItemVisibilityChanged(
- startIndexInclusive, endIndexExclusive),
- callback,
- "onItemVisibilityChanged");
- }
- }
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnSelectedListenerWrapper.java b/car/app/app/src/main/java/androidx/car/app/model/OnSelectedListenerWrapper.java
deleted file mode 100644
index e3b61ce..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnSelectedListenerWrapper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import androidx.annotation.NonNull;
-import androidx.car.app.OnDoneCallback;
-
-/**
- * A host-side interface for reporting to clients that an item was selected.
- *
- * @deprecated use {@link OnSelectedDelegate} instead.
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@Deprecated
-public interface OnSelectedListenerWrapper {
- /**
- * Notifies that an item was selected.
- *
- * <p>This event is called even if the selection did not change, for example, if the user
- * selected an already selected item.
- *
- * @param selectedIndex the index of the selected item.
- * @param callback the {@link OnDoneCallback} to trigger when the client finishes handling
- * the event.
- */
- void onSelected(int selectedIndex, @NonNull OnDoneCallback callback);
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/OnSelectedListenerWrapperImpl.java b/car/app/app/src/main/java/androidx/car/app/model/OnSelectedListenerWrapperImpl.java
deleted file mode 100644
index 8ff7485..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/OnSelectedListenerWrapperImpl.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import static androidx.annotation.RestrictTo.Scope.LIBRARY;
-
-import android.annotation.SuppressLint;
-import android.os.RemoteException;
-
-import androidx.annotation.Keep;
-import androidx.annotation.NonNull;
-import androidx.annotation.RestrictTo;
-import androidx.car.app.IOnDoneCallback;
-import androidx.car.app.OnDoneCallback;
-import androidx.car.app.model.ItemList.OnSelectedListener;
-import androidx.car.app.utils.RemoteUtils;
-
-/**
- * Implementation class for {@link OnSelectedListenerWrapper}.
- *
- * @hide
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@SuppressWarnings("deprecation")
-@RestrictTo(LIBRARY)
-public final class OnSelectedListenerWrapperImpl implements OnSelectedListenerWrapper {
-
- @Keep
- private final IOnSelectedListener mStub;
-
- @Override
- public void onSelected(int selectedIndex, @NonNull OnDoneCallback callback) {
- try {
- mStub.onSelected(selectedIndex,
- RemoteUtils.createOnDoneCallbackStub(callback));
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-
- private OnSelectedListenerWrapperImpl(@NonNull OnSelectedListener listener) {
- mStub = new OnSelectedListenerStub(listener);
- }
-
- /** For serialization. */
- private OnSelectedListenerWrapperImpl() {
- mStub = null;
- }
-
- @NonNull
- // This listener relates to UI event and is expected to be triggered on the main thread.
- @SuppressLint("ExecutorRegistration")
- static OnSelectedListenerWrapper create(@NonNull OnSelectedListener listener) {
- return new OnSelectedListenerWrapperImpl(listener);
- }
-
- @Keep // We need to keep these stub for Bundler serialization logic.
- private static class OnSelectedListenerStub extends IOnSelectedListener.Stub {
- private final OnSelectedListener mListener;
-
- OnSelectedListenerStub(OnSelectedListener listener) {
- this.mListener = listener;
- }
-
- @Override
- public void onSelected(int index, IOnDoneCallback callback) {
- RemoteUtils.dispatchHostCall(
- () -> mListener.onSelected(index), callback, "onSelectedListener");
- }
- }
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/Pane.java b/car/app/app/src/main/java/androidx/car/app/model/Pane.java
index 951b4e0..8b1bfd5 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/Pane.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/Pane.java
@@ -42,22 +42,10 @@
/**
* Returns the list of {@link Action}s displayed alongside the {@link Row}s in this pane.
- *
- * @deprecated use {@link #getActions()} instead.
- */
- // TODO(b/177276260): remove once {@link #getActions()} is used in the host.
- @Deprecated
- @NonNull
- public List<Action> getActionList() {
- return getActions();
- }
-
- /**
- * Returns the list of {@link Action}s displayed alongside the {@link Row}s in this pane.
*/
@NonNull
public List<Action> getActions() {
- return mActionList;
+ return CollectionUtils.emptyIfNull(mActionList);
}
/**
@@ -65,7 +53,7 @@
*/
@NonNull
public List<Row> getRows() {
- return mRows;
+ return CollectionUtils.emptyIfNull(mRows);
}
/**
@@ -77,7 +65,7 @@
@Deprecated
@NonNull
public List<Row> getRowList() {
- return mRows;
+ return CollectionUtils.emptyIfNull(mRows);
}
/**
@@ -165,29 +153,6 @@
}
/**
- * Sets multiple {@link Action}s to display alongside the rows in the pane.
- *
- * <p>By default, no actions are displayed.
- *
- * @throws NullPointerException if {@code actions} is {@code null}.
- * @deprecated use {@link #addAction(Action)} instead.
- */
- // TODO(b/177276260): remove once {@link #addAction(Action)} is used in the host.
- @Deprecated
- @NonNull
- public Builder setActionList(@NonNull List<Action> actions) {
- requireNonNull(actions);
- for (Action action : actions) {
- if (action == null) {
- throw new IllegalArgumentException(
- "Disallowed null action found in action list");
- }
- addAction(action);
- }
- return this;
- }
-
- /**
* Adds an {@link Action} to display alongside the rows in the pane.
*
* <p>By default, no actions are displayed.
diff --git a/car/app/app/src/main/java/androidx/car/app/model/PaneTemplate.java b/car/app/app/src/main/java/androidx/car/app/model/PaneTemplate.java
index fff72bb..4d9de4e 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/PaneTemplate.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/PaneTemplate.java
@@ -69,9 +69,9 @@
return mHeaderAction;
}
- @NonNull
+ @Nullable
public Pane getPane() {
- return requireNonNull(mPane);
+ return mPane;
}
@Nullable
diff --git a/car/app/app/src/main/java/androidx/car/app/model/Place.java b/car/app/app/src/main/java/androidx/car/app/model/Place.java
index 1bc8736..190ab06 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/Place.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/Place.java
@@ -41,9 +41,9 @@
/**
* @return the {@link CarLocation} set for this Place instance.
*/
- @NonNull
+ @Nullable
public CarLocation getLocation() {
- return requireNonNull(mLocation);
+ return mLocation;
}
@Override
diff --git a/car/app/app/src/main/java/androidx/car/app/model/Row.java b/car/app/app/src/main/java/androidx/car/app/model/Row.java
index 3ca7ef7..648c994 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/Row.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/Row.java
@@ -98,10 +98,6 @@
@Keep
@Nullable
private final Toggle mToggle;
- @SuppressWarnings("deprecation")
- @Keep
- @Nullable
- private final OnClickListenerWrapper mOnClickListener;
@Keep
@Nullable
private final OnClickDelegate mOnClickDelegate;
@@ -114,16 +110,15 @@
private final int mRowImageType;
/** Returns the title of the row. */
- @NonNull
+ @Nullable
public CarText getTitle() {
- return requireNonNull(mTitle);
+ return mTitle;
}
/** Returns the list of text below the title. */
@NonNull
public List<CarText> getTexts() {
- Objects.requireNonNull(mTexts);
- return mTexts;
+ return CollectionUtils.emptyIfNull(mTexts);
}
/** Returns the image of the row. */
@@ -159,20 +154,6 @@
/**
* Returns the {@link OnClickListener} to be called back when the row is clicked, or {@code
* null} if the row is non-clickable.
- *
- * @deprecated use {@link #getOnClickDelegate} instead.
- */
- // TODO(b/177591476): remove after host references have been cleaned up.
- @SuppressWarnings("deprecation")
- @Deprecated
- @Nullable
- public OnClickListenerWrapper getOnClickListener() {
- return mOnClickListener;
- }
-
- /**
- * Returns the {@link OnClickListener} to be called back when the row is clicked, or {@code
- * null} if the row is non-clickable.
*/
@Nullable
public OnClickDelegate getOnClickDelegate() {
@@ -182,7 +163,7 @@
/**
* Returns the {@link Metadata} associated with the row.
*/
- @NonNull
+ @Nullable
public Metadata getMetadata() {
return mMetadata;
}
@@ -260,7 +241,6 @@
mTexts = CollectionUtils.unmodifiableCopy(builder.mTexts);
mImage = builder.mImage;
mToggle = builder.mToggle;
- mOnClickListener = builder.mOnClickListener;
mOnClickDelegate = builder.mOnClickDelegate;
mMetadata = builder.mMetadata;
mIsBrowsable = builder.mIsBrowsable;
@@ -273,7 +253,6 @@
mTexts = null;
mImage = null;
mToggle = null;
- mOnClickListener = null;
mOnClickDelegate = null;
mMetadata = EMPTY_METADATA;
mIsBrowsable = false;
@@ -289,9 +268,6 @@
CarIcon mImage;
@Nullable
Toggle mToggle;
- @SuppressWarnings("deprecation")
- @Nullable
- OnClickListenerWrapper mOnClickListener;
@Nullable
OnClickDelegate mOnClickDelegate;
Metadata mMetadata = EMPTY_METADATA;
@@ -461,9 +437,8 @@
* @throws NullPointerException if {@code onClickListener} is {@code null}
*/
@NonNull
- @SuppressLint("ExecutorRegistration")
+ @SuppressLint({"MissingGetterMatchingBuilder", "ExecutorRegistration"})
public Builder setOnClickListener(@NonNull OnClickListener onClickListener) {
- mOnClickListener = OnClickListenerWrapperImpl.create(requireNonNull(onClickListener));
mOnClickDelegate = OnClickDelegateImpl.create(onClickListener);
return this;
}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/SearchCallbackWrapper.java b/car/app/app/src/main/java/androidx/car/app/model/SearchCallbackWrapper.java
deleted file mode 100644
index 2d51f02..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/SearchCallbackWrapper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import androidx.annotation.NonNull;
-import androidx.car.app.OnDoneCallback;
-
-/**
- * A host-side interface for reporting to search updates to clients.
- *
- * @deprecated use {@link SearchCallbackDelegate} instead.
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@Deprecated
-public interface SearchCallbackWrapper {
- /**
- * Notifies that the search text has changed.
- *
- * @param searchText the up-to-date search text.
- * @param callback the {@link OnDoneCallback} to trigger when the client finishes handling
- * the event.
- */
- void onSearchTextChanged(@NonNull String searchText, @NonNull OnDoneCallback callback);
-
- /**
- * Notifies that the user has submitted the search.
- *
- * @param searchText the search text that was submitted.
- * @param callback the {@link OnDoneCallback} to trigger when the client finishes handling
- * the event.
- */
- void onSearchSubmitted(@NonNull String searchText, @NonNull OnDoneCallback callback);
-}
-
diff --git a/car/app/app/src/main/java/androidx/car/app/model/SearchCallbackWrapperImpl.java b/car/app/app/src/main/java/androidx/car/app/model/SearchCallbackWrapperImpl.java
deleted file mode 100644
index ebafa4f..0000000
--- a/car/app/app/src/main/java/androidx/car/app/model/SearchCallbackWrapperImpl.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 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 androidx.car.app.model;
-
-import static androidx.annotation.RestrictTo.Scope.LIBRARY;
-import static androidx.car.app.model.SearchTemplate.SearchCallback;
-
-import android.annotation.SuppressLint;
-import android.os.RemoteException;
-
-import androidx.annotation.Keep;
-import androidx.annotation.NonNull;
-import androidx.annotation.RestrictTo;
-import androidx.car.app.IOnDoneCallback;
-import androidx.car.app.OnDoneCallback;
-import androidx.car.app.utils.RemoteUtils;
-
-/**
- * Implementation class for {@link SearchCallbackWrapper}.
- *
- * @hide
- */
-// TODO(b/177591476): remove after host references have been cleaned up.
-@SuppressWarnings("deprecation")
-@RestrictTo(LIBRARY)
-public final class SearchCallbackWrapperImpl implements SearchCallbackWrapper {
-
- @Keep
- private final ISearchCallback mStubCallback;
-
- @Override
- public void onSearchTextChanged(@NonNull String searchText,
- @NonNull OnDoneCallback callback) {
- try {
- mStubCallback.onSearchTextChanged(searchText,
- RemoteUtils.createOnDoneCallbackStub(callback));
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void onSearchSubmitted(@NonNull String searchText,
- @NonNull OnDoneCallback callback) {
- try {
- mStubCallback.onSearchSubmitted(searchText,
- RemoteUtils.createOnDoneCallbackStub(callback));
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-
- private SearchCallbackWrapperImpl(@NonNull SearchCallback callback) {
- mStubCallback = new SearchCallbackStub(callback);
- }
-
- /** For serialization. */
- private SearchCallbackWrapperImpl() {
- mStubCallback = null;
- }
-
- @NonNull
- // This listener relates to UI event and is expected to be triggered on the main thread.
- @SuppressLint("ExecutorRegistration")
- static SearchCallbackWrapper create(@NonNull SearchCallback callback) {
- return new SearchCallbackWrapperImpl(callback);
- }
-
- @Keep // We need to keep these stub for Bundler serialization logic.
- private static class SearchCallbackStub extends ISearchCallback.Stub {
- private final SearchCallback mCallback;
-
- SearchCallbackStub(SearchCallback callback) {
- mCallback = callback;
- }
-
- @Override
- public void onSearchTextChanged(String text, IOnDoneCallback callback) {
- RemoteUtils.dispatchHostCall(
- () -> mCallback.onSearchTextChanged(text), callback,
- "onSearchTextChanged");
- }
-
- @Override
- public void onSearchSubmitted(String text, IOnDoneCallback callback) {
- RemoteUtils.dispatchHostCall(
- () -> mCallback.onSearchSubmitted(text), callback, "onSearchSubmitted");
- }
- }
-}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/SearchTemplate.java b/car/app/app/src/main/java/androidx/car/app/model/SearchTemplate.java
index 49ded92..e25585f 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/SearchTemplate.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/SearchTemplate.java
@@ -68,9 +68,6 @@
@Keep
private final boolean mIsLoading;
- @SuppressWarnings("deprecation")
- @Keep
- private final SearchCallbackWrapper mSearchCallback;
@Keep
private final SearchCallbackDelegate mSearchCallbackDelegate;
@Keep
@@ -139,22 +136,9 @@
}
/**
- * Returns the {@link SearchCallbackWrapper} for search callbacks.
- *
- * @deprecated use {@link #getSearchCallbackDelegate()} instead.
- */
- // TODO(b/177591476): remove after host references have been cleaned up.
- @Deprecated
- @SuppressWarnings("deprecation")
- @NonNull
- public SearchCallbackWrapper getSearchCallback() {
- return mSearchCallback;
- }
-
- /**
* Returns the {@link SearchCallbackDelegate} for search callbacks.
*/
- @NonNull
+ @Nullable
public SearchCallbackDelegate getSearchCallbackDelegate() {
return mSearchCallbackDelegate;
}
@@ -211,7 +195,6 @@
mSearchHint = builder.mSearchHint;
mIsLoading = builder.mIsLoading;
mItemList = builder.mItemList;
- mSearchCallback = builder.mSearchCallback;
mSearchCallbackDelegate = builder.mSearchCallbackDelegate;
mShowKeyboardByDefault = builder.mShowKeyboardByDefault;
mHeaderAction = builder.mHeaderAction;
@@ -226,15 +209,12 @@
mItemList = null;
mHeaderAction = null;
mActionStrip = null;
- mSearchCallback = null;
mSearchCallbackDelegate = null;
mShowKeyboardByDefault = true;
}
/** A builder of {@link SearchTemplate}. */
public static final class Builder {
- @SuppressWarnings("deprecation")
- final SearchCallbackWrapper mSearchCallback;
final SearchCallbackDelegate mSearchCallbackDelegate;
@Nullable
String mInitialSearchText;
@@ -401,7 +381,6 @@
*/
@SuppressLint("ExecutorRegistration")
public Builder(@NonNull SearchCallback callback) {
- mSearchCallback = SearchCallbackWrapperImpl.create(callback);
mSearchCallbackDelegate = SearchCallbackDelegateImpl.create(callback);
}
}
diff --git a/car/app/app/src/main/java/androidx/car/app/model/SectionedItemList.java b/car/app/app/src/main/java/androidx/car/app/model/SectionedItemList.java
index 40003cf..19f3c32 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/SectionedItemList.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/SectionedItemList.java
@@ -61,15 +61,15 @@
}
/** Returns the {@link ItemList} for the section. */
- @NonNull
+ @Nullable
public ItemList getItemList() {
- return requireNonNull(mItemList);
+ return mItemList;
}
/** Returns the title of the section. */
- @NonNull
+ @Nullable
public CarText getHeader() {
- return requireNonNull(mHeader);
+ return mHeader;
}
@Override
diff --git a/car/app/app/src/main/java/androidx/car/app/model/TemplateInfo.java b/car/app/app/src/main/java/androidx/car/app/model/TemplateInfo.java
index add15fb..4d33ad2 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/TemplateInfo.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/TemplateInfo.java
@@ -16,8 +16,6 @@
package androidx.car.app.model;
-import static java.util.Objects.requireNonNull;
-
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -32,10 +30,8 @@
*/
public final class TemplateInfo {
@Keep
- @Nullable
private final Class<? extends Template> mTemplateClass;
@Keep
- @Nullable
private final String mTemplateId;
/**
@@ -67,12 +63,12 @@
@NonNull
public Class<? extends Template> getTemplateClass() {
- return requireNonNull(mTemplateClass);
+ return mTemplateClass;
}
@NonNull
public String getTemplateId() {
- return requireNonNull(mTemplateId);
+ return mTemplateId;
}
@Override
diff --git a/car/app/app/src/main/java/androidx/car/app/model/TemplateWrapper.java b/car/app/app/src/main/java/androidx/car/app/model/TemplateWrapper.java
index 819b266..d3c5d88 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/TemplateWrapper.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/TemplateWrapper.java
@@ -22,8 +22,8 @@
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
+import androidx.car.app.utils.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
@@ -98,7 +98,7 @@
/** Returns the wrapped {@link Template}. */
@NonNull
public Template getTemplate() {
- return requireNonNull(mTemplate);
+ return mTemplate;
}
/** Returns the ID associated with the wrapped {@link Template}. */
@@ -128,9 +128,9 @@
* n is
* the bottom of the stack given n screens on the stack.
*/
- @Nullable
+ @NonNull
public List<TemplateInfo> getTemplateInfosForScreenStack() {
- return mTemplateInfoForScreenStack;
+ return CollectionUtils.emptyIfNull(mTemplateInfoForScreenStack);
}
/**
diff --git a/car/app/app/src/main/java/androidx/car/app/model/Toggle.java b/car/app/app/src/main/java/androidx/car/app/model/Toggle.java
index 89d3490..2da80a6 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/Toggle.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/Toggle.java
@@ -16,8 +16,6 @@
package androidx.car.app.model;
-import static java.util.Objects.requireNonNull;
-
import android.annotation.SuppressLint;
import android.os.Looper;
@@ -33,10 +31,6 @@
void onCheckedChange(boolean isChecked);
}
- @SuppressWarnings("deprecation")
- @Keep
- @Nullable
- private final OnCheckedChangeListenerWrapper mOnCheckedChangeListener;
@Keep
@Nullable
private final OnCheckedChangeDelegate mOnCheckedChangeDelegate;
@@ -51,26 +45,12 @@
}
/**
- * Returns the {@link OnCheckedChangeListenerWrapper} that is called when the checked state of
- * the {@link Toggle} is changed.
- *
- * @deprecated use {@link #getOnCheckedChangeDelegate} instead.
- */
- // TODO(b/177591476): remove after host references have been cleaned up.
- @SuppressWarnings("deprecation")
- @Deprecated
- @NonNull
- public OnCheckedChangeListenerWrapper getOnCheckedChangeListener() {
- return requireNonNull(mOnCheckedChangeListener);
- }
-
- /**
* Returns the {@link OnCheckedChangeDelegate} that is called when the checked state of
* the {@link Toggle} is changed.
*/
- @NonNull
+ @Nullable
public OnCheckedChangeDelegate getOnCheckedChangeDelegate() {
- return requireNonNull(mOnCheckedChangeDelegate);
+ return mOnCheckedChangeDelegate;
}
@Override
@@ -100,21 +80,17 @@
Toggle(Builder builder) {
mIsChecked = builder.mIsChecked;
- mOnCheckedChangeListener = builder.mOnCheckedChangeListener;
mOnCheckedChangeDelegate = builder.mOnCheckedChangeDelegate;
}
/** Constructs an empty instance, used by serialization code. */
private Toggle() {
- mOnCheckedChangeListener = null;
mOnCheckedChangeDelegate = null;
mIsChecked = false;
}
/** A builder of {@link Toggle}. */
public static final class Builder {
- @SuppressWarnings("deprecation")
- OnCheckedChangeListenerWrapper mOnCheckedChangeListener;
OnCheckedChangeDelegate mOnCheckedChangeDelegate;
boolean mIsChecked;
@@ -146,8 +122,6 @@
*/
@SuppressLint("ExecutorRegistration")
public Builder(@NonNull OnCheckedChangeListener onCheckedChangeListener) {
- mOnCheckedChangeListener =
- OnCheckedChangeListenerWrapperImpl.create(onCheckedChangeListener);
mOnCheckedChangeDelegate = OnCheckedChangeDelegateImpl.create(onCheckedChangeListener);
}
}
diff --git a/car/app/app/src/main/java/androidx/car/app/navigation/model/Lane.java b/car/app/app/src/main/java/androidx/car/app/navigation/model/Lane.java
index eb6c82b..fd5bebc 100644
--- a/car/app/app/src/main/java/androidx/car/app/navigation/model/Lane.java
+++ b/car/app/app/src/main/java/androidx/car/app/navigation/model/Lane.java
@@ -40,7 +40,7 @@
@NonNull
public List<LaneDirection> getDirections() {
- return mDirections;
+ return CollectionUtils.emptyIfNull(mDirections);
}
@Override
diff --git a/car/app/app/src/main/java/androidx/car/app/navigation/model/MessageInfo.java b/car/app/app/src/main/java/androidx/car/app/navigation/model/MessageInfo.java
index c6e7ee2..e864404 100644
--- a/car/app/app/src/main/java/androidx/car/app/navigation/model/MessageInfo.java
+++ b/car/app/app/src/main/java/androidx/car/app/navigation/model/MessageInfo.java
@@ -40,9 +40,9 @@
@Nullable
private final CarIcon mImage;
- @NonNull
+ @Nullable
public CarText getTitle() {
- return requireNonNull(mTitle);
+ return mTitle;
}
@Nullable
diff --git a/car/app/app/src/main/java/androidx/car/app/navigation/model/NavigationTemplate.java b/car/app/app/src/main/java/androidx/car/app/navigation/model/NavigationTemplate.java
index a565497..729db82 100644
--- a/car/app/app/src/main/java/androidx/car/app/navigation/model/NavigationTemplate.java
+++ b/car/app/app/src/main/java/androidx/car/app/navigation/model/NavigationTemplate.java
@@ -118,9 +118,9 @@
/**
* Returns the {@link ActionStrip} with a list of the template-scoped actions for this template.
*/
- @NonNull
+ @Nullable
public ActionStrip getActionStrip() {
- return requireNonNull(mActionStrip);
+ return mActionStrip;
}
@NonNull
diff --git a/car/app/app/src/main/java/androidx/car/app/navigation/model/RoutingInfo.java b/car/app/app/src/main/java/androidx/car/app/navigation/model/RoutingInfo.java
index 4664f2d..47dc3ae 100644
--- a/car/app/app/src/main/java/androidx/car/app/navigation/model/RoutingInfo.java
+++ b/car/app/app/src/main/java/androidx/car/app/navigation/model/RoutingInfo.java
@@ -50,12 +50,12 @@
@Nullable
public Step getCurrentStep() {
- return requireNonNull(mCurrentStep);
+ return mCurrentStep;
}
@Nullable
public Distance getCurrentDistance() {
- return requireNonNull(mCurrentDistance);
+ return mCurrentDistance;
}
@Nullable
diff --git a/car/app/app/src/main/java/androidx/car/app/navigation/model/TravelEstimate.java b/car/app/app/src/main/java/androidx/car/app/navigation/model/TravelEstimate.java
index ead3a87..5c5f324 100644
--- a/car/app/app/src/main/java/androidx/car/app/navigation/model/TravelEstimate.java
+++ b/car/app/app/src/main/java/androidx/car/app/navigation/model/TravelEstimate.java
@@ -56,9 +56,9 @@
@Keep
private final CarColor mRemainingDistanceColor;
- @NonNull
+ @Nullable
public Distance getRemainingDistance() {
- return requireNonNull(mRemainingDistance);
+ return mRemainingDistance;
}
// TODO(rampara): Returned time values must be in milliseconds
@@ -72,12 +72,12 @@
return mArrivalTimeAtDestination;
}
- @NonNull
+ @Nullable
public CarColor getRemainingTimeColor() {
return mRemainingTimeColor;
}
- @NonNull
+ @Nullable
public CarColor getRemainingDistanceColor() {
return mRemainingDistanceColor;
}
diff --git a/car/app/app/src/main/java/androidx/car/app/navigation/model/Trip.java b/car/app/app/src/main/java/androidx/car/app/navigation/model/Trip.java
index 161f765..9c6f01e 100644
--- a/car/app/app/src/main/java/androidx/car/app/navigation/model/Trip.java
+++ b/car/app/app/src/main/java/androidx/car/app/navigation/model/Trip.java
@@ -52,22 +52,22 @@
@NonNull
public List<Destination> getDestinations() {
- return mDestinations;
+ return CollectionUtils.emptyIfNull(mDestinations);
}
@NonNull
public List<Step> getSteps() {
- return mSteps;
+ return CollectionUtils.emptyIfNull(mSteps);
}
@NonNull
public List<TravelEstimate> getDestinationTravelEstimates() {
- return mDestinationTravelEstimates;
+ return CollectionUtils.emptyIfNull(mDestinationTravelEstimates);
}
@NonNull
public List<TravelEstimate> getStepTravelEstimates() {
- return mStepTravelEstimates;
+ return CollectionUtils.emptyIfNull(mStepTravelEstimates);
}
@Nullable
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Clickable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Clickable.kt
index 99f155a..6032f46 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Clickable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Clickable.kt
@@ -16,13 +16,14 @@
package androidx.compose.foundation
-import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
-import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.gesture.doubleTapGestureFilter
+import androidx.compose.ui.gesture.longPressGestureFilter
+import androidx.compose.ui.gesture.pressIndicatorGestureFilter
+import androidx.compose.ui.gesture.tapGestureFilter
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.disabled
@@ -106,6 +107,7 @@
* @param onDoubleClick will be called when user double clicks on the element
* @param onClick will be called when user clicks on the element
*/
+@Suppress("DEPRECATION")
fun Modifier.clickable(
enabled: Boolean = true,
interactionState: InteractionState,
@@ -131,32 +133,25 @@
disabled()
}
}
- val onClickState = rememberUpdatedState(onClick)
- val interactionStateState = rememberUpdatedState(interactionState)
- val gesture =
+ val interactionUpdate =
if (enabled) {
- remember(onDoubleClick, onLongClick) {
- Modifier.pointerInput {
- detectTapGestures(
- onDoubleTap = if (onDoubleClick != null) {
- { onDoubleClick() }
- } else {
- null
- },
- onLongPress = if (onLongClick != null) {
- { onLongClick() }
- } else {
- null
- },
- onPress = {
- interactionStateState.value.addInteraction(Interaction.Pressed, it)
- tryAwaitRelease()
- interactionStateState.value.removeInteraction(Interaction.Pressed)
- },
- onTap = { onClickState.value.invoke() }
- )
- }
- }
+ Modifier.pressIndicatorGestureFilter(
+ onStart = { interactionState.addInteraction(Interaction.Pressed, it) },
+ onStop = { interactionState.removeInteraction(Interaction.Pressed) },
+ onCancel = { interactionState.removeInteraction(Interaction.Pressed) }
+ )
+ } else {
+ Modifier
+ }
+ val tap = if (enabled) tapGestureFilter(onTap = { onClick() }) else Modifier
+ val longTap = if (enabled && onLongClick != null) {
+ longPressGestureFilter(onLongPress = { onLongClick() })
+ } else {
+ Modifier
+ }
+ val doubleTap =
+ if (enabled && onDoubleClick != null) {
+ doubleTapGestureFilter(onDoubleTap = { onDoubleClick() })
} else {
Modifier
}
@@ -166,8 +161,11 @@
}
}
semanticModifier
- .then(gesture)
+ .then(interactionUpdate)
.indication(interactionState, indication)
+ .then(tap)
+ .then(longTap)
+ .then(doubleTap)
},
inspectorInfo = debugInspectorInfo {
name = "clickable"
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt
index ed255f1..504f56c 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt
@@ -21,14 +21,13 @@
import androidx.compose.foundation.Interaction
import androidx.compose.foundation.InteractionState
import androidx.compose.foundation.Strings
-import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.indication
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
-import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.gesture.pressIndicatorGestureFilter
+import androidx.compose.ui.gesture.tapGestureFilter
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.disabled
@@ -231,7 +230,7 @@
}
)
-@Suppress("ModifierInspectorInfo")
+@Suppress("ModifierInspectorInfo", "DEPRECATION")
private fun Modifier.toggleableImpl(
state: ToggleableState,
enabled: Boolean,
@@ -257,22 +256,17 @@
disabled()
}
}
- val clickState = rememberUpdatedState(onClick)
- val interactionStateState = rememberUpdatedState(interactionState)
- val gestures = if (enabled) {
- Modifier.pointerInput {
- detectTapGestures(
- onTap = { clickState.value.invoke() },
- onPress = {
- interactionStateState.value.addInteraction(Interaction.Pressed, it)
- tryAwaitRelease()
- interactionStateState.value.removeInteraction(Interaction.Pressed)
- }
+ val interactionUpdate =
+ if (enabled) {
+ Modifier.pressIndicatorGestureFilter(
+ onStart = { interactionState.addInteraction(Interaction.Pressed, it) },
+ onStop = { interactionState.removeInteraction(Interaction.Pressed) },
+ onCancel = { interactionState.removeInteraction(Interaction.Pressed) }
)
+ } else {
+ Modifier
}
- } else {
- Modifier
- }
+ val click = if (enabled) Modifier.tapGestureFilter { onClick() } else Modifier
DisposableEffect(interactionState) {
onDispose {
@@ -282,5 +276,6 @@
this
.then(semantics)
.indication(interactionState, indication)
- .then(gestures)
+ .then(interactionUpdate)
+ .then(click)
}
\ No newline at end of file
diff --git a/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/interoperability/Interoperability.kt b/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/interoperability/Interoperability.kt
index 1e2ce2b..ecc098a 100644
--- a/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/interoperability/Interoperability.kt
+++ b/compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/interoperability/Interoperability.kt
@@ -18,7 +18,7 @@
// Ignore lint warnings in documentation snippets
@file:Suppress(
"unused", "UNUSED_PARAMETER", "UNUSED_VARIABLE", "UNUSED_ANONYMOUS_PARAMETER",
- "RedundantSuspendModifier", "CascadeIf", "ClassName"
+ "RedundantSuspendModifier", "CascadeIf", "ClassName", "RemoveExplicitTypeArguments"
)
package androidx.compose.integration.docs.interoperability
@@ -48,6 +48,7 @@
import androidx.compose.foundation.layout.padding
import androidx.compose.integration.docs.databinding.ExampleLayoutBinding
import androidx.compose.material.Button
+import androidx.compose.material.ButtonDefaults
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
@@ -71,6 +72,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
+import androidx.compose.ui.platform.AbstractComposeView
import androidx.compose.ui.platform.AmbientConfiguration
import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.platform.ComposeView
@@ -630,6 +632,40 @@
private object InteropSnippet10 {
@Composable
+ fun LoginButton(
+ onClick: () -> Unit,
+ modifier: Modifier = Modifier,
+ ) {
+ Button(
+ colors = ButtonDefaults.buttonColors(
+ backgroundColor = MaterialTheme.colors.secondary
+ ),
+ onClick = onClick,
+ modifier = modifier,
+ ) {
+ Text(stringResource(R.string.login))
+ }
+ }
+
+ class LoginViewButton @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyle: Int = 0
+ ) : AbstractComposeView(context, attrs, defStyle) {
+
+ var onClick by mutableStateOf<() -> Unit>({})
+
+ @Composable
+ override fun Content() {
+ YourAppTheme {
+ LoginButton(onClick)
+ }
+ }
+ }
+ }
+
+ private object InteropSnippet11 {
+ @Composable
fun SystemBroadcastReceiver(
systemAction: String,
onSystemEvent: (intent: Intent?) -> Unit
@@ -686,15 +722,16 @@
object string {
const val ok = 4
const val plane_description = 5
+ const val login = 6
}
object dimen {
- const val padding_small = 6
+ const val padding_small = 7
}
object drawable {
- const val ic_plane = 7
+ const val ic_plane = 8
}
object color {
- const val Blue700 = 8
+ const val Blue700 = 9
}
}
@@ -730,6 +767,7 @@
@Composable private fun AppCompatTheme(content: @Composable () -> Unit) { }
@Composable private fun BlueTheme(content: @Composable () -> Unit) { }
@Composable private fun PinkTheme(content: @Composable () -> Unit) { }
+@Composable private fun YourAppTheme(content: @Composable () -> Unit) { }
@Composable private fun ProvideWindowInsets(content: @Composable () -> Unit) { }
@Composable private fun Icon() { }
diff --git a/compose/ui/ui-inspection/build.gradle b/compose/ui/ui-inspection/build.gradle
index b0b764a..e562922 100644
--- a/compose/ui/ui-inspection/build.gradle
+++ b/compose/ui/ui-inspection/build.gradle
@@ -79,3 +79,7 @@
]
}
}
+
+inspection {
+ name = "compose-ui-inspection.jar"
+}
\ No newline at end of file
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/ClickNotPlacedChildTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/ClickNotPlacedChildTest.kt
new file mode 100644
index 0000000..3fbc3d6
--- /dev/null
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/ClickNotPlacedChildTest.kt
@@ -0,0 +1,83 @@
+/*
+ * Copyright 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 androidx.compose.ui.input
+
+import android.os.Build
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.size
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.layout.Layout
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.compose.ui.test.onNodeWithTag
+import androidx.compose.ui.test.performClick
+import androidx.compose.ui.unit.dp
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.MediumTest
+import androidx.test.filters.SdkSuppress
+import org.junit.Assert.assertEquals
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@MediumTest
+@RunWith(AndroidJUnit4::class)
+class ClickNotPlacedChildTest {
+
+ @get:Rule
+ val composeTestRule = createComposeRule()
+
+ @Test
+ @SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
+ fun childIsDisplayedWhenItWasNotPlacedOriginallyButPlacedLater() {
+ var firstClickedTimes = 0
+ var secondClickedTimes = 0
+ composeTestRule.setContent {
+ Layout(
+ content = {
+ Box(
+ Modifier.fillMaxSize().clickable {
+ firstClickedTimes++
+ }
+ )
+ Box(
+ Modifier.fillMaxSize().clickable {
+ secondClickedTimes++
+ }
+ )
+ },
+ modifier = Modifier.size(100.dp).testTag("parent")
+ ) { measutables, constraints ->
+ val first = measutables[0].measure(constraints)
+ measutables[1].measure(constraints)
+ layout(first.width, first.height) {
+ first.place(0, 0)
+ }
+ }
+ }
+
+ composeTestRule.onNodeWithTag("parent")
+ .performClick()
+
+ composeTestRule.runOnIdle {
+ assertEquals(0, secondClickedTimes)
+ assertEquals(1, firstClickedTimes)
+ }
+ }
+}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInputEventProcessorTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInputEventProcessorTest.kt
index 3ae5bed..26bf47f 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInputEventProcessorTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInputEventProcessorTest.kt
@@ -16,6 +16,7 @@
package androidx.compose.ui.input.pointer
+import androidx.compose.foundation.layout.offset
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.Autofill
@@ -29,9 +30,10 @@
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
+import androidx.compose.ui.layout.layout
import androidx.compose.ui.node.InternalCoreApi
import androidx.compose.ui.node.LayoutNode
-import androidx.compose.ui.node.LayoutNodeWrapper
+import androidx.compose.ui.node.MeasureAndLayoutDelegate
import androidx.compose.ui.node.OwnedLayer
import androidx.compose.ui.node.Owner
import androidx.compose.ui.node.OwnerSnapshotObserver
@@ -51,7 +53,6 @@
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.google.common.truth.Truth.assertThat
-import com.nhaarman.mockitokotlin2.spy
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -83,15 +84,20 @@
@RunWith(AndroidJUnit4::class)
class PointerInputEventProcessorTest {
- private lateinit var root: LayoutNode
private lateinit var pointerInputEventProcessor: PointerInputEventProcessor
- private val testOwner: TestOwner = spy()
+ private lateinit var testOwner: TestOwner
@Before
fun setup() {
- root = LayoutNode(0, 0, 500, 500)
- root.attach(testOwner)
- pointerInputEventProcessor = PointerInputEventProcessor(root)
+ testOwner = TestOwner()
+ pointerInputEventProcessor = PointerInputEventProcessor(testOwner.root)
+ }
+
+ private fun addToRoot(vararg layoutNodes: LayoutNode) {
+ layoutNodes.forEachIndexed { index, node ->
+ testOwner.root.insertAt(index, node)
+ }
+ testOwner.measureAndLayout()
}
@Test
@@ -110,7 +116,7 @@
)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val offset = Offset(100f, 200f)
val previousEvents = mutableListOf<PointerInputEventData>()
@@ -173,7 +179,7 @@
)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val offset = Offset(100f, 200f)
val offset2 = Offset(300f, 400f)
@@ -230,7 +236,7 @@
)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val offsets = arrayOf(
Offset(100f, 200f),
@@ -296,7 +302,7 @@
)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val offsets = arrayOf(
Offset(99f, 200f),
@@ -372,7 +378,7 @@
).apply {
insertAt(0, middleLayoutNode)
}
- root.insertAt(0, parentLayoutNode)
+ addToRoot(parentLayoutNode)
val offset = when (numberOfChildrenHit) {
3 -> Offset(250f, 250f)
@@ -466,7 +472,7 @@
)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val down = PointerInputEvent(
0,
@@ -587,7 +593,7 @@
testOwner.position = IntOffset(aOX, aOY)
- root.insertAt(0, parentLayoutNode)
+ addToRoot(parentLayoutNode)
val additionalOffset = IntOffset(aOX, aOY)
@@ -752,10 +758,7 @@
childPointerInputFilter2
)
)
- root.apply {
- insertAt(0, childLayoutNode1)
- insertAt(0, childLayoutNode2)
- }
+ addToRoot(childLayoutNode1, childLayoutNode2)
val offset1 = Offset(25f, 25f)
val offset2 = Offset(75f, 75f)
@@ -904,11 +907,7 @@
)
)
- root.apply {
- insertAt(0, childLayoutNode1)
- insertAt(1, childLayoutNode2)
- insertAt(2, childLayoutNode3)
- }
+ addToRoot(childLayoutNode1, childLayoutNode2, childLayoutNode3)
val offset1 = Offset(25f, 25f)
val offset2 = Offset(75f, 75f)
@@ -1084,10 +1083,7 @@
)
)
- root.apply {
- insertAt(0, childLayoutNode1)
- insertAt(1, childLayoutNode2)
- }
+ addToRoot(childLayoutNode1, childLayoutNode2)
val offset1 = Offset(50f, 25f)
val offset2 = Offset(50f, 75f)
@@ -1204,10 +1200,7 @@
)
)
- root.apply {
- insertAt(0, childLayoutNode1)
- insertAt(1, childLayoutNode2)
- }
+ addToRoot(childLayoutNode1, childLayoutNode2)
val offset1 = Offset(25f, 50f)
val offset2 = Offset(75f, 50f)
@@ -1351,9 +1344,8 @@
insertAt(2, layoutNodeBottomLeft)
insertAt(3, layoutNodeBottomRight)
}
- root.apply {
- insertAt(0, parentLayoutNode)
- }
+ addToRoot(parentLayoutNode)
+
val offsetsTopLeft =
listOf(
Offset(0f, 1f),
@@ -1540,9 +1532,7 @@
singlePointerInputFilter
)
)
- root.apply {
- insertAt(0, layoutNode)
- }
+ addToRoot(layoutNode)
val offsetsThatHit =
listOf(
Offset(2f, 2f),
@@ -1616,9 +1606,7 @@
modifier
)
- root.apply {
- insertAt(0, layoutNode)
- }
+ addToRoot(layoutNode)
val offset1 = Offset(50f, 75f)
@@ -1698,9 +1686,7 @@
val layoutNode4: LayoutNode = LayoutNode(4, 8, 500, 500).apply {
insertAt(0, layoutNode3)
}
- root.apply {
- insertAt(0, layoutNode4)
- }
+ addToRoot(layoutNode4)
val offset1 = Offset(499f, 499f)
@@ -1776,9 +1762,7 @@
val layoutNode5: LayoutNode = LayoutNode(5, 10, 500, 500).apply {
insertAt(0, layoutNode4)
}
- root.apply {
- insertAt(0, layoutNode5)
- }
+ addToRoot(layoutNode5)
val offset1 = Offset(499f, 499f)
@@ -1884,10 +1868,7 @@
)
)
- root.apply {
- insertAt(0, layoutNode1)
- insertAt(1, layoutNode2)
- }
+ addToRoot(layoutNode1, layoutNode2)
val down = PointerInputEvent(
1, 0, Offset(50f, 50f), true
@@ -1912,9 +1893,7 @@
PointerInputModifierImpl2(pointerInputFilter1)
)
- root.apply {
- insertAt(0, layoutNode1)
- }
+ addToRoot(layoutNode1)
val down = PointerInputEvent(
1, 0, Offset(0f, 0f), true
@@ -1946,7 +1925,7 @@
PointerInputModifierImpl2(pointerInputFilter)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val pointerInputEvent =
PointerInputEvent(
@@ -2005,7 +1984,7 @@
)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val pointerInputEvent1 =
PointerInputEvent(
@@ -2123,8 +2102,7 @@
PointerInputModifierImpl2(pointerInputFilter2)
)
- root.insertAt(0, layoutNode1)
- root.insertAt(1, layoutNode2)
+ addToRoot(layoutNode1, layoutNode2)
val pointerInputEventData1 =
PointerInputEventData(
@@ -2217,7 +2195,7 @@
PointerInputModifierImpl2(pointerInputFilter)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val down =
PointerInputEvent(
@@ -2304,7 +2282,7 @@
PointerInputModifierImpl2(pointerInputFilter)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val down =
PointerInputEvent(
@@ -2364,7 +2342,7 @@
)
)
- root.insertAt(0, layoutNode)
+ addToRoot(layoutNode)
val down1 =
PointerInputEvent(
@@ -2460,7 +2438,7 @@
insertAt(0, childLayoutNode)
}
- root.insertAt(0, parentLayoutNode)
+ addToRoot(parentLayoutNode)
val offset = Offset(50f, 50f)
@@ -2575,7 +2553,7 @@
insertAt(0, childLayoutNode)
}
- root.insertAt(0, parentLayoutNode)
+ addToRoot(parentLayoutNode)
val down =
PointerInputEvent(0, 7, Offset(50f, 50f), true)
@@ -2616,7 +2594,7 @@
insertAt(0, childLayoutNode)
}
- root.insertAt(0, parentLayoutNode)
+ addToRoot(parentLayoutNode)
val offset = Offset(50f, 50f)
@@ -2731,7 +2709,7 @@
insertAt(0, childLayoutNode)
}
- root.insertAt(0, parentLayoutNode)
+ addToRoot(parentLayoutNode)
val down =
PointerInputEvent(0, 7, Offset(50f, 50f), true)
@@ -2779,9 +2757,7 @@
)
)
- root.apply {
- insertAt(0, layoutNode)
- }
+ addToRoot(layoutNode)
val offsets =
listOf(
@@ -2824,7 +2800,7 @@
pointerInputFilter
)
)
- root.apply { insertAt(0, layoutNode) }
+ addToRoot(layoutNode)
val pointerInputEvent =
PointerInputEvent(0, 11, Offset(0f, 0f), true)
@@ -2854,14 +2830,14 @@
pointerInputFilter
)
)
- root.apply { insertAt(0, layoutNode) }
+ addToRoot(layoutNode)
val down = PointerInputEvent(0, 11, Offset(0f, 0f), true)
pointerInputEventProcessor.process(down)
val move = PointerInputEvent(0, 11, Offset(1f, 0f), true)
// Act
- root.removeAt(0, 1)
+ testOwner.root.removeAt(0, 1)
val result = pointerInputEventProcessor.process(move)
// Assert
@@ -2886,7 +2862,7 @@
pointerInputFilter
)
)
- root.apply { insertAt(0, layoutNode) }
+ addToRoot(layoutNode)
val down = PointerInputEvent(0, 11, Offset(0f, 0f), true)
pointerInputEventProcessor.process(down)
val move = PointerInputEvent(0, 11, Offset(1f, 0f), true)
@@ -2927,7 +2903,7 @@
pointerInputFilter
)
)
- root.apply { insertAt(0, layoutNode) }
+ addToRoot(layoutNode)
val down = PointerInputEvent(0, 11, Offset(0f, 0f), true)
pointerInputEventProcessor.process(down)
val move = PointerInputEvent(0, 11, Offset(1f, 0f), true)
@@ -2987,59 +2963,45 @@
}
}
-abstract class TestOwner : Owner {
- var position: IntOffset? = null
-
- override val root: LayoutNode
- get() = LayoutNode()
-
- override fun calculatePosition(): IntOffset {
- return position ?: IntOffset.Zero
- }
-}
-
private class PointerInputModifierImpl2(override val pointerInputFilter: PointerInputFilter) :
PointerInputModifier
private fun LayoutNode(x: Int, y: Int, x2: Int, y2: Int, modifier: Modifier = Modifier) =
LayoutNode().apply {
- this.modifier = modifier
+ this.modifier = Modifier.layout { measurable, constraints ->
+ val placeable = measurable.measure(constraints)
+ layout(placeable.width, placeable.height) {
+ placeable.place(x, y)
+ }
+ }.then(modifier)
measureBlocks = object : LayoutNode.NoIntrinsicsMeasureBlocks("not supported") {
override fun measure(
measureScope: MeasureScope,
measurables: List<Measurable>,
constraints: Constraints
): MeasureResult =
- measureScope.layout(x2 - x, y2 - y) {}
+ measureScope.layout(x2 - x, y2 - y) {
+ measurables.forEach { it.measure(constraints).place(0, 0) }
+ }
}
- attach(mockOwner())
- layoutState = LayoutNode.LayoutState.NeedsRemeasure
- remeasure(Constraints())
- var wrapper: LayoutNodeWrapper? = outerLayoutNodeWrapper
- while (wrapper != null) {
- wrapper.measureResult = innerLayoutNodeWrapper.measureResult
- wrapper = (wrapper as? LayoutNodeWrapper)?.wrapped
- }
- place(x, y)
- detach()
}
-private fun mockOwner(
- position: IntOffset = IntOffset.Zero,
- targetRoot: LayoutNode = LayoutNode()
-): Owner = MockOwner(position, targetRoot)
-
@OptIn(ExperimentalComposeUiApi::class, InternalCoreApi::class)
-private class MockOwner(
- private val position: IntOffset,
- private val targetRoot: LayoutNode
-) : Owner {
+private class TestOwner : Owner {
+ var position: IntOffset = IntOffset.Zero
+ override val root = LayoutNode(0, 0, 500, 500)
+
+ private val delegate = MeasureAndLayoutDelegate(root)
+
+ init {
+ root.attach(this)
+ delegate.updateRootConstraints(Constraints(maxWidth = 500, maxHeight = 500))
+ }
+
override fun calculatePosition(): IntOffset = position
override fun calculatePositionInWindow(): IntOffset = position
override fun requestFocus(): Boolean = false
- override val root: LayoutNode
- get() = targetRoot
override val rootForTest: RootForTest
get() = TODO("Not yet implemented")
override val hapticFeedBack: HapticFeedback
@@ -3069,9 +3031,11 @@
set(@Suppress("UNUSED_PARAMETER") value) {}
override fun onRequestMeasure(layoutNode: LayoutNode) {
+ delegate.requestRemeasure(layoutNode)
}
override fun onRequestRelayout(layoutNode: LayoutNode) {
+ delegate.requestRelayout(layoutNode)
}
override fun onAttach(node: LayoutNode) {
@@ -3081,6 +3045,7 @@
}
override fun measureAndLayout() {
+ delegate.measureAndLayout()
}
override fun createLayer(
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt
index 0414d6a..f496339 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt
@@ -146,8 +146,12 @@
// not add PointerInputFilters on different paths so we should not even go looking.
val originalSize = hitPointerInputFilters.size
layoutNode.zSortedChildren.reversedAny { child ->
- callHitTest(child, pointerPositionRelativeToScreen, hitPointerInputFilters)
- hitPointerInputFilters.size > originalSize
+ if (child.isPlaced) {
+ callHitTest(child, pointerPositionRelativeToScreen, hitPointerInputFilters)
+ hitPointerInputFilters.size > originalSize
+ } else {
+ false
+ }
}
}
}
diff --git a/compose/ui/ui/src/test/kotlin/androidx/compose/ui/node/LayoutNodeTest.kt b/compose/ui/ui/src/test/kotlin/androidx/compose/ui/node/LayoutNodeTest.kt
index 4f34aef..e31400b8 100644
--- a/compose/ui/ui/src/test/kotlin/androidx/compose/ui/node/LayoutNodeTest.kt
+++ b/compose/ui/ui/src/test/kotlin/androidx/compose/ui/node/LayoutNodeTest.kt
@@ -32,6 +32,8 @@
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.hapticfeedback.HapticFeedback
import androidx.compose.ui.input.key.KeyEvent
+import androidx.compose.ui.input.pointer.PointerEvent
+import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerInputFilter
import androidx.compose.ui.input.pointer.PointerInputModifier
import androidx.compose.ui.layout.LayoutModifier
@@ -54,7 +56,6 @@
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.zIndex
import com.google.common.truth.Truth.assertThat
-import com.nhaarman.mockitokotlin2.spy
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
@@ -794,7 +795,7 @@
@Test
fun hitTest_pointerInBounds_pointerInputFilterHit() {
- val pointerInputFilter: PointerInputFilter = spy()
+ val pointerInputFilter: PointerInputFilter = mockPointerInputFilter()
val layoutNode =
LayoutNode(
0, 0, 1, 1,
@@ -811,7 +812,7 @@
@Test
fun hitTest_pointerOutOfBounds_nothingHit() {
- val pointerInputFilter: PointerInputFilter = spy()
+ val pointerInputFilter: PointerInputFilter = mockPointerInputFilter()
val layoutNode =
LayoutNode(
0, 0, 1, 1,
@@ -854,9 +855,9 @@
private fun hitTest_nestedOffsetNodes_allHitInCorrectOrder(numberOfChildrenHit: Int) {
// Arrange
- val childPointerInputFilter: PointerInputFilter = spy()
- val middlePointerInputFilter: PointerInputFilter = spy()
- val parentPointerInputFilter: PointerInputFilter = spy()
+ val childPointerInputFilter: PointerInputFilter = mockPointerInputFilter()
+ val middlePointerInputFilter: PointerInputFilter = mockPointerInputFilter()
+ val parentPointerInputFilter: PointerInputFilter = mockPointerInputFilter()
val childLayoutNode =
LayoutNode(
@@ -884,6 +885,8 @@
insertAt(0, middleLayoutNode)
attach(MockOwner())
}
+ middleLayoutNode.onNodePlaced()
+ childLayoutNode.onNodePlaced()
val offset = when (numberOfChildrenHit) {
3 -> Offset(250f, 250f)
@@ -952,8 +955,8 @@
// Arrange
- val childPointerInputFilter1: PointerInputFilter = spy()
- val childPointerInputFilter2: PointerInputFilter = spy()
+ val childPointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val childPointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
val childLayoutNode1 =
LayoutNode(
@@ -976,6 +979,8 @@
insertAt(1, childLayoutNode2)
attach(MockOwner())
}
+ childLayoutNode1.onNodePlaced()
+ childLayoutNode2.onNodePlaced()
val offset1 = Offset(25f, 25f)
val offset2 = Offset(75f, 75f)
@@ -1019,9 +1024,9 @@
@Test
fun hitTest_3DownOnOverlappingPointerInputModifiers_resultIsCorrect() {
- val childPointerInputFilter1: PointerInputFilter = spy()
- val childPointerInputFilter2: PointerInputFilter = spy()
- val childPointerInputFilter3: PointerInputFilter = spy()
+ val childPointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val childPointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
+ val childPointerInputFilter3: PointerInputFilter = mockPointerInputFilter()
val childLayoutNode1 =
LayoutNode(
@@ -1053,6 +1058,9 @@
insertAt(2, childLayoutNode3)
attach(MockOwner())
}
+ childLayoutNode1.onNodePlaced()
+ childLayoutNode2.onNodePlaced()
+ childLayoutNode3.onNodePlaced()
val offset1 = Offset(25f, 25f)
val offset2 = Offset(75f, 75f)
@@ -1094,8 +1102,8 @@
@Test
fun hitTest_3DownOnFloatingPointerInputModifierV_resultIsCorrect() {
- val childPointerInputFilter1: PointerInputFilter = spy()
- val childPointerInputFilter2: PointerInputFilter = spy()
+ val childPointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val childPointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
val childLayoutNode1 = LayoutNode(
0, 0, 100, 150,
@@ -1115,6 +1123,8 @@
insertAt(1, childLayoutNode2)
attach(MockOwner())
}
+ childLayoutNode1.onNodePlaced()
+ childLayoutNode2.onNodePlaced()
val offset1 = Offset(50f, 25f)
val offset2 = Offset(50f, 75f)
@@ -1156,8 +1166,8 @@
@Test
fun hitTest_3DownOnFloatingPointerInputModifierH_resultIsCorrect() {
- val childPointerInputFilter1: PointerInputFilter = spy()
- val childPointerInputFilter2: PointerInputFilter = spy()
+ val childPointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val childPointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
val childLayoutNode1 = LayoutNode(
0, 0, 150, 100,
@@ -1177,6 +1187,8 @@
insertAt(1, childLayoutNode2)
attach(MockOwner())
}
+ childLayoutNode2.onNodePlaced()
+ childLayoutNode1.onNodePlaced()
val offset1 = Offset(25f, 50f)
val offset2 = Offset(75f, 50f)
@@ -1226,10 +1238,10 @@
// Arrange
- val pointerInputFilter1: PointerInputFilter = spy()
- val pointerInputFilter2: PointerInputFilter = spy()
- val pointerInputFilter3: PointerInputFilter = spy()
- val pointerInputFilter4: PointerInputFilter = spy()
+ val pointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter3: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter4: PointerInputFilter = mockPointerInputFilter()
val layoutNode1 = LayoutNode(
-1, -1, 1, 1,
@@ -1263,6 +1275,10 @@
insertAt(3, layoutNode4)
attach(MockOwner())
}
+ layoutNode1.onNodePlaced()
+ layoutNode2.onNodePlaced()
+ layoutNode3.onNodePlaced()
+ layoutNode4.onNodePlaced()
val offsetsThatHit1 =
listOf(
@@ -1346,7 +1362,7 @@
// Arrange
- val pointerInputFilter: PointerInputFilter = spy()
+ val pointerInputFilter: PointerInputFilter = mockPointerInputFilter()
val layoutNode = LayoutNode(
0, 0, 2, 2,
@@ -1396,9 +1412,9 @@
// Arrange.
- val pointerInputFilter1: PointerInputFilter = spy()
- val pointerInputFilter2: PointerInputFilter = spy()
- val pointerInputFilter3: PointerInputFilter = spy()
+ val pointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter3: PointerInputFilter = mockPointerInputFilter()
val modifier =
PointerInputModifierImpl(
@@ -1440,7 +1456,7 @@
// Arrange.
- val pointerInputFilter: PointerInputFilter = spy()
+ val pointerInputFilter: PointerInputFilter = mockPointerInputFilter()
val layoutNode1 =
LayoutNode(
@@ -1460,6 +1476,9 @@
}.apply {
attach(MockOwner())
}
+ layoutNode3.onNodePlaced()
+ layoutNode2.onNodePlaced()
+ layoutNode1.onNodePlaced()
val offset1 = Offset(499f, 499f)
val hit = mutableListOf<PointerInputFilter>()
@@ -1478,10 +1497,10 @@
// Arrange.
- val pointerInputFilter1: PointerInputFilter = spy()
- val pointerInputFilter2: PointerInputFilter = spy()
- val pointerInputFilter3: PointerInputFilter = spy()
- val pointerInputFilter4: PointerInputFilter = spy()
+ val pointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter3: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter4: PointerInputFilter = mockPointerInputFilter()
val layoutNode1 = LayoutNode(
1, 6, 500, 500,
@@ -1514,6 +1533,10 @@
}.apply {
attach(MockOwner())
}
+ layoutNode4.onNodePlaced()
+ layoutNode3.onNodePlaced()
+ layoutNode2.onNodePlaced()
+ layoutNode1.onNodePlaced()
val offset1 = Offset(499f, 499f)
@@ -1538,8 +1561,8 @@
@Test
fun hitTest_pointerOnFullyOverlappingPointerInputModifiers_onlyTopPimIsHit() {
- val pointerInputFilter1: PointerInputFilter = spy()
- val pointerInputFilter2: PointerInputFilter = spy()
+ val pointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
val layoutNode1 = LayoutNode(
0, 0, 100, 100,
@@ -1559,6 +1582,8 @@
insertAt(1, layoutNode2)
attach(MockOwner())
}
+ layoutNode1.onNodePlaced()
+ layoutNode2.onNodePlaced()
val offset = Offset(50f, 50f)
@@ -1576,7 +1601,7 @@
@Test
fun hitTest_pointerOnPointerInputModifierInLayoutNodeWithNoSize_nothingHit() {
- val pointerInputFilter: PointerInputFilter = spy()
+ val pointerInputFilter: PointerInputFilter = mockPointerInputFilter()
val layoutNode = LayoutNode(
0, 0, 0, 0,
@@ -1603,8 +1628,8 @@
@Test
fun hitTest_zIndexIsAccounted() {
- val pointerInputFilter1: PointerInputFilter = spy()
- val pointerInputFilter2: PointerInputFilter = spy()
+ val pointerInputFilter1: PointerInputFilter = mockPointerInputFilter()
+ val pointerInputFilter2: PointerInputFilter = mockPointerInputFilter()
val parent = LayoutNode(
0, 0, 2, 2
@@ -1869,7 +1894,7 @@
get() = TODO("Not yet implemented")
}
-fun LayoutNode(x: Int, y: Int, x2: Int, y2: Int, modifier: Modifier = Modifier) =
+private fun LayoutNode(x: Int, y: Int, x2: Int, y2: Int, modifier: Modifier = Modifier) =
LayoutNode().apply {
this.modifier = modifier
measureBlocks = object : LayoutNode.NoIntrinsicsMeasureBlocks("not supported") {
@@ -1893,3 +1918,15 @@
place(x, y)
detach()
}
+
+private fun mockPointerInputFilter(): PointerInputFilter = object : PointerInputFilter() {
+ override fun onPointerEvent(
+ pointerEvent: PointerEvent,
+ pass: PointerEventPass,
+ bounds: IntSize
+ ) {
+ }
+
+ override fun onCancel() {
+ }
+}
\ No newline at end of file
diff --git a/development/project-creator/create_project.py b/development/project-creator/create_project.py
index 8c73140..8ad4d34 100755
--- a/development/project-creator/create_project.py
+++ b/development/project-creator/create_project.py
@@ -76,6 +76,31 @@
elif os.path.exists(path):
os.remove(path)
+def mv_dir(src_path_dir, dst_path_dir):
+ """Moves a directory from src_path_dir to dst_path_dir.
+
+ Args:
+ src_path_dir: the source directory, which must exist
+ dst_path_dir: the distination directory
+ """
+ if os.path.exists(dst_path_dir):
+ print_e('rename error: Destination path %s already exists.' % dst_path_dir)
+ return None
+ # If moving to a new parent directory, create that directory
+ parent_dst_path_dir = os.path.dirname(dst_path_dir)
+ if not os.path.exists(parent_dst_path_dir):
+ os.makedirs(parent_dst_path_dir)
+ if not os.path.exists(src_path_dir):
+ print_e('mv error: Source path %s does not exist.' % src_path_dir)
+ return None
+ try:
+ os.rename(src_path_dir, dst_path_dir)
+ except OSError as error:
+ print_e('FAIL: Unable to copy %s to destination %s' % (src_path_dir, dst_path_dir))
+ print_e(error)
+ return None
+ return dst_path_dir
+
def generate_package_name(group_id, artifact_id):
final_group_id_word = group_id.split(".")[-1]
artifact_id_suffix = artifact_id.replace(final_group_id_word, "")
@@ -98,7 +123,7 @@
return str(date.today().year)
def get_group_id_version_macro(group_id):
- group_id_version_macro = group_id.replace("androidx.", "").replace(".", "-").upper()
+ group_id_version_macro = group_id.replace("androidx.", "").replace(".", "_").upper()
if group_id.startswith("androidx.compose"):
group_id_version_macro = "COMPOSE"
return group_id_version_macro
@@ -157,6 +182,20 @@
group_id_path = get_group_id_path(group_id)
return group_id_path + "/" + artifact_id
+def get_package_info_file_dir(group_id, artifact_id):
+ """Generates the full package_info.java filepath
+
+ Given androidx.foo.bar:bar-qux, the structure will be:
+ frameworks/support/foo/bar/bar-qux/src/main/androidx/foo/package-info.java
+
+ Args:
+ group_id: group_id of the new library
+ artifact_id: group_id of the new library
+ """
+ full_artifact_path = get_full_artifact_path(group_id, artifact_id)
+ group_id_subpath = "/src/main/" + \
+ group_id.replace(".", "/")
+ return full_artifact_path + group_id_subpath
def create_directories(group_id, artifact_id):
"""Creates the standard directories for the given group_id and artifact_id.
@@ -164,6 +203,7 @@
Given androidx.foo.bar:bar-qux, the structure will be:
frameworks/support/foo/bar/bar-qux/build.gradle
frameworks/support/foo/bar/bar-qux/src/main/AndroidManifest.xml
+ frameworks/support/foo/bar/bar-qux/src/main/androidx/foo/bar/package-info.java
frameworks/support/foo/bar/bar-qux/src/androidTest/AndroidManifest.xml
frameworks/support/foo/bar/bar-qux/api/current.txt
@@ -183,15 +223,22 @@
# Copy the full src structure
cp(SAMPLE_SRC_FP, full_artifact_path)
+ # Rename the package-info directory
+ full_package_info_dir = get_package_info_file_dir(group_id, artifact_id)
+ full_package_info_path = full_package_info_dir + "/package-info.java"
+ mv_dir(full_artifact_path + "/src/main/groupId", full_package_info_dir)
+
# Populate the YEAR
year = get_year()
sed("<YEAR>", year, full_artifact_path + "/build.gradle")
sed("<YEAR>", year, full_artifact_path + "/src/androidTest/AndroidManifest.xml")
sed("<YEAR>", year, full_artifact_path + "/src/main/AndroidManifest.xml")
+ sed("<YEAR>", year, full_package_info_path)
# Populate the PACKAGE
package = generate_package_name(group_id, artifact_id)
sed("<PACKAGE>", package, full_artifact_path + "/src/androidTest/AndroidManifest.xml")
sed("<PACKAGE>", package, full_artifact_path + "/src/main/AndroidManifest.xml")
+ sed("<PACKAGE>", package, full_package_info_path)
# Populate the VERSION macro
group_id_version_macro = get_group_id_version_macro(group_id)
sed("<GROUPID>", group_id_version_macro, full_artifact_path + "/build.gradle")
diff --git a/development/project-creator/groupId/artifactId/src/main/groupId/package-info.java b/development/project-creator/groupId/artifactId/src/main/groupId/package-info.java
new file mode 100644
index 0000000..a51e68c
--- /dev/null
+++ b/development/project-creator/groupId/artifactId/src/main/groupId/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) <YEAR> 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.
+ */
+
+/**
+ * Insert package level documentation here
+ */
+package <PACKAGE>;
diff --git a/development/project-creator/test_directory_creator.py b/development/project-creator/test_directory_creator.py
index 5418a04..d3f4452 100755
--- a/development/project-creator/test_directory_creator.py
+++ b/development/project-creator/test_directory_creator.py
@@ -58,6 +58,20 @@
full_fp = get_full_artifact_path("androidx.foo.bar", "bar-qux")
self.assertTrue(full_fp.endswith("frameworks/support/foo/bar/bar-qux"))
+ def test_get_package_info_file_dir(self):
+ package_info_dir_fp = get_package_info_file_dir("androidx.foo", "foo")
+ frameworks_support_fp = os.path.abspath(os.path.join(os.getcwd(), '..', '..'))
+ self.assertEqual(frameworks_support_fp + "/foo/foo/src/main/androidx/foo", package_info_dir_fp)
+
+ package_info_dir_fp = get_package_info_file_dir("androidx.foo", "foo-bar")
+ self.assertEqual(frameworks_support_fp + "/foo/foo-bar/src/main/androidx/foo", package_info_dir_fp)
+
+ package_info_dir_fp = get_package_info_file_dir("androidx.foo.bar", "bar")
+ self.assertEqual(frameworks_support_fp + "/foo/bar/bar/src/main/androidx/foo/bar", package_info_dir_fp)
+
+ package_info_dir_fp = get_package_info_file_dir("androidx.foo.bar", "bar-qux")
+ self.assertEqual(frameworks_support_fp + "/foo/bar/bar-qux/src/main/androidx/foo/bar", package_info_dir_fp)
+
def test_group_id_directory_name(self):
full_fp = get_group_id_path("androidx.foo")
self.assertTrue(full_fp.endswith("frameworks/support/foo"))
@@ -71,6 +85,7 @@
full_fp = get_group_id_path("androidx.foo.bar")
self.assertTrue(full_fp.endswith("frameworks/support/foo/bar"))
+
class TestSettingsGradle(unittest.TestCase):
def test_settings_gradle_line(self):
@@ -147,7 +162,7 @@
self.assertEqual("FOO", macro)
macro = get_group_id_version_macro("androidx.foo.bar")
- self.assertEqual("FOO-BAR", macro)
+ self.assertEqual("FOO_BAR", macro)
macro = get_group_id_version_macro("androidx.compose.bar")
self.assertEqual("COMPOSE", macro)
@@ -168,5 +183,42 @@
self.assertEqual("d\nb\nc", file_contents)
rm(out_dir)
+ def test_mv_dir_within_same_dir(self):
+ src_out_dir = "./src_out"
+ test_src_file = src_out_dir + "/temp.txt"
+ test_file_contents = "a\nb\nc"
+ if not os.path.exists(src_out_dir):
+ os.makedirs(src_out_dir)
+ with open(test_src_file,"w") as f:
+ f.write("a\nb\nc")
+
+ dst_out_dir = "./dst_out"
+ mv_dir(src_out_dir, dst_out_dir)
+ # write back the file
+ with open(dst_out_dir + "/temp.txt") as f:
+ file_contents = f.read()
+ self.assertEqual("a\nb\nc", file_contents)
+ rm(src_out_dir)
+ rm(dst_out_dir)
+
+ def test_mv_dir_to_different_dir(self):
+ src_out_dir = "./src_out_2"
+ test_src_file = src_out_dir + "/temp.txt"
+ test_file_contents = "a\nb\nc"
+ if not os.path.exists(src_out_dir):
+ os.makedirs(src_out_dir)
+ with open(test_src_file,"w") as f:
+ f.write("a\nb\nc")
+
+ dst_out_dir_parent = "./dst_out_2"
+ dst_out_dir = dst_out_dir_parent + "/hello/world"
+ mv_dir(src_out_dir, dst_out_dir)
+ # write back the file
+ with open(dst_out_dir + "/temp.txt") as f:
+ file_contents = f.read()
+ self.assertEqual("a\nb\nc", file_contents)
+ rm(src_out_dir)
+ rm(dst_out_dir_parent)
+
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
diff --git a/docs-public/build.gradle b/docs-public/build.gradle
index 8f3fa73..5b2a169 100644
--- a/docs-public/build.gradle
+++ b/docs-public/build.gradle
@@ -32,47 +32,47 @@
docs("androidx.cardview:cardview:1.0.0")
docs("androidx.collection:collection:1.2.0-alpha01")
docs("androidx.collection:collection-ktx:1.2.0-alpha01")
- docs("androidx.compose.animation:animation:1.0.0-alpha11")
- docs("androidx.compose.animation:animation-core:1.0.0-alpha11")
- samples("androidx.compose.animation:animation-samples:1.0.0-alpha11")
- samples("androidx.compose.animation:animation-core-samples:1.0.0-alpha11")
- docs("androidx.compose.foundation:foundation:1.0.0-alpha11")
- docs("androidx.compose.foundation:foundation-layout:1.0.0-alpha11")
- samples("androidx.compose.foundation:foundation-layout-samples:1.0.0-alpha11")
- samples("androidx.compose.foundation:foundation-samples:1.0.0-alpha11")
- docs("androidx.compose.material:material:1.0.0-alpha11")
- docs("androidx.compose.material:material-icons-core:1.0.0-alpha11")
- samples("androidx.compose.material:material-icons-core-samples:1.0.0-alpha11")
- docs("androidx.compose.material:material-icons-extended:1.0.0-alpha11")
- docs("androidx.compose.material:material-ripple:1.0.0-alpha11")
- samples("androidx.compose.material:material-samples:1.0.0-alpha11")
- docs("androidx.compose.runtime:runtime:1.0.0-alpha11")
- docs("androidx.compose.runtime:runtime-dispatch:1.0.0-alpha11")
- docs("androidx.compose.runtime:runtime-livedata:1.0.0-alpha11")
- samples("androidx.compose.runtime:runtime-livedata-samples:1.0.0-alpha11")
- docs("androidx.compose.runtime:runtime-rxjava2:1.0.0-alpha11")
- samples("androidx.compose.runtime:runtime-rxjava2-samples:1.0.0-alpha11")
- docs("androidx.compose.runtime:runtime-rxjava3:1.0.0-alpha11")
- samples("androidx.compose.runtime:runtime-rxjava3-samples:1.0.0-alpha11")
- docs("androidx.compose.runtime:runtime-saved-instance-state:1.0.0-alpha11")
- samples("androidx.compose.runtime:runtime-saved-instance-state-samples:1.0.0-alpha11")
- samples("androidx.compose.runtime:runtime-samples:1.0.0-alpha11")
- docs("androidx.compose.ui:ui:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-geometry:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-graphics:1.0.0-alpha11")
- samples("androidx.compose.ui:ui-graphics-samples:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-test:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-test-junit4:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-text:1.0.0-alpha11")
+ docs("androidx.compose.animation:animation:1.0.0-alpha10")
+ docs("androidx.compose.animation:animation-core:1.0.0-alpha10")
+ samples("androidx.compose.animation:animation-samples:1.0.0-alpha10")
+ samples("androidx.compose.animation:animation-core-samples:1.0.0-alpha10")
+ docs("androidx.compose.foundation:foundation:1.0.0-alpha10")
+ docs("androidx.compose.foundation:foundation-layout:1.0.0-alpha10")
+ samples("androidx.compose.foundation:foundation-layout-samples:1.0.0-alpha10")
+ samples("androidx.compose.foundation:foundation-samples:1.0.0-alpha10")
+ docs("androidx.compose.material:material:1.0.0-alpha10")
+ docs("androidx.compose.material:material-icons-core:1.0.0-alpha10")
+ samples("androidx.compose.material:material-icons-core-samples:1.0.0-alpha10")
+ docs("androidx.compose.material:material-icons-extended:1.0.0-alpha10")
+ docs("androidx.compose.material:material-ripple:1.0.0-alpha10")
+ samples("androidx.compose.material:material-samples:1.0.0-alpha10")
+ docs("androidx.compose.runtime:runtime:1.0.0-alpha10")
+ docs("androidx.compose.runtime:runtime-dispatch:1.0.0-alpha10")
+ docs("androidx.compose.runtime:runtime-livedata:1.0.0-alpha10")
+ samples("androidx.compose.runtime:runtime-livedata-samples:1.0.0-alpha10")
+ docs("androidx.compose.runtime:runtime-rxjava2:1.0.0-alpha10")
+ samples("androidx.compose.runtime:runtime-rxjava2-samples:1.0.0-alpha10")
+ docs("androidx.compose.runtime:runtime-rxjava3:1.0.0-alpha10")
+ samples("androidx.compose.runtime:runtime-rxjava3-samples:1.0.0-alpha10")
+ docs("androidx.compose.runtime:runtime-saved-instance-state:1.0.0-alpha10")
+ samples("androidx.compose.runtime:runtime-saved-instance-state-samples:1.0.0-alpha10")
+ samples("androidx.compose.runtime:runtime-samples:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-geometry:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-graphics:1.0.0-alpha10")
+ samples("androidx.compose.ui:ui-graphics-samples:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-test:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-test-junit4:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-text:1.0.0-alpha10")
docs("androidx.compose.ui:ui-text-android:1.0.0-alpha06")
- samples("androidx.compose.ui:ui-text-samples:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-tooling:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-unit:1.0.0-alpha11")
- samples("androidx.compose.ui:ui-unit-samples:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-util:1.0.0-alpha11")
- docs("androidx.compose.ui:ui-viewbinding:1.0.0-alpha11")
- samples("androidx.compose.ui:ui-viewbinding-samples:1.0.0-alpha11")
- samples("androidx.compose.ui:ui-samples:1.0.0-alpha11")
+ samples("androidx.compose.ui:ui-text-samples:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-tooling:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-unit:1.0.0-alpha10")
+ samples("androidx.compose.ui:ui-unit-samples:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-util:1.0.0-alpha10")
+ docs("androidx.compose.ui:ui-viewbinding:1.0.0-alpha10")
+ samples("androidx.compose.ui:ui-viewbinding-samples:1.0.0-alpha10")
+ samples("androidx.compose.ui:ui-samples:1.0.0-alpha10")
docs("androidx.concurrent:concurrent-futures:1.1.0")
docs("androidx.concurrent:concurrent-futures-ktx:1.1.0")
docs("androidx.contentpager:contentpager:1.0.0")
@@ -117,22 +117,22 @@
docs("androidx.leanback:leanback-paging:1.1.0-alpha07")
docs("androidx.leanback:leanback-preference:1.1.0-beta01")
docs("androidx.leanback:leanback-tab:1.1.0-beta01")
- docs("androidx.lifecycle:lifecycle-common:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-common-java8:2.3.0-rc01")
+ docs("androidx.lifecycle:lifecycle-common:2.3.0")
+ docs("androidx.lifecycle:lifecycle-common-java8:2.3.0")
docs("androidx.lifecycle:lifecycle-extensions:2.2.0")
- docs("androidx.lifecycle:lifecycle-livedata:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-livedata-core:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-livedata-core-ktx:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-process:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-reactivestreams:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-reactivestreams-ktx:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-runtime:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-service:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-viewmodel:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-rc01")
- docs("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-rc01")
+ docs("androidx.lifecycle:lifecycle-livedata:2.3.0")
+ docs("androidx.lifecycle:lifecycle-livedata-core:2.3.0")
+ docs("androidx.lifecycle:lifecycle-livedata-core-ktx:2.3.0")
+ docs("androidx.lifecycle:lifecycle-livedata-ktx:2.3.0")
+ docs("androidx.lifecycle:lifecycle-process:2.3.0")
+ docs("androidx.lifecycle:lifecycle-reactivestreams:2.3.0")
+ docs("androidx.lifecycle:lifecycle-reactivestreams-ktx:2.3.0")
+ docs("androidx.lifecycle:lifecycle-runtime:2.3.0")
+ docs("androidx.lifecycle:lifecycle-runtime-ktx:2.3.0")
+ docs("androidx.lifecycle:lifecycle-service:2.3.0")
+ docs("androidx.lifecycle:lifecycle-viewmodel:2.3.0")
+ docs("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0")
+ docs("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0")
docs("androidx.loader:loader:1.1.0")
docs("androidx.localbroadcastmanager:localbroadcastmanager:1.1.0-alpha01")
docs("androidx.media2:media2-common:1.1.2")
@@ -156,7 +156,7 @@
docs("androidx.navigation:navigation-ui-ktx:2.3.3")
docs("androidx.paging:paging-common:3.0.0-alpha13")
docs("androidx.paging:paging-common-ktx:3.0.0-alpha13")
- docs("androidx.paging:paging-compose:1.0.0-alpha06")
+ docs("androidx.paging:paging-compose:1.0.0-alpha05")
samples("androidx.paging:paging-compose-samples:3.0.0-alpha08")
docs("androidx.paging:paging-guava:3.0.0-alpha13")
docs("androidx.paging:paging-runtime:3.0.0-alpha13")
@@ -183,8 +183,8 @@
docs("androidx.room:room-rxjava2:2.3.0-beta01")
docs("androidx.room:room-rxjava3:2.3.0-beta01")
docs("androidx.room:room-testing:2.3.0-beta01")
- docs("androidx.savedstate:savedstate:1.1.0-rc01")
- docs("androidx.savedstate:savedstate-ktx:1.1.0-rc01")
+ docs("androidx.savedstate:savedstate:1.1.0")
+ docs("androidx.savedstate:savedstate-ktx:1.1.0")
docs("androidx.security:security-crypto:1.1.0-alpha03")
docs("androidx.security:security-crypto-ktx:1.1.0-alpha02")
docs("androidx.security:security-identity-credential:1.0.0-alpha01")
diff --git a/docs/api_guidelines.md b/docs/api_guidelines.md
index 9b1fcb7..fd7b5bb 100644
--- a/docs/api_guidelines.md
+++ b/docs/api_guidelines.md
@@ -60,19 +60,20 @@
scenario:
* `androidx.library:1.0.0`
- * contains classes `androidx.library.A` and `androidx.library.util.B`
+ * contains class `androidx.library.A`
+ * contains class `androidx.library.util.B`
This module is split, moving `androidx.library.util.B` to a new module:
* `androidx.library:1.1.0`
* contains class `androidx.library.A`
- * depends on `androidx.library.util:1.0.0`
-* `androidx.library.util:1.0.0`
- * depends on `androidx.library.util.B`
+ * depends on `androidx.library.util:1.1.0`
+* `androidx.library.util:1.1.0`
+ * contains class `androidx.library.util.B`
-A developer writes an app that depends directly on `androidx.library.util:1.0.0`
-and transitively pulls in `androidx.library:1.0.0`. Their app will no longer
-compile due to class duplication of `androidx.library.util.B`.
+A developer writes an app that depends directly on `androidx.library.util:1.1.0`
+and also transitively pulls in `androidx.library:1.0.0`. Their app will no
+longer compile due to class duplication of `androidx.library.util.B`.
While it is possible for the developer to fix this by manually specifying a
dependency on `androidx.library:1.1.0`, there is no easy way for the developer
@@ -960,9 +961,16 @@
### Kotlin {#dependencies-kotlin}
-Kotlin is _recommended_ for new libraries; however, it's important to consider
-its size impact on clients. Currently, the Kotlin stdlib adds a minimum of 40kB
-post-optimization.
+Kotlin is _strongly recommended_ for new libraries; however, it's important to
+consider its size impact on clients. Currently, the Kotlin stdlib adds a minimum
+of 40kB post-optimization. It may not make sense to use Kotlin for a library
+that targets Java-only clients or space-constrained (ex. Android Go) clients.
+
+Existing Java-based libraries are _strongly discouraged_ from using Kotlin,
+primarily because our documentation system does not currently provide a
+Java-facing version of Kotlin API reference docs. Java-based libraries _may_
+migrate to Kotlin, but they must consider the docs usability and size impacts on
+existing Java-only and space-constrained clients.
### Kotlin coroutines {#dependencies-coroutines}
diff --git a/docs/policies.md b/docs/policies.md
index f42d6dc..0b790f5 100644
--- a/docs/policies.md
+++ b/docs/policies.md
@@ -21,10 +21,10 @@
```
<feature-name>/
<feature-name>-<sub-feature>/ [<feature-name>:<feature-name>-<sub-feature>]
+ samples/ [<feature-name>:<feature-name>-<sub-feature>:samples]
integration-tests/
testapp/ [<feature-name>:testapp]
testlib/ [<feature-name>:testlib]
- samples/ [<feature-name>:samples]
```
For example, the `navigation` library group's directory structure is:
diff --git a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/DexInspectorTask.kt b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/DexInspectorTask.kt
index b10b84b..4fa04be 100644
--- a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/DexInspectorTask.kt
+++ b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/DexInspectorTask.kt
@@ -73,12 +73,14 @@
fun Project.registerDexInspectorTask(
variant: BaseVariant,
extension: BaseExtension,
+ jarName: String?,
jar: TaskProvider<out Jar>
): TaskProvider<DexInspectorTask> {
return tasks.register(variant.taskName("dexInspector"), DexInspectorTask::class.java) {
it.setDx(extension.sdkDirectory, extension.buildToolsVersion)
it.jars.from(jar.get().destinationDirectory)
- val out = File(taskWorkingDir(variant, "dexedInspector"), "${project.name}.jar")
+ val name = jarName ?: "${project.name}.jar"
+ val out = File(taskWorkingDir(variant, "dexedInspector"), name)
it.outputFile.set(out)
it.dependsOn(jar)
}
diff --git a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt
index 81df245..9ee34da 100644
--- a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt
+++ b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt
@@ -27,6 +27,7 @@
import org.gradle.api.tasks.StopExecutionException
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.apply
+import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getPlugin
import java.io.File
@@ -44,6 +45,7 @@
override fun apply(project: Project) {
var foundLibraryPlugin = false
var foundReleaseVariant = false
+ val extension = project.extensions.create<InspectionExtension>(EXTENSION_NAME, project)
project.pluginManager.withPlugin("com.android.library") {
foundLibraryPlugin = true
val libExtension = project.extensions.getByType(LibraryExtension::class.java)
@@ -53,7 +55,9 @@
foundReleaseVariant = true
val unzip = project.registerUnzipTask(variant)
val shadowJar = project.registerShadowDependenciesTask(variant, unzip)
- dexTask = project.registerDexInspectorTask(variant, libExtension, shadowJar)
+ dexTask = project.registerDexInspectorTask(
+ variant, libExtension, extension.name, shadowJar
+ )
}
}
libExtension.sourceSets.findByName("main")!!.resources.srcDirs(
@@ -141,4 +145,13 @@
libExtension.libraryVariants.all { variant ->
libraryProject.registerGenerateProguardDetectionFileTask(variant)
}
+}
+
+const val EXTENSION_NAME = "inspection"
+
+open class InspectionExtension(@Suppress("UNUSED_PARAMETER") project: Project) {
+ /**
+ * Name of built inspector artifact, if not provided it is equal to project's name.
+ */
+ var name: String? = null
}
\ No newline at end of file
diff --git a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/ShadowDependenciesTask.kt b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/ShadowDependenciesTask.kt
index 853628b..9f1a0fb 100644
--- a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/ShadowDependenciesTask.kt
+++ b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/ShadowDependenciesTask.kt
@@ -40,6 +40,12 @@
val fileTree = project.fileTree(zipTask.get().destinationDir)
fileTree.include("**/*.jar", "**/*.so")
it.from(fileTree)
+ it.includeEmptyDirs = false
+ it.filesMatching("**/*.so") {
+ if (it.path.startsWith("jni")) {
+ it.path = "lib/${it.path.removePrefix("jni")}"
+ }
+ }
it.destinationDirectory.set(taskWorkingDir(variant, "shadowedJar"))
it.archiveBaseName.set("${project.name}-shadowed")
it.dependsOn(zipTask)
diff --git a/navigation/navigation-common/api/api_lint.ignore b/navigation/navigation-common/api/api_lint.ignore
index 99cd5e3..496b83c 100644
--- a/navigation/navigation-common/api/api_lint.ignore
+++ b/navigation/navigation-common/api/api_lint.ignore
@@ -1,4 +1,28 @@
// Baseline format: 1.0
+AllUpper: androidx.navigation.NavType#BoolArrayType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#BoolArrayType`, should be `BOOL_ARRAY_TYPE`?
+AllUpper: androidx.navigation.NavType#BoolType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#BoolType`, should be `BOOL_TYPE`?
+AllUpper: androidx.navigation.NavType#FloatArrayType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#FloatArrayType`, should be `FLOAT_ARRAY_TYPE`?
+AllUpper: androidx.navigation.NavType#FloatType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#FloatType`, should be `FLOAT_TYPE`?
+AllUpper: androidx.navigation.NavType#IntArrayType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#IntArrayType`, should be `INT_ARRAY_TYPE`?
+AllUpper: androidx.navigation.NavType#IntType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#IntType`, should be `INT_TYPE`?
+AllUpper: androidx.navigation.NavType#LongArrayType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#LongArrayType`, should be `LONG_ARRAY_TYPE`?
+AllUpper: androidx.navigation.NavType#LongType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#LongType`, should be `LONG_TYPE`?
+AllUpper: androidx.navigation.NavType#ReferenceType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#ReferenceType`, should be `REFERENCE_TYPE`?
+AllUpper: androidx.navigation.NavType#StringArrayType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#StringArrayType`, should be `STRING_ARRAY_TYPE`?
+AllUpper: androidx.navigation.NavType#StringType:
+ Constant field names must be named with only upper case characters: `androidx.navigation.NavType#StringType`, should be `STRING_TYPE`?
+
+
ArrayReturn: androidx.navigation.NavType.ParcelableArrayType#get(android.os.Bundle, String):
Method should return Collection<D> (or subclass) instead of raw array; was `D[]`
ArrayReturn: androidx.navigation.NavType.ParcelableArrayType#parseValue(String):
diff --git a/navigation/navigation-common/build.gradle b/navigation/navigation-common/build.gradle
index 3a15524..22a2bc5 100644
--- a/navigation/navigation-common/build.gradle
+++ b/navigation/navigation-common/build.gradle
@@ -28,8 +28,8 @@
dependencies {
api("androidx.annotation:annotation:1.1.0")
- implementation("androidx.core:core:1.1.0")
- implementation("androidx.collection:collection:1.1.0")
+ implementation("androidx.core:core-ktx:1.1.0")
+ implementation("androidx.collection:collection-ktx:1.1.0")
api(KOTLIN_STDLIB)
testImplementation(JUNIT)
diff --git a/navigation/navigation-fragment/build.gradle b/navigation/navigation-fragment/build.gradle
index 553469e..98390ed 100644
--- a/navigation/navigation-fragment/build.gradle
+++ b/navigation/navigation-fragment/build.gradle
@@ -27,10 +27,9 @@
}
dependencies {
- api("androidx.fragment:fragment:1.2.4")
- api(project(":navigation:navigation-runtime"))
+ api("androidx.fragment:fragment-ktx:1.2.4")
+ api(project(":navigation:navigation-runtime-ktx"))
- androidTestImplementation(project(":navigation:navigation-runtime-ktx"))
androidTestImplementation(ANDROIDX_TEST_EXT_JUNIT)
androidTestImplementation(ANDROIDX_TEST_CORE)
androidTestImplementation(ANDROIDX_TEST_RUNNER)
diff --git a/navigation/navigation-runtime/build.gradle b/navigation/navigation-runtime/build.gradle
index 718f4f9..43e324a 100644
--- a/navigation/navigation-runtime/build.gradle
+++ b/navigation/navigation-runtime/build.gradle
@@ -28,12 +28,13 @@
}
dependencies {
- api(project(":navigation:navigation-common"))
- api("androidx.activity:activity:1.1.0")
- api("androidx.lifecycle:lifecycle-viewmodel:2.2.0")
+ api(project(":navigation:navigation-common-ktx"))
+ api("androidx.activity:activity-ktx:1.1.0")
+ api("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0")
api("androidx.savedstate:savedstate:1.0.0")
api("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0")
+ api(KOTLIN_STDLIB)
androidTestImplementation(projectOrArtifact(":lifecycle:lifecycle-runtime-testing"))
androidTestImplementation(project(":internal-testutils-navigation"))
androidTestImplementation(ANDROIDX_TEST_EXT_JUNIT)
diff --git a/navigation/navigation-runtime/src/main/java/androidx/navigation/NavBackStackEntryState.java b/navigation/navigation-runtime/src/main/java/androidx/navigation/NavBackStackEntryState.java
deleted file mode 100644
index 5dd3b7e..0000000
--- a/navigation/navigation-runtime/src/main/java/androidx/navigation/NavBackStackEntryState.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2019 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 androidx.navigation;
-
-import android.annotation.SuppressLint;
-import android.os.Bundle;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import java.util.UUID;
-
-@SuppressLint("BanParcelableUsage")
-final class NavBackStackEntryState implements Parcelable {
-
- private final UUID mUUID;
- private final int mDestinationId;
- private final Bundle mArgs;
- private final Bundle mSavedState;
-
- NavBackStackEntryState(NavBackStackEntry entry) {
- mUUID = entry.mId;
- mDestinationId = entry.getDestination().getId();
- mArgs = entry.getArguments();
- mSavedState = new Bundle();
- entry.saveState(mSavedState);
- }
-
- @SuppressWarnings("WeakerAccess")
- NavBackStackEntryState(Parcel in) {
- mUUID = UUID.fromString(in.readString());
- mDestinationId = in.readInt();
- mArgs = in.readBundle(getClass().getClassLoader());
- mSavedState = in.readBundle(getClass().getClassLoader());
- }
-
- @NonNull
- UUID getUUID() {
- return mUUID;
- }
-
- int getDestinationId() {
- return mDestinationId;
- }
-
- @Nullable
- Bundle getArgs() {
- return mArgs;
- }
-
- @NonNull
- Bundle getSavedState() {
- return mSavedState;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel parcel, int i) {
- parcel.writeString(mUUID.toString());
- parcel.writeInt(mDestinationId);
- parcel.writeBundle(mArgs);
- parcel.writeBundle(mSavedState);
- }
-
- public static final Parcelable.Creator<NavBackStackEntryState> CREATOR =
- new Parcelable.Creator<NavBackStackEntryState>() {
- @Override
- public NavBackStackEntryState createFromParcel(Parcel in) {
- return new NavBackStackEntryState(in);
- }
-
- @Override
- public NavBackStackEntryState[] newArray(int size) {
- return new NavBackStackEntryState[size];
- }
- };
-}
diff --git a/navigation/navigation-runtime/src/main/java/androidx/navigation/NavBackStackEntryState.kt b/navigation/navigation-runtime/src/main/java/androidx/navigation/NavBackStackEntryState.kt
new file mode 100644
index 0000000..fcb4b47
--- /dev/null
+++ b/navigation/navigation-runtime/src/main/java/androidx/navigation/NavBackStackEntryState.kt
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2019 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 androidx.navigation
+
+import android.annotation.SuppressLint
+import android.os.Bundle
+import android.os.Parcelable
+import android.os.Parcel
+import java.util.UUID
+
+@SuppressLint("BanParcelableUsage")
+internal class NavBackStackEntryState : Parcelable {
+ val uuid: UUID
+ val destinationId: Int
+ val args: Bundle?
+ val savedState: Bundle
+
+ constructor(entry: NavBackStackEntry) {
+ uuid = entry.mId
+ destinationId = entry.destination.id
+ args = entry.arguments
+ savedState = Bundle()
+ entry.saveState(savedState)
+ }
+
+ constructor(inParcel: Parcel) {
+ uuid = UUID.fromString(inParcel.readString())
+ destinationId = inParcel.readInt()
+ args = inParcel.readBundle(javaClass.classLoader)
+ savedState = inParcel.readBundle(javaClass.classLoader)!!
+ }
+
+ override fun describeContents(): Int {
+ return 0
+ }
+
+ override fun writeToParcel(parcel: Parcel, i: Int) {
+ parcel.writeString(uuid.toString())
+ parcel.writeInt(destinationId)
+ parcel.writeBundle(args)
+ parcel.writeBundle(savedState)
+ }
+
+ companion object {
+ @JvmField
+ val CREATOR: Parcelable.Creator<NavBackStackEntryState> =
+ object : Parcelable.Creator<NavBackStackEntryState> {
+ override fun createFromParcel(inParcel: Parcel): NavBackStackEntryState {
+ return NavBackStackEntryState(inParcel)
+ }
+
+ override fun newArray(size: Int): Array<NavBackStackEntryState?> {
+ return arrayOfNulls(size)
+ }
+ }
+ }
+}
diff --git a/navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.java b/navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.java
index afd3cf0..6850ae1 100644
--- a/navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.java
+++ b/navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.java
@@ -626,7 +626,7 @@
}
NavBackStackEntry entry = new NavBackStackEntry(mContext, node, args,
mLifecycleOwner, mViewModel,
- state.getUUID(), state.getSavedState());
+ state.getUuid(), state.getSavedState());
mBackStack.add(entry);
}
updateOnBackPressedCallbackEnabled();
diff --git a/navigation/navigation-ui/build.gradle b/navigation/navigation-ui/build.gradle
index fc8a935..9450761 100644
--- a/navigation/navigation-ui/build.gradle
+++ b/navigation/navigation-ui/build.gradle
@@ -33,13 +33,12 @@
}
dependencies {
- api(project(":navigation:navigation-runtime"))
+ api(project(":navigation:navigation-runtime-ktx"))
api("androidx.customview:customview:1.1.0")
api("androidx.drawerlayout:drawerlayout:1.1.1")
api('com.google.android.material:material:1.0.0')
implementation('androidx.transition:transition:1.3.0')
- androidTestImplementation(project(":navigation:navigation-runtime-ktx"))
androidTestImplementation(project(":internal-testutils-navigation"), {
exclude group: 'androidx.navigation', module: 'navigation-common-ktx'
})
diff --git a/navigation/navigation-ui/src/main/java/androidx/navigation/ui/CollapsingToolbarOnDestinationChangedListener.java b/navigation/navigation-ui/src/main/java/androidx/navigation/ui/CollapsingToolbarOnDestinationChangedListener.java
deleted file mode 100644
index a7abd06..0000000
--- a/navigation/navigation-ui/src/main/java/androidx/navigation/ui/CollapsingToolbarOnDestinationChangedListener.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2018 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 androidx.navigation.ui;
-
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.RestrictTo;
-import androidx.annotation.StringRes;
-import androidx.appcompat.widget.Toolbar;
-import androidx.navigation.NavController;
-import androidx.navigation.NavDestination;
-import androidx.transition.TransitionManager;
-
-import com.google.android.material.appbar.CollapsingToolbarLayout;
-
-import java.lang.ref.WeakReference;
-
-/**
- * The OnDestinationChangedListener specifically for keeping a
- * CollapsingToolbarLayout+Toolbar updated.
- * This handles both updating the title and updating the Up Indicator, transitioning between
- * the drawer icon and up arrow as needed.
- * @hide
- */
-@RestrictTo(RestrictTo.Scope.LIBRARY)
-class CollapsingToolbarOnDestinationChangedListener
- extends AbstractAppBarOnDestinationChangedListener {
- private final WeakReference<CollapsingToolbarLayout> mCollapsingToolbarLayoutWeakReference;
- private final WeakReference<Toolbar> mToolbarWeakReference;
-
- CollapsingToolbarOnDestinationChangedListener(
- @NonNull CollapsingToolbarLayout collapsingToolbarLayout,
- @NonNull Toolbar toolbar, @NonNull AppBarConfiguration configuration) {
- super(collapsingToolbarLayout.getContext(), configuration);
- mCollapsingToolbarLayoutWeakReference = new WeakReference<>(collapsingToolbarLayout);
- mToolbarWeakReference = new WeakReference<>(toolbar);
- }
-
- @Override
- public void onDestinationChanged(@NonNull NavController controller,
- @NonNull NavDestination destination, @Nullable Bundle arguments) {
- CollapsingToolbarLayout collapsingToolbarLayout =
- mCollapsingToolbarLayoutWeakReference.get();
- Toolbar toolbar = mToolbarWeakReference.get();
- if (collapsingToolbarLayout == null || toolbar == null) {
- controller.removeOnDestinationChangedListener(this);
- return;
- }
- super.onDestinationChanged(controller, destination, arguments);
- }
-
- @Override
- protected void setTitle(CharSequence title) {
- CollapsingToolbarLayout collapsingToolbarLayout =
- mCollapsingToolbarLayoutWeakReference.get();
- if (collapsingToolbarLayout != null) {
- collapsingToolbarLayout.setTitle(title);
- }
- }
-
- @Override
- protected void setNavigationIcon(Drawable icon,
- @StringRes int contentDescription) {
- Toolbar toolbar = mToolbarWeakReference.get();
- if (toolbar != null) {
- boolean useTransition = icon == null && toolbar.getNavigationIcon() != null;
- toolbar.setNavigationIcon(icon);
- toolbar.setNavigationContentDescription(contentDescription);
- if (useTransition) {
- TransitionManager.beginDelayedTransition(toolbar);
- }
- }
- }
-}
diff --git a/navigation/navigation-ui/src/main/java/androidx/navigation/ui/CollapsingToolbarOnDestinationChangedListener.kt b/navigation/navigation-ui/src/main/java/androidx/navigation/ui/CollapsingToolbarOnDestinationChangedListener.kt
new file mode 100644
index 0000000..faa449d
--- /dev/null
+++ b/navigation/navigation-ui/src/main/java/androidx/navigation/ui/CollapsingToolbarOnDestinationChangedListener.kt
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2018 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 androidx.navigation.ui
+
+import android.graphics.drawable.Drawable
+import android.os.Bundle
+import androidx.annotation.RestrictTo
+import androidx.annotation.StringRes
+import androidx.appcompat.widget.Toolbar
+import androidx.navigation.NavController
+import androidx.navigation.NavDestination
+import androidx.transition.TransitionManager
+import com.google.android.material.appbar.CollapsingToolbarLayout
+import java.lang.ref.WeakReference
+
+/**
+ * The OnDestinationChangedListener specifically for keeping a
+ * CollapsingToolbarLayout+Toolbar updated.
+ * This handles both updating the title and updating the Up Indicator, transitioning between
+ * the drawer icon and up arrow as needed.
+ * @hide
+ */
+@RestrictTo(RestrictTo.Scope.LIBRARY)
+internal class CollapsingToolbarOnDestinationChangedListener(
+ collapsingToolbarLayout: CollapsingToolbarLayout,
+ toolbar: Toolbar,
+ configuration: AppBarConfiguration
+) : AbstractAppBarOnDestinationChangedListener(collapsingToolbarLayout.context, configuration) {
+
+ private val mCollapsingToolbarLayoutWeakReference: WeakReference<CollapsingToolbarLayout> =
+ WeakReference(collapsingToolbarLayout)
+ private val mToolbarWeakReference: WeakReference<Toolbar> = WeakReference(toolbar)
+
+ override fun onDestinationChanged(
+ controller: NavController,
+ destination: NavDestination,
+ arguments: Bundle?
+ ) {
+ val collapsingToolbarLayout = mCollapsingToolbarLayoutWeakReference.get()
+ val toolbar = mToolbarWeakReference.get()
+ if (collapsingToolbarLayout == null || toolbar == null) {
+ controller.removeOnDestinationChangedListener(this)
+ return
+ }
+ super.onDestinationChanged(controller, destination, arguments)
+ }
+
+ override fun setTitle(title: CharSequence) {
+ val collapsingToolbarLayout = mCollapsingToolbarLayoutWeakReference.get()
+ if (collapsingToolbarLayout != null) {
+ collapsingToolbarLayout.title = title
+ }
+ }
+
+ override fun setNavigationIcon(icon: Drawable?, @StringRes contentDescription: Int) {
+ val toolbar = mToolbarWeakReference.get()
+ if (toolbar != null) {
+ val useTransition = icon == null && toolbar.navigationIcon != null
+ toolbar.navigationIcon = icon
+ toolbar.setNavigationContentDescription(contentDescription)
+ if (useTransition) {
+ TransitionManager.beginDelayedTransition(toolbar)
+ }
+ }
+ }
+}
diff --git a/navigation/navigation-ui/src/main/java/androidx/navigation/ui/ToolbarOnDestinationChangedListener.java b/navigation/navigation-ui/src/main/java/androidx/navigation/ui/ToolbarOnDestinationChangedListener.java
deleted file mode 100644
index 0715dd2..0000000
--- a/navigation/navigation-ui/src/main/java/androidx/navigation/ui/ToolbarOnDestinationChangedListener.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2018 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 androidx.navigation.ui;
-
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.RestrictTo;
-import androidx.annotation.StringRes;
-import androidx.appcompat.widget.Toolbar;
-import androidx.navigation.NavController;
-import androidx.navigation.NavDestination;
-import androidx.transition.TransitionManager;
-
-import java.lang.ref.WeakReference;
-
-/**
- * The OnDestinationChangedListener specifically for keeping a Toolbar updated.
- * This handles both updating the title and updating the Up Indicator, transitioning between
- * the drawer icon and up arrow as needed.
- * @hide
- */
-@RestrictTo(RestrictTo.Scope.LIBRARY)
-class ToolbarOnDestinationChangedListener extends
- AbstractAppBarOnDestinationChangedListener {
- private final WeakReference<Toolbar> mToolbarWeakReference;
-
- ToolbarOnDestinationChangedListener(
- @NonNull Toolbar toolbar, @NonNull AppBarConfiguration configuration) {
- super(toolbar.getContext(), configuration);
- mToolbarWeakReference = new WeakReference<>(toolbar);
- }
-
- @Override
- public void onDestinationChanged(@NonNull NavController controller,
- @NonNull NavDestination destination, @Nullable Bundle arguments) {
- Toolbar toolbar = mToolbarWeakReference.get();
- if (toolbar == null) {
- controller.removeOnDestinationChangedListener(this);
- return;
- }
- super.onDestinationChanged(controller, destination, arguments);
- }
-
- @Override
- protected void setTitle(CharSequence title) {
- mToolbarWeakReference.get().setTitle(title);
- }
-
- @Override
- protected void setNavigationIcon(Drawable icon,
- @StringRes int contentDescription) {
- Toolbar toolbar = mToolbarWeakReference.get();
- if (toolbar != null) {
- boolean useTransition = icon == null && toolbar.getNavigationIcon() != null;
- toolbar.setNavigationIcon(icon);
- toolbar.setNavigationContentDescription(contentDescription);
- if (useTransition) {
- TransitionManager.beginDelayedTransition(toolbar);
- }
- }
- }
-}
diff --git a/navigation/navigation-ui/src/main/java/androidx/navigation/ui/ToolbarOnDestinationChangedListener.kt b/navigation/navigation-ui/src/main/java/androidx/navigation/ui/ToolbarOnDestinationChangedListener.kt
new file mode 100644
index 0000000..4e8b808
--- /dev/null
+++ b/navigation/navigation-ui/src/main/java/androidx/navigation/ui/ToolbarOnDestinationChangedListener.kt
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2018 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 androidx.navigation.ui
+
+import android.graphics.drawable.Drawable
+import android.os.Bundle
+import androidx.annotation.RestrictTo
+import androidx.annotation.StringRes
+import androidx.appcompat.widget.Toolbar
+import androidx.navigation.NavController
+import androidx.navigation.NavDestination
+import androidx.transition.TransitionManager
+import java.lang.ref.WeakReference
+
+/**
+ * The OnDestinationChangedListener specifically for keeping a Toolbar updated.
+ * This handles both updating the title and updating the Up Indicator, transitioning between
+ * the drawer icon and up arrow as needed.
+ * @hide
+ */
+@RestrictTo(RestrictTo.Scope.LIBRARY)
+internal class ToolbarOnDestinationChangedListener(
+ toolbar: Toolbar,
+ configuration: AppBarConfiguration
+) : AbstractAppBarOnDestinationChangedListener(toolbar.context, configuration) {
+ private val toolbarWeakReference: WeakReference<Toolbar> = WeakReference(toolbar)
+
+ override fun onDestinationChanged(
+ controller: NavController,
+ destination: NavDestination,
+ arguments: Bundle?
+ ) {
+ val toolbar = toolbarWeakReference.get()
+ if (toolbar == null) {
+ controller.removeOnDestinationChangedListener(this)
+ return
+ }
+ super.onDestinationChanged(controller, destination, arguments)
+ }
+
+ override fun setTitle(title: CharSequence) {
+ toolbarWeakReference.get()?.let { toolbar ->
+ toolbar.title = title
+ }
+ }
+
+ override fun setNavigationIcon(icon: Drawable?, @StringRes contentDescription: Int) {
+ toolbarWeakReference.get()?.run {
+ val useTransition = icon == null && navigationIcon != null
+ navigationIcon = icon
+ setNavigationContentDescription(contentDescription)
+ if (useTransition) {
+ TransitionManager.beginDelayedTransition(this)
+ }
+ }
+ }
+}
diff --git a/room/runtime/src/androidTest/java/androidx/room/AutoCloserTest.kt b/room/runtime/src/androidTest/java/androidx/room/AutoCloserTest.kt
index 1a6147b..8deb8c2 100644
--- a/room/runtime/src/androidTest/java/androidx/room/AutoCloserTest.kt
+++ b/room/runtime/src/androidTest/java/androidx/room/AutoCloserTest.kt
@@ -198,7 +198,8 @@
assertThat(db.isOpen).isFalse()
- assertThrows<IllegalStateException> { db.execSQL("select * from users") }
+ assertThrows<IllegalStateException> { db.query("select * from users").close() }
+ .hasMessageThat().contains("closed")
autoCloser.decrementCountAndScheduleClose() // Should succeed
diff --git a/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperFactoryTest.kt b/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperFactoryTest.kt
index 9603a47..f4ad009 100644
--- a/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperFactoryTest.kt
+++ b/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperFactoryTest.kt
@@ -17,6 +17,7 @@
package androidx.room
import android.content.Context
+import android.os.Build.VERSION_CODES.JELLY_BEAN
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
@@ -83,11 +84,28 @@
autoClosingRoomOpenHelper.writableDatabase
- assertEquals(3, callbackCount.get())
+ if (android.os.Build.VERSION.SDK_INT < JELLY_BEAN) {
+ // onConfigure does not exist before JELLY_BEAN
+ // onCreate + onOpen
+ assertEquals(2, callbackCount.get())
+ } else {
+ // onConfigure + onCreate + onOpen
+ assertEquals(3, callbackCount.get())
+ }
+
Thread.sleep(100)
autoClosingRoomOpenHelper.writableDatabase
- assertEquals(5, callbackCount.get()) // onCreate won't be called the second time.
+
+ // onCreate won't be called the second time.
+ if (android.os.Build.VERSION.SDK_INT < JELLY_BEAN) {
+ // onConfigure does not exist before JELLY_BEAN
+ // onCreate + onOpen + onOpen
+ assertEquals(3, callbackCount.get())
+ } else {
+ // onConfigure + onCreate + onOpen + onConfigure + onOpen
+ assertEquals(5, callbackCount.get())
+ }
}
@Test
diff --git a/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperTest.kt b/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperTest.kt
index d673e4c..dd0693c 100644
--- a/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperTest.kt
+++ b/room/runtime/src/androidTest/java/androidx/room/AutoClosingRoomOpenHelperTest.kt
@@ -17,11 +17,14 @@
package androidx.room
import android.content.Context
+import android.database.Cursor
import android.database.sqlite.SQLiteException
+import android.os.Build
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
import androidx.test.core.app.ApplicationProvider
+import androidx.test.filters.SdkSuppress
import androidx.testutils.assertThrows
import com.google.common.truth.Truth.assertThat
import org.junit.Before
@@ -110,6 +113,7 @@
}
@Test
+ @SdkSuppress(minSdkVersion = Build.VERSION_CODES.JELLY_BEAN)
public fun enableWriteAheadLogging_onOpenHelper() {
val autoClosingRoomOpenHelper = getAutoClosingRoomOpenHelper()
@@ -191,7 +195,7 @@
statement.executeInsert() // This should succeed
- db.query("select * from user").use {
+ db.query("select * from user").useCursor {
assertThat(it.count).isEqualTo(1)
}
@@ -217,7 +221,7 @@
statement.executeInsert()
- db.query("select * from users").use {
+ db.query("select * from users").useCursor {
assertThat(it.moveToFirst()).isTrue()
assertThat(it.getInt(0)).isEqualTo(123)
assertThat(it.getDouble(1)).isWithin(.01).of(1.23)
@@ -230,7 +234,7 @@
statement.clearBindings()
statement.executeInsert() // should insert with nulls
- db.query("select * from users").use {
+ db.query("select * from users").useCursor {
assertThat(it.moveToFirst()).isTrue()
it.moveToNext()
assertThat(it.isNull(0)).isTrue()
@@ -261,4 +265,13 @@
assertThat(autoClosing.getDelegate()).isSameInstanceAs(delegateOpenHelper)
}
+
+ // Older API versions didn't have Cursor implement Closeable
+ private inline fun Cursor.useCursor(block: (Cursor) -> Unit) {
+ try {
+ block(this)
+ } finally {
+ this.close()
+ }
+ }
}
\ No newline at end of file
diff --git a/wear/wear-tiles/build.gradle b/wear/wear-tiles/build.gradle
index fc0e747..bcfeda5 100644
--- a/wear/wear-tiles/build.gradle
+++ b/wear/wear-tiles/build.gradle
@@ -38,11 +38,20 @@
api(GUAVA_LISTENABLE_FUTURE)
implementation(PROTOBUF_LITE)
implementation 'androidx.annotation:annotation:1.2.0-alpha01'
+
+ testImplementation(ANDROIDX_TEST_EXT_JUNIT)
+ testImplementation(ANDROIDX_TEST_EXT_TRUTH)
+ testImplementation(ANDROIDX_TEST_CORE)
+ testImplementation(ANDROIDX_TEST_RUNNER)
+ testImplementation(ANDROIDX_TEST_RULES)
+ testImplementation(ROBOLECTRIC)
+ testImplementation(MOCKITO_CORE)
}
android {
defaultConfig {
- minSdkVersion 24
+ minSdkVersion 26
+ targetSdkVersion 28
}
buildFeatures {
aidl = true
diff --git a/wear/wear-tiles/src/main/AndroidManifest.xml b/wear/wear-tiles/src/main/AndroidManifest.xml
index e26eded..262aeeb 100644
--- a/wear/wear-tiles/src/main/AndroidManifest.xml
+++ b/wear/wear-tiles/src/main/AndroidManifest.xml
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="androidx.wear.tiles">
-</manifest>
+<manifest package="androidx.wear.tiles" />
\ No newline at end of file
diff --git a/wear/wear-tiles/src/main/java/androidx/wear/tiles/ProtoParcelable.java b/wear/wear-tiles/src/main/java/androidx/wear/tiles/ProtoParcelable.java
index 06b437c..a99c172 100644
--- a/wear/wear-tiles/src/main/java/androidx/wear/tiles/ProtoParcelable.java
+++ b/wear/wear-tiles/src/main/java/androidx/wear/tiles/ProtoParcelable.java
@@ -106,6 +106,6 @@
@Override
public int hashCode() {
- return Arrays.hashCode(mContents);
+ return 31 * mVersion + Arrays.hashCode(mContents);
}
}
diff --git a/wear/wear-tiles/src/test/java/androidx/wear/tiles/ProtoParcelableTest.java b/wear/wear-tiles/src/test/java/androidx/wear/tiles/ProtoParcelableTest.java
new file mode 100644
index 0000000..d5f1cea
--- /dev/null
+++ b/wear/wear-tiles/src/test/java/androidx/wear/tiles/ProtoParcelableTest.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 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 androidx.wear.tiles;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.os.Parcel;
+
+import androidx.wear.tiles.proto.RequestProto;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument // See http://g/robolectric-users/fTi2FRXgyGA/m/PkB0wYuwBgAJ
+public final class ProtoParcelableTest {
+ public static class Wrapper extends ProtoParcelable {
+ public static final int VERSION = 1;
+ public static final Creator<Wrapper> CREATOR = newCreator(Wrapper.class, Wrapper::new);
+
+ Wrapper(byte[] payload, int version) {
+ super(payload, version);
+ }
+ }
+
+ @Test
+ public void contentsEqualsAndHashCode() {
+ final Wrapper foo1 =
+ new Wrapper(RequestProto.ResourcesRequest.newBuilder().setVersion(
+ "foo").build().toByteArray(), Wrapper.VERSION);
+ final Wrapper foo2 =
+ new Wrapper(RequestProto.ResourcesRequest.newBuilder().setVersion(
+ "foo").build().toByteArray(), Wrapper.VERSION);
+ final Wrapper bar =
+ new Wrapper(RequestProto.ResourcesRequest.newBuilder().setVersion(
+ "bar").build().toByteArray(), Wrapper.VERSION);
+ assertThat(foo1).isEqualTo(foo2);
+ assertThat(foo1).isNotEqualTo(bar);
+ assertThat(foo1.hashCode()).isEqualTo(foo2.hashCode());
+ assertThat(foo1.hashCode()).isNotEqualTo(bar.hashCode());
+ }
+
+ @Test
+ public void versionEqualsAndHashCode() {
+ final Wrapper foo1 =
+ new Wrapper(RequestProto.ResourcesRequest.newBuilder().setVersion(
+ "foo").build().toByteArray(), Wrapper.VERSION);
+ final Wrapper foo2 =
+ new Wrapper(RequestProto.ResourcesRequest.newBuilder().setVersion(
+ "foo").build().toByteArray(), /* version= */2);
+
+ assertThat(foo1).isNotEqualTo(foo2);
+ assertThat(foo1.hashCode()).isNotEqualTo(foo2.hashCode());
+ }
+
+ @Test
+ public void toParcelAndBack() {
+ RequestProto.ResourcesRequest wrappedMessage =
+ RequestProto.ResourcesRequest.newBuilder().setVersion("foobar").build();
+ Wrapper wrapper = new Wrapper(wrappedMessage.toByteArray(), Wrapper.VERSION);
+
+ Parcel parcel = Parcel.obtain();
+ wrapper.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ assertThat(Wrapper.CREATOR.createFromParcel(parcel)).isEqualTo(wrapper);
+ }
+
+ @Test
+ public void arrayCreator() {
+ assertThat(Wrapper.CREATOR.newArray(123)).hasLength(123);
+ }
+}
diff --git a/wear/wear-tiles/src/test/java/androidx/wear/tiles/ResourcesDataTest.java b/wear/wear-tiles/src/test/java/androidx/wear/tiles/ResourcesDataTest.java
new file mode 100644
index 0000000..9465918
--- /dev/null
+++ b/wear/wear-tiles/src/test/java/androidx/wear/tiles/ResourcesDataTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 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 androidx.wear.tiles;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.os.Parcel;
+
+import androidx.wear.tiles.proto.ResourceProto.Resources;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument
+public final class ResourcesDataTest {
+ @Test
+ public void toParcelAndBack() {
+ Resources resources = Resources.newBuilder().setVersion("v123").build();
+ ResourcesData wrapper =
+ new ResourcesData(resources.toByteArray(), ResourcesData.VERSION_PROTOBUF);
+
+ Parcel parcel = Parcel.obtain();
+ wrapper.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ assertThat(ResourcesData.CREATOR.createFromParcel(parcel)).isEqualTo(wrapper);
+ }
+}
diff --git a/wear/wear-tiles/src/test/java/androidx/wear/tiles/ResourcesRequestDataTest.java b/wear/wear-tiles/src/test/java/androidx/wear/tiles/ResourcesRequestDataTest.java
new file mode 100644
index 0000000..9213528
--- /dev/null
+++ b/wear/wear-tiles/src/test/java/androidx/wear/tiles/ResourcesRequestDataTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 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 androidx.wear.tiles;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.os.Parcel;
+
+import androidx.wear.tiles.proto.RequestProto;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument
+public final class ResourcesRequestDataTest {
+ @Test
+ public void toParcelAndBack() {
+ RequestProto.ResourcesRequest request =
+ RequestProto.ResourcesRequest.newBuilder().setVersion("v123").build();
+ ResourcesRequestData wrapper =
+ new ResourcesRequestData(request.toByteArray(),
+ ResourcesRequestData.VERSION_PROTOBUF);
+
+ Parcel parcel = Parcel.obtain();
+ wrapper.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ assertThat(ResourcesRequestData.CREATOR.createFromParcel(parcel)).isEqualTo(wrapper);
+ }
+}
diff --git a/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileDataTest.java b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileDataTest.java
new file mode 100644
index 0000000..f1938b6
--- /dev/null
+++ b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileDataTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 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 androidx.wear.tiles;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.os.Parcel;
+
+import androidx.wear.tiles.proto.TileProto.Tile;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument
+public final class TileDataTest {
+ @Test
+ public void toParcelAndBack() {
+ Tile tile = Tile.newBuilder().setResourcesVersion("v123").build();
+ TileData wrapper = new TileData(tile.toByteArray(), TileData.VERSION_PROTOBUF);
+
+ Parcel parcel = Parcel.obtain();
+ wrapper.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ assertThat(TileData.CREATOR.createFromParcel(parcel)).isEqualTo(wrapper);
+ }
+}
diff --git a/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileProviderServiceTest.java b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileProviderServiceTest.java
new file mode 100644
index 0000000..7f5f73d
--- /dev/null
+++ b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileProviderServiceTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 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 androidx.wear.tiles;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.robolectric.Shadows.shadowOf;
+
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.Looper;
+
+import androidx.annotation.NonNull;
+import androidx.wear.tiles.builders.ResourceBuilders;
+import androidx.wear.tiles.builders.TileBuilders;
+import androidx.wear.tiles.proto.RequestProto;
+import androidx.wear.tiles.proto.ResourceProto.Resources;
+import androidx.wear.tiles.proto.TileProto.Tile;
+import androidx.wear.tiles.readers.RequestReaders.ResourcesRequest;
+import androidx.wear.tiles.readers.RequestReaders.TileRequest;
+
+import com.google.common.truth.Expect;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.android.controller.ServiceController;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument
+public class TileProviderServiceTest {
+ @Rule public final Expect expect = Expect.create();
+
+ private static final TileBuilders.Tile DUMMY_TILE =
+ TileBuilders.Tile.builder().setResourcesVersion("5").build();
+ private TileProvider mTileProviderService;
+
+ @Mock private TileCallback mMockTileCallback;
+ @Mock private ResourcesCallback mMockResourcesCallback;
+
+ @Before
+ public void setUp() {
+ mMockTileCallback = mock(TileCallback.class);
+ mMockResourcesCallback = mock(ResourcesCallback.class);
+
+ ServiceController<DummyTileProviderService> dummyTileProviderServiceController =
+ Robolectric.buildService(
+ DummyTileProviderService.class);
+
+ Intent i = new Intent(TileProviderService.ACTION_BIND_TILE_PROVIDER);
+ IBinder binder = dummyTileProviderServiceController.get().onBind(i);
+ mTileProviderService = TileProvider.Stub.asInterface(binder);
+ }
+
+ @Test
+ public void tileProvider_tileRequest() throws Exception {
+ mTileProviderService.onTileRequest(
+ 5,
+ new TileRequestData(
+ RequestProto.TileRequest.getDefaultInstance().toByteArray(),
+ TileRequestData.VERSION_PROTOBUF),
+ mMockTileCallback);
+
+ shadowOf(Looper.getMainLooper()).idle();
+
+ ArgumentCaptor<TileData> tileCaptor = ArgumentCaptor.forClass(TileData.class);
+
+ verify(mMockTileCallback).updateTileData(tileCaptor.capture());
+
+ Tile tile =
+ Tile.parseFrom(
+ tileCaptor.getValue().getContents());
+
+ expect.that(tile).isEqualTo(DUMMY_TILE.toProto());
+ }
+
+ @Test
+ public void tileProvider_resourcesRequest() throws Exception {
+ final String resourcesVersion = "HELLO WORLD";
+
+ ResourcesRequestData resourcesRequestData =
+ new ResourcesRequestData(
+ RequestProto.ResourcesRequest.newBuilder()
+ .setVersion(resourcesVersion)
+ .build()
+ .toByteArray(),
+ ResourcesRequestData.VERSION_PROTOBUF);
+
+ mTileProviderService.onResourcesRequest(5, resourcesRequestData, mMockResourcesCallback);
+
+ shadowOf(Looper.getMainLooper()).idle();
+
+ ArgumentCaptor<ResourcesData> resourcesCaptor = ArgumentCaptor.forClass(
+ ResourcesData.class);
+ verify(mMockResourcesCallback).updateResources(resourcesCaptor.capture());
+
+ Resources resources =
+ Resources.parseFrom(
+ resourcesCaptor.getValue().getContents());
+
+ expect.that(resources.getVersion()).isEqualTo(resourcesVersion);
+ }
+
+ public static class DummyTileProviderService extends TileProviderService {
+ @Override
+ @NonNull
+ protected ListenableFuture<TileBuilders.Tile> onTileRequest(
+ @NonNull TileRequest requestParams) {
+ return Futures.immediateFuture(DUMMY_TILE);
+ }
+
+ @Override
+ @NonNull
+ protected ListenableFuture<ResourceBuilders.Resources> onResourcesRequest(
+ @NonNull ResourcesRequest requestParams) {
+ ResourceBuilders.Resources resources =
+ ResourceBuilders.Resources.builder().setVersion(
+ requestParams.getVersion()).build();
+
+ return Futures.immediateFuture(resources);
+ }
+ }
+}
diff --git a/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileRequestDataTest.java b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileRequestDataTest.java
new file mode 100644
index 0000000..bf8ad22
--- /dev/null
+++ b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileRequestDataTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 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 androidx.wear.tiles;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.os.Parcel;
+
+import androidx.wear.tiles.proto.RequestProto;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument
+public final class TileRequestDataTest {
+ @Test
+ public void toParcelAndBack() {
+ RequestProto.TileRequest request = RequestProto.TileRequest.getDefaultInstance();
+ TileRequestData wrapper =
+ new TileRequestData(request.toByteArray(), TileRequestData.VERSION_PROTOBUF);
+
+ Parcel parcel = Parcel.obtain();
+ wrapper.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ assertThat(TileRequestData.CREATOR.createFromParcel(parcel)).isEqualTo(wrapper);
+ }
+}
diff --git a/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileUpdateRequestDataTest.java b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileUpdateRequestDataTest.java
new file mode 100644
index 0000000..73f336c
--- /dev/null
+++ b/wear/wear-tiles/src/test/java/androidx/wear/tiles/TileUpdateRequestDataTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 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 androidx.wear.tiles;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.os.Parcel;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument
+public final class TileUpdateRequestDataTest {
+ @Test
+ public void toParcelAndBack() {
+ // This payload ends up empty anyway (it's there for future expansion). Just test that it
+ // doesn't error out when being parceled and back again.
+ TileUpdateRequestData wrapper = new TileUpdateRequestData();
+
+ Parcel parcel = Parcel.obtain();
+ wrapper.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ assertThat(TileUpdateRequestData.CREATOR.createFromParcel(parcel)).isEqualTo(wrapper);
+ }
+}