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 androidx.transition; 18 19 import android.util.Log; 20 import android.view.ViewGroup; 21 22 import androidx.annotation.NonNull; 23 import androidx.annotation.RequiresApi; 24 25 import java.lang.reflect.InvocationTargetException; 26 import java.lang.reflect.Method; 27 28 @RequiresApi(18) 29 class ViewGroupUtilsApi18 { 30 31 private static final String TAG = "ViewUtilsApi18"; 32 33 private static Method sSuppressLayoutMethod; 34 private static boolean sSuppressLayoutMethodFetched; 35 36 static void suppressLayout(@NonNull ViewGroup group, boolean suppress) { 37 fetchSuppressLayoutMethod(); 38 if (sSuppressLayoutMethod != null) { 39 try { 40 sSuppressLayoutMethod.invoke(group, suppress); 41 } catch (IllegalAccessException e) { 42 Log.i(TAG, "Failed to invoke suppressLayout method", e); 43 } catch (InvocationTargetException e) { 44 Log.i(TAG, "Error invoking suppressLayout method", e); 45 } 46 } 47 } 48 49 private static void fetchSuppressLayoutMethod() { 50 if (!sSuppressLayoutMethodFetched) { 51 try { 52 sSuppressLayoutMethod = ViewGroup.class.getDeclaredMethod("suppressLayout", 53 boolean.class); 54 sSuppressLayoutMethod.setAccessible(true); 55 } catch (NoSuchMethodException e) { 56 Log.i(TAG, "Failed to retrieve suppressLayout method", e); 57 } 58 sSuppressLayoutMethodFetched = true; 59 } 60 } 61 62 private ViewGroupUtilsApi18() { 63 } 64 } 65