Example usage for android.net Uri getPathSegments

List of usage examples for android.net Uri getPathSegments

Introduction

In this page you can find the example usage for android.net Uri getPathSegments.

Prototype

public abstract List<String> getPathSegments();

Source Link

Document

Gets the decoded path segments.

Usage

From source file:com.android.calendar.EventInfoActivity.java

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

    // Get the info needed for the fragment
    Intent intent = getIntent();//  w  w  w . j av a 2 s.co  m
    int attendeeResponse = 0;
    mEventId = -1;
    boolean isDialog = false;
    ArrayList<ReminderEntry> reminders = null;

    if (icicle != null) {
        mEventId = icicle.getLong(EventInfoFragment.BUNDLE_KEY_EVENT_ID);
        mStartMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_START_MILLIS);
        mEndMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_END_MILLIS);
        attendeeResponse = icicle.getInt(EventInfoFragment.BUNDLE_KEY_ATTENDEE_RESPONSE);
        isDialog = icicle.getBoolean(EventInfoFragment.BUNDLE_KEY_IS_DIALOG);

        reminders = Utils.readRemindersFromBundle(icicle);
    } else if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
        mStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
        mEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
        attendeeResponse = intent.getIntExtra("attendeeStatus", Attendees.ATTENDEE_STATUS_NONE);
        Uri data = intent.getData();
        if (data != null) {
            try {
                List<String> pathSegments = data.getPathSegments();
                int size = pathSegments.size();
                if (size > 2 && "EventTime".equals(pathSegments.get(2))) {
                    // Support non-standard VIEW intent format:
                    // dat =
                    // content://com.android.calendar/events/[id]/EventTime/[start]/[end]
                    mEventId = Long.parseLong(pathSegments.get(1));
                    if (size > 4) {
                        mStartMillis = Long.parseLong(pathSegments.get(3));
                        mEndMillis = Long.parseLong(pathSegments.get(4));
                    }
                } else {
                    mEventId = Long.parseLong(data.getLastPathSegment());
                }
            } catch (NumberFormatException e) {
                if (mEventId == -1) {
                    // do nothing here , deal with it later
                } else if (mStartMillis == 0 || mEndMillis == 0) {
                    // Parsing failed on the start or end time , make sure
                    // the times were not
                    // pulled from the intent's extras and reset them.
                    mStartMillis = 0;
                    mEndMillis = 0;
                }
            }
        }
    }

    if (mEventId == -1) {
        Log.w(TAG, "No event id");
        Toast.makeText(this, R.string.event_not_found, Toast.LENGTH_SHORT).show();
        finish();
    }

    // If we do not support showing full screen event info in this
    // configuration,
    // close the activity and show the event in AllInOne.
    Resources res = getResources();
    if (!res.getBoolean(R.bool.agenda_show_event_info_full_screen)
            && !res.getBoolean(R.bool.show_event_info_full_screen)) {
        CalendarController.getInstance(this).launchViewEvent(mEventId, mStartMillis, mEndMillis,
                attendeeResponse);
        finish();
        return;
    }

    setContentView(R.layout.simple_frame_layout);

    // Get the fragment if exists
    mInfoFragment = (EventInfoFragment) getSupportFragmentManager().findFragmentById(R.id.main_frame);

    // Remove the application title
    ActionBar bar = getActionBar();
    if (bar != null) {
        bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP);
    }

    // Create a new fragment if none exists
    if (mInfoFragment == null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis, attendeeResponse,
                isDialog,
                (isDialog ? EventInfoFragment.DIALOG_WINDOW_STYLE : EventInfoFragment.FULL_WINDOW_STYLE),
                reminders);
        ft.replace(R.id.main_frame, mInfoFragment);
        ft.commit();
    }
}

From source file:com.ratebeer.android.gui.Home.java

