• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2020 The Android Open Source Project
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *      http://www.apache.org/licenses/LICENSE-2.0
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package android.util;
18  
19  import static android.view.Surface.ROTATION_0;
20  import static android.view.Surface.ROTATION_180;
21  import static android.view.Surface.ROTATION_270;
22  import static android.view.Surface.ROTATION_90;
23  
24  import android.graphics.Insets;
25  import android.view.Surface.Rotation;
26  
27  /**
28   * A class containing utility methods related to rotation.
29   *
30   * @hide
31   */
32  public class RotationUtils {
33  
34      /**
35       * Rotates an Insets according to the given rotation.
36       */
rotateInsets(Insets insets, @Rotation int rotation)37      public static Insets rotateInsets(Insets insets, @Rotation int rotation) {
38          if (insets == null || insets == Insets.NONE) {
39              return insets;
40          }
41          Insets rotated;
42          switch (rotation) {
43              case ROTATION_0:
44                  rotated = insets;
45                  break;
46              case ROTATION_90:
47                  rotated = Insets.of(
48                          insets.top,
49                          insets.right,
50                          insets.bottom,
51                          insets.left);
52                  break;
53              case ROTATION_180:
54                  rotated = Insets.of(
55                          insets.right,
56                          insets.bottom,
57                          insets.left,
58                          insets.top);
59                  break;
60              case ROTATION_270:
61                  rotated = Insets.of(
62                          insets.bottom,
63                          insets.left,
64                          insets.top,
65                          insets.right);
66                  break;
67              default:
68                  throw new IllegalArgumentException("unknown rotation: " + rotation);
69          }
70          return rotated;
71      }
72  }
73