Example usage for java.lang CharSequence subSequence

List of usage examples for java.lang CharSequence subSequence

Introduction

In this page you can find the example usage for java.lang CharSequence subSequence.

Prototype

CharSequence subSequence(int start, int end);

Source Link

Document

Returns a CharSequence that is a subsequence of this sequence.

Usage

From source file:org.archive.modules.extractor.ExtractorHTML.java

protected void processGeneralTag(CrawlURI curi, CharSequence element, CharSequence cs) {

    Matcher attr = TextUtils.getMatcher(eachAttributePattern, cs);

    // Just in case it's an OBJECT or APPLET tag
    String codebase = null;/*from   www. java  2s .com*/
    ArrayList<String> resources = null;

    // Just in case it's a FORM
    CharSequence action = null;
    CharSequence actionContext = null;
    CharSequence method = null;

    // Just in case it's a VALUE whose interpretation depends on accompanying NAME
    CharSequence valueVal = null;
    CharSequence valueContext = null;
    CharSequence nameVal = null;

    final boolean framesAsEmbeds = getTreatFramesAsEmbedLinks();

    final boolean ignoreFormActions = getIgnoreFormActionUrls();

    final boolean extractValueAttributes = getExtractValueAttributes();

    final String elementStr = element.toString();

    while (attr.find()) {
        int valueGroup = (attr.start(14) > -1) ? 14 : (attr.start(15) > -1) ? 15 : 16;
        int start = attr.start(valueGroup);
        int end = attr.end(valueGroup);
        assert start >= 0 : "Start is: " + start + ", " + curi;
        assert end >= 0 : "End is :" + end + ", " + curi;
        CharSequence value = cs.subSequence(start, end);
        CharSequence attrName = cs.subSequence(attr.start(1), attr.end(1));
        value = TextUtils.unescapeHtml(value);
        if (attr.start(2) > -1) {
            CharSequence context;
            // HREF
            if ("a".equals(element) && TextUtils.matches("(?i).*data-remote\\s*=\\s*([\"'])true.*\\1", cs)) {
                context = "a[data-remote='true']/@href";
            } else {
                context = elementContext(element, attr.group(2));
            }

            if ("a[data-remote='true']/@href".equals(context) || elementStr.equalsIgnoreCase(LINK)) {
                // <LINK> elements treated as embeds (css, ico, etc)
                processEmbed(curi, value, context);
            } else {
                // other HREFs treated as links
                processLink(curi, value, context);
            }
            if (elementStr.equalsIgnoreCase(BASE)) {
                try {
                    UURI base = UURIFactory.getInstance(value.toString());
                    curi.setBaseURI(base);
                } catch (URIException e) {
                    logUriError(e, curi.getUURI(), value);
                }
            }
        } else if (attr.start(3) > -1) {
            // ACTION
            if (!ignoreFormActions) {
                action = value;
                actionContext = elementContext(element, attr.group(3));
                // handling finished only at end (after METHOD also collected)
            }
        } else if (attr.start(4) > -1) {
            // ON____
            processScriptCode(curi, value); // TODO: context?
        } else if (attr.start(5) > -1) {
            // SRC etc.
            CharSequence context = elementContext(element, attr.group(5));

            // true, if we expect another HTML page instead of an image etc.
            final Hop hop;

            if (!framesAsEmbeds
                    && (elementStr.equalsIgnoreCase(FRAME) || elementStr.equalsIgnoreCase(IFRAME))) {
                hop = Hop.NAVLINK;
            } else {
                hop = Hop.EMBED;
            }
            processEmbed(curi, value, context, hop);
        } else if (attr.start(6) > -1) {
            // CODEBASE
            codebase = (value instanceof String) ? (String) value : value.toString();
            CharSequence context = elementContext(element, attr.group(6));
            processLink(curi, codebase, context);
        } else if (attr.start(7) > -1) {
            // CLASSID, DATA
            if (resources == null) {
                resources = new ArrayList<String>();
            }
            resources.add(value.toString());
        } else if (attr.start(8) > -1) {
            // ARCHIVE
            if (resources == null) {
                resources = new ArrayList<String>();
            }
            String[] multi = TextUtils.split(WHITESPACE, value);
            for (int i = 0; i < multi.length; i++) {
                resources.add(multi[i]);
            }
        } else if (attr.start(9) > -1) {
            // CODE
            if (resources == null) {
                resources = new ArrayList<String>();
            }
            // If element is applet and code value does not end with
            // '.class' then append '.class' to the code value.
            if (elementStr.equalsIgnoreCase(APPLET) && !value.toString().toLowerCase().endsWith(CLASSEXT)) {
                resources.add(value.toString() + CLASSEXT);
            } else {
                resources.add(value.toString());
            }
        } else if (attr.start(10) > -1) {
            // VALUE, with possibility of URI
            // store value, context for handling at end
            valueVal = value;
            valueContext = elementContext(element, attr.group(10));
        } else if (attr.start(11) > -1) {
            // STYLE inline attribute
            // then, parse for URIs
            numberOfLinksExtracted.addAndGet(ExtractorCSS.processStyleCode(this, curi, value));
        } else if (attr.start(12) > -1) {
            // METHOD
            method = value;
            // form processing finished at end (after ACTION also collected)
        } else if (attr.start(13) > -1) {
            if ("NAME".equalsIgnoreCase(attrName.toString())) {
                // remember 'name' for end-analysis
                nameVal = value;
            }
            if ("FLASHVARS".equalsIgnoreCase(attrName.toString())) {
                // consider FLASHVARS attribute immediately
                valueContext = elementContext(element, attr.group(13));
                considerQueryStringValues(curi, value, valueContext, Hop.SPECULATIVE);
            }
            // any other attribute
            // ignore for now
            // could probe for path- or script-looking strings, but
            // those should be vanishingly rare in other attributes,
            // and/or symptomatic of page bugs
        }
    }
    TextUtils.recycleMatcher(attr);

    // handle codebase/resources
    if (resources != null) {
        Iterator<String> iter = resources.iterator();
        UURI codebaseURI = null;
        String res = null;
        try {
            if (codebase != null) {
                // TODO: Pass in the charset.
                codebaseURI = UURIFactory.getInstance(curi.getUURI(), codebase);
            }
            while (iter.hasNext()) {
                res = iter.next().toString();
                res = (String) TextUtils.unescapeHtml(res);
                if (codebaseURI != null) {
                    res = codebaseURI.resolve(res).toString();
                }
                processEmbed(curi, res, element); // TODO: include attribute too
            }
        } catch (URIException e) {
            curi.getNonFatalFailures().add(e);
        } catch (IllegalArgumentException e) {
            DevUtils.logger.log(Level.WARNING, "processGeneralTag()\n" + "codebase=" + codebase + " res=" + res
                    + "\n" + DevUtils.extraInfo(), e);
        }
    }

    // finish handling form action, now method is available
    if (action != null) {
        if (method == null || "GET".equalsIgnoreCase(method.toString()) || !getExtractOnlyFormGets()) {
            processLink(curi, action, actionContext);
        }
    }

    // finish handling VALUE
    if (valueVal != null) {
        if ("PARAM".equalsIgnoreCase(elementStr) && nameVal != null
                && "flashvars".equalsIgnoreCase(nameVal.toString())) {
            // special handling for <PARAM NAME='flashvars" VALUE="">
            String queryStringLike = valueVal.toString();
            // treat value as query-string-like "key=value[&key=value]*" pairings
            considerQueryStringValues(curi, queryStringLike, valueContext, Hop.SPECULATIVE);
        } else {
            // regular VALUE handling
            if (extractValueAttributes) {
                considerIfLikelyUri(curi, valueVal, valueContext, Hop.NAVLINK);
            }
        }
    }
}

From source file:org.archive.crawler.extractor.ExtractorHTML.java

