• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 com.android.settings.testutils.shadow;
18 
19 import android.icu.util.ULocale;
20 import android.os.SystemProperties;
21 import android.provider.Settings;
22 import android.text.TextUtils;
23 import android.view.View;
24 import java.util.Locale;
25 import org.robolectric.annotation.Implementation;
26 import org.robolectric.annotation.Implements;
27 
28 /**
29  * Important: The current robolectric doesn't support API 24, so I copy the code
30  * from API 24 here to make it compatible. Once robolectric is upgraded to 24,
31  * We can delete this shadow class.
32  **/
33 @Implements(TextUtils.class)
34 public class ShadowTextUtils {
35 
36     @Implementation
getLayoutDirectionFromLocale(Locale locale)37     public static int getLayoutDirectionFromLocale(Locale locale) {
38         return ((locale != null && !locale.equals(Locale.ROOT)
39                 && ULocale.forLocale(locale).isRightToLeft())
40                 // If forcing into RTL layout mode, return RTL as default
41                 || SystemProperties.getBoolean(Settings.Global.DEVELOPMENT_FORCE_RTL, false))
42                 ? View.LAYOUT_DIRECTION_RTL
43                 : View.LAYOUT_DIRECTION_LTR;
44     }
45 
46 }
47