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 view.dispatchAttachedToWindow(info, 0); 41 } 42 dispatchOnPreDraw(View view)43 public static void dispatchOnPreDraw(View view) { 44 view.mAttachInfo.mTreeObserver.dispatchOnPreDraw(); 45 } 46 detachFromWindow(final View view)47 public static void detachFromWindow(final View view) { 48 if (view != null) { 49 view.dispatchDetachedFromWindow(); 50 } 51 } 52 getRootView(View view)53 public static ViewRootImpl getRootView(View view) { 54 return view.mAttachInfo != null ? view.mAttachInfo.mViewRootImpl : null; 55 } 56 } 57