protected void processGeneralTag(CrawlURI curi, CharSequence element, CharSequence cs) {
    // System.out.println("I'm processGeneralTag "+curi.toString()+"");
    Matcher attr = TextUtils.getMatcher(EACH_ATTRIBUTE_EXTRACTOR, cs);

    // Just in case it's an OBJECT or APPLET tag
    String codebase = null;// w  ww .  j  a v a  2  s.com
    ArrayList<String> resources = null;

    // Just in case it's a FORM
    CharSequence action = null;
    CharSequence actionContext = null;
    CharSequence method = null;

    // Just in case it's a VALUE whose interpretation depends on
    // accompanying NAME
    CharSequence valueVal = null;
    CharSequence valueContext = null;
    CharSequence nameVal = null;

    final boolean framesAsEmbeds = ((Boolean) getUncheckedAttribute(curi, ATTR_TREAT_FRAMES_AS_EMBED_LINKS))
            .booleanValue();

    final boolean ignoreFormActions = ((Boolean) getUncheckedAttribute(curi, ATTR_IGNORE_FORM_ACTION_URLS))
            .booleanValue();

    final boolean extractValueAttributes = ((Boolean) getUncheckedAttribute(curi, EXTRACT_VALUE_ATTRIBUTES))
            .booleanValue();

    final String elementStr = element.toString();
    while (attr.find()) {
        int valueGroup = (attr.start(14) > -1) ? 14 : (attr.start(15) > -1) ? 15 : 16;
        int start = attr.start(valueGroup);
        int end = attr.end(valueGroup);
        assert start >= 0 : "Start is: " + start + ", " + curi;
        assert end >= 0 : "End is :" + end + ", " + curi;
        CharSequence value = cs.subSequence(start, end);
        CharSequence attrName = cs.subSequence(attr.start(1), attr.end(1));
        value = TextUtils.unescapeHtml(value);
        if (attr.start(2) > -1) {
            // HREF
            CharSequence context = Link.elementContext(element, attr.group(2));
            if (elementStr.equalsIgnoreCase(LINK)) {
                // <LINK> elements treated as embeds (css, ico, etc)
                processEmbed(curi, value, context);
            } else {
                // other HREFs treated as links
                processLink(curi, value, context);
            }
            if (elementStr.equalsIgnoreCase(BASE)) {
                try {
                    curi.setBaseURI(value.toString());
                } catch (URIException e) {
                    if (getController() != null) {
                        // Controller can be null: e.g. when running
                        // ExtractorTool.
                        getController().logUriError(e, curi.getUURI(), value.toString());
                    } else {
                        logger.info("Failed set base uri: " + curi + ", " + value.toString() + ": "
                                + e.getMessage());
                    }
                }
            }
        } else if (attr.start(3) > -1) {
            // ACTION
            if (!ignoreFormActions) {
                action = value;
                actionContext = Link.elementContext(element, attr.group(3));
                // handling finished only at end (after METHOD also
                // collected)
            }
        } else if (attr.start(4) > -1) {
            // ON____
            processScriptCode(curi, value); // TODO: context?
        } else if (attr.start(5) > -1) {
            // SRC etc.
            CharSequence context = Link.elementContext(element, attr.group(5));

            // true, if we expect another HTML page instead of an image etc.
            // TODO: add explicit 'F'rame hop type? (it's not really L, and
            // different enough from other 'E's)
            final char hopType;

            if (!framesAsEmbeds
                    && (elementStr.equalsIgnoreCase(FRAME) || elementStr.equalsIgnoreCase(IFRAME))) {
                hopType = Link.NAVLINK_HOP;
            } else {
                hopType = Link.EMBED_HOP;
            }
            processEmbed(curi, value, context, hopType);
        } else if (attr.start(6) > -1) {
            // CODEBASE
            codebase = (value instanceof String) ? (String) value : value.toString();
            CharSequence context = Link.elementContext(element, attr.group(6));
            processEmbed(curi, codebase, context);
        } else if (attr.start(7) > -1) {
            // CLASSID, DATA
            if (resources == null) {
                resources = new ArrayList<String>();
            }
            resources.add(value.toString());
        } else if (attr.start(8) > -1) {
            // ARCHIVE
            if (resources == null) {
                resources = new ArrayList<String>();
            }
            String[] multi = TextUtils.split(WHITESPACE, value);
            for (int i = 0; i < multi.length; i++) {
                resources.add(multi[i]);
            }
        } else if (attr.start(9) > -1) {
            // CODE
            if (resources == null) {
                resources = new ArrayList<String>();
            }
            // If element is applet and code value does not end with
            // '.class' then append '.class' to the code value.
            if (elementStr.equalsIgnoreCase(APPLET) && !value.toString().toLowerCase().endsWith(CLASSEXT)) {
                resources.add(value.toString() + CLASSEXT);
            } else {
                resources.add(value.toString());
            }
        } else if (attr.start(10) > -1) {
            // VALUE, with possibility of URI
            // store value, context for handling at end
            valueVal = value;
            valueContext = Link.elementContext(element, attr.group(10));
        } else if (attr.start(11) > -1) {
            // STYLE inline attribute
            // then, parse for URIs
            this.numberOfLinksExtracted += ExtractorCSS.processStyleCode(curi, value, getController());

        } else if (attr.start(12) > -1) {
            // METHOD
            method = value;
            // form processing finished at end (after ACTION also collected)
        } else if (attr.start(13) > -1) {
            if ("NAME".equalsIgnoreCase(attrName.toString())) {
                // remember 'name' for end-analysis
                nameVal = value;
            }
            if ("FLASHVARS".equalsIgnoreCase(attrName.toString())) {
                // consider FLASHVARS attribute immediately
                valueContext = Link.elementContext(element, attr.group(13));
                considerQueryStringValues(curi, value, valueContext, Link.SPECULATIVE_HOP);
            }
            // any other attribute
            // ignore for now
            // could probe for path- or script-looking strings, but
            // those should be vanishingly rare in other attributes,
            // and/or symptomatic of page bugs
        }
    }
    TextUtils.recycleMatcher(attr);

    // finish handling codebase/resources now that all available
    if (resources != null) {
        Iterator<String> iter = resources.iterator();
        UURI codebaseURI = null;
        String res = null;
        try {
            if (codebase != null) {
                // TODO: Pass in the charset.
                codebaseURI = UURIFactory.getInstance(curi.getUURI(), codebase);
            }
            while (iter.hasNext()) {
                res = iter.next().toString();
                res = (String) TextUtils.unescapeHtml(res);
                if (codebaseURI != null) {
                    res = codebaseURI.resolve(res).toString();
                }
                processEmbed(curi, res, element); // TODO: include attribute
                // too
            }
        } catch (URIException e) {
            curi.addLocalizedError(getName(), e, "BAD CODEBASE " + codebase);
        } catch (IllegalArgumentException e) {
            DevUtils.logger.log(Level.WARNING, "processGeneralTag()\n" + "codebase=" + codebase + " res=" + res
                    + "\n" + DevUtils.extraInfo(), e);
        }
    }

    // finish handling form action, now method is available
    if (action != null) {
        if (method == null || "GET".equalsIgnoreCase(method.toString())
                || !((Boolean) getUncheckedAttribute(curi, ATTR_EXTRACT_ONLY_FORM_GETS)).booleanValue()) {
            processLink(curi, action, actionContext);
        }
    }

    // finish handling VALUE
    if (valueVal != null) {
        if ("PARAM".equalsIgnoreCase(elementStr) && "flashvars".equalsIgnoreCase(nameVal.toString())) {
            // special handling for <PARAM NAME='flashvars" VALUE="">
            String queryStringLike = valueVal.toString();
            // treat value as query-string-like "key=value[;key=value]*"
            // pairings
            considerQueryStringValues(curi, queryStringLike, valueContext, Link.SPECULATIVE_HOP);
        } else {
            // regular VALUE handling
            if (extractValueAttributes) {
                considerIfLikelyUri(curi, valueVal, valueContext, Link.NAVLINK_HOP);
            }
        }
    }
}

From source file:org.cafemember.messenger.NotificationsController.java

