Merge "Convert InsetsOEMV1 and TabOEMV1 to data objects" into sc-dev
diff --git a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/sharedlibrarysupport/SharedLibraryFactoryAdapterV1.java b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/sharedlibrarysupport/SharedLibraryFactoryAdapterV1.java
index 9dfd214..730d2d8 100644
--- a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/sharedlibrarysupport/SharedLibraryFactoryAdapterV1.java
+++ b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/sharedlibrarysupport/SharedLibraryFactoryAdapterV1.java
@@ -71,15 +71,11 @@
* SharedLibraryFactory.
*/
public final class SharedLibraryFactoryAdapterV1 implements SharedLibraryFactory {
-
- private final Context mSharedLibContext;
-
SharedLibraryFactoryOEMV1 mOem;
SharedLibraryFactoryStub mFactoryStub;
public SharedLibraryFactoryAdapterV1(SharedLibraryFactoryOEMV1 oem, Context sharedLibContext) {
mOem = oem;
- mSharedLibContext = sharedLibContext;
mFactoryStub = new SharedLibraryFactoryStub(sharedLibContext);
mOem.setRotaryFactories(
diff --git a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/TabAdapterV1.java b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/TabAdapterV1.java
index 8cee728..543a10d 100644
--- a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/TabAdapterV1.java
+++ b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/TabAdapterV1.java
@@ -16,48 +16,33 @@
package com.android.car.ui.toolbar;
-import android.graphics.drawable.Drawable;
-
import com.android.car.ui.sharedlibrary.oemapis.toolbar.TabOEMV1;
import java.util.function.Consumer;
@SuppressWarnings("AndroidJdkLibsChecker")
-class TabAdapterV1 implements TabOEMV1 {
+class TabAdapterV1 {
private final Tab mClientTab;
+ private final TabOEMV1 mSharedLibraryTab;
TabAdapterV1(Tab clientTab) {
mClientTab = clientTab;
+ Consumer<Tab> selectedListener = mClientTab.getSelectedListener();
+ mSharedLibraryTab = TabOEMV1.builder()
+ .setIcon(mClientTab.getIcon())
+ .setTitle(mClientTab.getText())
+ .setOnSelectedListener(selectedListener == null
+ ? null
+ : () -> selectedListener.accept(mClientTab))
+ .build();
}
public Tab getClientTab() {
return mClientTab;
}
- @Override
- public String getTitle() {
- return mClientTab.getText();
- }
-
- @Override
- public Drawable getIcon() {
- return mClientTab.getIcon();
- }
-
-
- @Override
- public Runnable getOnClickListener() {
- Consumer<Tab> selectedListener = mClientTab.getSelectedListener();
- if (selectedListener == null) {
- return null;
- } else {
- return () -> selectedListener.accept(mClientTab);
- }
- }
-
- @Override
- public boolean shouldTint() {
- return true;
+ public TabOEMV1 getSharedLibraryTab() {
+ return mSharedLibraryTab;
}
}
diff --git a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/ToolbarControllerAdapterV1.java b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/ToolbarControllerAdapterV1.java
index 981cf71..8742961 100644
--- a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/ToolbarControllerAdapterV1.java
+++ b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/toolbar/ToolbarControllerAdapterV1.java
@@ -475,11 +475,19 @@
boolean gainingTabs = newAdapterState.hasTabs() && !oldAdapterState.hasTabs();
boolean losingTabs = !newAdapterState.hasTabs() && oldAdapterState.hasTabs();
if (gainingTabs) {
- mOemToolbar.setTabs(newAdapterState.getTabs(), newAdapterState.getSelectedTab());
+ mOemToolbar.setTabs(newAdapterState.getTabs()
+ .stream()
+ .map(TabAdapterV1::getSharedLibraryTab)
+ .collect(toList()),
+ newAdapterState.getSelectedTab());
} else if (losingTabs) {
mOemToolbar.setTabs(Collections.emptyList(), -1);
} else if (newAdapterState.hasTabs() && newAdapterState.getTabsDirty()) {
- mOemToolbar.setTabs(newAdapterState.getTabs(), newAdapterState.getSelectedTab());
+ mOemToolbar.setTabs(newAdapterState.getTabs()
+ .stream()
+ .map(TabAdapterV1::getSharedLibraryTab)
+ .collect(toList()),
+ newAdapterState.getSelectedTab());
} else if (newAdapterState.hasTabs()
&& newAdapterState.getSelectedTab() != oldAdapterState.getSelectedTab()) {
mOemToolbar.selectTab(newAdapterState.getSelectedTab(), true);
diff --git a/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/InsetsOEMV1.java b/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/InsetsOEMV1.java
index 11421a8..0e501d6 100644
--- a/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/InsetsOEMV1.java
+++ b/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/InsetsOEMV1.java
@@ -15,17 +15,64 @@
*/
package com.android.car.ui.sharedlibrary.oemapis;
+import java.util.Objects;
+
/**
* Represents insets in the base layout. {@link com.android.car.ui.baselayout.Insets} for more
* information.
*/
-public interface InsetsOEMV1 {
- /** Gets the left inset */
- int getLeft();
- /** Gets the right inset */
- int getRight();
- /** Gets the top inset */
- int getTop();
- /** Gets the bottom inset */
- int getBottom();
+public final class InsetsOEMV1 {
+ private final int mLeft;
+ private final int mRight;
+ private final int mTop;
+ private final int mBottom;
+
+ public InsetsOEMV1() {
+ mLeft = mRight = mTop = mBottom = 0;
+ }
+
+ public InsetsOEMV1(int left, int top, int right, int bottom) {
+ mLeft = left;
+ mRight = right;
+ mTop = top;
+ mBottom = bottom;
+ }
+
+ public int getLeft() {
+ return mLeft;
+ }
+
+ public int getRight() {
+ return mRight;
+ }
+
+ public int getTop() {
+ return mTop;
+ }
+
+ public int getBottom() {
+ return mBottom;
+ }
+
+ @Override
+ public String toString() {
+ return "{ left: " + mLeft + ", right: " + mRight
+ + ", top: " + mTop + ", bottom: " + mBottom + " }";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ InsetsOEMV1 insets = (InsetsOEMV1) o;
+ return mLeft == insets.mLeft
+ && mRight == insets.mRight
+ && mTop == insets.mTop
+ && mBottom == insets.mBottom;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mLeft, mRight, mTop, mBottom);
+ }
}
diff --git a/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/toolbar/TabOEMV1.java b/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/toolbar/TabOEMV1.java
index 9db4423..d175aca 100644
--- a/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/toolbar/TabOEMV1.java
+++ b/car-ui-lib/oem-apis/src/main/java/com/android/car/ui/sharedlibrary/oemapis/toolbar/TabOEMV1.java
@@ -19,17 +19,85 @@
import android.graphics.drawable.Drawable;
/** Interface representing a toolbar tab */
-public interface TabOEMV1 {
+public final class TabOEMV1 {
+ private final String mTitle;
+ private final Drawable mIcon;
+ private final Runnable mOnSelectedListener;
+ private final boolean mTinted;
+
+ private TabOEMV1(Builder builder) {
+ mTitle = builder.mTitle;
+ mIcon = builder.mIcon;
+ mOnSelectedListener = builder.mOnSelectedListener;
+ mTinted = builder.mTinted;
+ }
+
+ /** Constructs a new {@link Builder} to build a tab with */
+ public static Builder builder() {
+ return new Builder();
+ }
+
/** Gets the title of the tab */
- String getTitle();
+ public String getTitle() {
+ return mTitle;
+ }
+
/** Gets the icon of the tab. The icon may be tinted to match the theme of the toolbar */
- Drawable getIcon();
+ public Drawable getIcon() {
+ return mIcon;
+ }
+
/** Gets the function to call when the tab is selected */
- Runnable getOnClickListener();
+ public Runnable getOnSelectedListener() {
+ return mOnSelectedListener;
+ }
+
/**
* Returns if the icon should be tinted to match the style of the toolbar.
* Most of the time this will be true. If not, then the original colors of the drawable
* should be shown.
*/
- boolean shouldTint();
+ public boolean isTinted() {
+ return mTinted;
+ }
+
+ /** Builder for {@link TabOEMV1} */
+ public static class Builder {
+ private String mTitle = null;
+ private Drawable mIcon = null;
+ private Runnable mOnSelectedListener = null;
+ private boolean mTinted = true;
+
+ private Builder() {
+ }
+
+ /** Sets the tab's text */
+ public Builder setTitle(String title) {
+ mTitle = title;
+ return this;
+ }
+
+ /** Sets the tab's icon */
+ public Builder setIcon(Drawable icon) {
+ mIcon = icon;
+ return this;
+ }
+
+ /** Sets a listener that is called when the tab is selected */
+ public Builder setOnSelectedListener(Runnable callback) {
+ mOnSelectedListener = callback;
+ return this;
+ }
+
+ /** See {@link TabOEMV1#isTinted} */
+ public Builder setTinted(boolean tinted) {
+ mTinted = tinted;
+ return this;
+ }
+
+ /** Builds the final {@link TabOEMV1} */
+ public TabOEMV1 build() {
+ return new TabOEMV1(this);
+ }
+ }
}
diff --git a/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/BaseLayoutInstaller.java b/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/BaseLayoutInstaller.java
index 602777a..e5dcb80 100644
--- a/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/BaseLayoutInstaller.java
+++ b/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/BaseLayoutInstaller.java
@@ -150,7 +150,7 @@
private Consumer<InsetsOEMV1> mInsetsChangedListenerDelegate;
private boolean mInsetsDirty = true;
- private InsetsOEMV1 mInsets = new Insets();
+ private InsetsOEMV1 mInsets = new InsetsOEMV1();
/**
* Constructs an InsetsUpdater that calculates and dispatches insets to the method provided
@@ -253,7 +253,7 @@
right += Math.max(0,
getRightOfView(mContentViewContainer) - getLeftOfView(mRightInsetView));
}
- InsetsOEMV1 insets = new Insets(left, top, right, bottom);
+ InsetsOEMV1 insets = new InsetsOEMV1(left, top, right, bottom);
mInsetsDirty = false;
if (!insets.equals(mInsets)) {
diff --git a/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/Insets.java b/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/Insets.java
deleted file mode 100644
index 7b27a24..0000000
--- a/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/Insets.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.chassis.car.ui.sharedlibrary.toolbar;
-
-import com.android.car.ui.sharedlibrary.oemapis.InsetsOEMV1;
-
-import java.util.Objects;
-
-class Insets implements InsetsOEMV1 {
- private final int mLeft;
- private final int mRight;
- private final int mTop;
- private final int mBottom;
-
- Insets() {
- mLeft = mRight = mTop = mBottom = 0;
- }
-
- Insets(int left, int top, int right, int bottom) {
- mLeft = left;
- mRight = right;
- mTop = top;
- mBottom = bottom;
- }
-
- @Override
- public int getLeft() {
- return mLeft;
- }
-
- @Override
- public int getRight() {
- return mRight;
- }
-
- @Override
- public int getTop() {
- return mTop;
- }
-
- @Override
- public int getBottom() {
- return mBottom;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Insets insets = (Insets) o;
- return mLeft == insets.mLeft
- && mRight == insets.mRight
- && mTop == insets.mTop
- && mBottom == insets.mBottom;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(mLeft, mRight, mTop, mBottom);
- }
-}
diff --git a/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/TabLayout.java b/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/TabLayout.java
index 25168d7..868193d 100644
--- a/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/TabLayout.java
+++ b/car-ui-lib/referencedesign/sharedlibrary/src/main/java/com/chassis/car/ui/sharedlibrary/toolbar/TabLayout.java
@@ -112,9 +112,9 @@
bindTab(oldSelectedTab);
bindTab(mSelectedTab);
- Runnable onClickListener = tab.getOnClickListener();
- if (onClickListener != null && sendCallback) {
- onClickListener.run();
+ Runnable onSelectedListener = tab.getOnSelectedListener();
+ if (onSelectedListener != null && sendCallback) {
+ onSelectedListener.run();
}
}