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:org.kontalk.ui.ConversationList.java

private void openConversation(Uri threadUri) {
    if (isDualPane()) {
        // TODO position
        //mFragment.getListView().setItemChecked(position, true);

        // load conversation
        String userId = threadUri.getLastPathSegment();
        Conversation conv = Conversation.loadFromUserId(this, userId);

        // get the old fragment
        ComposeMessageFragment f = (ComposeMessageFragment) getSupportFragmentManager()
                .findFragmentById(R.id.fragment_compose_message);

        // check if we are replacing the same fragment
        if (f == null || conv == null || !f.getConversation().getRecipient().equals(conv.getRecipient())) {
            if (conv == null)
                f = ComposeMessageFragment.fromUserId(this, userId);
            else/*  w  w w .  j  a  v  a2 s .co  m*/
                f = ComposeMessageFragment.fromConversation(this, conv);

            // Execute a transaction, replacing any existing fragment
            // with this one inside the frame.
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.fragment_compose_message, f);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.addToBackStack(null);
            ft.commitAllowingStateLoss();
        }
    } else {
        Intent i = ComposeMessage.fromUserId(this, threadUri.getLastPathSegment());
        if (i != null)
            startActivity(i);
        else
            Toast.makeText(this, R.string.contact_not_registered, Toast.LENGTH_LONG).show();
    }
}

From source file:org.teleportr.Ride.java

public Ride to(Uri to) {
    return to(Integer.parseInt(to.getLastPathSegment()));
}

From source file:org.teleportr.Ride.java

public Ride via(Uri via) {
    return to(Integer.parseInt(via.getLastPathSegment()));
}

From source file:com.spit.matrix15.CategoriesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //initRecyclerView();
    //initFab();// w w w .  java  2  s  . co  m
    initToolbar();
    setupDrawerLayout();

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.fragment_container, new CategoriesFragment());
    ft.commit();

    if (funItems.isEmpty() || preItems.isEmpty() || litItems.isEmpty() || codingItems.isEmpty()) {
        List<Event> funEvents = Event.find(Event.class, "event_category = ?", "Fun and Games");
        for (Event event : funEvents) {
            funItems.add(new ViewModel(event.eventName,
                    "http://matrixthefest.org/app_posters/" + event.eventPoster));
        }

        List<Event> codingEvents = Event.find(Event.class, "event_category = ?", "Coding");
        for (Event event : codingEvents) {
            codingItems.add(new ViewModel(event.eventName,
                    "http://matrixthefest.org/app_posters/" + event.eventPoster));
        }
        List<Event> preEvents = Event.find(Event.class, "event_category = ?", "Pre-Fest");
        for (Event event : preEvents) {
            preItems.add(new ViewModel(event.eventName,
                    "http://matrixthefest.org/app_posters/" + event.eventPoster));
        }
        List<Event> litEvents = Event.find(Event.class, "event_category = ?", "Literary");
        for (Event event : litEvents) {
            litItems.add(new ViewModel(event.eventName,
                    "http://matrixthefest.org/app_posters/" + event.eventPoster));
        }

        if (!reminderAdded) {
            Calendar beginTime = Calendar.getInstance();
            beginTime.set(2015, 9, 9, 9, 00);
            Calendar endTime = Calendar.getInstance();
            endTime.set(2015, 9, 9, 5, 00);
            long startInMillis = beginTime.getTimeInMillis();
            long endInMillis = endTime.getTimeInMillis();
            ContentValues eventValues = new ContentValues();
            eventValues.put(CalendarContract.Events.DTSTART, startInMillis);
            eventValues.put(CalendarContract.Events.DTEND, endInMillis);
            eventValues.put(CalendarContract.Events.TITLE, "Matrix 2015");
            eventValues.put(CalendarContract.Events.DESCRIPTION,
                    "The official Techfest of Sardar Patel Institute of Technology");
            eventValues.put(CalendarContract.Events.CALENDAR_ID, calID);
            eventValues.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
            AddReminderAsyncHandler eventAdder = new AddReminderAsyncHandler(getContentResolver());
            eventAdder.startInsert(1, null, CalendarContract.Events.CONTENT_URI, eventValues);
            Uri uri = getContentResolver().insert(CalendarContract.Events.CONTENT_URI, eventValues);
            long eventID = Long.parseLong(uri.getLastPathSegment());
            ContentValues reminderValues = new ContentValues();
            reminderValues.put(CalendarContract.Reminders.MINUTES, 60);
            reminderValues.put(CalendarContract.Reminders.EVENT_ID, eventID);
            reminderValues.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
            AddReminderAsyncHandler reminderAdder = new AddReminderAsyncHandler(getContentResolver());
            reminderAdder.startInsert(2, null, CalendarContract.Reminders.CONTENT_URI, reminderValues);
            beginTime.set(2015, 9, 10, 9, 00);
            endTime.set(2015, 9, 10, 5, 00);
            startInMillis = beginTime.getTimeInMillis();
            endInMillis = endTime.getTimeInMillis();
            eventValues.clear();
            eventValues.put(CalendarContract.Events.DTSTART, startInMillis);
            eventValues.put(CalendarContract.Events.DTEND, endInMillis);
            eventValues.put(CalendarContract.Events.TITLE, "Matrix 2015");
            eventValues.put(CalendarContract.Events.DESCRIPTION,
                    "The official Techfest of Sardar Patel Institute of Technology");
            eventValues.put(CalendarContract.Events.CALENDAR_ID, calID);
            eventValues.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
            eventAdder.startInsert(3, null, CalendarContract.Events.CONTENT_URI, eventValues);
            uri = getContentResolver().insert(CalendarContract.Events.CONTENT_URI, eventValues);
            eventID = Long.parseLong(uri.getLastPathSegment());
            reminderValues.clear();
            reminderValues.put(CalendarContract.Reminders.MINUTES, 60);
            reminderValues.put(CalendarContract.Reminders.EVENT_ID, eventID);
            reminderValues.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
            reminderAdder.startInsert(4, null, CalendarContract.Reminders.CONTENT_URI, reminderValues);
            reminderAdded = true;
        }
    }
    //
    //        mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    //        mAdapter = new YourPagerAdapter(getSupportFragmentManager());
    //        mPager = (ViewPager) findViewById(R.id.view_pager);
    //        mPager.setAdapter(mAdapter);
    //        //Notice how the Tab Layout links with the Pager Adapter
    //        mTabLayout.setTabsFromPagerAdapter(mAdapter);
    //
    //        //Notice how The Tab Layout adn View Pager object are linked
    //        mTabLayout.setupWithViewPager(mPager);
    //        mPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
    //
    //
    //
    //        content = findViewById(R.id.content);
    //
    //        final ImageView avatar = (ImageView) findViewById(R.id.avatar);
    //        Picasso.with(this).load(AVATAR_URL).transform(new CircleTransform()).into(avatar);
}

