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:net.sf.xfd.provider.PublicProvider.java

@Nullable
public String getType(@NonNull Uri uri) {
    final String hardCodedType = uri.getQueryParameter(URI_ARG_TYPE);
    if (hardCodedType != null) {
        return hardCodedType.isEmpty() ? null : hardCodedType;
    }//from  w w  w.  j av a  2  s .co  m

    try {
        assertAbsolute(uri.getPath());

        final String path = uri.getPath();

        final String name = extractName(path);

        return base.getTypeFast(path, name, new Stat());
    } catch (IOException e) {
        return null;
    }
}

From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java

boolean checkSyncToNetwork(Uri uri) {
    final String syncToNetworkUri = uri.getQueryParameter(ContentHelper.SYNCTONETWORK);
    return syncToNetworkUri == null || Boolean.parseBoolean(syncToNetworkUri);
}

From source file:com.coinomi.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    final List<String> pathSegments = uri.getPathSegments();
    if (pathSegments.size() != 2) {
        throw new IllegalArgumentException("Unrecognized URI: " + uri);
    }/*from w w w.ja  v a  2s .  co  m*/

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;
    long lastUpdated;

    final String symbol;
    final boolean isLocalToCrypto;

    if (pathSegments.get(0).equals("to-crypto")) {
        isLocalToCrypto = true;
        symbol = pathSegments.get(1);
        lastUpdated = symbol.equals(lastLocalCurrency) ? localToCryptoLastUpdated : 0;
    } else if (pathSegments.get(0).equals("to-local")) {
        isLocalToCrypto = false;
        symbol = pathSegments.get(1);
        lastUpdated = symbol.equals(lastCryptoCurrency) ? cryptoToLocalLastUpdated : 0;
    } else {
        throw new IllegalArgumentException("Unrecognized URI path: " + uri);
    }

    if (!offline && (lastUpdated == 0 || now - lastUpdated > Constants.RATE_UPDATE_FREQ_MS)) {
        URL url;
        try {
            if (isLocalToCrypto) {
                url = new URL(String.format(TO_CRYPTO_URL, symbol));
            } else {
                url = new URL(String.format(TO_LOCAL_URL, symbol));
            }
        } catch (final MalformedURLException x) {
            throw new RuntimeException(x); // Should not happen
        }

        JSONObject newExchangeRatesJson = requestExchangeRatesJson(url);
        Map<String, ExchangeRate> newExchangeRates = parseExchangeRates(newExchangeRatesJson, symbol,
                isLocalToCrypto);

        if (newExchangeRates != null) {
            if (isLocalToCrypto) {
                localToCryptoRates = newExchangeRates;
                localToCryptoLastUpdated = now;
                lastLocalCurrency = symbol;
                config.setCachedExchangeRates(lastLocalCurrency, newExchangeRatesJson);
            } else {
                cryptoToLocalRates = newExchangeRates;
                cryptoToLocalLastUpdated = now;
                lastCryptoCurrency = symbol;
            }
        }
    }

    Map<String, ExchangeRate> exchangeRates = isLocalToCrypto ? localToCryptoRates : cryptoToLocalRates;

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID, KEY_CURRENCY_ID, KEY_RATE_COIN,
            KEY_RATE_COIN_CODE, KEY_RATE_FIAT, KEY_RATE_FIAT_CODE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            addRow(cursor, exchangeRate);
        }
    } else if (selection.equals(KEY_CURRENCY_ID)) {
        final ExchangeRate exchangeRate = exchangeRates.get(selectionArgs[0]);
        if (exchangeRate != null) {
            addRow(cursor, exchangeRate);
        }
    }

    return cursor;
}

From source file:com.jtechme.apphub.views.ManageReposActivity.java

private void showAddRepo() {
    /*//from www . j a va 2 s  .com
     * If there is text in the clipboard, and it looks like a URL, use that.
     * Otherwise use "https://" as default repo string.
     */
    ClipboardCompat clipboard = ClipboardCompat.create(this);
    String text = clipboard.getText();
    String fingerprint = null;
    if (!TextUtils.isEmpty(text)) {
        try {
            new URL(text);
            Uri uri = Uri.parse(text);
            fingerprint = uri.getQueryParameter("fingerprint");
            // uri might contain a QR-style, all uppercase URL:
            if (TextUtils.isEmpty(fingerprint))
                fingerprint = uri.getQueryParameter("FINGERPRINT");
            text = NewRepoConfig.sanitizeRepoUri(uri);
        } catch (MalformedURLException e) {
            text = null;
        }
    }

    if (TextUtils.isEmpty(text)) {
        text = DEFAULT_NEW_REPO_TEXT;
    }
    showAddRepo(text, fingerprint);
}