private String getStringForMessage(MessageObject messageObject, boolean shortMessage) {
    long dialog_id = messageObject.messageOwner.dialog_id;
    int chat_id = messageObject.messageOwner.to_id.chat_id != 0 ? messageObject.messageOwner.to_id.chat_id
            : messageObject.messageOwner.to_id.channel_id;
    int from_id = messageObject.messageOwner.to_id.user_id;
    if (from_id == 0) {
        if (messageObject.isFromUser() || messageObject.getId() < 0) {
            from_id = messageObject.messageOwner.from_id;
        } else {/*from w w  w.  j  a v a2s  .c o  m*/
            from_id = -chat_id;
        }
    } else if (from_id == UserConfig.getClientUserId()) {
        from_id = messageObject.messageOwner.from_id;
    }

    if (dialog_id == 0) {
        if (chat_id != 0) {
            dialog_id = -chat_id;
        } else if (from_id != 0) {
            dialog_id = from_id;
        }
    }

    String name = null;
    if (from_id > 0) {
        TLRPC.User user = MessagesController.getInstance().getUser(from_id);
        if (user != null) {
            name = UserObject.getUserName(user);
        }
    } else {
        TLRPC.Chat chat = MessagesController.getInstance().getChat(-from_id);
        if (chat != null) {
            name = chat.title;
        }
    }

    if (name == null) {
        return null;
    }
    TLRPC.Chat chat = null;
    if (chat_id != 0) {
        chat = MessagesController.getInstance().getChat(chat_id);
        if (chat == null) {
            return null;
        }
    }

    String msg = null;
    if ((int) dialog_id == 0 || AndroidUtilities.needShowPasscode(false)
            || UserConfig.isWaitingForPasscodeEnter) {
        msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
    } else {
        if (chat_id == 0 && from_id != 0) {
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            if (preferences.getBoolean("EnablePreviewAll", true)) {
                if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
                    if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) {
                        msg = LocaleController.formatString("NotificationContactJoined",
                                R.string.NotificationContactJoined, name);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                        msg = LocaleController.formatString("NotificationContactNewPhoto",
                                R.string.NotificationContactNewPhoto, name);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
                        String date = LocaleController.formatString("formatDateAtTime",
                                R.string.formatDateAtTime,
                                LocaleController.getInstance().formatterYear
                                        .format(((long) messageObject.messageOwner.date) * 1000),
                                LocaleController.getInstance().formatterDay
                                        .format(((long) messageObject.messageOwner.date) * 1000));
                        msg = LocaleController.formatString("NotificationUnrecognizedDevice",
                                R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name,
                                date, messageObject.messageOwner.action.title,
                                messageObject.messageOwner.action.address);
                    }
                } else {
                    if (messageObject.isMediaEmpty()) {
                        if (!shortMessage) {
                            if (messageObject.messageOwner.message != null
                                    && messageObject.messageOwner.message.length() != 0) {
                                msg = LocaleController.formatString("NotificationMessageText",
                                        R.string.NotificationMessageText, name,
                                        messageObject.messageOwner.message);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageNoText",
                                        R.string.NotificationMessageNoText, name);
                            }
                        } else {
                            msg = LocaleController.formatString("NotificationMessageNoText",
                                    R.string.NotificationMessageNoText, name);
                        }
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                        msg = LocaleController.formatString("NotificationMessagePhoto",
                                R.string.NotificationMessagePhoto, name);
                    } else if (messageObject.isVideo()) {
                        msg = LocaleController.formatString("NotificationMessageVideo",
                                R.string.NotificationMessageVideo, name);
                    } else if (messageObject.isVoice()) {
                        msg = LocaleController.formatString("NotificationMessageAudio",
                                R.string.NotificationMessageAudio, name);
                    } else if (messageObject.isMusic()) {
                        msg = LocaleController.formatString("NotificationMessageMusic",
                                R.string.NotificationMessageMusic, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                        msg = LocaleController.formatString("NotificationMessageContact",
                                R.string.NotificationMessageContact, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                            || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                        msg = LocaleController.formatString("NotificationMessageMap",
                                R.string.NotificationMessageMap, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                        if (messageObject.isSticker()) {
                            msg = LocaleController.formatString("NotificationMessageSticker",
                                    R.string.NotificationMessageSticker, name);
                        } else if (messageObject.isGif()) {
                            msg = LocaleController.formatString("NotificationMessageGif",
                                    R.string.NotificationMessageGif, name);
                        } else {
                            msg = LocaleController.formatString("NotificationMessageDocument",
                                    R.string.NotificationMessageDocument, name);
                        }
                    }
                }
            } else {
                msg = LocaleController.formatString("NotificationMessageNoText",
                        R.string.NotificationMessageNoText, name);
            }
        } else if (chat_id != 0) {
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            if (preferences.getBoolean("EnablePreviewGroup", true)) {
                if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
                    if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
                        int singleUserId = messageObject.messageOwner.action.user_id;
                        if (singleUserId == 0 && messageObject.messageOwner.action.users.size() == 1) {
                            singleUserId = messageObject.messageOwner.action.users.get(0);
                        }
                        if (singleUserId != 0) {
                            if (messageObject.messageOwner.to_id.channel_id != 0
                                    && !messageObject.isMegagroup()) {
                                msg = LocaleController.formatString("ChannelAddedByNotification",
                                        R.string.ChannelAddedByNotification, name, chat.title);
                            } else {
                                if (singleUserId == UserConfig.getClientUserId()) {
                                    msg = LocaleController.formatString("NotificationInvitedToGroup",
                                            R.string.NotificationInvitedToGroup, name, chat.title);
                                } else {
                                    TLRPC.User u2 = MessagesController.getInstance().getUser(singleUserId);
                                    if (u2 == null) {
                                        return null;
                                    }
                                    if (from_id == u2.id) {
                                        if (messageObject.isMegagroup()) {
                                            msg = LocaleController.formatString("NotificationGroupAddSelfMega",
                                                    R.string.NotificationGroupAddSelfMega, name, chat.title);
                                        } else {
                                            msg = LocaleController.formatString("NotificationGroupAddSelf",
                                                    R.string.NotificationGroupAddSelf, name, chat.title);
                                        }
                                    } else {
                                        msg = LocaleController.formatString("NotificationGroupAddMember",
                                                R.string.NotificationGroupAddMember, name, chat.title,
                                                UserObject.getUserName(u2));
                                    }
                                }
                            }
                        } else {
                            StringBuilder names = new StringBuilder("");
                            for (int a = 0; a < messageObject.messageOwner.action.users.size(); a++) {
                                TLRPC.User user = MessagesController.getInstance()
                                        .getUser(messageObject.messageOwner.action.users.get(a));
                                if (user != null) {
                                    String name2 = UserObject.getUserName(user);
                                    if (names.length() != 0) {
                                        names.append(", ");
                                    }
                                    names.append(name2);
                                }
                            }
                            msg = LocaleController.formatString("NotificationGroupAddMember",
                                    R.string.NotificationGroupAddMember, name, chat.title, names.toString());
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
                        msg = LocaleController.formatString("NotificationInvitedToGroupByLink",
                                R.string.NotificationInvitedToGroupByLink, name, chat.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
                        msg = LocaleController.formatString("NotificationEditedGroupName",
                                R.string.NotificationEditedGroupName, name,
                                messageObject.messageOwner.action.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto
                            || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
                        if (messageObject.messageOwner.to_id.channel_id != 0 && !messageObject.isMegagroup()) {
                            msg = LocaleController.formatString("ChannelPhotoEditNotification",
                                    R.string.ChannelPhotoEditNotification, chat.title);
                        } else {
                            msg = LocaleController.formatString("NotificationEditedGroupPhoto",
                                    R.string.NotificationEditedGroupPhoto, name, chat.title);
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                        if (messageObject.messageOwner.action.user_id == UserConfig.getClientUserId()) {
                            msg = LocaleController.formatString("NotificationGroupKickYou",
                                    R.string.NotificationGroupKickYou, name, chat.title);
                        } else if (messageObject.messageOwner.action.user_id == from_id) {
                            msg = LocaleController.formatString("NotificationGroupLeftMember",
                                    R.string.NotificationGroupLeftMember, name, chat.title);
                        } else {
                            TLRPC.User u2 = MessagesController.getInstance()
                                    .getUser(messageObject.messageOwner.action.user_id);
                            if (u2 == null) {
                                return null;
                            }
                            msg = LocaleController.formatString("NotificationGroupKickMember",
                                    R.string.NotificationGroupKickMember, name, chat.title,
                                    UserObject.getUserName(u2));
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
                        msg = messageObject.messageText.toString();
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
                        msg = messageObject.messageText.toString();
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                        msg = LocaleController.formatString("ActionMigrateFromGroupNotify",
                                R.string.ActionMigrateFromGroupNotify, chat.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
                        msg = LocaleController.formatString("ActionMigrateFromGroupNotify",
                                R.string.ActionMigrateFromGroupNotify, messageObject.messageOwner.action.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        if (messageObject.replyMessageObject == null) {
                            if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                msg = LocaleController.formatString("NotificationActionPinnedNoText",
                                        R.string.NotificationActionPinnedNoText, name, chat.title);
                            } else {
                                msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel",
                                        R.string.NotificationActionPinnedNoTextChannel, name, chat.title);
                            }
                        } else {
                            MessageObject object = messageObject.replyMessageObject;
                            if (object.isMusic()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedMusic",
                                            R.string.NotificationActionPinnedMusic, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedMusicChannel",
                                            R.string.NotificationActionPinnedMusicChannel, chat.title);
                                }
                            } else if (object.isVideo()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedVideo",
                                            R.string.NotificationActionPinnedVideo, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedVideoChannel",
                                            R.string.NotificationActionPinnedVideoChannel, chat.title);
                                }
                            } else if (object.isGif()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedGif",
                                            R.string.NotificationActionPinnedGif, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedGifChannel",
                                            R.string.NotificationActionPinnedGifChannel, chat.title);
                                }
                            } else if (object.isVoice()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedVoice",
                                            R.string.NotificationActionPinnedVoice, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedVoiceChannel",
                                            R.string.NotificationActionPinnedVoiceChannel, chat.title);
                                }
                            } else if (object.isSticker()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedSticker",
                                            R.string.NotificationActionPinnedSticker, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString(
                                            "NotificationActionPinnedStickerChannel",
                                            R.string.NotificationActionPinnedStickerChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedFile",
                                            R.string.NotificationActionPinnedFile, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedFileChannel",
                                            R.string.NotificationActionPinnedFileChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedGeo",
                                            R.string.NotificationActionPinnedGeo, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedGeoChannel",
                                            R.string.NotificationActionPinnedGeoChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedContact",
                                            R.string.NotificationActionPinnedContact, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString(
                                            "NotificationActionPinnedContactChannel",
                                            R.string.NotificationActionPinnedContactChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedPhoto",
                                            R.string.NotificationActionPinnedPhoto, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedPhotoChannel",
                                            R.string.NotificationActionPinnedPhotoChannel, chat.title);
                                }
                            } else if (object.messageText != null && object.messageText.length() > 0) {
                                CharSequence message = object.messageText;
                                if (message.length() > 20) {
                                    message = message.subSequence(0, 20) + "...";
                                }
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedText",
                                            R.string.NotificationActionPinnedText, name, message, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedTextChannel",
                                            R.string.NotificationActionPinnedTextChannel, chat.title, message);
                                }
                            } else {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedNoText",
                                            R.string.NotificationActionPinnedNoText, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel",
                                            R.string.NotificationActionPinnedNoTextChannel, chat.title);
                                }
                            }
                        }
                    }
                } else {
                    if (ChatObject.isChannel(chat) && !chat.megagroup) {
                        if (messageObject.isImportant()) {
                            if (messageObject.isMediaEmpty()) {
                                if (!shortMessage && messageObject.messageOwner.message != null
                                        && messageObject.messageOwner.message.length() != 0) {
                                    msg = LocaleController.formatString("NotificationMessageGroupText",
                                            R.string.NotificationMessageGroupText, name, chat.title,
                                            messageObject.messageOwner.message);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageNoText",
                                            R.string.ChannelMessageNoText, name, chat.title);
                                }
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                msg = LocaleController.formatString("ChannelMessagePhoto",
                                        R.string.ChannelMessagePhoto, name, chat.title);
                            } else if (messageObject.isVideo()) {
                                msg = LocaleController.formatString("ChannelMessageVideo",
                                        R.string.ChannelMessageVideo, name, chat.title);
                            } else if (messageObject.isVoice()) {
                                msg = LocaleController.formatString("ChannelMessageAudio",
                                        R.string.ChannelMessageAudio, name, chat.title);
                            } else if (messageObject.isMusic()) {
                                msg = LocaleController.formatString("ChannelMessageMusic",
                                        R.string.ChannelMessageMusic, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                msg = LocaleController.formatString("ChannelMessageContact",
                                        R.string.ChannelMessageContact, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                    || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                                msg = LocaleController.formatString("ChannelMessageMap",
                                        R.string.ChannelMessageMap, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (messageObject.isSticker()) {
                                    msg = LocaleController.formatString("ChannelMessageSticker",
                                            R.string.ChannelMessageSticker, name, chat.title);
                                } else if (messageObject.isGif()) {
                                    msg = LocaleController.formatString("ChannelMessageGIF",
                                            R.string.ChannelMessageGIF, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageDocument",
                                            R.string.ChannelMessageDocument, name, chat.title);
                                }
                            }
                        } else {
                            if (messageObject.isMediaEmpty()) {
                                if (!shortMessage && messageObject.messageOwner.message != null
                                        && messageObject.messageOwner.message.length() != 0) {
                                    msg = LocaleController.formatString("NotificationMessageGroupText",
                                            R.string.NotificationMessageGroupText, name, chat.title,
                                            messageObject.messageOwner.message);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageGroupNoText",
                                            R.string.ChannelMessageGroupNoText, name, chat.title);
                                }
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                msg = LocaleController.formatString("ChannelMessageGroupPhoto",
                                        R.string.ChannelMessageGroupPhoto, name, chat.title);
                            } else if (messageObject.isVideo()) {
                                msg = LocaleController.formatString("ChannelMessageGroupVideo",
                                        R.string.ChannelMessageGroupVideo, name, chat.title);
                            } else if (messageObject.isVoice()) {
                                msg = LocaleController.formatString("ChannelMessageGroupAudio",
                                        R.string.ChannelMessageGroupAudio, name, chat.title);
                            } else if (messageObject.isMusic()) {
                                msg = LocaleController.formatString("ChannelMessageGroupMusic",
                                        R.string.ChannelMessageGroupMusic, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                msg = LocaleController.formatString("ChannelMessageGroupContact",
                                        R.string.ChannelMessageGroupContact, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                    || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                                msg = LocaleController.formatString("ChannelMessageGroupMap",
                                        R.string.ChannelMessageGroupMap, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (messageObject.isSticker()) {
                                    msg = LocaleController.formatString("ChannelMessageGroupSticker",
                                            R.string.ChannelMessageGroupSticker, name, chat.title);
                                } else if (messageObject.isGif()) {
                                    msg = LocaleController.formatString("ChannelMessageGroupGif",
                                            R.string.ChannelMessageGroupGif, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageGroupDocument",
                                            R.string.ChannelMessageGroupDocument, name, chat.title);
                                }
                            }
                        }
                    } else {
                        if (messageObject.isMediaEmpty()) {
                            if (!shortMessage && messageObject.messageOwner.message != null
                                    && messageObject.messageOwner.message.length() != 0) {
                                msg = LocaleController.formatString("NotificationMessageGroupText",
                                        R.string.NotificationMessageGroupText, name, chat.title,
                                        messageObject.messageOwner.message);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageGroupNoText",
                                        R.string.NotificationMessageGroupNoText, name, chat.title);
                            }
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                            msg = LocaleController.formatString("NotificationMessageGroupPhoto",
                                    R.string.NotificationMessageGroupPhoto, name, chat.title);
                        } else if (messageObject.isVideo()) {
                            msg = LocaleController.formatString("NotificationMessageGroupVideo",
                                    R.string.NotificationMessageGroupVideo, name, chat.title);
                        } else if (messageObject.isVoice()) {
                            msg = LocaleController.formatString("NotificationMessageGroupAudio",
                                    R.string.NotificationMessageGroupAudio, name, chat.title);
                        } else if (messageObject.isMusic()) {
                            msg = LocaleController.formatString("NotificationMessageGroupMusic",
                                    R.string.NotificationMessageGroupMusic, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                            msg = LocaleController.formatString("NotificationMessageGroupContact",
                                    R.string.NotificationMessageGroupContact, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                            msg = LocaleController.formatString("NotificationMessageGroupMap",
                                    R.string.NotificationMessageGroupMap, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                            if (messageObject.isSticker()) {
                                msg = LocaleController.formatString("NotificationMessageGroupSticker",
                                        R.string.NotificationMessageGroupSticker, name, chat.title);
                            } else if (messageObject.isGif()) {
                                msg = LocaleController.formatString("NotificationMessageGroupGif",
                                        R.string.NotificationMessageGroupGif, name, chat.title);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageGroupDocument",
                                        R.string.NotificationMessageGroupDocument, name, chat.title);
                            }
                        }
                    }
                }
            } else {
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    msg = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText,
                            name, chat.title);
                } else {
                    msg = LocaleController.formatString("NotificationMessageGroupNoText",
                            R.string.NotificationMessageGroupNoText, name, chat.title);
                }
            }
        }
    }
    return msg;
}

