1 /* 2 * Copyright (C) 2017 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.printspooler.widget; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.widget.Spinner; 22 23 /** 24 * Spinner that can intercept {@link Spinner#performClick()} 25 */ 26 public class ClickInterceptSpinner extends Spinner { 27 private OnClickListener mListener; 28 29 /** 30 * Create a new spinner with the given attributes. 31 * 32 * @param context The context for the spinner 33 * @param attrs Attributes of the spinner 34 */ ClickInterceptSpinner(Context context, AttributeSet attrs)35 public ClickInterceptSpinner(Context context, AttributeSet attrs) { 36 super(context, attrs); 37 } 38 39 /** 40 * Set a listener invoked on {@link #performClick()} 41 * 42 * @param listener The listener to be invoked 43 */ setPerformClickListener(OnClickListener listener)44 public void setPerformClickListener(OnClickListener listener) { 45 mListener = listener; 46 } 47 48 @Override performClick()49 public boolean performClick() { 50 if (mListener != null) { 51 mListener.onClick(this); 52 } 53 54 return super.performClick(); 55 } 56 } 57