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:im.ene.lab.attiq.ui.activities.DeepLinkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Uri data = getIntent().getData();
    String scheme = data.getScheme();
    List<String> paths = data.getPathSegments();
    if (SCHEME_INTERNAL.equals(scheme)) {
        if (!UIUtil.isEmpty(paths)) {
            if (TYPE_TAG.equals(paths.get(0))) {
                String lastPath = data.getLastPathSegment();
                TaskStackBuilder.create(this).addParentStack(TagItemsActivity.class)
                        .addNextIntent(TagItemsActivity.createIntent(this, lastPath)).startActivities();
            } else if (TYPE_USER.equals(paths.get(0))) {
                String lastPath = data.getLastPathSegment();
                startActivity(ProfileActivity.createIntent(this, lastPath));
            }//from w  w  w .  ja v a2  s .  co m
        }
    } else if (SCHEME_HTTP.equals(scheme) || SCHEME_HTTPS.equals(scheme)) {
        if (!UIUtil.isEmpty(paths)) {
            Iterator<String> iterator = paths.iterator();
            String id = null;
            while (iterator.hasNext()) {
                if (TYPE_ITEMS.equals(iterator.next())) {
                    id = iterator.next();
                    break;
                }
            }

            if (id != null) {
                TaskStackBuilder.create(this).addParentStack(ItemDetailActivity.class)
                        .addNextIntent(ItemDetailActivity.createIntent(this, id)).startActivities();
                // startActivity(ItemDetailActivity.createIntent(this, id));
            }
        }
    }

    finish();
}

From source file:util.CalendarExporter.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private long pushAppointmentsToCalender(final LvPlanEntries entry) {
    try {/*from w  ww  .ja v  a2 s. com*/
        if (ics) {
            ContentValues eventValues = new ContentValues();
            //The _ID of the calendar the event belongs to --> Primary == 1
            eventValues.put("calendar_id", calendarID);
            eventValues.put(CalendarContract.Events.TITLE, entry.getSummary());
            eventValues.put(CalendarContract.Events.DESCRIPTION, MARKER); //used to find again !?!?
            eventValues.put(CalendarContract.Events.EVENT_LOCATION, entry.getLocation());
            eventValues.put(CalendarContract.Events.DTSTART, entry.getFromDate().getTimeInMillis()); //The time the event starts in UTC millis since epoch
            eventValues.put(CalendarContract.Events.DTEND, entry.getToDate().getTimeInMillis());
            //eventValues.put("eventStatus", status);
            //eventValues.put(CalendarContract.Events.VISIBLE, 0); // visibility to default (0),
            // confidential (1), private
            // (2), or public (3):
            //eventValues.put("transparency", 0); // You can control whether
            // an event consumes time
            // opaque (0) or transparent
            // (1).
            eventValues.put(CalendarContract.Events.HAS_ALARM, 0); // 0 for false, 1 for true
            TimeZone timeZone = TimeZone.getDefault();
            eventValues.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());

            Uri uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI, eventValues);
            return Long.parseLong(uri.getLastPathSegment());
        } else {
            ContentValues eventValues = new ContentValues();
            //The _ID of the calendar the event belongs to --> Primary == 1
            eventValues.put("calendar_id", calendarID);
            eventValues.put("title", entry.getSummary());
            eventValues.put("description", MARKER); //used to find again !?!?
            eventValues.put("eventLocation", entry.getLocation());
            eventValues.put("dtstart", entry.getFromDate().getTimeInMillis()); //The time the event starts in UTC millis since epoch
            eventValues.put("dtend", entry.getToDate().getTimeInMillis());
            //eventValues.put("eventStatus", status);
            eventValues.put("visibility", 0); // visibility to default (0),
                                              // confidential (1), private
                                              // (2), or public (3):
                                              //eventValues.put("transparency", 0); // You can control whether
                                              // an event consumes time
                                              // opaque (0) or transparent
                                              // (1).
            eventValues.put("hasAlarm", 0); // 0 for false, 1 for true
            Uri eventUri = appContext.getContentResolver().insert(Uri.parse(URI_CALENDAR), eventValues);
            long eventID = Long.parseLong(eventUri.getLastPathSegment());

            return eventID;
        }
    } catch (Exception ex) {
        Log.d("Add Event", "Error", ex);
        return -1;
    }
}

From source file:com.android.gallery3d.app.AbstractGalleryActivity.java

public void printSelectedImage(Uri uri) {
    if (uri == null) {
        return;/*from   www.  j av  a 2  s.co m*/
    }
    String path = ImageLoader.getLocalPathFromUri(this, uri);
    if (path != null) {
        Uri localUri = Uri.parse(path);
        path = localUri.getLastPathSegment();
    } else {
        path = uri.getLastPathSegment();
    }
    PrintHelper printer = new PrintHelper(this);
    try {
        printer.printBitmap(path, uri);
    } catch (FileNotFoundException fnfe) {
        Log.e(TAG, "Error printing an image", fnfe);
    }
}

From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java