From source file:ir.irani.telecam.messenger.NotificationsController.java

private String getStringForMessage(MessageObject messageObject, boolean shortMessage) {
    long dialog_id = messageObject.messageOwner.dialog_id;
    int chat_id = messageObject.messageOwner.to_id.chat_id != 0 ? messageObject.messageOwner.to_id.chat_id
            : messageObject.messageOwner.to_id.channel_id;
    int from_id = messageObject.messageOwner.to_id.user_id;
    if (from_id == 0) {
        if (messageObject.isFromUser() || messageObject.getId() < 0) {
            from_id = messageObject.messageOwner.from_id;
        } else {//from   w  w w .  j  a  va 2  s .  c o m
            from_id = -chat_id;
        }
    } else if (from_id == UserConfig.getClientUserId()) {
        from_id = messageObject.messageOwner.from_id;
    }

    if (dialog_id == 0) {
        if (chat_id != 0) {
            dialog_id = -chat_id;
        } else if (from_id != 0) {
            dialog_id = from_id;
        }
    }

    String name = null;
    if (from_id > 0) {
        TLRPC.User user = MessagesController.getInstance().getUser(from_id);
        if (user != null) {
            name = UserObject.getUserName(user);
        }
    } else {
        TLRPC.Chat chat = MessagesController.getInstance().getChat(-from_id);
        if (chat != null) {
            name = chat.title;
        }
    }

    if (name == null) {
        return null;
    }
    TLRPC.Chat chat = null;
    if (chat_id != 0) {
        chat = MessagesController.getInstance().getChat(chat_id);
        if (chat == null) {
            return null;
        }
    }

    String msg = null;
    if ((int) dialog_id == 0 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter
            || HiddenController.isHidden(dialog_id)) {
        msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
    } else {
        if (chat_id == 0 && from_id != 0) {
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            if (preferences.getBoolean("EnablePreviewAll", true)) {
                if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
                    if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) {
                        msg = LocaleController.formatString("NotificationContactJoined",
                                R.string.NotificationContactJoined, name);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                        msg = LocaleController.formatString("NotificationContactNewPhoto",
                                R.string.NotificationContactNewPhoto, name);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
                        String date = LocaleController.formatString("formatDateAtTime",
                                R.string.formatDateAtTime,
                                LocaleController.getInstance().formatterYear
                                        .format(((long) messageObject.messageOwner.date) * 1000),
                                LocaleController.getInstance().formatterDay
                                        .format(((long) messageObject.messageOwner.date) * 1000));
                        msg = LocaleController.formatString("NotificationUnrecognizedDevice",
                                R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name,
                                date, messageObject.messageOwner.action.title,
                                messageObject.messageOwner.action.address);
                    }
                } else {
                    if (messageObject.isMediaEmpty()) {
                        if (!shortMessage) {
                            if (messageObject.messageOwner.message != null
                                    && messageObject.messageOwner.message.length() != 0) {
                                msg = LocaleController.formatString("NotificationMessageText",
                                        R.string.NotificationMessageText, name,
                                        messageObject.messageOwner.message);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageNoText",
                                        R.string.NotificationMessageNoText, name);
                            }
                        } else {
                            msg = LocaleController.formatString("NotificationMessageNoText",
                                    R.string.NotificationMessageNoText, name);
                        }
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                        msg = LocaleController.formatString("NotificationMessagePhoto",
                                R.string.NotificationMessagePhoto, name);
                    } else if (messageObject.isVideo()) {
                        msg = LocaleController.formatString("NotificationMessageVideo",
                                R.string.NotificationMessageVideo, name);
                    } else if (messageObject.isVoice()) {
                        msg = LocaleController.formatString("NotificationMessageAudio",
                                R.string.NotificationMessageAudio, name);
                    } else if (messageObject.isMusic()) {
                        msg = LocaleController.formatString("NotificationMessageMusic",
                                R.string.NotificationMessageMusic, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                        msg = LocaleController.formatString("NotificationMessageContact",
                                R.string.NotificationMessageContact, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                            || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                        msg = LocaleController.formatString("NotificationMessageMap",
                                R.string.NotificationMessageMap, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                        if (messageObject.isSticker()) {
                            String emoji = messageObject.getStickerEmoji();
                            if (emoji != null) {
                                msg = LocaleController.formatString("NotificationMessageStickerEmoji",
                                        R.string.NotificationMessageStickerEmoji, name, emoji);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageSticker",
                                        R.string.NotificationMessageSticker, name);
                            }
                        } else if (messageObject.isGif()) {
                            msg = LocaleController.formatString("NotificationMessageGif",
                                    R.string.NotificationMessageGif, name);
                        } else {
                            msg = LocaleController.formatString("NotificationMessageDocument",
                                    R.string.NotificationMessageDocument, name);
                        }
                    }
                }
            } else {
                msg = LocaleController.formatString("NotificationMessageNoText",
                        R.string.NotificationMessageNoText, name);
            }
        } else if (chat_id != 0) {
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            if (preferences.getBoolean("EnablePreviewGroup", true)) {
                if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
                    if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
                        int singleUserId = messageObject.messageOwner.action.user_id;
                        if (singleUserId == 0 && messageObject.messageOwner.action.users.size() == 1) {
                            singleUserId = messageObject.messageOwner.action.users.get(0);
                        }
                        if (singleUserId != 0) {
                            if (messageObject.messageOwner.to_id.channel_id != 0
                                    && !messageObject.isMegagroup()) {
                                msg = LocaleController.formatString("ChannelAddedByNotification",
                                        R.string.ChannelAddedByNotification, name, chat.title);
                            } else {
                                if (singleUserId == UserConfig.getClientUserId()) {
                                    msg = LocaleController.formatString("NotificationInvitedToGroup",
                                            R.string.NotificationInvitedToGroup, name, chat.title);
                                } else {
                                    TLRPC.User u2 = MessagesController.getInstance().getUser(singleUserId);
                                    if (u2 == null) {
                                        return null;
                                    }
                                    if (from_id == u2.id) {
                                        if (messageObject.isMegagroup()) {
                                            msg = LocaleController.formatString("NotificationGroupAddSelfMega",
                                                    R.string.NotificationGroupAddSelfMega, name, chat.title);
                                        } else {
                                            msg = LocaleController.formatString("NotificationGroupAddSelf",
                                                    R.string.NotificationGroupAddSelf, name, chat.title);
                                        }
                                    } else {
                                        msg = LocaleController.formatString("NotificationGroupAddMember",
                                                R.string.NotificationGroupAddMember, name, chat.title,
                                                UserObject.getUserName(u2));
                                    }
                                }
                            }
                        } else {
                            StringBuilder names = new StringBuilder("");
                            for (int a = 0; a < messageObject.messageOwner.action.users.size(); a++) {
                                TLRPC.User user = MessagesController.getInstance()
                                        .getUser(messageObject.messageOwner.action.users.get(a));
                                if (user != null) {
                                    String name2 = UserObject.getUserName(user);
                                    if (names.length() != 0) {
                                        names.append(", ");
                                    }
                                    names.append(name2);
                                }
                            }
                            msg = LocaleController.formatString("NotificationGroupAddMember",
                                    R.string.NotificationGroupAddMember, name, chat.title, names.toString());
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
                        msg = LocaleController.formatString("NotificationInvitedToGroupByLink",
                                R.string.NotificationInvitedToGroupByLink, name, chat.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
                        msg = LocaleController.formatString("NotificationEditedGroupName",
                                R.string.NotificationEditedGroupName, name,
                                messageObject.messageOwner.action.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto
                            || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
                        if (messageObject.messageOwner.to_id.channel_id != 0 && !messageObject.isMegagroup()) {
                            msg = LocaleController.formatString("ChannelPhotoEditNotification",
                                    R.string.ChannelPhotoEditNotification, chat.title);
                        } else {
                            msg = LocaleController.formatString("NotificationEditedGroupPhoto",
                                    R.string.NotificationEditedGroupPhoto, name, chat.title);
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                        if (messageObject.messageOwner.action.user_id == UserConfig.getClientUserId()) {
                            msg = LocaleController.formatString("NotificationGroupKickYou",
                                    R.string.NotificationGroupKickYou, name, chat.title);
                        } else if (messageObject.messageOwner.action.user_id == from_id) {
                            msg = LocaleController.formatString("NotificationGroupLeftMember",
                                    R.string.NotificationGroupLeftMember, name, chat.title);
                        } else {
                            TLRPC.User u2 = MessagesController.getInstance()
                                    .getUser(messageObject.messageOwner.action.user_id);
                            if (u2 == null) {
                                return null;
                            }
                            msg = LocaleController.formatString("NotificationGroupKickMember",
                                    R.string.NotificationGroupKickMember, name, chat.title,
                                    UserObject.getUserName(u2));
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
                        msg = messageObject.messageText.toString();
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
                        msg = messageObject.messageText.toString();
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                        msg = LocaleController.formatString("ActionMigrateFromGroupNotify",
                                R.string.ActionMigrateFromGroupNotify, chat.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
                        msg = LocaleController.formatString("ActionMigrateFromGroupNotify",
                                R.string.ActionMigrateFromGroupNotify, messageObject.messageOwner.action.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        if (messageObject.replyMessageObject == null) {
                            if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                msg = LocaleController.formatString("NotificationActionPinnedNoText",
                                        R.string.NotificationActionPinnedNoText, name, chat.title);
                            } else {
                                msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel",
                                        R.string.NotificationActionPinnedNoTextChannel, name, chat.title);
                            }
                        } else {
                            MessageObject object = messageObject.replyMessageObject;
                            if (object.isMusic()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedMusic",
                                            R.string.NotificationActionPinnedMusic, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedMusicChannel",
                                            R.string.NotificationActionPinnedMusicChannel, chat.title);
                                }
                            } else if (object.isVideo()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedVideo",
                                            R.string.NotificationActionPinnedVideo, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedVideoChannel",
                                            R.string.NotificationActionPinnedVideoChannel, chat.title);
                                }
                            } else if (object.isGif()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedGif",
                                            R.string.NotificationActionPinnedGif, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedGifChannel",
                                            R.string.NotificationActionPinnedGifChannel, chat.title);
                                }
                            } else if (object.isVoice()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedVoice",
                                            R.string.NotificationActionPinnedVoice, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedVoiceChannel",
                                            R.string.NotificationActionPinnedVoiceChannel, chat.title);
                                }
                            } else if (object.isSticker()) {
                                String emoji = messageObject.getStickerEmoji();
                                if (emoji != null) {
                                    if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                        msg = LocaleController.formatString(
                                                "NotificationActionPinnedStickerEmoji",
                                                R.string.NotificationActionPinnedStickerEmoji, name, chat.title,
                                                emoji);
                                    } else {
                                        msg = LocaleController.formatString(
                                                "NotificationActionPinnedStickerEmojiChannel",
                                                R.string.NotificationActionPinnedStickerEmojiChannel,
                                                chat.title, emoji);
                                    }
                                } else {
                                    if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                        msg = LocaleController.formatString("NotificationActionPinnedSticker",
                                                R.string.NotificationActionPinnedSticker, name, chat.title);
                                    } else {
                                        msg = LocaleController.formatString(
                                                "NotificationActionPinnedStickerChannel",
                                                R.string.NotificationActionPinnedStickerChannel, chat.title);
                                    }
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedFile",
                                            R.string.NotificationActionPinnedFile, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedFileChannel",
                                            R.string.NotificationActionPinnedFileChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedGeo",
                                            R.string.NotificationActionPinnedGeo, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedGeoChannel",
                                            R.string.NotificationActionPinnedGeoChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedContact",
                                            R.string.NotificationActionPinnedContact, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString(
                                            "NotificationActionPinnedContactChannel",
                                            R.string.NotificationActionPinnedContactChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedPhoto",
                                            R.string.NotificationActionPinnedPhoto, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedPhotoChannel",
                                            R.string.NotificationActionPinnedPhotoChannel, chat.title);
                                }
                            } else if (object.messageText != null && object.messageText.length() > 0) {
                                CharSequence message = object.messageText;
                                if (message.length() > 20) {
                                    message = message.subSequence(0, 20) + "...";
                                }
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedText",
                                            R.string.NotificationActionPinnedText, name, message, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedTextChannel",
                                            R.string.NotificationActionPinnedTextChannel, chat.title, message);
                                }
                            } else {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedNoText",
                                            R.string.NotificationActionPinnedNoText, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel",
                                            R.string.NotificationActionPinnedNoTextChannel, chat.title);
                                }
                            }
                        }
                    }
                } else {
                    if (ChatObject.isChannel(chat) && !chat.megagroup) {
                        if (messageObject.messageOwner.post) {
                            if (messageObject.isMediaEmpty()) {
                                if (!shortMessage && messageObject.messageOwner.message != null
                                        && messageObject.messageOwner.message.length() != 0) {
                                    msg = LocaleController.formatString("NotificationMessageGroupText",
                                            R.string.NotificationMessageGroupText, name, chat.title,
                                            messageObject.messageOwner.message);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageNoText",
                                            R.string.ChannelMessageNoText, name, chat.title);
                                }
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                msg = LocaleController.formatString("ChannelMessagePhoto",
                                        R.string.ChannelMessagePhoto, name, chat.title);
                            } else if (messageObject.isVideo()) {
                                msg = LocaleController.formatString("ChannelMessageVideo",
                                        R.string.ChannelMessageVideo, name, chat.title);
                            } else if (messageObject.isVoice()) {
                                msg = LocaleController.formatString("ChannelMessageAudio",
                                        R.string.ChannelMessageAudio, name, chat.title);
                            } else if (messageObject.isMusic()) {
                                msg = LocaleController.formatString("ChannelMessageMusic",
                                        R.string.ChannelMessageMusic, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                msg = LocaleController.formatString("ChannelMessageContact",
                                        R.string.ChannelMessageContact, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                    || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                                msg = LocaleController.formatString("ChannelMessageMap",
                                        R.string.ChannelMessageMap, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (messageObject.isSticker()) {
                                    String emoji = messageObject.getStickerEmoji();
                                    if (emoji != null) {
                                        msg = LocaleController.formatString("ChannelMessageStickerEmoji",
                                                R.string.ChannelMessageStickerEmoji, name, chat.title, emoji);
                                    } else {
                                        msg = LocaleController.formatString("ChannelMessageSticker",
                                                R.string.ChannelMessageSticker, name, chat.title);
                                    }
                                } else if (messageObject.isGif()) {
                                    msg = LocaleController.formatString("ChannelMessageGIF",
                                            R.string.ChannelMessageGIF, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageDocument",
                                            R.string.ChannelMessageDocument, name, chat.title);
                                }
                            }
                        } else {
                            if (messageObject.isMediaEmpty()) {
                                if (!shortMessage && messageObject.messageOwner.message != null
                                        && messageObject.messageOwner.message.length() != 0) {
                                    msg = LocaleController.formatString("NotificationMessageGroupText",
                                            R.string.NotificationMessageGroupText, name, chat.title,
                                            messageObject.messageOwner.message);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageGroupNoText",
                                            R.string.ChannelMessageGroupNoText, name, chat.title);
                                }
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                msg = LocaleController.formatString("ChannelMessageGroupPhoto",
                                        R.string.ChannelMessageGroupPhoto, name, chat.title);
                            } else if (messageObject.isVideo()) {
                                msg = LocaleController.formatString("ChannelMessageGroupVideo",
                                        R.string.ChannelMessageGroupVideo, name, chat.title);
                            } else if (messageObject.isVoice()) {
                                msg = LocaleController.formatString("ChannelMessageGroupAudio",
                                        R.string.ChannelMessageGroupAudio, name, chat.title);
                            } else if (messageObject.isMusic()) {
                                msg = LocaleController.formatString("ChannelMessageGroupMusic",
                                        R.string.ChannelMessageGroupMusic, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                msg = LocaleController.formatString("ChannelMessageGroupContact",
                                        R.string.ChannelMessageGroupContact, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                    || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                                msg = LocaleController.formatString("ChannelMessageGroupMap",
                                        R.string.ChannelMessageGroupMap, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (messageObject.isSticker()) {
                                    String emoji = messageObject.getStickerEmoji();
                                    if (emoji != null) {
                                        msg = LocaleController.formatString("ChannelMessageGroupStickerEmoji",
                                                R.string.ChannelMessageGroupStickerEmoji, name, chat.title,
                                                emoji);
                                    } else {
                                        msg = LocaleController.formatString("ChannelMessageGroupSticker",
                                                R.string.ChannelMessageGroupSticker, name, chat.title);
                                    }
                                } else if (messageObject.isGif()) {
                                    msg = LocaleController.formatString("ChannelMessageGroupGif",
                                            R.string.ChannelMessageGroupGif, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageGroupDocument",
                                            R.string.ChannelMessageGroupDocument, name, chat.title);
                                }
                            }
                        }
                    } else {
                        if (messageObject.isMediaEmpty()) {
                            if (!shortMessage && messageObject.messageOwner.message != null
                                    && messageObject.messageOwner.message.length() != 0) {
                                msg = LocaleController.formatString("NotificationMessageGroupText",
                                        R.string.NotificationMessageGroupText, name, chat.title,
                                        messageObject.messageOwner.message);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageGroupNoText",
                                        R.string.NotificationMessageGroupNoText, name, chat.title);
                            }
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                            msg = LocaleController.formatString("NotificationMessageGroupPhoto",
                                    R.string.NotificationMessageGroupPhoto, name, chat.title);
                        } else if (messageObject.isVideo()) {
                            msg = LocaleController.formatString("NotificationMessageGroupVideo",
                                    R.string.NotificationMessageGroupVideo, name, chat.title);
                        } else if (messageObject.isVoice()) {
                            msg = LocaleController.formatString("NotificationMessageGroupAudio",
                                    R.string.NotificationMessageGroupAudio, name, chat.title);
                        } else if (messageObject.isMusic()) {
                            msg = LocaleController.formatString("NotificationMessageGroupMusic",
                                    R.string.NotificationMessageGroupMusic, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                            msg = LocaleController.formatString("NotificationMessageGroupContact",
                                    R.string.NotificationMessageGroupContact, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                            msg = LocaleController.formatString("NotificationMessageGroupMap",
                                    R.string.NotificationMessageGroupMap, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                            if (messageObject.isSticker()) {
                                String emoji = messageObject.getStickerEmoji();
                                if (emoji != null) {
                                    msg = LocaleController.formatString("NotificationMessageGroupStickerEmoji",
                                            R.string.NotificationMessageGroupStickerEmoji, name, chat.title,
                                            emoji);
                                } else {
                                    msg = LocaleController.formatString("NotificationMessageGroupSticker",
                                            R.string.NotificationMessageGroupSticker, name, chat.title);
                                }
                            } else if (messageObject.isGif()) {
                                msg = LocaleController.formatString("NotificationMessageGroupGif",
                                        R.string.NotificationMessageGroupGif, name, chat.title);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageGroupDocument",
                                        R.string.NotificationMessageGroupDocument, name, chat.title);
                            }
                        }
                    }
                }
            } else {
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    msg = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText,
                            name, chat.title);
                } else {
                    msg = LocaleController.formatString("NotificationMessageGroupNoText",
                            R.string.NotificationMessageGroupNoText, name, chat.title);
                }
            }
        }
    }
    return msg;
}