protected void handleStartIntent() {

    firstStart = false;//from w  w  w  .j  a v a2  s .  c  o  m

    // Start a search?
    if (getIntent().hasExtra(SearchManager.QUERY)) {
        load(SearchFragment_.builder().query(getIntent().getStringExtra(SearchManager.QUERY)).build());
        return;
    }

    // See if some concrete action was requested (such as from the background poster service)
    String action = getIntent().getAction();
    action = action == null ? "" : action;
    Uri data = getIntent().getData();

    // Open details for some specific beer
    if (action.equals(Intent.ACTION_VIEW) && data != null) {
        List<String> segments = data.getPathSegments();
        if (segments.size() > 1) {
            try {
                int beerId = Integer.parseInt(segments.get(1));
                load(BeerViewFragment_.builder().beerId(beerId).build());
                return;
            } catch (NumberFormatException e) {
                Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME,
                        "Invalid ACTION_VIEW Intent data; " + segments.get(1) + " is not a number.");
            }
        }
    }

    // Open the rating screen for a beer
    if (action.equals(PosterService.ACTION_EDITRATING)) {
        load(RateFragment_.buildFromExtras(getIntent().getExtras()));
        return;
    }

    // Open the add UPC code screen again; this assumes the UPC code is given in the extras
    if (action.equals(PosterService.ACTION_ADDUPCCODE)) {
        load(AddUpcCodeFragment_.builder().upcCode(getIntent().getStringExtra(PosterService.EXTRA_UPCCODE))
                .build());
        return;
    }

    // Open the beermails screen
    if (action.equals(BeermailService.ACTION_VIEWBEERMAILS)) {
        load(MailsFragment_.builder().build());
        return;
    }

    // Open the beermail screen to a specific mail
    if (action.equals(BeermailService.ACTION_VIEWBEERMAIL)) {
        load(MailViewFragment_.buildFromExtras(getIntent().getExtras()));
        return;
    }

    // Open the beermail send mail screen to reply to a specific mail
    if (action.equals(BeermailService.ACTION_REPLYBEERMAIL)) {
        load(SendMailFragment.buildReplyFromExtras(getIntent().getExtras()));
        return;
    }

    // Open the beermail send mail screen to recover a failed send
    if (action.equals(PosterService.ACTION_SENDMAIL)) {
        load(SendMailFragment.buildFromFailedSend(getIntent().getExtras()));
        return;
    }

    // Normal startup; show dashboard
    load(DashboardFragment_.builder().build());

}

From source file:com.silverpop.engage.deeplinking.EngageDeepLinkManager.java

Uri trimDeeplink(Uri deeplink) {
    String host = deeplink.getHost();
    List<String> pathSegments = new LinkedList<String>(deeplink.getPathSegments());
    if (pathSegments.isEmpty()) {
        // trim off host
        if (!TextUtils.isEmpty(host)) {
            host = null;/* w  ww .jav  a2  s .  c o  m*/
        }
    }

    for (int i = pathSegments.size() - 1; i >= 0; i--) {
        // remove trailing slashes
        if (pathSegments.get(i).equals("/")) {
            pathSegments.remove(i);
        } else {
            pathSegments.remove(i);
            break;
        }
    }

    String pathString = "";
    for (int i = 0; i < pathSegments.size(); i++) {
        pathString += "/";
        pathString += pathSegments.get(i);
    }

    Uri.Builder builder = new Uri.Builder();
    builder.scheme(deeplink.getScheme());
    builder.path(pathString);
    builder.query(deeplink.getQuery());

    return builder.build();
}

