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.vuze.android.remote.fragment.FilesFragment.java

private void reallySaveFile(final String contentURL, final File outFile) {
    showProgressBar();/*  www  .j a  v a 2  s . c  om*/
    new Thread(new Runnable() {
        String failText = null;

        @Override
        public void run() {
            try {
                AndroidUtils.copyUrlToFile(contentURL, outFile);
            } catch (Exception e) {
                VuzeEasyTracker.getInstance().logError(e);
                failText = e.getMessage();
            }
            FragmentActivity activity = getActivity();
            if (activity == null) {
                return;
            }
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    hideProgressBar();
                    Activity activity = getActivity();
                    Context context = activity == null ? VuzeRemoteApp.getContext() : activity;
                    String s;
                    if (failText == null) {
                        s = context.getResources().getString(R.string.content_saved,
                                TextUtils.htmlEncode(outFile.getName()),
                                TextUtils.htmlEncode(outFile.getParent()));
                    } else {
                        s = context.getResources().getString(R.string.content_saved_failed,
                                TextUtils.htmlEncode(outFile.getName()),
                                TextUtils.htmlEncode(outFile.getParent()), TextUtils.htmlEncode(failText));
                    }
                    Toast.makeText(context, Html.fromHtml(s), Toast.LENGTH_SHORT).show();
                }
            });
        }
    }).start();
}

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

protected boolean streamFile(final Map<?, ?> selectedFile) {

    if (VuzeRemoteApp.getNetworkState().isOnlineMobile()) {
        String name = MapUtils.getMapString(selectedFile, "name", null);

        Resources resources = getActivity().getResources();
        String message = resources.getString(R.string.on_mobile,
                resources.getString(R.string.stream_content, TextUtils.htmlEncode(name)));
        Builder builder = new AlertDialog.Builder(getActivity()).setMessage(Html.fromHtml(message))
                .setPositiveButton(R.string.yes, new OnClickListener() {
                    @Override//from  w  ww . j a  va  2  s .  c  o m
                    public void onClick(DialogInterface dialog, int which) {
                        reallyStreamFile(selectedFile);
                    }
                }).setNegativeButton(R.string.no, null);
        builder.show();
    } else {
        reallyStreamFile(selectedFile);
    }
    return true;
}

From source file:com.irccloud.android.data.EventsDataSource.java

public Event addEvent(IRCCloudJSONObject event) {
    synchronized (events) {
        if (!events.containsKey(event.bid()))
            events.put(event.bid(), new TreeMap<Long, Event>());

        Event e = getEvent(event.eid(), event.bid());
        if (e == null) {
            e = new Event();
            events.get(event.bid()).put(event.eid(), e);
        }/*from  w  w w  . j av  a  2s  .  c o m*/
        e.cid = event.cid();
        e.bid = event.bid();
        e.eid = event.eid();
        e.type = event.type();
        e.msg = event.getString("msg");
        e.hostmask = event.getString("hostmask");
        e.from = event.getString("from");
        e.from_mode = event.getString("from_mode");
        e.chan = event.getString("chan");
        if (event.has("newnick"))
            e.nick = event.getString("newnick");
        else if (event.has("nick"))
            e.nick = event.getString("nick");
        else
            e.nick = null;
        e.old_nick = event.getString("oldnick");
        e.server = event.getString("server");
        e.diff = event.getString("diff");
        e.highlight = event.getBoolean("highlight");
        e.self = event.getBoolean("self");
        e.to_chan = event.getBoolean("to_chan");
        e.to_buffer = event.getBoolean("to_buffer");
        e.ops = event.getJsonNode("ops");
        e.color = R.color.row_message_label;
        e.bg_color = R.color.message_bg;
        e.row_type = 0;
        e.html = null;
        e.group_msg = null;
        e.linkify = true;
        e.target_mode = null;
        e.pending = false;
        e.failed = false;
        e.command = null;
        e.day = -1;
        e.entities = event.getJsonNode("entities");

        if (event.has("reqid"))
            e.reqid = event.getInt("reqid");
        else
            e.reqid = -1;

        if (e.from != null)
            e.from = TextUtils.htmlEncode(e.from);

        if (e.msg != null)
            e.msg = TextUtils.htmlEncode(e.msg);

        Formatter f = formatterMap.get(e.type);
        if (f != null)
            f.format(event, e);

        if (event.has("value") && !event.type().startsWith("cap_")) {
            e.msg = "<pre>" + event.getString("value") + " " + e.msg + "</pre>";
        }

        if (e.highlight)
            e.bg_color = R.color.highlight;

        if (e.self)
            e.bg_color = R.color.self;

        if (highest_eid < event.eid())
            highest_eid = event.eid();

        return e;
    }
}

