Example usage for android.text TextUtils htmlEncode

List of usage examples for android.text TextUtils htmlEncode

Introduction

In this page you can find the example usage for android.text TextUtils htmlEncode.

Prototype

public static String htmlEncode(String s) 

Source Link

Document

Html-encode the string.

Usage

From source file:com.luyaozhou.recognizethisforglass.ViewFinder.java

private String formatSOAPMessage(String method, HashMap<String, String> params) {
    StringBuilder mBuilder = new StringBuilder();
    mBuilder.setLength(0);// ww w.  java2 s.  c o  m
    mBuilder.append("<?xml version='1.0' encoding='utf-8'?>");
    mBuilder.append(
            "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>");
    mBuilder.append("<soap:Body><");
    mBuilder.append(method);
    mBuilder.append(" xmlns='http://www.miteksystems.com/'>");
    Iterator<String> it = params.keySet().iterator();
    String key;
    while (it.hasNext()) {
        key = it.next();

        mBuilder.append("<");
        mBuilder.append(key);
        mBuilder.append(">");

        mBuilder.append(TextUtils.htmlEncode(params.get(key)));

        mBuilder.append("</");
        mBuilder.append(key);
        mBuilder.append(">");

    }

    mBuilder.append("</");
    mBuilder.append(method);
    mBuilder.append("></soap:Body></soap:Envelope>");
    return mBuilder.toString();
}

From source file:com.irccloud.android.Notifications.java

public synchronized void addNotification(int cid, int bid, long eid, String from, String message, String chan,
        String buffer_type, String message_type) {
    long last_eid = getLastSeenEid(bid);
    if (eid <= last_eid) {
        Crashlytics.log("Refusing to add notification for seen eid: " + eid);
        return;//from ww w  .  jav  a 2s  .  c o m
    }

    String network = getNetwork(cid);
    if (network == null)
        addNetwork(cid, "Unknown Network");
    Notification n = new Notification();
    n.bid = bid;
    n.cid = cid;
    n.eid = eid;
    n.nick = from;
    n.message = TextUtils.htmlEncode(ColorFormatter.emojify(message));
    n.chan = chan;
    n.buffer_type = buffer_type;
    n.message_type = message_type;
    n.network = network;

    synchronized (mNotifications) {
        //Log.d("IRCCloud", "Add: " + n);
        mNotifications.add(n);
        Collections.sort(mNotifications, new comparator());
    }
    save();
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_settings:
        startActivity(new Intent(this, ZumoPreferenceActivity.class));
        return true;

    case R.id.menu_run_tests:
        if (getMobileServiceKey().trim() == "" || getMobileServiceURL().trim() == "") {
            startActivity(new Intent(this, ZumoPreferenceActivity.class));
        } else {/*w  ww.jav  a2s .c o m*/
            runTests();
        }
        return true;

    case R.id.menu_check_all:
        changeCheckAllTests(true);
        return true;

    case R.id.menu_uncheck_all:
        changeCheckAllTests(false);
        return true;

    case R.id.menu_reset:
        refreshTestGroupsAndLog();
        return true;

    case R.id.menu_view_log:
        AlertDialog.Builder logDialogBuilder = new AlertDialog.Builder(this);
        logDialogBuilder.setTitle("Log");

        final WebView webView = new WebView(this);

        String logContent = TextUtils.htmlEncode(mLog.toString()).replace("\n", "<br />");
        String logHtml = "<html><body><pre>" + logContent + "</pre></body></html>";
        webView.loadData(logHtml, "text/html", "utf-8");

        logDialogBuilder.setPositiveButton("Copy", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                clipboardManager.setText(mLog.toString());
            }
        });

        logDialogBuilder.setView(webView);

        logDialogBuilder.create().show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.g_node.gca.abstracts.AbstractContentTabFragment.java

