List of usage examples for android.net Uri encode
public static String encode(String s)
From source file:com.example.ward.view.CursorFragment.java
public Loader<Cursor> onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. This // sample only has one Loader, so we don't care about the ID. // First, pick the base URI to use depending on whether we are // currently filtering. Uri baseUri;/*from w ww .jav a 2 s.c om*/ if (mCurFilter != null) { baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(mCurFilter)); } else { baseUri = Contacts.CONTENT_URI; } // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.HAS_PHONE_NUMBER + "=1) AND (" + Contacts.DISPLAY_NAME + " != '' ))"; return new CursorLoader(getActivity(), baseUri, CONTACTS_SUMMARY_PROJECTION, select, null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); }
From source file:org.smssecure.smssecure.contacts.ContactAccessor.java
public Collection<ContactData> getContactsWithPush(Context context) { final ContentResolver resolver = context.getContentResolver(); final String[] inProjection = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME }; List<String> pushNumbers = SMSSecureDirectory.getInstance(context).getActiveNumbers(); final Collection<ContactData> lookupData = new ArrayList<ContactData>(pushNumbers.size()); for (String pushNumber : pushNumbers) { Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber)); Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null); try {// w w w . j av a 2 s. c o m if (lookupCursor != null && lookupCursor.moveToFirst()) { final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1)); contactData.numbers.add(new NumberData("SMSSecure", pushNumber)); lookupData.add(contactData); } } finally { if (lookupCursor != null) lookupCursor.close(); } } return lookupData; }
From source file:com.mentalmachines.cjkdroid.SimpleWikiHelper.java
/** * Read and return the content for a specific Wiktionary page. This makes a * lightweight API call, and trims out just the page content returned. * Because this call blocks until results are available, it should not be * run from a UI thread.//from w w w . j av a 2 s . c om * * @param title The exact title of the Wiktionary page requested. * @param expandTemplates If true, expand any wiki templates found. * @return Exact content of page. * @throws ApiException If any connection or server error occurs. * @throws ParseException If there are problems parsing the response. */ public static String getPageContent(String title, boolean expandTemplates) throws ApiException, ParseException { // Encode page title and expand templates if requested String encodedTitle = Uri.encode(title); String expandClause = expandTemplates ? WIKTIONARY_EXPAND_TEMPLATES : ""; // Query the API for content String content = getUrlContent(String.format(WIKTIONARY_PAGE + title, encodedTitle, expandClause)); try { // Drill into the JSON response to find the content body JSONObject response = new JSONObject(content); JSONObject query = response.getJSONObject("query"); JSONObject pages = query.getJSONObject("pages"); JSONObject page = pages.getJSONObject((String) pages.keys().next()); JSONArray revisions = page.getJSONArray("revisions"); JSONObject revision = revisions.getJSONObject(0); return revision.getString("*"); } catch (JSONException e) { throw new ParseException("Problem parsing API response", e); } }
From source file:com.drc.wiktionary.SimpleWikiHelper.java
/** * Read and return the content for a specific Wiktionary page. This makes a * lightweight API call, and trims out just the page content returned. * Because this call blocks until results are available, it should not be * run from a UI thread./*from w w w . ja v a 2 s . c o m*/ * * @param title The exact title of the Wiktionary page requested. * @param expandTemplates If true, expand any wiki templates found. * @return Exact content of page. * @throws ApiException If any connection or server error occurs. * @throws ParseException If there are problems parsing the response. */ public static String getPageContent(String title, boolean expandTemplates) throws ApiException, ParseException { // Encode page title and expand templates if requested String encodedTitle = Uri.encode(title); String expandClause = expandTemplates ? WIKTIONARY_EXPAND_TEMPLATES : ""; // Query the API for content String url = String.format(WIKTIONARY_PAGE, encodedTitle, expandClause); Log.d("SimpleWikiHelper", "url: " + url); String content = getUrlContent(url); try { // Drill into the JSON response to find the content body JSONObject response = new JSONObject(content); JSONObject query = response.getJSONObject("query"); JSONObject pages = query.getJSONObject("pages"); JSONObject page = pages.getJSONObject((String) pages.keys().next()); JSONArray revisions = page.getJSONArray("revisions"); JSONObject revision = revisions.getJSONObject(0); return revision.getString("*"); } catch (JSONException e) { throw new ParseException("Problem parsing API response", e); } }
From source file:com.google.samples.apps.abelana.AbelanaThings.java
public static String getImage(String name) { final String Bucket = "abelana"; DateTime soon = DateTime.now(DateTimeZone.UTC).plusMinutes(20); long expires = soon.getMillis() / 1000; String stringToSign = "GET\n\n\n" + expires + "\n" + "/" + Bucket + "/" + name + ".webp"; String uri = "https://storage.googleapis.com/abelana/" + name + ".webp" + "?GoogleAccessId=" + credential.getServiceAccountId() + "&Expires=" + expires + "&Signature=" + Uri.encode(signData(stringToSign)); return uri;//from w w w . j a va 2 s . co m }
From source file:in.risysnetworks.shplayer.fragments.childfragment.ChildFragmentArtists.java
private Cursor getArtistCursor(AsyncQueryHandler async, String filter) { String[] cols = new String[] { MediaStore.Audio.Artists._ID, MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Artists.NUMBER_OF_ALBUMS, MediaStore.Audio.Artists.NUMBER_OF_TRACKS }; Uri uri = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI; if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); }/*from w w w.jav a 2s . c om*/ Cursor ret = null; if (async != null) { async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Artists.ARTIST_KEY); } else { ret = SHPlayerUtility.query(getActivity(), uri, cols, null, null, MediaStore.Audio.Artists.ARTIST_KEY); } return ret; }
From source file:fr.spaz.widget.word.SimpleWiktionaryHelper.java
/** * Read and return the content for a specific Wiktionary page. This makes a lightweight API call, and trims out just the page content returned. Because this call blocks until results are available, it should not be run from a UI thread. * // w ww . jav a 2 s . c om * @param title * The exact title of the Wiktionary page requested. * @param expandTemplates * If true, expand any wiki templates found. * @return Exact content of page. * @throws ApiException * If any connection or server error occurs. * @throws ParseException * If there are problems parsing the response. */ public static String getPageContent(String title, boolean expandTemplates) throws ApiException, ParseException { // Encode page title and expand templates if requested String encodedTitle = Uri.encode(title); String expandClause = expandTemplates ? WIKTIONARY_EXPAND_TEMPLATES : ""; // Query the API for content final String s = String.format(WIKTIONARY_PAGE, encodedTitle, expandClause); Log.d("Spaz", s); String content = getUrlContent(s); try { // Drill into the JSON response to find the content body JSONObject response = new JSONObject(content); JSONObject query = response.getJSONObject("query"); JSONObject pages = query.getJSONObject("pages"); JSONObject page = pages.getJSONObject((String) pages.keys().next()); JSONArray revisions = page.getJSONArray("revisions"); JSONObject revision = revisions.getJSONObject(0); return revision.getString("*"); } catch (JSONException e) { throw new ParseException("Problem parsing API response", e); } }
From source file:co.codecrunch.musicplayerlite.childfragment.ChildFragmentAlbum.java
private Cursor getAlbumCursor(AsyncQueryHandler async, String filter) { String[] cols = new String[] { MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST, MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Albums.ALBUM_ART }; Cursor ret = null;/*from ww w . ja v a 2 s .co m*/ Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI; if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } if (async != null) { async.startQuery(0, null, uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER); } else { ret = MusicPlayerUtility.query(getActivity(), uri, cols, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER); } return ret; }
From source file:com.juick.android.UserCenterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { JuickAdvancedApplication.setupTheme(this); handler = new Handler(); super.onCreate(savedInstanceState); setContentView(R.layout.user_center); final ListView list = (ListView) findViewById(R.id.list); final View listWait = findViewById(R.id.list_wait); final TextView userRealName = (TextView) findViewById(R.id.user_realname); final ImageView userPic = (ImageView) findViewById(R.id.userpic); final TextView userName = (TextView) findViewById(R.id.username); search = findViewById(R.id.search);/* w w w. jav a 2 s . co m*/ final View stats = findViewById(R.id.stats); userRealName.setText("..."); Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } uname = extras.getString("uname"); final int uid = extras.getInt("uid"); final MessageID mid = (MessageID) extras.getSerializable("mid"); final MessagesSource messagesSource = (MessagesSource) extras.getSerializable("messagesSource"); if (uname == null || mid == null) { finish(); return; } int height = getWindow().getWindowManager().getDefaultDisplay().getHeight(); final int userpicSize = height <= 320 ? 32 : 96; float scaledDensity = getResources().getDisplayMetrics().scaledDensity; userPic.setMinimumHeight((int) (scaledDensity * userpicSize)); userPic.setMinimumWidth((int) (scaledDensity * userpicSize)); stats.setEnabled(false); userName.setText("@" + uname); final boolean russian = Locale.getDefault().getLanguage().equals("ru"); new Thread() { @Override public void run() { final Utils.RESTResponse json = Utils.getJSON(UserCenterActivity.this, "http://" + Utils.JA_ADDRESS + "/api/userinfo?uname=" + Uri.encode(uname), null); runOnUiThread(new Runnable() { @Override public void run() { stats.setEnabled(true); if (json.getErrorText() != null) { Toast.makeText(UserCenterActivity.this, "JA server: " + json.getErrorText(), Toast.LENGTH_LONG).show(); listWait.setVisibility(View.GONE); } else { final UserInfo userInfo = new Gson().fromJson(json.getResult(), UserInfo.class); if (userInfo == null) { Toast.makeText(UserCenterActivity.this, "Unable to parse JSON", Toast.LENGTH_LONG) .show(); listWait.setVisibility(View.GONE); } else { userRealName.setText(userInfo.fullName); listWait.setVisibility(View.GONE); list.setVisibility(View.VISIBLE); list.setAdapter(new BaseAdapter() { @Override public int getCount() { return userInfo.getExtraInfo().size(); } @Override public Object getItem(int position) { return userInfo.getExtraInfo().get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getLayoutInflater().inflate(R.layout.listitem_userinfo, null); } TextView text = (TextView) convertView.findViewById(R.id.text); TextView text2 = (TextView) convertView.findViewById(R.id.text2); String info = userInfo.getExtraInfo().get(position); int ix = info.indexOf("|"); if (ix == -1) { text.setText(info); if (russian && UserInfo.translations.containsKey(info)) { info = UserInfo.translations.get(info); } text2.setText(""); } else { String theInfo = info.substring(0, ix); if (russian && UserInfo.translations.containsKey(theInfo)) { theInfo = UserInfo.translations.get(theInfo); } text.setText(theInfo); String value = info.substring(ix + 1); if (value.startsWith("Date:")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); value = value.substring(5); value = sdf.format(new Date(Long.parseLong(value))); } text2.setText(value); } return convertView; } }); } } } }); } }.start(); View subscribe_user = findViewById(R.id.subscribe_user); View unsubscribe_user = findViewById(R.id.unsubscribe_user); View subscribe_comments = findViewById(R.id.subscribe_comments); View unsubscribe_comments = findViewById(R.id.unsubscribe_comments); View filter_user = findViewById(R.id.filter_user); View blacklist_user = findViewById(R.id.blacklist_user); View show_blog = findViewById(R.id.show_blog); MicroBlog microBlog = MainActivity.getMicroBlog(mid.getMicroBlogCode()); final MessageMenu mm = microBlog.getMessageMenu(this, messagesSource, null, null); JuickMessage message = microBlog.createMessage(); mm.listSelectedItem = message; message.User = new JuickUser(); message.User.UName = uname; message.User.UID = uid; message.setMID(mid); final UserpicStorage.AvatarID avatarID = microBlog.getAvatarID(message); final UserpicStorage.Listener userpicListener = new UserpicStorage.Listener() { @Override public void onUserpicReady(UserpicStorage.AvatarID id, int size) { final UserpicStorage.Listener thiz = this; runOnUiThread(new Runnable() { @Override public void run() { UserpicStorage.instance.removeListener(avatarID, userpicSize, thiz); final Bitmap userpic = UserpicStorage.instance.getUserpic(UserCenterActivity.this, avatarID, userpicSize, thiz); userPic.setImageBitmap(userpic); // can be null } }); } }; Bitmap userpic = UserpicStorage.instance.getUserpic(this, avatarID, userpicSize, userpicListener); userPic.setImageBitmap(userpic); // can be null subscribe_user.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mm.actionSubscribeUser(); } }); show_blog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mm.listSelectedItem.User.UID == 0) { JuickMicroBlog.obtainProperUserIdByName(UserCenterActivity.this, mm.listSelectedItem.User.UName, "Getting Juick User Id", new Utils.Function<Void, Pair<String, String>>() { @Override public Void apply(Pair<String, String> cred) { mm.listSelectedItem.User.UID = Integer.parseInt(cred.first); mm.actionUserBlog(); return null; } }); } else { mm.actionUserBlog(); } } }); search.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { search.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { menu.add(0, SEARCH_PAST_CONVERSATIONS, 0, "My dialogs with user"); menu.add(0, SEARCH_MORE, 1, "More"); } }); search.showContextMenu(); } }); stats.setOnClickListener(new View.OnClickListener() { NewJuickPreferenceActivity.MenuItem[] items = new NewJuickPreferenceActivity.MenuItem[] { new NewJuickPreferenceActivity.MenuItem(R.string.UserAllTimeActivityReport, R.string.UserAllTimeActivityReport2, new Runnable() { @Override public void run() { NewJuickPreferenceActivity.showChart(UserCenterActivity.this, "USER_ACTIVITY_VOLUME", "uid=" + uid); } }), new NewJuickPreferenceActivity.MenuItem(R.string.UserHoursReport, R.string.UserHoursReport2, new Runnable() { @Override public void run() { NewJuickPreferenceActivity.showChart(UserCenterActivity.this, "USER_HOURS_ACTIVITY", "uid=" + uid + "&tzoffset=" + TimeZone.getDefault().getRawOffset() / 1000 / 60 / 60); } }) }; @Override public void onClick(View v) { list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { items[position].action.run(); } }); list.setAdapter(new BaseAdapter() { @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return items[position]; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater layoutInflater = getLayoutInflater(); View listItem = layoutInflater.inflate(android.R.layout.simple_list_item_2, null); TextView text = (TextView) listItem.findViewById(android.R.id.text1); text.setText(items[position].labelId); TextView text2 = (TextView) listItem.findViewById(android.R.id.text2); text2.setText(items[position].label2Id); return listItem; } }); } }); blacklist_user.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mm.actionBlacklistUser(); } }); filter_user.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mm.actionFilterUser(uname); } }); unsubscribe_user.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mm.actionUnsubscribeUser(); } }); subscribe_comments.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { enableJAM(new Runnable() { @Override public void run() { JAMService.instance.client.subscribeToComments(uname); } }); } }); unsubscribe_comments.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { enableJAM(new Runnable() { @Override public void run() { JAMService.instance.client.unsubscribeFromComments(uname); } }); } }); }
From source file:com.balk.rsswidget.GoogleReaderHelper.java
/** * Read and return the content for a specific Wiktionary page. This makes a * lightweight API call, and trims out just the page content returned. * Because this call blocks until results are available, it should not be * run from a UI thread./*from ww w . j av a 2 s . com*/ * * @param title The exact title of the Wiktionary page requested. * @param expandTemplates If true, expand any wiki templates found. * @return Exact content of page. * @throws ApiException If any connection or server error occurs. * @throws ParseException If there are problems parsing the response. */ public static String getPageContent(String title, boolean expandTemplates) throws ApiException, ParseException { // Encode page title and expand templates if requested String encodedTitle = Uri.encode(title); String expandClause = expandTemplates ? WIKTIONARY_EXPAND_TEMPLATES : ""; // Query the API for content String content = getUrlContent(String.format(WIKTIONARY_PAGE, encodedTitle, expandClause)); try { // Drill into the JSON response to find the content body JSONObject response = new JSONObject(content); JSONObject query = response.getJSONObject("query"); JSONObject pages = query.getJSONObject("pages"); JSONObject page = pages.getJSONObject((String) pages.keys().next()); JSONArray revisions = page.getJSONArray("revisions"); JSONObject revision = revisions.getJSONObject(0); return revision.getString("*"); } catch (JSONException e) { throw new ParseException("Problem parsing API response", e); } }