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.andrew.apollo.utils.MusicUtils.java

/**
 * @param context The {@link Context} to use.
 * @param name The name of the new playlist.
 * @return A new playlist ID./*from  ww w  . ja v a  2s. co m*/
 */
public static long createPlaylist(final Context context, final String name) {
    long result = -1;
    if (name != null && name.length() > 0) {
        final ContentResolver resolver = context.getContentResolver();
        final String[] projection = new String[] { PlaylistsColumns.NAME };
        final String selection = PlaylistsColumns.NAME + " = ?";
        Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection,
                new String[] { name }, null);
        if (cursor != null && cursor.getCount() <= 0) {
            final ContentValues values = new ContentValues(1);
            values.put(PlaylistsColumns.NAME, name);
            final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values);

            if (uri != null) {
                result = Long.parseLong(uri.getLastPathSegment());
            }
        }

        if (cursor != null) {
            cursor.close();
        }
    }
    return result;
}

From source file:org.kontalk.ui.ComposeMessage.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CONTACT_PICKER) {
        if (resultCode == RESULT_OK) {
            Uri threadUri = data.getData();
            if (threadUri != null) {
                Log.i(TAG, "composing message for conversation: " + threadUri);
                String userId = threadUri.getLastPathSegment();
                Intent i = fromUserId(this, userId);
                if (i != null) {
                    if (Kontalk.hasTwoPanesUI(this)) {
                        // we need to go back to the main activity
                        Intent startIntent = new Intent(getApplicationContext(), ConversationsActivity.class);
                        startIntent.setAction(ACTION_VIEW_USERID);
                        startIntent.setData(threadUri);
                        startIntent.putExtra(ConversationsActivity.EXTRA_SEND_INTENT, sendIntent);
                        startActivity(startIntent);
                        finish();/*  www  . j  av  a2  s  .c om*/
                    } else {
                        onNewIntent(i);

                        // process SEND intent if necessary
                        if (sendIntent != null)
                            processSendIntent();
                    }
                } else {
                    Toast.makeText(this, R.string.contact_not_registered, Toast.LENGTH_LONG).show();
                    finish();
                }
            }
        } else {
            // no contact chosen or other problems - quit
            finish();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.aengbee.android.leanback.ui.VideoDetailsFragment.java

/**
 * Check if there is a global search intent. If there is, load that video.
 *///from  w ww . jav a  2 s  .c o m
private boolean hasGlobalSearchIntent() {
    Intent intent = getActivity().getIntent();
    String intentAction = intent.getAction();
    String globalSearch = getString(R.string.global_search);

    if (globalSearch.equalsIgnoreCase(intentAction)) {
        Uri intentData = intent.getData();
        String videoId = intentData.getLastPathSegment();

        Bundle args = new Bundle();
        args.putString(VideoContract.VideoEntry._ID, videoId);
        getLoaderManager().initLoader(mGlobalSearchVideoId++, args, this);
        return true;
    }
    return false;
}

From source file:th.in.ffc.person.visit.VisitMainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.visit_main_activity);

    mVisitText = (TextView) findViewById(R.id.view1);
    mDX = (TextView) findViewById(R.id.view4);
    mVisitImage = (ImageView) findViewById(R.id.image);
    mVisitImage.setOnClickListener(this);
    mVisitImage.setOnLongClickListener(this);

    mVisitButton = (ImageButton) findViewById(R.id.visit);
    mVisitButton.setOnClickListener(this);

    mVisitGrid = (GridView) findViewById(R.id.grid);
    mProgress = (ProgressBar) findViewById(android.R.id.progress);

    mPhotoTaker = new PhotoTaker(this, this);
    Uri uri = getIntent().getData();
    mPid = uri.getLastPathSegment();
    mVisitNo = getIntent().getStringExtra(Visit.NO);
    if (!TextUtils.isEmpty(mVisitNo))
        mVisitText.setText(getString(R.string.visit) + " #" + mVisitNo);

    mVisitButton.setEnabled(false);// ww w  .  j ava2s. co  m
    // Uri deathUri = Uri.withAppendedPath(Death.CONTENT_URI, mPid);
    // Cursor dc = getContentResolver().query(deathUri, new String[]{
    // Death.CAUSE}, null, null, Death.UPDATE);
    // if(dc.moveToFirst()){
    //
    // mVisitImage.setImageResource(R.drawable.ic_launcher_death);
    // mVisitImage.setEnabled(false);
    // }

    if (savedInstanceState != null) {
        mVisitNo = savedInstanceState.getString(Visit.NO);
        if (!TextUtils.isEmpty(mVisitNo))
            mVisitText.setText("Visit #" + mVisitNo);
    }

    getSupportLoaderManager().initLoader(LOAD_PERSON, null, this);

    // Cursor c = getContentResolver().query(uri, PROJECTION, null, null,
    // Person.DEFAULT_SORTING);
    // if (c.moveToFirst()) {
    // mPcuCodePerson = c
    // .getString(c.getColumnIndex(Person.PCUPERSONCODE));
    // String id = c.getString(c.getColumnIndex(Person.CITIZEN_ID));
    // doSetupActionBar(c.getString(c.getColumnIndex(Person.FULL_NAME)),
    // (!TextUtils.isEmpty(id)) ? ThaiCitizenID.parse(id) : null);
    // doSetupGrid(c);
    // } else {
    // this.finish();
    // }

}