private void getAndUpdateAbstractContent() {

    cursorTwo.moveToFirst();//from ww w .  jav a  2 s.  c o  m

    do {

        String Text = cursorTwo.getString(cursorTwo.getColumnIndexOrThrow("ABSRACT_TEXT"));
        Text = TextUtils.htmlEncode(Text);
        content.getSettings().setJavaScriptEnabled(true);
        content.getSettings().setBuiltInZoomControls(false);
        if (Text.contains("$")) {
            //if (true){
            content.loadDataWithBaseURL("http://bar", "<script type='text/x-mathjax-config'>"
                    + "MathJax.Hub.Config({ " + "showMathMenu: false, "
                    + "jax: ['input/TeX','output/HTML-CSS'], "
                    + "tex2jax: {inlineMath: [ ['$','$']],displayMath: [ ['$$','$$'] ],processEscapes: true},"
                    + "extensions: ['tex2jax.js'], " + "TeX: { extensions: ['AMSmath.js','AMSsymbols.js',"
                    + "'noErrors.js','noUndefined.js'] }, " + "});</script>" + "<script type='text/javascript' "
                    + "src='file:///android_asset/MathJax/MathJax.js'" + "></script><span id='math'>" + Text
                    + "</span>", "text/html", "UTF-8", "");
            content.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
        } else {
            content.loadDataWithBaseURL("http://bar", Text, "text/html", "UTF-8", "");

        }

    } while (cursorTwo.moveToNext());

    //parsing SortID to extract group id & poster number and add it to abstract text body.
    cursorTwo.moveToFirst();
    int sortID = cursorTwo.getInt(cursorTwo.getColumnIndexOrThrow("SORTID"));
    Log.i("GCA-SortID", "Sort ID: " + sortID);
    if (sortID != 0) {
        int groupid = ((sortID & (0xFFFF << 16)) >> 16);
        int poster_no = sortID & 0xFFFF;
        Log.i("GCA-groupid", "groupid: " + groupid);
        Log.i("GCA-posterno", "Poster Nr: " + poster_no);
        //absSortID.append("\r\nSort ID: " + sortID);
        title.append("   (" + get_groupid_str(groupid));
        title.append("" + poster_no + ")");

    } else {
        absSortID.setVisibility(View.GONE);
    }
}

From source file:com.irccloud.android.CollapsedEventsList.java

public String formatNick(String nick, String from_mode, boolean colorize) {
    ObjectNode PREFIX = null;/*from   w  w  w.  jav  a2  s.  co m*/
    if (server != null)
        PREFIX = server.PREFIX;

    if (PREFIX == null) {
        PREFIX = new ObjectMapper().createObjectNode();
        PREFIX.put(server != null ? server.MODE_OPER : "Y", "!");
        PREFIX.put(server != null ? server.MODE_OWNER : "q", "~");
        PREFIX.put(server != null ? server.MODE_ADMIN : "a", "&");
        PREFIX.put(server != null ? server.MODE_OP : "o", "@");
        PREFIX.put(server != null ? server.MODE_HALFOP : "h", "%");
        PREFIX.put(server != null ? server.MODE_VOICED : "v", "+");
    }

    String[] colors = { "fc009a", "ff1f1a", "d20004", "fd6508", "880019", "c7009c", "804fc4", "5200b7",
            "123e92", "1d40ff", "108374", "2e980d", "207607", "196d61" };
    String color = null;

    if (colorize) {
        // Normalise a bit
        // typically ` and _ are used on the end alone
        String normalizedNick = nick.toLowerCase().replaceAll("[`_]+$", "");
        //remove |<anything> from the end
        normalizedNick = normalizedNick.replaceAll("|.*$", "");

        Double hash = 0.0;

        for (int i = 0; i < normalizedNick.length(); i++) {
            hash = ((int) normalizedNick.charAt(i)) + (double) ((int) (hash.longValue()) << 6)
                    + (double) ((int) (hash.longValue()) << 16) - hash;
        }

        color = colors[(int) Math.abs(hash.longValue() % 14)];
    }

    StringBuilder output = new StringBuilder();
    boolean showSymbol = false;
    try {
        if (NetworkConnection.getInstance().getUserInfo() != null
                && NetworkConnection.getInstance().getUserInfo().prefs != null)
            showSymbol = NetworkConnection.getInstance().getUserInfo().prefs.getBoolean("mode-showsymbol");
    } catch (Exception e) {
    }
    String mode = "";
    if (from_mode != null && from_mode.length() > 0) {
        if (from_mode.contains(server != null ? server.MODE_OPER : "Y"))
            mode = server != null ? server.MODE_OPER : "Y";
        else if (from_mode.contains(server != null ? server.MODE_OWNER : "q"))
            mode = server != null ? server.MODE_OWNER : "q";
        else if (from_mode.contains(server != null ? server.MODE_ADMIN : "a"))
            mode = server != null ? server.MODE_ADMIN : "a";
        else if (from_mode.contains(server != null ? server.MODE_OP : "o"))
            mode = server != null ? server.MODE_OP : "o";
        else if (from_mode.contains(server != null ? server.MODE_HALFOP : "h"))
            mode = server != null ? server.MODE_HALFOP : "h";
        else if (from_mode.contains(server != null ? server.MODE_VOICED : "v"))
            mode = server != null ? server.MODE_VOICED : "v";
        else
            mode = from_mode.substring(0, 1);
    }
    if (mode != null && mode.length() > 0) {
        if (mode_colors.containsKey(mode))
            output.append("\u0004").append(mode_colors.get(mode)).append("\u0002");
        else
            output.append("\u0002");
        if (showSymbol) {
            if (PREFIX.has(mode))
                output.append(TextUtils.htmlEncode(PREFIX.get(mode).asText()));
        } else {
            output.append("");
        }
        output.append("\u000f ");
    }

    if (color != null)
        output.append("\u0004").append(color);
    output.append(nick);
    if (color != null)
        output.append("\u0004");
    return output.toString();
}

