1 /*
2  * Copyright (C) 2014 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 com.android.cts.verifier.projection;
18 
19 import android.app.Presentation;
20 import android.content.Context;
21 import android.view.Display;
22 import android.view.KeyEvent;
23 import android.view.MotionEvent;
24 import android.view.WindowManager;
25 
26 /**
27  * Base class for Presentations which are to be projected onto a VirtualDisplay
28  */
29 public abstract class ProjectedPresentation extends Presentation {
ProjectedPresentation(Context outerContext, Display display)30     public ProjectedPresentation(Context outerContext, Display display) {
31         // This theme is required to prevent an extra view from obscuring the presentation
32         super(outerContext, display, android.R.style.Theme_Holo_Light_NoActionBar_TranslucentDecor);
33 
34         getWindow().setType(WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION);
35 
36         // So we can control the input
37         getWindow().addFlags(WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE);
38         getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
39     }
40 
injectTouchEvent(MotionEvent event)41     public void injectTouchEvent(MotionEvent event) {
42         getWindow().setLocalFocus(true, true);
43         getWindow().injectInputEvent(event);
44     }
45 
injectKeyEvent(KeyEvent event)46     public void injectKeyEvent(KeyEvent event) {
47         getWindow().setLocalFocus(true, false);
48         getWindow().injectInputEvent(event);
49     }
50 }
51