List of usage examples for android.text TextUtils join
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens)
From source file:com.facebook.samples.hellofacebook.MapFriends.java
private void onFriendPickerDone(FriendPickerFragment fragment) { FragmentManager fm = getSupportFragmentManager(); fm.popBackStack();//from w w w . j a va 2 s.c o m String results = ""; List<GraphUser> selection = fragment.getSelection(); if (selection != null && selection.size() > 0) { ArrayList<String> names = new ArrayList<String>(); for (GraphUser user : selection) { names.add(user.getName()); } results = TextUtils.join(", ", names); } else { results = getString(R.string.no_friends_selected); } showAlert(getString(R.string.you_picked), results); }
From source file:com.example.minigameapp.NewLogin.java
private void onFriendPickerDone(FriendPickerFragment fragment) { FragmentManager fm = getSupportFragmentManager(); fm.popBackStack();/*from ww w. ja va 2 s .c om*/ String results = ""; Collection<GraphUser> selection = fragment.getSelection(); if (selection != null && selection.size() > 0) { ArrayList<String> names = new ArrayList<String>(); for (GraphUser user : selection) { names.add(user.getName()); } results = TextUtils.join(", ", names); } else { results = "no friends"; } showAlert("rar", results); }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.service.MbtoolTask.java
private boolean performRomInstallation(RomInstallerParams params, MbtoolInterface iface) throws IOException, MbtoolCommandException, MbtoolException { printSeparator();//from w w w .java 2s .co m printBoldText(Color.MAGENTA, "Processing action: Flash file\n"); printBoldText(Color.MAGENTA, "- File URI: " + params.getUri() + "\n"); printBoldText(Color.MAGENTA, "- File name: " + params.getDisplayName() + "\n"); printBoldText(Color.MAGENTA, "- Destination: " + params.getRomId() + "\n"); // Extract mbtool from the zip file File zipInstaller = new File(getContext().getCacheDir() + File.separator + "rom-installer"); File zipInstallerSig = new File(getContext().getCacheDir() + File.separator + "rom-installer.sig"); try { // An attacker can't exploit this by creating an undeletable malicious file because // mbtool will not execute an untrusted binary try { deleteWithPrejudice(zipInstaller.getAbsolutePath(), iface); deleteWithPrejudice(zipInstallerSig.getAbsolutePath(), iface); } catch (MbtoolCommandException e) { if (e.getErrno() != Constants.ENOENT) { throw e; } } if (DEBUG_USE_ALTERNATE_MBTOOL) { printBoldText(Color.YELLOW, "[DEBUG] Copying alternate mbtool binary: " + ALTERNATE_MBTOOL_PATH + "\n"); try { org.apache.commons.io.FileUtils.copyFile(new File(ALTERNATE_MBTOOL_PATH), zipInstaller); } catch (IOException e) { printBoldText(Color.RED, "Failed to copy alternate mbtool binary\n"); return false; } printBoldText(Color.YELLOW, "[DEBUG] Copying alternate mbtool signature: " + ALTERNATE_MBTOOL_SIG_PATH + "\n"); try { org.apache.commons.io.FileUtils.copyFile(new File(ALTERNATE_MBTOOL_SIG_PATH), zipInstallerSig); } catch (IOException e) { printBoldText(Color.RED, "Failed to copy alternate mbtool signature\n"); return false; } } else { printBoldText(Color.YELLOW, "Extracting mbtool ROM installer from the zip file\n"); try { FileUtils.zipExtractFile(getContext(), params.getUri(), UPDATE_BINARY, zipInstaller.getPath()); } catch (IOException e) { printBoldText(Color.RED, "Failed to extract update-binary\n"); return false; } printBoldText(Color.YELLOW, "Extracting mbtool signature from the zip file\n"); try { FileUtils.zipExtractFile(getContext(), params.getUri(), UPDATE_BINARY_SIG, zipInstallerSig.getPath()); } catch (IOException e) { printBoldText(Color.RED, "Failed to extract update-binary.sig\n"); return false; } } String zipPath = getPathFromUri(params.getUri(), iface); if (zipPath == null) { return false; } ArrayList<String> argsList = new ArrayList<>(); argsList.add("--romid"); argsList.add(params.getRomId()); argsList.add(translateEmulatedPath(zipPath)); if (params.getSkipMounts()) { argsList.add("--skip-mount"); } if (params.getAllowOverwrite()) { argsList.add("--allow-overwrite"); } String[] args = argsList.toArray(new String[argsList.size()]); printBoldText(Color.YELLOW, "Running rom-installer with arguments: [" + TextUtils.join(", ", args) + "]\n"); SignedExecCompletion completion = iface.signedExec(zipInstaller.getAbsolutePath(), zipInstallerSig.getAbsolutePath(), "rom-installer", args, this); switch (completion.result) { case SignedExecResult.PROCESS_EXITED: printBoldText(completion.exitStatus == 0 ? Color.GREEN : Color.RED, "\nCommand returned: " + completion.exitStatus + "\n"); return completion.exitStatus == 0; case SignedExecResult.PROCESS_KILLED_BY_SIGNAL: printBoldText(Color.RED, "\nProcess killed by signal: " + completion.termSig + "\n"); return false; case SignedExecResult.INVALID_SIGNATURE: printBoldText(Color.RED, "\nThe mbtool binary has an invalid signature. This" + " can happen if an unofficial app was used to patch the file or if" + " the zip was maliciously modified. The file was NOT flashed.\n"); return false; case SignedExecResult.OTHER_ERROR: default: printBoldText(Color.RED, "\nError: " + completion.errorMsg + "\n"); return false; } } finally { // Clean up installer files try { deleteWithPrejudice(zipInstaller.getAbsolutePath(), iface); deleteWithPrejudice(zipInstallerSig.getAbsolutePath(), iface); } catch (Exception e) { if (e instanceof MbtoolCommandException && ((MbtoolCommandException) e).getErrno() != Constants.ENOENT) { Log.e(TAG, "Failed to clean up", e); } } } }
From source file:it.feio.android.omninotes.async.DataBackupIntentService.java
/** * Imports notes and notebooks from Springpad exported archive */*from w ww .j a va 2 s.c o m*/ * @param intent */ synchronized private void importDataFromSpringpad(Intent intent) { String backupPath = intent.getStringExtra(EXTRA_SPRINGPAD_BACKUP); Importer importer = new Importer(); try { importer.setZipProgressesListener(percentage -> mNotificationsHelper .setMessage(getString(R.string.extracted) + " " + percentage + "%").show()); importer.doImport(backupPath); // Updating notification updateImportNotification(importer); } catch (ImportException e) { new NotificationsHelper(this).createNotification(R.drawable.ic_emoticon_sad_white_24dp, getString(R.string.import_fail) + ": " + e.getMessage(), null).setLedActive().show(); return; } List<SpringpadElement> elements = importer.getSpringpadNotes(); // If nothing is retrieved it will exit if (elements == null || elements.size() == 0) { return; } // These maps are used to associate with post processing notes to categories (notebooks) HashMap<String, Category> categoriesWithUuid = new HashMap<>(); // Adds all the notebooks (categories) for (SpringpadElement springpadElement : importer.getNotebooks()) { Category cat = new Category(); cat.setName(springpadElement.getName()); cat.setColor(String.valueOf(Color.parseColor("#F9EA1B"))); DbHelper.getInstance().updateCategory(cat); categoriesWithUuid.put(springpadElement.getUuid(), cat); // Updating notification importedSpringpadNotebooks++; updateImportNotification(importer); } // And creates a default one for notes without notebook Category defaulCategory = new Category(); defaulCategory.setName("Springpad"); defaulCategory.setColor(String.valueOf(Color.parseColor("#F9EA1B"))); DbHelper.getInstance().updateCategory(defaulCategory); // And then notes are created Note note; Attachment mAttachment = null; Uri uri; for (SpringpadElement springpadElement : importer.getNotes()) { note = new Note(); // Title note.setTitle(springpadElement.getName()); // Content dependent from type of Springpad note StringBuilder content = new StringBuilder(); content.append( TextUtils.isEmpty(springpadElement.getText()) ? "" : Html.fromHtml(springpadElement.getText())); content.append( TextUtils.isEmpty(springpadElement.getDescription()) ? "" : springpadElement.getDescription()); // Some notes could have been exported wrongly if (springpadElement.getType() == null) { Toast.makeText(this, getString(R.string.error), Toast.LENGTH_SHORT).show(); continue; } if (springpadElement.getType().equals(SpringpadElement.TYPE_VIDEO)) { try { content.append(System.getProperty("line.separator")) .append(springpadElement.getVideos().get(0)); } catch (IndexOutOfBoundsException e) { content.append(System.getProperty("line.separator")).append(springpadElement.getUrl()); } } if (springpadElement.getType().equals(SpringpadElement.TYPE_TVSHOW)) { content.append(System.getProperty("line.separator")) .append(TextUtils.join(", ", springpadElement.getCast())); } if (springpadElement.getType().equals(SpringpadElement.TYPE_BOOK)) { content.append(System.getProperty("line.separator")).append("Author: ") .append(springpadElement.getAuthor()).append(System.getProperty("line.separator")) .append("Publication date: ").append(springpadElement.getPublicationDate()); } if (springpadElement.getType().equals(SpringpadElement.TYPE_RECIPE)) { content.append(System.getProperty("line.separator")).append("Ingredients: ") .append(springpadElement.getIngredients()).append(System.getProperty("line.separator")) .append("Directions: ").append(springpadElement.getDirections()); } if (springpadElement.getType().equals(SpringpadElement.TYPE_BOOKMARK)) { content.append(System.getProperty("line.separator")).append(springpadElement.getUrl()); } if (springpadElement.getType().equals(SpringpadElement.TYPE_BUSINESS) && springpadElement.getPhoneNumbers() != null) { content.append(System.getProperty("line.separator")).append("Phone number: ") .append(springpadElement.getPhoneNumbers().getPhone()); } if (springpadElement.getType().equals(SpringpadElement.TYPE_PRODUCT)) { content.append(System.getProperty("line.separator")).append("Category: ") .append(springpadElement.getCategory()).append(System.getProperty("line.separator")) .append("Manufacturer: ").append(springpadElement.getManufacturer()) .append(System.getProperty("line.separator")).append("Price: ") .append(springpadElement.getPrice()); } if (springpadElement.getType().equals(SpringpadElement.TYPE_WINE)) { content.append(System.getProperty("line.separator")).append("Wine type: ") .append(springpadElement.getWine_type()).append(System.getProperty("line.separator")) .append("Varietal: ").append(springpadElement.getVarietal()) .append(System.getProperty("line.separator")).append("Price: ") .append(springpadElement.getPrice()); } if (springpadElement.getType().equals(SpringpadElement.TYPE_ALBUM)) { content.append(System.getProperty("line.separator")).append("Artist: ") .append(springpadElement.getArtist()); } for (SpringpadComment springpadComment : springpadElement.getComments()) { content.append(System.getProperty("line.separator")).append(springpadComment.getCommenter()) .append(" commented at 0").append(springpadComment.getDate()).append(": ") .append(springpadElement.getArtist()); } note.setContent(content.toString()); // Checklists if (springpadElement.getType().equals(SpringpadElement.TYPE_CHECKLIST)) { StringBuilder sb = new StringBuilder(); String checkmark; for (SpringpadItem mSpringpadItem : springpadElement.getItems()) { checkmark = mSpringpadItem.getComplete() ? it.feio.android.checklistview.interfaces.Constants.CHECKED_SYM : it.feio.android.checklistview.interfaces.Constants.UNCHECKED_SYM; sb.append(checkmark).append(mSpringpadItem.getName()) .append(System.getProperty("line.separator")); } note.setContent(sb.toString()); note.setChecklist(true); } // Tags String tags = springpadElement.getTags().size() > 0 ? "#" + TextUtils.join(" #", springpadElement.getTags()) : ""; if (note.isChecklist()) { note.setTitle(note.getTitle() + tags); } else { note.setContent(note.getContent() + System.getProperty("line.separator") + tags); } // Address String address = springpadElement.getAddresses() != null ? springpadElement.getAddresses().getAddress() : ""; if (!TextUtils.isEmpty(address)) { try { double[] coords = GeocodeHelper.getCoordinatesFromAddress(this, address); note.setLatitude(coords[0]); note.setLongitude(coords[1]); } catch (IOException e) { Log.e(Constants.TAG, "An error occurred trying to resolve address to coords during Springpad import"); } note.setAddress(address); } // Reminder if (springpadElement.getDate() != null) { note.setAlarm(springpadElement.getDate().getTime()); } // Creation, modification, category note.setCreation(springpadElement.getCreated().getTime()); note.setLastModification(springpadElement.getModified().getTime()); // Image String image = springpadElement.getImage(); if (!TextUtils.isEmpty(image)) { try { File file = StorageHelper.createNewAttachmentFileFromHttp(this, image); uri = Uri.fromFile(file); String mimeType = StorageHelper.getMimeType(uri.getPath()); mAttachment = new Attachment(uri, mimeType); } catch (MalformedURLException e) { uri = Uri.parse(importer.getWorkingPath() + image); mAttachment = StorageHelper.createAttachmentFromUri(this, uri, true); } catch (IOException e) { Log.e(Constants.TAG, "Error retrieving Springpad online image"); } if (mAttachment != null) { note.addAttachment(mAttachment); } mAttachment = null; } // Other attachments for (SpringpadAttachment springpadAttachment : springpadElement.getAttachments()) { // The attachment could be the image itself so it's jumped if (image != null && image.equals(springpadAttachment.getUrl())) continue; if (TextUtils.isEmpty(springpadAttachment.getUrl())) { continue; } // Tries first with online images try { File file = StorageHelper.createNewAttachmentFileFromHttp(this, springpadAttachment.getUrl()); uri = Uri.fromFile(file); String mimeType = StorageHelper.getMimeType(uri.getPath()); mAttachment = new Attachment(uri, mimeType); } catch (MalformedURLException e) { uri = Uri.parse(importer.getWorkingPath() + springpadAttachment.getUrl()); mAttachment = StorageHelper.createAttachmentFromUri(this, uri, true); } catch (IOException e) { Log.e(Constants.TAG, "Error retrieving Springpad online image"); } if (mAttachment != null) { note.addAttachment(mAttachment); } mAttachment = null; } // If the note has a category is added to the map to be post-processed if (springpadElement.getNotebooks().size() > 0) { note.setCategory(categoriesWithUuid.get(springpadElement.getNotebooks().get(0))); } else { note.setCategory(defaulCategory); } // The note is saved DbHelper.getInstance().updateNote(note, false); ReminderHelper.addReminder(OmniNotes.getAppContext(), note); // Updating notification importedSpringpadNotes++; updateImportNotification(importer); } // Delete temp data try { importer.clean(); } catch (IOException e) { Log.w(Constants.TAG, "Springpad import temp files not deleted"); } String title = getString(R.string.data_import_completed); String text = getString(R.string.click_to_refresh_application); createNotification(intent, this, title, text, null); }
From source file:io.github.hidroh.materialistic.FavoriteFragment.java
private String makeEmailContent(ArrayList<Favorite> favorites) { return TextUtils.join("\n\n", favorites); }
From source file:org.alfresco.mobile.android.api.services.impl.onpremise.OnPremiseWorkflowServiceImpl.java
/** {@inheritDoc} */ public Process startProcess(ProcessDefinition processDefinition, List<Person> assignees, Map<String, Serializable> variables, List<Document> items) { if (isObjectNull(processDefinition)) { throw new IllegalArgumentException(String.format( Messagesl18n.getString("ErrorCodeRegistry.GENERAL_INVALID_ARG_NULL"), "processDefinition")); }// w ww. j a v a 2 s. com Process process = null; try { String link = OnPremiseUrlRegistry.getFormProcessUrl(session, processDefinition.getKey()); UrlBuilder url = new UrlBuilder(link); // prepare json data JSONObject jo = new JSONObject(); // ASSIGNEES // We need to retrieve the noderef associated to the person if (assignees != null && !assignees.isEmpty()) { if (assignees.size() == 1 && WorkflowModel.FAMILY_PROCESS_ADHOC.contains(processDefinition.getKey()) || WorkflowModel.FAMILY_PROCESS_REVIEW.contains(processDefinition.getKey())) { jo.put(OnPremiseConstant.ASSOC_BPM_ASSIGNEE_ADDED_VALUE, getPersonGUID(assignees.get(0))); } else if (WorkflowModel.FAMILY_PROCESS_PARALLEL_REVIEW.contains(processDefinition.getKey())) { List<String> guids = new ArrayList<String>(assignees.size()); for (Person p : assignees) { guids.add(getPersonGUID(p)); } jo.put(OnPremiseConstant.ASSOC_BPM_ASSIGNEES_ADDED_VALUE, TextUtils.join(",", guids)); } } // VARIABLES if (variables != null && !variables.isEmpty()) { for (Entry<String, Serializable> entry : variables.entrySet()) { if (ALFRESCO_TO_WORKFLOW.containsKey(entry.getKey())) { jo.put(ALFRESCO_TO_WORKFLOW.get(entry.getKey()), entry.getValue()); } else { jo.put(entry.getKey(), entry.getValue()); } } } // ITEMS if (items != null && !items.isEmpty()) { List<String> variablesItems = new ArrayList<String>(items.size()); for (Node node : items) { variablesItems.add(NodeRefUtils.getCleanIdentifier(node.getIdentifier())); } jo.put(OnPremiseConstant.ASSOC_PACKAGEITEMS_ADDED_VALUE, TextUtils.join(",", variablesItems.toArray(new String[0]))); } final JsonDataWriter dataWriter = new JsonDataWriter(jo); // send Response resp = post(url, dataWriter.getContentType(), new Output() { public void write(OutputStream out) throws IOException { dataWriter.write(out); } }, ErrorCodeRegistry.WORKFLOW_GENERIC); Map<String, Object> json = JsonUtils.parseObject(resp.getStream(), resp.getCharset()); String data = JSONConverter.getString(json, OnPremiseConstant.PERSISTEDOBJECT_VALUE); // WorkflowInstance[id=activiti$18328,active=true,def=WorkflowDefinition[ String processId = data.split("\\[")[1].split(",")[0].split("=")[1]; process = getProcess(processId); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); convertException(e); } return process; }
From source file:com.codyy.rx.permissions.RxPermissions.java
@TargetApi(Build.VERSION_CODES.M) void requestPermissionsFromFragment(String[] permissions) { mRxPermissionsFragment.log("requestPermissionsFromFragment " + TextUtils.join(", ", permissions)); mRxPermissionsFragment.requestPermissions(permissions); }
From source file:com.shopify.buy.dataprovider.BuyClient.java
/** * Fetch a list of Products/*from ww w .j ava2s . com*/ * * @param productIds a List of the productIds to fetch * @param callback the {@link Callback} that will be used to indicate the response from the asynchronous network operation, not null */ public void getProducts(List<String> productIds, final Callback<List<Product>> callback) { if (productIds == null) { throw new NullPointerException("productIds List cannot be null"); } if (productIds.size() < 1) { throw new IllegalArgumentException("productIds List cannot be empty"); } String queryString = TextUtils.join(",", productIds.toArray()); // All product responses from the server are wrapped in a ProductPublication object // The same endpoint is used for single and multiple product queries. // For this call we will query with multiple ids. // The returned product array will contain products for each id found. // If no ids were found, the array will be empty retrofitService.getProducts(channelId, queryString, new Callback<ProductPublication>() { @Override public void success(ProductPublication productPublications, Response response) { List<Product> products = null; if (productPublications != null) { products = productPublications.getProducts(); } callback.success(products, response); } @Override public void failure(RetrofitError error) { callback.failure(error); } }); }
From source file:com.ichi2.libanki.Tags.java
/** Join tags into a single string, with leading and trailing spaces. */ public String join(java.util.Collection<String> tags) { if (tags == null || tags.size() == 0) { return ""; } else {/* ww w . ja v a 2 s . c o m*/ String joined = TextUtils.join(" ", tags); return String.format(Locale.US, " %s ", joined); } }
From source file:org.proninyaroslav.libretorrent.core.storage.TorrentStorage.java
@NonNull private String integerListToString(Collection<Integer> indexes) { return TextUtils.join(Model.FILE_LIST_SEPARATOR, indexes); }