/**
 * Executes the query to loan out the book
 *///from   ww  w  .j av  a2s.  co  m
private void loanBook(int mYear, int mMonth, int mDay) {
    // set the due date
    Calendar c = Calendar.getInstance();
    c.set(mYear, mMonth, mDay);

    // gets the uri path to the user selected
    Uri user = loanData.getData();

    // gets the user id
    String id = user.getLastPathSegment();

    // prepare the query
    ContentValues values = new ContentValues();
    values.put(PapyrusContentProvider.Loans.FIELD_BOOK_ID, selectedBookID);
    values.put(PapyrusContentProvider.Loans.FIELD_CONTACT_ID, id);
    values.put(PapyrusContentProvider.Loans.FIELD_LEND_DATE, System.currentTimeMillis());
    values.put(PapyrusContentProvider.Loans.FIELD_DUE_DATE, c.getTimeInMillis());

    // insert the entry in the database, and get the new loan id
    Uri newLoan = resolver.insert(PapyrusContentProvider.Loans.CONTENT_URI, values);
    int loanID = (int) ContentUris.parseId(newLoan);

    // Book book = new Book(isbn10, title, author);
    Loan loan = new Loan(loanID, values.getAsInteger(PapyrusContentProvider.Loans.FIELD_BOOK_ID),
            values.getAsInteger(PapyrusContentProvider.Loans.FIELD_CONTACT_ID),
            values.getAsLong(PapyrusContentProvider.Loans.FIELD_LEND_DATE),
            values.getAsLong(PapyrusContentProvider.Loans.FIELD_DUE_DATE));

    // get an alarm manager
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // create the intent for the alarm
    Intent intent = new Intent(this, AlarmReceiver.class);

    // put the loan object into the alarm receiver
    intent.putExtra("loan", loan);

    // create the pendingIntent to run when the alarm goes off and be handled by a receiver
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
    // set the repeating alarm
    am.set(AlarmManager.RTC, c.getTimeInMillis(), pendingIntent);

    Toast.makeText(this, getString(R.string.BooksBrowser_toast_loanSuccessful), Toast.LENGTH_LONG).show();
}

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

/** {@inheritDoc} */
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    switch (loaderId) {
    case LOADER_HEADER: {
        Uri uri = getIntent().getData();
        String[] projection = { Artists._ID, Artists.IDSTR, Artists.IMAGE, Artists.NAME };
        String selection = String.format("%s=?", JamendoContract.PARAM_IMAGE_SIZE);
        String[] selectionArgs = { getDimensionPixelSizeAsString(R.dimen.image_size) };
        String sortOrder = null;/*from ww w.j  a  va 2s  .  c  o m*/
        return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder);
    }
    case LOADER_LIST: {
        Uri uri = Albums.CONTENT_URI;
        String[] projection = { Albums._ID, Albums.IMAGE, Albums.NAME };
        Uri data = getIntent().getData();
        Long artistId = null;
        String artistIdStr = null;
        try {
            artistId = Long.valueOf(ContentUris.parseId(data));
        } catch (NumberFormatException e) {
            artistIdStr = data.getLastPathSegment();
        }
        String selection = String.format("%s=?&%s=?", artistId != null ? Artists.ID : Artists.IDSTR,
                JamendoContract.PARAM_IMAGE_SIZE);
        String[] selectionArgs = { artistId != null ? artistId.toString() : artistIdStr,
                getDimensionPixelSizeAsString(R.dimen.image_size) };
        String sortOrder = Albums.Order.RELEASEDATE.descending();
        return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder);
    }
    default:
        return null;
    }
}

From source file:com.github.riotopsys.shoppinglist.activity.ShoppingListPreview.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shopping_list_preview);

    AccountUtils accountUtils = new AccountUtils();
    String account = accountUtils.getAccountName(this);

    if (account == null) {
        AccountManager am = AccountManager.get(this);
        am.getAuthTokenByFeatures(AppKeys.ACCOUNT_TYPE, AppKeys.OAUTH2_SCOPE, null, this, null, null,
                new AccountManagerCallback<Bundle>() {
                    @Override/*w w  w  .  j a v  a  2 s .  co m*/
                    public void run(AccountManagerFuture<Bundle> future) {
                        try {
                            Bundle bundle = future.getResult();
                            Log.i(TAG, "Got Bundle:\n" + " act name: "
                                    + bundle.getString(AccountManager.KEY_ACCOUNT_NAME) + "\n act type: "
                                    + bundle.getString(AccountManager.KEY_ACCOUNT_TYPE) + "\n auth token: "
                                    + bundle.getString(AccountManager.KEY_AUTHTOKEN));
                            AccountUtils accountUtils = new AccountUtils();
                            accountUtils.setAccountName(getBaseContext(),
                                    bundle.getString(AccountManager.KEY_ACCOUNT_NAME));
                            accountUtils.setToken(getBaseContext(),
                                    bundle.getString(AccountManager.KEY_AUTHTOKEN));
                        } catch (Exception e) {
                            Log.i(TAG, "getAuthTokenByFeatures() cancelled or failed:", e);
                            Toast.makeText(getBaseContext(), R.string.no_account, Toast.LENGTH_LONG).show();
                            finish();
                        }
                    }
                }, null);
    }

    mShoppingListCollection = new ShoppingListCollection();

    mShoppingListCollectionAdapter = new ShoppingListCollectionAdapter(this, getSupportFragmentManager(),
            mShoppingListCollection);

    //      mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mShoppingListCollectionAdapter);

    Intent startingIntent = getIntent();
    if (startingIntent != null) {
        Uri data = startingIntent.getData();
        if (data != null) {
            UUID guid = UUID.fromString(data.getLastPathSegment());
            Intent i = new Intent(this, ServerInterfaceService.class);
            i.putExtra(AppKeys.SERVER_TASK_KEY, ServerTask.SUBSCRIBE);
            i.putExtra(AppKeys.GUID_KEY, guid);
            startService(i);
        }
    }

    IConfigurations config = new Configurations();

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);
    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
        GCMRegistrar.register(this, config.getGCMSenderID());
    } else {
        Log.v(TAG, "Already registered");
    }

}

