blob: fca44aed04476b643eda0dd519b01b7c2c90670c [file] [log] [blame]
Jason Monkde850bb2017-02-01 19:26:30 -05001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
Jason Monk340b0e52017-03-08 14:57:56 -050015package android.testing;
Jason Monkde850bb2017-02-01 19:26:30 -050016
Jason Monk9ec0f1e2017-02-23 11:33:54 -050017import android.content.pm.ApplicationInfo;
Jason Monkde850bb2017-02-01 19:26:30 -050018import android.graphics.PixelFormat;
Jason Monk340b0e52017-03-08 14:57:56 -050019import android.support.test.InstrumentationRegistry;
Jason Monkde850bb2017-02-01 19:26:30 -050020import android.view.View;
21import android.view.WindowManager;
22import android.view.WindowManager.LayoutParams;
Jason Monkde850bb2017-02-01 19:26:30 -050023
24public class ViewUtils {
25
26 public static void attachView(View view) {
Jason Monk9ec0f1e2017-02-23 11:33:54 -050027 // Make sure hardware acceleration isn't turned on.
28 view.getContext().getApplicationInfo().flags &=
29 ~(ApplicationInfo.FLAG_HARDWARE_ACCELERATED);
Jason Monkde850bb2017-02-01 19:26:30 -050030 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
31 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
Jason Monk7d6fa832017-02-03 15:16:21 -050032 LayoutParams.TYPE_APPLICATION_OVERLAY,
Jason Monkde850bb2017-02-01 19:26:30 -050033 0, PixelFormat.TRANSLUCENT);
Jason Monk893f0bd2017-06-01 11:21:14 -040034 view.getContext().getSystemService(WindowManager.class).addView(view, lp);
Jason Monkde850bb2017-02-01 19:26:30 -050035 }
36
37 public static void detachView(View view) {
Jason Monk893f0bd2017-06-01 11:21:14 -040038 view.getContext().getSystemService(WindowManager.class).removeViewImmediate(view);
Jason Monkde850bb2017-02-01 19:26:30 -050039 }
40}