From source file:com.irccloud.android.fragment.MessageViewFragment.java

@Override
public void setArguments(Bundle args) {
    ready = false;/*from  w  w w . j a  va2s. com*/
    if (heartbeatTask != null)
        heartbeatTask.cancel(true);
    heartbeatTask = null;
    if (tapTimerTask != null)
        tapTimerTask.cancel();
    tapTimerTask = null;
    if (buffer != null && buffer.bid != args.getInt("bid", -1) && adapter != null)
        adapter.clearLastSeenEIDMarker();
    buffer = BuffersDataSource.getInstance().getBuffer(args.getInt("bid", -1));
    if (buffer != null) {
        server = ServersDataSource.getInstance().getServer(buffer.cid);
        Crashlytics.log(Log.DEBUG, "IRCCloud", "MessageViewFragment: switched to bid: " + buffer.bid);
    } else {
        Crashlytics.log(Log.WARN, "IRCCloud", "MessageViewFragment: couldn't find buffer to switch to");
    }
    requestingBacklog = false;
    avgInsertTime = 0;
    newMsgs = 0;
    newMsgTime = 0;
    newHighlights = 0;
    earliest_eid = 0;
    backlog_eid = 0;
    currentCollapsedEid = -1;
    lastCollapsedDay = -1;
    if (server != null) {
        ignore.setIgnores(server.ignores);
        if (server.away != null && server.away.length() > 0) {
            awayTxt.setText(ColorFormatter
                    .html_to_spanned(
                            ColorFormatter.irc_to_html(TextUtils.htmlEncode("Away (" + server.away + ")")))
                    .toString());
            awayView.setVisibility(View.VISIBLE);
        } else {
            awayView.setVisibility(View.GONE);
        }
        collapsedEvents.setServer(server);
        update_status(server.status, server.fail_info);
    }
    if (unreadTopView != null)
        unreadTopView.setVisibility(View.GONE);
    backlogFailed.setVisibility(View.GONE);
    loadBacklogButton.setVisibility(View.GONE);
    try {
        if (getListView().getHeaderViewsCount() == 0) {
            getListView().addHeaderView(headerViewContainer);
        }
    } catch (IllegalStateException e) {
    }
    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) headerView.getLayoutParams();
    lp.topMargin = 0;
    headerView.setLayoutParams(lp);
    lp = (ViewGroup.MarginLayoutParams) backlogFailed.getLayoutParams();
    lp.topMargin = 0;
    backlogFailed.setLayoutParams(lp);
    if (buffer != null && EventsDataSource.getInstance().getEventsForBuffer(buffer.bid) != null) {
        requestingBacklog = true;
        if (refreshTask != null)
            refreshTask.cancel(true);
        refreshTask = new RefreshTask();
        if (args.getBoolean("fade")) {
            Crashlytics.log(Log.DEBUG, "IRCCloud",
                    "MessageViewFragment: Loading message contents in the background");
            refreshTask.execute((Void) null);
        } else {
            Crashlytics.log(Log.DEBUG, "IRCCloud", "MessageViewFragment: Loading message contents");
            refreshTask.onPreExecute();
            refreshTask.onPostExecute(refreshTask.doInBackground());
        }
    } else {
        if (buffer == null || buffer.min_eid == 0 || earliest_eid == buffer.min_eid
                || conn.getState() != NetworkConnection.STATE_CONNECTED || !conn.ready) {
            headerView.setVisibility(View.GONE);
        } else {
            headerView.setVisibility(View.VISIBLE);
        }
        if (adapter != null) {
            adapter.clear();
            adapter.notifyDataSetInvalidated();
        }
        mListener.onMessageViewReady();
        ready = true;
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.BrandingMgr.java

private BrandingResult extractBranding(final BrandedItem item, final File encryptedBrandingFile,
        final File tmpDecryptedBrandingFile, final File tmpBrandingDir) throws BrandingFailureException {
    try {//w  w w  .j a  v a2 s  .c o m
        L.i("Extracting " + tmpDecryptedBrandingFile + " (" + item.brandingKey + ")");
        File brandingFile = new File(tmpBrandingDir, "branding.html");
        File watermarkFile = null;
        Integer backgroundColor = null;
        Integer menuItemColor = null;
        ColorScheme scheme = ColorScheme.light;
        boolean showHeader = true;
        String contentType = null;
        boolean wakelockEnabled = false;
        ByteArrayOutputStream brandingBos = new ByteArrayOutputStream();
        try {
            MessageDigest digester = MessageDigest.getInstance("SHA256");
            DigestInputStream dis = new DigestInputStream(
                    new BufferedInputStream(new FileInputStream(tmpDecryptedBrandingFile)), digester);
            try {
                ZipInputStream zis = new ZipInputStream(dis);
                try {
                    byte data[] = new byte[BUFFER_SIZE];
                    ZipEntry entry;
                    while ((entry = zis.getNextEntry()) != null) {
                        L.d("Extracting: " + entry);
                        int count = 0;
                        if (entry.getName().equals("branding.html")) {
                            while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) {
                                brandingBos.write(data, 0, count);
                            }
                        } else {
                            if (entry.isDirectory()) {
                                L.d("Skipping branding dir " + entry.getName());
                                continue;
                            }
                            File destination = new File(tmpBrandingDir, entry.getName());
                            destination.getParentFile().mkdirs();
                            if ("__watermark__".equals(entry.getName())) {
                                watermarkFile = destination;
                            }
                            final OutputStream fos = new BufferedOutputStream(new FileOutputStream(destination),
                                    BUFFER_SIZE);
                            try {
                                while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) {
                                    fos.write(data, 0, count);
                                }
                            } finally {
                                fos.close();
                            }
                        }
                    }
                    while (dis.read(data) >= 0)
                        ;
                } finally {
                    zis.close();
                }
            } finally {
                dis.close();
            }
            String hexDigest = com.mobicage.rogerthat.util.TextUtils.toHex(digester.digest());
            if (!hexDigest.equals(item.brandingKey)) {
                encryptedBrandingFile.delete();
                SystemUtils.deleteDir(tmpBrandingDir);
                throw new BrandingFailureException("Branding cache was invalid!");
            }
            brandingBos.flush();
            byte[] brandingBytes = brandingBos.toByteArray();
            if (brandingBytes.length == 0) {
                encryptedBrandingFile.delete();
                SystemUtils.deleteDir(tmpBrandingDir);
                throw new BrandingFailureException("Invalid branding package!");
            }
            String brandingHtml = new String(brandingBytes, "UTF8");

            switch (item.type) {
            case BrandedItem.TYPE_MESSAGE:
                MessageTO message = (MessageTO) item.object;
                brandingHtml = brandingHtml.replace(NUNTIUZ_MESSAGE,
                        TextUtils.htmlEncode(message.message).replace("\r", "").replace("\n", "<br>"));

                brandingHtml = brandingHtml.replace(NUNTIUZ_TIMESTAMP,
                        TimeUtils.getDayTimeStr(mContext, message.timestamp * 1000));

                FriendsPlugin friendsPlugin = mMainService.getPlugin(FriendsPlugin.class);
                brandingHtml = brandingHtml.replace(NUNTIUZ_IDENTITY_NAME,
                        TextUtils.htmlEncode(friendsPlugin.getName(message.sender)));
                break;
            case BrandedItem.TYPE_FRIEND:
                FriendTO friend = (FriendTO) item.object;
                // In this case Friend is fully populated
                brandingHtml = brandingHtml.replace(NUNTIUZ_MESSAGE,
                        TextUtils.htmlEncode(friend.description).replace("\r", "").replace("\n", "<br>"));

                brandingHtml = brandingHtml.replace(NUNTIUZ_IDENTITY_NAME, TextUtils.htmlEncode(friend.name));

                break;
            case BrandedItem.TYPE_GENERIC:
                if (item.object instanceof FriendTO) {
                    brandingHtml = brandingHtml.replace(NUNTIUZ_IDENTITY_NAME,
                            TextUtils.htmlEncode(((FriendTO) item.object).name));
                }
                break;
            }

            Matcher matcher = RegexPatterns.BRANDING_BACKGROUND_COLOR.matcher(brandingHtml);
            if (matcher.find()) {
                String bg = matcher.group(1);
                if (bg.length() == 4) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("#");
                    sb.append(bg.charAt(1));
                    sb.append(bg.charAt(1));
                    sb.append(bg.charAt(2));
                    sb.append(bg.charAt(2));
                    sb.append(bg.charAt(3));
                    sb.append(bg.charAt(3));
                    bg = sb.toString();
                }
                backgroundColor = Color.parseColor(bg);
            }

            matcher = RegexPatterns.BRANDING_MENU_ITEM_COLOR.matcher(brandingHtml);
            if (matcher.find()) {
                String bg = matcher.group(1);
                if (bg.length() == 4) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("#");
                    sb.append(bg.charAt(1));
                    sb.append(bg.charAt(1));
                    sb.append(bg.charAt(2));
                    sb.append(bg.charAt(2));
                    sb.append(bg.charAt(3));
                    sb.append(bg.charAt(3));
                    bg = sb.toString();
                }
                menuItemColor = Color.parseColor(bg);
            }

            matcher = RegexPatterns.BRANDING_COLOR_SCHEME.matcher(brandingHtml);
            if (matcher.find()) {
                String schemeStr = matcher.group(1);
                scheme = "dark".equalsIgnoreCase(schemeStr) ? ColorScheme.dark : ColorScheme.light;
            }

            matcher = RegexPatterns.BRANDING_SHOW_HEADER.matcher(brandingHtml);
            if (matcher.find()) {
                String showHeaderStr = matcher.group(1);
                showHeader = "true".equalsIgnoreCase(showHeaderStr);
            }

            matcher = RegexPatterns.BRANDING_CONTENT_TYPE.matcher(brandingHtml);
            if (matcher.find()) {
                String contentTypeStr = matcher.group(1);
                L.i("Branding content-type: " + contentTypeStr);
                if (AttachmentViewerActivity.CONTENT_TYPE_PDF.equalsIgnoreCase(contentTypeStr)) {
                    File tmpBrandingFile = new File(tmpBrandingDir, "embed.pdf");
                    if (tmpBrandingFile.exists()) {
                        contentType = AttachmentViewerActivity.CONTENT_TYPE_PDF;
                    }
                }
            }

            Dimension dimension1 = null;
            Dimension dimension2 = null;
            matcher = RegexPatterns.BRANDING_DIMENSIONS.matcher(brandingHtml);
            if (matcher.find()) {
                String dimensionsStr = matcher.group(1);
                L.i("Branding dimensions: " + dimensionsStr);
                String[] dimensions = dimensionsStr.split(",");
                try {
                    dimension1 = new Dimension(Integer.parseInt(dimensions[0]),
                            Integer.parseInt(dimensions[1]));
                    dimension2 = new Dimension(Integer.parseInt(dimensions[2]),
                            Integer.parseInt(dimensions[3]));
                } catch (Exception e) {
                    L.bug("Invalid branding dimension: " + matcher.group(), e);
                }
            }

            matcher = RegexPatterns.BRANDING_WAKELOCK_ENABLED.matcher(brandingHtml);
            if (matcher.find()) {
                String wakelockEnabledStr = matcher.group(1);
                wakelockEnabled = "true".equalsIgnoreCase(wakelockEnabledStr);
            }

            final List<String> externalUrlPatterns = new ArrayList<String>();
            matcher = RegexPatterns.BRANDING_EXTERNAL_URLS.matcher(brandingHtml);
            while (matcher.find()) {
                externalUrlPatterns.add(matcher.group(1));
            }

            FileOutputStream fos = new FileOutputStream(brandingFile);

            try {
                fos.write(brandingHtml.getBytes("UTF8"));
            } finally {
                fos.close();
            }
            if (contentType != null
                    && AttachmentViewerActivity.CONTENT_TYPE_PDF.equalsIgnoreCase(contentType)) {
                brandingFile = new File(tmpBrandingDir, "embed.pdf");
            }
            return new BrandingResult(tmpBrandingDir, brandingFile, watermarkFile, backgroundColor,
                    menuItemColor, scheme, showHeader, dimension1, dimension2, contentType, wakelockEnabled,
                    externalUrlPatterns);
        } finally {
            brandingBos.close();
        }
    } catch (IOException e) {
        L.e(e);
        throw new BrandingFailureException("Error copying cached branded file to private space", e);
    } catch (NoSuchAlgorithmException e) {
        L.e(e);
        throw new BrandingFailureException("Cannot validate ", e);
    }
}

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

