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.nextgis.mobile.forms.CameraFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    sensorManager.unregisterListener(sensorListener);
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        //add angle
        float dfAngle = 0;
        try {/*from ww w .  j  a  v a2 s.c  o  m*/
            ExifInterface exif = new ExifInterface(imgFile.getPath());
            String sDate = exif.getAttribute(ExifInterface.TAG_DATETIME);
            Date datetime = stringToDate(sDate, "yyyy:MM:dd HH:mm:ss");
            Log.d(TAG, "image date: " + datetime.toString());
            long testMilli = datetime.getTime();

            long nDif = 1000000;
            for (long n : mAngles.keySet()) {
                long nDifTmp = Math.abs(testMilli - n);
                if (nDifTmp < nDif) {
                    nDif = nDifTmp;
                    dfAngle = (Float) mAngles.get(n);
                }
            }
            Log.d(TAG, "image angle: " + dfAngle);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String listItem;
        if (data != null) {
            Uri outPath = data.getData();
            listItem = outPath.getLastPathSegment();
        } else {
            listItem = fileName;
        }
        HashMap<String, Object> hm = new HashMap<String, Object>();
        hm.put(IMG_NAME, listItem);
        String sAngle = CompassFragment.formatNumber(dfAngle, 0, 0) + CompassFragment.DEGREE_CHAR + " "
                + CompassFragment.getDirectionCode(dfAngle, getResources());
        hm.put(IMG_ROT, sAngle);

        listItems.add(hm);

        adapter.notifyDataSetChanged();

        InputPointActivity activity = (InputPointActivity) getActivity();
        if (activity == null)
            return;
        activity.AddImage(listItem, dfAngle);
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptAsymmetricFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_PUBLIC_KEYS: {
        if (resultCode == Activity.RESULT_OK) {
            Bundle bundle = data.getExtras();
            setEncryptionKeyIds(bundle.getLongArray(SelectPublicKeyActivity.RESULT_EXTRA_MASTER_KEY_IDS));
        }//  w  w  w.j  a  va2s  . com
        break;
    }

    case REQUEST_CODE_SECRET_KEYS: {
        if (resultCode == Activity.RESULT_OK) {
            Uri uriMasterKey = data.getData();
            setSignatureKeyId(Long.valueOf(uriMasterKey.getLastPathSegment()));
        } else {
            setSignatureKeyId(Constants.key.none);
        }
        break;
    }

    default: {
        super.onActivityResult(requestCode, resultCode, data);

        break;
    }
    }
}

From source file:org.mobisocial.corral.ContentCorral.java

private static String getIndexPath(Uri uri) {
    String seg = uri.getLastPathSegment();
    if (seg.endsWith(".html") || seg.endsWith(".htm") || seg.endsWith(".php")) {
        return uri.getPath();
    }/*from www  .  j a v a  2s  .  c o m*/
    return uri.buildUpon().appendPath("index.html").build().getPath();
}

From source file:nz.ac.otago.psyanlab.common.PaleActivity.java

/**
 * Perform new experiment action. Creates a new experiment and sends an
 * intent to edit it. If the user discards the new experiment without
 * 'saving' it, we'll have to delete the new experiment when the edit
 * activity returns./*from   w ww .j a  va 2 s  .c  o  m*/
 */
private void doNewExperiment() {
    Experiment experiment = new Experiment();
    experiment.authors = mUserDelegate.getUserName();
    experiment.dateCreated = System.currentTimeMillis();
    experiment.lastModified = System.currentTimeMillis();
    experiment.name = getString(R.string.default_name_new_experiment);
    long experimentId;
    try {
        Uri uri = mUserDelegate.addExperiment(experiment);
        experimentId = Long.parseLong(uri.getLastPathSegment());
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    Intent i = new Intent(this, ExperimentDesignerActivity.class);
    i.putExtra(Args.USER_EXPERIMENT_DELEGATE, mUserDelegate.getUserExperimentDelegate(experimentId));
    startActivityForResult(i, REQUEST_NEW);
}

From source file:com.android.quicksearchbox.google.GoogleSuggestionProvider.java

/**
 * Gets the search text from a uri.//w  ww.j av a2  s.  c o m
 */
private String getQuery(Uri uri) {
    if (uri.getPathSegments().size() > 1) {
        return uri.getLastPathSegment();
    } else {
        return "";
    }
}

From source file:com.vishwa.pinit.LocationSuggestionProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    switch (uriMatcher.match(uri)) {
    case SEARCH_SUGGEST:
        String query = uri.getLastPathSegment();

        MatrixCursor cursor = new MatrixCursor(SEARCH_SUGGEST_COLUMNS, 1);
        if (Geocoder.isPresent()) {
            try {
                mGeocoder = new Geocoder(getContext(), Locale.ENGLISH);
                List<Address> addressList = mGeocoder.getFromLocationName(query, 5);
                for (int i = 0; i < addressList.size(); i++) {
                    Address address = addressList.get(i);
                    StringBuilder fullAddress = new StringBuilder();
                    for (int j = 1; j < address.getMaxAddressLineIndex(); j++) {
                        fullAddress.append(address.getAddressLine(j));
                    }//from   ww w . j ava  2s . c  om
                    cursor.addRow(new String[] { Integer.toString(i), address.getAddressLine(0).toString(),
                            fullAddress.toString(), address.getLatitude() + "," + address.getLongitude() });
                }

                return cursor;
            } catch (IllegalArgumentException e) {
                return getLocationSuggestionsUsingAPI(query, cursor);
            } catch (IOException e) {
                return getLocationSuggestionsUsingAPI(query, cursor);
            }
        }
    default:
        throw new IllegalArgumentException("Unknown Uri: " + uri);
    }
}

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

