Example usage for android.net Uri getQueryParameter

List of usage examples for android.net Uri getQueryParameter

Introduction

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

Prototype

@Nullable
public String getQueryParameter(String key) 

Source Link

Document

Searches the query string for the first value with the given key.

Usage

From source file:com.pindroid.activity.BrowseBookmarks.java

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

    Intent intent = getIntent();// w w w .j ava2  s.  c  om

    Uri data = intent.getData();
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction t = fm.beginTransaction();

    if (fm.findFragmentById(R.id.listcontent) == null) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            Bundle searchData = intent.getBundleExtra(SearchManager.APP_DATA);

            if (searchData != null) {
                tagname = searchData.getString("tagname");
                app.setUsername(searchData.getString("username"));
                unread = searchData.getBoolean("unread");
            }

            query = intent.getStringExtra(SearchManager.QUERY);

            if (intent.hasExtra("username")) {
                app.setUsername(intent.getStringExtra("username"));
            }

            if (data != null) {
                feed = data.getQueryParameter("feed");

                if (data.getUserInfo() != null) {
                    app.setUsername(data.getUserInfo());
                }
            }
        } else {
            if (data != null) {
                tagname = data.getQueryParameter("tagname");
                feed = data.getQueryParameter("feed");
                unread = data.getQueryParameter("unread") != null;
                path = data.getPath();
            }
        }

        if (feed == null || feed.equals("")) {
            bookmarkFrag = new BrowseBookmarksFragment();
        } else {
            bookmarkFrag = new BrowseBookmarkFeedFragment();
        }

        t.add(R.id.listcontent, bookmarkFrag);
    } else {
        if (savedInstanceState != null) {
            tagname = savedInstanceState.getString(STATE_TAGNAME);
            unread = savedInstanceState.getBoolean(STATE_UNREAD);
            query = savedInstanceState.getString(STATE_QUERY);
            path = savedInstanceState.getString(STATE_PATH);
            feed = savedInstanceState.getString(STATE_FEED);
        }

        bookmarkFrag = fm.findFragmentById(R.id.listcontent);
    }

    if (feed == null || feed.equals("")) {
        if (query != null && !query.equals("")) {
            ((BrowseBookmarksFragment) bookmarkFrag).setSearchQuery(query, app.getUsername(), tagname, unread);
        } else {
            ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), tagname, unread ? "unread" : null);
        }

        ((BrowseBookmarksFragment) bookmarkFrag).refresh();
    } else {
        if (query == null || query.equals("")) {
            ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), tagname, feed);
        } else {
            ((BookmarkBrowser) bookmarkFrag).setQuery(app.getUsername(), query, feed);
        }
    }

    BrowseTagsFragment tagFrag = (BrowseTagsFragment) fm.findFragmentById(R.id.tagcontent);

    if (tagFrag != null) {
        tagFrag.setAccount(app.getUsername());
    }

    if (path != null && path.contains("tags")) {
        t.hide(fm.findFragmentById(R.id.maincontent));
        findViewById(R.id.panel_collapse_button).setVisibility(View.GONE);
    } else {
        if (tagFrag != null) {
            t.hide(tagFrag);
        }
    }

    Fragment addFrag = fm.findFragmentById(R.id.addcontent);
    if (addFrag != null) {
        t.hide(addFrag);
    }

    t.commit();
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private WebViewClient createWebViewClientThatHandlesFileLinksForCharts() {
    WebViewClient webViewClient = new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);
            if (uri.getScheme().startsWith("http")) {
                return true; // throw away http requests - we don't want 3rd party javascript sending url requests due to security issues.
            }//www  . j  a  va 2  s.  c  o m

            String inputIdStr = uri.getQueryParameter("inputId");
            if (inputIdStr == null) {
                return true;
            }
            long inputId = Long.parseLong(inputIdStr);
            JSONArray results = new JSONArray();
            for (Event event : experiment.getEvents()) {
                JSONArray eventJson = new JSONArray();
                DateTime responseTime = event.getResponseTime();
                if (responseTime == null) {
                    continue; // missed signal;
                }
                eventJson.put(responseTime.getMillis());

                // in this case we are looking for one input from the responses that we are charting.
                for (Output response : event.getResponses()) {
                    if (response.getInputServerId() == inputId) {
                        Input inputById = experiment.getInputById(inputId);
                        if (!inputById.isInvisible() && inputById.isNumeric()) {
                            eventJson.put(response.getDisplayOfAnswer(inputById));
                            results.put(eventJson);
                            continue;
                        }
                    }
                }

            }
            env.put("data", results.toString());
            env.put("inputId", inputIdStr);

            view.loadUrl(stripQuery(url));
            return true;
        }
    };
    return webViewClient;
}

