List of usage examples for android.net Uri toString
public abstract String toString();
From source file:com.eyekabob.VenueInfo.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.venue_info); findViewById(R.id.findLiveMusicButton).setOnClickListener(linksListener); findViewById(R.id.aboutButton).setOnClickListener(linksListener); findViewById(R.id.contactButton).setOnClickListener(linksListener); Venue thisVenue = (Venue) getIntent().getExtras().get("venue"); Map<String, String> params = new HashMap<String, String>(); params.put("venue", thisVenue.getId()); TextView nameView = (TextView) findViewById(R.id.venueNameView); nameView.setText(thisVenue.getName()); TextView infoView = (TextView) findViewById(R.id.venueInfoView); nameView.setText(thisVenue.getName()); String venueDesc = ""; // TODO: Padding instead of whitespace if (!thisVenue.getCity().equals("") && !thisVenue.getStreet().equals("")) { // TODO: I18N venueDesc += "Address:\n " + thisVenue.getStreet() + "\n " + thisVenue.getCity(); }//from w ww.j a v a 2 s . c o m infoView.setText(venueDesc); TextView websiteView = (TextView) findViewById(R.id.venueMoreInfoView); if (!"".equals((thisVenue.getUrl().toString()))) { // TODO: I18N websiteView.setText(Html.fromHtml("<a href=\"" + thisVenue.getUrl() + "\">More Information</a>")); websiteView.setMovementMethod(LinkMovementMethod.getInstance()); } Uri uri = EyekabobHelper.LastFM.getUri("venue.getEvents", params); new RequestTask().execute(uri.toString()); }
From source file:org.quizpoll.net.UrlShortenerHelper.java
@Override public HttpUriRequest createRequest() { try {/*from w ww.j a va 2s. c o m*/ Uri url = Uri.parse(URL_SHORTENER_URL).buildUpon().appendQueryParameter("key", URL_SHORTENER_API_KEY) .build(); HttpUriRequest request = new HttpPost(url.toString()); String requestString = "{\"longUrl\": \"" + (String) requestData + "\"}"; ((HttpPost) request).setEntity(new StringEntity(requestString)); request.setHeader("Content-Type", "application/json"); return request; } catch (UnsupportedEncodingException e) { return null; } }
From source file:net.peterkuterna.android.apps.devoxxsched.service.TwitterSearchService.java
@Override protected void doSync(Intent intent) throws Exception { Log.d(TAG, "Refreshing twitter results"); final Cursor c = mResolver.query(Tweets.CONTENT_URI, TweetsQuery.PROJECTION, null, null, null); String tweetId = "0"; try {/*from ww w . ja va2 s. c o m*/ if (c.moveToFirst()) { tweetId = c.getString(TweetsQuery.MAX_TWEET_ID); } } finally { c.close(); } final Uri uri = TwitterApiUriUtils.buildTwitterSearchUri("from:Devoxx OR #devoxx +exclude:retweets", tweetId); mRemoteExecutor.executeGet(uri.toString(), new TwitterSearchHandler()); }
From source file:mobisocial.musubi.objects.FileObj.java
public static Obj from(Context context, Uri dataUri) throws IOException { //TODO: is this the proper way to do it? if (dataUri == null) { throw new NullPointerException(); }/*from w ww. j a va 2 s . co m*/ ContentResolver cr = context.getContentResolver(); InputStream in = cr.openInputStream(dataUri); long length = in.available(); String ext; String mimeType; String filename; MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); if ("content".equals(dataUri.getScheme())) { ContentResolver resolver = context.getContentResolver(); mimeType = resolver.getType(dataUri); ext = mimeTypeMap.getExtensionFromMimeType(mimeType); filename = "Musubi-" + sDateFormat.format(new Date()); } else { ext = MimeTypeMap.getFileExtensionFromUrl(dataUri.toString()); mimeType = mimeTypeMap.getMimeTypeFromExtension(ext); filename = Uri.parse(dataUri.toString()).getLastPathSegment(); if (filename == null) { filename = "Musubi-" + sDateFormat.format(new Date()); } } if (mimeType == null || mimeType.isEmpty()) { throw new IOException("Unidentified mime type"); } if (ext == null || ext.isEmpty()) { ext = mimeTypeMap.getExtensionFromMimeType(mimeType); } if (!ext.isEmpty() && !filename.endsWith(ext)) { filename = filename + "." + ext; } if (mimeType.startsWith("video/")) { return VideoObj.from(context, dataUri, mimeType); } else if (mimeType.startsWith("image/")) { return PictureObj.from(context, dataUri, true); } if (length > EMBED_SIZE_LIMIT) { if (length > CORRAL_SIZE_LIMIT) { throw new IOException("file too large for push"); } else { return fromCorral(context, mimeType, filename, length, dataUri); } } else { in = cr.openInputStream(dataUri); return from(mimeType, filename, length, IOUtils.toByteArray(in)); } }
From source file:com.eincs.athens.android.OlympusWriteActivity.java
public void onClick(View v) { if (v.getId() == R.id.btn_write_submit) { final String content = mContent.getText().toString(); final HttpClient httpClient = new DefaultHttpClient(); new DefaultAsyncTask<JSONObject>(ProgressDialogs.createDialog(this)) { @Override//from ww w . j a va2 s .c o m protected JSONObject doInBackground(Object... params) { Uri uri = Uri.parse(OlympusConst.SERVER_HOST + OlympusConst.PATH_WRITE); HttpPost httpPost = new HttpPost(uri.toString()); httpPost.addHeader(OlympusConst.HEADER_ACCESS_TOKEN, mPref.getAccessToken()); ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("content", content)); try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); JSONObject result = httpClient.execute(httpPost, new JSONResponseHandler()); return result; } catch (Exception e) { Log.e("Olympus", e.getMessage(), e); return null; } } protected void onPostExecute(JSONObject result) { super.onPostExecute(result); if (result == null) { Toast.makeText(mContext, "error", Toast.LENGTH_SHORT).show(); } else if (result.has("error")) { try { Toast.makeText(mContext, result.getString("error"), Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); } } else { finish(); } }; }.execute(); } else if (v.getId() == R.id.btn_write_cancel) { finish(); } }
From source file:org.blanco.techmun.android.cproviders.TechMunContentProvider.java
@Override public Uri insert(Uri uri, ContentValues values) { if (uri.toString().matches(MESA_CONTENT_COMENTARIOS_INSERT_PETITION_REG_EXP)) { boolean success = comentsFetcher.publishComentario(values); if (success) { return Uri.parse(CONTENT_BASE_URI + "/comentarios/"); } else {// w w w . j a v a 2s. c o m return Uri.EMPTY; } } else if (uri.toString().matches(MESA_CONTENT_MENSAJES_PETITION_REG_EXP)) { return Uri.parse(CONTENT_BASE_URI + "/mensajes/" + 123); } else { throw new UnsupportedOperationException( "Can't insert other elements that not " + "complain with comentarios expression"); } }
From source file:com.microsoft.services.msa.TokenRequest.java
/** * Performs the Token Request and returns the OAuth server's response. * * @return The OAuthResponse from the server * @throws LiveAuthException if there is any exception while executing the request * (e.g., IOException, JSONException) */// w w w. j a va 2 s. c o m public OAuthResponse execute() throws LiveAuthException { final Uri requestUri = mOAuthConfig.getTokenUri(); final HttpPost request = new HttpPost(requestUri.toString()); final List<NameValuePair> body = new ArrayList<NameValuePair>(); body.add(new BasicNameValuePair(OAuth.CLIENT_ID, this.clientId)); // constructBody allows subclasses to add to body this.constructBody(body); try { final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(body, HTTP.UTF_8); entity.setContentType(CONTENT_TYPE); request.setEntity(entity); } catch (UnsupportedEncodingException e) { throw new LiveAuthException(ErrorMessages.CLIENT_ERROR, e); } final HttpResponse response; try { response = this.client.execute(request); } catch (ClientProtocolException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } catch (IOException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } final HttpEntity entity = response.getEntity(); final String stringResponse; try { stringResponse = EntityUtils.toString(entity); } catch (IOException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } final JSONObject jsonResponse; try { jsonResponse = new JSONObject(stringResponse); } catch (JSONException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } if (OAuthErrorResponse.validOAuthErrorResponse(jsonResponse)) { return OAuthErrorResponse.createFromJson(jsonResponse); } else if (OAuthSuccessfulResponse.validOAuthSuccessfulResponse(jsonResponse)) { return OAuthSuccessfulResponse.createFromJson(jsonResponse); } else { throw new LiveAuthException(ErrorMessages.SERVER_ERROR); } }
From source file:com.android.email.LegacyConversions.java
/** * Add a single attachment part to the message * * This will skip adding attachments if they are already found in the attachments table. * The heuristic for this will fail (false-positive) if two identical attachments are * included in a single POP3 message./* w w w . j a va 2 s . c om*/ * TODO: Fix that, by (elsewhere) simulating an mLocation value based on the attachments * position within the list of multipart/mixed elements. This would make every POP3 attachment * unique, and might also simplify the code (since we could just look at the positions, and * ignore the filename, etc.) * * TODO: Take a closer look at encoding and deal with it if necessary. * * @param context a context for file operations * @param localMessage the attachments will be built against this message * @param part a single attachment part from POP or IMAP * @param upgrading true if upgrading a local account - handle attachments differently * @throws IOException */ private static void addOneAttachment(Context context, EmailContent.Message localMessage, Part part, boolean upgrading) throws MessagingException, IOException { Attachment localAttachment = new Attachment(); // Transfer fields from mime format to provider format String contentType = MimeUtility.unfoldAndDecode(part.getContentType()); String name = MimeUtility.getHeaderParameter(contentType, "name"); if (name == null) { String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition()); name = MimeUtility.getHeaderParameter(contentDisposition, "filename"); } // Select the URI for the new attachments. For attachments downloaded by the legacy // IMAP/POP code, this is not determined yet, so is null (it will be rewritten below, // or later, when the actual attachment file is created.) // // When upgrading older local accounts, the URI represents a local asset (e.g. a photo) // so we need to preserve the URI. // TODO This works for outgoing messages, where the URI does not change. May need // additional logic to handle the case of rewriting URI for received attachments. Uri contentUri = null; String contentUriString = null; if (upgrading) { Body body = part.getBody(); if (body instanceof LocalStore.LocalAttachmentBody) { LocalStore.LocalAttachmentBody localBody = (LocalStore.LocalAttachmentBody) body; contentUri = localBody.getContentUri(); if (contentUri != null) { contentUriString = contentUri.toString(); } } } // Find size, if available, via a number of techniques: long size = 0; if (upgrading) { // If upgrading a legacy account, the size must be recaptured from the data source if (contentUri != null) { Cursor metadataCursor = context.getContentResolver().query(contentUri, ATTACHMENT_META_COLUMNS_PROJECTION, null, null, null); if (metadataCursor != null) { try { if (metadataCursor.moveToFirst()) { size = metadataCursor.getInt(ATTACHMENT_META_COLUMNS_SIZE); } } finally { metadataCursor.close(); } } } // TODO: a downloaded legacy attachment - see if the above code works } else { // Incoming attachment: Try to pull size from disposition (if not downloaded yet) String disposition = part.getDisposition(); if (disposition != null) { String s = MimeUtility.getHeaderParameter(disposition, "size"); if (s != null) { size = Long.parseLong(s); } } } // Get partId for unloaded IMAP attachments (if any) // This is only provided (and used) when we have structure but not the actual attachment String[] partIds = part.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA); String partId = partIds != null ? partIds[0] : null; localAttachment.mFileName = name; localAttachment.mMimeType = part.getMimeType(); localAttachment.mSize = size; // May be reset below if file handled localAttachment.mContentId = part.getContentId(); localAttachment.mContentUri = contentUriString; localAttachment.mMessageKey = localMessage.mId; localAttachment.mLocation = partId; localAttachment.mEncoding = "B"; // TODO - convert other known encodings if (DEBUG_ATTACHMENTS) { Log.d(Email.LOG_TAG, "Add attachment " + localAttachment); } // To prevent duplication - do we already have a matching attachment? // The fields we'll check for equality are: // mFileName, mMimeType, mContentId, mMessageKey, mLocation // NOTE: This will false-positive if you attach the exact same file, twice, to a POP3 // message. We can live with that - you'll get one of the copies. Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId); Cursor cursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); boolean attachmentFoundInDb = false; try { while (cursor.moveToNext()) { Attachment dbAttachment = new Attachment().restore(cursor); // We test each of the fields here (instead of in SQL) because they may be // null, or may be strings. if (stringNotEqual(dbAttachment.mFileName, localAttachment.mFileName)) continue; if (stringNotEqual(dbAttachment.mMimeType, localAttachment.mMimeType)) continue; if (stringNotEqual(dbAttachment.mContentId, localAttachment.mContentId)) continue; if (stringNotEqual(dbAttachment.mLocation, localAttachment.mLocation)) continue; // We found a match, so use the existing attachment id, and stop looking/looping attachmentFoundInDb = true; localAttachment.mId = dbAttachment.mId; if (DEBUG_ATTACHMENTS) { Log.d(Email.LOG_TAG, "Skipped, found db attachment " + dbAttachment); } break; } } finally { cursor.close(); } // Save the attachment (so far) in order to obtain an id if (!attachmentFoundInDb) { localAttachment.save(context); } // If an attachment body was actually provided, we need to write the file now if (!upgrading) { saveAttachmentBody(context, part, localAttachment, localMessage.mAccountKey); } if (localMessage.mAttachments == null) { localMessage.mAttachments = new ArrayList<Attachment>(); } localMessage.mAttachments.add(localAttachment); localMessage.mFlagAttachment = true; }
From source file:com.microsoft.live.TokenRequest.java
/** * Performs the Token Request and returns the OAuth server's response. * * @return The OAuthResponse from the server * @throws LiveAuthException if there is any exception while executing the request * (e.g., IOException, JSONException) *///from w ww.ja v a 2 s . co m public OAuthResponse execute() throws LiveAuthException { final Uri requestUri = Config.INSTANCE.getOAuthTokenUri(); final HttpPost request = new HttpPost(requestUri.toString()); final List<NameValuePair> body = new ArrayList<NameValuePair>(); body.add(new BasicNameValuePair(OAuth.CLIENT_ID, this.clientId)); // constructBody allows subclasses to add to body this.constructBody(body); try { final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(body, HTTP.UTF_8); entity.setContentType(CONTENT_TYPE); request.setEntity(entity); } catch (UnsupportedEncodingException e) { throw new LiveAuthException(ErrorMessages.CLIENT_ERROR, e); } final HttpResponse response; try { response = this.client.execute(request); } catch (ClientProtocolException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } catch (IOException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } final HttpEntity entity = response.getEntity(); final String stringResponse; try { stringResponse = EntityUtils.toString(entity); } catch (IOException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } final JSONObject jsonResponse; try { jsonResponse = new JSONObject(stringResponse); } catch (JSONException e) { throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e); } if (OAuthErrorResponse.validOAuthErrorResponse(jsonResponse)) { return OAuthErrorResponse.createFromJson(jsonResponse); } else if (OAuthSuccessfulResponse.validOAuthSuccessfulResponse(jsonResponse)) { return OAuthSuccessfulResponse.createFromJson(jsonResponse); } else { throw new LiveAuthException(ErrorMessages.SERVER_ERROR); } }
From source file:com.eincs.athens.android.OlympusJoinActivity.java
public void onClick(View v) { final String email = mEditJoinEmail.getText().toString(); final String nickname = mEditJoinNickname.getText().toString(); final String tag = android.os.Build.MODEL; final HttpClient httpClient = new DefaultHttpClient(); new DefaultAsyncTask<JSONObject>(ProgressDialogs.createDialog(this)) { @Override/* w w w .ja v a 2 s .c om*/ protected JSONObject doInBackground(Object... params) { Uri uri = Uri.parse(OlympusConst.SERVER_HOST + OlympusConst.PATH_GET_ACCEESS_TOKEN); HttpPost httpPost = new HttpPost(uri.toString()); ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("email", email)); nameValuePairs.add(new BasicNameValuePair("nickname", nickname)); nameValuePairs.add(new BasicNameValuePair("tag", tag)); try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); JSONObject result = httpClient.execute(httpPost, new JSONResponseHandler()); return result; } catch (Exception e) { Log.e("Olympus", e.getMessage(), e); return null; } } protected void onPostExecute(JSONObject result) { super.onPostExecute(result); if (result == null || result.has("error")) { Toast.makeText(OlympusJoinActivity.this, "error occered", Toast.LENGTH_SHORT).show(); } else { try { String accessToken = result.getString("result"); mPref.setAccessToken(accessToken); checkAndMove(); } catch (JSONException e) { e.printStackTrace(); } } }; }.execute(); }