List of usage examples for java.util.regex Matcher reset
public Matcher reset()
From source file:org.sakaiproject.component.impl.BasicConfigurationService.java
/** * This will search for any values in the string which need to be replaced * with actual values from the current known set of properties which are * available to the config service/*from w ww . jav a 2 s . com*/ * * @param value any string (might have a reference like: "thing-${suffix}") * @return the value with all matched ${vars} replaced (unmatched ones are left as is), only returns null if the input is null */ protected String dereferenceValue(String value) { if (M_log.isDebugEnabled()) M_log.debug("dereferenceValue(" + value + ")"); /* * NOTE: if the performance of this becomes an issue then the right way to handle it is * to place a flag on the ConfigItem to indicate if there is replaceable refs in it * (probably when this runs the first time) and if there are none then skip this * until the value is changed and then reset the flag so it will be checked again, * if there are still issues then adding a "lastChecked" timestamp and * a cache of the processed value to the ConfigItem which is used as long as the timestamp * has not expired (maybe 15 mins or something), with automatic expiration when the value changes */ String drValue = value; if (value != null && value.length() >= 4) { // min length of a replaceable value - "${a}" Matcher matcher = referencePattern.matcher(value); if (matcher.find()) { if (M_log.isDebugEnabled()) M_log.debug("dereferenceValue(" + value + "), found refs to replace"); matcher.reset(); StringBuilder sb = new StringBuilder(); // loop through and find the vars to replace and write out the new string int pointer = 0; while (matcher.find()) { String name = matcher.group(1); if (name != null && StringUtils.isNotBlank(name)) { // look up the value String replacementValue = null; ConfigItemImpl ci = findConfigItem(name, null); if (ci != null) { // found the config name so we will at least replace with empty string replacementValue = ""; if (ci.getValue() != null) { replacementValue = StringUtils.trimToEmpty(ci.getValue().toString()); } } sb.append(value.substring(pointer, matcher.start())); if (replacementValue == null) { replacementValue = matcher.group(); // just put the ${name} back in } else { // need to recurse in the case of nested refs replacementValue = dereferenceValue(replacementValue); } sb.append(replacementValue); pointer = matcher.end(); } } sb.append(value.substring(pointer, value.length())); // get the remainder of the value drValue = sb.toString(); } } if (M_log.isDebugEnabled()) M_log.debug("dereferenceValue(" + value + "): return=" + drValue); return drValue; }
From source file:sapience.injectors.stax.inject.StringBasedStaxStreamInjector.java
/** * Helper method, taking a XML string like <ows:Metadata xmlns:ows=\"http://ogc.org/ows\" xmlns:xlink=\"http://wrc.org/xlink\" * xlink:href=\"http://dude.com\"></ows:Metadata> from the reference * and checks if /*from w w w.j a v a 2 s. com*/ * a the used prefixes match the globally used ones and * b) any of the declared namespaces are redundant * * The same is true for the XPath definition * * @param resultingXMLString * @param context */ private void processNamespace(StringBuilder sb, NamespaceContext global, LocalNamespaceContext local) { Matcher prefixMatcher = prefixPattern.matcher(sb); Matcher nsMatcher = nsPattern.matcher(sb); String prefix; String uri; /* process the local namespaces */ while (nsMatcher.find()) { int start = nsMatcher.start(); int end = nsMatcher.end(); StringBuilder sbu = new StringBuilder(sb.substring(start, end)); String thisPrefix = sbu.substring(sbu.indexOf(":") + 1, sbu.lastIndexOf("=")); String thisUri = sbu.substring(sbu.indexOf("\"") + 1, sbu.lastIndexOf("\"")); // add to local namespace context local.put(thisPrefix, thisUri); if ((prefix = global.getPrefix(thisUri)) != null) { // namespace is registered, let's remove it sb.delete(start - 1, end); // we have to reset, since we changed the state of the matched string with the deletion nsMatcher.reset(); } } /* change the prefixes */ try { while (prefixMatcher.find()) { int start = prefixMatcher.start(); int end = prefixMatcher.end(); String localprefix = sb.substring(start + 1, end - 1); if ((global.getNamespaceURI(localprefix) == null) && (uri = local.getNamespaceURI(localprefix)) != null) { // get the other prefix prefix = global.getPrefix(uri); if ((prefix != null) && (!(localprefix.contentEquals(prefix)))) { sb.replace(start + 1, end - 1, prefix); prefixMatcher.reset(); } } } } catch (StringIndexOutOfBoundsException e) { // we do nothing here } }
From source file:org.catnut.ui.ComposeTweetActivity.java
private void shorten() { String text = mText.getText().toString(); final Matcher matcher = TweetTextView.WEB_URL.matcher(text); String urls = ""; while (matcher.find()) { urls += matcher.group() + ""; // ? }//from w w w. j a va2 s .co m // http request if (!TextUtils.isEmpty(urls)) { final ProgressDialog dialog = ProgressDialog.show(this, null, getString(R.string.converting), true, false); CatnutAPI api = StuffAPI.shorten(urls.split("")); mApp.getRequestQueue() .add(new JsonObjectRequest(api.method, api.uri, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { matcher.reset(); // ? JSONArray _urls = response.optJSONArray("urls"); StringBuffer sb = new StringBuffer(); int i = 0; try { while (matcher.find()) { matcher.appendReplacement(sb, _urls.optJSONObject(i).optString("url_short")); i++; } matcher.appendTail(sb); mText.setText(sb); mText.setSelection(mText.length()); } catch (Exception ex) { Log.e(TAG, "replace shorten url error!", ex); } dialog.dismiss(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { dialog.dismiss(); WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error); Toast.makeText(ComposeTweetActivity.this, weiboAPIError.error, Toast.LENGTH_SHORT) .show(); } })); } else { Toast.makeText(this, getString(R.string.no_links_hint), Toast.LENGTH_SHORT).show(); } }
From source file:org.codemine.jchatter.JChat.java
/** * Colored text using & to format color and style for this message part. * * @param text the text that will be used for the text message. * @return the {@link org.codemine.jchatter.JChat} instance of itself to allow chaining of methods */// ww w.j a va 2 s . c om public JChat coloredText(String text) { JChatPart latest = latest(); if (latest.hasText()) { throw new IllegalStateException("text for this message part is already set"); } if (!(text.contains("&"))) { throw new IllegalStateException( "this message text does not contain any color code use alternative method text instead"); } int max = text.length(); //First calculate the number of regions the input has Matcher matcher = pattern.matcher(text); int regionFound = 0; while (matcher.find()) { if (max == matcher.end()) { //Check the input does not end with a color or style code if it does throw an error throw new IllegalArgumentException( "Can not have color codes at the end of the text please remove them and run again"); } regionFound++; } matcher.reset(); // System.out.println("For the text " + text + " it has found " + regionFound + " regions"); String remaining = text; int lastEnd = 0; while (matcher.find()) { //Start parsing input that only has a region if (regionFound == 1) { //if the regions found is 1 this means the region MUST start at the start of the input //if it doesn't throw an error if (matcher.start() != 0) { throw new IllegalArgumentException("The text line must start with a color or style code"); } ChatColor color = ChatColor.WHITE; List<ChatColor> style = new ArrayList<>(); String codeMatches = matcher.group().replaceAll("&", ""); // System.out.println(codeMatches); for (int i = 0; i < codeMatches.length(); i++) { char theCode = codeMatches.charAt(i); if (ChatColor.getByChar(theCode).isColor()) { color = ChatColor.getByChar(theCode); } else if (ChatColor.getByChar(theCode).isFormat()) { style.add(ChatColor.getByChar(theCode)); } } latest().text = transAndStrip(text); latest().color = color; if (style.size() > 0) latest().styles.addAll(style); _dirty = true; } //Parse input that has multiple regions else { // System.out.println("Multi regions still to do"); String message = ""; remaining = text.substring(matcher.end(), max); Matcher subMatcher = pattern.matcher(remaining); if (subMatcher.find()) { // System.out.println("End is " + matcher.end()); // System.out.println("Sub start is " + subMatcher.start()); remaining = remaining.substring(0, subMatcher.start()); message = transAndStrip(remaining); } else { message = transAndStrip(remaining); } ChatColor color = ChatColor.WHITE; List<ChatColor> style = new ArrayList<>(); String codeMatches = matcher.group().replaceAll("&", ""); // System.out.println(codeMatches); for (int i2 = 0; i2 < codeMatches.length(); i2++) { char theCode = codeMatches.charAt(i2); if (ChatColor.getByChar(theCode).isColor()) { color = ChatColor.getByChar(theCode); } else if (ChatColor.getByChar(theCode).isFormat()) { style.add(ChatColor.getByChar(theCode)); } } if (latest().hasText()) then(); latest().text = message; latest().color = color; if (style.size() > 0) latest().styles.addAll(style); _dirty = true; } } //Global end return instance of itself return this; }
From source file:meff.Function.java
private Map<String, String> compile() { class Compiler { private Map<String, StringBuilder> functions; private String currentFunctionName; private StringBuilder currentFunction; Compiler(String functionName) { functions = new HashMap<>(); currentFunctionName = functionName; currentFunction = new StringBuilder(); functions.put(currentFunctionName, currentFunction); }// ww w . ja v a 2 s. c om void compileLine(StringBuilder line) { // Manage score value features { Matcher m = Pattern.compile("(score_\\w+)(>=|>|<=|<|==)(-?\\d+)").matcher(line); while (m.find()) { int offset = m.start(); String beginning = m.group(1); String operator = m.group(2); String end = m.group(3); StringBuilder newScore = new StringBuilder(); switch (operator) { case ">=": newScore.append(beginning).append("_min=").append(end); break; case ">": newScore.append(beginning).append("_min=").append(Integer.parseInt(end) + 1); break; case "<=": newScore.append(beginning).append("=").append(end); break; case "<": newScore.append(beginning).append("=").append(Integer.parseInt(end) - 1); break; case "==": newScore.append(beginning).append("_min=").append(end).append(",").append(beginning) .append("=").append(end); break; } line.replace(offset, offset + m.group().length(), newScore.toString()); m.reset(); // Need to reset the matcher, so it updates the length of the text } } currentFunction.append(line).append("\n"); } Map<String, String> getOutput() { Map<String, String> outputMap = new HashMap<>(functions.size()); for (Map.Entry<String, StringBuilder> entry : functions.entrySet()) { outputMap.put(entry.getKey() + ".mcfunction", entry.getValue().toString()); } return outputMap; } } Compiler compiler = new Compiler(getName()); boolean comment = false; StringBuilder sb = new StringBuilder(); for (String line : data.lines) { line = line.trim(); if (line.startsWith("#") || line.startsWith("//")) { continue; } if (line.isEmpty()) { continue; } int si = 0; // start index int bci = -1; // block comment index int bcei = -1; // block comment end index int prevBci = -1; int prevBcei = -1; while ((!comment && (bci = line.indexOf("/*", si)) > -1) || (comment && (bcei = line.indexOf("*/", si)) > -1)) { if (comment) { if (line.charAt(bcei - 1) == '\\') { si = bcei + 2; bcei = prevBcei; continue; } comment = false; si = bcei + 2; } else { if (line.charAt(bci - 1) == '\\') { sb.append(line.substring(si, bci - 1)).append("/*"); si = bci + 2; bci = prevBci; continue; } sb.append(line.substring(si, bci)); comment = true; si = bci + 2; } prevBci = bci; prevBcei = bcei; } if (comment) { continue; } if (line.endsWith("\\")) { line = line.substring(si, line.length() - 1); sb.append(line); } else { sb.append(line.substring(si)); compiler.compileLine(sb); sb.delete(0, sb.length()); } } return compiler.getOutput(); }
From source file:project.combiner.P2ProfileGenerator.java
private static void addUnitProvides(ArrayList<String> lines, String id, String version, Map<String, String> props, HashMap<String, String> manifest, Map<String, String> p2Inf) { String exportPackage = manifest.get("Export-Package"); if (exportPackage == null) { exportPackage = ""; }//from www . j a va2 s.c om int size = 3; if (props.notEmpty()) { size++; } String fragment = null; if (manifest.get("Fragment-Host") != null) { Matcher matcher = EXPORTED_PACKAGE_PATTERN.matcher(manifest.get("Fragment-Host")); if (matcher.find()) { size++; String name = matcher.group(1); fragment = " <provided namespace='osgi.fragment' name='" + name + "' version='" + version + "'/>"; } } Matcher matcher = EXPORTED_PACKAGE_PATTERN.matcher(exportPackage); while (matcher.find()) { size++; } matcher.reset(); for (int i = 0;; i++) { if (p2Inf.containsKey("provides." + i + ".name") == false) { break; } size++; } providesOpen(lines, size); lines.add(String.format(" <provided namespace='org.eclipse.equinox.p2.iu' name='%s' version='%s'/>", id, version)); for (int i = 0;; i++) { String p2InfName = p2Inf.get("provides." + i + ".name"); if (p2InfName == null) { break; } String p2InfNamespace = p2Inf.getOrDefault("provides." + i + ".namespace", "org.eclipse.equinox.p2.iu"); String p2InfVersion = p2Inf.getOrDefault("provides." + i + ".version", "0.0.0"); lines.add(String.format(" <provided namespace='%s' name='%s' version='%s'/>", p2InfNamespace, p2InfName, p2InfVersion.replace("$version$", version))); } lines.add(String.format(" <provided namespace='osgi.bundle' name='%s' version='%s'/>", id, version)); while (matcher.find()) { String group = matcher.group(); String name = matcher.group(1); String ver = findVersion(group); lines.add(String.format(" <provided namespace='java.package' name='%s' version='%s'/>", name, ver)); } lines.add( " <provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>"); if (fragment != null) { lines.add(fragment); } if (MAVEN_PROPERTIES.containsAll(props.keySet()) == false) { lines.add( " <provided namespace='org.eclipse.equinox.p2.localization' name='df_LT' version='1.0.0'/>"); } providesClose(lines); }
From source file:org.silverpeas.tools.dbBuilder.wysiwyg.adjustment.DataWiring.java
/** * Retrieve from a line the component id. * @param line/*w ww. jav a 2 s.c o m*/ * @return */ public String getComponentIdFromLine(String line) { Matcher componentMatcher = REGEXP_COMPONENT_ID.matcher(line); Matcher simpleDocIdMatcher = REGEXP_SIMPLEDOC_ID.matcher(line); Matcher wysiwygBasenameMatcher = REGEXP_WYSIWYG_BASENAME.matcher(line); for (String componentId : components) { while (componentMatcher.find()) { String extractedComponentId = componentMatcher.group(1); if (extractedComponentId.equals(componentId)) { return componentId; } } Set<String> simpleDocIds = componentSimpledocs.get(componentId); if (simpleDocIds != null) { while (simpleDocIdMatcher.find()) { String extractedSimpleDocId = simpleDocIdMatcher.group(1); for (String simpleDocId : simpleDocIds) { if (extractedSimpleDocId.equals(simpleDocId)) { return componentId; } } } } // Set<String> wysiwygBasenames = componentWysiwygBasenames.get(componentId); // if (wysiwygBasenames != null) { // while (wysiwygBasenameMatcher.find()) { // String extractedWysiwygBasename = wysiwygBasenameMatcher.group(1); // for (String wysiwygBasename : wysiwygBasenames) { // if (extractedWysiwygBasename.equals(wysiwygBasename)) { // return componentId; // } // } // } // } componentMatcher.reset(); simpleDocIdMatcher.reset(); wysiwygBasenameMatcher.reset(); } return null; }
From source file:com.piusvelte.sonet.core.SonetComments.java
@Override protected void onListItemClick(ListView list, View view, final int position, long id) { super.onListItemClick(list, view, position, id); final String sid = mComments.get(position).get(Statuses.SID); final String liked = mComments.get(position).get(getString(R.string.like)); // wait for previous attempts to finish if ((liked.length() > 0) && !liked.equals(getString(R.string.loading))) { // parse comment body, as in StatusDialog.java Matcher m = Sonet.getLinksMatcher(mComments.get(position).get(Statuses.MESSAGE)); int count = 0; while (m.find()) { count++;//from w w w. j av a 2 s .c o m } // like comments, the first comment is the post itself switch (mService) { case TWITTER: // retweet items = new String[count + 1]; items[0] = getString(R.string.retweet); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET, mToken, mSecret); HttpPost httpPost = new HttpPost( String.format(TWITTER_RETWEET, TWITTER_BASE_URL, sid)); // resolve Error 417 Expectation by Twitter httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpPost)); } @Override protected void onPostExecute(String response) { setCommentStatus(0, getString(R.string.retweet)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString( response != null ? R.string.success : R.string.failure), Toast.LENGTH_LONG)).show(); } }; setCommentStatus(0, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case FACEBOOK: items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { if (liked.equals(getString(R.string.like))) { return SonetHttpClient.httpResponse(mHttpClient, new HttpPost(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, sid, Saccess_token, mToken))); } else { HttpDelete httpDelete = new HttpDelete(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, sid, Saccess_token, mToken)); httpDelete.setHeader("Content-Length", "0"); return SonetHttpClient.httpResponse(mHttpClient, httpDelete); } } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case LINKEDIN: if (position == 0) { items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, mToken, mSecret); HttpPut httpPut = new HttpPut( String.format(LINKEDIN_IS_LIKED, LINKEDIN_BASE_URL, mSid)); httpPut.addHeader( new BasicHeader("Content-Type", "application/xml")); try { httpPut.setEntity(new StringEntity( String.format(LINKEDIN_LIKE_BODY, Boolean.toString( liked.equals(getString(R.string.like)))))); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpPut)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } return null; } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } else { // no like option here items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } break; case IDENTICA: // retweet items = new String[count + 1]; items[0] = getString(R.string.repeat); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(IDENTICA_KEY, IDENTICA_SECRET, mToken, mSecret); HttpPost httpPost = new HttpPost( String.format(IDENTICA_RETWEET, IDENTICA_BASE_URL, sid)); // resolve Error 417 Expectation by Twitter httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpPost)); } @Override protected void onPostExecute(String response) { setCommentStatus(0, getString(R.string.repeat)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString( response != null ? R.string.success : R.string.failure), Toast.LENGTH_LONG)).show(); } }; setCommentStatus(0, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case GOOGLEPLUS: //TODO: // plus1 items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case CHATTER: if (position == 0) { items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { HttpUriRequest httpRequest; if (liked.equals(getString(R.string.like))) { httpRequest = new HttpPost(String.format(CHATTER_URL_LIKES, mChatterInstance, mSid)); } else { httpRequest = new HttpDelete(String.format(CHATTER_URL_LIKE, mChatterInstance, mChatterLikeId)); } httpRequest.setHeader("Authorization", "OAuth " + mChatterToken); return SonetHttpClient.httpResponse(mHttpClient, httpRequest); } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } else { // no like option here items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } break; } } }
From source file:com.piusvelte.sonet.SonetComments.java
@Override protected void onListItemClick(ListView list, View view, final int position, long id) { super.onListItemClick(list, view, position, id); final String sid = mComments.get(position).get(Statuses.SID); final String liked = mComments.get(position).get(getString(R.string.like)); // wait for previous attempts to finish if ((liked.length() > 0) && !liked.equals(getString(R.string.loading))) { // parse comment body, as in StatusDialog.java Matcher m = Sonet.getLinksMatcher(mComments.get(position).get(Statuses.MESSAGE)); int count = 0; while (m.find()) { count++;/*w ww.j a v a 2 s.c o m*/ } // like comments, the first comment is the post itself switch (mService) { case TWITTER: // retweet items = new String[count + 1]; items[0] = getString(R.string.retweet); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET, mToken, mSecret); HttpPost httpPost = new HttpPost( String.format(TWITTER_RETWEET, TWITTER_BASE_URL, sid)); // resolve Error 417 Expectation by Twitter httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpPost)); } @Override protected void onPostExecute(String response) { setCommentStatus(0, getString(R.string.retweet)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString( response != null ? R.string.success : R.string.failure), Toast.LENGTH_LONG)).show(); } }; setCommentStatus(0, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case FACEBOOK: items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { if (liked.equals(getString(R.string.like))) { return SonetHttpClient.httpResponse(mHttpClient, new HttpPost(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, sid, Saccess_token, mToken))); } else { HttpDelete httpDelete = new HttpDelete(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, sid, Saccess_token, mToken)); httpDelete.setHeader("Content-Length", "0"); return SonetHttpClient.httpResponse(mHttpClient, httpDelete); } } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case LINKEDIN: if (position == 0) { items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(BuildConfig.LINKEDIN_KEY, BuildConfig.LINKEDIN_SECRET, mToken, mSecret); HttpPut httpPut = new HttpPut( String.format(LINKEDIN_IS_LIKED, LINKEDIN_BASE_URL, mSid)); httpPut.addHeader( new BasicHeader("Content-Type", "application/xml")); try { httpPut.setEntity(new StringEntity( String.format(LINKEDIN_LIKE_BODY, Boolean.toString( liked.equals(getString(R.string.like)))))); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpPut)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } return null; } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } else { // no like option here items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } break; case IDENTICA: // retweet items = new String[count + 1]; items[0] = getString(R.string.repeat); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(BuildConfig.IDENTICA_KEY, BuildConfig.IDENTICA_SECRET, mToken, mSecret); HttpPost httpPost = new HttpPost( String.format(IDENTICA_RETWEET, IDENTICA_BASE_URL, sid)); // resolve Error 417 Expectation by Twitter httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest(httpPost)); } @Override protected void onPostExecute(String response) { setCommentStatus(0, getString(R.string.repeat)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString( response != null ? R.string.success : R.string.failure), Toast.LENGTH_LONG)).show(); } }; setCommentStatus(0, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case GOOGLEPLUS: //TODO: // plus1 items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case CHATTER: if (position == 0) { items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { HttpUriRequest httpRequest; if (liked.equals(getString(R.string.like))) { httpRequest = new HttpPost(String.format(CHATTER_URL_LIKES, mChatterInstance, mSid)); } else { httpRequest = new HttpDelete(String.format(CHATTER_URL_LIKE, mChatterInstance, mChatterLikeId)); } httpRequest.setHeader("Authorization", "OAuth " + mChatterToken); return SonetHttpClient.httpResponse(mHttpClient, httpRequest); } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(SonetComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } else { // no like option here items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(SonetComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } break; } } }
From source file:com.shafiq.myfeedle.core.MyfeedleComments.java
@Override protected void onListItemClick(ListView list, View view, final int position, long id) { super.onListItemClick(list, view, position, id); final String sid = mComments.get(position).get(Statuses.SID); final String liked = mComments.get(position).get(getString(R.string.like)); // wait for previous attempts to finish if ((liked.length() > 0) && !liked.equals(getString(R.string.loading))) { // parse comment body, as in StatusDialog.java Matcher m = Myfeedle.getLinksMatcher(mComments.get(position).get(Statuses.MESSAGE)); int count = 0; while (m.find()) { count++;//from www . j av a 2s . c om } // like comments, the first comment is the post itself switch (mService) { case TWITTER: // retweet items = new String[count + 1]; items[0] = getString(R.string.retweet); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET, mToken, mSecret); HttpPost httpPost = new HttpPost( String.format(TWITTER_RETWEET, TWITTER_BASE_URL, sid)); // resolve Error 417 Expectation by Twitter httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false); return MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(httpPost)); } @Override protected void onPostExecute(String response) { setCommentStatus(0, getString(R.string.retweet)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString( response != null ? R.string.success : R.string.failure), Toast.LENGTH_LONG)).show(); } }; setCommentStatus(0, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case FACEBOOK: items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { if (liked.equals(getString(R.string.like))) { return MyfeedleHttpClient.httpResponse(mHttpClient, new HttpPost(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, sid, Saccess_token, mToken))); } else { HttpDelete httpDelete = new HttpDelete(String.format(FACEBOOK_LIKES, FACEBOOK_BASE_URL, sid, Saccess_token, mToken)); httpDelete.setHeader("Content-Length", "0"); return MyfeedleHttpClient.httpResponse(mHttpClient, httpDelete); } } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case LINKEDIN: if (position == 0) { items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, mToken, mSecret); HttpPut httpPut = new HttpPut( String.format(LINKEDIN_IS_LIKED, LINKEDIN_BASE_URL, mSid)); httpPut.addHeader( new BasicHeader("Content-Type", "application/xml")); try { httpPut.setEntity(new StringEntity( String.format(LINKEDIN_LIKE_BODY, Boolean.toString( liked.equals(getString(R.string.like)))))); return MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(httpPut)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } return null; } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } else { // no like option here items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } break; case IDENTICA: // retweet items = new String[count + 1]; items[0] = getString(R.string.repeat); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET, mToken, mSecret); HttpPost httpPost = new HttpPost( String.format(IDENTICA_RETWEET, IDENTICA_BASE_URL, sid)); // resolve Error 417 Expectation by Twitter httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false); return MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(httpPost)); } @Override protected void onPostExecute(String response) { setCommentStatus(0, getString(R.string.repeat)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString( response != null ? R.string.success : R.string.failure), Toast.LENGTH_LONG)).show(); } }; setCommentStatus(0, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case GOOGLEPLUS: //TODO: // plus1 items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)).setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); break; case CHATTER: if (position == 0) { items = new String[count + 1]; items[0] = getString( mComments.get(position).get(getString(R.string.like)) == getString(R.string.like) ? R.string.like : R.string.unlike); count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { HttpUriRequest httpRequest; if (liked.equals(getString(R.string.like))) { httpRequest = new HttpPost(String.format(CHATTER_URL_LIKES, mChatterInstance, mSid)); } else { httpRequest = new HttpDelete(String.format(CHATTER_URL_LIKE, mChatterInstance, mChatterLikeId)); } httpRequest.setHeader("Authorization", "OAuth " + mChatterToken); return MyfeedleHttpClient.httpResponse(mHttpClient, httpRequest); } @Override protected void onPostExecute(String response) { if (response != null) { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.unlike : R.string.like)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString(R.string.success), Toast.LENGTH_LONG)).show(); } else { setCommentStatus(position, getString(liked.equals(getString(R.string.like)) ? R.string.like : R.string.unlike)); (Toast.makeText(MyfeedleComments.this, mServiceName + " " + getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; setCommentStatus(position, getString(R.string.loading)); asyncTask.execute(); } else { if ((which < items.length) && (items[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } else { // no like option here items = new String[count]; count = 1; m.reset(); while (m.find()) { items[count++] = m.group(); } mDialog = (new AlertDialog.Builder(this)) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if ((which < items.length) && (items[which] != null)) // open link startActivity( new Intent(Intent.ACTION_VIEW).setData(Uri.parse(items[which]))); else (Toast.makeText(MyfeedleComments.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); } }).setCancelable(true).setOnCancelListener(this).create(); mDialog.show(); } break; } } }