From source file:busradar.madison.StopDialog.java

@Override
public void show() {
    new Thread() {
        @Override/* w ww. jav  a2 s.c o m*/
        public void run() {

            for (final RouteURL r : routes) {
                G.activity.runOnUiThread(new Runnable() {
                    public void run() {
                        cur_loading_text
                                .setText(String.format("Loading route %s...", G.route_points[r.route].name));
                    }
                });

                final ArrayList<RouteTime> curtimes = new ArrayList<RouteTime>();
                try {
                    System.err.printf("BusRadar URL %s\n", TRANSITTRACKER_URL + r.url);
                    URL url = new URL(TRANSITTRACKER_URL + r.url);
                    URLConnection url_conn = url.openConnection();
                    if (url_conn instanceof HttpsURLConnection) {
                        ((HttpsURLConnection) url_conn).setHostnameVerifier(new HostnameVerifier() {

                            public boolean verify(String hostname, SSLSession session) {
                                return true;
                            }
                        });
                    }
                    InputStream is = url_conn.getInputStream();
                    Scanner scan = new Scanner(is, "UTF-8");

                    //String outstr_cur = "Route " + r.route + "\n";

                    if (scan.findWithinHorizon(num_vehicles_re, 0) != null) {

                        while (scan.findWithinHorizon(time_re, 0) != null) {
                            RouteTime time = new RouteTime();
                            time.route = r.route;
                            time.time = scan.match().group(1).replace(".", "");
                            time.dir = scan.match().group(2);
                            //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time);

                            SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US);
                            time.date = f.parse(time.time);
                            r.status = RouteURL.DONE;

                            //outstr_cur += String.format("%s to %s\n", time.time, time.dir);
                            curtimes.add(time);
                        }

                        while (scan.findWithinHorizon(time_re_backup, 0) != null) {
                            RouteTime time = new RouteTime();
                            time.route = r.route;
                            time.time = scan.match().group(1).replace(".", "");
                            //time.dir = scan.match().group(2);
                            //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time);

                            SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US);
                            time.date = f.parse(time.time);
                            r.status = RouteURL.DONE;

                            //outstr_cur += String.format("%s to %s\n", time.time, time.dir);
                            curtimes.add(time);
                        }

                    }

                    //                  else if (scan.findWithinHorizon(no_busses_re, 0) != null) {
                    //                     r.status = RouteURL.NO_MORE_TODAY; 
                    //                  } 
                    //                  else if (scan.findWithinHorizon(no_timepoints_re, 0) != null) {
                    //                     r.status = RouteURL.NO_TIMEPOINTS;
                    //                  }
                    //                  else {
                    //                     r.status = RouteURL.ERROR;
                    //                     System.out.printf("BusRadar: Could not get stop info for %s\n", r.url);
                    //                     
                    //                     throw new Exception("Error parsing TransitTracker webpage.");
                    //                  }
                    else {
                        r.status = RouteURL.NO_STOPS_UNKONWN;
                    }

                    //r.text = outstr_cur;

                    G.activity.runOnUiThread(new Runnable() {
                        public void run() {
                            times.addAll(curtimes);
                            StopDialog.this.update_times();
                        }
                    });

                }
                //               catch  (final IOException ioe) {
                //                  log_problem(ioe);
                //                  G.activity.runOnUiThread(new Runnable() {
                //                     public void run() {
                //                        final Context ctx = StopDialog.this.getContext();
                //                        
                //                        StopDialog.this.setContentView(new RelativeLayout(ctx) {{
                //                           addView(new TextView(ctx) {{
                //                              setText(Html.fromHtml("Error downloading data. Is the data connection enabled?"+
                //                                                  "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>"+ioe));
                //                              setPadding(5, 5, 5, 5);
                //                              this.setMovementMethod(LinkMovementMethod.getInstance());
                //                           }}, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
                //                        }});
                //                     }
                //                  });                  
                //                  return;
                //               }
                catch (Exception e) {
                    log_problem(e);

                    String custom_msg = "";
                    final String turl = TRANSITTRACKER_URL + r.url;
                    if ((e instanceof SocketException) || (e instanceof UnknownHostException)) {
                        // data connection doesn't work
                        custom_msg = "Error downloading data. Is the data connection enabled?"
                                + "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>"
                                + TextUtils.htmlEncode(e.toString());
                    } else {

                        String rurl = String.format(
                                "http://www.cityofmadison.com/metro/BusStopDepartures/StopID/%04d.pdf", stopid);
                        custom_msg = "Trouble retrieving real-time arrival estimates from <a href='" + turl
                                + "'>this</a> TransitTracker webpage, which is displayed below. "
                                + "Meanwhile, try PDF timetable <a href='" + rurl + "'>here</a>. "
                                + "Contact us at <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a> to report the problem.<p>"
                                + TextUtils.htmlEncode(e.toString());
                    }

                    final String msg = custom_msg;

                    G.activity.runOnUiThread(new Runnable() {
                        public void run() {
                            final Context ctx = StopDialog.this.getContext();

                            StopDialog.this.setContentView(new RelativeLayout(ctx) {
                                {
                                    addView(new TextView(ctx) {
                                        {
                                            setId(1);
                                            setText(Html.fromHtml(msg));
                                            setPadding(5, 5, 5, 5);
                                            this.setMovementMethod(LinkMovementMethod.getInstance());
                                        }
                                    }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

                                    addView(new WebView(ctx) {
                                        {
                                            setWebViewClient(new WebViewClient());
                                            loadUrl(turl);
                                        }
                                    }, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                                            LayoutParams.FILL_PARENT) {
                                        {
                                            addRule(RelativeLayout.BELOW, 1);
                                        }
                                    });
                                }
                            });
                        }
                    });
                    return;
                }

            }

            G.activity.runOnUiThread(new Runnable() {
                public void run() {
                    cur_loading_text.setText("");
                }
            });
        }
    }.start();

    super.show();

}

