Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(969)

Unified Diff: remoting/android/java/src/org/chromium/chromoting/HostListAdapter.java

Issue 102273006: Refactor Chromoting.java to pull out some nested classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/Chromoting.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..12f9c637f81a388a39cc6adf41ef527d89a9fe1a
--- /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=\"" +
+ (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;
+ }
+}
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/Chromoting.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698