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:mobisocial.socialkit.musubi.DbObj.java

/**
 * Prepares ContentValues that can be delivered to Musubi's Content Provider
 * for insertion into a SocialDb feed.// w w w  .jav  a2s. c o  m
 */
public static ContentValues toContentValues(Uri feedUri, Long parentObjId, Obj obj) {
    ContentValues values = new ContentValues();
    values.put(DbObj.COL_TYPE, obj.getType());
    if (obj.getStringKey() != null) {
        values.put(DbObj.COL_STRING_KEY, obj.getStringKey());
    }
    if (obj.getJson() != null) {
        values.put(DbObj.COL_JSON, obj.getJson().toString());
    }
    if (obj.getIntKey() != null) {
        values.put(DbObj.COL_INT_KEY, obj.getIntKey());
    }
    if (obj.getRaw() != null) {
        values.put(DbObj.COL_RAW, obj.getRaw());
    }
    if (parentObjId != null) {
        values.put(DbObj.COL_PARENT_ID, parentObjId);
    }
    try {
        Long feedId = Long.parseLong(feedUri.getLastPathSegment());
        values.put(DbObj.COL_FEED_ID, feedId);
    } catch (Exception e) {
        throw new IllegalArgumentException("No feed id found for " + feedUri, e);
    }
    return values;
}

From source file:com.pdftron.pdf.utils.Utils.java

public static String getUriDisplayName(Context context, Uri contentUri) {
    String displayName = null;//  ww  w  .j  a  v a  2 s  .  c om
    String[] projection = { OpenableColumns.DISPLAY_NAME };
    Cursor cursor = null;

    if (contentUri.getScheme().equalsIgnoreCase("file")) {
        return contentUri.getLastPathSegment();
    }
    try {
        cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int nameIndex = cursor.getColumnIndexOrThrow(projection[0]);
            if (nameIndex >= 0) {
                displayName = cursor.getString(nameIndex);
            }
        }
    } catch (Exception e) {
        displayName = null;
    }
    if (cursor != null) {
        cursor.close();
    }
    return displayName;
}

From source file:com.google.android.demos.jamendo.app.UserActivity.java

/** {@inheritDoc} */
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    switch (loaderId) {
    case LOADER_HEADER: {
        Uri uri = getIntent().getData();
        String[] projection = { Users._ID, Users.IMAGE, Users.NAME, Users.LANG };
        String selection = String.format("%s=?", JamendoContract.PARAM_IMAGE_SIZE);
        String[] selectionArgs = { getDimensionPixelSizeAsString(R.dimen.avatar_size) };
        String sortOrder = null;/*www.j ava 2s . co m*/
        return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder);
    }
    case LOADER_LIST: {
        Uri data = getIntent().getData();
        String id = data.getLastPathSegment();
        Uri uri = Albums.CONTENT_URI;
        String[] projection = { Albums._ID, Albums.IMAGE, Artists.NAME, Albums.NAME };
        String selection = String.format("%s=?&%s=?&%s=?", getColumnNameForId(id), JamendoContract.PARAM_JOIN,
                JamendoContract.PARAM_IMAGE_SIZE);
        String[] selectionArgs = { id, JamendoContract.JOIN_ALBUM_USER_STARRED,
                getDimensionPixelSizeAsString(R.dimen.image_size) };
        String sortOrder = Albums.Order.STARREDDATE.descending();
        return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder);
    }
    default:
        return null;
    }
}

From source file:th.in.ffc.person.PersonActivity.java

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

    if (mCheckData) {
        Uri data = getIntent().getData();
        if (data != null)
            mPid = data.getLastPathSegment();

        if (TextUtils.isEmpty(mPid))
            throw new IllegalStateException("Data was null");

        mPcucodePerson = getIntent().getExtras().getString(PersonColumns._PCUCODEPERSON);

        if (TextUtils.isEmpty(mPcucodePerson))
            throw new IllegalStateException("pid or pcucodeperson was null");
    }//w w w . j  a  v  a  2  s.  com
}

From source file:org.sensapp.android.sensappdroid.activities.CompositeActivity.java

@Override
public void onSensorSelected(Uri uri) {
    Intent i = new Intent(this, MeasuresActivity.class);
    i.setData(Uri.parse(SensAppContract.Measure.CONTENT_URI + "/" + uri.getLastPathSegment()));
    startActivity(i);/*  ww w.j a  va 2 s  .  c o  m*/
}

From source file:com.owncloud.android.ui.activity.ShareActivity.java

@Override
protected void onNewIntent(Intent intent) {
    // Verify the action and get the query
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        Log_OC.w(TAG, "Ignored Intent requesting to query for " + query);

    } else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
        Uri data = intent.getData();
        doShareWith(data.getLastPathSegment(),
                UsersAndGroupsSearchProvider.DATA_GROUP.equals(data.getAuthority()));

    } else {/* w w  w  .  ja v  a 2s .  co m*/
        Log_OC.wtf(TAG, "Unexpected intent " + intent.toString());
    }
}

