List of usage examples for android.text TextUtils join
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens)
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String StartPrg(String[] progArray, OutputStream out, boolean startAsRoot, int timeoutSeconds) { String sRet = ""; int lcv = 0;/*from w w w .ja v a 2 s. c o m*/ try { if (startAsRoot) { // we need to requote the program string here, in case // there's spaces or other characters which need quoting // before being passed to su List<String> quotedProgList = new ArrayList<String>(); for (String arg : progArray) { String quotedArg = arg; quotedArg = quotedArg.replace("\"", "\\\""); quotedArg = quotedArg.replace("\'", "\\\'"); if (quotedArg.contains(" ")) { quotedArg = "\"" + quotedArg + "\""; } quotedProgList.add(quotedArg); } pProc = Runtime.getRuntime().exec(this.getSuArgs(TextUtils.join(" ", quotedProgList))); } else { pProc = Runtime.getRuntime().exec(progArray); } RedirOutputThread outThrd = new RedirOutputThread(pProc, out); outThrd.start(); try { outThrd.join(timeoutSeconds * 1000); int nRetCode = pProc.exitValue(); sRet = "return code [" + nRetCode + "]"; } catch (IllegalThreadStateException itse) { } outThrd.stopRedirect(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); sRet = "Timed out!"; } return (sRet); }
From source file:g7.bluesky.launcher3.Launcher.java
@Override public void bindAddScreens(ArrayList<Long> orderedScreenIds) { // Log to disk Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true); Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " + TextUtils.join(", ", orderedScreenIds), true); int count = orderedScreenIds.size(); for (int i = 0; i < count; i++) { mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); }/*w ww.ja v a 2 s . com*/ }
From source file:net.bluehack.ui.ChatActivity.java
private void searchLinks(final CharSequence charSequence, final boolean force) { if (currentEncryptedChat != null && (MessagesController.getInstance().secretWebpagePreview == 0 || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 46)) { return;// ww w . java 2 s .c o m } if (force && foundWebPage != null) { if (foundWebPage.url != null) { int index = TextUtils.indexOf(charSequence, foundWebPage.url); char lastChar = 0; boolean lenEqual = false; if (index == -1) { if (foundWebPage.display_url != null) { index = TextUtils.indexOf(charSequence, foundWebPage.display_url); lenEqual = index != -1 && index + foundWebPage.display_url.length() == charSequence.length(); lastChar = index != -1 && !lenEqual ? charSequence.charAt(index + foundWebPage.display_url.length()) : 0; } } else { lenEqual = index + foundWebPage.url.length() == charSequence.length(); lastChar = !lenEqual ? charSequence.charAt(index + foundWebPage.url.length()) : 0; } if (index != -1 && (lenEqual || lastChar == ' ' || lastChar == ',' || lastChar == '.' || lastChar == '!' || lastChar == '/')) { return; } } pendingLinkSearchString = null; showReplyPanel(false, null, null, foundWebPage, false, true); } Utilities.searchQueue.postRunnable(new Runnable() { @Override public void run() { if (linkSearchRequestId != 0) { ConnectionsManager.getInstance().cancelRequest(linkSearchRequestId, true); linkSearchRequestId = 0; } ArrayList<CharSequence> urls = null; CharSequence textToCheck; try { Matcher m = AndroidUtilities.WEB_URL.matcher(charSequence); while (m.find()) { if (m.start() > 0) { if (charSequence.charAt(m.start() - 1) == '@') { continue; } } if (urls == null) { urls = new ArrayList<>(); } urls.add(charSequence.subSequence(m.start(), m.end())); } if (urls != null && foundUrls != null && urls.size() == foundUrls.size()) { boolean clear = true; for (int a = 0; a < urls.size(); a++) { if (!TextUtils.equals(urls.get(a), foundUrls.get(a))) { clear = false; } } if (clear) { return; } } foundUrls = urls; if (urls == null) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } }); return; } textToCheck = TextUtils.join(" ", urls); } catch (Exception e) { FileLog.e("tmessages", e); String text = charSequence.toString().toLowerCase(); if (charSequence.length() < 13 || !text.contains("http://") && !text.contains("https://")) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } }); return; } textToCheck = charSequence; } if (currentEncryptedChat != null && MessagesController.getInstance().secretWebpagePreview == 2) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MessagesController.getInstance().secretWebpagePreview = 1; ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE) .edit() .putInt("secretWebpage2", MessagesController.getInstance().secretWebpagePreview) .commit(); foundUrls = null; searchLinks(charSequence, force); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setMessage(LocaleController.getString("SecretLinkPreviewAlert", R.string.SecretLinkPreviewAlert)); showDialog(builder.create()); MessagesController.getInstance().secretWebpagePreview = 0; ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit() .putInt("secretWebpage2", MessagesController.getInstance().secretWebpagePreview) .commit(); } }); return; } final TLRPC.TL_messages_getWebPagePreview req = new TLRPC.TL_messages_getWebPagePreview(); if (textToCheck instanceof String) { req.message = (String) textToCheck; } else { req.message = textToCheck.toString(); } linkSearchRequestId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { linkSearchRequestId = 0; if (error == null) { if (response instanceof TLRPC.TL_messageMediaWebPage) { foundWebPage = ((TLRPC.TL_messageMediaWebPage) response).webpage; if (foundWebPage instanceof TLRPC.TL_webPage || foundWebPage instanceof TLRPC.TL_webPagePending) { if (foundWebPage instanceof TLRPC.TL_webPagePending) { pendingLinkSearchString = req.message; } if (currentEncryptedChat != null && foundWebPage instanceof TLRPC.TL_webPagePending) { foundWebPage.url = req.message; } showReplyPanel(true, null, null, foundWebPage, false, true); } else { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } } else { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } } } }); } }); ConnectionsManager.getInstance().bindRequestToGuid(linkSearchRequestId, classGuid); } }); }
From source file:kr.wdream.ui.ChatActivity.java
private void searchLinks(final CharSequence charSequence, final boolean force) { if (currentEncryptedChat != null && (MessagesController.getInstance().secretWebpagePreview == 0 || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 46)) { return;/*from w w w . j a v a 2 s . c o m*/ } if (force && foundWebPage != null) { if (foundWebPage.url != null) { int index = TextUtils.indexOf(charSequence, foundWebPage.url); char lastChar = 0; boolean lenEqual = false; if (index == -1) { if (foundWebPage.display_url != null) { index = TextUtils.indexOf(charSequence, foundWebPage.display_url); lenEqual = index != -1 && index + foundWebPage.display_url.length() == charSequence.length(); lastChar = index != -1 && !lenEqual ? charSequence.charAt(index + foundWebPage.display_url.length()) : 0; } } else { lenEqual = index + foundWebPage.url.length() == charSequence.length(); lastChar = !lenEqual ? charSequence.charAt(index + foundWebPage.url.length()) : 0; } if (index != -1 && (lenEqual || lastChar == ' ' || lastChar == ',' || lastChar == '.' || lastChar == '!' || lastChar == '/')) { return; } } pendingLinkSearchString = null; showReplyPanel(false, null, null, foundWebPage, false, true); } Utilities.searchQueue.postRunnable(new Runnable() { @Override public void run() { if (linkSearchRequestId != 0) { ConnectionsManager.getInstance().cancelRequest(linkSearchRequestId, true); linkSearchRequestId = 0; } ArrayList<CharSequence> urls = null; CharSequence textToCheck; try { Matcher m = AndroidUtilities.WEB_URL.matcher(charSequence); while (m.find()) { if (m.start() > 0) { if (charSequence.charAt(m.start() - 1) == '@') { continue; } } if (urls == null) { urls = new ArrayList<>(); } urls.add(charSequence.subSequence(m.start(), m.end())); } if (urls != null && foundUrls != null && urls.size() == foundUrls.size()) { boolean clear = true; for (int a = 0; a < urls.size(); a++) { if (!TextUtils.equals(urls.get(a), foundUrls.get(a))) { clear = false; } } if (clear) { return; } } foundUrls = urls; if (urls == null) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } }); return; } textToCheck = TextUtils.join(" ", urls); } catch (Exception e) { FileLog.e("tmessages", e); String text = charSequence.toString().toLowerCase(); if (charSequence.length() < 13 || !text.contains("http://") && !text.contains("https://")) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } }); return; } textToCheck = charSequence; } if (currentEncryptedChat != null && MessagesController.getInstance().secretWebpagePreview == 2) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MessagesController.getInstance().secretWebpagePreview = 1; ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE) .edit() .putInt("secretWebpage2", MessagesController.getInstance().secretWebpagePreview) .commit(); foundUrls = null; searchLinks(charSequence, force); } }); builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); builder.setMessage(LocaleController.getString("SecretLinkPreviewAlert", kr.wdream.storyshop.R.string.SecretLinkPreviewAlert)); showDialog(builder.create()); MessagesController.getInstance().secretWebpagePreview = 0; ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit() .putInt("secretWebpage2", MessagesController.getInstance().secretWebpagePreview) .commit(); } }); return; } final TLRPC.TL_messages_getWebPagePreview req = new TLRPC.TL_messages_getWebPagePreview(); if (textToCheck instanceof String) { req.message = (String) textToCheck; } else { req.message = textToCheck.toString(); } linkSearchRequestId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { linkSearchRequestId = 0; if (error == null) { if (response instanceof TLRPC.TL_messageMediaWebPage) { foundWebPage = ((TLRPC.TL_messageMediaWebPage) response).webpage; if (foundWebPage instanceof TLRPC.TL_webPage || foundWebPage instanceof TLRPC.TL_webPagePending) { if (foundWebPage instanceof TLRPC.TL_webPagePending) { pendingLinkSearchString = req.message; } if (currentEncryptedChat != null && foundWebPage instanceof TLRPC.TL_webPagePending) { foundWebPage.url = req.message; } showReplyPanel(true, null, null, foundWebPage, false, true); } else { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } } else { if (foundWebPage != null) { showReplyPanel(false, null, null, foundWebPage, false, true); foundWebPage = null; } } } } }); } }); ConnectionsManager.getInstance().bindRequestToGuid(linkSearchRequestId, classGuid); } }); }
From source file:org.telegram.android.MessagesController.java
public void getDialogUnreadPostNum() { Log.d("getDialogUnreadPostNum", "getDialogUnreadPostNum"); ArrayList<Long> ids = new ArrayList<>(); for (TLRPC.TL_dialog dialog : dialogs) { if (dialog.id < 0) { ids.add(-dialog.id);// ww w . j a v a 2 s . c o m } } // add public stream ids.add(-1L); dialogUnreadPost.clear(); String chatIds = TextUtils.join(",", ids); ApiRequestHelper.groupUnreadMsgCount(String.valueOf(UserConfig.getClientUserId()), chatIds, new ApiRequestHelper.BuildParamsCallBack() { @Override public void build(RequestParams params) { ApiUrlHelper.GROUP_UNREAD_MSG_COUNT.build(params, new TextHttpResponseHandler() { @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { T8Log.ZHAO_ZHEN.d(responseString); } @Override public void onSuccess(int statusCode, Header[] headers, String responseString) { T8Log.ZHAO_ZHEN.d(responseString); GroupPostUnreadNumEntity queryEntity = new GroupPostUnreadNumEntity(); queryEntity = queryEntity.jsonParse(responseString); if (queryEntity.getError() == null) { ArrayList<GroupPostUnreadNumEntity.UnreadPostNum> datas = queryEntity.getData(); for (GroupPostUnreadNumEntity.UnreadPostNum data : datas) { dialogUnreadPost.put(data.getTg_group_id(), data.getCount()); } } NotificationCenter.getInstance() .postNotificationName(NotificationCenter.dialogUnreadPostNumDidLoaded); } }, T8UserConfig.getUserId()).execute(); } }); }