From source file:com.xabber.android.ui.activity.ContactViewer.java

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

    if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        // View information about contact from system contact list
        Uri data = getIntent().getData();
        if (data != null && "content".equals(data.getScheme())) {
            List<String> segments = data.getPathSegments();
            if (segments.size() == 2 && "data".equals(segments.get(0))) {
                Long id;//from   w w  w .  j a v a2s . c o  m
                try {
                    id = Long.valueOf(segments.get(1));
                } catch (NumberFormatException e) {
                    id = null;
                }
                if (id != null)
                    // FIXME: Will be empty while application is loading
                    for (RosterContact rosterContact : RosterManager.getInstance().getContacts())
                        if (id.equals(rosterContact.getViewId())) {
                            account = rosterContact.getAccount();
                            bareAddress = rosterContact.getUser();
                            break;
                        }
            }
        }
    } else {
        account = getAccount(getIntent());
        bareAddress = getUser(getIntent());
    }

    if (bareAddress != null && bareAddress.equalsIgnoreCase(GroupManager.IS_ACCOUNT)) {
        bareAddress = Jid.getBareAddress(AccountManager.getInstance().getAccount(account).getRealJid());
    }

    if (account == null || bareAddress == null) {
        Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
        finish();
        return;
    }

    setContentView(R.layout.contact_viewer);

    if (savedInstanceState == null) {

        Fragment fragment;
        if (MUCManager.getInstance().hasRoom(account, bareAddress)) {
            fragment = ConferenceInfoFragment.newInstance(account, bareAddress);
        } else {
            fragment = ContactVcardViewerFragment.newInstance(account, bareAddress);
        }

        getFragmentManager().beginTransaction().add(R.id.scrollable_container, fragment).commit();

    }

    bestContact = RosterManager.getInstance().getBestContact(account, bareAddress);

    toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(ContactViewer.this);
        }
    });

    StatusBarPainter statusBarPainter = new StatusBarPainter(this);
    statusBarPainter.updateWithAccountName(account);

    final int accountMainColor = ColorManager.getInstance().getAccountPainter().getAccountMainColor(account);

    contactTitleView = findViewById(R.id.contact_title_expanded);
    findViewById(R.id.status_icon).setVisibility(View.GONE);
    contactTitleView.setBackgroundColor(accountMainColor);
    TextView contactNameView = (TextView) findViewById(R.id.name);
    contactNameView.setVisibility(View.INVISIBLE);

    collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(bestContact.getName());

    collapsingToolbar.setBackgroundColor(accountMainColor);
    collapsingToolbar.setContentScrimColor(accountMainColor);
}

From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivity.java

/**
 * View record by id contained in Uri/*from  ww w  .ja v a  2  s .  c  o m*/
 * @param uri Uri appended with record id
 * @param ticket Intent tracker id
 */
void viewUri(Uri uri, int ticket) {
    int nodeId = 0;
    String errorMessage = null;
    // Handles a click on a search suggestion
    if (uri.getPathSegments().size() < 2)
        errorMessage = "Invalid resource address: \"" + uri.toString() + "\"";
    else
        try {
            nodeId = Integer.parseInt(uri.getPathSegments().get(1));
        } catch (NumberFormatException e) {
            errorMessage = "Resource address has invalid ID: \"" + uri.toString() + "\"";
        }
    if (errorMessage != null) {
        showTitle(RECORD_NOT_FOUND);
        displayToast(errorMessage);
        ticketManager.removeIntent(ticket);
    } else
        displayNodeDetails(nodeId, ticket);
}

From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java

private void handleIntent(Intent intent) {
    String id = null;/* w w w  . ja  v a2  s  .  c  om*/
    if (intent != null) {
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            // only one message sent during the beam
            NdefMessage msg = (NdefMessage) rawMsgs[0];
            // record 0 contains the MIME type, record 1 is the AAR, if present
            id = new String(msg.getRecords()[0].getPayload());
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            id = StringUtils.defaultIfBlank(intent.getDataString(), intent.getStringExtra(RECORD_ID));
        }
        if (StringUtils.contains(id, "europeana.eu/")) {
            Uri uri = Uri.parse(id);
            List<String> paths = uri.getPathSegments();
            if ((paths != null) && (paths.size() == 4)) {
                String collectionId = paths.get(paths.size() - 2);
                String recordId = StringUtils.removeEnd(paths.get(paths.size() - 1), ".html");
                id = StringUtils.join("/", collectionId, "/", recordId);
            } else {
                // invalid url/id, cancel opening record
                id = null;
            }
        }
        if (StringUtils.isNotBlank(id)) {
            openRecord(id);
        }
    }
}

