• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.annotation.SuppressLint;
20 import android.util.Log;
21 import android.view.View;
22 
23 import androidx.annotation.RequiresApi;
24 
25 import java.lang.reflect.InvocationTargetException;
26 import java.lang.reflect.Method;
27 
28 @RequiresApi(22)
29 class ViewUtilsApi22 extends ViewUtilsApi21 {
30 
31     private static final String TAG = "ViewUtilsApi22";
32 
33     private static Method sSetLeftTopRightBottomMethod;
34     private static boolean sSetLeftTopRightBottomMethodFetched;
35 
36     @Override
setLeftTopRightBottom(View v, int left, int top, int right, int bottom)37     public void setLeftTopRightBottom(View v, int left, int top, int right, int bottom) {
38         fetchSetLeftTopRightBottomMethod();
39         if (sSetLeftTopRightBottomMethod != null) {
40             try {
41                 sSetLeftTopRightBottomMethod.invoke(v, left, top, right, bottom);
42             } catch (IllegalAccessException e) {
43                 // Do nothing
44             } catch (InvocationTargetException e) {
45                 throw new RuntimeException(e.getCause());
46             }
47         }
48     }
49 
50     @SuppressLint("PrivateApi")
fetchSetLeftTopRightBottomMethod()51     private void fetchSetLeftTopRightBottomMethod() {
52         if (!sSetLeftTopRightBottomMethodFetched) {
53             try {
54                 sSetLeftTopRightBottomMethod = View.class.getDeclaredMethod("setLeftTopRightBottom",
55                         int.class, int.class, int.class, int.class);
56                 sSetLeftTopRightBottomMethod.setAccessible(true);
57             } catch (NoSuchMethodException e) {
58                 Log.i(TAG, "Failed to retrieve setLeftTopRightBottom method", e);
59             }
60             sSetLeftTopRightBottomMethodFetched = true;
61         }
62     }
63 
64 }
65 
66