From source file:com.mygeopay.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    final List<String> pathSegments = uri.getPathSegments();
    if (pathSegments.size() != 2) {
        throw new IllegalArgumentException("Unrecognized URI: " + uri);
    }/*from  w ww  .j ava  2s. c  o m*/

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;
    long lastUpdated;
    // TODO Add rate values for other Altcoins
    final String symbol;
    final boolean isLocalToCrypto;

    if (pathSegments.get(0).equals("to-crypto")) {
        isLocalToCrypto = true;
        symbol = pathSegments.get(1);
        lastUpdated = symbol.equals(lastLocalCurrency) ? localToCryptoLastUpdated : 0;
    } else if (pathSegments.get(0).equals("to-local")) {
        isLocalToCrypto = false;
        symbol = pathSegments.get(1);
        lastUpdated = symbol.equals(lastCryptoCurrency) ? cryptoToLocalLastUpdated : 0;
    } else {
        throw new IllegalArgumentException("Unrecognized URI path: " + uri);
    }
    // TODO Add rate values for other Altcoins
    if (!offline && (lastUpdated == 0 || now - lastUpdated > Constants.RATE_UPDATE_FREQ_MS)) {
        URL url;
        try {
            if (isLocalToCrypto) {
                url = new URL(String.format(TO_CRYPTO_URL, symbol));
            } else {
                url = new URL(String.format(TO_LOCAL_URL, symbol));
            }
        } catch (final MalformedURLException x) {
            throw new RuntimeException(x); // Should not happen
        }

        JSONObject newExchangeRatesJson = requestExchangeRatesJson(url);
        Map<String, ExchangeRate> newExchangeRates = parseExchangeRates(newExchangeRatesJson, symbol,
                isLocalToCrypto);

        if (newExchangeRates != null) {
            if (isLocalToCrypto) {
                localToCryptoRates = newExchangeRates;
                localToCryptoLastUpdated = now;
                lastLocalCurrency = symbol;
                config.setCachedExchangeRates(lastLocalCurrency, newExchangeRatesJson);
            } else {
                cryptoToLocalRates = newExchangeRates;
                cryptoToLocalLastUpdated = now;
                lastCryptoCurrency = symbol;
            }
        }
    }

    Map<String, ExchangeRate> exchangeRates = isLocalToCrypto ? localToCryptoRates : cryptoToLocalRates;

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID, KEY_CURRENCY_ID, KEY_RATE_COIN,
            KEY_RATE_COIN_CODE, KEY_RATE_FIAT, KEY_RATE_FIAT_CODE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            addRow(cursor, exchangeRate);
        }
    } else if (selection.equals(KEY_CURRENCY_ID)) {
        final ExchangeRate exchangeRate = exchangeRates.get(selectionArgs[0]);
        if (exchangeRate != null) {
            addRow(cursor, exchangeRate);
        }
    }

    return cursor;
}

From source file:net.sf.xfd.provider.PublicProvider.java

@Nullable
@Override// ww  w  .  j a  va 2s .  c om
public String[] getStreamTypes(@NonNull Uri uri, @NonNull String mimeTypeFilter) {
    final String hardCodedType = uri.getQueryParameter(URI_ARG_TYPE);
    if (hardCodedType != null) {
        if (hardCodedType.isEmpty())
            return null;

        if (mimeTypeMatches(mimeTypeFilter, hardCodedType)) {
            return new String[] { hardCodedType };
        }
    }

    try {
        assertAbsolute(uri.getPath());
    } catch (FileNotFoundException e) {
        return null;
    }

    return base.getStreamTypes(uri.getPath(), mimeTypeFilter);
}

From source file:org.fdroid.fdroid.views.ManageReposActivity.java