From source file:de.hshannover.f4.trust.ironcontrol.view.AdvancedRequestFragment.java

public String saveSubscribtion(String savedName) {
    if (!isNameValid(savedName)) {
        return null;
    }/*from w ww . ja  va 2 s . com*/

    String id = getExistSubscriptionId(savedName);

    if (id != null) {
        return id;
    }

    String startIdentifier = sStartIdentifier.getSelectedItem().toString();
    String startIdentifierValue = etStartIdentifier.getText().toString();
    String matchLinks = etMatchLinks.getText().toString();
    String resultFilter = etResultFilter.getText().toString();
    int maxDepth = sbMaxDepth.getProgress();
    int maxSize = sbMaxSize.getProgress() * 1000;
    String terminalIdentifiers = terminalIdentifierTypesToString();

    ContentValues publishValues = new ContentValues();
    publishValues.put(Requests.COLUMN_NAME, savedName);
    publishValues.put(Requests.COLUMN_IDENTIFIER1, startIdentifier);
    publishValues.put(Requests.COLUMN_IDENTIFIER1_Value, startIdentifierValue);
    publishValues.put(Requests.COLUMN_MATCH_LINKS, matchLinks);
    publishValues.put(Requests.COLUMN_RESULT_FILTER, resultFilter);
    publishValues.put(Requests.COLUMN_MAX_DEPTH, maxDepth);
    publishValues.put(Requests.COLUMN_MAX_SITZ, maxSize);
    publishValues.put(Requests.COLUMN_TERMINAL_IDENTIFIER_TYPES, terminalIdentifiers);

    Uri returnUri = getActivity().getContentResolver().insert(DBContentProvider.SUBSCRIPTION_URI,
            publishValues);
    return returnUri.getLastPathSegment();

}

From source file:org.teleportr.Ride.java

