1 /*
2  * Copyright (C) 2011 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 android.view;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.view.View.AttachInfo;
22 
23 import com.android.layoutlib.bridge.util.ReflectionUtils;
24 
25 /**
26  * Class allowing access to package-protected methods/fields.
27  */
28 public class AttachInfo_Accessor {
29 
setAttachInfo(View view)30     public static void setAttachInfo(View view) {
31         Context context = view.getContext();
32         WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
33         Display display = wm.getDefaultDisplay();
34         ViewRootImpl root = new ViewRootImpl(context, display);
35         AttachInfo info = new AttachInfo(ReflectionUtils.createProxy(IWindowSession.class),
36                 ReflectionUtils.createProxy(IWindow.class), display, root, new Handler(), null,
37                 context);
38         info.mHasWindowFocus = true;
39         info.mWindowVisibility = View.VISIBLE;
40         info.mInTouchMode = false; // this is so that we can display selections.
41         info.mHardwareAccelerated = false;
42         view.dispatchAttachedToWindow(info, 0);
43     }
44 
dispatchOnPreDraw(View view)45     public static void dispatchOnPreDraw(View view) {
46         view.mAttachInfo.mTreeObserver.dispatchOnPreDraw();
47     }
48 
detachFromWindow(View view)49     public static void detachFromWindow(View view) {
50         if (view != null) {
51             view.dispatchDetachedFromWindow();
52         }
53     }
54 
getRootView(View view)55     public static ViewRootImpl getRootView(View view) {
56         return view.mAttachInfo != null ? view.mAttachInfo.mViewRootImpl : null;
57     }
58 }
59