How to get Values from HTML String in Android - android

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.

Related

How to decode special characters from JSON. (e.g. " ' " to " ' " )

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"));

How can I get just the Video to play on Android?

I want to play just the video from youtube. but this code i use show more detail just like I open it from the website. how can I get ride of the detail like suggested video, comments, info.... I just want to have the Video on the app. Any help would be appreciate :) thanks
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
WebView webView1 =(WebView)findViewById(R.id.webView1);
webView1.getSettings().setAllowFileAccess(true);
webView1.getSettings().setLoadWithOverviewMode(false);
webView1.getSettings().setUseWideViewPort(false);
webView1.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView1.getSettings().setSupportMultipleWindows(false);
webView1.setWebChromeClient(new WebChromeClient());
webView1.setWebViewClient(new WebViewClient());
webView1.setWebViewClient(new Callback());
webView1.getSettings().setJavaScriptEnabled(true);
webView1.getSettings().setPluginState(PluginState.ON);
String video_path = "http://www.youtube.com/watch?v=jtrltr-uIvw";
Uri uri = Uri.parse(video_path);
uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Use VideoView instead of WebView.
VideoView video = (VideoView)findViewById(R.id.video);
video.setVideoURI(Uri.parse("insert rtsp here"));
video.start();
I had this problem some time ago. The trick is to determine the actual URL of the video and then use MediaPlayer to play the video.
Let's say, you're after this video: http://www.youtube.com/watch?v=ou87i6Oq5M0 - note the video tag: ou87i6Oq5M0. To get the URL of the actual video stream, you can retrieve this resource: http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0?v=2 - this will return the metadata of the youtube video, including the actual URL of the stream:
<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/"CkUCSH47eCp7I2A9Wh5WF00."'><id>tag:youtube.com,2008:video:ou87i6Oq5M0</id><published>2013-09-01T11:21:22.000Z</published><updated>2013-11-29T04:44:29.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='News' label='News & Politics'/><title>WORLDS FASTEST propellar driven AIRCRAFT Russian Tu 95MC Nuclear Bomber</title><content type='application/x-shockwave-flash' src='http://www.youtube.com/v/ou87i6Oq5M0?version=3&f=videos&app=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.in-response-to' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/hdFswfC_Egk?v=2'/><link rel='
alternate' type='text/html' href='http://www.youtube.com/watch?v=ou87i6Oq5M0&feature=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0/related?v=2'/><link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=ou87i6Oq5M0'/><link rel='http://gdata.youtube.com/schemas/2007#uploader' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/D8bmW4A7eYzHrW7sXwsqwQ?v=2'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0?v=2'/><author><name>ArmedForcesUpdate</name><uri>http://gdata.youtube.com/feeds/api/users/ArmedForcesUpdate</uri><yt:userId>D8bmW4A7eYzHrW7sXwsqwQ</yt:userId></author><yt:accessControl action='comment' permission='allowed'/><yt:accessControl action='commentVote' permission='allowed'/><yt:accessControl action='videoRespond' permission='moderated'/><yt:
accessControl action='rate' permission='allowed'/><yt:accessControl action='embed' permission='allowed'/><yt:accessControl action='list' permission='allowed'/><yt:accessControl action='autoPlay' permission='allowed'/><yt:accessControl action='syndicate' permission='allowed'/><gd:comments><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#comments' href='http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0/comments?v=2' countHint='45'/></gd:comments><media:group><media:category label='News & Politics' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>News</media:category><media:content url='http://www.youtube.com/v/ou87i6Oq5M0?version=3&f=videos&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='165' yt:format='5'/><media:content url='rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='165' yt:format='1'/
><media:content url='rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='165' yt:format='6'/><media:credit role='uploader' scheme='urn:youtube' yt:display='ArmedForcesUpdate' yt:type='partner'>armedforcesupdate</media:credit><media:description type='plain'>Russian Aircraft The Tupolev Tu-95 (Russian: Туполев Ту--95; NATO reporting name: Bear) is a large, four-engine turboprop-powered strategic bomber and missile platform. First flown in 1952, the Tu-95 entered service with the Soviet Union in 1956 and is expected to serve the Russian Air Force until at least 2040.[1] A naval development of the bomber is designated Tu-142.
The aircraft has four Kuznetsov NK-12 engines, developed by the Kuznetsov Design Bureau with participation of Ferdinand Brandner and other captured German engineers, each driving contra-rotating propellers. An airliner variant Tu-114 holds the record as the world's fastest propeller-driven aircraft. Some experimental aircraft were designed for theoretically higher speeds, but none attained or registered them. It also remains the only turboprop-powered strategic bomber in operational use. Its distinctively swept-back wings are at 35°, a very sharp angle by the standards of propeller-driven aircraft, and justified by its operating speeds and altitudes. Its blades, which rotate faster than the speed of sound, according to one media source, make it arguably the noisiest military aircraft on earth,[2] with only the experimental 1950s era Republic XF-84H "Thunderscreech" turboprop powered American fighter design as a likely rival.[citation needed] It was reportedly so loud that the underwater Hydrophones of
submerged submarines and SOSUS could detect it.
Russia Listeni/ˈrʌʃə/ or /ˈrʊʃə/ (Russian: Россия, tr. Rossiya, IPA: [rɐˈsʲijə] ( listen)), also officially known as the Russian Federation[10] (Russian: Российская Федерация, tr. Rossiyskaya Federatsiya, IPA: [rɐˈsʲijskəjə fʲɪdʲɪˈrat͡sɨjə] ( listen)), is a country in northern Eurasia.[11] It is a federal semi-presidential republic, comprising 83 federal subjects. From northwest to southeast, Russia shares land borders with Norway, Finland, Estonia, Latvia, Lithuania and Poland (both with Kaliningrad Oblast), Belarus, Ukraine, Georgia, Azerbaijan, Kazakhstan, China, Mongolia, and North Korea. It shares maritime borders with Japan by the Sea of Okhotsk and the US state of Alaska across the Bering Strait. At 17,075,400 square kilometres (6,592,800 sq mi), Russia is the largest country in the world, covering more than one-eighth of the Earth's inhabited land area. Russia is also the world's ninth most populous nation with 143 million people as of 2012.[12] Extending across the entirety of northern Asia and much
of Europe, Russia spans nine time zones and incorporates a wide range of environments and landforms.
An aircraft is a machine that is able to fly by gaining support from the air, or, in general, the atmosphere of a planet. It counters the force of gravity by using either static lift or by using the dynamic lift of an airfoil,[1] or in a few cases the downward thrust from jet engines.
The human activity that surrounds aircraft is called aviation. Crewed aircraft are flown by an onboard pilot, but unmanned aerial vehicles may be remotely controlled or self-controlled by onboard computers. Aircraft may be classified by different criteria, such as lift type, propulsion, usage and others.
The Russian Air Force (Russian: Военно-воздушные cилы России, tr. Voyenno-Vozdushnye Sily Rossii) is the aerial warfare service branch of the Armed Forces of the Russian Federation. It is currently under the command of Lieutenant General Viktor Bondarev. The Russian Navy has its own air arm, the Russian Naval Aviation, which is the former Soviet Aviatsiya Voyenno Morskogo Flota ("Naval Aviation"), or AV-MF).
The Air Force was formed from parts of the former Soviet Air Forces after the dissolution of the Soviet Union in 1991--92. Boris Yeltsin's creation of the Ministry of Defence of the Russian Federation on 7 May 1992, can be taken as a convenient formation date for the new Air Force. Since that time, the Air Force has suffered severe setbacks due to lack of resources, and has constantly shrunk in size. Since Vladimir Putin became President of the Russian Federation however, much more money has been allocated to the Armed Forces as a whole.
The United States Air Force (USAF) is the aerial warfare service branch of the United States Armed Forces and one of the seven American uniformed services. Initially part of the United States Army, the USAF was formed as a separate branch of the military on 18 September 1947 under the National Security Act of 1947.[5] It is the most recent branch of the U.S. military to be formed, and is the largest and one of the world's most technologically advanced air forces. The USAF articulates its core functions as Nuclear Deterrence Operations, Special Operations, Air Superiority, Global Integrated ISR, Space Superiority, Command and Control, Cyberspace Superiority, Personnel Recovery, Global Precision Attack, Building Partnerships, Rapid Global Mobility and Agile.[6]
Vladimir Vladimirovich Putin</media:description><media:keywords/><media:license type='text/html' href='http://www.youtube.com/t/terms'>youtube</media:license><media:player url='http://www.youtube.com/watch?v=ou87i6Oq5M0&feature=youtube_gdata_player'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/default.jpg' height='90' width='120' time='00:01:22.500' yt:name='default'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/1.jpg' height='90' width='120' time='00:00:41.250' yt:name='start'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/2.jpg' height='90' width='120' time='00:01:22.500' yt:name='middle'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/3.jpg' height='90' width='120' time='00:02:03.750' yt:name='end'/><media:title type='plain'
>WORLDS FASTEST propellar driven AIRCRAFT Russian Tu 95MC Nuclear Bomber</media:title><yt:duration seconds='165'/><yt:uploaded>2013-09-01T11:21:22.000Z</yt:uploaded><yt:uploaderId>UCD8bmW4A7eYzHrW7sXwsqwQ</yt:uploaderId><yt:videoid>ou87i6Oq5M0</yt:videoid></media:group><gd:rating average='4.855856' max='5' min='1' numRaters='111' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='0' viewCount='67834'/><yt:rating numDislikes='4' numLikes='107'/></entry>
Don't worry too much about the complexity. All you need is this element from it:
<media:content
url='rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp'
type='video/3gpp'
medium='video'
expression='full'
duration='165'
yt:format='1'/>
Note that there may be more than one media:content element - you need the one with type=video/3gpp` content type. Take the URL from it - this is the URL of the video stream.
Now use VideoView to show your video:
VideoView video = (VideoView)findViewById(R.id.video_player);
video.setVideoURI(Uri.parse(videoUrl));
video.start();
In this code the videoUrl is the URL as shown above, specifically,
rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp

Parsing xml only getting CDATA within Tag

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.

Scheduling latency of Android sensors handlers

rather than an answer I'm looking for an idea here.
I'd like to measure the scheduling latency of sensor sampling in Android. In particular I want to measure the time from the sensor interrupt request to when the bottom half, which is in charge of the data read, is executed.
The bottom half already has, besides the data read, a timestamping instruction. Indeed samples are collected by applications (being java or native, no difference) as a tuple [measurement, timestamp].
The timestamp follows the clock source clock_gettime(CLOCK_MONOTONIC, &t);
So assuming that the bottom-half is not preempted, somehow this timestamp gives an indication of the task scheduling instant. What is missing is a direct or indirect way to find out its corresponding irq instant.
Safely assume that we can ask any sampling rate to the sensor. The driver skeleton is the following (Galaxy's S3 gyroscope)
err = request_threaded_irq(data->client->irq, NULL,
lsm330dlc_gyro_interrupt_thread\
, IRQF_TRIGGER_RISING | IRQF_ONESHOT,\
"lsm330dlc_gyro", data);
static irqreturn_t lsm330dlc_gyro_interrupt_thread(int irq\
, void *lsm330dlc_gyro_data_p) {
...
struct lsm330dlc_gyro_data *data = lsm330dlc_gyro_data_p;
...
res = lsm330dlc_gyro_read_values(data->client,
&data->xyz_data, data->entries);
...
input_report_rel(data->input_dev, REL_RX, gyro_adjusted[0]);
input_report_rel(data->input_dev, REL_RY, gyro_adjusted[1]);
input_report_rel(data->input_dev, REL_RZ, gyro_adjusted[2]);
input_sync(data->input_dev);
...
}
The key constraint is that I need to (well, I only have enough resources to) perform this measurement from user-space, on a commercial device, without toucing and recompliling the kernel. Hopefully with a limited mpact on the experiment accuracy. I don't know if such an experiment is possible with this constraint and so far I couldn't figure out any reasonable method.
I might consider also recompiling the kernel if the experiment then becomes straightforward.
Thanks.
First Its not possible to perform this measurement without touching the kernel.
Second I didnt see any bottom half configured in your ISR code.
Third if at all Bottom half is scheduled and kernel can be recompiled , you can sample jiffie value in ISR and again resample it in bottom half. take the difference between the two samples and subtract that offset from timestamp that is exported to U-space.

How can i stress my phone's CPU programatically?

So i overclocked my phone to 1.664ghz and I know there are apps that test your phone's CPU performance and stressers but I would like to make my own someway. What is the best way to really make your CPU work? I was thinking just making a for loop do 1 million iterations of doing some time-consuming math...but that did not work becuase my phone did it in a few milliseconds i think...i tried trillions of iterations...the app froze but my task manager did not show the cpu even being used by the app. Usually stress test apps show up as red and say cpu:85% ram: 10mb ...So how can i really make my processor seriously think?
To compile a regex string:
Pattern p1 = Pattern.compile("a*b"); // a simple regex
// slightly more complex regex: an attempt at validating email addresses
Pattern p2 = Pattern.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b");
You need to launch these in background threads:
class RegexThread extends Thread {
RegexThread() {
// Create a new, second thread
super("Regex Thread");
start(); // Start the thread
}
// This is the entry point for the second thread.
public void run() {
while(true) {
Pattern p = Pattern.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*#(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b");
}
}
}
class CPUStresser {
public static void main(String args[]) {
static int NUM_THREADS = 10, RUNNING_TIME = 120; // run 10 threads for 120s
for(int i = 0; i < NUM_THREADS; ++i) {
new RegexThread(); // create a new thread
}
Thread.sleep(1000 * RUNNING_TIME);
}
}
(above code appropriated from here)
See how that goes.
I would suggest a slightly different test, it is not a simple mathematical algorithms and functions. There are plenty of odd-looking tests whose results always contains all reviews. You launch the application, it works for a while, and then gives you the result in standard scores. The more points more (or less), it is considered that the device better. But that the comparison results mean in real life, is not always clear. And not all.
Regard to mathematics, the first thing that comes to mind is a massive amount of counting decimal places and the task to count the number "pi"
OK. No problem, we will do it:
Here's a test number one - "The Number Pi" - how long it takes your phone to calculate the ten million digits of Pi (3.14) (if someone said this phrase a hundred years ago, exactly would be immediately went to a psychiatric hospital)
When you feel that the phone is slow. You turn / twist interface. But how to measure it - it is unclear.
Angry Birds run on different devices at different times - perhaps test "Angry Birds"
We think further - get a couple more tests, "heavy book" and "a large page."
algorithm of calculation:
Test "of Pi"
Take the Speed Pi.
Count ten million marks by using a slow algorithm "Abraham Sharp Series. Repeat measurements several times, take the average.
Test "Angry Birds"
Take the very first Angry Birds (not required, but these versions are not the most optimized)
Measure the time from launch to the first sounds of music. Exit. Immediately run over and over again. Repeat several times and take the average.
Test "Large Page"
Measure the load time of heavy site pages. You can do it with your favorite browser :)
You can use This link (sorry for the Cyrillic)
This page is maintained by using "computers browser" along with pictures. Total turns out 6.5 Mb and 99 files (I'm still on this page in its stored version of a small sound file)
All 99 files upload to the phone. Turn off Wi-Fi and mobile Internet (this is important!)
Page opens with your browser. Click the "back" button. And now click "Forward" and measure the time the page is fully loaded. And so a few times. Back-forward, backward-forward. As usual, we take the average.
All results are given in seconds.
During testing all devices that support microSD cards, was one and the same card-Transcend 16 Gb, class 10. And all data on it.
Well, the actual results of the tests for some devices TEST RESULT
https://play.google.com/store/apps/details?id=xcom.saplin.xOPS - the app crunches numbers (integer and float) on multiple threads (2x number of cores) and builds performance and CPU temperature graphs.
https://github.com/maxim-saplin/xOPS-Console/blob/master/Saplin.xOPS/Compute.cs - that's the core of the app

Categories

Resources