blob: 3dcba48b8dc8cb4b0ff7e4da5e7cb6b8837f6d88 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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.widget;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.content.Context;
20import android.content.res.TypedArray;
21import android.database.DataSetObserver;
22import android.graphics.Rect;
23import android.os.Parcel;
24import android.os.Parcelable;
25import android.util.AttributeSet;
Philip P. Moltmann96689032017-03-09 13:19:55 -080026import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.util.SparseArray;
28import android.view.View;
29import android.view.ViewGroup;
Felipe Leme640f30a2017-03-06 15:44:06 -080030import android.view.autofill.AutofillValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
Aurimas Liutikas99441c52016-10-11 16:48:32 -070032import com.android.internal.R;
33
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034/**
35 * An abstract base class for spinner widgets. SDK users will probably not
36 * need to use this class.
Aurimas Liutikas99441c52016-10-11 16:48:32 -070037 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038 * @attr ref android.R.styleable#AbsSpinner_entries
39 */
40public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> {
Philip P. Moltmann96689032017-03-09 13:19:55 -080041 private static final String LOG_TAG = AbsSpinner.class.getSimpleName();
42
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 SpinnerAdapter mAdapter;
44
45 int mHeightMeasureSpec;
46 int mWidthMeasureSpec;
Romain Guyafc01552010-02-22 16:48:47 -080047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 int mSelectionLeftPadding = 0;
49 int mSelectionTopPadding = 0;
50 int mSelectionRightPadding = 0;
51 int mSelectionBottomPadding = 0;
Romain Guyafc01552010-02-22 16:48:47 -080052 final Rect mSpinnerPadding = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
Romain Guyafc01552010-02-22 16:48:47 -080054 final RecycleBin mRecycler = new RecycleBin();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 private DataSetObserver mDataSetObserver;
56
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 /** Temporary frame to hold a child View's frame rectangle */
58 private Rect mTouchFrame;
59
60 public AbsSpinner(Context context) {
61 super(context);
62 initAbsSpinner();
63 }
64
65 public AbsSpinner(Context context, AttributeSet attrs) {
66 this(context, attrs, 0);
67 }
68
Alan Viverette617feb92013-09-09 18:09:13 -070069 public AbsSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
70 this(context, attrs, defStyleAttr, 0);
71 }
72
73 public AbsSpinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
74 super(context, attrs, defStyleAttr, defStyleRes);
Felipe Lemed04a6972017-03-02 12:56:18 -080075
76 // Spinner is important by default, unless app developer overrode attribute.
77 if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
78 setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
79 }
80
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 initAbsSpinner();
82
Alan Viverette617feb92013-09-09 18:09:13 -070083 final TypedArray a = context.obtainStyledAttributes(
Alan Viverette3f221cf2015-01-16 14:40:04 -080084 attrs, R.styleable.AbsSpinner, defStyleAttr, defStyleRes);
Aurimas Liutikasab324cf2019-02-07 16:46:38 -080085 saveAttributeDataForStyleable(context, R.styleable.AbsSpinner, attrs, a, defStyleAttr,
86 defStyleRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
Alan Viverette3f221cf2015-01-16 14:40:04 -080088 final CharSequence[] entries = a.getTextArray(R.styleable.AbsSpinner_entries);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 if (entries != null) {
Alan Viverette3f221cf2015-01-16 14:40:04 -080090 final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
91 context, R.layout.simple_spinner_item, entries);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
93 setAdapter(adapter);
94 }
95
96 a.recycle();
97 }
98
99 /**
100 * Common code for different constructor flavors
101 */
102 private void initAbsSpinner() {
103 setFocusable(true);
104 setWillNotDraw(false);
105 }
106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 /**
108 * The Adapter is used to provide the data which backs this Spinner.
109 * It also provides methods to transform spinner items based on their position
110 * relative to the selected item.
111 * @param adapter The SpinnerAdapter to use for this Spinner
112 */
113 @Override
114 public void setAdapter(SpinnerAdapter adapter) {
115 if (null != mAdapter) {
116 mAdapter.unregisterDataSetObserver(mDataSetObserver);
117 resetList();
118 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 mAdapter = adapter;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 mOldSelectedPosition = INVALID_POSITION;
123 mOldSelectedRowId = INVALID_ROW_ID;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 if (mAdapter != null) {
126 mOldItemCount = mItemCount;
127 mItemCount = mAdapter.getCount();
128 checkFocus();
129
130 mDataSetObserver = new AdapterDataSetObserver();
131 mAdapter.registerDataSetObserver(mDataSetObserver);
132
133 int position = mItemCount > 0 ? 0 : INVALID_POSITION;
134
135 setSelectedPositionInt(position);
136 setNextSelectedPositionInt(position);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 if (mItemCount == 0) {
139 // Nothing selected
140 checkSelectionChanged();
141 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 } else {
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700144 checkFocus();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 resetList();
146 // Nothing selected
147 checkSelectionChanged();
148 }
149
150 requestLayout();
151 }
152
153 /**
154 * Clear out all children from the list
155 */
156 void resetList() {
157 mDataChanged = false;
158 mNeedSync = false;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 removeAllViewsInLayout();
161 mOldSelectedPosition = INVALID_POSITION;
162 mOldSelectedRowId = INVALID_ROW_ID;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 setSelectedPositionInt(INVALID_POSITION);
165 setNextSelectedPositionInt(INVALID_POSITION);
166 invalidate();
167 }
168
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700169 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 * @see android.view.View#measure(int, int)
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700171 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 * Figure out the dimensions of this Spinner. The width comes from
173 * the widthMeasureSpec as Spinnners can't have their width set to
174 * UNSPECIFIED. The height is based on the height of the selected item
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700175 * plus padding.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 */
177 @Override
178 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
179 int widthMode = MeasureSpec.getMode(widthMeasureSpec);
180 int widthSize;
181 int heightSize;
182
183 mSpinnerPadding.left = mPaddingLeft > mSelectionLeftPadding ? mPaddingLeft
184 : mSelectionLeftPadding;
185 mSpinnerPadding.top = mPaddingTop > mSelectionTopPadding ? mPaddingTop
186 : mSelectionTopPadding;
187 mSpinnerPadding.right = mPaddingRight > mSelectionRightPadding ? mPaddingRight
188 : mSelectionRightPadding;
189 mSpinnerPadding.bottom = mPaddingBottom > mSelectionBottomPadding ? mPaddingBottom
190 : mSelectionBottomPadding;
191
192 if (mDataChanged) {
193 handleDataChanged();
194 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 int preferredHeight = 0;
197 int preferredWidth = 0;
198 boolean needsMeasuring = true;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 int selectedPosition = getSelectedItemPosition();
Romain Guyafc01552010-02-22 16:48:47 -0800201 if (selectedPosition >= 0 && mAdapter != null && selectedPosition < mAdapter.getCount()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 // Try looking in the recycler. (Maybe we were measured once already)
203 View view = mRecycler.get(selectedPosition);
204 if (view == null) {
205 // Make a new one
206 view = mAdapter.getView(selectedPosition, null, this);
Svetoslav Ganov42138042012-03-20 11:51:39 -0700207
208 if (view.getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
209 view.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 }
212
213 if (view != null) {
214 // Put in recycler for re-measuring and/or layout
215 mRecycler.put(selectedPosition, view);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 if (view.getLayoutParams() == null) {
218 mBlockLayoutRequests = true;
219 view.setLayoutParams(generateDefaultLayoutParams());
220 mBlockLayoutRequests = false;
221 }
222 measureChild(view, widthMeasureSpec, heightMeasureSpec);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 preferredHeight = getChildHeight(view) + mSpinnerPadding.top + mSpinnerPadding.bottom;
225 preferredWidth = getChildWidth(view) + mSpinnerPadding.left + mSpinnerPadding.right;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 needsMeasuring = false;
228 }
229 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 if (needsMeasuring) {
232 // No views -- just use padding
233 preferredHeight = mSpinnerPadding.top + mSpinnerPadding.bottom;
234 if (widthMode == MeasureSpec.UNSPECIFIED) {
235 preferredWidth = mSpinnerPadding.left + mSpinnerPadding.right;
236 }
237 }
238
239 preferredHeight = Math.max(preferredHeight, getSuggestedMinimumHeight());
240 preferredWidth = Math.max(preferredWidth, getSuggestedMinimumWidth());
241
Dianne Hackborn189ee182010-12-02 21:48:53 -0800242 heightSize = resolveSizeAndState(preferredHeight, heightMeasureSpec, 0);
243 widthSize = resolveSizeAndState(preferredWidth, widthMeasureSpec, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244
245 setMeasuredDimension(widthSize, heightSize);
246 mHeightMeasureSpec = heightMeasureSpec;
247 mWidthMeasureSpec = widthMeasureSpec;
248 }
249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 int getChildHeight(View child) {
251 return child.getMeasuredHeight();
252 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 int getChildWidth(View child) {
255 return child.getMeasuredWidth();
256 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 @Override
259 protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
260 return new ViewGroup.LayoutParams(
Romain Guy980a9382010-01-08 15:06:28 -0800261 ViewGroup.LayoutParams.MATCH_PARENT,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 ViewGroup.LayoutParams.WRAP_CONTENT);
263 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 void recycleAllViews() {
Romain Guyafc01552010-02-22 16:48:47 -0800266 final int childCount = getChildCount();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final AbsSpinner.RecycleBin recycleBin = mRecycler;
Romain Guyafc01552010-02-22 16:48:47 -0800268 final int position = mFirstPosition;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269
270 // All views go in recycler
Romain Guyafc01552010-02-22 16:48:47 -0800271 for (int i = 0; i < childCount; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 View v = getChildAt(i);
Romain Guyafc01552010-02-22 16:48:47 -0800273 int index = position + i;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 recycleBin.put(index, v);
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277
278 /**
279 * Jump directly to a specific item in the adapter data.
280 */
281 public void setSelection(int position, boolean animate) {
282 // Animate only if requested position is already on screen somewhere
283 boolean shouldAnimate = animate && mFirstPosition <= position &&
284 position <= mFirstPosition + getChildCount() - 1;
285 setSelectionInt(position, shouldAnimate);
286 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287
288 @Override
289 public void setSelection(int position) {
290 setNextSelectedPositionInt(position);
291 requestLayout();
292 invalidate();
293 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295
296 /**
297 * Makes the item at the supplied position selected.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700298 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 * @param position Position to select
300 * @param animate Should the transition be animated
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700301 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 */
303 void setSelectionInt(int position, boolean animate) {
304 if (position != mOldSelectedPosition) {
305 mBlockLayoutRequests = true;
306 int delta = position - mSelectedPosition;
307 setNextSelectedPositionInt(position);
308 layout(delta, animate);
309 mBlockLayoutRequests = false;
310 }
311 }
312
313 abstract void layout(int delta, boolean animate);
314
315 @Override
316 public View getSelectedView() {
317 if (mItemCount > 0 && mSelectedPosition >= 0) {
318 return getChildAt(mSelectedPosition - mFirstPosition);
319 } else {
320 return null;
321 }
322 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 /**
325 * Override to prevent spamming ourselves with layout requests
326 * as we place views
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700327 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 * @see android.view.View#requestLayout()
329 */
330 @Override
331 public void requestLayout() {
332 if (!mBlockLayoutRequests) {
333 super.requestLayout();
334 }
335 }
336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 @Override
338 public SpinnerAdapter getAdapter() {
339 return mAdapter;
340 }
341
342 @Override
343 public int getCount() {
344 return mItemCount;
345 }
346
347 /**
348 * Maps a point to a position in the list.
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700349 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 * @param x X in local coordinate
351 * @param y Y in local coordinate
352 * @return The position of the item which contains the specified point, or
353 * {@link #INVALID_POSITION} if the point does not intersect an item.
354 */
355 public int pointToPosition(int x, int y) {
356 Rect frame = mTouchFrame;
357 if (frame == null) {
358 mTouchFrame = new Rect();
359 frame = mTouchFrame;
360 }
361
362 final int count = getChildCount();
363 for (int i = count - 1; i >= 0; i--) {
364 View child = getChildAt(i);
365 if (child.getVisibility() == View.VISIBLE) {
366 child.getHitRect(frame);
367 if (frame.contains(x, y)) {
368 return mFirstPosition + i;
369 }
370 }
Andrei Stingaceanucf381102016-04-25 14:17:37 +0100371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 return INVALID_POSITION;
373 }
Andrei Stingaceanucf381102016-04-25 14:17:37 +0100374
375 @Override
376 protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
377 super.dispatchRestoreInstanceState(container);
378 // Restores the selected position when Spinner gets restored,
379 // rather than wait until the next measure/layout pass to do it.
380 handleDataChanged();
381 }
382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 static class SavedState extends BaseSavedState {
384 long selectedId;
385 int position;
386
387 /**
388 * Constructor called from {@link AbsSpinner#onSaveInstanceState()}
389 */
390 SavedState(Parcelable superState) {
391 super(superState);
392 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 /**
395 * Constructor called from {@link #CREATOR}
396 */
Adam Powell235ae5f2012-12-10 13:38:03 -0800397 SavedState(Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 super(in);
399 selectedId = in.readLong();
400 position = in.readInt();
401 }
402
403 @Override
404 public void writeToParcel(Parcel out, int flags) {
405 super.writeToParcel(out, flags);
406 out.writeLong(selectedId);
407 out.writeInt(position);
408 }
409
410 @Override
411 public String toString() {
412 return "AbsSpinner.SavedState{"
413 + Integer.toHexString(System.identityHashCode(this))
414 + " selectedId=" + selectedId
415 + " position=" + position + "}";
416 }
417
418 public static final Parcelable.Creator<SavedState> CREATOR
419 = new Parcelable.Creator<SavedState>() {
420 public SavedState createFromParcel(Parcel in) {
421 return new SavedState(in);
422 }
423
424 public SavedState[] newArray(int size) {
425 return new SavedState[size];
426 }
427 };
428 }
429
430 @Override
431 public Parcelable onSaveInstanceState() {
432 Parcelable superState = super.onSaveInstanceState();
433 SavedState ss = new SavedState(superState);
434 ss.selectedId = getSelectedItemId();
435 if (ss.selectedId >= 0) {
436 ss.position = getSelectedItemPosition();
437 } else {
438 ss.position = INVALID_POSITION;
439 }
440 return ss;
441 }
442
443 @Override
444 public void onRestoreInstanceState(Parcelable state) {
445 SavedState ss = (SavedState) state;
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 super.onRestoreInstanceState(ss.getSuperState());
448
449 if (ss.selectedId >= 0) {
450 mDataChanged = true;
451 mNeedSync = true;
452 mSyncRowId = ss.selectedId;
453 mSyncPosition = ss.position;
454 mSyncMode = SYNC_SELECTED_POSITION;
455 requestLayout();
456 }
457 }
458
459 class RecycleBin {
Romain Guyafc01552010-02-22 16:48:47 -0800460 private final SparseArray<View> mScrapHeap = new SparseArray<View>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461
462 public void put(int position, View v) {
463 mScrapHeap.put(position, v);
464 }
Aurimas Liutikas99441c52016-10-11 16:48:32 -0700465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 View get(int position) {
467 // System.out.print("Looking for " + position);
468 View result = mScrapHeap.get(position);
469 if (result != null) {
470 // System.out.println(" HIT");
471 mScrapHeap.delete(position);
472 } else {
473 // System.out.println(" MISS");
474 }
475 return result;
476 }
Romain Guyafc01552010-02-22 16:48:47 -0800477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 void clear() {
479 final SparseArray<View> scrapHeap = mScrapHeap;
480 final int count = scrapHeap.size();
481 for (int i = 0; i < count; i++) {
482 final View view = scrapHeap.valueAt(i);
483 if (view != null) {
484 removeDetachedView(view, true);
485 }
486 }
487 scrapHeap.clear();
488 }
489 }
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800490
491 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -0800492 public CharSequence getAccessibilityClassName() {
493 return AbsSpinner.class.getName();
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800494 }
Felipe Lemed04a6972017-03-02 12:56:18 -0800495
Felipe Lemed04a6972017-03-02 12:56:18 -0800496 @Override
Felipe Leme955e2522017-03-29 17:47:58 -0700497 public void autofill(AutofillValue value) {
498 if (!isEnabled()) return;
Felipe Lemed04a6972017-03-02 12:56:18 -0800499
Felipe Leme955e2522017-03-29 17:47:58 -0700500 if (!value.isList()) {
Philip P. Moltmann96689032017-03-09 13:19:55 -0800501 Log.w(LOG_TAG, value + " could not be autofilled into " + this);
Felipe Leme955e2522017-03-29 17:47:58 -0700502 return;
Philip P. Moltmann96689032017-03-09 13:19:55 -0800503 }
Felipe Leme955e2522017-03-29 17:47:58 -0700504
505 setSelection(value.getListValue());
Felipe Lemed04a6972017-03-02 12:56:18 -0800506 }
507
508 @Override
509 public @AutofillType int getAutofillType() {
510 return isEnabled() ? AUTOFILL_TYPE_LIST : AUTOFILL_TYPE_NONE;
511 }
512
513 @Override
Felipe Leme640f30a2017-03-06 15:44:06 -0800514 public AutofillValue getAutofillValue() {
515 return isEnabled() ? AutofillValue.forList(getSelectedItemPosition()) : null;
Felipe Lemed04a6972017-03-02 12:56:18 -0800516 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517}