From source file:com.microsoft.rightsmanagement.sampleapp.MainActivity.java

/**
 * Handle URI input./*from  w w  w . j a  v  a  2 s. c o m*/
 * 
 * @param uri the uri
 * @throws FileNotFoundException the file not found exception
 */
private void handleUriInput(Uri uri) throws FileNotFoundException {
    String originalFileName;
    // If the URI scheme is a content type, this means we must attempt to retrieve the file name from the
    // content provider service.
    if (uri.getScheme().toString().equals("content")) {
        originalFileName = App.getFileNameFromContent(this, uri);
    } else {
        originalFileName = uri.getLastPathSegment().toString();
    }
    if (App.isPTxtFile(originalFileName)) {
        InputStream inputStream = getContentResolver().openInputStream(uri);
        mMsipcTaskFragment.startContentConsumptionFromPtxtFileFormat(inputStream);
    } else if (App.isTxt2File(originalFileName)) {
        InputStream inputStream = getContentResolver().openInputStream(uri);
        mMsipcTaskFragment.startContentConsumptionFromMyOwnProtectedTextFileFormat(inputStream);
    }
}

From source file:com.google.android.apps.mytracks.ImportActivity.java

private String getNameFromContentUri(Uri contentUri) {

    final String name;

    final Cursor returnCursor = this.getContentResolver().query(contentUri, null, null, null, null);

    if (returnCursor != null && returnCursor.moveToFirst()) {

        int columnIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);

        if (columnIndex != -1) {

            name = returnCursor.getString(columnIndex);

        } else {//from  w w w.  ja  v  a 2s .  c o m

            name = contentUri.getLastPathSegment();

        }

    } else {

        name = null;

    }

    if (returnCursor != null && !returnCursor.isClosed()) {

        returnCursor.close();

    }

    return name;

}

From source file:edu.stanford.mobisocial.dungbeetle.ui.ViewContactActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed_home);

    checked = new boolean[filterTypes.length];

    for (int x = 0; x < filterTypes.length; x++) {
        checked[x] = true;//from   w w w .j ava 2  s.c o m
    }

    findViewById(R.id.btn_broadcast).setVisibility(View.GONE);
    mContactId = getIntent().getLongExtra("contact_id", -1);
    if (mContactId == -1) {
        Uri data = getIntent().getData();
        if (data != null) {
            try {
                mContactId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
            }
        }
    }

    Bundle args = new Bundle();
    args.putLong("contact_id", mContactId);
    Fragment profileFragment = new ViewProfileFragment();
    profileFragment.setArguments(args);
    if (mContactId == Contact.MY_ID) {
        doTitleBar(this, "My Profile");
        mLabels.add("View");
        mLabels.add("Edit");
        mFragments.add(profileFragment);
        mFragments.add(new EditProfileFragment());

        // TODO: Legitimize this. Move objects to a randomly generated private feed
        // Ability to "move" private feeds.
        // Have a "feedPtrObj" that tracks your current private. Store in-app feed.
        Uri privateUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/private");
        mLabels.add("Notes");
        Fragment feedView = new FeedViewFragment();
        args = new Bundle(args);
        args.putParcelable(FeedViewFragment.ARG_FEED_URI, privateUri);
        feedView.setArguments(args);
        mFragments.add(feedView);
    } else {
        String title = "Profile";
        Uri feedUri = null;
        try {
            Contact contact = Contact.forId(this, mContactId).get();
            title = contact.name;
            feedUri = contact.getFeedUri();
        } catch (NoValError e) {
        }
        args.putParcelable(FeedViewFragment.ARG_FEED_URI, feedUri);
        doTitleBar(this, title);
        mLabels.add("Feed");
        mLabels.add("Apps");
        mLabels.add("Profile");
        Fragment feedView = new FeedViewFragment();
        feedView.setArguments(args);
        Fragment appView = new AppsViewFragment();
        appView.setArguments(args);

        mFragments.add(feedView);
        mFragments.add(appView);
        mFragments.add(profileFragment);

        if (MusubiBaseActivity.getInstance().isDeveloperModeEnabled()) {
            FeedView sharingView = new PresenceView();
            sharingView.getFragment().setArguments(args);
            mLabels.add(sharingView.getName());
            mFragments.add(sharingView.getFragment());
        }
    }

    PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments);
    mViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mViewPager.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(this);

    ViewGroup group = (ViewGroup) findViewById(R.id.tab_frame);
    int i = 0;
    for (String s : mLabels) {
        Button button = new Button(this);
        button.setText(s);
        button.setTextSize(18f);

        button.setLayoutParams(CommonLayouts.FULL_HEIGHT);
        button.setTag(i++);
        button.setOnClickListener(mViewSelected);

        group.addView(button);
        mButtons.add(button);
    }

    // Listen for future changes
    Uri feedUri;
    if (mContactId == Contact.MY_ID) {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/me");
    } else {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts");
    }
    mProfileContentObserver = new ProfileContentObserver(mHandler);
    getContentResolver().registerContentObserver(feedUri, true, mProfileContentObserver);

    onPageSelected(0);
}

