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.widgets; 18 19 import android.os.Bundle; 20 import android.os.RemoteException; 21 import android.util.Log; 22 import android.view.KeyEvent; 23 import android.view.View; 24 import android.view.View.OnClickListener; 25 import android.widget.Button; 26 27 import com.android.cts.verifier.R; 28 import com.android.cts.verifier.projection.ProjectionActivity; 29 import com.android.cts.verifier.projection.ProjectionPresentationType; 30 31 public class ProjectionWidgetActivity extends ProjectionActivity { 32 private static final String TAG = ProjectionWidgetActivity.class.getSimpleName(); 33 34 private class InjectDPadClickListener implements OnClickListener { 35 private int mKeyCode; 36 InjectDPadClickListener(int keyCode)37 InjectDPadClickListener(int keyCode) { 38 mKeyCode = keyCode; 39 } 40 41 @Override onClick(View view)42 public void onClick(View view) { 43 if (mService != null) { 44 try { 45 mService.onKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, mKeyCode)); 46 } catch (RemoteException e) { 47 Log.e(TAG, "Error executing onKeyEvent", e); 48 } 49 } 50 } 51 } 52 53 @Override onCreate(Bundle savedInstanceState)54 protected void onCreate(Bundle savedInstanceState) { 55 super.onCreate(savedInstanceState); 56 View view = setContentViewAndInfoResources(R.layout.pwa_widgets, R.string.pwa_test, 57 R.string.pwa_info); 58 59 mType = ProjectionPresentationType.BASIC_WIDGETS; 60 61 Button button; 62 { 63 button = (Button) view.findViewById(R.id.up_button); 64 button.setOnClickListener(new InjectDPadClickListener(KeyEvent.KEYCODE_DPAD_UP)); 65 } 66 { 67 button = (Button) view.findViewById(R.id.down_button); 68 button.setOnClickListener(new InjectDPadClickListener(KeyEvent.KEYCODE_DPAD_DOWN)); 69 } 70 } 71 } 72