TextView with permenant http:// - android

I'm setting up a TextView in my application that users type in a web address, and then a WebView loads it. All of this currently works, and I have it auto filling the TextView with the last used address.
I would like it to prompt the user to put in the address without the https:// by having https:// already there, bold and uneditable. I have seen this done before, but im not even sure how to start on it. any help would be appreciated.

I don't think there is a xml namespace for that, but you can put a TextViewin fron of the EditText and create an illusion like explained here
But the real magic happens when you are reading the EditText which means you put the http:// in front of it.
For example like this
String url = textView.getText().toString();
if (!url.startsWith("http")) {
url = "http://" + url;
}

Related

Reading web and replace some words

I want to read web pages (not mine and specified) and replace some words with other words in the web page loaded.
For example, let's suppose that there is a webpage that shows string "Hello, World! 07-17-2015". And I want to replace all "07" with "08". Then this page will be shown like this: "Hello, World! 08-17-2015". (There is only a string in this example, but I want to execute at any page)
I want to do this with Android. Can I make an app with this feature?
Just make a request to get the HTML content of the page (bazillions methods to do it, lots and lots of libraries, or plain HttpURLConnection).
Then take that output as String and replace what you want:
// Your network implementation
String htmlContent = response.data.replaceAll("07", "08");
Then use a WebView and load this String inside it:
webView.loadData(htmlContent, "utf-8");

Android : How to get HTML content in String from WebView

I just want to get the HTML String from my webview for that i am trying with the following code
webviewTxt.loadUrl("javascript:HTMLOUT.processHTML(document.documentElement.outerHTML);");
But i don't know how can i get this code to string. I even don't know whether this is true code to grab the HTML String or not.
In my webview i have following String
This is a test Demo
Where "test" is written in Italic and "Demo" is written in Bold So i want to get the HTML string from above code.
Above string is just an Example, The string may be anything not the same as above string each time.
If anyone is having any idea then please guide me, I already checked so many link links from SO and other google stuff but i am not able to grab the String in HTML from Webview.

Html content in android not displaying in textview android

I am working on android applications. In my app I am getting the html content and setting it to text view. My html data is displaying in the textview but at one point it stopped. i .e only half of the paragraph is displaying in the textview.
The data is
"The Internet is a global system of interconnected computer networks that use the standard Internet protocol suite (TCP/IP) to serve several billion users worldwide. It is a network of networks that consists of millions of private, public, academic, business, and government networks, of local to global scope, that are linked by a broad array of electronic, wireless, and optical networking technologies. The (water A1c <5.0) may be detrimental in certain populations, such as the elderly and those with cardiovascular disease."
In the above paragraph upto "The (water A1c" the data is displaying in the textview and from there the data is not displaying. Th remaning data is cutted. I tried to trim the data but it didnt work. Please give me any suggestions for this.
Mycode:
Textview.setText((Html.fromHtml(data)));
The below content is being cut in the textview. It is not displaying.
<5.0) may be detrimental in certain populations, such as the elderly and those with cardiovascular disease."
String htmlStr = "<b>" +
context.getResources().getString(R.string.yourText)+
"</b>";
textView.setText(Html.fromHtml(htmlStr));
TextView myTextview;
myTextview= (TextView) findViewById(R.id.my_text_view);
htmltext = <your html (markup) character>;
Spanned sp = Html.fromHtml( htmltext );
myTextview.setText(sp);
Try something like below.
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("Hello Everyone"));
Actually it is the problem with the < symbol.
Just use the ASCII value of < symbol. and that is <.
Take a look here for more ASCII values.
Hope this will help. :)
As Aby Mathew suggested, you can display your data in TextView if you replace < by its HTML equivalent
Code that can be used:
data=data.replace("<","<");
Textview.setText((Html.fromHtml(data)));
Hope it helps :)

Downloading a PDFpage to a string

Having done some basic tutorials, I started making my first real android app in eclipse. I want this app to check if the text in an EditText matches the text on a PDFpage (this one: http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf (it contains my school's schedule changes)). I've found out how to make the app check if the text in the EditText matches a string (with the method contains()), so now the only thing I need to do is to download all of the text of that PDFpage to a string. But I have no idea how to. Or is there maybe a method which I can check with if a PDFpage contains a certain word without downloading the entire website to a string?
Thank You!
A PDF is not a text-file, it is a binary file. Therefore you should not download the data into a string but into a byte array. Then you must extract the text data from the PDF using some PDF library. In that text you then can search your keyword.
The most interesting part will be to extract the text from the PDF. You may look around this site for other questions which tried the same. Here is a quick search or this.

Android TextView enable LinkiFy and Href tags

I want to set a text to the textview which contains href tags as well as normal http links. For ex, text like this "please <a href=/'http://google.com' target='_blank'>click here</a>. or visit http://yahoo.com".
The issue is I am unable to set both properties together. If I set Html.fromHtml to the text, the link with the href tag is highlighted. But the Linkfy property is not working for "http://yahoo.com" and vice versa. Is there any default property to enable both href tags and normal links in a TextView.
Thanks,
I couldn't find one myself as I worked through a similar situation with HREFs and telephone numbers; in lieu of anything better, I am currently using a custom REGEX for calling Linkfiy.addLinks. Calling Linkify.addLinks with a mask "also removes any existing URLSpans attached to the Spannable", which were created by Html.fromHtml. See the Linkify Documentation.
If it's possible using an mx controls Label (spark does not support this any longer) u can use htmlText like the following example:
import mx.controls.Label //class need to be imported
var textview:Label = new Label();
textview.htmlText = "please <a href=/'http://google.com' target='_blank'>click here</a>. or visit http://yahoo.com";
yourItemContainer.addElement(textview);
This should work. But I don't know if it's possible for u using a normal label.

Categories

Resources