From 9e335e2d4fb43b22c7f95b2e9d4e048798e8e239 Mon Sep 17 00:00:00 2001 From: Android Dialer Date: Thu, 1 Mar 2018 08:27:39 -0800 Subject: Updating SecondaryInfo value class to use AutoValue with builder pattern. Test: CallCardPresenterTest,SecondaryInfoTest PiperOrigin-RevId: 187481728 Change-Id: I3d2b23b5d51ea1e5ff30b8f6b6570d76c006fe86 --- .../incallui/incall/protocol/SecondaryInfo.java | 125 ++++++++++++--------- 1 file changed, 72 insertions(+), 53 deletions(-) (limited to 'java/com/android/incallui/incall/protocol/SecondaryInfo.java') diff --git a/java/com/android/incallui/incall/protocol/SecondaryInfo.java b/java/com/android/incallui/incall/protocol/SecondaryInfo.java index cadfca6bf..2dfd220a4 100644 --- a/java/com/android/incallui/incall/protocol/SecondaryInfo.java +++ b/java/com/android/incallui/incall/protocol/SecondaryInfo.java @@ -18,41 +18,62 @@ package com.android.incallui.incall.protocol; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.Nullable; import com.android.dialer.common.LogUtil; +import com.google.auto.value.AutoValue; import java.util.Locale; /** Information about the secondary call. */ -public class SecondaryInfo implements Parcelable { - public final boolean shouldShow; - public final String name; - public final boolean nameIsNumber; - public final String label; - public final String providerLabel; - public final boolean isConference; - public final boolean isVideoCall; - public final boolean isFullscreen; - - public static SecondaryInfo createEmptySecondaryInfo(boolean isFullScreen) { - return new SecondaryInfo(false, null, false, null, null, false, false, isFullScreen); +@AutoValue +public abstract class SecondaryInfo implements Parcelable { + public abstract boolean shouldShow(); + + @Nullable + public abstract String name(); + + public abstract boolean nameIsNumber(); + + @Nullable + public abstract String label(); + + @Nullable + public abstract String providerLabel(); + + public abstract boolean isConference(); + + public abstract boolean isVideoCall(); + + public abstract boolean isFullscreen(); + + public static Builder builder() { + return new AutoValue_SecondaryInfo.Builder() + .setShouldShow(false) + .setNameIsNumber(false) + .setIsConference(false) + .setIsVideoCall(false) + .setIsFullscreen(false); } - public SecondaryInfo( - boolean shouldShow, - String name, - boolean nameIsNumber, - String label, - String providerLabel, - boolean isConference, - boolean isVideoCall, - boolean isFullscreen) { - this.shouldShow = shouldShow; - this.name = name; - this.nameIsNumber = nameIsNumber; - this.label = label; - this.providerLabel = providerLabel; - this.isConference = isConference; - this.isVideoCall = isVideoCall; - this.isFullscreen = isFullscreen; + /** Builder class for secondary info. */ + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setShouldShow(boolean shouldShow); + + public abstract Builder setName(String name); + + public abstract Builder setNameIsNumber(boolean nameIsNumber); + + public abstract Builder setLabel(String label); + + public abstract Builder setProviderLabel(String providerLabel); + + public abstract Builder setIsConference(boolean isConference); + + public abstract Builder setIsVideoCall(boolean isVideoCall); + + public abstract Builder setIsFullscreen(boolean isFullscreen); + + public abstract SecondaryInfo build(); } @Override @@ -60,28 +81,26 @@ public class SecondaryInfo implements Parcelable { return String.format( Locale.US, "SecondaryInfo, show: %b, name: %s, label: %s, " + "providerLabel: %s", - shouldShow, - LogUtil.sanitizePii(name), - label, - providerLabel); - } - - protected SecondaryInfo(Parcel in) { - shouldShow = in.readByte() != 0; - name = in.readString(); - nameIsNumber = in.readByte() != 0; - label = in.readString(); - providerLabel = in.readString(); - isConference = in.readByte() != 0; - isVideoCall = in.readByte() != 0; - isFullscreen = in.readByte() != 0; + shouldShow(), + LogUtil.sanitizePii(name()), + label(), + providerLabel()); } public static final Creator CREATOR = new Creator() { @Override public SecondaryInfo createFromParcel(Parcel in) { - return new SecondaryInfo(in); + return builder() + .setShouldShow(in.readByte() != 0) + .setName(in.readString()) + .setNameIsNumber(in.readByte() != 0) + .setLabel(in.readString()) + .setProviderLabel(in.readString()) + .setIsConference(in.readByte() != 0) + .setIsVideoCall(in.readByte() != 0) + .setIsFullscreen(in.readByte() != 0) + .build(); } @Override @@ -97,13 +116,13 @@ public class SecondaryInfo implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeByte((byte) (shouldShow ? 1 : 0)); - dest.writeString(name); - dest.writeByte((byte) (nameIsNumber ? 1 : 0)); - dest.writeString(label); - dest.writeString(providerLabel); - dest.writeByte((byte) (isConference ? 1 : 0)); - dest.writeByte((byte) (isVideoCall ? 1 : 0)); - dest.writeByte((byte) (isFullscreen ? 1 : 0)); + dest.writeByte((byte) (shouldShow() ? 1 : 0)); + dest.writeString(name()); + dest.writeByte((byte) (nameIsNumber() ? 1 : 0)); + dest.writeString(label()); + dest.writeString(providerLabel()); + dest.writeByte((byte) (isConference() ? 1 : 0)); + dest.writeByte((byte) (isVideoCall() ? 1 : 0)); + dest.writeByte((byte) (isFullscreen() ? 1 : 0)); } } -- cgit v1.2.3