I am new to android developing..
i have only one textview like this
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:autoLink="web"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
Then i set settext for textview like
<string name="content_ontheroad">Check road conditions on your route before you leave.\nEach state or territory has a different phone number and\nwebsite detailing relevant information, or ask a local.\n\n
\u2022 ACT 13 22 81\n
http://www.tams.act.gov.au/roads-transport \n\n
\u2022 N SW 13 27 01\n
https://www.livetraffic.com \n\n
\u2022 Northern Territory 1800 246 199 or\n http://www.securent.nt.gov.au/\n\n
\u2022 Queensland 13 19 40 or\n http://www.racq.com.au/roadconditions\n\n
\u2022 South Australia 1300 361 033 or\n
http://www.dpti.sa.gov.au/OutbackRoads\n\n
\u2022 Tasmania 1300 135 513 or\n http://www.dier.tas.gov.au/road_closures_and_delays\n\n
\u2022 Victoria, 13 11 70 or\n http://www.vicroads.vic.gov.au\n\n
\u2022 Western Australia 1800 013 314 or\n https://www.mainroads.wa.gov.au/UsingRoads/RoadTrafficInformation/Pages/RoadTrafficInformation.aspx \n\n
On country roads, always keep alert for wildlife, particularly\n at dawn or dusk when animals may be active. Be cautious,\n scanning both the road ahead and the roadsides. Be\n aware of traffic behind you, as well as oncoming traffic.\n\n
When safe to do so, use your high beam headlights so that\n you can see further when driving at night. However, bright\n lights can dazzle animals and rather than move off the\n road, they may remain stationery and in the path of your\n vehicle.\n\n
When travelling at speed, do not swerve to avoid hitting an\n animal, as this could put you and other motorists in danger.\n Sometimes, it may be impossible to avoid a collision with\n an animal.\n\n
More information:\n\nhttp://www.racv.com.au/wps/wcm/connect/racv/Internet/Primary/travel/before+you+go/driving+tips</string>
it has some more than one link.i enable autolink to textview for open link in default browser.
But i need to open it in webview within my app
Assuming you want to set every href to a new web view...
First, have different text view for every part of your text. Then which part has href, simply set underline and colour blue or anything. Plus you can add other properties separately.
Now every for every textview, give it setOnClick event and redirect them to your webview intent.
Hope this help :)
Related
I am trying to use Tesseract OCR on Android to read the state of a gas meter when you take a picture of it:
This is the output when I parse this image:
vb"
22% BK-G4T ||||||||I||||I|||ii\|||\
’ 64 2007
22?: 06.0"! 'm'lm Mm. 23212274 ,
v 2,0 dm’ 1
pmn 0_5 bar tm ~25°C v‘40"(1 I
1amp é 0_o1m’ sb15°cl :Sp 20°c l
'I ELSTEQ~I¢¢>>InstrogwnSs HB Z _ 18 _ 1013 . ‘
a, 069373593435- 3 I
i'23212214 Y _ w w V'
g
The idea is to extract the first 5 digits of the state of the gas meter ( 06937 on this image ).
My question is, is there a way to train Tesseract to only parse this part of the image? Absolute coordinates are not an option since every picture would be different. I am guessing the best logic would be something like: parse only white numbers on black background.
By changing the page segmentation mode (psm), tesseract 4.00.00 alpha is able to read the meter line characters correctly as 06937598-m3 apart from other characters.
The command used is:
tesseract meter.jpg output --psm 11 -l eng
--psm 11 means to recognize "Sparse text. Find as much text as possible in no particular order".
Here is the output file with showing all the ASCII control characters.
If --psm 11 works on other meter images, then you could just need to search -m3 at the end of the line to extract the who meter line characters. With that, you can get the first 5 digits right away.
Hope this help.
In my CMS I have json responses for different data I insert,and I get them in JSON format.
ie.
[{"id":"7","image":"vangal.jpe","name":"Louis Van Gaal","nationality":"Dutch","managed_from":"14 July 2014",
"article":"Louis van Gaal arrived at Manchester United with an outstanding record of success first in his native Netherlands and subsequently at some of the biggest clubs in the world.\r\n\r\nAs a manager he has won league titles in three different countries, guided a youthful Ajax side to UEFA Champions League glory, as well as lifting the UEFA Cup. His second stint in charge of the Dutch national team ended with the Netherlands making the semi-finals of the 2014 World Cup, a run which included a magnificent 5-1 win over holders Spain.\r\n\r\nBorn Aloysius Paulus Maria van Gaal in Amsterdam on 8 August 1951, he joined Ajax aged 20 and while he never played for the great Dutch club's first team, the influence of the time he spent immersed in its culture of Total Football has never left him.\r\n\r\nHe cut his teeth at professional level after moving over the border to Royal Antwerp in Belgium, but following four years there he returned to Holland to complete his playing career, briefly at Telstar, then for eight years at Sparta Rotterdam before retiring after a short stint at AZ.\r\n\r\nVan Gaal remained at AZ to begin a coaching and management career where the characteristics of fluent passing, talented youngsters being given a chance and canny tactics through a high attention to detail have remained to great effect at the highest level of the global game.\r\n\r\nAfter leaving AZ, van Gaal's coaching education continued under the legendary Leo Beenhakker at Ajax, who he succeeded as first team boss in 1991. The club's fortunes had dipped since the golden era of the 1970s, but under van Gaal Ajax secured three consecutive Eredivisie titles and the UEFA Cup. But more importantly they delivered European Cup success, in its new guise as the Champions League, returning the trophy to the club for the first time in over 20 years.\r\n\r\nA side containing future United star Edwin van der Sar, the De Boer brothers, Frank Rijkaard, Edgar Davids, Clarence Seedorf, Marc Overmars and Patrick Kluivert overcame AC Milan in Vienna, and after this success it was inevitable that van Gaal would be linked with some of the biggest clubs in Europe. He eventually succeeded Bobby Robson at Barcelona in 1997, and after inheriting a set-up that included Jose Mourinho on the coaching staff, his new side won La Liga in his first season in charge, retaining the title the following year.\r\n\r\nWhile at Barca, van Gaal had the first of four meetings with United in the Champions League, handing an 18-year-old Xavi his European debut during the 3-3 draw at Old Trafford. The first goalscorer that night? Ryan Giggs.\r\n\r\nVan Gaal then had spells in charge of the Dutch national side and the Catalan giants again, and following a brief time at Ajax as technical director he returned to AZ and guided them to the Dutch title in 2009.\r\n\r\nThis dramatic success led to Bayern Munich recruiting him, and van Gaal became the first Dutch manager to win the Bundesliga, claiming a league title in his debut season in charge at a club for the second time β something Reds fans would love to see him do again at United.\r\n\r\nA second Champions League final for van Gaal, in 2010, ended in defeat to an Inter Milan side managed by former assistant Mourinho, and after leaving Bayern he took up the reins of the Dutch national side once again and successfully steered them through to the 2014 World Cup finals. The Netherlands won the third place play-off with a 3-0 win over hosts Brazil, but just a few days later van Gaal was officially unveiled in Manchester to begin the next chapter of an already stellar career.\r\n\r\nHis announcement as the next United manager, the club's first continental coach to take charge of the first team, arrived on 19 May 2014. Ryan Giggs was announced as his assistant manager, while assistant coaches Albert Stuivenberg, Frans Hoek (specialising with goalkeepers) and Marcel Bout (focusing on opposition scouting), training physiologist Jos van Dijk and performance analyst Max Reckers also joined a new-look backroom team at Old Trafford.\r\n\r\nVan Gaal, who eventually started work at United on 14 July 2014, said: "It was always a wish for me to work in the Premier League. To work as a manager for Manchester United, the biggest club in the world, makes me very proud. I have managed in games at Old Trafford before and know what an incredible arena it is and how passionate and knowledgeable the fans are. This club has big ambitions; I too have big ambitions. Together I'm sure we will make history.""}]
In this case I have a simple JSON Array with some text in it. However,I can't read some characters from that text like the ' one and "". I hope you can see that from the following screenshot.
How can I take out characters 's? It looks really ugly and hard to read.
Τhanks.
Use like the following
myTextView.setText(Html.fromHtml("ur text here"));
Provided JSON is incorrect, try to parse it using http://jsonlint.com/ first.
If I understand you correctly, you have some issues with ' and ". Try to use \' and \" instead.
Thank you for the replies! Problem is fixed thanks to the user called lal.
myTextView.setText(Html.fromHtml("ur text here"));
I used twitter4j to post tweet include image and text in android. My text has been truncate to less than 140. But I wonder why the server response over 140 characters exception.
Here is my try:
message = trimTweet(message); // guaranteed max length is less than 140
StatusUpdate status = new StatusUpdate(message);
if(bitmapUri != null){
status.setMedia(new File(getRealPathFromURI(getApplicationContext(), bitmapUri)));
}
twitter.updateStatus(status);
The server response:
10-23 19:18:00.842: E//NewsActivity.java:280(25288):
TwitterException{exceptionCode=[b2b52c28-11aaaacd], statusCode=403,
message=Status is over 140 characters., code=186, retryAfter=-1,
rateLimitStatus=null, version=3.0.4}
10-23 19:18:00.842: E//NewsDetailActivity.java:280(25288): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:162)
10-23 19:18:00.842: E//NewsDetailActivity.java:280(25288): at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
10-23 19:18:00.842: E//NewsDetailActivity.java:280(25288): at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
From debug, I can see my tweet message less than 140 characters (sometime is 138 or 139). But when I try to send only 108 or 110 characters, it sent success. Then I wonder twitter4j add my image to tweet text. Is that right?
How can I send image and text with only 140 characters?
Finally I figured out my problem. When adding URL or image, Twitter limit characters down to 118. That 's sound stupid, I think. From this link: http://mediacause.org/10-nonprofit-twitter-tips-140-characters/
We all get tripped up by just how limiting 140 characters can be (it
sounds like a lot until you start typing). Add in a link or a photo,
and your character count for accompanying text is cut down to 118.
Keep this in mind when crafting tweets and include text that gets
straight to the point
Update: Thanks to #Aggressor, now twitter updated limit link depend on the URL that gets t.co wrapped.
The https steals away 23 characters(it was 21), so you have only 117 characters for text.
For non https url, you have 118 characters (wrapped url is 22).
Https:
Http:
I found from the twitter documentation that while Tweets are still limited to 140 characters, the character counting model has evolved over time. Tweets are UTF-8 string content and any UTF-8 character counts as a single character. Strings that are understood as links, such as "http://twitter.com", "twitter.com", "twitter.com/twitterapi" will be automatically converted to t.co. t.co links represent a variant character count (currently "22" for HTTP-based links and "23" for HTTPS-based links). See How Twitter wraps URLs with t.co for more information on how t.co plays a role in character counting. Counting Characters provides more details on character counting strategies.
Use GET help/configuration to programmatically keep track of t.co wrapping lengths. The fields "short_url_length" and "short_url_length_https" will indicate the current lengths.
I am trying to get text from an xml file that looks like so:
<description>
<p>
<strong>Last updated:</strong>
Mon, 19 Aug 2013 23:52:31</p>
<p>Incident is 53% contained.</p>
<![CDATA[<p>The American Fire burning in heavy fuels on extreme slopes about 10 air miles northeast of the community of Foresthill, California, and eight air miles south of Interstate 80 has grown to 14,765 acres.</p> <p><strong>The public is invited to an American Fire update meeting at the Foresthill Veteran's Memorial Hall at 24601 Harrison Street in Foresthill beginning at 7 p.m. tonight.</strong></p> <p>Heavy smoke shaded the fire yesterday, moderating fire behavior. Backing fire with single and group tree torching was observed. On the northeast corner a spot fire was quickly contained by firefighters as they made good progress with hand lines and dozer lines. Along the eastern portion of the fire last night, firefighters conducted a firing operation, meaning they used fire to reduce unburned fuel between the fire line and the main fire. The center portion of the east flank was still very active during the day, but indirect containment lines remained secure. On the extreme south end, firefighters will begin building a very steep hand line today, which descends to the river. The west side of the fire was relatively inactive. Mop-up is occurring in this area, which involves checking the interior of the fire to ensure no hot spots remain that may threaten the containment lines.</p> <p>Firefighters continue to be concerned about dry fuels that have not seen fire in over a century, as well as any winds over 5 m.p.h. and rolling burning debris, all of which could cause a rapid spread of the fire.</p> <p>The National Weather Service has issued a Red Flag Warning for the fire area beginning at 11 a.m. today and extending through 11 p.m. Wednesday. This Warning is due to the threat of abundant lightning and gusty, erratic outflow winds. Significant rainfall and flooding in and around the fire is also possible over the next three days.</p> <p>The Robinson Flat Campground is closed. The Tahoe National Forest has issued a voluntary evacuation notice for Big Oak Flat located near the south end of the fire. Forest Road 43 (Robinson Flat Road) is closed at its intersection with Forest Road 96 (Mosquito Ridge Road).</p> <p>An emergency closure order is in place for portions of National Forest System lands within and adjacent to the American Fire. A map and description of the closed area can be obtained at Tahoe National Forest offices as well as online at http://www.fs.usda.gov/tahoe. Portions of the Foresthill Divide road are closed.</p> <p><strong>At 6 a.m. today, management of the fire was transferred to the California Interagency Management Team 4.</strong></p> <p>Firefighter and public safety are the highest priority.</p>]]>
<p>
View American Wildfire web site
</p>
<p>
<strong>NOTE: </strong>
All fire perimeters and points are approximations.</p>
</description>
When I parse it, I can get all the information within the CDATA area, but the rest of it is ignored. I am parsing and putting into my text view like so:
description.setText(extras.getString("desc"));
I am using android query and can have it format no problem with this:
aq.id(R.id.description).text(Html.fromHtml(extras.getString("desc")));
However, same issue, just getting the cdata info. My log.v() shows just the info between cdata. So I guess I need to escape it somehow? Why is the text outside of cdata being ignored?
Thanks
Thanks
Just change
if(child.getNodeType() == Node.TEXT_NODE)
to
if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE)
in XMLParser.java file.
I was able to get rid of cdata this way:
for (XmlDom entry : entries) {
XmlDom description = entry.tag("description");
String cdatareplace = description.toString();
String desc = cdatareplace.replace("<![CDATA[", "");
desc = desc.replace("]]>", "");
kmllist.add(new KML(entry.text("name"), desc));
}
Add the entry tag to the variable then use string replace to get rid of the cdata and then show all of the text within the tags. Works fine.
I have a problem that I want to get different values from different tags from HTML String as, <p><div class=\"image_wrapper\" style=\"width:320px;\"><img name=\"tccimg_100322484_s\" **title=\"2011 Chevrolet Corvette 2-door Coupe Z06 w/2LZ Angular Front Exterior View\"** src=\"http://images.thecarconnection.com/sml/2011-chevrolet-corvette-2-door-coupe-z06-w-2lz-angular-front-exterior-view_100322484_s.jpg\" alt=\"2011 Chevrolet Corvette 2-door Coupe Z06 w/2LZ Angular Front Exterior View\" width=\"320\" height=\"240\" /><p>2011 Chevrolet Corvette 2-door Coupe Z06 w/2LZ Angular Front Exterior View</p><a name=\"tccwrp_100322484\" class=\"enlarge\" href=\"/image/100322484_2011-chevrolet-corvette-2-door-coupe-z06-w-2lz-angular-front-exterior-view\" target=\"_blank\">Enlarge Photo</a></div></p>\n<p>The Chevrolet Corvette is an American icon: a rear-wheel drive, two-seat sports car that started its legendary run in 1953 and has seen 57 years of continuous production in Flint, Michigan, St. Louis, Missouri and most recently in Bowling Green, Kentucky. Over the years it has constantly evolved to lead performance and value, with occasional lows and numerous highs along the way. Though it has little domestic competition, cars as disparate as the Dodge Viper, Porsche Boxster and 911, and the Nissan GT-R and 370Z can be considered rivals in terms of performance and/or price. The Chevrolet Corvette is priced from $48,000 to $56,000 for the standard Coupe and Convertible, from $58,000 to $68,000 for the Grand Sport, from $75,000 to $82,000 for the Z06, and from $106,800 for the ZR1.</p>\n<p>Over the past 57 years of production, there have been six generations of Corvette. The first 1953 models featured solid rear axles and inline six-cylinder engines, though in 1955, the V-8 became standard. When the second generation \"Sting Ray\" debuted in 1963, independent rear suspension was added and output was increased to 360 horsepower. A big-block 6.5-liter model was added in 1965, before the famous 427 cubic inch (7.0-liter) engine joined in 1966. The third-gen car began its run in 1968, running for 13 years until 1982--the longest run of the various Corvette generations. The new, fender-flared body style was the primary new addition to the line, along with a three-year run for the ZR-1 performance edition, though emissions and fuel regulations conspired to restrict power output and potential of Corvettes throughout the 1970s. The fourth-generation Corvette hit the street in 1983 as a 1984 year model, bringing with it a complete redesign of the car aside from the engine, with a sleek, modern design and digital instruments, and the second ZR-1 performance version. The fifth-gen car, introduced in 1997, saw another major upgrade, with improved build quality, more performance, and better handling the result. The Z06 model was introduced in 2001, and engines continued to be upgraded, producing 405 horsepower in the Z06.</p>\n<p>The sixth and current Corvette generation debuted in 2005, and brought with it all new bodywork and improved suspension. Power climbed to 400 horsepower for the base Corvette initially, now up to 430 horsepower from its 6.2-liter V-8 LS3 engine, and 505 horsepower for the current 7.0-liter Z06. The ZR1 was added back to the lineup in late 2007 as a 2008 year model, producing 638 horsepower from a supercharged 6.2-liter V-8 engine. Currently available in Coupe, Convertible, a Grand Sport version with upgraded brakes and special bodywork, the high-performance Z06, and the supercar-rivaling ZR1.</p>\n<p>The Coupe and Convertible are the standard Corvettes, with 430 horsepower output and all the conveniences of a modern car, including available Bluetooth on some models, a choice of six-speed manual or automatic transmission, and available leather interior. The Grand Sport is also available as both a coupe and convertible, though the coupe gets a few performance upgrades over the soft top, including a dry-sump oil system when equipped with the six-speed manual transmission, plus the upgraded brakes and flared fenders that both variants get. The Corvette Z06 ups the performance ante with extensive use of carbon fiber body panels and components, an aluminum frame, and a 505-horsepower engine. The ZR1 is king of the hill, its massive power output combined with Brembo ceramic carbon brakes, visible carbon fiber weave components, and a 205-mph top speed. Despite their huge power and impressive performance figures, the brawny engines in the Corvette enable it to achieve up to 26 mpg on the highway.</p>\n<p>No major changes were made for the 2012 model year, though the range did get interior updates, new technology packages, and a range of new exterior colors. High-performance Z06 and ZR1 models also got new performance packages.</p>\n<p>For 2013, a new 427 Convertible Collector Edition has been added, pairing the Z06's LS7 V-8 engine with a Corvette Convertible chassis and unique 60th Anniversary touches. A 60th Anniversary Package will also be available on all 2013 model Corvettes, adding a special touch to celebrate six decades of the Corvette. The rest of the line carries forward largely unchanged from last year.</p>\n<p>The next major generational upgrade is expected to come in late 2013, with the seventh-generation car drawing on GM's global resources for its new design--the first time the Corvette team has looked outside the U.S. for the iconic 'Vette.</p>\n"
I want to get Image title value from this html string in the starting, but I am unable to get that. I am using Jsoup for parsing of this HTML String as,
Code:
Document doc = Jsoup.parse(html);
Elements element = doc.getAllElements();
for(Element e: element)
{
Elements str = e.getElementsByTag("img");
for(Element el: str)
{
String title = el.getElementsByAttribute("title").text();
System.out.println("The Title:"+title);
}
}
Please suggest me any solution regarding the same.
Thanks in advance.
Replace the following line:
String title = el.getElementsByAttribute("title").text();
with
String title = el.attr("title");
Explanation: the function call getElementsByAttribute("title") will return a List of Elements (see Jsoup Doumentation - Element), when really you just want to look at the attribute for a specific element. See also Jsoup Documentation - Node.