From source file:com.manning.androidhacks.hack043.provider.MySQLContentProvider.java

@Override
protected int deleteInTransaction(Uri uri, String selection, String[] selectionArgs) {

    int count;//from   w  w  w.  j  a v a  2  s. com

    switch (sUriMatcher.match(uri)) {
    case ITEM:
        count = mDb.delete(TABLE_NAME, selection, selectionArgs);
        break;
    case ITEM_ID:
        String id = uri.getPathSegments().get(1);
        count = mDb.delete(TABLE_NAME,
                COLUMN_ID + "=" + id + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : ""),
                selectionArgs);
        break;
    default:
        throw new RuntimeException("Unkown URI: " + uri);
    }

    return count;
}

From source file:au.id.micolous.frogjump.LoginActivity.java

private boolean resolveIntent(Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_VIEW)) {
        final Uri intentUri = intent.getData();

        if (intentUri.getHost().endsWith("frjmp.xyz")) {
            // Known host, figure out our action!
            List<String> pathSegments = intentUri.getPathSegments();
            if (pathSegments.get(0).equalsIgnoreCase("g")) {
                // Join Group (G)
                // Parameter 1 is the group number, prefill the box with it.

                // Make sure it is a number
                int group_id;
                try {
                    group_id = Integer.valueOf(pathSegments.get(1));
                } catch (NumberFormatException ex) {
                    return false;
                }// w  w w  . ja va2s  .c  o  m

                // Now set the text field
                txtGroupId.setText(String.format("%1$09d", group_id));

                // Make sure futures are set to auto-join
                auto_join = true;
            }
        }

    }

    return false;
}

From source file:felixwiemuth.lincal.ui.HtmlDialogFragment.java

private boolean loadUrl(WebView webView, Uri uri) {
    if (uri.getScheme().equals("file")) {
        webView.loadUrl(uri.toString());
    } else if (uri.getScheme().equals("action")) {
        List<String> segments = uri.getPathSegments();
        if (segments.isEmpty()) {
            throw new RuntimeException("Error in WebView: No action name provided.");
        } else {//from w w  w.  j a  va 2 s  .c  o m
            handleAction(segments.get(0), segments.subList(1, segments.size()));
        }
    } else {
        // If the URI is not pointing to a local file, open with an ACTION_VIEW Intent
        webView.getContext().startActivity(new Intent(Intent.ACTION_VIEW, uri));
    }
    return true; // in both cases we handle the link manually
}

From source file:org.ohmage.app.OhmletActivity.java

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

    mLoadingView = findViewById(R.id.loading);

    String action = getIntent().getAction();
    Bundle extras = new Bundle();
    Uri data = getIntent().getData();
    if (data.getScheme().equals("https") || data.getScheme().equals("http")) {
        if (data.getPathSegments().size() > 3) {
            if (data.getPathSegments().get(3).equals("invitation")) {
                action = OhmletFragment.ACTION_JOIN;
            }/*from  w  w w . j a  v  a 2  s  . co  m*/
        }
        extras.putString(OhmletFragment.EXTRA_OHMLET_INVITATION_ID,
                data.getQueryParameter("ohmlet_invitation_id"));
        extras.putString(AuthenticatorActivity.EXTRA_USER_INVITATION_CODE,
                data.getQueryParameter("user_invitation_id"));
        extras.putString(AuthenticatorActivity.EXTRA_EMAIL, data.getQueryParameter("email"));
        data = Ohmlets.getUriForOhmletId(data.getPathSegments().get(2));
    }

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, OhmletFragment.getInstance(action, data, extras)).commit();
    }
}