From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java

public static AddContentRelatedRepresentation prepareLink(Fragment fr, Uri uri) {
    Cursor cursor = null;/*from  w  w w  .ja  va2 s.  c  o m*/
    String name = null, source, sourceId, mimetype;
    String nodeId, type, alfAccountId;
    try {
        // Retrieve Document information
        cursor = fr.getActivity().getApplicationContext().getContentResolver().query(uri, null, null, null,
                null);

        if (cursor != null && cursor.moveToFirst()) {
            type = cursor.getString(cursor.getColumnIndex("alf_type"));
            alfAccountId = cursor.getString(cursor.getColumnIndex("alf_account_id"));
            name = cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME));
            mimetype = cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE));
        } else {
            throw new Exception("Cursor is empty");
        }

        ActivitiAccount acc = ActivitiAccountManager.getInstance(fr.getActivity()).getCurrentAccount();
        Integration integration = IntegrationManager.getInstance(fr.getActivity())
                .getByAlfrescoId(Long.parseLong(alfAccountId), acc.getId());

        // Retrieve NodeId
        String pathSegment = uri.getLastPathSegment();
        nodeId = pathSegment.split("&")[1].substring(3);
        // nodeId =
        // NodeRefUtils.getCleanIdentifier(uri.getLastPathSegment().split("&")[1].substring(3));

        // Be aware this is an hack !
        // Ideally we should populate with site Id.
        // In this case all link are absolute from root.
        sourceId = nodeId.concat("@A");
        source = "alfresco-" + integration.getId();

        return new AddContentRelatedRepresentation(name, true, source, sourceId, mimetype);
    } catch (Exception e) {
        return null;
    } finally {
        CursorUtils.closeCursor(cursor);
    }
}

From source file:com.deliciousdroid.fragment.MainSearchResultsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    base = (FragmentBaseActivity) getActivity();
    base.setTitle(R.string.main_search_results_title);

    String[] MENU_ITEMS = new String[] { getString(R.string.search_results_bookmark),
            getString(R.string.search_results_tag), getString(R.string.search_results_global_tag) };

    setListAdapter(new ArrayAdapter<String>(base, R.layout.main_view, MENU_ITEMS));

    final Intent intent = base.getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(base, MainSearchResultsFragment.class);
            i.putExtras(intent.getExtras());
            startActivity(i);/* ww w .  j  a v a 2  s.  com*/
            base.finish();
        } else {
            base.onSearchRequested();
        }
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);

            startActivity(i);
            base.finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())) {
            Intent viewBookmark = new Intent(base, ViewBookmark.class);
            viewBookmark.setData(data);

            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            base.finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(base, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            base.finish();
        }
    }

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                searchActionListener.onBookmarkSearch();
            } else if (position == 1) {
                searchActionListener.onTagSearch();
            } else if (position == 2) {
                searchActionListener.onGlobalTagSearch();
            }
        }
    });
}

From source file:auribises.com.visitorbook.Activites.AdminEntryActivity.java

void insertIntoDB() {

    ContentValues values = new ContentValues();

    values.put(Util.COL_NAMEVISITOR, adminentry.getName());
    values.put(Util.COL_PHONEVISITOR, adminentry.getPhone());
    values.put(Util.COL_EMAILVISITOR, adminentry.getEmail());
    values.put(Util.COL_GENDERVISITOR, adminentry.getGender());
    values.put(Util.COL_ADDRESSVISITOR, adminentry.getAddress());
    values.put(Util.COL_PURPOSEVISITOR, adminentry.getPurpose());
    values.put(Util.COL_DATEVISITOR, adminentry.getDate());
    values.put(Util.COL_TIMEVISITOR, adminentry.getTime());
    values.put(Util.COL_ADMINVISITOR, adminentry.getAdmin());
    values.put(Util.COL_IDPROOFVISITOR, adminentry.getIDProof());
    values.put(Util.COL_IDPROOFNUBERVISITOR, adminentry.getIDProofnumber());
    values.put(Util.COL_VEHICLEVISITOR, adminentry.getVehicle());
    values.put(Util.COL_VEHICLENUMBERVISITOR, adminentry.getVehiclenumber());

    if (!updateMode) {
        Uri dummy = resolver.insert(Util.VISITORENTRY_URI, values);
        Toast.makeText(this, adminentry.getName() + " Registered Successfully " + dummy.getLastPathSegment(),
                Toast.LENGTH_LONG).show();

        Log.i("insertintocloud", adminentry.toString());

        clearFields();//from w w  w .j  av a  2  s  .c  o  m
    } else {
        String where = Util.COL_IDVISITOR + " = " + rcvAdminentry.getId();
        int i = resolver.update(Util.ADMINENTRY_URI, values, where, null);
        if (i > 0) {
            Toast.makeText(this, "Updation Successful", Toast.LENGTH_LONG).show();
            finish();
        }
    }

}