From source file:com.markupartist.sthlmtraveling.RoutesActivity.java

private JourneyQuery getJourneyQueryFromUri(Uri uri) {
    JourneyQuery jq = new JourneyQuery();

    jq.origin = new Planner.Location();
    jq.origin.name = uri.getQueryParameter("start_point");
    if (!TextUtils.isEmpty(uri.getQueryParameter("start_point_id"))) {
        jq.origin.id = Integer.parseInt(uri.getQueryParameter("start_point_id"));
    }//from w  w w  . ja v  a 2s  .c  o  m
    if (!TextUtils.isEmpty(uri.getQueryParameter("start_point_lat"))
            && !TextUtils.isEmpty(uri.getQueryParameter("start_point_lng"))) {
        jq.origin.latitude = (int) (Double.parseDouble(uri.getQueryParameter("start_point_lat")) * 1E6);
        jq.origin.longitude = (int) (Double.parseDouble(uri.getQueryParameter("start_point_lng")) * 1E6);
    }

    jq.destination = new Planner.Location();
    jq.destination.name = uri.getQueryParameter("end_point");
    if (!TextUtils.isEmpty(uri.getQueryParameter("end_point_id"))) {
        jq.destination.id = Integer.parseInt(uri.getQueryParameter("end_point_id"));
    }
    if (!TextUtils.isEmpty(uri.getQueryParameter("end_point_lat"))
            && !TextUtils.isEmpty(uri.getQueryParameter("end_point_lng"))) {
        jq.destination.latitude = (int) (Double.parseDouble(uri.getQueryParameter("end_point_lat")) * 1E6);
        jq.destination.longitude = (int) (Double.parseDouble(uri.getQueryParameter("end_point_lng")) * 1E6);
    }

    jq.isTimeDeparture = true;
    if (!TextUtils.isEmpty(uri.getQueryParameter("isTimeDeparture"))) {
        jq.isTimeDeparture = Boolean.parseBoolean(uri.getQueryParameter("isTimeDeparture"));
    }

    jq.time = new Time();
    String timeString = uri.getQueryParameter("time");
    if (!TextUtils.isEmpty(timeString)) {
        jq.time.parse(timeString);
    } else {
        jq.time.setToNow();
    }

    return jq;
}

From source file:net.sf.fdshare.BaseProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    final String filePath = uri.getPath();
    if (TextUtils.isEmpty(filePath))
        throw new IllegalArgumentException("Empty path!");

    if (projection == null) {
        projection = new String[] { MediaStore.MediaColumns.MIME_TYPE, OpenableColumns.DISPLAY_NAME,
                OpenableColumns.SIZE };/*  w w  w .  jav a  2s  .  c o m*/
    }

    final MatrixCursor result = new MatrixCursor(projection);

    final TimestampedMime info = guessTypeInternal(filePath);

    final Object[] row = new Object[projection.length];
    for (int i = 0; i < projection.length; i++) {
        String projColumn = projection[i];

        if (TextUtils.isEmpty(projColumn))
            continue;

        switch (projColumn.toLowerCase()) {
        case OpenableColumns.DISPLAY_NAME:

            row[i] = uri.getLastPathSegment();

            break;
        case OpenableColumns.SIZE:

            row[i] = info.size >= 0 ? info.size : null;

            break;
        case MediaStore.MediaColumns.MIME_TYPE:

            final String forcedType = uri.getQueryParameter("type");

            if (!TextUtils.isEmpty(forcedType))
                row[i] = "null".equals(forcedType) ? null : forcedType;
            else
                row[i] = info.mime[0];

            break;
        case MediaStore.MediaColumns.DATA:
            Log.w("BaseProvider", "Relying on MediaColumns.DATA is unreliable and must be avoided!");
            row[i] = uri.getPath();
            break;
        }
    }

    result.addRow(row);
    return result;
}

