Example usage for android.text Html fromHtml

List of usage examples for android.text Html fromHtml

Introduction

In this page you can find the example usage for android.text Html fromHtml.

Prototype

@Deprecated
public static Spanned fromHtml(String source) 

Source Link

Document

Returns displayable styled text from the provided HTML string with the legacy flags #FROM_HTML_MODE_LEGACY .

Usage

From source file:carnero.cgeo.original.libs.Base.java

public ArrayList<TrackableLog> parseTrackableLog(String page) {
    if (page == null || page.length() == 0) {
        return null;
    }//ww w.  j  av a  2  s.com

    final ArrayList<TrackableLog> trackables = new ArrayList<TrackableLog>();

    int startPos = -1;
    int endPos = -1;

    startPos = page.indexOf("<table id=\"tblTravelBugs\"");
    if (startPos == -1) {
        Log.e(Settings.tag, "cgeoBase.parseTrackableLog: ID \"tblTravelBugs\" not found on page");
        return null;
    }

    page = page.substring(startPos); // cut on <table

    endPos = page.indexOf("</table>");
    if (endPos == -1) {
        Log.e(Settings.tag, "cgeoBase.parseTrackableLog: end of ID \"tblTravelBugs\" not found on page");
        return null;
    }

    page = page.substring(0, endPos); // cut on </table>

    startPos = page.indexOf("<tbody>");
    if (startPos == -1) {
        Log.e(Settings.tag, "cgeoBase.parseTrackableLog: tbody not found on page");
        return null;
    }

    page = page.substring(startPos); // cut on <tbody>

    endPos = page.indexOf("</tbody>");
    if (endPos == -1) {
        Log.e(Settings.tag, "cgeoBase.parseTrackableLog: end of tbody not found on page");
        return null;
    }

    page = page.substring(0, endPos); // cut on </tbody>

    final Pattern trackablePattern = Pattern
            .compile("<tr id=\"ctl00_ContentBody_LogBookPanel1_uxTrackables_repTravelBugs_ctl[0-9]+_row\"[^>]*>"
                    + "[^<]*<td>[^<]*<a href=\"[^\"]+\">([A-Z0-9]+)</a>[^<]*</td>[^<]*<td>([^<]+)</td>[^<]*<td>"
                    + "[^<]*<select name=\"ctl00\\$ContentBody\\$LogBookPanel1\\$uxTrackables\\$repTravelBugs\\$ctl([0-9]+)\\$ddlAction\"[^>]*>"
                    + "([^<]*<option value=\"([0-9]+)(_[a-z]+)?\">[^<]+</option>)+"
                    + "[^<]*</select>[^<]*</td>[^<]*</tr>", Pattern.CASE_INSENSITIVE);
    final Matcher trackableMatcher = trackablePattern.matcher(page);
    while (trackableMatcher.find()) {
        if (trackableMatcher.groupCount() > 0) {
            final TrackableLog trackable = new TrackableLog();

            if (trackableMatcher.group(1) != null) {
                trackable.trackCode = trackableMatcher.group(1);
            } else {
                continue;
            }
            if (trackableMatcher.group(2) != null) {
                trackable.name = Html.fromHtml(trackableMatcher.group(2)).toString();
            } else {
                continue;
            }
            if (trackableMatcher.group(3) != null) {
                trackable.ctl = new Integer(trackableMatcher.group(3));
            } else {
                continue;
            }
            if (trackableMatcher.group(5) != null) {
                trackable.id = new Integer(trackableMatcher.group(5));
            } else {
                continue;
            }

            Log.i(Settings.tag, "Trackable in inventory (#" + trackable.ctl + "/" + trackable.id + "): "
                    + trackable.trackCode + " - " + trackable.name);

            trackables.add(trackable);
        }
    }

    return trackables;
}

From source file:carnero.cgeo.cgBase.java