public Ride from(Uri from) {
    return from(Integer.parseInt(from.getLastPathSegment()));
}

From source file:com.musenkishi.wally.fragments.LatestFragment.java

@Override
public boolean handleMessage(Message msg) {
    switch (msg.what) {

    case MSG_GET_IMAGES:
        final int index = msg.arg1;
        WallyApplication.getDataProviderInstance().getImages(NetworkDataProvider.PATH_LATEST, index,
                WallyApplication.getFilterSettings(), new DataProvider.OnImagesReceivedListener() {
                    @Override/*from  www.  ja v a  2 s .  co  m*/
                    public void onImagesReceived(ArrayList<Image> images) {
                        Message msgObj = uiHandler.obtainMessage();
                        msgObj.what = index == 1 ? MSG_IMAGES_REQUEST_CREATE : MSG_IMAGES_REQUEST_APPEND;
                        msgObj.obj = images;
                        uiHandler.sendMessage(msgObj);
                    }

                    @Override
                    public void onError(DataProviderError dataProviderError) {
                        showError(dataProviderError, index);
                    }
                });
        break;

    case MSG_SAVE_BUTTON_CLICKED:
        Image image = (Image) msg.obj;
        WallyApplication.getDataProviderInstance().getPageData(image.imagePageURL(),
                new DataProvider.OnPageReceivedListener() {
                    @Override
                    public void onPageReceived(ImagePage imagePage) {
                        Message msgImagePage = uiHandler.obtainMessage();
                        msgImagePage.what = MSG_PAGE_RECEIVED;
                        msgImagePage.obj = imagePage;
                        uiHandler.sendMessage(msgImagePage);
                    }

                    @Override
                    public void onError(DataProviderError dataProviderError) {
                        Message msgObj = uiHandler.obtainMessage();
                        msgObj.what = MSG_ERROR_IMAGE_SAVING;
                        msgObj.obj = dataProviderError;
                        uiHandler.sendMessage(msgObj);
                    }
                });
        break;

    case MSG_PAGE_RECEIVED:
        ImagePage imagePage = (ImagePage) msg.obj;
        if (imagePage != null) {
            SaveImageRequest saveImageRequest = WallyApplication.getDataProviderInstance()
                    .downloadImageIfNeeded(imagePage.imagePath(), imagePage.imageId(),
                            getResources().getString(R.string.notification_title_image_saving));

            if (saveImageRequest.getDownloadID() != null && getActivity() instanceof MainActivity) {
                WallyApplication.getDownloadIDs().put(saveImageRequest.getDownloadID(), imagePage.imageId());
            } else {
                onFileChange();
            }
        }
        break;

    case MSG_ERROR_IMAGE_REQUEST:
        if (getActivity() != null) {
            DataProviderError dataProviderError = (DataProviderError) msg.obj;
            int imagesIndex = msg.arg1;
            showErrorMessage(dataProviderError, imagesIndex);
        }
        break;

    case MSG_ERROR_IMAGE_SAVING:
        if (getActivity() != null) {
            NotificationProvider notificationProvider = new NotificationProvider();
            notificationProvider.cancelAll(getActivity());
            Toast.makeText(getActivity(), "Couldn't save image", Toast.LENGTH_SHORT).show();
        }
        break;

    case MSG_IMAGES_REQUEST_CREATE:
        ArrayList<Image> images = (ArrayList<Image>) msg.obj;
        boolean shouldScheduleLayoutAnimation = msg.arg1 == 0;
        isLoading = false;
        if (images != null) {
            hideLoader();
            imagesAdapter = new RecyclerImagesAdapter(images, itemSize);
            imagesAdapter.setOnSaveButtonClickedListener(LatestFragment.this);
            imagesAdapter.updateSavedFilesList(savedFiles);
            gridView.setAdapter(imagesAdapter);
            setupAdapter();
            if (shouldScheduleLayoutAnimation) {
                gridView.scheduleLayoutAnimation();
            }
        }
        break;

    case MSG_IMAGES_REQUEST_APPEND:
        ArrayList<Image> extraImages = (ArrayList<Image>) msg.obj;
        isLoading = false;
        if (extraImages != null) {
            hideLoader();
            int endPosition = imagesAdapter.getItemCount();
            ArrayList<Image> currentList = imagesAdapter.getImages();
            currentList.addAll(extraImages);
            imagesAdapter.notifyItemRangeInserted(endPosition, extraImages.size());
        }
        break;

    case MSG_GET_LIST_OF_SAVED_IMAGES:
        Map<String, Boolean> existingFiles = new HashMap<String, Boolean>();

        FileManager fileManager = new FileManager();
        for (Uri uri : fileManager.getFiles()) {
            String filename = uri.getLastPathSegment();
            String[] filenames = filename.split("\\.(?=[^\\.]+$)"); //split filename from it's extension
            existingFiles.put(filenames[0], true);
        }

        Message fileListMessage = uiHandler.obtainMessage();
        fileListMessage.obj = existingFiles;
        fileListMessage.what = MSG_SAVE_LIST_OF_SAVED_IMAGES;
        uiHandler.sendMessage(fileListMessage);
        break;

    case MSG_SAVE_LIST_OF_SAVED_IMAGES:
        savedFiles = (HashMap<String, Boolean>) msg.obj;
        if (imagesAdapter != null) {
            imagesAdapter.updateSavedFilesList(savedFiles);
            imagesAdapter.notifySavedItemsChanged();
        }
        break;
    }
    return false;
}

