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.
5 package org.chromium.chromoting;
7 import android.view.View;
8 import android.view.ViewGroup;
9 import android.widget.ArrayAdapter;
10 import android.widget.TextView;
11 import android.widget.Toast;
13 /** Describes the appearance and behavior of each host list entry. */
14 class HostListAdapter extends ArrayAdapter<HostInfo> {
15 /** Color to use for hosts that are online. */
16 private static final String HOST_COLOR_ONLINE = "green";
18 /** Color to use for hosts that are offline. */
19 private static final String HOST_COLOR_OFFLINE = "red";
21 private Chromoting mChromoting;
24 public HostListAdapter(Chromoting chromoting, int textViewResourceId, HostInfo[] hosts) {
25 super(chromoting, textViewResourceId, hosts);
26 mChromoting = chromoting;
29 /** Generates a View corresponding to this particular host. */
31 public View getView(int position, View convertView, ViewGroup parent) {
32 TextView target = (TextView) super.getView(position, convertView, parent);
34 final HostInfo host = getItem(position);
36 target.setText(host.name);
37 target.setCompoundDrawablesWithIntrinsicBounds(
38 host.isOnline ? R.drawable.icon_host : R.drawable.icon_host_offline, 0, 0, 0);
41 target.setOnClickListener(new View.OnClickListener() {
43 public void onClick(View v) {
44 mChromoting.connectToHost(host);
48 target.setTextColor(mChromoting.getResources().getColor(R.color.host_offline_text));
49 target.setBackgroundResource(R.drawable.list_item_disabled_selector);
50 target.setOnClickListener(new View.OnClickListener() {
52 public void onClick(View v) {
53 Toast.makeText(mChromoting,
54 mChromoting.getString(R.string.host_offline_tooltip),
55 Toast.LENGTH_SHORT).show();