• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 androidx.window.extensions.embedding;
18 
19 import android.content.res.Configuration;
20 import android.view.View;
21 
22 import androidx.annotation.NonNull;
23 import androidx.window.extensions.embedding.SplitAttributes.SplitType.ExpandContainersSplitType;
24 
25 /** Helper functions for {@link SplitAttributes} */
26 class SplitAttributesHelper {
27     /**
28      * Returns whether the split layout direction is reversed. Right-to-left and bottom-to-top are
29      * considered reversed.
30      */
isReversedLayout( @onNull SplitAttributes splitAttributes, @NonNull Configuration configuration)31     static boolean isReversedLayout(
32             @NonNull SplitAttributes splitAttributes, @NonNull Configuration configuration) {
33         switch (splitAttributes.getLayoutDirection()) {
34             case SplitAttributes.LayoutDirection.LEFT_TO_RIGHT:
35             case SplitAttributes.LayoutDirection.TOP_TO_BOTTOM:
36                 return false;
37             case SplitAttributes.LayoutDirection.RIGHT_TO_LEFT:
38             case SplitAttributes.LayoutDirection.BOTTOM_TO_TOP:
39                 return true;
40             case SplitAttributes.LayoutDirection.LOCALE:
41                 return configuration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
42             default:
43                 throw new IllegalArgumentException(
44                         "Invalid layout direction:" + splitAttributes.getLayoutDirection());
45         }
46     }
47 
48     /**
49      * Returns whether the {@link SplitAttributes} is an {@link ExpandContainersSplitType} and it
50      * should show a draggable handle that allows the user to drag and restore it into a split.
51      * This state is a result of user dragging the divider to fully expand the secondary container.
52      */
isDraggableExpandType(@onNull SplitAttributes splitAttributes)53     static boolean isDraggableExpandType(@NonNull SplitAttributes splitAttributes) {
54         final DividerAttributes dividerAttributes = splitAttributes.getDividerAttributes();
55         return splitAttributes.getSplitType() instanceof ExpandContainersSplitType
56                 && dividerAttributes != null
57                 && dividerAttributes.getDividerType() == DividerAttributes.DIVIDER_TYPE_DRAGGABLE;
58 
59     }
60 }
61