From source file:edu.cens.loci.ui.PlaceViewActivity.java

/**
 * Build up the entries to display on the screen.
 *
 * @param personCursor the URI for the contact being displayed
 *///  w  w  w  . j a v  a2 s .c om
private final void buildEntries() {

    final Context context = this;
    final Sources sources = Sources.getInstance(context);

    ArrayList<ViewEntry> items = new ArrayList<ViewEntry>();

    int typeIcon = R.drawable.icon_question;
    String typeString = "Unknown";

    if (mPlace.type == Places.TYPE_GPS) {
        typeIcon = R.drawable.icon_satellite;
        typeString = "GPS";
    } else if (mPlace.type == Places.TYPE_WIFI) {
        typeIcon = R.drawable.icon_wifi;
        typeString = "Wi-Fi";
    }

    // detection type
    items.add(new ViewEntry(LIST_ACTION_NO_ACTION, typeIcon, "Dectection Sensor", typeString, null));

    // recent visit time
    String recentVisitTime = getRecentVisitSubstring(); //"May 4, 3:00pm, 1hr";
    items.add(new ViewEntry(LIST_ACTION_VIEW_VISITS, R.drawable.ic_clock_strip_desk_clock, "View recent visits",
            recentVisitTime, null));

    for (Entity entity : mEntities) {
        final ContentValues entValues = entity.getEntityValues();
        final String accountType = entValues.getAsString(Places.ACCOUNT_TYPE);
        final long placeId = entValues.getAsLong(Places._ID);

        for (NamedContentValues subValue : entity.getSubValues()) {
            final ContentValues entryValues = subValue.values;
            entryValues.put(Places.Data.PLACE_ID, placeId);
            final long dataId = entryValues.getAsLong(Data._ID);
            final String mimeType = entryValues.getAsString(Data.MIMETYPE);
            if (mimeType == null)
                continue;

            final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this,
                    PlacesSource.LEVEL_MIMETYPES);
            if (kind == null)
                continue;

            //Log.e(TAG, "buildEntries: dataId=" + dataId + ", mimeType=" + mimeType);

            // public ViewEntry(int action, int icon, String text, String subtext, Intent intent) {

            if (WifiFingerprint.CONTENT_ITEM_TYPE.equals(mimeType)) {
                String fingerprint = entryValues.getAsString(WifiFingerprint.FINGERPRINT);
                long timestamp = entryValues.getAsLong(WifiFingerprint.TIMESTAMP);
                String subtext = "Captured at " + MyDateUtils.getAbrv_MMM_d_h_m(timestamp);
                //Log.d(TAG, fingerprint);
                //String apsAbstract = getWifiInfoSubstring(5, fingerprint); 
                ViewEntry item = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless,
                        "View Wi-Fi APs", subtext, null);
                item.extra_string = fingerprint;
                mWifiEntries.add(item);
            } else if (GpsCircleArea.CONTENT_ITEM_TYPE.equals(mimeType)) {
                double lat = entryValues.getAsDouble(GpsCircleArea.LATITUDE);
                double lon = entryValues.getAsDouble(GpsCircleArea.LONGITUDE);
                float rad = entryValues.getAsFloat(GpsCircleArea.RADIUS);
                //Log.d(TAG, "lat=" + lat + ",lon=" + lon + ",rad=" + rad);
                ViewEntry item = new ViewEntry(-1, -1, null, null, null);
                item.extra_double1 = lat;
                item.extra_double2 = lon;
                item.extra_float1 = rad;
                mGpsEntries.add(item);
            } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                String uri = "geo:0,0?q=" + TextUtils.htmlEncode(item.data);
                item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                item.action = LIST_ACTION_POSTAL;
                item.text = item.label;
                item.subtext = item.data;
                mPostalEntries.add(item);
            } else if (Keyword.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.text = item.data;
                item.subtext = null;
                mTagEntries.add(item);
            } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.text = item.label;
                item.subtext = item.data;
                mOtherEntries.add(item);
            } else if (Website.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.uri = null;
                item.action = LIST_ACTION_WEBSITE;
                item.text = item.label;
                item.subtext = item.data;
                item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.data));
                mWebsiteEntries.add(item);
            }
        }
    }

    for (ViewEntry item : mWifiEntries) {
        items.add(item);
    }
    mWifiEntries.clear();
    for (ViewEntry item : mPostalEntries) {
        items.add(item);
    }
    mPostalEntries.clear();
    for (ViewEntry item : mTagEntries) {
        items.add(item);
    }
    mTagEntries.clear();
    for (ViewEntry item : mWebsiteEntries) {
        items.add(item);
    }
    mWebsiteEntries.clear();
    for (ViewEntry item : mOtherEntries) {
        items.add(item);
    }
    mOtherEntries.clear();
    // Log.d(TAG, "size of items = " + items.size());

    ViewEntryAdapter adapter = new ViewEntryAdapter(this, R.layout.place_view_list_item, items);
    mListView.setAdapter(adapter);
}

