Example usage for android.net Uri getLastPathSegment

List of usage examples for android.net Uri getLastPathSegment

Introduction

In this page you can find the example usage for android.net Uri getLastPathSegment.

Prototype

@Nullable
public abstract String getLastPathSegment();

Source Link

Document

Gets the decoded last segment in the path.

Usage

From source file:com.gmail.emerssso.srbase.database.SRContentProvider.java

/**
 * Helper method to update an item represented by an ID type Uri 
 * @param uri Uri to update/*  ww w.  java  2 s .com*/
 * @param values Values to update items represented by Uri with
 * @param selection Selection to select items to update with
 * @param selArgs arguments for selection
 * @param sqlDB db to perform update on
 * @param table table to perform update on
 * @return number of rows updated
 */
private int updateIdTypeUri(Uri uri, ContentValues values, String selection, String[] selArgs,
        SQLiteDatabase sqlDB, String table) {
    String id = uri.getLastPathSegment();
    if (StringUtils.isBlank(selection)) {
        selection = "_id = " + id;
    } else {
        selection = "_id = " + id + selection;
    }
    return sqlDB.update(table, values, selection, selArgs);
}

From source file:ca.rmen.android.poetassistant.main.PagerAdapter.java

PagerAdapter(Context context, FragmentManager fm, Intent intent) {
    super(fm);//from  w w  w.j  ava  2 s. co m
    Log.v(TAG, "Constructor: intent = " + intent);
    mContext = context;
    Uri initialQuery = intent.getData();
    // Deep link to query in a specific tab
    if (initialQuery != null) {
        Tab tab = Tab.parse(initialQuery.getHost());
        if (tab == Tab.PATTERN) {
            mInitialPatternQuery = initialQuery.getLastPathSegment();
        } else if (tab == Tab.RHYMER) {
            mInitialRhymeQuery = initialQuery.getLastPathSegment();
        } else if (tab == Tab.THESAURUS) {
            mInitialThesaurusQuery = initialQuery.getLastPathSegment();
        } else if (tab == Tab.DICTIONARY) {
            mInitialDictionaryQuery = initialQuery.getLastPathSegment();
        } else if (Constants.DEEP_LINK_QUERY.equals(initialQuery.getHost())) {
            mInitialRhymeQuery = initialQuery.getLastPathSegment();
            mInitialThesaurusQuery = initialQuery.getLastPathSegment();
            mInitialDictionaryQuery = initialQuery.getLastPathSegment();
        }
    }
    // Text shared from another app:
    else if (Intent.ACTION_SEND.equals(intent.getAction())) {
        mInitialPoemText = intent.getStringExtra(Intent.EXTRA_TEXT);
    }
}

From source file:mobisocial.musubi.objects.WebAppObj.java

String getAppName(Obj obj) {
    Uri appUri = Uri.parse(obj.getJson().optString(OBJ_URL));
    String given = appUri.getQueryParameter("n");
    if (given == null) {
        given = appUri.getLastPathSegment();
        if (given == null || given.length() <= 1 || given.startsWith("index")) {
            List<String> segs = appUri.getPathSegments();
            if (segs.size() > 1) {
                given = segs.get(segs.size() - 2);
            } else {
                given = appUri.getAuthority();
            }//  w  w w . j av a2s  .c  o m
        }
    }
    return given;
}

From source file:com.linroid.pushapp.service.DownloadService.java

private void newDownloadTask(Pack pack) {
    if (pack == null || TextUtils.isEmpty(pack.getDownloadUrl())) {
        Timber.e("invalid package download url");
        return;/*from  w  ww  .  j  a  va  2  s  .  c o  m*/
    }
    Timber.d("Download url: %s", pack.getDownloadUrl());
    Uri downloadUri = Uri.parse(pack.getDownloadUrl());

    File savedDir = new File(downloadDir, String.valueOf(pack.getId()));
    File savedFile = new File(savedDir, downloadUri.getLastPathSegment());
    DownloadRequest request = new DownloadRequest(downloadUri);
    if (downloadPackageMap.containsKey(pack.getId())) {
        Timber.w("download existing... break out");
        return;
    }
    if (!savedDir.exists()) {
        savedDir.mkdir();
    }
    //???
    Cursor cursor = db.query(Pack.DB.SQL_ITEM_QUERY, String.valueOf(pack.getId()));
    if (cursor.moveToNext()) {
        Pack saved = Pack.fromCursor(cursor);
        if (!TextUtils.isEmpty(saved.getPath()) && savedFile.exists()) {
            onDownloadComplete(saved);
            return;
        }
    } else {
        db.insert(Pack.DB.TABLE_NAME, pack.toContentValues());
    }
    pack.setPath(savedFile.getAbsolutePath());
    request.setDestinationURI(Uri.fromFile(savedFile));
    request.setDownloadListener(new DownloadStatusListener() {
        @Override
        @DebugLog
        public void onDownloadComplete(int i) {
            prevProgress = -1;
            Pack pack = downloadPackageMap.remove(i);
            CharSequence label = AndroidUtil.getApkLabel(DownloadService.this, pack.getPath());
            pack.setAppName(label != null ? label.toString() : pack.getAppName());
            //TODO ThinDownloadManagerAPK?MD5?)
            String md5 = MD5.calculateFile(new File(pack.getPath()));
            pack.setMD5(md5);
            db.update(Pack.DB.TABLE_NAME, pack.toContentValues(), Pack.DB.WHERE_ID,
                    String.valueOf(pack.getId()));
            DownloadService.this.onDownloadComplete(pack);
        }

        @Override
        @DebugLog
        public void onDownloadFailed(int i, int i1, String s) {
            Pack pack = downloadPackageMap.get(i);
            Timber.e("%s :( %d %s", pack.getAppName(), i1, s);
            showNotification(pack, -1);
            downloadPackageMap.remove(i);
            prevProgress = -1;
        }

        @Override
        public void onProgress(int i, long l, int i1) {
            showNotification(downloadPackageMap.get(i), i1);
        }
    });
    int downloadId = downloadManager.add(request);
    downloadPackageMap.put(downloadId, pack);
    showNotification(pack, 0);
}

