Chromium Code Reviews| Index: remoting/android/java/src/org/chromium/chromoting/HostListAdapter.java |
| diff --git a/remoting/android/java/src/org/chromium/chromoting/HostListAdapter.java b/remoting/android/java/src/org/chromium/chromoting/HostListAdapter.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a1c656c6614b4eecb5972f73f9a3fce073736ebc |
| --- /dev/null |
| +++ b/remoting/android/java/src/org/chromium/chromoting/HostListAdapter.java |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chromoting; |
| + |
| +import android.text.Html; |
| +import android.util.Log; |
| +import android.view.View; |
| +import android.view.ViewGroup; |
| +import android.widget.ArrayAdapter; |
| +import android.widget.TextView; |
| +import android.widget.Toast; |
| + |
| +import org.json.JSONException; |
| +import org.json.JSONObject; |
| + |
| +/** Describes the appearance and behavior of each host list entry. */ |
| +class HostListAdapter extends ArrayAdapter<JSONObject> { |
| + /** Color to use for hosts that are online. */ |
| + private static final String HOST_COLOR_ONLINE = "green"; |
| + |
| + /** Color to use for hosts that are offline. */ |
| + private static final String HOST_COLOR_OFFLINE = "red"; |
| + |
| + private Chromoting mChromoting; |
| + |
| + /** Constructor. */ |
| + public HostListAdapter(Chromoting chromoting, int textViewResourceId) { |
| + super(chromoting, textViewResourceId); |
| + mChromoting = chromoting; |
| + } |
| + |
| + /** Generates a View corresponding to this particular host. */ |
| + @Override |
| + public View getView(int position, View convertView, ViewGroup parent) { |
| + TextView target = (TextView)super.getView(position, convertView, parent); |
| + |
| + try { |
| + final JSONObject host = getItem(position); |
| + String status = host.getString("status"); |
| + boolean online = status.equals("ONLINE"); |
| + target.setText(Html.fromHtml(host.getString("hostName") + " (<font color = \"" + |
|
Sergey Ulanov
2013/12/28 02:17:30
nit: remove spaces around =
Ideally we should als
Lambros
2013/12/30 21:46:35
Done.
|
| + (online ? HOST_COLOR_ONLINE : HOST_COLOR_OFFLINE) + "\">" + status + |
| + "</font>)")); |
| + |
| + if (online) { |
| + target.setOnClickListener(new View.OnClickListener() { |
| + @Override |
| + public void onClick(View v) { |
| + mChromoting.connectToHost(host); |
| + } |
| + }); |
| + } else { |
| + // Disallow interaction with this entry. |
| + target.setEnabled(false); |
| + } |
| + } catch (JSONException ex) { |
| + Log.w("hostlist", ex); |
| + Toast.makeText(mChromoting, mChromoting.getString(R.string.error_displaying_host), |
| + Toast.LENGTH_LONG).show(); |
| + |
| + // Close the application. |
| + mChromoting.finish(); |
| + } |
| + |
| + return target; |
| + } |
| +} |