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 --- java/com/android/incallui/CallCardPresenter.java | 44 ++++---- java/com/android/incallui/hold/OnHoldFragment.java | 8 +- .../incallui/incall/impl/InCallFragment.java | 2 +- .../incallui/incall/protocol/SecondaryInfo.java | 125 ++++++++++++--------- .../video/impl/SurfaceViewVideoCallFragment.java | 2 +- .../video/impl/SwitchOnHoldCallController.java | 2 +- .../incallui/video/impl/VideoCallFragment.java | 2 +- 7 files changed, 102 insertions(+), 83 deletions(-) (limited to 'java/com') diff --git a/java/com/android/incallui/CallCardPresenter.java b/java/com/android/incallui/CallCardPresenter.java index ad92f57c9..c60da63d6 100644 --- a/java/com/android/incallui/CallCardPresenter.java +++ b/java/com/android/incallui/CallCardPresenter.java @@ -907,7 +907,7 @@ public class CallCardPresenter if (secondary == null) { // Clear the secondary display info. - inCallScreen.setSecondary(SecondaryInfo.createEmptySecondaryInfo(isFullscreen)); + inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); return; } @@ -915,39 +915,39 @@ public class CallCardPresenter LogUtil.i( "CallCardPresenter.updateSecondaryDisplayInfo", "secondary call is merge in process, clearing info"); - inCallScreen.setSecondary(SecondaryInfo.createEmptySecondaryInfo(isFullscreen)); + inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); return; } if (secondary.isConferenceCall()) { inCallScreen.setSecondary( - new SecondaryInfo( - true /* show */, - CallerInfoUtils.getConferenceString( - context, secondary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)), - false /* nameIsNumber */, - null /* label */, - secondary.getCallProviderLabel(), - true /* isConference */, - secondary.isVideoCall(), - isFullscreen)); + SecondaryInfo.builder() + .setShouldShow(true) + .setName( + CallerInfoUtils.getConferenceString( + context, secondary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE))) + .setProviderLabel(secondary.getCallProviderLabel()) + .setIsConference(true) + .setIsVideoCall(secondary.isVideoCall()) + .setIsFullscreen(isFullscreen) + .build()); } else if (secondaryContactInfo != null) { LogUtil.v("CallCardPresenter.updateSecondaryDisplayInfo", "" + secondaryContactInfo); String name = getNameForCall(secondaryContactInfo); boolean nameIsNumber = name != null && name.equals(secondaryContactInfo.number); inCallScreen.setSecondary( - new SecondaryInfo( - true /* show */, - secondary.updateNameIfRestricted(name), - nameIsNumber, - secondaryContactInfo.label, - secondary.getCallProviderLabel(), - false /* isConference */, - secondary.isVideoCall(), - isFullscreen)); + SecondaryInfo.builder() + .setShouldShow(true) + .setName(secondary.updateNameIfRestricted(name)) + .setNameIsNumber(nameIsNumber) + .setLabel(secondaryContactInfo.label) + .setProviderLabel(secondary.getCallProviderLabel()) + .setIsVideoCall(secondary.isVideoCall()) + .setIsFullscreen(isFullscreen) + .build()); } else { // Clear the secondary display info. - inCallScreen.setSecondary(SecondaryInfo.createEmptySecondaryInfo(isFullscreen)); + inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); } } diff --git a/java/com/android/incallui/hold/OnHoldFragment.java b/java/com/android/incallui/hold/OnHoldFragment.java index 33ca158d3..bddb9bafb 100644 --- a/java/com/android/incallui/hold/OnHoldFragment.java +++ b/java/com/android/incallui/hold/OnHoldFragment.java @@ -59,14 +59,14 @@ public class OnHoldFragment extends Fragment { ((TextView) view.findViewById(R.id.hold_contact_name)) .setText( - secondaryInfo.nameIsNumber + secondaryInfo.nameIsNumber() ? PhoneNumberUtils.createTtsSpannable( BidiFormatter.getInstance() - .unicodeWrap(secondaryInfo.name, TextDirectionHeuristics.LTR)) - : secondaryInfo.name); + .unicodeWrap(secondaryInfo.name(), TextDirectionHeuristics.LTR)) + : secondaryInfo.name()); ((ImageView) view.findViewById(R.id.hold_phone_icon)) .setImageResource( - secondaryInfo.isVideoCall + secondaryInfo.isVideoCall() ? R.drawable.quantum_ic_videocam_white_18 : R.drawable.quantum_ic_phone_paused_vd_theme_24); view.addOnAttachStateChangeListener( diff --git a/java/com/android/incallui/incall/impl/InCallFragment.java b/java/com/android/incallui/incall/impl/InCallFragment.java index 29160abef..5f558a4ce 100644 --- a/java/com/android/incallui/incall/impl/InCallFragment.java +++ b/java/com/android/incallui/incall/impl/InCallFragment.java @@ -305,7 +305,7 @@ public class InCallFragment extends Fragment savedSecondaryInfo = null; FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); Fragment oldBanner = getChildFragmentManager().findFragmentById(R.id.incall_on_hold_banner); - if (secondaryInfo.shouldShow) { + if (secondaryInfo.shouldShow()) { transaction.replace(R.id.incall_on_hold_banner, OnHoldFragment.newInstance(secondaryInfo)); } else { if (oldBanner != null) { 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)); } } diff --git a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java index 631cc1d68..28ee774ba 100644 --- a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java +++ b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java @@ -846,7 +846,7 @@ public class SurfaceViewVideoCallFragment extends Fragment updateButtonStates(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); Fragment oldBanner = getChildFragmentManager().findFragmentById(R.id.videocall_on_hold_banner); - if (secondaryInfo.shouldShow) { + if (secondaryInfo.shouldShow()) { OnHoldFragment onHoldFragment = OnHoldFragment.newInstance(secondaryInfo); onHoldFragment.setPadTopInset(!isInFullscreenMode); transaction.replace(R.id.videocall_on_hold_banner, onHoldFragment); diff --git a/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java b/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java index 372b56b4e..3efdfd7fa 100644 --- a/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java +++ b/java/com/android/incallui/video/impl/SwitchOnHoldCallController.java @@ -74,7 +74,7 @@ public class SwitchOnHoldCallController implements OnClickListener { } private boolean hasSecondaryInfo() { - return secondaryInfo != null && secondaryInfo.shouldShow; + return secondaryInfo != null && secondaryInfo.shouldShow(); } public void updateButtonState() { diff --git a/java/com/android/incallui/video/impl/VideoCallFragment.java b/java/com/android/incallui/video/impl/VideoCallFragment.java index 0793d1830..6b5a9797f 100644 --- a/java/com/android/incallui/video/impl/VideoCallFragment.java +++ b/java/com/android/incallui/video/impl/VideoCallFragment.java @@ -887,7 +887,7 @@ public class VideoCallFragment extends Fragment updateButtonStates(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); Fragment oldBanner = getChildFragmentManager().findFragmentById(R.id.videocall_on_hold_banner); - if (secondaryInfo.shouldShow) { + if (secondaryInfo.shouldShow()) { OnHoldFragment onHoldFragment = OnHoldFragment.newInstance(secondaryInfo); onHoldFragment.setPadTopInset(!isInFullscreenMode); transaction.replace(R.id.videocall_on_hold_banner, onHoldFragment); -- cgit v1.2.3