SearchOrbView.java revision e2679e4ccab0ce75f701629c22c179165df4f15e
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 17package android.support.v17.leanback.widget; 18 19 20import android.content.Context; 21import android.graphics.Rect; 22import android.support.v17.leanback.R; 23import android.util.AttributeSet; 24import android.util.Log; 25import android.view.LayoutInflater; 26import android.view.View; 27import android.widget.LinearLayout; 28 29public class SearchOrbView extends LinearLayout implements View.OnClickListener { 30 private final static String TAG = SearchOrbView.class.getSimpleName(); 31 private final static boolean DEBUG = false; 32 33 private OnClickListener mListener; 34 private LinearLayout mSearchOrbView; 35 36 public SearchOrbView(Context context) { 37 this(context, null); 38 } 39 40 public SearchOrbView(Context context, AttributeSet attrs) { 41 this(context, attrs, 0); 42 } 43 44 public SearchOrbView(Context context, AttributeSet attrs, int defStyle) { 45 super(context, attrs, defStyle); 46 47 LayoutInflater inflater = (LayoutInflater) context 48 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 49 mSearchOrbView = (LinearLayout) inflater.inflate(R.layout.lb_search_orb, this, true); 50 51 // By default we are not visible 52 setVisibility(INVISIBLE); 53 setFocusable(true); 54 mSearchOrbView.setAlpha(0.5f); 55 56 setOnClickListener(this); 57 } 58 59 @Override 60 public void onClick(View view) { 61 if (null != mListener) { 62 mListener.onClick(view); 63 } 64 } 65 66 @Override 67 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { 68 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); 69 if (DEBUG) Log.v(TAG, "onFocusChanged " + gainFocus + " " + direction); 70 if (gainFocus) { 71 mSearchOrbView.setAlpha(1.0f); 72 } else { 73 mSearchOrbView.setAlpha(0.5f); 74 } 75 } 76 77 /** 78 * Set the on click listener for the orb 79 * @param listener The listener. 80 */ 81 public void setOnOrbClickedListener(OnClickListener listener) { 82 mListener = listener; 83 if (null != listener) { 84 setVisibility(View.VISIBLE); 85 } else { 86 setVisibility(View.INVISIBLE); 87 } 88 } 89 90} 91