Wikipedia redirect target containing a # symbol - android

I am doing direct queries to wikipedia's website via an android app.
However, sometimes when I get "REDIRECT" queries, and my redirect suggestion has a # sign in it, I don't really know how to handle it. I know I can just throw everything out past the # sign, but that means I'm looking up something that is relatively unimportant.
Here is an example link;
http://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=Poof_(The_Fairly_OddParents)&format=json
I can just redirect to List_of_The_Fairly_OddParents_characters, but I want to know if there is anything useful I can do with the "#Poof" because I'm sure that the information is there for a reason.
I could not find anything on MediaWiki APIs.
Please help!
Thanks

Most of the time the part after the hash is a section title (though it is simply appended to the new URL, so it can be, and occasionally is, used to point to other kinds of anchors), so you can locate the section (with the mobileview action for example) and with the section index you can query the HTML for that section. (extracts does not support sections, so you you must use something else and enforce length limits manually.)

The hash points to a named anchor or ID in the target document. So if you're parsing the page content, then ideally you'd find the anchor tag or ID and return the content that follows that element, rather than starting at the beginning of the content.

Related

How to go to next page on Github API

With this. I want to use rel="next" instead of incrementing the parameter page manually
This's my Service.java Interface (using retrofit2):
#GET("user/repos")
Call<Repos> getRepos(#Query("api_key") String apiKey,
#Query("page") int pageIndex);
How can I do it? Android - using Java
By principle, HTTP RESTful APIs are stateless.
This means the Github API doesn't know what your current page is, and what your next page is.
Therefore, you must pass the page and per_page parameter.
rel="next" in the Link header indicates that the resource request is for the next page, but it can't and shouldn't be used to get the next page results without passing the page parameter.
In the simplest case, a link relation type identifies the semantics
of a link. For example, a link with the relation type "copyright"
indicates that the resource identified by the target IRI is a
statement of the copyright terms applying to the current context IRI.
Link relation types can also be used to indicate that the target
resource has particular attributes, or exhibits particular
behaviours; for example, a "service" link implies that the identified
resource is part of a defined protocol (in this case, a service
description).
From RFC-5988 Web Linking

How to access linkify number

I need to make all numbers in a string become links.
The expected action when any of these links is clicked is to append the clicked number to an existing string.
I managed to linkify the numbers by using the following code:
Pattern myMatcher = Pattern.compile("[0-9]*");
Linkify.addLinks(myString, myMatcher, null);
How can I access and retrieve the clicked number in this case?
I tried looking in other questions related to Linkify but seems all are describing ways to have an action that opens an activity or open the default app for that link type (email address/web URL/etc.)
Thanks in advance for you help :)
You can Customize Linkify to append any predefiened string(scheme) into that.
Take a look at the following post Android Developer Blogspot (Search for "Custom Linkify")
For clarity I am describing a portion of that post here:
Linkify will automatically append whatever is matched to a scheme that
is supplied to it, so for the sake of argument let's assume we have a
ContentProvider that matches the following content URI:
content://com.google.android.wikinotes.db.wikinotes/wikinotes/WikiWord
The WikiWord part will be appended by Linkify when it finds a match,
so we just need the part before that as our scheme.
Now that we have these two things, we use Linkify to connect them up:
Pattern wikiWordMatcher = Pattern.compile("\\b[A-Z]+[a-z0-9]+[A-Z][A-Za-z0-9]+\\b");
String wikiViewURL = "content://com.google.android.wikinotes.db.wikinotes/wikinotes/";
Linkify.addLinks(noteView, wikiWordMatcher, wikiViewURL);
Linkify can be used multiple times on the same view to add more links,
so using this after the Default Linkify call means that the existing
active links will be maintained and the new WikiWords will be added.
You could define more Linkify actions and keep applying them to the
same TextView if you wanted to.
Now, if we have a WikiWord in the TextView, let's say MyToDoList,
Linkify will turn it into an active link with the content URI:
content://com.google.android.wikinotes.db.wikinotes/wikinotes/MyToDoList
and if you click on it, Android will fire the default intent for that
content URI.
For this to all work, you will need a ContentProvider that understands
that Content URI, and you will need a default activity capable of
doing something with the resulting data. I plan to cover these in
future blog entries (and soon). In fact, the whole Wiki Note Pad
application is currently undergoing some clean up and review, and will
then hopefully be released as a sample application.

Calabash android output to HTML gives timeout errors when finding view elements

When running calabash-android and outputting to HTML format, I am getting intermittent exceptions as per the below (typically within the first step of the app). I am using Xamarin and MVVMCross libraries.
Timeout waiting for elements: * marked:'Terms of Use'
(Calabash::Android::WaitHelpers::WaitError)
./features/step_definitions/calabash_steps.rb:4:in `/^User has accepted the Terms of Use$/'
features\registration.feature:8:in `Given User has accepted the Terms of Use'
2
3Given /^User has accepted the Terms of Use$/ do
4 #current_page=page(TermsOfUse).await
5 #current_page.tap_accept_button
6end
7# gem install syntax to get syntax highlighting
The screenshots generated show the UI element is present on the screen, and the same errors never occur when I exclude the html format option and simply write the detail out to the console. Does anybody else have any experience of this?
Most likely the view's text has some formatting information in it.
It's a good practice to use id instead of text for identifying elements. If you have an id, use that:
query("* id:'terms_of_use_id'")
If you don't have an id try to add one.
If that is not possible try to query the whole UI with:
query("*")
Find the element and see what's in it's text property.

Still uncleared on the dex format

I had read the .dex format document on Google, but I still got some confuses with some layer.
link_size & link_off : Google said it left unspecified and then said it's hook for runtime, so what it is? The static hook for global or local? or the hook to native library?
map_off : Why it need this redundancy IDs list? is it some kinda like the file address table?
proto_size & proto_off : Not quite sure what it actually is. I had de-assembled an randomly picked dex and look on this section, this section contained some short sign like DD/LL/JLJJ/...brabrabra, that made me more confused about this section. What exactly this section doing for?
Can anyone enlighten me?
The link section has never been specified or used. You might run across some dex files that have a garbage value for these fields, as an attempt to prevent baksmali from being able to be run on them (due to an old bug, that has been fixed for a while).
For the map item, Yes, there is redundancy for the locations of the indexed item sections - the location for these are specified in both the header item and the map item. But the map item is the only place the locations of the offset item sections are specified (the variable size items in the data section)
The prototype section defines the prototype for a method, i.e. the parameters and return type. If you look in the method_id_item, you'll see that it has a reference to a prototype item.

Save images inside webview Android SDK

Im making a simple app for some friends to use on there android phone that shows my website with images. Im using a webview to show the website inside the app. I want the users, to be able to save the actual image. Either by Hold down on the image or actually clicking a button. Been looking around on googles docs ands cant seem to find anything for this.
I haven't actually played around with this yet, but from the docs it appears you have at least two (non-deprecated) options:
getHitTestResult()
requestImageRef(Message msg)
According to the documentation you can use the first option to test for IMAGE_TYPE as result, and a url to the image is provided as well:
If a HTML::img tag is found, the HitTestResult type is set to
IMAGE_TYPE and the url is set in the "extra" field.
The second option will give you a similar result:
Request the url of the image last touched by the user. msg will be
sent to its target with a String representing the url as its object.
Not sure if these options are compatible with a 'long click' too though.
Alternatively, how did you have in mind to link clicking a button to a specific image? Depending on your solution for this, you may also be able to simply capture all loaded image resources using onLoadResource(WebView view, String url), build a list of image references and download the one that button click refers too.

Categories

Resources