private void showAddRepo() {
    /*/*from w w  w.  j  a  v  a  2  s  . co m*/
     * If there is text in the clipboard, and it looks like a URL, use that.
     * Otherwise use "https://" as default repo string.
     */
    ClipboardCompat clipboard = ClipboardCompat.create(this);
    String text = clipboard.getText();
    String fingerprint = null;
    if (!TextUtils.isEmpty(text)) {
        try {
            new URL(text);
            Uri uri = Uri.parse(text);
            fingerprint = uri.getQueryParameter("fingerprint");
            // uri might contain a QR-style, all uppercase URL:
            if (TextUtils.isEmpty(fingerprint)) {
                fingerprint = uri.getQueryParameter("FINGERPRINT");
            }
            text = NewRepoConfig.sanitizeRepoUri(uri);
        } catch (MalformedURLException e) {
            text = null;
        }
    }

    if (TextUtils.isEmpty(text)) {
        text = DEFAULT_NEW_REPO_TEXT;
    }
    showAddRepo(text, fingerprint);
}

From source file:com.takondi.tartt.ARActivity.java

@Override
public boolean urlWasInvoked(String url) {
    Log.d(TAG, "urlWasInvoked " + url);
    if (url != null) {
        Uri uri = Uri.parse(url);
        if (URL_ARCHITECTSDK_SCHEME.equals(uri.getScheme())) {
            JSONObject paramJson = new JSONObject();
            if (!uri.getQueryParameterNames().isEmpty()) {
                for (String param : uri.getQueryParameterNames()) {
                    try {
                        paramJson.put(param, uri.getQueryParameter(param));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }// ww  w.  j  a  va2 s .c  o  m
                }
            }
            handleEvent(uri.getHost(), paramJson);
        }
    }
    return false;
}

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

private void onNewItemsInserted(final Uri uri, final int count, final ContentValues... values) {
    if (uri == null || values == null || values.length == 0 || count == 0)
        return;/*from w ww  .j a  v a2s  . c  o  m*/
    if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY)))
        return;
    final Context context = getContext();
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
            .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
    final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image);
    switch (getTableId(uri)) {
    case URI_STATUSES: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_HOME_TIMELINE, false))
            return;
        final String message = res.getQuantityString(R.plurals.Ntweets, mNewStatusesCount, mNewStatusesCount);
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_HOME_TIMELINE);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent = new Intent(context, HomeActivity.class);
        content_intent.setAction(Intent.ACTION_MAIN);
        content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
        final Bundle content_extras = new Bundle();
        content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_HOME);
        content_intent.putExtras(content_extras);
        builder.setOnlyAlertOnce(true);
        final Notification notification = buildNotification(builder, res.getString(R.string.new_notifications),
                message, message, R.drawable.ic_stat_tweet, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_HOME_TIMELINE, notification);
        break;
    }
    case URI_MENTIONS: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_MENTIONS, false))
            return;
        if (mNewMentionsCount > 1) {
            builder.setNumber(mNewMentionsCount);
        }
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent;
        final List<String> screen_names = new NoDuplicatesArrayList<String>();
        ContentValues notification_value = null;
        int notified_count = 0;
        for (final ContentValues value : values) {
            final String screen_name = value.getAsString(Statuses.SCREEN_NAME);
            if (!isFiltered(mDatabase, screen_name, value.getAsString(Statuses.SOURCE),
                    value.getAsString(Statuses.TEXT_PLAIN))) {
                if (notification_value == null) {
                    notification_value = value;
                }
                screen_names.add(screen_name);
                notified_count++;
            }
        }
        if (notified_count == 1) {
            final Uri.Builder uri_builder = new Uri.Builder();
            uri_builder.scheme(SCHEME_TWIDERE);
            uri_builder.authority(AUTHORITY_STATUS);
            uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID,
                    notification_value.getAsString(Statuses.ACCOUNT_ID));
            uri_builder.appendQueryParameter(QUERY_PARAM_STATUS_ID,
                    notification_value.getAsString(Statuses.STATUS_ID));
            content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());

        } else {
            content_intent = new Intent(context, HomeActivity.class);
            content_intent.setAction(Intent.ACTION_MAIN);
            content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final Bundle content_extras = new Bundle();
            content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MENTIONS);
            content_intent.putExtras(content_extras);
        }
        if (notification_value == null)
            return;
        final String title;
        if (screen_names.size() > 1) {
            title = res.getString(R.string.notification_mention_multiple,
                    display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME)
                            : notification_value.getAsString(Statuses.NAME),
                    screen_names.size() - 1);
        } else {
            title = res.getString(R.string.notification_mention,
                    display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME)
                            : notification_value.getAsString(Statuses.NAME));
        }
        final String message = notification_value.getAsString(Statuses.TEXT_PLAIN);
        final String profile_image_url_string = notification_value.getAsString(Statuses.PROFILE_IMAGE_URL);
        final File profile_image_file = mProfileImageLoader.getCachedImageFile(
                display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                        : profile_image_url_string);
        final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
        final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
        builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile()
                ? BitmapFactory.decodeFile(profile_image_file.getPath())
                : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true));
        final Notification notification = buildNotification(builder, title, title, message,
                R.drawable.ic_stat_mention, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, notification);
        break;
    }
    case URI_DIRECT_MESSAGES_INBOX: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_DIRECT_MESSAGES, false))
            return;
        if (mNewMessagesCount > 1) {
            builder.setNumber(mNewMessagesCount);
        }
        final List<String> screen_names = new NoDuplicatesArrayList<String>();
        final ContentValues notification_value = values[0];
        for (final ContentValues value : values) {
            screen_names.add(value.getAsString(DirectMessages.SENDER_SCREEN_NAME));
        }
        if (notification_value == null)
            return;
        final String title;
        if (screen_names.size() > 1) {
            title = res.getString(R.string.notification_direct_message_multiple,
                    display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME)
                            : notification_value.getAsString(DirectMessages.SENDER_NAME),
                    screen_names.size() - 1);
        } else {
            title = res.getString(R.string.notification_direct_message,
                    display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME)
                            : notification_value.getAsString(DirectMessages.SENDER_NAME));
        }
        final String message = notification_value.getAsString(DirectMessages.TEXT_PLAIN);
        final String profile_image_url_string = notification_value
                .getAsString(DirectMessages.SENDER_PROFILE_IMAGE_URL);
        final File profile_image_file = mProfileImageLoader.getCachedImageFile(
                display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                        : profile_image_url_string);
        final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
        final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
        builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile()
                ? BitmapFactory.decodeFile(profile_image_file.getPath())
                : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true));
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_DIRECT_MESSAGES);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent;
        if (values.length == 1) {
            final Uri.Builder uri_builder = new Uri.Builder();
            final long account_id = notification_value.getAsLong(DirectMessages.ACCOUNT_ID);
            final long conversation_id = notification_value.getAsLong(DirectMessages.SENDER_ID);
            uri_builder.scheme(SCHEME_TWIDERE);
            uri_builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
            uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
            uri_builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(conversation_id));
            content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());
        } else {
            content_intent = new Intent(context, HomeActivity.class);
            content_intent.setAction(Intent.ACTION_MAIN);
            content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final Bundle content_extras = new Bundle();
            content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MESSAGES);
            content_intent.putExtras(content_extras);
        }
        final Notification notification = buildNotification(builder, title, title, message,
                R.drawable.ic_stat_direct_message, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, notification);
        break;
    }
    }
}