From source file:com.vuze.android.remote.fragment.FilesFragment.java

protected boolean saveFile(Map<?, ?> selectedFile) {
    if (selectedFile == null) {
        return false;
    }// w ww.  ja  va 2 s.  c  o m
    if (sessionInfo == null) {
        return false;
    }
    if (sessionInfo.getRemoteProfile().isLocalHost()) {
        return false;
    }
    final String contentURL = getContentURL(selectedFile);
    if (contentURL == null || contentURL.length() == 0) {
        return false;
    }

    final File directory = AndroidUtils.getDownloadDir();
    final File outFile = new File(directory, MapUtils.getMapString(selectedFile, "name", "foo.txt"));

    if (VuzeRemoteApp.getNetworkState().isOnlineMobile()) {
        Resources resources = getActivity().getResources();
        String message = resources.getString(R.string.on_mobile,
                resources.getString(R.string.save_content, TextUtils.htmlEncode(outFile.getName())));
        Builder builder = new AlertDialog.Builder(getActivity()).setMessage(Html.fromHtml(message))
                .setPositiveButton(R.string.yes, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        saveFile(contentURL, outFile);
                    }
                }).setNegativeButton(R.string.no, null);
        builder.show();
        return true;
    }

    saveFile(contentURL, outFile);

    return true;
}