From source file:nl.thehyve.transmartclient.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "--> onCreate called");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FirebaseApp.initializeApp(getApplicationContext());

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w ww.j  a v  a  2  s.co  m

    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
    drawer = (DrawerLayout) findViewById(R.id.main_view);
    toggle = new ActionBarDrawerToggle(this, drawer, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            hideKeyboard();
        }
    };
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    refreshNavigationMenu();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(new OnTransmartNavigationItemSelectedListener(drawer));

    fragmentManager = getSupportFragmentManager();

    if (savedInstanceState == null) {
        Log.d(TAG, "savedInstanceState is null");
        readTransmartServersFromFile();
    }

    //        When the activity is started from the OAuth return URL: Get the code out
    Intent intent = getIntent();
    Uri uri = intent.getData();
    SharedPreferences settings = getPreferences(MODE_PRIVATE);
    boolean oauthCodeUsed = settings.getBoolean("oauthCodeUsed", false);
    boolean receivedURI = false;

    if (uri != null && uri.toString().startsWith("transmart://oauthresponse") && !oauthCodeUsed) {
        //            TODO Show waiting sign: "Connecting to the tranSMART server"

        // Keep in mind that a new instance of the same application has been started
        Log.d(TAG, "Received uri");
        String code = uri.getQueryParameter("code");
        Log.d(TAG, "Received OAuth code: " + code);

        TransmartServer transmartServer = getUniqueConnectionStatus(TransmartServer.ConnectionStatus.SENTTOURL);

        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("oauthCodeUsed", true);
        editor.apply();

        if (code != null) {

            if (transmartServer != null) {
                setUniqueConnectionStatus(transmartServer, TransmartServer.ConnectionStatus.CODERECEIVED);
                Log.d(TAG, "Now the connectionStatus is " + transmartServer.getConnectionStatus());

                Fragment fragment = AddNewServerFragment.newInstance(transmartServer.getServerUrl(),
                        transmartServer.getServerLabel(), true);
                fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                        // Don't add to backstack, always the first fragment of a session
                        .commit();

                new TokenGetterTask(this.getApplicationContext(), transmartServer, CLIENT_ID, CLIENT_SECRET,
                        code).execute();
            } else {
                Log.w(TAG, "No servers with connectionStatus: SENTTOURL");
            }

        } else {
            Log.d(TAG, "Received empty OAuth code");

            if (transmartServer != null) {

                // Show snackbar
                String message = getString(R.string.received_empty_code);
                Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG)
                        .setAction(R.string.snackbar_ok, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                            }
                        }).show();

                if (transmartServer.wasConnected()) {

                    // Set status back to connected
                    transmartServer.setNonUniqueConnectionStatus(TransmartServer.ConnectionStatus.CONNECTED);
                    Log.d(TAG, "Now the connectionStatus is " + transmartServer.getConnectionStatus());

                    // Navigate back to serverOverviewFragment
                    Fragment fragment = ServerOverviewFragment.newInstance(transmartServer);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                            // Don't add to backstack, always the first fragment of a session
                            .commit();
                } else {
                    // Navigate back to AddNewServerFragment with correct values
                    Fragment fragment = AddNewServerFragment.newInstance(transmartServer.getServerUrl(),
                            transmartServer.getServerLabel(), true);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment)
                            // Don't add to backstack, always the first fragment of a session
                            .commit();
                }
            } else {
                Log.w(TAG, "No servers with connectionStatus: SENTTOURL");
            }

        }

        receivedURI = true;
    }

    if (savedInstanceState == null) {
        if (!receivedURI) {
            navigateToBeginState(true);
        }
    }

    mBroadcastMgr = LocalBroadcastManager.getInstance(getApplicationContext());
    tokenReceiver.setTokenReceivedListener(this);
}

From source file:org.opensilk.music.artwork.provider.ArtworkProvider.java