From source file:com.github.gorbin.asne.linkedin.LinkedInJSocialNetwork.java

/**
 * Overrided for LinkedIn support//from w ww  .j a v a  2 s  . c o  m
 * @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.
 * @param resultCode The integer result code returned by the child activity through its setResult().
 * @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    int sanitizedRequestCode = requestCode & 0xFFFF;
    if (sanitizedRequestCode != REQUEST_AUTH)
        return;

    if (resultCode != Activity.RESULT_OK || data == null || data.getData() == null) {
        if (mLocalListeners.get(REQUEST_LOGIN) != null) {
            mLocalListeners.get(REQUEST_LOGIN).onError(getID(), REQUEST_LOGIN, "Login canceled", null);
        }
        return;
    }

    Uri uri = data.getData();

    final String problem = uri.getQueryParameter(OAUTH_QUERY_PROBLEM);
    if (problem != null) {
        if (mLocalListeners.get(REQUEST_LOGIN) != null) {
            mLocalListeners.get(REQUEST_LOGIN).onError(getID(), REQUEST_LOGIN, problem, null);
        }

        return;
    }

    Bundle args = new Bundle();
    args.putString(RequestLogin2AsyncTask.PARAM_VERIFIER, uri.toString());
    args.putString(RequestLogin2AsyncTask.PARAM_AUTH_REQUEST_TOKEN, mOAuthTokenSecret);
    executeRequest(new RequestLogin2AsyncTask(), args, REQUEST_LOGIN2);
}