From source file:com.irccloud.android.activity.MainActivity.java

private void show_topic_popup() {
    if (buffer == null)
        return;//  www .jav a  2  s.  c om
    ChannelsDataSource.Channel c = ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid);
    if (c != null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
        View v = getLayoutInflater().inflate(R.layout.dialog_topic, null);
        if (c.topic_text.length() > 0) {
            String author = "";
            if (c.topic_author != null && c.topic_author.length() > 0) {
                author = " Set by " + c.topic_author;
                if (c.topic_time > 0) {
                    author += " on " + DateFormat.getDateTimeInstance().format(new Date(c.topic_time * 1000));
                }
                v.findViewById(R.id.setBy).setVisibility(View.VISIBLE);
                ((TextView) v.findViewById(R.id.setBy)).setText(author);
            }
            ((TextView) v.findViewById(R.id.topic)).setText(ColorFormatter.html_to_spanned(
                    ColorFormatter.emojify(ColorFormatter.irc_to_html(TextUtils.htmlEncode(c.topic_text))),
                    true, server));
        } else {
            ((TextView) v.findViewById(R.id.topic)).setText("No topic set.");
        }
        if (c.mode.length() > 0) {
            v.findViewById(R.id.mode).setVisibility(View.VISIBLE);
            ((TextView) v.findViewById(R.id.mode)).setText("Mode: +" + c.mode);

            for (ChannelsDataSource.Mode m : c.modes) {
                switch (m.mode) {
                case "i":
                    v.findViewById(R.id.mode_i).setVisibility(View.VISIBLE);
                    break;
                case "k":
                    v.findViewById(R.id.mode_k).setVisibility(View.VISIBLE);
                    ((TextView) v.findViewById(R.id.key)).setText(m.param);
                    break;
                case "m":
                    v.findViewById(R.id.mode_m).setVisibility(View.VISIBLE);
                    break;
                case "n":
                    v.findViewById(R.id.mode_n).setVisibility(View.VISIBLE);
                    break;
                case "p":
                    v.findViewById(R.id.mode_p).setVisibility(View.VISIBLE);
                    break;
                case "s":
                    v.findViewById(R.id.mode_s).setVisibility(View.VISIBLE);
                    break;
                case "t":
                    v.findViewById(R.id.mode_t).setVisibility(View.VISIBLE);
                    break;
                }
            }
        }
        builder.setView(v);
        builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        boolean canEditTopic;
        if (c.hasMode("t")) {
            UsersDataSource.User self_user = UsersDataSource.getInstance().getUser(buffer.bid, server.nick);
            canEditTopic = (self_user != null
                    && (self_user.mode.contains(server != null ? server.MODE_OPER : "Y")
                            || self_user.mode.contains(server != null ? server.MODE_OWNER : "q")
                            || self_user.mode.contains(server != null ? server.MODE_ADMIN : "a")
                            || self_user.mode.contains(server != null ? server.MODE_OP : "o")
                            || self_user.mode.contains(server != null ? server.MODE_HALFOP : "h")));
        } else {
            canEditTopic = true;
        }

        if (canEditTopic) {
            builder.setPositiveButton("Edit Topic", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    editTopic();
                }
            });
        }
        final AlertDialog dialog = builder.create();
        dialog.setOwnerActivity(MainActivity.this);
        dialog.show();

        ((TextView) v.findViewById(R.id.topic)).setMovementMethod(new LinkMovementMethod() {
            @Override
            public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
                if (super.onTouchEvent(widget, buffer, event) && event.getAction() == MotionEvent.ACTION_UP) {
                    dialog.dismiss();
                    return true;
                }
                return false;
            }
        });
    }
}