From source file:com.musenkishi.wally.fragments.ToplistFragment.java

@Override
public boolean handleMessage(Message msg) {
    switch (msg.what) {

    case MSG_GET_IMAGES:
        final int index = msg.arg1;
        WallyApplication.getDataProviderInstance().getImages(NetworkDataProvider.PATH_TOPLIST, index,
                WallyApplication.getFilterSettings(), new DataProvider.OnImagesReceivedListener() {
                    @Override//from www.  j  av  a 2 s . c  o m
                    public void onImagesReceived(ArrayList<Image> images) {
                        Message msgObj = uiHandler.obtainMessage();
                        msgObj.what = index == 1 ? MSG_IMAGES_REQUEST_CREATE : MSG_IMAGES_REQUEST_APPEND;
                        msgObj.obj = images;
                        uiHandler.sendMessage(msgObj);
                    }

                    @Override
                    public void onError(DataProviderError dataProviderError) {
                        showError(dataProviderError, index);
                    }
                });
        break;

    case MSG_SAVE_BUTTON_CLICKED:
        Image image = (Image) msg.obj;
        WallyApplication.getDataProviderInstance().getPageData(image.imagePageURL(),
                new DataProvider.OnPageReceivedListener() {
                    @Override
                    public void onPageReceived(ImagePage imagePage) {
                        Message msgImagePage = uiHandler.obtainMessage();
                        msgImagePage.what = MSG_PAGE_RECEIVED;
                        msgImagePage.obj = imagePage;
                        uiHandler.sendMessage(msgImagePage);
                    }

                    @Override
                    public void onError(DataProviderError dataProviderError) {
                        Message msgObj = uiHandler.obtainMessage();
                        msgObj.what = MSG_ERROR_IMAGE_SAVING;
                        msgObj.obj = dataProviderError;
                        uiHandler.sendMessage(msgObj);
                    }
                });
        break;

    case MSG_PAGE_RECEIVED:
        ImagePage imagePage = (ImagePage) msg.obj;
        if (imagePage != null) {
            SaveImageRequest saveImageRequest = WallyApplication.getDataProviderInstance()
                    .downloadImageIfNeeded(imagePage.imagePath(), imagePage.imageId(),
                            getResources().getString(R.string.notification_title_image_saving));

            if (saveImageRequest.getDownloadID() != null && getActivity() instanceof MainActivity) {
                WallyApplication.getDownloadIDs().put(saveImageRequest.getDownloadID(), imagePage.imageId());
            } else {
                onFileChange();
            }
        }
        break;

    case MSG_ERROR_IMAGE_REQUEST:
        if (getActivity() != null) {
            DataProviderError dataProviderError = (DataProviderError) msg.obj;
            int imagesIndex = msg.arg1;
            showErrorMessage(dataProviderError, imagesIndex);
        }
        break;

    case MSG_ERROR_IMAGE_SAVING:
        if (getActivity() != null) {
            NotificationProvider notificationProvider = new NotificationProvider();
            notificationProvider.cancelAll(getActivity());
            Toast.makeText(getActivity(), "Couldn't save image", Toast.LENGTH_SHORT).show();
        }
        break;

    case MSG_IMAGES_REQUEST_CREATE:
        ArrayList<Image> images = (ArrayList<Image>) msg.obj;
        boolean shouldScheduleLayoutAnimation = msg.arg1 == 0;
        isLoading = false;
        if (images != null) {
            hideLoader();
            imagesAdapter = new RecyclerImagesAdapter(images, itemSize);
            imagesAdapter.setOnSaveButtonClickedListener(ToplistFragment.this);
            imagesAdapter.updateSavedFilesList(savedFiles);
            gridView.setAdapter(imagesAdapter);
            setupAdapter();
            if (shouldScheduleLayoutAnimation) {
                gridView.scheduleLayoutAnimation();
            }
        }
        break;

    case MSG_IMAGES_REQUEST_APPEND:
        ArrayList<Image> extraImages = (ArrayList<Image>) msg.obj;
        isLoading = false;
        if (extraImages != null) {
            hideLoader();
            int endPosition = imagesAdapter.getItemCount();
            ArrayList<Image> currentList = imagesAdapter.getImages();
            currentList.addAll(extraImages);
            imagesAdapter.notifyItemRangeInserted(endPosition, extraImages.size());
        }
        break;

    case MSG_GET_LIST_OF_SAVED_IMAGES:
        Map<String, Boolean> existingFiles = new HashMap<String, Boolean>();

        FileManager fileManager = new FileManager();
        for (Uri uri : fileManager.getFiles()) {
            String filename = uri.getLastPathSegment();
            String[] filenames = filename.split("\\.(?=[^\\.]+$)"); //split filename from it's extension
            existingFiles.put(filenames[0], true);
        }

        Message fileListMessage = uiHandler.obtainMessage();
        fileListMessage.obj = existingFiles;
        fileListMessage.what = MSG_SAVE_LIST_OF_SAVED_IMAGES;
        uiHandler.sendMessage(fileListMessage);
        break;

    case MSG_SAVE_LIST_OF_SAVED_IMAGES:
        savedFiles = (HashMap<String, Boolean>) msg.obj;
        if (imagesAdapter != null) {
            imagesAdapter.updateSavedFilesList(savedFiles);
            imagesAdapter.notifySavedItemsChanged();
        }
        break;
    }
    return false;
}