From source file:com.example.android.dragonTV.ui.MovieDetailsFragment.java

private boolean checkGlobalSearchIntent() {
    Intent intent = getActivity().getIntent();
    String intentAction = intent.getAction();
    String globalSearch = getString(R.string.global_search);
    if (globalSearch.equalsIgnoreCase(intentAction)) {
        Uri intentData = intent.getData();
        Log.d(TAG, "action: " + intentAction + " intentData:" + intentData);
        int selectedIndex = Integer.parseInt(intentData.getLastPathSegment());
        HashMap<String, List<Movie>> movies = VideoProvider.getMovieList();
        int movieTally = 0;
        if (movies == null) {
            return false;
        }//from  ww w  .  jav a  2  s . co  m
        for (Map.Entry<String, List<Movie>> entry : movies.entrySet()) {
            List<Movie> list = entry.getValue();
            for (Movie movie : list) {
                movieTally++;
                if (selectedIndex == movieTally) {
                    mSelectedMovie = movie;
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.treefrogapps.friendlychat.MainActivity.java

private void uploadToFirebase(Uri imageUri) {
    StorageReference reference = storageReference.child(imageUri.getLastPathSegment());
    reference.putFile(imageUri).addOnSuccessListener(uploadSuccessListener)
            .addOnFailureListener(uploadFailureListener);
}

From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.LibraryCursorAdapter.java

@Override
protected void updateIcon(TwoLinesViewHolder vh, Cursor cursor) {
    String data = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
    File f = new File(data);

    switch (mediaTypeId) {
    case MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE:
        vh.icon.setImageResource(R.drawable.mime_img);
        renditionManager.getPicasso().load(f).resize(150, 150).centerCrop().placeholder(R.drawable.mime_256_img)
                .error(R.drawable.mime_256_img).into(vh.icon);
        break;/* w ww  . j a v  a 2 s .c o  m*/
    case MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO:
        vh.icon.setImageResource(R.drawable.mime_video);
        break;
    case MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO:
        vh.icon.setImageResource(R.drawable.mime_audio);
        break;
    default:
        Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)));
        vh.icon.setImageResource(MimeTypeManager.getInstance(context).getIcon(uri.getLastPathSegment()));
        break;
    }

    if (mode == FileExplorerFragment.MODE_LISTING && fragmentRef.get().getActivity() instanceof MainActivity) {
        vh.choose.setImageResource(R.drawable.ic_more_options);
        vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light);
        int d_16 = DisplayUtils.getPixels(context, R.dimen.d_16);
        vh.choose.setPadding(d_16, d_16, d_16, d_16);
        vh.choose.setVisibility(View.VISIBLE);
        vh.choose.setTag(R.id.node_action, f);
        vh.choose.setOnClickListener(new OnClickListener() {

            @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            @Override
            public void onClick(View v) {
                File item = (File) v.getTag(R.id.node_action);
                selectedOptionItems.add(item);
                PopupMenu popup = new PopupMenu(context, v);
                getMenu(popup.getMenu(), item);
                popup.setOnDismissListener(new OnDismissListener() {
                    @Override
                    public void onDismiss(PopupMenu menu) {
                        selectedOptionItems.clear();
                    }
                });

                popup.setOnMenuItemClickListener(LibraryCursorAdapter.this);

                popup.show();
            }
        });
    } else {
        UIUtils.setBackground(vh.choose, null);
        vh.choose.setVisibility(View.GONE);
    }
}

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

public String saveSearch(String savedName) {
    if (!isNameValid(savedName)) {
        return null;
    }//  w  w  w. ja v a  2  s .c  o m

    String id = getExistSearchId(savedName);

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

    String startIdentifier = sStartIdentifier.getSelectedItem().toString();
    String startIdentifierValue = etStartIdentifier.getText().toString();
    int maxDepth = sbMaxDepth.getProgress();

    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_MAX_DEPTH, maxDepth);

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