private void update_subtitle() {
    if (server == null || buffer == null) {
        title.setText(bufferToOpen);//from   ww  w  . j av a2  s  . c  o  m
        subtitle.setVisibility(View.GONE);
    } else {
        if (buffer.type.equals("console")) {
            if (server.name.length() > 0) {
                title.setText(server.name);
                if (progressBar.getVisibility() == View.GONE)
                    getSupportActionBar().setTitle(server.name);
            } else {
                title.setText(server.hostname);
                if (progressBar.getVisibility() == View.GONE)
                    getSupportActionBar().setTitle(server.hostname);
            }
        } else {
            title.setText(buffer.name);
            if (progressBar.getVisibility() == View.GONE)
                getSupportActionBar().setTitle(buffer.name);
        }

        if (buffer.archived > 0 && !buffer.type.equals("console")) {
            subtitle.setVisibility(View.VISIBLE);
            subtitle.setText("(archived)");
            if (buffer.type.equals("conversation")) {
                title.setContentDescription("Conversation with " + title.getText());
            } else if (buffer.type.equals("channel")) {
                title.setContentDescription("Channel " + buffer.normalizedName());
            }
        } else {
            if (buffer.type.equals("conversation")) {
                title.setContentDescription("Conversation with " + title.getText());
                if (buffer.away_msg != null && buffer.away_msg.length() > 0) {
                    subtitle.setVisibility(View.VISIBLE);
                    if (buffer.away_msg != null && buffer.away_msg.length() > 0) {
                        subtitle.setText("Away: " + ColorFormatter
                                .html_to_spanned(ColorFormatter.emojify(
                                        ColorFormatter.irc_to_html(TextUtils.htmlEncode(buffer.away_msg))))
                                .toString());
                    } else {
                        subtitle.setText("Away");
                    }
                } else {
                    UsersDataSource.User u = UsersDataSource.getInstance().findUserOnConnection(buffer.cid,
                            buffer.name);
                    if (u != null && u.away > 0) {
                        subtitle.setVisibility(View.VISIBLE);
                        if (u.away_msg != null && u.away_msg.length() > 0) {
                            subtitle.setText("Away: " + ColorFormatter
                                    .html_to_spanned(ColorFormatter.emojify(
                                            ColorFormatter.irc_to_html(TextUtils.htmlEncode(u.away_msg))))
                                    .toString());
                        } else {
                            subtitle.setText("Away");
                        }
                    } else {
                        subtitle.setVisibility(View.GONE);
                    }
                }
                key.setVisibility(View.GONE);
            } else if (buffer.type.equals("channel")) {
                title.setContentDescription(
                        "Channel " + buffer.normalizedName() + ". Double-tap to view or edit the topic.");
                ChannelsDataSource.Channel c = ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid);
                if (c != null && c.topic_text.length() > 0) {
                    subtitle.setVisibility(View.VISIBLE);
                    subtitle.setText(ColorFormatter
                            .html_to_spanned(ColorFormatter
                                    .emojify(ColorFormatter.irc_to_html(TextUtils.htmlEncode(c.topic_text))))
                            .toString());
                    subtitle.setContentDescription(".");
                } else {
                    subtitle.setVisibility(View.GONE);
                }
                if (c != null && c.key) {
                    key.setImageResource(R.drawable.lock);
                    key.setVisibility(View.VISIBLE);
                } else {
                    key.setVisibility(View.GONE);
                }
            } else if (buffer.type.equals("console")) {
                subtitle.setVisibility(View.VISIBLE);
                subtitle.setText(server.hostname + ":" + server.port);
                title.setContentDescription("Network " + server.name);
                subtitle.setContentDescription(".");
                if (server.ssl > 0)
                    key.setImageResource(R.drawable.world_shield);
                else
                    key.setImageResource(R.drawable.world);
                key.setVisibility(View.VISIBLE);
            }
        }
    }
    supportInvalidateOptionsMenu();
}