From source file:com.birdgang.sample.ui.fragment.ViewPagerHeaderVideoFragment.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, eventLogger);
    case C.TYPE_DASH:
        return new DashMediaSource(uri, buildDataSourceFactory(false),
                new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
    case C.TYPE_HLS:
        return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger);
    case C.TYPE_OTHER:
        return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
                mainHandler, eventLogger);
    default: {/*from   w  w  w  .  j  av a 2 s  . c  o m*/
        throw new IllegalStateException("Unsupported type: " + type);
    }
    }
}

From source file:org.godotengine.godot.storage.UploadService.java

private void uploadFromUri(final Uri fileUri, final String folder, final String meta) {
    Utils.d("SD:UploadFromUri:src:" + fileUri.toString());

    taskStarted();//from  ww  w  .  jav  a2 s  .com
    showProgressNotification("progress_uploading", 0, 0);

    // Get a reference to store file at photos/<FILENAME>.jpg
    final StorageReference photoRef;

    if (folder.equals("")) {
        photoRef = mStorageRef.child(fileUri.getLastPathSegment());
    } else {
        photoRef = mStorageRef.child(folder).child(fileUri.getLastPathSegment());
    }

    // Upload file to Firebase Storage
    Utils.d("SD:UploadFromUri:dist:" + photoRef.getPath());

    UploadTask task;

    if (meta.equals("")) {
        task = photoRef.putFile(fileUri);
    } else {
        StorageMetadata metadata = new StorageMetadata.Builder().setContentType(meta).build();

        task = photoRef.putFile(fileUri, metadata);
    }

    task.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
            showProgressNotification("progress_uploading", taskSnapshot.getBytesTransferred(),
                    taskSnapshot.getTotalByteCount());
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            // Upload succeeded
            Utils.d("SD:UploadFromUri:onSuccess");

            // Get the public download URL
            Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();

            broadcastUploadFinished(downloadUri, fileUri);
            showUploadFinishedNotification(downloadUri, fileUri);
            taskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Upload failed
            Utils.w("SD:UploadFromUri:onFailure:" + exception.toString());

            broadcastUploadFinished(null, fileUri);
            showUploadFinishedNotification(null, fileUri);

            taskCompleted();
        }
    });
}