1 /** 2 * Copyright (c) 2013, Google Inc. 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.mail.utils; 18 19 import android.annotation.SuppressLint; 20 import android.support.v4.view.ViewCompat; 21 import android.view.View; 22 23 /** 24 * Utility class to perform some common operations on views. 25 */ 26 public class ViewUtils { 27 28 /** 29 * Determines whether the given view has RTL layout. NOTE: do not call this 30 * on a view until it has been measured. This value is not guaranteed to be 31 * accurate until then. 32 */ 33 public static boolean isViewRtl(View view) { 34 return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; 35 } 36 37 /** 38 * @return the start padding of the view. Prior to API 17, will return the left padding. 39 */ 40 @SuppressLint("NewApi") 41 public static int getPaddingStart(View view) { 42 return Utils.isRunningJBMR1OrLater() ? view.getPaddingStart() : view.getPaddingLeft(); 43 } 44 45 /** 46 * @return the end padding of the view. Prior to API 17, will return the right padding. 47 */ 48 @SuppressLint("NewApi") 49 public static int getPaddingEnd(View view) { 50 return Utils.isRunningJBMR1OrLater() ? view.getPaddingEnd() : view.getPaddingRight(); 51 } 52 53 /** 54 * Sets the text alignment of the view. Prior to API 17, will no-op. 55 */ 56 @SuppressLint("NewApi") 57 public static void setTextAlignment(View view, int textAlignment) { 58 if (Utils.isRunningJBMR1OrLater()) { 59 view.setTextAlignment(textAlignment); 60 } 61 } 62 } 63