From source file:org.sensapp.android.sensappdroid.fragments.SensorListFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = { SensAppContract.Sensor.NAME, SensAppContract.Sensor.ICON };
    Uri uri = getActivity().getIntent().getData();
    if (uri == null) {
        uri = SensAppContract.Sensor.CONTENT_URI;
    } else {// w ww  .  ja v  a2s . c o  m
        ((TextView) getActivity().findViewById(android.R.id.empty))
                .setText(getString(R.string.no_sensors) + " in " + uri.getLastPathSegment() + " composite");
    }
    return new CursorLoader(getActivity(), uri, projection, null, null, null);
}

From source file:name.zurell.kirk.apps.android.rhetolog.RhetologApplication.java

/** Generate (placeholder) report for numbered session */

String reportForSession(Uri session) {

    // Use own contentprovider streaming?

    Uri uri = Uri.withAppendedPath(RhetologContract.SESSIONSREPORT_URI, session.getLastPathSegment());
    try {/*from ww  w .  j  a va 2  s .c  om*/
        InputStream inputStream = getContentResolver().openInputStream(uri);
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.append("Report for session " + session.toString() + "\n\n");

        String line;
        while ((line = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
            stringBuilder.append("\n"); // oh well.
        }

        return stringBuilder.toString();

    } catch (IOException e) {
        return null;
    }

}

From source file:at.tomtasche.reader.ui.activity.ShortcutActivity.java

@Override
public DocumentLoader loadUri(Uri uri) {
    ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

    Intent intent = new Intent();

    Intent launchIntent = new Intent(this, MainActivity.class);
    launchIntent.setAction(Intent.ACTION_VIEW);
    launchIntent.setData(uri);//  ww  w.j  a  v  a2s  . c o m

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, uri.getLastPathSegment());
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    setResult(RESULT_OK, intent);

    finish();

    return null;
}

From source file:com.bt.download.android.gui.UniversalScanner.java

private void scanDocument(String filePath) {
    File file = new File(filePath);

    if (documentExists(filePath, file.length())) {
        return;//from   w  w w  . j  a  v a  2s .  com
    }

    String displayName = FilenameUtils.getBaseName(file.getName());

    ContentResolver cr = context.getContentResolver();

    ContentValues values = new ContentValues();

    values.put(DocumentsColumns.DATA, filePath);
    values.put(DocumentsColumns.SIZE, file.length());
    values.put(DocumentsColumns.DISPLAY_NAME, displayName);
    values.put(DocumentsColumns.TITLE, displayName);
    values.put(DocumentsColumns.DATE_ADDED, System.currentTimeMillis());
    values.put(DocumentsColumns.DATE_MODIFIED, file.lastModified());
    values.put(DocumentsColumns.MIME_TYPE, UIUtils.getMimeType(filePath));

    Uri uri = cr.insert(Documents.Media.CONTENT_URI, values);

    FileDescriptor fd = new FileDescriptor();
    fd.fileType = Constants.FILE_TYPE_DOCUMENTS;
    fd.id = Integer.valueOf(uri.getLastPathSegment());

    shareFinishedDownload(fd);
}

From source file:ca.ggolda.lendit.fragments.FragChat.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            Toast.makeText(getContext(), "You're Signed In", Toast.LENGTH_SHORT).show();
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getContext(), "Sign In Canceled", Toast.LENGTH_SHORT).show();
            getActivity().finish();/*from   ww  w  . j  a  va2s. c o  m*/
        }
    } else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) {
        Uri selectedImageUri = data.getData();

        // Get a reference to store file at chat_photos/<FILENAME>
        StorageReference photoRef = mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment());

        // Upload file to Firebase Storage
        photoRef.putFile(selectedImageUri).addOnSuccessListener(getActivity(),
                new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        // When the image has successfully uploaded, we get its download URL
                        Uri downloadUrl = taskSnapshot.getDownloadUrl();

                        // Set the download URL to the message box, so that the user can send it to the database
                        InstanceMessage friendlyMessage = new InstanceMessage(null, mUsername,
                                downloadUrl.toString());
                        mMessagesDatabaseReference.push().setValue(friendlyMessage);
                    }
                });
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedMembersFragment.java

private void groupUpdateHack(final Uri feedUri) {
    final Context context = getActivity();
    new Thread() {
        public void run() {
            String feedName = feedUri.getLastPathSegment();
            final IdentityProvider ident = new DBIdentityProvider(mHelper);
            Maybe<Group> mg = mHelper.groupByFeedName(feedName);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }/*www  . ja  v a 2 s  . c  om*/
            try {
                // group exists already, load view
                final Group g = mg.get();
                Collection<Contact> existingContacts = g.contactCollection(mHelper);
                //TODO: XXXXX these two won't do a thing because g.forceUpdate happens
                //in the background.....
                g.forceUpdate(context);
                Collection<Contact> newContacts = g.contactCollection(mHelper);
                newContacts.removeAll(existingContacts);

                Helpers.resendProfile(context, newContacts, true);
            } catch (Maybe.NoValError e) {
            }
            ident.close();
        };
    }.start();
}