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.Flags; 24 import com.android.launcher3.R; 25 import com.android.launcher3.util.Themes; 26 27 /** 28 * A helper class to draw background of a focused view. 29 */ 30 public abstract class FocusIndicatorHelper extends ItemFocusIndicatorHelper<View> 31 implements OnFocusChangeListener { 32 FocusIndicatorHelper(View container)33 public FocusIndicatorHelper(View container) { 34 super(container, 35 Flags.enableFocusOutline() ? new int[]{Themes.getAttrColor(container.getContext(), 36 R.attr.focusOutlineColor), Themes.getAttrColor(container.getContext(), 37 R.attr.focusInnerOutlineColor)} 38 : new int[]{container.getResources().getColor(R.color.focused_background)}); 39 } 40 41 @Override onFocusChange(View v, boolean hasFocus)42 public void onFocusChange(View v, boolean hasFocus) { 43 changeFocus(v, hasFocus); 44 } 45 46 @Override shouldDraw(View item)47 protected boolean shouldDraw(View item) { 48 return item.isAttachedToWindow(); 49 } 50 51 /** 52 * Simple subclass which assumes that the target view is a child of the container. 53 */ 54 public static class SimpleFocusIndicatorHelper extends FocusIndicatorHelper { 55 SimpleFocusIndicatorHelper(View container)56 public SimpleFocusIndicatorHelper(View container) { 57 super(container); 58 } 59 60 @Override viewToRect(View v, Rect outRect)61 public void viewToRect(View v, Rect outRect) { 62 outRect.set(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); 63 } 64 } 65 } 66