List of usage examples for android.net Uri encode
public static String encode(String s, String allow)
From source file:Main.java
public static String encodeUrl(String url) { return Uri.encode(url, "-![.:/,%?&=]"); }
From source file:Main.java
public static final String getRawQueryParameter(Uri uri, String queryParameterName) { String ret = null;//from ww w . j a v a 2 s.c o m if ((uri != null) && (!TextUtils.isEmpty(queryParameterName))) { final String query = uri.getEncodedQuery(); if (query == null) { return null; } final String encodedKey = Uri.encode(queryParameterName, null); final int length = query.length(); int start = 0; do { int nextAmpersand = query.indexOf('&', start); int end = nextAmpersand != -1 ? nextAmpersand : length; int separator = query.indexOf('=', start); if (separator > end || separator == -1) { separator = end; } if (separator - start == encodedKey.length() && query.regionMatches(start, encodedKey, 0, encodedKey.length())) { if (separator == end) { ret = ""; } else { ret = query.substring(separator + 1, end); } break; } // Move start to end of name. if (nextAmpersand != -1) { start = nextAmpersand + 1; } else { break; } } while (true); } return ret; }
From source file:Main.java
/** * Encodes a path according to URI RFC 2396. * // w w w.ja v a2s . co m * If the received path doesn't start with "/", the method adds it. * * @param remoteFilePath Path * @return Encoded path according to RFC 2396, always starting with "/" */ public static String encodePath(String remoteFilePath) { String encodedPath = Uri.encode(remoteFilePath, "/"); if (!encodedPath.startsWith("/")) encodedPath = "/" + encodedPath; return encodedPath; }
From source file:com.dishcuss.foodie.hub.GCM.RegistrationIntentService.java
/** * Persist registration to third-party servers. * <p>// w ww. ja va 2s. co m * Modify this method to associate the user's GCM registration token with any server-side account * maintained by your application. * * @param token The new token. */ private void sendRegistrationToServer(String token) { // Add custom implementation, as needed. tokenRegister = Uri.encode(URLs.userToken, ALLOWED_URI_CHARS); sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply(); SendToken(token); }
From source file:org.jared.synodroid.ds.server.SimpleSynoServer.java
/** * Create a connection and add all required cookies information * /*from w ww .jav a 2s . c o m*/ * @param uriP * @param requestP * @param methodP * @return * @throws MalformedURLException * @throws IOException */ protected HttpURLConnection createConnection(String uriP, String requestP, String methodP, boolean log) throws MalformedURLException, IOException { // Prepare the connection HttpURLConnection con = (HttpURLConnection) new URL(getUrl() + Uri.encode(uriP, "/")).openConnection(); // Add cookies if exist if (cookies != null) { con.addRequestProperty("Cookie", getCookies()); if (DEBUG) Log.v(Synodroid.DS_TAG, "Added cookie to the request: " + cookies); } con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.setRequestMethod(methodP); con.setConnectTimeout(20000); if (DEBUG) { if (log) { Log.i(Synodroid.DS_TAG, methodP + ": " + uriP + "?" + requestP); } else { Log.i(Synodroid.DS_TAG, methodP + ": " + uriP + " (hidden request)"); } } return con; }
From source file:org.restcomm.app.utillib.DataObjects.Carrier.java
public void loadLogo(Context context) { if (Path != null && Path.length() > 1) { //String localPath = Environment.getExternalStorageDirectory().toString(); String localPath = context.getApplicationContext().getFilesDir() + "/images/logos"; File file = new File(localPath); file.mkdirs();// w w w.ja va2 s .co m localPath = context.getApplicationContext().getFilesDir() + Path; //file.mkdirs(); try { file = new File(localPath); if (file.exists()) return; } catch (Exception e) { String str = e.getMessage(); } InputStream stream = null; FileOutputStream fos = null; try { String imageUrl = Global.getApiUrl(null);//.getString("MMC_URL_LIN"); // MMC_URL_CLOUD String imagePath = Uri.encode(Path, "/"); URL request = new URL(imageUrl + imagePath); HttpURLConnection connection = (HttpURLConnection) request.openConnection(); connection.connect(); stream = connection.getInputStream(); byte[] byteChunk = new byte[4096]; // Or whatever size you want to read in at a time. int n; fos = new FileOutputStream(localPath); while ((n = stream.read(byteChunk)) > 0) { fos.write(byteChunk, 0, n); } fos.flush(); fos.close(); } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, "Carrier", "loadLogo", "Exception loading logo " + Path); } finally { if (stream != null) { try { stream.close(); } catch (Exception e) { } } } } }
From source file:com.nostra13.universalimageloader.core.download.BaseImageDownloader.java
/** * Create {@linkplain HttpURLConnection HTTP connection} for incoming URL * * @param url URL to connect to/* w w w . ja v a 2 s .c o m*/ * @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object) * DisplayImageOptions.extraForDownloader(Object)}; can be null * @return {@linkplain HttpURLConnection Connection} for incoming URL. Connection isn't established so it still configurable. * @throws IOException if some I/O error occurs during network request or if no InputStream could be created for * URL. */ protected HttpURLConnection createConnection(String url, Object extra) throws IOException { String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS); HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl).openConnection(); conn.setConnectTimeout(connectTimeout); conn.setReadTimeout(readTimeout); return conn; }
From source file:com.fivehundredpxdemo.android.storage.ImageFetcher.java
/** * The main process method, which will be called by the ImageWorker in the AsyncTask background * thread./* www.j ava 2 s.com*/ */ private Bitmap processBitmap(ImageData imageData) { // for thumbnails and images, we need to encode URLs because they can // contain UTF-8 characters (e.g. Japanese/Chinese characters) in the permalink // (the 2nd parameter is a list of characters not to encode) final String formattedURL = Uri.encode(imageData.toString(), ":/-_%|+?#=&$,.;@"); if (imageData.mType == ImageData.IMAGE_TYPE_NORMAL) { return processNormalBitmap(formattedURL); // Process a regular, full sized bitmap } else if (imageData.mType == ImageData.IMAGE_TYPE_THUMBNAIL) { return processThumbnailBitmap(formattedURL); // Process a smaller, thumbnail bitmap } else if (imageData.mType == ImageData.IMAGE_TYPE_URI) { return processUriBitmap((Uri) imageData.mKey); } else if (imageData.mType == ImageData.IMAGE_TYPE_FILE) { return processFileBitmap(imageData.toString()); } return null; }
From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java
public void UpdateCurrentGroupMenu() { StartActivity rootactivity = (StartActivity) getActivity(); Menu menu = rootactivity.getActionMenu(); if (menu != null) { MenuItem automation = menu.findItem(R.id.menu_automation); if (automation != null) { automation.setEnabled(false); Menu submenu = automation.getSubMenu(); if (submenu == null) return; ////from w ww . ja v a 2s . co m submenu.removeGroup(Menu.NONE); if (mGroupPrograms.size() > 0) { for (Module program : mGroupPrograms) { MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName()); prg.setIcon(R.drawable.ic_action_flash_on); MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT); final String paddress = program.Address; String groupname = ""; try { groupname = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8"); } catch (Exception e) { } final String gname = groupname; prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { String apicall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" + paddress + "/" + gname + "/" + new Date().getTime(); Control.callServiceApi(apicall, null); return true; } }); } automation.setEnabled(true); } } // // MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro"); // recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { // @Override // public boolean onMenuItemClick(MenuItem menuItem) { // StartActivity sa = (StartActivity)getActivity(); // sa.openMacroRecordMenu(); // return true; // } // }); // rootactivity.supportInvalidateOptionsMenu(); } }
From source file:io.github.data4all.handler.TagSuggestionHandler.java
/** * Get a list of locations near by the given location. * /*from ww w . j a v a 2s.c o m*/ * @param location * @return locations near by a given Location */ private static List<Location> getNearestLocations(Location location) { final List<Location> locations = new LinkedList<Location>(); try { final double boundingbox[] = getBoundingBox(location.getLatitude(), location.getLongitude(), 0.020); StringBuilder url = new StringBuilder("http://overpass-api.de/api/interpreter?data=[out:json];"); StringBuilder param = new StringBuilder(""); param.append("node(").append(boundingbox[0]).append(",").append(boundingbox[1]).append(","); param.append(boundingbox[2]).append(",").append(boundingbox[3]).append(");out;"); final String urlParam = url.toString() + Uri.encode(param.toString(), "UTF-8"); final JSONObject jsonObj = getJSONfromURL(urlParam); final JSONArray elements = jsonObj.getJSONArray("elements"); int index = 0; while (!elements.isNull(index)) { final JSONObject obj = elements.getJSONObject(index); final String lat = getJsonValue(obj, "lat"); final String lon = getJsonValue(obj, "lon"); if (!lat.isEmpty() && !lon.isEmpty()) { final Location loc = new Location(""); loc.setLatitude(Double.valueOf(lat)); loc.setLongitude(Double.valueOf(lon)); locations.add(loc); } index++; } Log.i(TAG, "getNear: " + index); } catch (Exception e) { Log.i(TAG, "getNear: ", e); } return locations; }