OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chromoting; |
| 6 |
| 7 import android.accounts.Account; |
| 8 import android.content.Context; |
| 9 import android.view.LayoutInflater; |
| 10 import android.view.View; |
| 11 import android.view.ViewGroup; |
| 12 import android.widget.ArrayAdapter; |
| 13 import android.widget.TextView; |
| 14 |
| 15 /** SpinnerAdapter class used for the ActionBar accounts spinner. */ |
| 16 public class AccountsAdapter extends ArrayAdapter<Account> { |
| 17 private LayoutInflater mInflater; |
| 18 |
| 19 public AccountsAdapter(Context context, Account[] accounts) { |
| 20 // ArrayAdapter only uses the |resource| parameter to return a View from
getView() and |
| 21 // getDropDownView(). But these methods are overridden here to return cu
stom Views, so it's |
| 22 // OK to provide 0 as the resource for the base class. |
| 23 super(context, 0, accounts); |
| 24 mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFL
ATER_SERVICE); |
| 25 } |
| 26 |
| 27 @Override |
| 28 public View getView(int position, View convertView, ViewGroup parent) { |
| 29 View view = mInflater.inflate(R.layout.account_selected, parent, false); |
| 30 Account account = getItem(position); |
| 31 TextView target = (TextView)view.findViewById(R.id.account_name); |
| 32 target.setText(account.name); |
| 33 return view; |
| 34 } |
| 35 |
| 36 @Override |
| 37 public View getDropDownView(int position, View convertView, ViewGroup parent
) { |
| 38 TextView view = (TextView)mInflater.inflate(R.layout.account_dropdown, p
arent, false); |
| 39 Account account = getItem(position); |
| 40 view.setText(account.name); |
| 41 return view; |
| 42 } |
| 43 } |
OLD | NEW |