/** Called when the activity is first created. */
@Override// w ww.j av  a  2  s .co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed_home);
    mNfc = new Nfc(this);

    checked = new boolean[filterTypes.length];

    for (int x = 0; x < filterTypes.length; x++) {
        checked[x] = true;
    }

    mFeedViews = new ArrayList<FeedView>();
    mFeedViews.add(FeedViews.feedViewFrom("Feed", new FeedViewFragment()));
    mFeedViews.add(FeedViews.feedViewFrom("Apps", new AppsViewFragment()));
    mFeedViews.add(FeedViews.feedViewFrom("People", new FeedMembersFragment()));
    mFeedViews.add(new PresenceView());

    Intent intent = getIntent();
    String feed_name = null;
    String dyn_feed_uri = null;
    if (intent.getType() != null && intent.getType().equals(Feed.MIME_TYPE)) {
        Uri feedUri = getIntent().getData();
        feed_name = feedUri.getLastPathSegment();
        Maybe<Group> maybeG = Group.forFeedName(FeedHomeActivity.this, feed_name);
        try {
            Group g = maybeG.get();
            mGroupName = g.name;
            dyn_feed_uri = g.dynUpdateUri;
        } catch (Exception e) {
        }
    }

    if (dyn_feed_uri != null) {
        mNfc.share(NdefFactory.fromUri(dyn_feed_uri));
        Log.w(TAG, dyn_feed_uri);
    }

    mFeedUri = Feed.uriForName(feed_name);
    mColor = Feed.colorFor(feed_name);

    Bundle args = new Bundle();
    args.putParcelable(FeedViewFragment.ARG_FEED_URI, mFeedUri);
    mActionsFragment = new FeedActionsFragment();
    mActionsFragment.setArguments(args);

    for (FeedView f : mFeedViews) {
        f.getFragment().setArguments(args);
    }

    // TODO: Why is FeedActionsFragment.getActivity() null without this hack?
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    Fragment actions = getSupportFragmentManager().findFragmentByTag("feedActions");
    if (actions != null) {
        ft.remove(actions);
    }
    ft.add(mActionsFragment, "feedActions");
    ft.commit();

    PagerAdapter adapter = new FeedFragmentAdapter(getSupportFragmentManager(), mFeedUri);
    mFeedViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mFeedViewPager.setAdapter(adapter);
    mFeedViewPager.setOnPageChangeListener(this);
    mFeedViewPager.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

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

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

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

    doTitleBar(this, mGroupName);
    onPageSelected(0);
}

From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteScheduleHandler.java

