1 package com.android.car.developeroptions.homepage.contextualcards; 2 3 import android.content.Context; 4 import android.util.AttributeSet; 5 6 import androidx.annotation.Nullable; 7 import androidx.recyclerview.widget.RecyclerView; 8 9 public class FocusRecyclerView extends RecyclerView { 10 11 private FocusListener mListener; 12 FocusRecyclerView(Context context)13 public FocusRecyclerView(Context context) { 14 super(context); 15 } 16 FocusRecyclerView(Context context, @Nullable AttributeSet attrs)17 public FocusRecyclerView(Context context, @Nullable AttributeSet attrs) { 18 super(context, attrs); 19 } 20 21 @Override onWindowFocusChanged(boolean hasWindowFocus)22 public void onWindowFocusChanged(boolean hasWindowFocus) { 23 super.onWindowFocusChanged(hasWindowFocus); 24 if (mListener != null) { 25 mListener.onWindowFocusChanged(hasWindowFocus); 26 } 27 } 28 setListener(FocusListener listener)29 public void setListener(FocusListener listener) { 30 mListener = listener; 31 } 32 33 public interface FocusListener { onWindowFocusChanged(boolean hasWindowFocus)34 void onWindowFocusChanged(boolean hasWindowFocus); 35 } 36 } 37