1 /* 2 * Copyright (C) 2016 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.launcher3.keyboard; 18 19 import android.graphics.Rect; 20 import android.view.View; 21 import android.view.View.OnFocusChangeListener; 22 23 import com.android.launcher3.R; 24 25 /** 26 * A helper class to draw background of a focused view. 27 */ 28 public abstract class FocusIndicatorHelper extends ItemFocusIndicatorHelper<View> 29 implements OnFocusChangeListener { 30 FocusIndicatorHelper(View container)31 public FocusIndicatorHelper(View container) { 32 super(container, container.getResources().getColor(R.color.focused_background)); 33 } 34 35 @Override onFocusChange(View v, boolean hasFocus)36 public void onFocusChange(View v, boolean hasFocus) { 37 changeFocus(v, hasFocus); 38 } 39 40 @Override shouldDraw(View item)41 protected boolean shouldDraw(View item) { 42 return item.isAttachedToWindow(); 43 } 44 45 /** 46 * Simple subclass which assumes that the target view is a child of the container. 47 */ 48 public static class SimpleFocusIndicatorHelper extends FocusIndicatorHelper { 49 SimpleFocusIndicatorHelper(View container)50 public SimpleFocusIndicatorHelper(View container) { 51 super(container); 52 } 53 54 @Override viewToRect(View v, Rect outRect)55 public void viewToRect(View v, Rect outRect) { 56 outRect.set(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); 57 } 58 } 59 } 60