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
17package android.view;
18
19import com.android.layoutlib.bridge.android.BridgeWindow;
20import com.android.layoutlib.bridge.android.BridgeWindowSession;
21
22import android.content.Context;
23import android.os.Handler;
24import android.view.View.AttachInfo;
25
26/**
27 * Class allowing access to package-protected methods/fields.
28 */
29public class AttachInfo_Accessor {
30
31    public static void setAttachInfo(View view) {
32        Context context = view.getContext();
33        WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
34        Display display = wm.getDefaultDisplay();
35        ViewRootImpl root = new ViewRootImpl(context, display);
36        AttachInfo info = new AttachInfo(new BridgeWindowSession(), new BridgeWindow(),
37                display, root, new Handler(), null, 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
45    public static void dispatchOnPreDraw(View view) {
46        view.mAttachInfo.mTreeObserver.dispatchOnPreDraw();
47    }
48
49    public static void detachFromWindow(View view) {
50        if (view != null) {
51            view.dispatchDetachedFromWindow();
52        }
53    }
54
55    public static ViewRootImpl getRootView(View view) {
56        return view.mAttachInfo != null ? view.mAttachInfo.mViewRootImpl : null;
57    }
58}
59