From source file:ir.besteveryeverapp.telegram.NotificationsController.java

private String getStringForMessage(MessageObject messageObject, boolean shortMessage) {
    long dialog_id = messageObject.messageOwner.dialog_id;
    int chat_id = messageObject.messageOwner.to_id.chat_id != 0 ? messageObject.messageOwner.to_id.chat_id
            : messageObject.messageOwner.to_id.channel_id;
    int from_id = messageObject.messageOwner.to_id.user_id;
    if (from_id == 0) {
        if (messageObject.isFromUser() || messageObject.getId() < 0) {
            from_id = messageObject.messageOwner.from_id;
        } else {//  w ww .  java 2  s  . c  o m
            from_id = -chat_id;
        }
    } else if (from_id == UserConfig.getClientUserId()) {
        from_id = messageObject.messageOwner.from_id;
    }

    if (dialog_id == 0) {
        if (chat_id != 0) {
            dialog_id = -chat_id;
        } else if (from_id != 0) {
            dialog_id = from_id;
        }
    }

    String name = null;
    if (from_id > 0) {
        TLRPC.User user = MessagesController.getInstance().getUser(from_id);
        if (user != null) {
            name = UserObject.getUserName(user);
        }
    } else {
        TLRPC.Chat chat = MessagesController.getInstance().getChat(-from_id);
        if (chat != null) {
            name = chat.title;
        }
    }

    if (name == null) {
        return null;
    }
    TLRPC.Chat chat = null;
    if (chat_id != 0) {
        chat = MessagesController.getInstance().getChat(chat_id);
        if (chat == null) {
            return null;
        }
    }

    String msg = null;
    if ((int) dialog_id == 0 || AndroidUtilities.needShowPasscode(false)
            || UserConfig.isWaitingForPasscodeEnter) {
        msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
    } else {
        if (chat_id == 0 && from_id != 0) {
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            if (preferences.getBoolean("EnablePreviewAll", true)) {
                if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
                    if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) {
                        msg = LocaleController.formatString("NotificationContactJoined",
                                R.string.NotificationContactJoined, name);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                        msg = LocaleController.formatString("NotificationContactNewPhoto",
                                R.string.NotificationContactNewPhoto, name);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
                        String date = LocaleController.formatString("formatDateAtTime",
                                R.string.formatDateAtTime,
                                LocaleController.getInstance().formatterYear
                                        .format(((long) messageObject.messageOwner.date) * 1000),
                                LocaleController.getInstance().formatterDay
                                        .format(((long) messageObject.messageOwner.date) * 1000));
                        msg = LocaleController.formatString("NotificationUnrecognizedDevice",
                                R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name,
                                date, messageObject.messageOwner.action.title,
                                messageObject.messageOwner.action.address);
                    }
                } else {
                    if (messageObject.isMediaEmpty()) {
                        if (!shortMessage) {
                            if (messageObject.messageOwner.message != null
                                    && messageObject.messageOwner.message.length() != 0) {
                                msg = LocaleController.formatString("NotificationMessageText",
                                        R.string.NotificationMessageText, name,
                                        messageObject.messageOwner.message);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageNoText",
                                        R.string.NotificationMessageNoText, name);
                            }
                        } else {
                            msg = LocaleController.formatString("NotificationMessageNoText",
                                    R.string.NotificationMessageNoText, name);
                        }
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                        msg = LocaleController.formatString("NotificationMessagePhoto",
                                R.string.NotificationMessagePhoto, name);
                    } else if (messageObject.isVideo()) {
                        msg = LocaleController.formatString("NotificationMessageVideo",
                                R.string.NotificationMessageVideo, name);
                    } else if (messageObject.isVoice()) {
                        msg = LocaleController.formatString("NotificationMessageAudio",
                                R.string.NotificationMessageAudio, name);
                    } else if (messageObject.isMusic()) {
                        msg = LocaleController.formatString("NotificationMessageMusic",
                                R.string.NotificationMessageMusic, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                        msg = LocaleController.formatString("NotificationMessageContact",
                                R.string.NotificationMessageContact, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                            || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                        msg = LocaleController.formatString("NotificationMessageMap",
                                R.string.NotificationMessageMap, name);
                    } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                        if (messageObject.isSticker()) {
                            String emoji = messageObject.getStickerEmoji();
                            if (emoji != null) {
                                msg = LocaleController.formatString("NotificationMessageStickerEmoji",
                                        R.string.NotificationMessageStickerEmoji, name, emoji);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageSticker",
                                        R.string.NotificationMessageSticker, name);
                            }
                        } else if (messageObject.isGif()) {
                            msg = LocaleController.formatString("NotificationMessageGif",
                                    R.string.NotificationMessageGif, name);
                        } else {
                            msg = LocaleController.formatString("NotificationMessageDocument",
                                    R.string.NotificationMessageDocument, name);
                        }
                    }
                }
            } else {
                msg = LocaleController.formatString("NotificationMessageNoText",
                        R.string.NotificationMessageNoText, name);
            }
        } else if (chat_id != 0) {
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            if (preferences.getBoolean("EnablePreviewGroup", true)) {
                if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
                    if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
                        int singleUserId = messageObject.messageOwner.action.user_id;
                        if (singleUserId == 0 && messageObject.messageOwner.action.users.size() == 1) {
                            singleUserId = messageObject.messageOwner.action.users.get(0);
                        }
                        if (singleUserId != 0) {
                            if (messageObject.messageOwner.to_id.channel_id != 0
                                    && !messageObject.isMegagroup()) {
                                msg = LocaleController.formatString("ChannelAddedByNotification",
                                        R.string.ChannelAddedByNotification, name, chat.title);
                            } else {
                                if (singleUserId == UserConfig.getClientUserId()) {
                                    msg = LocaleController.formatString("NotificationInvitedToGroup",
                                            R.string.NotificationInvitedToGroup, name, chat.title);
                                } else {
                                    TLRPC.User u2 = MessagesController.getInstance().getUser(singleUserId);
                                    if (u2 == null) {
                                        return null;
                                    }
                                    if (from_id == u2.id) {
                                        if (messageObject.isMegagroup()) {
                                            msg = LocaleController.formatString("NotificationGroupAddSelfMega",
                                                    R.string.NotificationGroupAddSelfMega, name, chat.title);
                                        } else {
                                            msg = LocaleController.formatString("NotificationGroupAddSelf",
                                                    R.string.NotificationGroupAddSelf, name, chat.title);
                                        }
                                    } else {
                                        msg = LocaleController.formatString("NotificationGroupAddMember",
                                                R.string.NotificationGroupAddMember, name, chat.title,
                                                UserObject.getUserName(u2));
                                    }
                                }
                            }
                        } else {
                            StringBuilder names = new StringBuilder("");
                            for (int a = 0; a < messageObject.messageOwner.action.users.size(); a++) {
                                TLRPC.User user = MessagesController.getInstance()
                                        .getUser(messageObject.messageOwner.action.users.get(a));
                                if (user != null) {
                                    String name2 = UserObject.getUserName(user);
                                    if (names.length() != 0) {
                                        names.append(", ");
                                    }
                                    names.append(name2);
                                }
                            }
                            msg = LocaleController.formatString("NotificationGroupAddMember",
                                    R.string.NotificationGroupAddMember, name, chat.title, names.toString());
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
                        msg = LocaleController.formatString("NotificationInvitedToGroupByLink",
                                R.string.NotificationInvitedToGroupByLink, name, chat.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
                        msg = LocaleController.formatString("NotificationEditedGroupName",
                                R.string.NotificationEditedGroupName, name,
                                messageObject.messageOwner.action.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto
                            || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
                        if (messageObject.messageOwner.to_id.channel_id != 0 && !messageObject.isMegagroup()) {
                            msg = LocaleController.formatString("ChannelPhotoEditNotification",
                                    R.string.ChannelPhotoEditNotification, chat.title);
                        } else {
                            msg = LocaleController.formatString("NotificationEditedGroupPhoto",
                                    R.string.NotificationEditedGroupPhoto, name, chat.title);
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                        if (messageObject.messageOwner.action.user_id == UserConfig.getClientUserId()) {
                            msg = LocaleController.formatString("NotificationGroupKickYou",
                                    R.string.NotificationGroupKickYou, name, chat.title);
                        } else if (messageObject.messageOwner.action.user_id == from_id) {
                            msg = LocaleController.formatString("NotificationGroupLeftMember",
                                    R.string.NotificationGroupLeftMember, name, chat.title);
                        } else {
                            TLRPC.User u2 = MessagesController.getInstance()
                                    .getUser(messageObject.messageOwner.action.user_id);
                            if (u2 == null) {
                                return null;
                            }
                            msg = LocaleController.formatString("NotificationGroupKickMember",
                                    R.string.NotificationGroupKickMember, name, chat.title,
                                    UserObject.getUserName(u2));
                        }
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
                        msg = messageObject.messageText.toString();
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
                        msg = messageObject.messageText.toString();
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                        msg = LocaleController.formatString("ActionMigrateFromGroupNotify",
                                R.string.ActionMigrateFromGroupNotify, chat.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
                        msg = LocaleController.formatString("ActionMigrateFromGroupNotify",
                                R.string.ActionMigrateFromGroupNotify, messageObject.messageOwner.action.title);
                    } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        if (messageObject.replyMessageObject == null) {
                            if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                msg = LocaleController.formatString("NotificationActionPinnedNoText",
                                        R.string.NotificationActionPinnedNoText, name, chat.title);
                            } else {
                                msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel",
                                        R.string.NotificationActionPinnedNoTextChannel, name, chat.title);
                            }
                        } else {
                            MessageObject object = messageObject.replyMessageObject;
                            if (object.isMusic()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedMusic",
                                            R.string.NotificationActionPinnedMusic, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedMusicChannel",
                                            R.string.NotificationActionPinnedMusicChannel, chat.title);
                                }
                            } else if (object.isVideo()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedVideo",
                                            R.string.NotificationActionPinnedVideo, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedVideoChannel",
                                            R.string.NotificationActionPinnedVideoChannel, chat.title);
                                }
                            } else if (object.isGif()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedGif",
                                            R.string.NotificationActionPinnedGif, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedGifChannel",
                                            R.string.NotificationActionPinnedGifChannel, chat.title);
                                }
                            } else if (object.isVoice()) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedVoice",
                                            R.string.NotificationActionPinnedVoice, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedVoiceChannel",
                                            R.string.NotificationActionPinnedVoiceChannel, chat.title);
                                }
                            } else if (object.isSticker()) {
                                String emoji = messageObject.getStickerEmoji();
                                if (emoji != null) {
                                    if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                        msg = LocaleController.formatString(
                                                "NotificationActionPinnedStickerEmoji",
                                                R.string.NotificationActionPinnedStickerEmoji, name, chat.title,
                                                emoji);
                                    } else {
                                        msg = LocaleController.formatString(
                                                "NotificationActionPinnedStickerEmojiChannel",
                                                R.string.NotificationActionPinnedStickerEmojiChannel,
                                                chat.title, emoji);
                                    }
                                } else {
                                    if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                        msg = LocaleController.formatString("NotificationActionPinnedSticker",
                                                R.string.NotificationActionPinnedSticker, name, chat.title);
                                    } else {
                                        msg = LocaleController.formatString(
                                                "NotificationActionPinnedStickerChannel",
                                                R.string.NotificationActionPinnedStickerChannel, chat.title);
                                    }
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedFile",
                                            R.string.NotificationActionPinnedFile, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedFileChannel",
                                            R.string.NotificationActionPinnedFileChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedGeo",
                                            R.string.NotificationActionPinnedGeo, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedGeoChannel",
                                            R.string.NotificationActionPinnedGeoChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedContact",
                                            R.string.NotificationActionPinnedContact, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString(
                                            "NotificationActionPinnedContactChannel",
                                            R.string.NotificationActionPinnedContactChannel, chat.title);
                                }
                            } else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedPhoto",
                                            R.string.NotificationActionPinnedPhoto, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedPhotoChannel",
                                            R.string.NotificationActionPinnedPhotoChannel, chat.title);
                                }
                            } else if (object.messageText != null && object.messageText.length() > 0) {
                                CharSequence message = object.messageText;
                                if (message.length() > 20) {
                                    message = message.subSequence(0, 20) + "...";
                                }
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedText",
                                            R.string.NotificationActionPinnedText, name, message, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedTextChannel",
                                            R.string.NotificationActionPinnedTextChannel, chat.title, message);
                                }
                            } else {
                                if (!ChatObject.isChannel(chat) || chat.megagroup) {
                                    msg = LocaleController.formatString("NotificationActionPinnedNoText",
                                            R.string.NotificationActionPinnedNoText, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel",
                                            R.string.NotificationActionPinnedNoTextChannel, chat.title);
                                }
                            }
                        }
                    }
                } else {
                    if (ChatObject.isChannel(chat) && !chat.megagroup) {
                        if (messageObject.messageOwner.post) {
                            if (messageObject.isMediaEmpty()) {
                                if (!shortMessage && messageObject.messageOwner.message != null
                                        && messageObject.messageOwner.message.length() != 0) {
                                    msg = LocaleController.formatString("NotificationMessageGroupText",
                                            R.string.NotificationMessageGroupText, name, chat.title,
                                            messageObject.messageOwner.message);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageNoText",
                                            R.string.ChannelMessageNoText, name, chat.title);
                                }
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                msg = LocaleController.formatString("ChannelMessagePhoto",
                                        R.string.ChannelMessagePhoto, name, chat.title);
                            } else if (messageObject.isVideo()) {
                                msg = LocaleController.formatString("ChannelMessageVideo",
                                        R.string.ChannelMessageVideo, name, chat.title);
                            } else if (messageObject.isVoice()) {
                                msg = LocaleController.formatString("ChannelMessageAudio",
                                        R.string.ChannelMessageAudio, name, chat.title);
                            } else if (messageObject.isMusic()) {
                                msg = LocaleController.formatString("ChannelMessageMusic",
                                        R.string.ChannelMessageMusic, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                msg = LocaleController.formatString("ChannelMessageContact",
                                        R.string.ChannelMessageContact, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                    || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                                msg = LocaleController.formatString("ChannelMessageMap",
                                        R.string.ChannelMessageMap, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (messageObject.isSticker()) {
                                    String emoji = messageObject.getStickerEmoji();
                                    if (emoji != null) {
                                        msg = LocaleController.formatString("ChannelMessageStickerEmoji",
                                                R.string.ChannelMessageStickerEmoji, name, chat.title, emoji);
                                    } else {
                                        msg = LocaleController.formatString("ChannelMessageSticker",
                                                R.string.ChannelMessageSticker, name, chat.title);
                                    }
                                } else if (messageObject.isGif()) {
                                    msg = LocaleController.formatString("ChannelMessageGIF",
                                            R.string.ChannelMessageGIF, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageDocument",
                                            R.string.ChannelMessageDocument, name, chat.title);
                                }
                            }
                        } else {
                            if (messageObject.isMediaEmpty()) {
                                if (!shortMessage && messageObject.messageOwner.message != null
                                        && messageObject.messageOwner.message.length() != 0) {
                                    msg = LocaleController.formatString("NotificationMessageGroupText",
                                            R.string.NotificationMessageGroupText, name, chat.title,
                                            messageObject.messageOwner.message);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageGroupNoText",
                                            R.string.ChannelMessageGroupNoText, name, chat.title);
                                }
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                                msg = LocaleController.formatString("ChannelMessageGroupPhoto",
                                        R.string.ChannelMessageGroupPhoto, name, chat.title);
                            } else if (messageObject.isVideo()) {
                                msg = LocaleController.formatString("ChannelMessageGroupVideo",
                                        R.string.ChannelMessageGroupVideo, name, chat.title);
                            } else if (messageObject.isVoice()) {
                                msg = LocaleController.formatString("ChannelMessageGroupAudio",
                                        R.string.ChannelMessageGroupAudio, name, chat.title);
                            } else if (messageObject.isMusic()) {
                                msg = LocaleController.formatString("ChannelMessageGroupMusic",
                                        R.string.ChannelMessageGroupMusic, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                                msg = LocaleController.formatString("ChannelMessageGroupContact",
                                        R.string.ChannelMessageGroupContact, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                    || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                                msg = LocaleController.formatString("ChannelMessageGroupMap",
                                        R.string.ChannelMessageGroupMap, name, chat.title);
                            } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                                if (messageObject.isSticker()) {
                                    String emoji = messageObject.getStickerEmoji();
                                    if (emoji != null) {
                                        msg = LocaleController.formatString("ChannelMessageGroupStickerEmoji",
                                                R.string.ChannelMessageGroupStickerEmoji, name, chat.title,
                                                emoji);
                                    } else {
                                        msg = LocaleController.formatString("ChannelMessageGroupSticker",
                                                R.string.ChannelMessageGroupSticker, name, chat.title);
                                    }
                                } else if (messageObject.isGif()) {
                                    msg = LocaleController.formatString("ChannelMessageGroupGif",
                                            R.string.ChannelMessageGroupGif, name, chat.title);
                                } else {
                                    msg = LocaleController.formatString("ChannelMessageGroupDocument",
                                            R.string.ChannelMessageGroupDocument, name, chat.title);
                                }
                            }
                        }
                    } else {
                        if (messageObject.isMediaEmpty()) {
                            if (!shortMessage && messageObject.messageOwner.message != null
                                    && messageObject.messageOwner.message.length() != 0) {
                                msg = LocaleController.formatString("NotificationMessageGroupText",
                                        R.string.NotificationMessageGroupText, name, chat.title,
                                        messageObject.messageOwner.message);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageGroupNoText",
                                        R.string.NotificationMessageGroupNoText, name, chat.title);
                            }
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                            msg = LocaleController.formatString("NotificationMessageGroupPhoto",
                                    R.string.NotificationMessageGroupPhoto, name, chat.title);
                        } else if (messageObject.isVideo()) {
                            msg = LocaleController.formatString("NotificationMessageGroupVideo",
                                    R.string.NotificationMessageGroupVideo, name, chat.title);
                        } else if (messageObject.isVoice()) {
                            msg = LocaleController.formatString("NotificationMessageGroupAudio",
                                    R.string.NotificationMessageGroupAudio, name, chat.title);
                        } else if (messageObject.isMusic()) {
                            msg = LocaleController.formatString("NotificationMessageGroupMusic",
                                    R.string.NotificationMessageGroupMusic, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                            msg = LocaleController.formatString("NotificationMessageGroupContact",
                                    R.string.NotificationMessageGroupContact, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo
                                || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                            msg = LocaleController.formatString("NotificationMessageGroupMap",
                                    R.string.NotificationMessageGroupMap, name, chat.title);
                        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                            if (messageObject.isSticker()) {
                                String emoji = messageObject.getStickerEmoji();
                                if (emoji != null) {
                                    msg = LocaleController.formatString("NotificationMessageGroupStickerEmoji",
                                            R.string.NotificationMessageGroupStickerEmoji, name, chat.title,
                                            emoji);
                                } else {
                                    msg = LocaleController.formatString("NotificationMessageGroupSticker",
                                            R.string.NotificationMessageGroupSticker, name, chat.title);
                                }
                            } else if (messageObject.isGif()) {
                                msg = LocaleController.formatString("NotificationMessageGroupGif",
                                        R.string.NotificationMessageGroupGif, name, chat.title);
                            } else {
                                msg = LocaleController.formatString("NotificationMessageGroupDocument",
                                        R.string.NotificationMessageGroupDocument, name, chat.title);
                            }
                        }
                    }
                }
            } else {
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    msg = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText,
                            name, chat.title);
                } else {
                    msg = LocaleController.formatString("NotificationMessageGroupNoText",
                            R.string.NotificationMessageGroupNoText, name, chat.title);
                }
            }
        }
    }
    return msg;
}