@Override
//@DebugLog/*from  w w  w. j a  v a  2 s . c  o m*/
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
    if (!"r".equals(mode)) {
        throw new FileNotFoundException("Provider is read only");
    }
    switch (mUriMatcher.match(uri)) {
    case ArtworkUris.MATCH.ARTWORK: { //Fullscreen
        final List<String> seg = uri.getPathSegments();
        if (seg == null || seg.size() < 2) {
            break;
        }
        final ArtInfo artInfo = new ArtInfo(seg.get(seg.size() - 2), seg.get(seg.size() - 1), null);
        final ParcelFileDescriptor pfd = getArtwork(uri, artInfo);
        if (pfd != null) {
            return pfd;
        }
        break;
    }
    case ArtworkUris.MATCH.THUMBNAIL: { //Thumbnail
        final List<String> seg = uri.getPathSegments();
        if (seg == null || seg.size() < 2) {
            break;
        }
        final ArtInfo artInfo = new ArtInfo(seg.get(seg.size() - 2), seg.get(seg.size() - 1), null);
        final ParcelFileDescriptor pfd = getArtworkThumbnail(uri, artInfo);
        if (pfd != null) {
            return pfd;
        }
        break;
    }
    case ArtworkUris.MATCH.ALBUM_REQ:
    case ArtworkUris.MATCH.ARTIST_REQ: {
        final String q = uri.getQueryParameter("q");
        final String t = uri.getQueryParameter("t");
        if (q != null) {
            final ArtInfo artInfo = UtilsArt.artInfoFromBase64EncodedJson(mGson, q);
            ArtworkType artworkType = ArtworkType.THUMBNAIL;
            if (t != null) {
                artworkType = ArtworkType.valueOf(t);
            }
            final ParcelFileDescriptor pfd;
            switch (artworkType) {
            case LARGE:
                pfd = getArtwork(uri, artInfo);
                break;
            default:
                pfd = getArtworkThumbnail(uri, artInfo);
                break;
            }
            if (pfd != null) {
                return pfd;
            }
        }
        break;
    }
    }
    throw new FileNotFoundException("Could not obtain image from cache");
}

From source file:org.openhab.habdroid.ui.OpenHABMainActivity.java

/**
 * This method processes new intents generated by NFC subsystem
 *
 * @param nfcData - a data which NFC subsystem got from the NFC tag
 *//* ww w.  jav  a 2 s  .c om*/
