Example usage for android.net Uri encode

List of usage examples for android.net Uri encode

Introduction

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

Prototype

public static String encode(String s) 

Source Link

Document

Encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme.

Usage

From source file:ch.pec0ra.mobilityratecalculator.DistanceCalculator.java

private String buildDistancesUrl() {
    String ret = MapsDistances.BASE_DISTANCES_URL;
    ret += MapsDistances.ORIGINS + Uri.encode(from);
    ret += MapsDistances.AND;/*from  w w w  .  j  a  va  2  s . co  m*/
    ret += MapsDistances.DESTINATIONS + Uri.encode(to);
    ret += MapsDistances.AND;
    ret += MapsDistances.KEY + MapsDistances.distancesKey;
    return ret;
}

From source file:com.klinker.android.twitter.utils.api_helper.TweetMarkerHelper.java

public TweetMarkerHelper(int currentAccount, String screenname, Twitter twitter,
        SharedPreferences sharedPrefs) {
    this.currentAccount = currentAccount;
    this.screenname = screenname;
    this.twitter = twitter;
    this.sharedPrefs = sharedPrefs;

    postURL = "https://api.tweetmarker.net/v2/lastread?api_key=" + Uri.encode(TWEETMARKER_API_KEY)
            + "&username=" + Uri.encode(screenname);
}

From source file:com.inferiorhumanorgans.WayToGo.Agency.NextBus.RouteList.RouteListXMLTask.java

@Override
protected Void doInBackground(final NextBusAgency... someAgencies) {
    Assert.assertEquals(1, someAgencies.length);
    super.doInBackground(someAgencies);
    String theNBName = theAgency.getNextBusName();

    Log.i(LOG_NAME, "Trying to get the route list for " + theNBName + ".");

    InputStream content = null;//from   ww w . j a v  a 2s . c  om
    ClientConnectionManager connman = new ThreadSafeClientConnManager(params, registry);
    DefaultHttpClient hc = new DefaultHttpClient(connman, params);

    String theNBURL = "http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=";
    theNBURL += Uri.encode(theNBName);
    Log.i(LOG_NAME, "Fetching from: " + theNBURL);
    HttpGet getRequest = new HttpGet(theNBURL);
    try {
        content = hc.execute(getRequest).getEntity().getContent();
    } catch (ClientProtocolException ex) {
        Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex);
        this.cancel(true);
        return null;
    }

    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();

        XMLReader xr = sp.getXMLReader();

        xr.setContentHandler(theDataHandler);

        xr.parse(new InputSource(content));

    } catch (ParserConfigurationException pce) {
        Log.e(LOG_NAME + " SAX XML", "sax parse error", pce);
    } catch (AbortXMLParsingException abrt) {
        Log.i(LOG_NAME + " AsyncXML", "Cancelled!!!!!");
    } catch (SAXException se) {
        Log.e(LOG_NAME + " SAX XML", "sax error", se);
    } catch (IOException ioe) {
        Log.e(LOG_NAME + " SAX XML", "sax parse io error", ioe);
    }
    //Log.i(LOG_NAME + " SAX XML", "Done parsing XML for " + theNBName);
    return null;
}

From source file:com.inferiorhumanorgans.WayToGo.Agency.NextBus.RouteConfig.RouteConfigXMLTask.java

@Override
protected Void doInBackground(final NextBusAgency... someAgencies) {
    super.doInBackground(someAgencies);

    final String ourNBName = theAgency.getNextBusName();

    Log.i(LOG_NAME, "Trying to get the route config for " + ourNBName + ".");
    Log.i(LOG_NAME, "Fetching from: " + NB_URL_BASE + ourNBName);
    InputStream ourInputStream = null;
    ClientConnectionManager ourConnectionManager = new ThreadSafeClientConnManager(params, registry);
    DefaultHttpClient ourHttpClient = new DefaultHttpClient(ourConnectionManager, params);

    final HttpGet getRequest = new HttpGet(NB_URL_BASE + Uri.encode(ourNBName));
    try {//from  w  w w  .j  a v  a  2s.c o  m
        ourInputStream = ourHttpClient.execute(getRequest).getEntity().getContent();
    } catch (ClientProtocolException ex) {
        Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex);
    }
    Log.i(LOG_NAME, "Done with the route config for " + ourNBName + ".");

    try {
        SAXParserFactory ourParserFactory = SAXParserFactory.newInstance();
        SAXParser ourParser = ourParserFactory.newSAXParser();

        XMLReader xr = ourParser.getXMLReader();

        RouteConfigXMLHandler ourDataHandler = new RouteConfigXMLHandler(this);
        xr.setContentHandler(ourDataHandler);

        xr.parse(new InputSource(ourInputStream));

    } catch (ParserConfigurationException pce) {
        Log.e(LOG_NAME + "SAX XML", "sax parse error", pce);
    } catch (AbortXMLParsingException abrt) {
        Log.i(LOG_NAME + "AsyncXML", "Cancelled!!!!!");
    } catch (SAXException se) {
        Log.e(LOG_NAME + "SAX XML", "sax error", se);
    } catch (IOException ioe) {
        Log.e(LOG_NAME + "SAX XML", "sax parse io error", ioe);
    }
    Log.i(LOG_NAME + "SAX XML", "Done parsing XML for " + ourNBName);
    return null;
}

