Stop storing device orientation in DialpadView's instance variable to improve reliability.

Bug: 68941995
Test: Manual
PiperOrigin-RevId: 174782574
Change-Id: I93f358507f1f60b87e26e1bdcddf50ed1ef8e1b2
diff --git a/java/com/android/dialer/dialpadview/DialpadView.java b/java/com/android/dialer/dialpadview/DialpadView.java
index 5794038..5728f81 100644
--- a/java/com/android/dialer/dialpadview/DialpadView.java
+++ b/java/com/android/dialer/dialpadview/DialpadView.java
@@ -78,7 +78,6 @@
   private final ColorStateList mRippleColor;
   private final String[] mPrimaryLettersMapping;
   private final String[] mSecondaryLettersMapping;
-  private final boolean mIsLandscape; // whether the device is in landscape mode
   private final boolean mIsRtl; // whether the dialpad is shown in a right-to-left locale
   private final int mTranslateDistance;
 
@@ -108,9 +107,6 @@
 
     mTranslateDistance =
         getResources().getDimensionPixelSize(R.dimen.dialpad_key_button_translate_y);
-
-    mIsLandscape =
-        getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
     mIsRtl =
         TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
 
@@ -230,7 +226,7 @@
     super.onLayout(changed, l, t, r, b);
 
     if (changed) {
-      if (mIsLandscape) {
+      if (isLandscapeMode()) {
         adjustKeyWidths();
       } else {
         adjustDigitKeyHeights();
@@ -249,7 +245,7 @@
    * framework.
    */
   private void adjustDigitKeyHeights() {
-    Assert.checkState(!mIsLandscape);
+    Assert.checkState(!isLandscapeMode());
 
     int maxHeight = 0;
     for (int i = 0; i <= 9; i++) {
@@ -290,7 +286,7 @@
    * framework.
    */
   private void adjustKeyWidths() {
-    Assert.checkState(mIsLandscape);
+    Assert.checkState(isLandscapeMode());
 
     // A pre-defined minimum width for the letters shown beside a key.
     final int minimumKeyLettersWidth =
@@ -395,7 +391,7 @@
       final DialpadKeyButton dialpadKey = (DialpadKeyButton) findViewById(BUTTON_IDS[i]);
 
       ViewPropertyAnimator animator = dialpadKey.animate();
-      if (mIsLandscape) {
+      if (isLandscapeMode()) {
         // Landscape orientation requires translation along the X axis.
         // For RTL locales, ensure we translate negative on the X axis.
         dialpadKey.setTranslationX((mIsRtl ? -1 : 1) * mTranslateDistance);
@@ -434,7 +430,7 @@
    * @return The animation delay.
    */
   private int getKeyButtonAnimationDelay(int buttonId) {
-    if (mIsLandscape) {
+    if (isLandscapeMode()) {
       if (mIsRtl) {
         if (buttonId == R.id.three) {
           return KEY_FRAME_DURATION * 1;
@@ -522,7 +518,7 @@
    * @return The animation duration.
    */
   private int getKeyButtonAnimationDuration(int buttonId) {
-    if (mIsLandscape) {
+    if (isLandscapeMode()) {
       if (mIsRtl) {
         if (buttonId == R.id.one
             || buttonId == R.id.four
@@ -576,4 +572,8 @@
     LogUtil.e(TAG, "Attempted to get animation duration for invalid key button id.");
     return 0;
   }
+
+  private boolean isLandscapeMode() {
+    return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
+  }
 }