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.view.View.AttachInfo; 21 22 /** 23 * Class allowing access to package-protected methods/fields. 24 */ 25 public class AttachInfo_Accessor { 26 setAttachInfo(ViewGroup view)27 public static void setAttachInfo(ViewGroup view) { 28 Context context = view.getContext(); 29 WindowManagerImpl wm = (WindowManagerImpl)context.getSystemService(Context.WINDOW_SERVICE); 30 wm.setBaseRootView(view); 31 Display display = wm.getDefaultDisplay(); 32 ViewRootImpl root = new ViewRootImpl(context, display, new IWindowSession.Default(), 33 new WindowLayout()); 34 AttachInfo info = root.mAttachInfo; 35 info.mHasWindowFocus = true; 36 info.mWindowVisibility = View.VISIBLE; 37 info.mInTouchMode = false; // this is so that we can display selections. 38 info.mHardwareAccelerated = false; 39 info.mApplicationScale = 1.0f; 40 ViewRootImpl_Accessor.setChild(root, view); 41 view.assignParent(root); 42 view.dispatchAttachedToWindow(info, 0); 43 } 44 dispatchOnPreDraw(View view)45 public static void dispatchOnPreDraw(View view) { 46 view.mAttachInfo.mTreeObserver.dispatchOnPreDraw(); 47 } 48 dispatchOnGlobalLayout(View view)49 public static void dispatchOnGlobalLayout(View view) { 50 view.mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); 51 } 52 detachFromWindow(final View view)53 public static void detachFromWindow(final View view) { 54 if (view != null) { 55 final View.AttachInfo attachInfo = view.mAttachInfo; 56 view.dispatchDetachedFromWindow(); 57 if (attachInfo != null) { 58 ViewRootImpl_Accessor.detachFromWindow(attachInfo.mViewRootImpl); 59 } 60 } 61 } 62 getRootView(View view)63 public static ViewRootImpl getRootView(View view) { 64 return view.mAttachInfo != null ? view.mAttachInfo.mViewRootImpl : null; 65 } 66 } 67