From source file:org.uguess.android.sysinfo.SiragonManager.java

static String escapeHtml(String str) {
    if (TextUtils.isEmpty(str) || containsNone(str, HTML_SEARCH_CHARS)) {
        return str;
    }/*from   w  w w .  j a v a  2s  .  c o  m*/

    str = TextUtils.htmlEncode(str);

    if (str.indexOf('\n') == -1) {
        return str;
    }

    StringBuffer sb = new StringBuffer();
    char c;
    for (int i = 0, size = str.length(); i < size; i++) {
        c = str.charAt(i);

        if (c == '\n') {
            sb.append("<br>"); //$NON-NLS-1$
        } else {
            sb.append(c);
        }
    }

    return sb.toString();
}

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

public static CharSequence strip(String msg) {
    if (Build.VERSION.SDK_INT >= 19 && EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCESS)
        return EmojiCompat.get()
                .process(html_to_spanned(irc_to_html(TextUtils.htmlEncode(emojify(msg)))).toString());
    else//from   www. j a  v a2s  . com
        return html_to_spanned(irc_to_html(TextUtils.htmlEncode(emojify(msg)))).toString();
}

From source file:com.irccloud.android.fragment.MessageViewFragment.java

public void onIRCEvent(int what, final Object obj) {
    IRCCloudJSONObject e;//from   ww w.  ja v a  2 s.co  m

    switch (what) {
    case NetworkConnection.EVENT_BACKLOG_FAILED:
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                headerView.setVisibility(View.GONE);
                backlogFailed.setVisibility(View.VISIBLE);
                loadBacklogButton.setVisibility(View.VISIBLE);
            }
        });
        break;
    case NetworkConnection.EVENT_BACKLOG_END:
    case NetworkConnection.EVENT_CONNECTIVITY:
    case NetworkConnection.EVENT_USERINFO:
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (refreshTask != null)
                    refreshTask.cancel(true);
                refreshTask = new RefreshTask();
                refreshTask.execute((Void) null);
            }
        });
        break;
    case NetworkConnection.EVENT_CONNECTIONLAG:
        try {
            IRCCloudJSONObject object = (IRCCloudJSONObject) obj;
            if (server != null && buffer != null && object.cid() == buffer.cid) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        update_status(server.status, server.fail_info);
                    }
                });
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        break;
    case NetworkConnection.EVENT_STATUSCHANGED:
        try {
            final IRCCloudJSONObject object = (IRCCloudJSONObject) obj;
            if (buffer != null && object.cid() == buffer.cid) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        update_status(object.getString("new_status"), object.getJsonObject("fail_info"));
                    }
                });
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        break;
    case NetworkConnection.EVENT_SETIGNORES:
        e = (IRCCloudJSONObject) obj;
        if (buffer != null && e.cid() == buffer.cid) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (refreshTask != null)
                        refreshTask.cancel(true);
                    refreshTask = new RefreshTask();
                    refreshTask.execute((Void) null);
                }
            });
        }
        break;
    case NetworkConnection.EVENT_HEARTBEATECHO:
        try {
            if (buffer != null && adapter != null && adapter.data.size() > 0) {
                if (buffer.last_seen_eid == adapter.data.get(adapter.data.size() - 1).eid
                        || !shouldTrackUnread()) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            hideView(unreadTopView);
                        }
                    });
                }
            }
        } catch (Exception ex) {
        }
        break;
    case NetworkConnection.EVENT_CHANNELTOPIC:
    case NetworkConnection.EVENT_JOIN:
    case NetworkConnection.EVENT_PART:
    case NetworkConnection.EVENT_NICKCHANGE:
    case NetworkConnection.EVENT_QUIT:
    case NetworkConnection.EVENT_KICK:
    case NetworkConnection.EVENT_CHANNELMODE:
    case NetworkConnection.EVENT_SELFDETAILS:
    case NetworkConnection.EVENT_USERMODE:
    case NetworkConnection.EVENT_USERCHANNELMODE:
        e = (IRCCloudJSONObject) obj;
        if (buffer != null && e.bid() == buffer.bid) {
            final EventsDataSource.Event event = EventsDataSource.getInstance().getEvent(e.eid(), e.bid());
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (adapter != null)
                        insertEvent(adapter, event, false, false);
                }
            });
        }
        break;
    case NetworkConnection.EVENT_BUFFERMSG:
        final EventsDataSource.Event event = (EventsDataSource.Event) obj;
        if (buffer != null && event.bid == buffer.bid) {
            if (event.from != null && event.from.equalsIgnoreCase(buffer.name) && event.reqid == -1) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (adapter != null)
                            adapter.clearPending();
                    }
                });
            } else if (event.reqid != -1) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (adapter != null && adapter.data != null) {
                            for (int i = 0; i < adapter.data.size(); i++) {
                                EventsDataSource.Event e = adapter.data.get(i);
                                if (e.reqid == event.reqid && e.pending) {
                                    if (i > 0) {
                                        EventsDataSource.Event p = adapter.data.get(i - 1);
                                        if (p.row_type == ROW_TIMESTAMP) {
                                            adapter.data.remove(p);
                                            i--;
                                        }
                                    }
                                    adapter.data.remove(e);
                                    i--;
                                }
                            }
                        }
                    }
                });
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    insertEvent(adapter, event, false, false);
                }
            });
            if (event.pending && event.self && adapter != null && getListView() != null) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        getListView().setSelection(adapter.getCount() - 1);
                    }
                });
            }
        }
        BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBuffer(event.bid);
        if (b != null && !b.scrolledUp && EventsDataSource.getInstance().getSizeOfBuffer(b.bid) > 200) {
            EventsDataSource.getInstance().pruneEvents(b.bid);
            if (buffer != null && b.bid == buffer.bid) {
                if (b.last_seen_eid < event.eid && unreadTopView.getVisibility() == View.GONE)
                    b.last_seen_eid = event.eid;

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (refreshTask != null)
                            refreshTask.cancel(true);
                        refreshTask = new RefreshTask();
                        refreshTask.execute((Void) null);
                    }
                });
            }
        }
        break;
    case NetworkConnection.EVENT_AWAY:
    case NetworkConnection.EVENT_SELFBACK:
        if (server != null) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (server.away != null && server.away.length() > 0) {
                        awayTxt.setText(ColorFormatter
                                .html_to_spanned(ColorFormatter
                                        .irc_to_html(TextUtils.htmlEncode("Away (" + server.away + ")")))
                                .toString());
                        awayView.setVisibility(View.VISIBLE);
                    } else {
                        awayView.setVisibility(View.GONE);
                    }
                }
            });
        }
        break;
    case NetworkConnection.EVENT_GLOBALMSG:
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                update_global_msg();
            }
        });
        break;
    default:
        break;
    }
}