List of usage examples for android.net Uri getLastPathSegment
@Nullable public abstract String getLastPathSegment();
From source file:com.example.linhdq.test.documents.viewing.single.DocumentActivity.java
private boolean init(Bundle savedInstanceState) { Uri data = getIntent().getData(); if (data == null && savedInstanceState != null) { data = savedInstanceState.getParcelable(STATE_DOCUMENT_URI); }// w w w .j a va 2 s .c o m if (data == null) { return false; } String id = data.getLastPathSegment(); int parentId = getParentId(data); // Base class needs that value if (parentId == -1) { mParentId = Integer.parseInt(id); } else { mParentId = parentId; } mIsCursorLoaded = false; getSupportLoaderManager().initLoader(DOCUMENT_CURSOR_LOADER_ID, null, this); return true; }
From source file:nz.ac.otago.psyanlab.common.ImportPaleActivity.java
@Override public void onFilesPicked(File... files) { new AsyncTask<File, Void, Pair<ArrayList<String>, ArrayList<Long>>>() { @Override/*from w w w.j a v a 2s . com*/ protected Pair<ArrayList<String>, ArrayList<Long>> doInBackground(File... files) { ArrayList<Long> ids = new ArrayList<Long>(); ArrayList<String> errored = new ArrayList<String>(); for (int i = 0; i < files.length; i++) { Uri uri; try { uri = mUserDelegate.addExperiment(files[i].getPath()); } catch (JSONException e) { errored.add(files[i].getName()); e.printStackTrace(); continue; } catch (IOException e) { errored.add(files[i].getName()); e.printStackTrace(); continue; } ids.add(Long.parseLong(uri.getLastPathSegment())); } return new Pair<ArrayList<String>, ArrayList<Long>>(errored, ids); } @Override protected void onPostExecute(Pair<ArrayList<String>, ArrayList<Long>> result) { ArrayList<String> errored = result.first; ArrayList<Long> ids = result.second; if (errored.size() > 0) { toast(getResources().getString(R.string.format_error_importing, TextUtils.join(", ", errored))); } if (ids.size() > 0) { Intent r = new Intent(); long[] lids = new long[ids.size()]; for (int i = 0; i < ids.size(); i++) { lids[i] = ids.get(i); } r.putExtra(RETURN_IDS, lids); setResult(RESULT_OK, r); finish(); } }; }.execute(files); }
From source file:com.viktorrudometkin.burramys.fragment.EntryFragment.java
@Override public void onClickEnclosure() { getActivity().runOnUiThread(new Runnable() { @Override//www . j a v a 2s . c o m public void run() { final String enclosure = mEntryPagerAdapter.getCursor(mCurrentPagerPos).getString(mEnclosurePos); final int position1 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR); final int position2 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR, position1 + 3); final Uri uri = Uri.parse(enclosure.substring(0, position1)); final String filename = uri.getLastPathSegment(); new AlertDialog.Builder(getActivity()).setTitle(R.string.open_enclosure) .setMessage(getString(R.string.file) + ": " + filename) .setPositiveButton(R.string.open_link, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showEnclosure(uri, enclosure, position1, position2); } }).setNegativeButton(R.string.download_and_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DownloadManager.Request r = new DownloadManager.Request(uri); r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); r.allowScanningByMediaScanner(); r.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); DownloadManager dm = (DownloadManager) MainApplication.getContext() .getSystemService(Context.DOWNLOAD_SERVICE); dm.enqueue(r); } catch (Exception e) { UiUtils.showMessage(getActivity(), R.string.error); } } }).show(); } }); }
From source file:auribises.com.visitorbook.Activites.VisitorEntryActivity.java
void insertIntoDB() { ContentValues values = new ContentValues(); values.put(Util.COL_NAMEVISITOR, visitorentry.getName()); values.put(Util.COL_PHONEVISITOR, visitorentry.getPhone()); values.put(Util.COL_EMAILVISITOR, visitorentry.getEmail()); values.put(Util.COL_GENDERVISITOR, visitorentry.getGender()); values.put(Util.COL_ADDRESSVISITOR, visitorentry.getAddress()); values.put(Util.COL_PURPOSEVISITOR, visitorentry.getPurpose()); values.put(Util.COL_DATEVISITOR, visitorentry.getDate()); values.put(Util.COL_TIMEVISITOR, visitorentry.getTime()); values.put(Util.COL_TEACHERVISITOR, visitorentry.getTeacher()); values.put(Util.COL_BRANCHVISITOR, visitorentry.getBranch()); values.put(Util.COL_IDPROOFVISITOR, visitorentry.getIDProof()); values.put(Util.COL_IDPROOFNUBERVISITOR, visitorentry.getIDProofnumber()); values.put(Util.COL_VEHICLEVISITOR, visitorentry.getVehicle()); values.put(Util.COL_VEHICLENUMBERVISITOR, visitorentry.getVehiclenumber()); if (!updateMode) { Uri dummy = resolver.insert(Util.VISITORENTRY_URI, values); Toast.makeText(this, visitorentry.getName() + " Registered Successfully " + dummy.getLastPathSegment(), Toast.LENGTH_LONG).show(); Log.i("insertintocloud", visitorentry.toString()); clearFields();// w ww .ja va 2s . co m } else { String where = Util.COL_IDVISITOR + " = " + rcvVisitorentry.getId(); int i = resolver.update(Util.VISITORENTRY_URI, values, where, null); if (i > 0) { Toast.makeText(this, "Updation Successful", Toast.LENGTH_LONG).show(); finish(); } } }
From source file:com.example.office.ui.mail.MailItemFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case MailItemActivity.CAMERA_REQUEST_CODE: if (resultCode == Activity.RESULT_OK) { try { String currentPhotoPath = ((MailItemActivity) getActivity()).getCurrentPhotoPath(); Bitmap bmp = BitmapFactory.decodeFile(currentPhotoPath); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 100, stream); MailItem mail = (MailItem) getActivity().getIntent().getExtras() .get(getString(R.string.intent_mail_key)); Utility.showToastNotification("Starting file uploading"); mId = mail.getId();/*from w w w . j av a 2 s . c o m*/ mImageBytes = stream.toByteArray(); mFilename = StringUtils.substringAfterLast(currentPhotoPath, "/"); getMessageAndAttachData(); } catch (Exception e) { Utility.showToastNotification("Error during getting image from camera"); } } break; case MailItemActivity.SELECT_PHOTO: if (resultCode == Activity.RESULT_OK) { try { Uri selectedImage = data.getData(); InputStream imageStream = getActivity().getContentResolver().openInputStream(selectedImage); MailItem mail = (MailItem) getActivity().getIntent().getExtras() .get(getString(R.string.intent_mail_key)); Utility.showToastNotification("Starting file uploading"); mId = mail.getId(); mImageBytes = IOUtils.toByteArray(imageStream); mFilename = selectedImage.getLastPathSegment(); getMessageAndAttachData(); } catch (Throwable t) { Utility.showToastNotification("Error during getting image from file"); } } break; default: super.onActivityResult(requestCode, resultCode, data); } }
From source file:com.flym.dennikn.fragment.EntryFragment.java
@Override public void onClickEnclosure() { getActivity().runOnUiThread(new Runnable() { @Override//from w ww . ja v a 2s .c o m public void run() { final String enclosure = mEntryPagerAdapter.getCursor(mCurrentPagerPos).getString(mEnclosurePos); final int position1 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR); final int position2 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR, position1 + 3); final Uri uri = Uri.parse(enclosure.substring(0, position1)); final String filename = uri.getLastPathSegment(); new AlertDialog.Builder(getActivity()).setTitle(R.string.open_enclosure) .setMessage(getString(R.string.file) + ": " + filename) .setPositiveButton(R.string.open_link, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showEnclosure(uri, enclosure, position1, position2); } }).setNegativeButton(R.string.download_and_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DownloadManager.Request r = new DownloadManager.Request(uri); r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); r.allowScanningByMediaScanner(); r.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); DownloadManager dm = (DownloadManager) MainApplication.getContext() .getSystemService(Context.DOWNLOAD_SERVICE); dm.enqueue(r); } catch (Exception e) { Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_LONG).show(); } } }).show(); } }); }
From source file:im.ene.toro.exoplayer2.ExoVideoView.java
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType( !TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null /* eventLogger */); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null /* eventLogger */); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null /* eventLogger */); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null /* eventLogger */); default: {/*from www .j a va 2 s .c o m*/ throw new IllegalStateException("Unsupported type: " + type); } } }
From source file:com.gvccracing.android.tttimer.Tabs.RaceInfoTab.java
public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://www.gvccracing.com/?page_id=2525&pass=com.gvccracing.android.tttimer"); try {/* w w w . j a v a2 s. c om*/ // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); InputStream is = response.getEntity().getContent(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(20); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert the Bytes read to a String. */ String text = new String(baf.toByteArray()); JSONObject mainJson = new JSONObject(text); JSONArray jsonArray = mainJson.getJSONArray("members"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); String firstName = json.getString("fname"); String lastName = json.getString("lname"); String licenseStr = json.getString("license"); Integer license = 0; try { license = Integer.parseInt(licenseStr); } catch (Exception ex) { Log.e(LOG_TAG(), "Unable to parse license string"); } long age = json.getLong("age"); String categoryStr = json.getString("category"); Integer category = 5; try { category = Integer.parseInt(categoryStr); } catch (Exception ex) { Log.e(LOG_TAG(), "Unable to parse category string"); } String phone = json.getString("phone"); long phoneNumber = 0; try { phoneNumber = Long.parseLong(phone.replace("-", "").replace("(", "").replace(")", "") .replace(" ", "").replace(".", "").replace("*", "")); } catch (Exception e) { Log.e(LOG_TAG(), "Unable to parse phone number"); } String gender = json.getString("gender"); String econtact = json.getString("econtact"); String econtactPhone = json.getString("econtact_phone"); long eContactPhoneNumber = 0; try { eContactPhoneNumber = Long.parseLong(econtactPhone.replace("-", "").replace("(", "") .replace(")", "").replace(" ", "").replace(".", "").replace("*", "")); } catch (Exception e) { Log.e(LOG_TAG(), "Unable to parse econtact phone number"); } Long member_id = json.getLong("member_id"); String gvccCategory; switch (category) { case 1: case 2: case 3: gvccCategory = "A"; break; case 4: gvccCategory = "B4"; break; case 5: gvccCategory = "B5"; break; default: gvccCategory = "B5"; break; } Log.w(LOG_TAG(), lastName); Cursor racerInfo = Racer.Instance().Read(getActivity(), new String[] { Racer._ID, Racer.FirstName, Racer.LastName, Racer.USACNumber, Racer.PhoneNumber, Racer.EmergencyContactName, Racer.EmergencyContactPhoneNumber }, Racer.USACNumber + "=?", new String[] { license.toString() }, null); if (racerInfo.getCount() > 0) { racerInfo.moveToFirst(); Long racerID = racerInfo.getLong(racerInfo.getColumnIndex(Racer._ID)); Racer.Instance().Update(getActivity(), racerID, firstName, lastName, license, 0l, phoneNumber, econtact, eContactPhoneNumber, gender); Cursor racerClubInfo = RacerClubInfo.Instance().Read(getActivity(), new String[] { RacerClubInfo._ID, RacerClubInfo.GVCCID, RacerClubInfo.RacerAge, RacerClubInfo.Category }, RacerClubInfo.Racer_ID + "=? AND " + RacerClubInfo.Year + "=? AND " + RacerClubInfo.Upgraded + "=?", new String[] { racerID.toString(), "2013", "0" }, null); if (racerClubInfo.getCount() > 0) { racerClubInfo.moveToFirst(); long racerClubInfoID = racerClubInfo .getLong(racerClubInfo.getColumnIndex(RacerClubInfo._ID)); String rciCategory = racerClubInfo .getString(racerClubInfo.getColumnIndex(RacerClubInfo.Category)); boolean upgraded = gvccCategory != rciCategory; if (upgraded) { RacerClubInfo.Instance().Update(getActivity(), racerClubInfoID, null, null, null, null, null, null, null, null, null, upgraded); RacerClubInfo.Instance().Create(getActivity(), racerID, null, 2013, gvccCategory, 0, 0, 0, age, member_id, false); } else { RacerClubInfo.Instance().Update(getActivity(), racerClubInfoID, null, null, null, null, null, null, null, age, member_id, upgraded); } } else { RacerClubInfo.Instance().Create(getActivity(), racerID, null, 2013, gvccCategory, 0, 0, 0, age, member_id, false); } if (racerClubInfo != null) { racerClubInfo.close(); } } else { // TODO: Better birth date Uri resultUri = Racer.Instance().Create(getActivity(), firstName, lastName, license, 0l, phoneNumber, econtact, eContactPhoneNumber, gender); long racerID = Long.parseLong(resultUri.getLastPathSegment()); RacerClubInfo.Instance().Create(getActivity(), racerID, null, 2013, gvccCategory, 0, 0, 0, age, member_id, false); } if (racerInfo != null) { racerInfo.close(); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { Log.e(LOG_TAG(), e.getMessage()); } }
From source file:com.android.nfc.beam.BeamTransferManager.java
void processFiles() { // Check the amount of files we received in this transfer; // If more than one, create a separate directory for it. String extRoot = Environment.getExternalStorageDirectory().getPath(); File beamPath = new File(extRoot + "/" + BEAM_DIR); if (!checkMediaStorage(beamPath) || mUris.size() == 0) { Log.e(TAG, "Media storage not valid or no uris received."); updateStateAndNotification(STATE_FAILED); return;/* www. j a v a 2 s .c o m*/ } if (mUris.size() > 1) { beamPath = generateMultiplePath(extRoot + "/" + BEAM_DIR + "/"); if (!beamPath.isDirectory() && !beamPath.mkdir()) { Log.e(TAG, "Failed to create multiple path " + beamPath.toString()); updateStateAndNotification(STATE_FAILED); return; } } for (int i = 0; i < mUris.size(); i++) { Uri uri = mUris.get(i); String mimeType = mTransferMimeTypes.get(i); File srcFile = new File(uri.getPath()); File dstFile = generateUniqueDestination(beamPath.getAbsolutePath(), uri.getLastPathSegment()); Log.d(TAG, "Renaming from " + srcFile); if (!srcFile.renameTo(dstFile)) { if (DBG) Log.d(TAG, "Failed to rename from " + srcFile + " to " + dstFile); srcFile.delete(); return; } else { mPaths.add(dstFile.getAbsolutePath()); mMimeTypes.put(dstFile.getAbsolutePath(), mimeType); if (DBG) Log.d(TAG, "Did successful rename from " + srcFile + " to " + dstFile); } } // We can either add files to the media provider, or provide an ACTION_VIEW // intent to the file directly. We base this decision on the mime type // of the first file; if it's media the platform can deal with, // use the media provider, if it's something else, just launch an ACTION_VIEW // on the file. String mimeType = mMimeTypes.get(mPaths.get(0)); if (mimeType.startsWith("image/") || mimeType.startsWith("video/") || mimeType.startsWith("audio/")) { String[] arrayPaths = new String[mPaths.size()]; MediaScannerConnection.scanFile(mContext, mPaths.toArray(arrayPaths), null, this); updateStateAndNotification(STATE_W4_MEDIA_SCANNER); } else { // We're done. updateStateAndNotification(STATE_SUCCESS); } }
From source file:com.carlrice.reader.fragment.EntryFragment.java
@Override public void onClickEnclosure() { getActivity().runOnUiThread(new Runnable() { @Override//from ww w . ja v a2s .c o m public void run() { final String enclosure = mEntryPagerAdapter.getCursor(mCurrentPagerPos).getString(mEnclosurePos); final int position1 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR); final int position2 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR, position1 + 3); final Uri uri = Uri.parse(enclosure.substring(0, position1)); final String filename = uri.getLastPathSegment(); new AlertDialog.Builder(getActivity()).setTitle(R.string.open_enclosure) .setMessage(getString(R.string.file) + ": " + filename) .setPositiveButton(R.string.open_link, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showEnclosure(uri, enclosure, position1, position2); } }).setNegativeButton(R.string.download_and_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DownloadManager.Request r = new DownloadManager.Request(uri); r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); r.allowScanningByMediaScanner(); r.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); DownloadManager dm = (DownloadManager) Application.context() .getSystemService(Context.DOWNLOAD_SERVICE); dm.enqueue(r); } catch (Exception e) { Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_LONG).show(); } } }).show(); } }); }