From source file:com.android.mms.ui.MessageUtils.java

public static final String findSpanishChar(CharSequence s) {
    int sLength = s.length();
    StringBuilder sPs = new StringBuilder();
    for (int i = 0; i < sLength; i++) {
        char tmpC = s.charAt(i);
        int tmpi = (int) tmpC;
        //   Log.e("chenshu","MessageUtils->>findSpanishChar->>tmpi->>"+Integer.toHexString(tmpi));
        //   Log.d("chenshu","MessageUtils->>findSpanishChar->>calculateLength->>"+s.subSequence(i,i+1));

        int[] params = SmsMessage.calculateLength(s.subSequence(i, i + 1), false);
        //            /* SmsMessage.calculateLength returns an int[4] with:
        //             *   int[0] being the number of SMS's required,
        //             *   int[1] the number of code units used,
        //             *   int[2] is the number of code units remaining until the next message.
        //             *   int[3] is the encoding type that should be used for the message.
        //             *//*www.jav a  2  s  .c o  m*/
        int remainingInCurrentMessage = params[2];
        //   Log.d("chenshu","MessageUtils->>findSpanishChar->>remainingInCurrentMessage->>"+remainingInCurrentMessage);
        if (remainingInCurrentMessage > 70) {
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>Default 7-bit char");
            sPs.append(tmpC);
            continue;
        }

        switch (tmpi) {
        case 0x00C0:
        case 0x00C1:
        case 0x00C2:
        case 0x00C3:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to A");
            sPs.append('A');
            break;
        case 0x00C8:
        case 0x00CA:
        case 0x00CB:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to E");
            sPs.append('E');
            break;
        case 0x00CC:
        case 0x00CD:
        case 0x00CE:
        case 0x00CF:
        case 0x0130:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to I");
            sPs.append('I');
            break;
        case 0x00D2:
        case 0x00D3:
        case 0x00D4:
        case 0x00D5:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to O");
            sPs.append('O');
            break;
        case 0x00D9:
        case 0x00DA:
        case 0x00DB:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to U");
            sPs.append('U');
            break;
        case 0x00E1:
        case 0x00E2:
        case 0x00E3:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to a");
            sPs.append('a');
            break;
        //case 0x00C7:
        case 0x00E7:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to c");
            sPs.append('c');
            break;
        case 0x00EA:
        case 0x00EB:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to e");
            sPs.append('e');
            break;
        case 0x00ED:
        case 0x00EE:
        case 0x00EF:
        case 0x0131:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to i");
            sPs.append('i');
            break;
        case 0x00F3:
        case 0x00F4:
        case 0x00F5:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to o");
            sPs.append('o');
            break;
        case 0x00FA:
        case 0x00FB:
            //   Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to u");
            sPs.append('u');
            break;
        case 0x011E:
            sPs.append('G');
            break;
        case 0x011F:
            sPs.append('g');
            break;
        case 0x015E:
            sPs.append('S');
            break;
        case 0x015F:
            sPs.append('s');
            break;
        default:
            if (tmpC > 127 || tmpC < 0) {
                //      Log.e("chenshu","MessageUtil->>findSpanishChar->>becaus it was not ascii char->>tmpC->>"+tmpC);
                return null;
            } else {
                sPs.append(tmpC);
            }
            break;
        }
        //   Log.e("chenshu","MessageUtil->>findSpanishChar->>tmpC->>"+tmpC);
    }

    if (sPs.toString().endsWith(s.toString())) {
        return null;
    } else {
        //   Log.e("chenshu","MessageUtil->>findSpanishChar->>mRepliceText->>"+sPs.toString());
        return sPs.toString();
    }
}

From source file:org.telegram.ui.Components.ChatActivityEnterView.java

public boolean processSendingText(CharSequence text) {
    text = AndroidUtilities.getTrimmedString(text);
    if (text.length() != 0) {
        int count = (int) Math.ceil(text.length() / 4096.0f);
        for (int a = 0; a < count; a++) {
            CharSequence[] message = new CharSequence[] {
                    text.subSequence(a * 4096, Math.min((a + 1) * 4096, text.length())) };
            ArrayList<TLRPC.MessageEntity> entities = MessagesQuery.getEntities(message);
            SendMessagesHelper.getInstance().sendMessage(message[0].toString(), dialog_id,
                    replyingMessageObject, messageWebPage, messageWebPageSearch, entities, null, null);
        }// ww  w  .j a va 2 s.c  o m
        return true;
    }
    return false;
}