public void onNfcTag(String nfcData) {
    Log.d(TAG, "onNfcTag()");
    Uri openHABURI = Uri.parse(nfcData);
    Log.d(TAG, "NFC Scheme = " + openHABURI.getScheme());
    Log.d(TAG, "NFC Host = " + openHABURI.getHost());
    Log.d(TAG, "NFC Path = " + openHABURI.getPath());
    String nfcItem = openHABURI.getQueryParameter("item");
    String nfcCommand = openHABURI.getQueryParameter("command");
    String nfcItemType = openHABURI.getQueryParameter("itemType");
    // If there is no item parameter it means tag contains only sitemap page url
    if (TextUtils.isEmpty(nfcItem)) {
        Log.d(TAG, "This is a sitemap tag without parameters");
        // Form the new sitemap page url
        String newPageUrl = openHABBaseUrl + "rest/sitemaps" + openHABURI.getPath();
        // Check if we have this page in stack?
        mPendingNfcPage = newPageUrl;
    } else {
        Log.d(TAG, "Target item = " + nfcItem);
        sendItemCommand(nfcItem, nfcCommand);
        // if mNfcData is not empty, this means we were launched with NFC touch
        // and thus need to autoexit after an item action
        if (!TextUtils.isEmpty(mNfcData))
            finish();
    }
    mNfcData = "";
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.GBWebClient.java

private WebResourceResponse mimicReply(Uri requestedUri) {
    if (requestedUri.getHost() != null && (org.apache.commons.lang3.StringUtils
            .indexOfAny(requestedUri.getHost(), AllowedDomains) != -1)) {
        if (internetHelperBound) {
            LOG.debug("WEBVIEW forwarding request to the internet helper");
            Bundle bundle = new Bundle();
            bundle.putString("URL", requestedUri.toString());
            Message webRequest = Message.obtain();
            webRequest.replyTo = internetHelperListener;
            webRequest.setData(bundle);/*ww  w.j av a 2s  .c o m*/
            try {
                latch = new CountDownLatch(1); //the messenger should run on a single thread, hence we don't need to be worried about concurrency. This approach however is certainly not ideal.
                internetHelper.send(webRequest);
                latch.await();
                return internetResponse;

            } catch (RemoteException | InterruptedException e) {
                LOG.warn("Error downloading data from " + requestedUri, e);
            }

        } else {
            LOG.debug("WEBVIEW request to openweathermap.org detected of type: " + requestedUri.getPath()
                    + " params: " + requestedUri.getQuery());
            return mimicOpenWeatherMapResponse(requestedUri.getPath(), requestedUri.getQueryParameter("units"));
        }
    } else {
        LOG.debug("WEBVIEW request:" + requestedUri.toString() + " not intercepted");
    }
    return null;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionLivestreamActivity.java

/**
 * Updates views that rely on session data from explicit strings.
 *///from  w w  w  .  j  a v a 2s. c om
private void updateSessionViews(final String youtubeUrl, final String title, final String sessionAbstract,
        final String hashTag, final String trackName) {

    if (youtubeUrl == null) {
        // Get out, nothing to do here
        finish();
        return;
    }

    mTrackName = trackName;
    String youtubeVideoId = youtubeUrl;
    if (youtubeUrl.startsWith("http")) {
        final Uri youTubeUri = Uri.parse(youtubeUrl);
        youtubeVideoId = youTubeUri.getQueryParameter("v");
    }

    // Play the video
    playVideo(youtubeVideoId);

    if (mTrackPlay) {
        EasyTracker.getTracker().sendView("Live Streaming: " + title);
        LOGD("Tracker", "Live Streaming: " + title);
    }

    final String newYoutubeUrl = Config.YOUTUBE_SHARE_URL_PREFIX + youtubeVideoId;
    mSessionShareData = new SessionShareData(title, hashTag, newYoutubeUrl);
    mShareMenuDeferredSetup = new Runnable() {
        @Override
        public void run() {
            new SessionsHelper(SessionLivestreamActivity.this).tryConfigureShareMenuItem(mShareMenuItem,
                    R.string.share_livestream_template, title, hashTag, newYoutubeUrl);
        }
    };

    if (mShareMenuItem != null) {
        mShareMenuDeferredSetup.run();
        mShareMenuDeferredSetup = null;
    }

    mSessionSummaryDeferredSetup = new Runnable() {
        @Override
        public void run() {
            updateSessionSummaryFragment(title, sessionAbstract);
            updateSessionLiveCaptionsFragment(trackName);
        }
    };

    if (!mLoadFromExtras) {
        mSessionSummaryDeferredSetup.run();
        mSessionSummaryDeferredSetup = null;
    }
}

From source file:org.mariotaku.twidere.provider.TweetStoreProvider.java

@Override
public int bulkInsert(final Uri uri, final ContentValues[] values) {
    final String table = getTableNameForContentUri(uri);
    final int table_id = getTableId(uri);
    int result = 0;
    final int notification_count;
    if (table != null && values != null) {
        final Context context = getContext();
        final int old_count;
        switch (table_id) {
        case URI_STATUSES: {
            old_count = getAllStatusesCount(context, Statuses.CONTENT_URI);
            break;
        }// w w w  .  j ava 2 s  . c o  m
        case URI_MENTIONS: {
            old_count = getAllStatusesCount(context, Mentions.CONTENT_URI);
            break;
        }
        default:
            old_count = 0;
        }
        mDatabase.beginTransaction();
        for (final ContentValues contentValues : values) {
            mDatabase.insert(table, null, contentValues);
            result++;
        }
        mDatabase.setTransactionSuccessful();
        mDatabase.endTransaction();
        if (!"false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY))) {
            switch (table_id) {
            case URI_STATUSES: {
                mNewStatusesCount += notification_count = getAllStatusesCount(context, Statuses.CONTENT_URI)
                        - old_count;
                break;
            }
            case URI_MENTIONS: {
                mNewMentionsCount += notification_count = getAllStatusesCount(context, Mentions.CONTENT_URI)
                        - old_count;
                break;
            }
            case URI_DIRECT_MESSAGES_INBOX: {
                mNewMessagesCount += notification_count = result;
                break;
            }
            default:
                notification_count = 0;
            }
        } else {
            notification_count = 0;
        }
    } else {
        notification_count = 0;
    }
    if (result > 0) {
        onDatabaseUpdated(uri);
    }
    onNewItemsInserted(uri, notification_count, values);
    return result;
}