1 /* 2 * Copyright (C) 2023 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.example.android.vdmdemo.common; 18 19 import android.os.Bundle; 20 import android.view.MotionEvent; 21 import android.view.View; 22 23 import androidx.fragment.app.Fragment; 24 25 import dagger.hilt.android.AndroidEntryPoint; 26 27 import java.util.function.Consumer; 28 29 /** Fragment to show UI for a navigation touchpad. */ 30 @AndroidEntryPoint(Fragment.class) 31 public final class NavTouchpadFragment extends Hilt_NavTouchpadFragment { 32 33 private Consumer<MotionEvent> mInputEventListener; 34 NavTouchpadFragment()35 public NavTouchpadFragment() { 36 super(R.layout.nav_touchpad_fragment); 37 } 38 setInputEventListener(Consumer<MotionEvent> listener)39 public void setInputEventListener(Consumer<MotionEvent> listener) { 40 mInputEventListener = listener; 41 } 42 43 @Override onViewCreated(View view, Bundle savedInstanceState)44 public void onViewCreated(View view, Bundle savedInstanceState) { 45 view.setOnTouchListener( 46 (v, event) -> { 47 if (mInputEventListener != null) { 48 mInputEventListener.accept(event); 49 } 50 return true; 51 }); 52 } 53 } 54