From source file:enterprayz.megatools.Tools.java

public static void openGmaps(Activity activity, String label, double latitude, double longitude)
        throws ActivityNotFoundException {
    String uriBegin = "geo:" + latitude + "," + longitude;
    String query = latitude + "," + longitude + "(" + label + ")";
    String encodedQuery = Uri.encode(query);
    String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
    Uri uri = Uri.parse(uriString);// w w  w. j a  v  a 2  s .co m
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
    activity.startActivity(intent);
}

From source file:com.juick.android.TagsActivity.java

public void onTagLongClick(String tag, int uid) {
    Intent i = new Intent(this, MessagesActivity.class);
    JuickCompatibleURLMessagesSource ms = new JuickCompatibleURLMessagesSource(
            getString(R.string.Tag) + ": " + tag, "usergtag", this).putArg("tag", Uri.encode(tag))
                    .putArg("user_id", "" + uid);
    ms.setCanNext(false);/* w ww .j  a va2 s  . c  o  m*/
    ms.setKind("user_tag");
    i.putExtra("messagesSource", ms);
    startActivity(i);
}

From source file:com.pursuer.reader.easyrss.network.url.AbsURL.java

protected void addParam(final String key, final String value) {
    for (final NameValuePair p : params) {
        if (p.getName().equals(key)) {
            params.remove(p);// w w  w.ja v  a 2s  .co  m
            break;
        }
    }
    params.add(new BasicNameValuePair(key, Uri.encode(value)));
}

From source file:com.owncloud.android.lib.resources.files.ToggleFavoriteOperation.java

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    PropPatchMethod propPatchMethod = null;

    DavPropertySet newProps = new DavPropertySet();
    DavPropertyNameSet removeProperties = new DavPropertyNameSet();

    if (makeItFavorited) {
        DavProperty favoriteProperty = new DefaultDavProperty("oc:favorite", "1",
                Namespace.getNamespace(WebdavEntry.NAMESPACE_OC));
        newProps.add(favoriteProperty);/*from  w w  w  . j av a  2 s .  c o  m*/
    } else {
        removeProperties.add("oc:favorite", Namespace.getNamespace(WebdavEntry.NAMESPACE_OC));
    }

    String webDavUrl = client.getNewWebdavUri().toString();
    String encodedPath = Uri.encode(userID + filePath).replace("%2F", "/");
    String fullFilePath = webDavUrl + "/files/" + encodedPath;

    try {
        propPatchMethod = new PropPatchMethod(fullFilePath, newProps, removeProperties);
        int status = client.executeMethod(propPatchMethod);

        boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK);

        if (isSuccess) {
            result = new RemoteOperationResult(true, status, propPatchMethod.getResponseHeaders());
        } else {
            client.exhaustResponse(propPatchMethod.getResponseBodyAsStream());
            result = new RemoteOperationResult(false, status, propPatchMethod.getResponseHeaders());
        }
    } catch (IOException e) {
        result = new RemoteOperationResult(e);
    } finally {
        if (propPatchMethod != null) {
            propPatchMethod.releaseConnection(); // let the connection available for other methods
        }
    }

    return result;
}

From source file:org.pixmob.feedme.net.NetworkClient.java

/**
 * Generate a Google Reader client ID.// ww  w.j  a  v a 2 s .  co m
 */
private static final String generateClientId(Context context) {
    String applicationVersion = null;
    try {
        applicationVersion = context.getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {
        applicationVersion = "0.0.0";
    }
    return Uri.encode("feedme_" + applicationVersion);
}

From source file:com.serloman.imagecachedownloader.cache.LRUImageCache.java

private String getKey(String url) {
    return Uri.encode(url);
}