From source file:com.google.samples.apps.iosched.feedback.FeedbackWearableListenerService.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LOGD(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());

    for (DataEvent event : dataEvents) {
        LOGD(TAG, "Uri is: " + event.getDataItem().getUri());
        DataMapItem mapItem = DataMapItem.fromDataItem(event.getDataItem());
        String path = event.getDataItem().getUri().getPath();
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (PATH_RESPONSE.equals(path)) {
                // we have a response
                DataMap data = mapItem.getDataMap();
                saveFeedback(data);//from w  ww  . jav  a2s.  co m
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            if (path.startsWith(SessionAlarmService.PATH_FEEDBACK)) {
                Uri uri = event.getDataItem().getUri();
                dismissLocalNotification(uri.getLastPathSegment());
            }
        }
    }
}

From source file:com.google.samples.apps.iosched.ui.NfcBadgeActivity.java

private void addToHistory(String url) {
    Uri uri = Uri.parse(url);
    final String plusId = uri.getLastPathSegment();
    if (!isValidPlusId(plusId)) {
        LOGE(TAG, "Unknown ID format: " + plusId);
        return;//from   ww  w  .  j av  a2  s  .  c  o  m
    }
    if (isDummyPlusId(plusId)) {
        Toast.makeText(this, R.string.people_ive_met_dummy_badge, Toast.LENGTH_SHORT).show();
        return;
    }
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            Cursor cursor = null;
            try {
                cursor = getContentResolver().query(ScheduleContract.PeopleIveMet.buildPersonUri(plusId),
                        new String[] { ScheduleContract.PeopleIveMet.PERSON_ID }, null, null, null);
                if (0 < cursor.getCount()) {
                    ContentValues values = new ContentValues();
                    values.put(ScheduleContract.PeopleIveMet.PERSON_TIMESTAMP, System.currentTimeMillis());
                    getContentResolver().update(ScheduleContract.PeopleIveMet.buildPersonUri(plusId), values,
                            null, null);
                } else {
                    ContentValues values = new ContentValues();
                    values.put(ScheduleContract.PeopleIveMet.PERSON_ID, plusId);
                    values.put(ScheduleContract.PeopleIveMet.PERSON_TIMESTAMP, System.currentTimeMillis());
                    values.put(ScheduleContract.PeopleIveMet.PERSON_IMAGE_URL, (String) null);
                    values.put(ScheduleContract.PeopleIveMet.PERSON_NAME, (String) null);
                    getContentResolver().insert(ScheduleContract.PeopleIveMet.CONTENT_URI, values);
                }
            } finally {
                if (null != cursor) {
                    cursor.close();
                }
            }
            return null;
        }
    }.execute();
}

From source file:com.saarang.samples.apps.iosched.ui.NfcBadgeActivity.java

private void addToHistory(String url) {
    Uri uri = Uri.parse(url);
    final String plusId = uri.getLastPathSegment();
    if (!isValidPlusId(plusId)) {
        LogUtils.LOGE(TAG, "Unknown ID format: " + plusId);
        return;/* ww  w .  j av a2s  .com*/
    }
    if (isDummyPlusId(plusId)) {
        Toast.makeText(this, com.saarang.samples.apps.iosched.R.string.people_ive_met_dummy_badge,
                Toast.LENGTH_SHORT).show();
        return;
    }
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            Cursor cursor = null;
            try {
                cursor = getContentResolver().query(ScheduleContract.PeopleIveMet.buildPersonUri(plusId),
                        new String[] { ScheduleContract.PeopleIveMet.PERSON_ID }, null, null, null);
                if (0 < cursor.getCount()) {
                    ContentValues values = new ContentValues();
                    values.put(ScheduleContract.PeopleIveMet.PERSON_TIMESTAMP, System.currentTimeMillis());
                    getContentResolver().update(ScheduleContract.PeopleIveMet.buildPersonUri(plusId), values,
                            null, null);
                } else {
                    ContentValues values = new ContentValues();
                    values.put(ScheduleContract.PeopleIveMet.PERSON_ID, plusId);
                    values.put(ScheduleContract.PeopleIveMet.PERSON_TIMESTAMP, System.currentTimeMillis());
                    values.put(ScheduleContract.PeopleIveMet.PERSON_IMAGE_URL, (String) null);
                    values.put(ScheduleContract.PeopleIveMet.PERSON_NAME, (String) null);
                    getContentResolver().insert(ScheduleContract.PeopleIveMet.CONTENT_URI, values);
                }
            } finally {
                if (null != cursor) {
                    cursor.close();
                }
            }
            return null;
        }
    }.execute();
}

From source file:com.razza.apps.iosched.feedback.FeedbackWearableListenerService.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LogUtils.LOGD(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());

    for (DataEvent event : dataEvents) {
        LogUtils.LOGD(TAG, "Uri is: " + event.getDataItem().getUri());
        DataMapItem mapItem = DataMapItem.fromDataItem(event.getDataItem());
        String path = event.getDataItem().getUri().getPath();
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (PATH_RESPONSE.equals(path)) {
                // we have a response
                DataMap data = mapItem.getDataMap();
                saveFeedback(data);//from w w  w.j  a  v  a 2  s.c om
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            if (path.startsWith(SessionAlarmService.PATH_FEEDBACK)) {
                Uri uri = event.getDataItem().getUri();
                dismissLocalNotification(uri.getLastPathSegment());
            }
        }
    }
}