public cgTrackable parseTrackable(String page) {
    if (page == null || page.length() == 0) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackable: No page given");
        return null;
    }/*from w w w. j  a  v a2 s .  c  o  m*/

    final Pattern patternTrackableId = Pattern.compile(
            "<a id=\"ctl00_ContentBody_LogLink\" title=\"[^\"]*\" href=\".*log\\.aspx\\?wid=([a-z0-9\\-]+)\"[^>]*>[^<]*</a>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternGeocode = Pattern.compile(
            "<span id=\"ctl00_ContentBody_BugDetails_BugTBNum\" String=\"[^\"]*\">Use[^<]*<strong>(TB[0-9a-z]+)[^<]*</strong> to reference this item.[^<]*</span>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternName = Pattern.compile(
            "<h2>([^<]*<img[^>]*>)?[^<]*<span id=\"ctl00_ContentBody_lbHeading\">([^<]+)</span>[^<]*</h2>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternOwner = Pattern.compile(
            "<dt>[^\\w]*Owner:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugOwner\" title=\"[^\"]*\" href=\"[^\"]*/profile/\\?guid=([a-z0-9\\-]+)\">([^<]+)<\\/a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternReleased = Pattern.compile(
            "<dt>[^\\w]*Released:[^<]*</dt>[^<]*<dd>[^<]*<span id=\"ctl00_ContentBody_BugDetails_BugReleaseDate\">([^<]+)<\\/span>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternOrigin = Pattern.compile(
            "<dt>[^\\w]*Origin:[^<]*</dt>[^<]*<dd>[^<]*<span id=\"ctl00_ContentBody_BugDetails_BugOrigin\">([^<]+)<\\/span>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedCache = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\" title=\"[^\"]*\" href=\"[^\"]*/seek/cache_details.aspx\\?guid=([a-z0-9\\-]+)\">In ([^<]+)</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedUser = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\" href=\"[^\"]*/profile/\\?guid=([a-z0-9\\-]+)\">In the hands of ([^<]+).</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedUnknown = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\">Unknown Location[^<]*</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedOwner = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\">In the hands of the owner[^<]*</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternGoal = Pattern.compile(
            "<h3>[^\\w]*Current GOAL[^<]*</h3>[^<]*<p[^>]*>(.*)</p>[^<]*<h3>[^\\w]*About This Item[^<]*</h3>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternDetailsImage = Pattern.compile(
            "<h3>[^\\w]*About This Item[^<]*</h3>([^<]*<p>([^<]*<img id=\"ctl00_ContentBody_BugDetails_BugImage\" class=\"[^\"]+\" src=\"([^\"]+)\"[^>]*>)?[^<]*</p>)?[^<]*<p[^>]*>(.*)</p>[^<]*<div id=\"ctl00_ContentBody_BugDetails_uxAbuseReport\">",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternLogs = Pattern.compile(
            "<table class=\"TrackableItemLogTable Table\">(.*)<\\/table>[^<]*<ul", Pattern.CASE_INSENSITIVE);
    final Pattern patternIcon = Pattern.compile(
            "<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"([^\"]+)\"[^>]*>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternType = Pattern.compile(
            "<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"[^\"]+\" alt=\"([^\"]+)\"[^>]*>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternDistance = Pattern.compile(
            "<h4[^>]*[^\\w]*Tracking History \\(([0-9\\.,]+(km|mi))[^\\)]*\\)", Pattern.CASE_INSENSITIVE);

    final cgTrackable trackable = new cgTrackable();

    // trackable geocode
    try {
        final Matcher matcherGeocode = patternGeocode.matcher(page);
        while (matcherGeocode.find()) {
            if (matcherGeocode.groupCount() > 0) {
                trackable.geocode = matcherGeocode.group(1).toUpperCase();
            }
        }
    } catch (Exception e) {
        // failed to parse trackable geocode
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable geocode");
    }

    // trackable id
    try {
        final Matcher matcherTrackableId = patternTrackableId.matcher(page);
        while (matcherTrackableId.find()) {
            if (matcherTrackableId.groupCount() > 0) {
                trackable.guid = matcherTrackableId.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable id
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable id");
    }

    // trackable icon
    try {
        final Matcher matcherTrackableIcon = patternIcon.matcher(page);
        while (matcherTrackableIcon.find()) {
            if (matcherTrackableIcon.groupCount() > 0) {
                trackable.iconUrl = matcherTrackableIcon.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable icon
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable icon");
    }

    // trackable name
    try {
        final Matcher matcherName = patternName.matcher(page);
        while (matcherName.find()) {
            if (matcherName.groupCount() > 1) {
                trackable.name = matcherName.group(2);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable name
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable name");
    }

    // trackable type
    if (trackable.name != null && trackable.name.length() > 0) {
        try {
            final Matcher matcherType = patternType.matcher(page);
            while (matcherType.find()) {
                if (matcherType.groupCount() > 0) {
                    trackable.type = matcherType.group(1);
                }
            }
        } catch (Exception e) {
            // failed to parse trackable type
            Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable type");
        }
    }

    // trackable owner name
    try {
        final Matcher matcherOwner = patternOwner.matcher(page);
        while (matcherOwner.find()) {
            if (matcherOwner.groupCount() > 0) {
                trackable.ownerGuid = matcherOwner.group(1);
                trackable.owner = matcherOwner.group(2);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable owner name
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable owner name");
    }

    // trackable origin
    try {
        final Matcher matcherOrigin = patternOrigin.matcher(page);
        while (matcherOrigin.find()) {
            if (matcherOrigin.groupCount() > 0) {
                trackable.origin = matcherOrigin.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable origin
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable origin");
    }

    // trackable spotted
    try {
        final Matcher matcherSpottedCache = patternSpottedCache.matcher(page);
        while (matcherSpottedCache.find()) {
            if (matcherSpottedCache.groupCount() > 0) {
                trackable.spottedGuid = matcherSpottedCache.group(1);
                trackable.spottedName = matcherSpottedCache.group(2);
                trackable.spottedType = cgTrackable.SPOTTED_CACHE;
            }
        }

        final Matcher matcherSpottedUser = patternSpottedUser.matcher(page);
        while (matcherSpottedUser.find()) {
            if (matcherSpottedUser.groupCount() > 0) {
                trackable.spottedGuid = matcherSpottedUser.group(1);
                trackable.spottedName = matcherSpottedUser.group(2);
                trackable.spottedType = cgTrackable.SPOTTED_USER;
            }
        }

        final Matcher matcherSpottedUnknown = patternSpottedUnknown.matcher(page);
        if (matcherSpottedUnknown.find()) {
            trackable.spottedType = cgTrackable.SPOTTED_UNKNOWN;
        }

        final Matcher matcherSpottedOwner = patternSpottedOwner.matcher(page);
        if (matcherSpottedOwner.find()) {
            trackable.spottedType = cgTrackable.SPOTTED_OWNER;
        }
    } catch (Exception e) {
        // failed to parse trackable last known place
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable last known place");
    }

    // released
    try {
        final Matcher matcherReleased = patternReleased.matcher(page);
        while (matcherReleased.find()) {
            if (matcherReleased.groupCount() > 0 && matcherReleased.group(1) != null) {
                try {
                    if (trackable.released == null) {
                        trackable.released = dateTbIn1.parse(matcherReleased.group(1));
                    }
                } catch (Exception e) {
                    //
                }

                try {
                    if (trackable.released == null) {
                        trackable.released = dateTbIn2.parse(matcherReleased.group(1));
                    }
                } catch (Exception e) {
                    //
                }
            }
        }
    } catch (Exception e) {
        // failed to parse trackable released date
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable released date");
    }

    // trackable distance
    try {
        final Matcher matcherDistance = patternDistance.matcher(page);
        while (matcherDistance.find()) {
            if (matcherDistance.groupCount() > 0) {
                trackable.distance = parseDistance(matcherDistance.group(1));
            }
        }
    } catch (Exception e) {
        // failed to parse trackable distance
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable distance");
    }

    // trackable goal
    try {
        final Matcher matcherGoal = patternGoal.matcher(page);
        while (matcherGoal.find()) {
            if (matcherGoal.groupCount() > 0) {
                trackable.goal = matcherGoal.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable goal
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable goal");
    }

    // trackable details & image
    try {
        final Matcher matcherDetailsImage = patternDetailsImage.matcher(page);
        while (matcherDetailsImage.find()) {
            if (matcherDetailsImage.groupCount() > 0) {
                final String image = matcherDetailsImage.group(3);
                final String details = matcherDetailsImage.group(4);

                if (image != null) {
                    trackable.image = image;
                }
                if (details != null) {
                    trackable.details = details;
                }
            }
        }
    } catch (Exception e) {
        // failed to parse trackable details & image
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable details & image");
    }

    // trackable logs
    try {
        final Matcher matcherLogs = patternLogs.matcher(page);
        while (matcherLogs.find()) {
            if (matcherLogs.groupCount() > 0) {
                final Pattern patternLog = Pattern.compile("[^>]*>"
                        + "[^<]*<td[^<]*<img src=[\"|'].*\\/icons\\/([^\\.]+)\\.[a-z]{2,5}[\"|'][^>]*>&nbsp;(\\d+).(\\d+).(\\d+)[^<]*</td>"
                        + "[^<]*<td>[^<]*<a href=[^>]+>([^<]+)<.a>([^<]*|[^<]*<a href=[\"|'].*guid=([^\"]*)\">([^<]*)</a>[^<]*)</td>"
                        + "[^<]*<td>[^<]*</td>" + "[^<]*<td[^<]*<a href=[^>]+>[^<]+</a>[^<]*</td>[^<]*</tr>"
                        + "[^<]*<tr[^>]*>[^<]*<td[^>]*>(.*?)</td>[^<]*</tr>.*" + "");
                // 1 filename == type
                // 2 month
                // 3 date
                // 4 year
                // 5 user
                // 6 action dependent
                // 7 cache guid
                // 8 cache name
                // 9 text
                final String[] logs = matcherLogs.group(1).split("<tr class=\"Data BorderTop");
                final int logsCnt = logs.length;

                for (int k = 1; k < logsCnt; k++) {
                    final Matcher matcherLog = patternLog.matcher(logs[k]);
                    if (matcherLog.find()) {
                        final cgLog logDone = new cgLog();

                        String logTmp = matcherLog.group(9);
                        logTmp = Pattern.compile("<p>").matcher(logTmp).replaceAll("\n");
                        logTmp = Pattern.compile("<br[^>]*>").matcher(logTmp).replaceAll("\n");
                        logTmp = Pattern.compile("<\\/p>").matcher(logTmp).replaceAll("");
                        logTmp = Pattern.compile("\r+").matcher(logTmp).replaceAll("\n");

                        int day = -1;
                        try {
                            day = Integer.parseInt(matcherLog.group(3));
                        } catch (Exception e) {
                            Log.w(cgSettings.tag, "Failed to parse logs date (day): " + e.toString());
                        }

                        int month = -1;
                        try {
                            month = Integer.parseInt(matcherLog.group(2));
                            month -= 1;
                        } catch (Exception e) {
                            Log.w(cgSettings.tag, "Failed to parse logs date (month): " + e.toString());
                        }

                        int year = -1;
                        try {
                            year = Integer.parseInt(matcherLog.group(4));
                        } catch (Exception e) {
                            Log.w(cgSettings.tag, "Failed to parse logs date (year): " + e.toString());
                        }

                        long logDate;
                        if (year > 0 && month >= 0 && day > 0) {
                            Calendar date = Calendar.getInstance();
                            date.set(year, month, day, 12, 0, 0);
                            logDate = date.getTimeInMillis();
                            logDate = (long) (Math.ceil(logDate / 1000)) * 1000;
                        } else {
                            logDate = 0;
                        }

                        if (logTypes.containsKey(matcherLog.group(1).toLowerCase()) == true) {
                            logDone.type = logTypes.get(matcherLog.group(1).toLowerCase());
                        } else {
                            logDone.type = logTypes.get("icon_note");
                        }

                        logDone.author = Html.fromHtml(matcherLog.group(5)).toString();
                        logDone.date = logDate;
                        logDone.log = logTmp;
                        if (matcherLog.group(7) != null && matcherLog.group(8) != null) {
                            logDone.cacheGuid = matcherLog.group(7);
                            logDone.cacheName = matcherLog.group(8);
                        }

                        trackable.logs.add(logDone);
                    }
                }
            }
        }
    } catch (Exception e) {
        // failed to parse logs
        Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache logs");
    }

    app.saveTrackable(trackable);

    return trackable;
}

From source file:carnero.cgeo.cgBase.java

public ArrayList<cgTrackableLog> parseTrackableLog(String page) {
    if (page == null || page.length() == 0) {
        return null;
    }/* w ww  . jav a 2  s .  c om*/

    final ArrayList<cgTrackableLog> trackables = new ArrayList<cgTrackableLog>();

    int startPos = -1;
    int endPos = -1;

    startPos = page.indexOf("<table id=\"tblTravelBugs\"");
    if (startPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: ID \"tblTravelBugs\" not found on page");
        return null;
    }

    page = page.substring(startPos); // cut on <table

    endPos = page.indexOf("</table>");
    if (endPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: end of ID \"tblTravelBugs\" not found on page");
        return null;
    }

    page = page.substring(0, endPos); // cut on </table>

    startPos = page.indexOf("<tbody>");
    if (startPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: tbody not found on page");
        return null;
    }

    page = page.substring(startPos); // cut on <tbody>

    endPos = page.indexOf("</tbody>");
    if (endPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: end of tbody not found on page");
        return null;
    }

    page = page.substring(0, endPos); // cut on </tbody>

    final Pattern trackablePattern = Pattern
            .compile("<tr id=\"ctl00_ContentBody_LogBookPanel1_uxTrackables_repTravelBugs_ctl[0-9]+_row\"[^>]*>"
                    + "[^<]*<td>[^<]*<a href=\"[^\"]+\">([A-Z0-9]+)</a>[^<]*</td>[^<]*<td>([^<]+)</td>[^<]*<td>"
                    + "[^<]*<select name=\"ctl00\\$ContentBody\\$LogBookPanel1\\$uxTrackables\\$repTravelBugs\\$ctl([0-9]+)\\$ddlAction\"[^>]*>"
                    + "([^<]*<option value=\"([0-9]+)(_[a-z]+)?\">[^<]+</option>)+"
                    + "[^<]*</select>[^<]*</td>[^<]*</tr>", Pattern.CASE_INSENSITIVE);
    final Matcher trackableMatcher = trackablePattern.matcher(page);
    while (trackableMatcher.find()) {
        if (trackableMatcher.groupCount() > 0) {
            final cgTrackableLog trackable = new cgTrackableLog();

            if (trackableMatcher.group(1) != null) {
                trackable.trackCode = trackableMatcher.group(1);
            } else {
                continue;
            }
            if (trackableMatcher.group(2) != null) {
                trackable.name = Html.fromHtml(trackableMatcher.group(2)).toString();
            } else {
                continue;
            }
            if (trackableMatcher.group(3) != null) {
                trackable.ctl = new Integer(trackableMatcher.group(3));
            } else {
                continue;
            }
            if (trackableMatcher.group(5) != null) {
                trackable.id = new Integer(trackableMatcher.group(5));
            } else {
                continue;
            }

            Log.i(cgSettings.tag, "Trackable in inventory (#" + trackable.ctl + "/" + trackable.id + "): "
                    + trackable.trackCode + " - " + trackable.name);

            trackables.add(trackable);
        }
    }

    return trackables;
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void displaytourInfo() {
    String message = "";
    int i = 0;/*from   w w w  .ja  va  2s . c  o m*/
    int tagCount = 0;
    boolean singleDisplay = false; //indicates that only 1 item is to be displayed in the tour list
    List<Boolean> tourtagsIncluded = new ArrayList<Boolean>();
    List<Boolean> tourtagsScanned = new ArrayList<Boolean>();
    List<Integer> tourOrder = new ArrayList<Integer>();
    List<String> messageList = new ArrayList<String>();

    //check if this is a single display (second last character of tour name is a space)
    singleDisplay = isSingleRandomTour();
    tourDB.open();

    Cursor c = tourDB.getRecordByTour(GTConstants.tourName);

    if (c != null && c.moveToFirst()) {
        tourtagsScanned = refreshtourtagList(c.getCount(), false, true, false, false);
        tourtagsIncluded = refreshtourtagList(c.getCount(), false, false, true, false);
        tourOrder = gettourOrder(c.getCount());

        //initialize the message array which wil be used to display the messages in the random order
        while (messageList.size() < c.getCount())
            messageList.add("");

        for (i = 0; i < c.getCount(); i++) {
            if (tourtagsScanned.get(i) && tourtagsIncluded.get(i) && !singleDisplay)
                messageList.add(tourOrder.get(i),
                        "<br><font color='#00FF00'>" + c.getString(2) + "</font><br/>");
            else if (!tourtagsScanned.get(i) && !Utility.istourOntime(tourEnd)
                    && Utility.getcurrentState().equals(GTConstants.onShift) && tourtagsIncluded.get(i)
                    && !singleDisplay)
                messageList.add(tourOrder.get(i),
                        "<br><font color='#FF0000'>" + c.getString(2) + "</font><br/>");
            else if (!tourtagsScanned.get(i) && tourtagsIncluded.get(i) && !singleDisplay)
                messageList.add(tourOrder.get(i),
                        "<br><font color='#FFFFFF'>" + c.getString(2) + "</font><br/>");
            else if (singleDisplay && i == touritemNumber)
                messageList.add(tourOrder.get(i),
                        "<br><font color='#FFFFFF'>" + c.getString(2) + "</font><br/>");

            //get the number of tags included
            if (tourtagsIncluded.get(i))
                tagCount++;
            c.moveToNext();
        }
    }

    tourDB.close();

    //create the message string
    for (i = 0; i < messageList.size(); i++)
        if (messageList.get(i).length() > 1)
            message = message + messageList.get(i);

    LayoutInflater inflater = LayoutInflater.from(HomeScreen.this);
    View view = inflater.inflate(R.layout.scroll_dialog, null);

    TextView textview = (TextView) view.findViewById(R.id.dialogtext);
    textview.setText(Html.fromHtml(message));
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(HomeScreen.this);

    //create custom title
    TextView title = new TextView(HomeScreen.this);

    //if this is a single display tour then do not indicate how many tags are in the tour
    if (isSingleRandomTour()) //this is a single display tour
        title.setText(GTConstants.tourName + CRLF + tourTime + CRLF);
    else
        title.setText(GTConstants.tourName + CRLF + tourTime + CRLF + String.valueOf(tagCount) + " Tags");
    title.setPadding(10, 10, 10, 10);
    title.setGravity(Gravity.CENTER);
    title.setTextColor(Color.parseColor("#79ABFF"));
    title.setTextSize(20);
    alertDialog.setCustomTitle(title);

    //alertDialog.setTitle(tourName + CRLF + String.valueOf(i-1) + " Tags"); 
    alertDialog.setView(view);
    alertDialog.setPositiveButton("OK", null);
    AlertDialog alert = alertDialog.create();
    alert.show();
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Parses HTML into a {@link Spanned} Object
 * @param html the HTML to parse/*from ww w  .  j av a  2 s  .com*/
 * @return the Spanned Object created from the given HTML
 */
public static Spanned parseHTML(String html) {
    return Html.fromHtml(html);
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Include the html string the selected views. If a view has a setText method, it is used. Otherwise,
 * a new TextView is created. This html can also handle image tags for both urls and local files.
 * Local files should be the name (for example, for R.id.ic_launcher, just use ic_launcher).
 * @param html the HTML String to include
 *///  w  ww .j  a va 2s. c  o  m
public $ html(String html) {
    for (int i = 0; i < this.views.size(); i++) {
        View view = this.views.get(i);
        try {
            Method m = view.getClass().getMethod("setText", new Class<?>[] { CharSequence.class });
            m.invoke(view, (CharSequence) Html.fromHtml(html));
        } catch (Throwable t) {
            if (view instanceof ViewGroup) {
                try {
                    //no setText method. Try a TextView
                    TextView tv = new TextView(this.context);
                    tv.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
                    tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                            ViewGroup.LayoutParams.FILL_PARENT));
                    ((ViewGroup) view).addView(tv);
                    tv.setText(Html.fromHtml(html, new AsyncImageGetter(tv), null));
                } catch (Throwable t2) {
                    //unable to set content
                    Log.w("droidQuery", "unable to set HTML content");
                }
            } else {
                //unable to set content
                Log.w("droidQuery", "unable to set textual content");
            }
        }
    }

    return this;
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void showMensajeContact(int position, final Context context, final Message message, View rowView,
        TextView icnMessageArrow) {//from ww w  .j a va 2  s  .c  om

    final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages);
    TextView messageTime = (TextView) rowView.findViewById(R.id.message_time);
    final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo);
    final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider);
    final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy);
    final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back);
    TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status);
    final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout);
    final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout);
    TextView messageDate = (TextView) rowView.findViewById(R.id.message_date);
    TextView contactPhoto = (TextView) rowView.findViewById(R.id.contact_photo);
    TextView contactName = (TextView) rowView.findViewById(R.id.contact_name);
    final TextView contactPhone = (TextView) rowView.findViewById(R.id.contact_phone);

    TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL);
    TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL);
    TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL);
    TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL);
    TFCache.apply(context, contactPhoto, TFCache.TF_SPEAKALL);
    TFCache.apply(context, prevMessages, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, contactName, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, contactPhone, TFCache.TF_WHITNEY_MEDIUM);

    try {
        JSONObject contactData = new JSONObject(message.mensaje);
        contactName.setText(contactData.getString("nombre"));
        contactPhone.setText(Html.fromHtml("<u>" + contactData.getString("telefono") + "</u>"));
        if (contactPhone.length() > 0) {
            contactPhone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dontClose = true;
                    ((MainActivity) activity).dontClose = true;
                    hideKeyBoard();
                    Intent intent = new Intent(Intent.ACTION_CALL,
                            Uri.parse("tel:" + contactPhone.getText().toString()));
                    context.startActivity(intent);
                }
            });
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    if (position == 0) {
        if (mensajesTotal > mensajesOffset) {
            prevMessages.setVisibility(View.VISIBLE);
            prevMessages.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    prevMessages.setVisibility(View.GONE);
                    if (mensajesTotal - mensajesOffset >= 10) {
                        mensajesLimit = 10;
                        mensajesOffset += mensajesLimit;
                        showPreviousMessages(mensajesOffset);
                    } else {
                        mensajesLimit = mensajesTotal - mensajesOffset;
                        mensajesOffset += mensajesLimit;
                        showPreviousMessages(mensajesOffset);
                    }
                }
            });
        }
    }

    DateFormat dateDay = new SimpleDateFormat("d");
    DateFormat dateDayText = new SimpleDateFormat("EEEE");
    DateFormat dateMonth = new SimpleDateFormat("MMMM");
    DateFormat dateYear = new SimpleDateFormat("yyyy");
    DateFormat timeFormat = new SimpleDateFormat("h:mm a");

    Calendar fechamsj = Calendar.getInstance();
    fechamsj.setTimeInMillis(message.emitedAt);
    String time = timeFormat.format(fechamsj.getTime());
    String dayMessage = dateDay.format(fechamsj.getTime());
    String monthMessage = dateMonth.format(fechamsj.getTime());
    String yearMessage = dateYear.format(fechamsj.getTime());
    String dayMessageText = dateDayText.format(fechamsj.getTime());
    char[] caracteres = dayMessageText.toCharArray();
    caracteres[0] = Character.toUpperCase(caracteres[0]);
    dayMessageText = new String(caracteres);

    Calendar fechaActual = Calendar.getInstance();
    String dayActual = dateDay.format(fechaActual.getTime());
    String monthActual = dateMonth.format(fechaActual.getTime());
    String yearActual = dateYear.format(fechaActual.getTime());

    String fechaMostrar = "";
    if (dayMessage.equals(dayActual) && monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) {
        fechaMostrar = getString(R.string.messages_today);
    } else if (monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) {
        int days = Integer.parseInt(dayActual) - Integer.parseInt(dayMessage);
        if (days < 7) {
            switch (days) {
            case 1:
                fechaMostrar = getString(R.string.messages_yesterday);
                break;
            default:
                fechaMostrar = dayMessageText;
                break;
            }
        } else {
            fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase();
        }
    } else {
        fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase();
    }

    messageDate.setText(fechaMostrar);
    if (position != -1) {
        if (itemAnterior != null) {
            if (!fechaMostrar.equals(fechaAnterior)) {
                itemAnterior.findViewById(R.id.message_date).setVisibility(View.VISIBLE);
            } else {
                itemAnterior.findViewById(R.id.message_date).setVisibility(View.GONE);
            }
        }
        itemAnterior = rowView;
        fechaAnterior = fechaMostrar;
    } else {
        View v = messagesList.getChildAt(messagesList.getChildCount() - 1);
        if (v != null) {
            TextView tv = (TextView) v.findViewById(R.id.message_date);
            if (tv.getText().toString().equals(fechaMostrar)) {
                messageDate.setVisibility(View.GONE);
            } else {
                messageDate.setVisibility(View.VISIBLE);
            }
        }
    }
    messageTime.setText(time);

    if (message.emisor.equals(u.id)) {
        if (message.status != -1) {
            rowView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    if (messageSelected != null) {
                        View vista = messagesList.findViewWithTag(messageSelected);
                        vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                        messageSelected = message.mensajeId;
                        ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                            @Override
                            public void doBack() {
                                View vista = messagesList.findViewWithTag(messageSelected);
                                vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                                ((MainActivity) activity).setOnBackPressedListener(null);
                                messageSelected = null;
                            }
                        });
                    } else {
                        messageSelected = message.mensajeId;
                        ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                            @Override
                            public void doBack() {
                                if (messageSelected != null) {
                                    View vista = messagesList.findViewWithTag(messageSelected);
                                    vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                                    ((MainActivity) activity).setOnBackPressedListener(null);
                                    messageSelected = null;
                                }
                            }
                        });
                    }

                    Vibrator x = (Vibrator) activity.getApplicationContext()
                            .getSystemService(Context.VIBRATOR_SERVICE);
                    x.vibrate(30);
                    Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId)
                            .executeSingle();
                    if (mensaje.status != 4) {
                        icnMesajeTempo.setVisibility(View.VISIBLE);
                        icnMensajeTempoDivider.setVisibility(View.VISIBLE);
                        icnMesajeCopy.setVisibility(View.VISIBLE);
                        icnMesajeBack.setVisibility(View.VISIBLE);
                        messageMenu.setVisibility(View.VISIBLE);
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(ObjectAnimator.ofFloat(icnMesajeTempo, "alpha", 0, 1),
                                ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1),
                                ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1),
                                ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1),
                                ObjectAnimator.ofFloat(icnMesajeTempo, "translationX", 150, 0),
                                ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0),
                                ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0));
                        set.setDuration(200).start();
                    } else {
                        icnMesajeCopy.setVisibility(View.VISIBLE);
                        icnMesajeBack.setVisibility(View.VISIBLE);
                        messageMenu.setVisibility(View.VISIBLE);
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1),
                                ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1),
                                ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1),
                                ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0),
                                ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0));
                        set.setDuration(200).start();
                    }

                    return false;
                }
            });
        }
        if (message.status == 1) {
            messageStatus.setTextSize(16);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground();
            drawable.setCornerRadius(radius);
            drawable.setColor(BalloonFragment.getBackgroundColor(activity));
            icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity));
            messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray));
            messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString());
            ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0);
            colorAnim.setRepeatCount(ValueAnimator.INFINITE);
            colorAnim.setRepeatMode(ValueAnimator.REVERSE);
            colorAnim.setDuration(1000).start();
            animaciones.put(message.mensajeId, colorAnim);
            JSONObject data = new JSONObject();
            try {
                data.put("message_id", message.mensajeId);
                data.put("source", message.emisor);
                data.put("source_email", message.emisorEmail);
                data.put("target_email", message.receptorEmail);
                data.put("target", message.receptor);
                data.put("message", message.mensaje);
                data.put("delay", message.delay);
                data.put("translation_required", message.translation);
                data.put("target_lang", message.receptorLang);
                data.put("type", message.tipo);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (SpeakSocket.mSocket != null)
                if (SpeakSocket.mSocket.connected()) {
                    message.status = 1;
                    SpeakSocket.mSocket.emit("message", data);
                } else {
                    message.status = -1;
                }
        }
        if (message.status == -1) {
            messageStatus.setTextSize(11);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground();
            drawable.setCornerRadius(radius);
            drawable.setColor(BalloonFragment.getBackgroundColor(activity));
            icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity));
            messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString());
        }
        if (message.status == 3) {
            messageStatus.setTextSize(11);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground();
            drawable.setCornerRadius(radius);
            drawable.setColor(BalloonFragment.getBackgroundColor(activity));
            icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity));
            messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString());
        }
        if (message.status == 2) {
            messageStatus.setTextSize(16);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground();
            drawable.setCornerRadius(radius);
            drawable.setColor(BalloonFragment.getBackgroundColor(activity));
            icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity));
            messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString());
        }
        if (message.status == 4) {
            messageStatus.setTextSize(11);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground();
            drawable.setCornerRadius(radius);
            drawable.setColor(BalloonFragment.getBackgroundColor(activity));
            icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity));
            messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString());
            icnMensajeTempoDivider.setVisibility(View.GONE);
            icnMesajeTempo.setVisibility(View.GONE);
        } else {
            icnMensajeTempoDivider.setVisibility(View.INVISIBLE);
            icnMesajeTempo.setVisibility(View.INVISIBLE);
        }

        icnMesajeTempo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JSONObject notifyMessage = new JSONObject();
                try {
                    Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId)
                            .executeSingle();

                    if (mensaje.status != 4) {
                        notifyMessage.put("type", mensaje.tipo);
                        notifyMessage.put("message_id", mensaje.mensajeId);
                        notifyMessage.put("source", mensaje.receptor);
                        notifyMessage.put("target", mensaje.emisor);
                        notifyMessage.put("status", 5);
                        SpeakSocket.mSocket.emit("message-status", notifyMessage);
                    }
                    new Delete().from(Message.class).where("mensajeId = ?", mensaje.mensajeId).execute();
                    Message message = null;
                    if (mensaje.emisor.equals(u.id)) {
                        message = new Select().from(Message.class)
                                .where("emisor = ? or receptor = ?", mensaje.receptor, mensaje.receptor)
                                .orderBy("emitedAt DESC").executeSingle();
                    } else {
                        message = new Select().from(Message.class)
                                .where("emisor = ? or receptor = ?", mensaje.emisor, mensaje.emisor)
                                .orderBy("emitedAt DESC").executeSingle();
                    }
                    if (message != null) {
                        Chats chat = null;
                        if (mensaje.emisor.equals(u.id)) {
                            chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.receptor)
                                    .executeSingle();
                        } else {
                            chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor)
                                    .executeSingle();
                        }
                        if (chat != null) {
                            chat.mensajeId = message.mensajeId;
                            chat.lastStatus = message.status;
                            chat.emitedAt = message.emitedAt;
                            chat.lang = message.emisorLang;
                            chat.notRead = 0;
                            if (chat.idContacto.equals(message.emisor))
                                chat.lastMessage = message.mensajeTrad;
                            else
                                chat.lastMessage = message.mensaje;
                            chat.save();
                        }
                    } else {
                        if (mensaje.emisor.equals(u.id)) {
                            new Delete().from(Chats.class).where("idContacto = ?", mensaje.receptor).execute();
                        } else {
                            new Delete().from(Chats.class).where("idContacto = ?", mensaje.emisor).execute();
                        }
                    }

                    View delete = messagesList.findViewWithTag(mensaje.mensajeId);
                    if (delete != null)
                        messagesList.removeView(delete);
                    messageSelected = null;
                    ((MainActivity) activity).setOnBackPressedListener(null);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

    } else {
        mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
        GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground();
        drawable.setCornerRadius(radius);
        drawable.setColor(BalloonFragment.getFriendBalloon(activity));
        if (message.tipo == Integer.parseInt(getString(R.string.MSG_TYPE_BROADCAST_TEXT))) {
            messageStatus.setTextSize(15);
            messageStatus.setText(Finder.STRING.ICN_BROADCAST_FILL.toString());
        }
        rowView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (messageSelected != null) {
                    longclick = true;
                    View vista = messagesList.findViewWithTag(messageSelected);
                    vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                    messageSelected = message.mensajeId;
                    ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                        @Override
                        public void doBack() {
                            View vista = messagesList.findViewWithTag(messageSelected);
                            vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                            ((MainActivity) activity).setOnBackPressedListener(null);
                            messageSelected = null;
                        }
                    });
                } else {
                    messageSelected = message.mensajeId;
                    ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                        @Override
                        public void doBack() {
                            View vista = messagesList.findViewWithTag(messageSelected);
                            vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                            ((MainActivity) activity).setOnBackPressedListener(null);
                            messageSelected = null;
                        }
                    });
                }

                Vibrator x = (Vibrator) activity.getApplicationContext()
                        .getSystemService(Context.VIBRATOR_SERVICE);
                x.vibrate(20);
                icnMesajeTempo.setVisibility(View.GONE);
                icnMensajeTempoDivider.setVisibility(View.GONE);
                icnMesajeCopy.setVisibility(View.VISIBLE);
                icnMesajeBack.setVisibility(View.VISIBLE);
                messageMenu.setVisibility(View.VISIBLE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1),
                        ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1),
                        ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1),
                        ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0),
                        ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0));
                set.setDuration(200).start();
                longclick = true;
                return false;
            }
        });
        icnMesajeTempo.setOnClickListener(new View.OnClickListener() {
            boolean translation = true;

            @Override
            public void onClick(View v) {
                translation = !translation;
                if (translation) {
                    icnMesajeTempo.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    icnMesajeTempo.setTextColor(getResources().getColor(R.color.speak_all_white));
                }
            }
        });
    }

    /*icnMesajeCopy.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          ClipData clip = ClipData.newPlainText("text", messageContent.getText().toString());
          ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
          clipboard.setPrimaryClip(clip);
          Toast.makeText(activity, "Copiado", Toast.LENGTH_SHORT).show();
      }
    });*/

    icnMesajeBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (message.emisor.equals(u.id)) {
                getFragmentManager().beginTransaction()
                        .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje))
                        .addToBackStack(null).commit();
                ((MainActivity) activity).setOnBackPressedListener(null);
            } else {
                getFragmentManager().beginTransaction()
                        .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad))
                        .addToBackStack(null).commit();
                ((MainActivity) activity).setOnBackPressedListener(null);
            }
        }
    });

    rowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (messageSelected != null) {
                View vista = messagesList.findViewWithTag(messageSelected);
                if (!messageSelected.equals(message.mensajeId)) {
                    longclick = true;
                    vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messageSelected = null;
                }
            }
            Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId)
                    .executeSingle();
            if (mensaje.status == -1) {
                String message = mensaje.mensaje;
                JSONObject data = new JSONObject();
                try {
                    data.put("message_id", mensaje.mensajeId);
                    data.put("source", mensaje.emisor);
                    data.put("source_email", mensaje.emisorEmail);
                    data.put("target_email", mensaje.receptorEmail);
                    data.put("target", mensaje.receptor);
                    data.put("message", mensaje.mensaje);
                    data.put("delay", mensaje.delay);
                    data.put("type", mensaje.tipo);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                if (SpeakSocket.mSocket != null)
                    if (SpeakSocket.mSocket.connected()) {
                        mensaje.status = 1;
                        SpeakSocket.mSocket.emit("message", data);
                    } else {
                        mensaje.status = -1;
                    }
                mensaje.save();
                changeStatus(mensaje.mensajeId, mensaje.status);
            }
            if (!mensaje.emisor.equals(u.id)) {
                if (!longclick) {
                    showDialogAddContact(mensaje.mensaje);
                }
                longclick = false;
            }
        }
    });
}