@Override
public ArrayList<ContentProviderOperation> parse(ArrayList<JSONArray> entries, ContentResolver resolver)
        throws JSONException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();
    final HashMap<String, ContentProviderOperation> blockBatchMap = Maps.newHashMap();
    final HashMap<String, ContentProviderOperation> sessionUpdateBatchMap = Maps.newHashMap();

    int nrEntries = 0;
    for (JSONArray schedules : entries) {
        Log.d(TAG, "Retrieved " + schedules.length() + " schedule entries.");
        nrEntries += schedules.length();

        for (int i = 0; i < schedules.length(); i++) {
            JSONObject schedule = schedules.getJSONObject(i);

            final long startTime = ParserUtils.parseDevoxxTime(schedule.getString("fromTime"));
            final long endTime = ParserUtils.parseDevoxxTime(schedule.getString("toTime"));
            final String kind = schedule.getString("kind");

            final String blockId = Blocks.generateBlockId(kind, startTime, endTime);

            if (!blockBatchMap.containsKey(blockId)) {
                final Uri blockUri = Blocks.buildBlockUri(blockId);

                ContentProviderOperation.Builder builder;
                if (isRowExisting(Blocks.buildBlockUri(blockId), BlocksQuery.PROJECTION, resolver)) {
                    builder = ContentProviderOperation.newUpdate(blockUri);
                } else {
                    builder = ContentProviderOperation.newInsert(Blocks.CONTENT_URI);
                    builder.withValue(Blocks.BLOCK_ID, blockId);
                }//w  w w.j  a  v a 2 s . c o m
                builder.withValue(Blocks.BLOCK_START, startTime);
                builder.withValue(Blocks.BLOCK_END, endTime);

                final String type = schedule.getString("type");
                final String code = schedule.getString("code");

                if (code.startsWith("D10")) {
                    builder.withValue(Blocks.BLOCK_TITLE, type.replaceAll("\\ \\(.*\\)", ""));
                } else {
                    builder.withValue(Blocks.BLOCK_TITLE, schedule.getString("code"));
                }

                builder.withValue(Blocks.BLOCK_TYPE, kind);
                blockBatchMap.put(blockId, builder.build());
            }

            if (schedule.has("presentationUri")) {
                final Uri presentationUri = Uri.parse(schedule.getString("presentationUri"));
                final String sessionId = presentationUri.getLastPathSegment();
                final Uri sessionUri = Sessions.buildSessionUri(sessionId);

                if (isRowExisting(sessionUri, SessionsQuery.PROJECTION, resolver)) {
                    String roomId = null;
                    if (schedule.has("room")) {
                        final String roomName = schedule.getString("room");
                        Cursor cursor = resolver.query(Rooms.buildRoomsWithNameUri(roomName),
                                RoomsQuery.PROJECTION, null, null, null);
                        if (cursor.moveToNext()) {
                            roomId = cursor.getString(RoomsQuery.ROOM_ID);
                        }
                        cursor.close();
                    }
                    final ContentProviderOperation.Builder builder = ContentProviderOperation
                            .newUpdate(sessionUri);
                    builder.withValue(Sessions.BLOCK_ID, blockId);
                    builder.withValue(Sessions.ROOM_ID, roomId);
                    if (schedule.has("note")) {
                        final String note = schedule.getString("note");
                        if (note != null && note.trim().length() > 0) {
                            builder.withValue(Sessions.NOTE, note.trim());
                        }
                    }

                    sessionUpdateBatchMap.put(sessionId, builder.build());
                }
            }
        }
    }

    batch.addAll(blockBatchMap.values());
    batch.addAll(sessionUpdateBatchMap.values());

    if (isRemoteSync() && nrEntries > 0) {
        for (String lostId : getLostIds(blockBatchMap.keySet(), Blocks.CONTENT_URI, BlocksQuery.PROJECTION,
                BlocksQuery.BLOCK_ID, resolver)) {
            if (!lostId.startsWith("lab")) {
                final Uri lostBlockUri = Blocks.buildBlockUri(lostId);
                batch.add(ContentProviderOperation.newDelete(lostBlockUri).build());
            }
        }
        for (String lostId : getLostIds(sessionUpdateBatchMap.keySet(), Sessions.CONTENT_URI,
                SessionsQuery.PROJECTION, SessionsQuery.SESSION_ID, resolver)) {
            Uri deleteUri = Sessions.buildSpeakersDirUri(lostId);
            batch.add(ContentProviderOperation.newDelete(deleteUri).build());
            deleteUri = Sessions.buildTagsDirUri(lostId);
            batch.add(ContentProviderOperation.newDelete(deleteUri).build());
            deleteUri = Sessions.buildSessionUri(lostId);
            batch.add(ContentProviderOperation.newDelete(deleteUri).build());
        }
    }

    return batch;
}

From source file:net.simonvt.schematic.sample.ui.fragment.NoteFragment.java

@OnClick(R.id.action)
void onAction() {
    final String note = noteView.getText().toString();
    final String status;
    if (statusView.isChecked()) {
        status = NoteColumns.STATUS_COMPLETED;
    } else {//from  w  ww .j  a va 2 s.c  om
        status = NoteColumns.STATUS_NEW;
    }
    final String tagList = tags.getText().toString();
    final Context appContext = getActivity().getApplicationContext();
    if (noteId == NO_ID) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                ContentValues cv = new ContentValues();
                cv.put(NoteColumns.LIST_ID, listId);
                cv.put(NoteColumns.NOTE, note);
                cv.put(NoteColumns.STATUS, status);
                Uri newUri = appContext.getContentResolver().insert(Notes.CONTENT_URI, cv);
                long newId = Long.parseLong(newUri.getLastPathSegment());
                insertTags(newId, tagList, appContext);
            }
        }).start();
    } else {
        final long id = noteId;
        new Thread(new Runnable() {
            @Override
            public void run() {
                ContentValues cv = new ContentValues();
                cv.put(NoteColumns.NOTE, note);
                cv.put(NoteColumns.STATUS, status);
                appContext.getContentResolver().update(Notes.withId(noteId), cv, null, null);
                appContext.getContentResolver().delete(NotesProvider.NotesTags.fromNote(noteId), null, null);
                insertTags(id, tagList, appContext);
            }
        }).start();
    }

    listener.onNoteChange();
}

From source file:fr.seeks.SuggestionProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    String query = uri.getLastPathSegment();

    if (query == null || query.equals("") || query.equals("search_suggest_query"))
        return null;

    Log.v(TAG, "Request '" + query + "' for '" + uri + "'");

    MatrixCursor matrix = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_TITLE, KEY_DESCRIPTION, KEY_QUERY, KEY_ACTION, KEY_URL });

    Boolean instant_suggest = mPrefs.getBoolean("instant_suggest", false);
    if (instant_suggest) {
        setCursorOfQuery(uri, query, matrix);
    } else {//w w  w. jav a2s .  co m
        perhapsSetCursorOfQuery(uri, query, matrix);
    }
    matrix.setNotificationUri(getContext().getContentResolver(), uri);

    return matrix;
}