<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Beneti</title>
	<atom:link href="http://www.beneti.com.br/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.beneti.com.br</link>
	<description>Engenharia, TI e algo mais...</description>
	<lastBuildDate>Thu, 10 Nov 2011 00:05:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>RubyConf 2011 &#8211; #eufui</title>
		<link>http://www.beneti.com.br/2011/11/09/rubyconf-2011-eufui/</link>
		<comments>http://www.beneti.com.br/2011/11/09/rubyconf-2011-eufui/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 00:05:00 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[evento]]></category>
		<category><![CDATA[rubyconf]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=516</guid>
		<description><![CDATA[Aconteceu dias 03 e 04/11 no Centro de Convenções Frei Caneca, a edição de 2011 do RubyConf. Foi o primeiro ano que participei e não tive uma boa impressão. Com o tema &#8220;A experiência dos outros aumenta a sua. Aproveite&#8221;, não rolou legal na minha opinião. O tema é interessante, mas eu senti que tinhas [...]]]></description>
			<content:encoded><![CDATA[<p><center><img class="aligncenter size-full wp-image-517" title="LogoRubyConf" src="http://www.beneti.com.br/wp-content/uploads/2011/11/LogoRubyConf.jpg" alt="" width="335" height="107" /></center><br />
Aconteceu dias 03 e 04/11 no Centro de Convenções Frei Caneca, a edição de 2011 do RubyConf. Foi o primeiro ano que participei e não tive uma boa impressão. Com o tema &#8220;A experiência dos outros aumenta a sua. Aproveite&#8221;, não rolou legal na minha opinião. O tema é interessante, mas eu senti que tinhas um pessoal muito bom tecnicamente, mas que não tem &#8220;preparo&#8221; para palestrar&#8230; sem contar os &#8220;chico estrela&#8221;. Algumas palestras foram muito maçantes ao ponto de eu cochilar e brigar para ficar acordado.</p>
<p>A abertura ficou com a palestra &#8220;Ruby é fácil?&#8221; com o <a href="http://www.rubyconf.com.br/br/talks/david-a-black-146.html" target="_blank">David A. Black</a>. Ele tem mais de 10 anos de experiência com Ruby e foi uma palestra bem interessante. Teve a palestra do inglês <a href="http://www.rubyconf.com.br/br/talks/martyn-loughran-153.html" target="_blank">Martyn Loughran</a> que é CTO do Pusher, que foi interessante também. E só. De 8 palestras que assisti somente 2 eu gostei. No 2o dia, a primeira palestra era a mais esperada <a href="http://www.rubyconf.com.br/br/talks/aaron-patterson-147.html" target="_blank">&#8220;Quem faz o melhor churrasco?&#8221;</a>, com o <a href="https://twitter.com/#!/tenderlove" target="_blank">TenderLove</a>, que dispensa comentários. Só não foi a melhor palestra para mim pois dei a sorte de assistir a palestra do Evan &#8220;<a href="https://twitter.com/#!/rabble" target="_blank">Rabble</a>&#8221; Henshaw, <a href="http://www.rubyconf.com.br/br/talks/evan-henshaw-150.html" target="_blank">&#8220;Lean Startups para o Hacker Ruby&#8221;</a>. Essa sim, foi fantástica, pois o assunto startup/empreendedorismo me interessa demais e o cara é muito gente boa. Eu gostei da palestra do <a href="http://www.rubyconf.com.br/br/talks/bruno-oliveira-abstractj-73.html" target="_blank">Bruno Oliveira</a> também, falando do projeto <a href="http://torquebox.org/" target="_blank">TorqueBox</a>, que é rodar aplicações Rails/Sinatra ou qualquer uma que use o Rack em cima do JBoss. A vantagem é ter suporte a mensageria ou agendamento de tarefas, por exemplo. E só. Teve a palestra do <a href="http://www.rubyconf.com.br/br/talks/jose-valim-151.html" target="_blank">José Valim</a>, que foi uma introdução de uma aula de compiladores, deu uma dica de um livro e falou do que ele fez no Erlang. Teve a palestra do <a href="http://www.rubyconf.com.br/br/talks/nick-sutterer-7.html" target="_blank">Nick Sutterer</a> que falaram que foi bacana, mas dei o azar de não assistir. Escolhi mal.</p>
<p>Não gostei de algumas atitudes de alguns palestrantes. Eu encaro da seguinte forma: quando você é um palestrante, você de certa forma é um formador de opinião, então tem que tomar cuidado com o linguajar, evitar palavrões/gírias, evitar &#8220;pra mim fazer&#8221; e ainda ao dizer &#8220;não use tal coisa&#8230;&#8221;, explicar o porque. Dizer &#8220;não use tal coisa porque é um lixo/merda/tosco&#8221; não leva a nada.</p>
<p>Sem menosprezar ninguém, pois sei que dá trabalho organizar um evento e ainda elaborar uma palestra, mas eu esperava mais do evento. Não vou comparar eventos também. Ano passado disseram que foi bem interessante, esse ano eu não achei. Mas ano que vem, com certeza estarei presente para ver. Vai que esse ano foi um azar. Uma coisa que me irrita um pouco são os fanboys-xiitas. De um lado escuto &#8220;java é um lixo. é verboso. é chato.&#8221;, do outro lado &#8220;ruby não escala. ruby é de vagabundo.&#8221; ou então &#8220;iphone dá de 1000 no android. android é um lixo.&#8221;&#8230; tudo o que eu leio é mimimi.</p>
<p><center><img class="aligncenter size-full wp-image-518" title="rubyconf" src="http://www.beneti.com.br/wp-content/uploads/2011/11/rubyconf.jpg" alt="" width="466" height="350" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/11/09/rubyconf-2011-eufui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GDD2011 &#8211; #eufui</title>
		<link>http://www.beneti.com.br/2011/09/18/gdd2011-eufui/</link>
		<comments>http://www.beneti.com.br/2011/09/18/gdd2011-eufui/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 18:26:43 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Eventos]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=502</guid>
		<description><![CDATA[Aconteceu dia 16/09 no Sheraton WTC Hotel, a edição de 2011 do Google Developer Day (GDD). Foi o primeiro ano que participei e saí com sensação de &#8220;quero ir em todos&#8221;. Até fui ver quanto fica pra ir no Google IO, mas muito caro. O evento focou android, html5, cloud, social e tech em geral. [...]]]></description>
			<content:encoded><![CDATA[<p><center><img class="aligncenter size-full wp-image-503" title="google developer day 2011 sao paulo" src="http://www.beneti.com.br/wp-content/uploads/2011/09/logo_google-developer-day-brasil-2011.png" alt="" width="218" height="442" /></center></p>
<p>Aconteceu dia 16/09 no Sheraton WTC Hotel, a edição de 2011 do Google Developer Day (GDD). Foi o primeiro ano que participei e saí com sensação de &#8220;quero ir em todos&#8221;. Até fui ver quanto fica pra ir no Google IO, mas muito caro. O evento focou android, html5, cloud, social e tech em geral. O evento estava dividido em quatro salas: verde, vermelha, amarela e azul. Eu basicamente fiquei na sala verde onde o tema foi android. Assisti quatro palestras e depois fui para a sala azul.</p>
<p>A primeira palestra foi com o <a title="twitter do bruno oliveira" href="http://twitter.com/#!/btco">Bruno Oliveira</a> com o título &#8216;<a title="Resumo" href="http://www.google.com/intl/pt-BR/events/developerday/2011/sao-paulo/agenda/session_2004.html" target="_blank">O que há de novo e importante no Android</a>&#8216;, onde ele mostrou principalmente as novidades da versão Honeycomb e o que podemos esperar com a versão Ice Cream Sandwich. Em seguida foi a palestra do <a href="http://twitter.com/#!/dagalpin" target="_blank">Dan Galpin</a>, &#8216;<a href="http://www.google.com/intl/pt-BR/events/developerday/2011/sao-paulo/agenda/session_2000.html" target="_blank">Android Market para desenvolvedores</a>&#8216;. Foi a terceira vez que assisti essa palestra, sendo as anteriores no Google IO e no TDC2011. O conteúdo da palestra é sobre os piratas e vampiros, melhores práticas e dicas de como implementar ou não, principalmente no In-App billing, que é a venda de conteúdo dentro da aplicação. Excelente a palestra.</p>
<p>Depois tivemos uma pausa para o almoço. O evento serviu um almoço, bacana. Eu gostei. Lanche, fruta, refrigerante&#8230; bem gostoso. Vi gente reclamando, era só ir no shopping, não passa vontade não. Na volta do almoço, outra palesta com o Bruno, agora com o título &#8216;<a href="http://www.google.com/intl/pt-BR/events/developerday/2011/sao-paulo/agenda/session_2001.html" target="_blank">Excelência na experiência do usuário Android</a>&#8216;. O conteúdo foi parecido com a palestra dele no TDC2011, foi interessante rever. Depois outra palestra com o Dan com o título &#8216;<a href="http://www.google.com/intl/pt-BR/events/developerday/2011/sao-paulo/agenda/session_2003.html" target="_blank">Gráficos de alto desempenho para Android</a>&#8216;. Confesso que não me prendeu muito, pois falou muito de 2D, 3D, renderscript, NDK e eu não estou indo muito atrás disso.</p>
<p>Após o break, fui pra sala azul e vi a palestra &#8216;Construa seu negócio com aplicativos móveis&#8217; com o Peter Fernandez. Falou bastante de maneiras de ganhar dinheiro com um aplicativo móvel, falou do AdMob e contou com a presença do Gui Schvartsman da &#8216;Best, Cool &amp; Fun Games&#8217; (empresa do Ant Smasher), que falou que a principal fonte de renda ainda é a propaganda.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-505" title="eufui" src="http://www.beneti.com.br/wp-content/uploads/2011/09/399464174.jpg" alt="" width="480" height="359" /></p>
<p>Bom, resumindo, foi um evento bacana. Pretendo ir sempre que possível.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/09/18/gdd2011-eufui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TDC2011 &#8211; #eufui</title>
		<link>http://www.beneti.com.br/2011/09/15/tdc2011-eufui/</link>
		<comments>http://www.beneti.com.br/2011/09/15/tdc2011-eufui/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 12:36:48 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Eventos]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=492</guid>
		<description><![CDATA[Esse post vem com um atraso de quase dois meses. De 6 a 10 de julho, aconteceu em São Paulo a edição de 2011 do TDC (The Developers Conference). O evento é organizado pela Globalcode (@globalcode) que tenta montar trilhas que agradem todas as comunidades, seja Java, ruby, C/C++, empreendedorismo, teste, mobile, php e etc. [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.beneti.com.br/wp-content/uploads/2011/09/tdc2011.jpg"><img class="aligncenter size-full wp-image-494" title="tdc2011" src="http://www.beneti.com.br/wp-content/uploads/2011/09/tdc2011.jpg" alt="" width="495" height="270" /></a></p>
<p>Esse post vem com um atraso de quase dois meses. De 6 a 10 de julho, aconteceu em São Paulo a edição de 2011 do TDC (The Developers Conference). O evento é organizado pela Globalcode (<a href="http://twitter.com/globalcode" target="_blank">@globalcode</a>) que tenta montar <a href="http://www.thedevelopersconference.com.br/tdc/2011/saopaulo/trilhas" target="_blank">trilhas</a> que agradem todas as comunidades, seja Java, ruby, C/C++, empreendedorismo, teste, mobile, php e etc. Novamente eu só participei de uma trilha, só consegui ir na quarta-feira e foram palestras bem bacanas. Esse ano o Neto (<a href="http://twitter.com/netomarin" target="_blank">@netomarin</a>) conseguiu montar duas trilhas, android e mobile. Eu fui na de android, pois é específico e era o que eu queria.</p>
<p>Foram 7 palestras, que eu gostaria de falar em detalhes sobre todas, mas falarei apenas das duas (resumido) que me chamaram mais a atenção: Construindo Aplicativos Android de Alto Desempenho, com o Bruno Oliveira e Melhores Práticas para Interfaces de Usuário, com o Tim Bray, ambos da Google. A primeira, do Bruno, ele falou basicamente do ANR (application not responding), como acontece, o que deve ser feito para evitar, boas práticas, frisou várias vezes para o uso de AsyncTask, para não travar a UI e alertou que o usuário é extremamente impaciente, que é fato. Se sua aplicação começa a dar ANR, o usuário pode começar a dar nota baixa no market, desinstalar e a única coisa que ele não vai fazer é te mandar o erro, vai simplesmente te colocar com 1 estrela e comentar &#8220;não funciona&#8221; ou &#8220;trava&#8221;.</p>
<p>Já a palestra do Tim Bray, foi no stadium, que é um auditório. Ele falou sobre as melhores práticas das interfaces, mas focando os tablets. Mostrou alguns exemplos, disse que se você quer fazer uma aplicação bacana, tem que ter um designer, que é o cara que entende. Você pode até tentar fazer algo bacana, mas vai ficar feio. Eu, particularmente, não tenho a manha. Após a palestra, eu fui trocar uma idéia com ele sobre widgets, que ele não tinha comentado. Acabei mostrando minha aplicação (apenas um &#8216;hour track&#8217;) que eu usava um widget para marcar a entrada e saída.</p>
<p style="text-align: left;"><img class="aligncenter size-full wp-image-495" title="tdc" src="http://www.beneti.com.br/wp-content/uploads/2011/09/tdc.jpg" alt="" width="490" height="327" /></p>
<p>Resumindo, o TDC é um evento bem bacana, tem palestras para todos os gostos. Esse ano, o almoço foi por conta deles também, um lanche do subway e refrigerante. Quem não puder ir, ou achar caro, eles transmitem as palestras do stadium. O TDC acontece em outras cidades também, então fique atento no site: <a href="http://www.thedevelopersconference.com.br/">http://www.thedevelopersconference.com.br/</a></p>
<p>Caso queira instalar o PontoDroid (minha app), segue o <a href="https://market.android.com/details?id=br.com.minervamobile.pontodroid" target="_blank">link no market</a>. E amanhã tem Google Developer Day, espero fazer um post mais rápido.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/09/15/tdc2011-eufui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Android] &#8211; Admob</title>
		<link>http://www.beneti.com.br/2011/06/11/android-admob/</link>
		<comments>http://www.beneti.com.br/2011/06/11/android-admob/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 20:19:04 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[admob]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[propaganda]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=477</guid>
		<description><![CDATA[Bom, hoje vou dar uma dica para a adicionar propaganda na sua aplicação android. Apesar do AdMob ter a documentação, pode existir alguma falha no entendimento. Primeiro passo, claro é você ser cadastrado no AdMob e ter o seu ID editor da aplicação. É necessário baixar o SDK do AdMob. Coloque o .jar em algum [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-408" title="bg_logo" src="http://www.beneti.com.br/wp-content/uploads/2010/10/bg_logo.png" alt="" width="180" height="50" /></p>
<p>Bom, hoje vou dar uma dica para a adicionar propaganda na sua aplicação android. Apesar do AdMob ter a documentação, pode existir alguma falha no entendimento. Primeiro passo, claro é você ser cadastrado no AdMob e ter o seu ID editor da aplicação. É necessário baixar o SDK do AdMob. Coloque o .jar em algum lugar que você esteja acostumado a deixar e adicione no projeto. Caso tenha dúvida de como fazer isso, siga:</p>
<ol>
<li>Clique com o botão direito em cima do projeto e clique em <strong>Properties</strong>;</li>
<li>Clique em <strong>Java Build Path</strong>, do lado esquerdo;</li>
<li>Clique na aba <strong>Libraries</strong>;</li>
<li>Clique em <strong>Add Jars&#8230;</strong> ou <strong>Add External Jars&#8230;</strong> (dependendo de onde você colocou o arquivo .jar);</li>
<li>Selecione o arquivo (hoje o nome é <em>GoogleAdMobAdsSdk-4.1.0.jar</em>) e dê OK;</li>
</ol>
<p>Feito isso, vamos ao que interessa. É necessário alterar o manifest, criar um resource, adicionar esse resource no layout, chamar a propaganda e testar.</p>
<p><strong>Alterando o manifest</strong></p>
<p>Insira a seguinte linha:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;activity</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;com.google.ads.AdActivity&quot;</span> <span style="color: #000066;">android:configChanges</span>=<span style="color: #ff0000;">&quot;keyboard|keyboardHidden|orientation&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Para o AdMob funcionar, são duas permissões. Adicione:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.INTERNET&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.ACCESS_NETWORK_STATE&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p><strong>Criando o resource</strong></p>
<p>Caso já exista o arquivo <em>attrs.xml</em> dentro do diretório values, apenas acrescente o código abaixo, apartir da tag resource. Caso não exista, crie o arquivo e adicione tudo.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;declare-styleable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.google.ads.AdView&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attr</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;adSize&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enum</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;BANNER&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enum</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IAB_MRECT&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enum</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IAB_BANNER&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enum</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IAB_LEADERBOARD&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attr</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;adUnitId&quot;</span> <span style="color: #000066;">format</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/declare-styleable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Adicionando o resource no layout</strong></p>
<p>Abra o layout que você deseja colocar a propaganda e insira o código:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xmlns:ads</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/lib/com.google.ads&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;com.google.ads.AdView</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/adView&quot;</span></span>
<span style="color: #009900;">                         <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">                         <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">                         <span style="color: #000066;">ads:adUnitId</span>=<span style="color: #ff0000;">&quot;MY_AD_UNIT_ID&quot;</span></span>
<span style="color: #009900;">                         <span style="color: #000066;">ads:adSize</span>=<span style="color: #ff0000;">&quot;BANNER&quot;</span></span>
<span style="color: #009900;">                         <span style="color: #000066;">ads:loadAdOnCreate</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Note que a linha ( xmlns:ads=&#8221;http://schemas.android.com/apk/lib/com.google.ads&#8221; ) é extremamente importante. Se você <em><span style="text-decoration: underline;">NÃO</span></em> colocar, dá erro de parse do XML e se você colocar <em><span style="text-decoration: underline;">ERRADO</span></em> vai dar erro na hora de exibir. É necessário alterar o <strong>MY_AD_UNIT_ID</strong>, para o ID do editor.</p>
<p><strong>Chamando a propaganda</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">AdView adView <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AdView<span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">adView</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
AdRequest adRequest <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AdRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
adView.<span style="color: #006633;">loadAd</span><span style="color: #009900;">&#40;</span>adRequest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Testando no emulador</strong></p>
<p>Para aparecer a propaganda e você conseguir ver, adicione a seguinte linha, antes do adView.load:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">adRequest.<span style="color: #006633;">addTestDevice</span><span style="color: #009900;">&#40;</span>AdRequest.<span style="color: #006633;">TEST_EMULATOR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p lang="java">Pronto. Espero ter sido de ajuda. Uma outra observação, caso dê o erro Error inflating class com.admob.android.ads.AdView, é por que o recurso não foi definido, no passo do attrs.xml. Até a próxima!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/06/11/android-admob/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>[Android] &#8211; AsyncTask</title>
		<link>http://www.beneti.com.br/2011/05/24/android-asynctask/</link>
		<comments>http://www.beneti.com.br/2011/05/24/android-asynctask/#comments</comments>
		<pubDate>Wed, 25 May 2011 01:49:21 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[async]]></category>
		<category><![CDATA[asynctask]]></category>
		<category><![CDATA[dica]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=471</guid>
		<description><![CDATA[Hoje vou dar uma dica sobre o AsyncTask. As vezes temos a necessidade de realizar tarefas em background, seja para baixar um conteúdo ou atualizar informações de um servidor. É comum pensarmos em utilizar threads. É um caminho que requer alguns cuidados. Para evitar o uso e manipulação de threads e facilitar as tarefas executadas [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-408" title="bg_logo" src="http://www.beneti.com.br/wp-content/uploads/2010/10/bg_logo.png" alt="" width="180" height="50" /></p>
<p>Hoje vou dar uma dica sobre o AsyncTask. As vezes temos a necessidade de realizar tarefas em background, seja para baixar um conteúdo ou atualizar informações de um servidor. É comum pensarmos em utilizar threads. É um caminho que requer alguns cuidados. Para evitar o uso e manipulação de threads e facilitar as tarefas executadas em background pode-se utilizar a classe AsyncTask. A implementação é simples.</p>
<p>É necessário extender a classe AsyncTask e implementar o método doInBackground.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> SomeTask <span style="color: #000000; font-weight: bold;">extends</span> AsyncTask<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> ProgressDialog dialog <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ProgressDialog<span style="color: #009900;">&#40;</span>MainActivity.<span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPreExecute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dialog</span>.<span style="color: #006633;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Downloading...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dialog</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Void</span> doInBackground<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>... <span style="color: #006633;">params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// doSomething</span>
      someMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPostExecute<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Void</span> unused<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dialog</span>.<span style="color: #006633;">isShowing</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dialog</span>.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note que, com esse pequeno trecho de código, aparecerá um dialog com a mensagem &#8220;Downloading&#8230;&#8221;, executará o método someMethod() e no final esconderá a dialog. Simples, não? Note também os métodos onPreExecute, ou seja, será chamado antes do doInBackground e o onPostExecute, ou seja, após o doInBackground. E como disparar isso? Basta acrescentar a seguinte linha de código:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> SomeTask<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Espero que a dica tenha sido útil e facilite! <img src='http://www.beneti.com.br/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/05/24/android-asynctask/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Startup Weekend Campinas &#8211; #eufui</title>
		<link>http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/</link>
		<comments>http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/#comments</comments>
		<pubDate>Tue, 17 May 2011 03:17:14 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[startupweekcps]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=447</guid>
		<description><![CDATA[Bom, no último final de semana (13 a 15 de maio) aconteceu em Campinas o Startup Weekend. É um evento que coloca todo mundo que quer ser empreendedor, quer fazer uma startup, junto para desenvolver uma idéia, no final ter um protótipo e ainda participar da competição. Confesso, que minhas expectativas eram outras. Fui ao [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-448" title="campinas-logobanner-01" src="http://www.beneti.com.br/wp-content/uploads/2011/05/campinas-logobanner-01.jpg" alt="" width="525" height="126" /></p>
<p>Bom, no último final de semana (13 a 15 de maio) aconteceu em Campinas o <a href="http://campinas.startupweekend.org/" target="_blank">Startup Weekend</a>. É um evento que coloca todo mundo que quer ser empreendedor, quer fazer uma startup, junto para desenvolver uma idéia, no final ter um protótipo e ainda participar da competição. Confesso, que minhas expectativas eram outras. Fui ao evento achando que no final eu estaria apto a desenvolver um &#8220;Business Model Canvas&#8221; e sabendo um pouco mais sobre a metodolodia &#8220;Lean Startup&#8221;&#8230; mas para a minha surpresa não foi bem assim. Foi MUITO mais que isso.</p>
<p>O evento começou com três painéis, sendo: Investidor, Startup e Grande Empresa. O primeiro painel, contou com a <a href="http://br.linkedin.com/pub/thais-nagata/0/306/422" target="_blank">Thais Nagata</a>, profissional da BM&amp;F, que comentou principalmente que uma empresa deve visar entrar na bolsa um dia, mas que deve seguir todo um fluxo sustentável de investimento, passando pelos angels/seeds, depois o venture capital, private equity e por fim o IPO. Foi uma mini-palestra, interessante (tinham pouco tempo para falar). O segundo palestrante foi o <a href="http://br.linkedin.com/pub/marcio-filho/12/448/68" target="_blank">Marcio Santos Filho</a> da Inseed Investimentos, que contou sobre o Venture Capital, &#8220;como chegar lá&#8221;, estimulando as pessoas a participarem dos eventos como Meetup, Startup Weekend, Desafio Brasil e outros. Encerrando o painel, quem falou foi o <a href="http://br.linkedin.com/pub/francisco-martinez/8/437/b26" target="_blank">Francisco Martinez</a> da Integra, que nos deu uma aula (pelo menos foi a sensação que eu tive). Falou dos fatores de sucesso, os fatores de insucesso, way-out e ainda nos passou algumas dicas.</p>
<p>O segundo painel, foi o da grande empresa que contou somente com um palestrante, Benedito Luis Fayan que nos contou as iniciativas da Telefônica em atacar &#8220;novos&#8221; segmentos através da inovação e com as startups, citando a TecTotal e AtHome.</p>
<p>O terceiro e último painel, foi o da startup, que o Julio Vasconcellos (criado do PeixeUrbano) nos contou rapidamente a história do site. Foi interessante e foi do jeito que eu imaginei, poucos pessoas, mas as pessoas certas, um de marketing, um de TI e um de vendas. O resultado está aí, não precisa nem comentar.</p>
<p>Após isso, teve início aos pitches. Se você não sabe o que é, eu te explico rapidamente. Você tem um minuto para vender a sua idéia. Foram 33 idéias no total. Vejam o meu pitch desastroso (eu nunca tinha feito um) parecendo uma sessão de stand-up comedy. Juro que foi sem querer. É um vídeo longo, o meu está no minuto 41.</p>
<p><iframe width="448" height="340" src="http://cdn.livestream.com/embed/innoveur?layout=4&amp;clip=flv_b629cb44-9d74-44d0-8f83-cf616acca1c5&amp;autoplay=false" style="border:0;outline:0" frameborder="0" scrolling="no"></iframe></p>
<p>Após os pitches, houve uma votação onde cada um poderia escolher 3 pitches que gostou. Eu votei no &#8220;ToComFome&#8221; que virou &#8220;PaladarApp&#8221;, votei no &#8220;Nossos Peludos&#8221; e votei no &#8220;Social Book&#8221;. A minha idéia foi selecionada, mas só porque tinha vários amigos meus lá, achei injusto e abri mão dela. Acabei trabalhando na idéia dos &#8220;Nossos Peludos&#8221;. A idéia da Marina, é fazer uma espécie de agregador de ONGs de animais abandonados e possibilitar que qualquer pessoa ajude um determinado cachorro de uma maneira mais fácil. A idéia é aumentar a visibilidade das ONGs e ainda permitir que empresas do ramo de Pet tenham uma exposição maior da sua marca para projetos sociais.</p>
<p>Na equipe estavam eu, o <a href="http://twitter.com/#!/guiceolin" target="_blank">Guilherme Ceolin</a>, <a href="http://twitter.com/#!/danieltdt" target="_blank">Daniel Teixeira</a>, <a href="http://twitter.com/#!/fabianoamaro" target="_blank">Fabiano Amaro</a>, Pedro Ruggiero, Marina de Camargo (dona da idéia) e o Euripedes Almeida. Eu e a nerdaiada do Ceolin e do Daniel, ficamos responsáveis pelo desenvolvimento do protótipo do &#8220;Nossos Peludos&#8221;. Como eu não tinha notebook, apenas o Daniel e o Ceolin começaram o desenvolvimento. Eis que o nosso mentor <a href="http://br.linkedin.com/in/wcampaj" target="_blank">Wilson Campanholi Jr</a>, me perguntou se um netbook com ubuntu me ajudaria&#8230; e me emprestou o dele. O cara mandou bem, meio que nos &#8220;adotou&#8221;. Nos deu várias dicas do Lean, nos incentivou a realizar pesquisa para validar a idéia e nos colocava nos trilhos, como disse o Fabiano. No geral, foi bem interessante trabalhar desse jeito, embora tenha sido cansativo. Mas é interessante ver o que pode ser feito em 2 dias, com uma equipe motivada e focada.</p>
<p>Nosso trabalho não ganhou a competição, mas a recompensa foi maior que isso. Levo comigo uma experiência de um evento fanstástico e ainda um networking, extremamente importante. Foi na minha opinião, o melhor evento que participei até hoje. Com certeza participarei de outros até ter minha startup e fazer uma coisa notável. Depois de ter a minha startup, quero estar do outro lado, ajudando e estimulando as pessoas a perseguirem seus sonhos.</p>

<a href='http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/np3/' title='np3'><img width="150" height="150" src="http://www.beneti.com.br/wp-content/uploads/2011/05/np3-150x150.jpg" class="attachment-thumbnail" alt="np3" title="np3" /></a>
<a href='http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/np2/' title='np2'><img width="150" height="150" src="http://www.beneti.com.br/wp-content/uploads/2011/05/np2-150x150.jpg" class="attachment-thumbnail" alt="np2" title="np2" /></a>
<a href='http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/np1/' title='np1'><img width="150" height="150" src="http://www.beneti.com.br/wp-content/uploads/2011/05/np1-150x150.jpg" class="attachment-thumbnail" alt="np1" title="np1" /></a>
<a href='http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/swc2011-1/' title='Equipe Nossos Peludos'><img width="150" height="150" src="http://www.beneti.com.br/wp-content/uploads/2011/05/swc2011-1-150x150.jpg" class="attachment-thumbnail" alt="Daniel, Euripedes, Marina, Wilson, Fabiano, Pedro, Ceolin e Eu" title="Equipe Nossos Peludos" /></a>
<a href='http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/swc2011-2/' title='swc2011-2'><img width="150" height="150" src="http://www.beneti.com.br/wp-content/uploads/2011/05/swc2011-2-150x150.jpg" class="attachment-thumbnail" alt="Daniel, Euripedes, Marina, Pedro, Ceolin, Eu e Fabiano" title="swc2011-2" /></a>
<a href='http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/swc2011-4/' title='swc2011-4'><img width="150" height="150" src="http://www.beneti.com.br/wp-content/uploads/2011/05/swc2011-4-150x150.jpg" class="attachment-thumbnail" alt="Ceolin, Daniel, Augusto, Mello, Eu e Alê" title="swc2011-4" /></a>

<p>Parabenizar os trutas <a href="http://twitter.com/#!/augustorsouza" target="_blank">Augusto Souza</a>, <a href="http://twitter.com/#!/guimello_silva" target="_blank">Guilherme Mello</a> e <a href="http://twitter.com/#!/alexandrearc" target="_blank">Alê</a> pelo segundo lugar com a aplicação <a href="http://www.paladarapp.com" target="_blank">PaladarApp</a>. Os cara mandaram bem, fizeram protótipo em Android e iPhone, show de bola.</p>
<p>Claro, parabenizar toda a equipe de organização que fez um trabalho fanstástico: <a href="http://twitter.com/andreLOParaense" target="_blank">André Paraense</a>, <a href="http://twitter.com/igorsantiagoIS" target="_blank">Igor Santiago</a>, <a href="http://twitter.com/bedy" target="_blank">Bedy</a> (&#8220;figurinha carimbada&#8221; em eventos de Startup/Empreendedorismo e gente boa), <a href="http://www.twitter.com/horaciopoblete" target="_blank">Horacio Poblete</a>, <a href="http://www.twitter.com/gentros" target="_blank">Taila Lemos</a>, <a href="http://www.twitter.com/agroinfoti" target="_blank">Marcelo Lima</a> e <a href="http://twitter.com/AnaCarolMerighe" target="_blank">Ana Carolina Merighe</a>&#8230; se faltou alguém, desculpe, é que não estava no site <img src='http://www.beneti.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="_mcePaste" class="mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">
<h1 id="firstHeading" class="firstHeading">Business Model Canvas</h1>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/05/16/startup-weekend-campinas-eufui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Vida em Porto Alegre</title>
		<link>http://www.beneti.com.br/2011/05/03/a-vida-em-porto-alegre/</link>
		<comments>http://www.beneti.com.br/2011/05/03/a-vida-em-porto-alegre/#comments</comments>
		<pubDate>Wed, 04 May 2011 03:02:31 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Escrevendo]]></category>
		<category><![CDATA[porto alegre]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=442</guid>
		<description><![CDATA[Bom, hoje não farei um post técnico. Apenas relatarei uma pequena jornada. No final do ano passado, eu recebi uma proposta para trabalhar em Porto Alegre e acabei aceitando, era o que eu estava procurando. Foi uma mudança, um tanto quanto radical, pois eu estava saindo do estado de São Paulo, indo para um lugar [...]]]></description>
			<content:encoded><![CDATA[<p><center><img class="aligncenter size-full wp-image-443" title="Redenção" src="http://www.beneti.com.br/wp-content/uploads/2011/05/redencao.jpg" alt="" width="440" height="329" /></center></p>
<p>Bom, hoje não farei um post técnico. Apenas relatarei uma pequena jornada. No final do ano passado, eu recebi uma proposta para trabalhar em Porto Alegre e acabei aceitando, era o que eu estava procurando. Foi uma mudança, um tanto quanto radical, pois eu estava saindo do estado de São Paulo, indo para um lugar que eu não conhecia absolutamente ninguém. Eu realmente teria que me virar&#8230; era um desafio e uma experiência que eu queria.</p>
<p>Arrumei minhas malas e fui. A empresa iria pagar 30 dias de hotel e eu teria esse tempo para encontrar um apartamento/kitnet para alugar. Confesso, que perguntar para um gaúcho se ele gosta de Porto Alegre, não é uma boa idéia. Ele fará 1001 propagandas da cidade&#8230; A primeira impressão que tive, foi a de Porto Alegre ser parecida com Campinas. Claro que estranhei o sotaque, no começo foi até chato, pois para algumas pessoas eu tinha que pedir para repetir o que tinham falado. Estranhei o clima também. Fiquei 6 meses em Porto Alegre, só peguei calor, mas MUITO calor. Lá dizem &#8220;Forno Alegre&#8221;, os paulistas quase não fazem piada com isso&#8230;</p>
<p>Tive muitos problemas para alugar um imóvel lá. Extremamente burocrático, muito mais do que em Campinas. Para começar, eu tinha que apresentar um fiador com dois imóveis (é difícil ter um, imagina dois) ou dois com um imóvel. As outras opções eram: fazer um titulo de capitalização de 18 alugueis ( no caso, seria pouco mais de R$ 14 mil reais) ou um seguro (leia-se, jogar dinheiro fora) de um aluguel e meio. Meio alucinados. Claramente, optei pelo seguro. Mas eles não estão nem aí&#8230; As imobiliárias de lá são terríveis.</p>
<p>O gaúcho é extremamente fanático por futebol. Eu trabalhava na rua do Beira-Rio. Em dia de jogo, era uma invasão de pessoas: homem, mulher, senhor, senhora, criança&#8230; independente de idade ou sexo, indo para o estádio. O bom de Porto Alegre é que não tem corinthiano, mas os colorados compensam isso. Tudo o Inter é melhor (na cabeça deles)&#8230; Incrível. O dia do mundial interclubes foi bem engraçado ver os gremistas secando.</p>
<p>Conheci poucos pontos turísticos&#8230; eu estava sozinho lá, não tinha muita vontade de ficar indo. Conheci a famosa &#8216;Redenção&#8217;. É um parque gigante, onde o pessoal vai no final da tarde ou no final de semana para correr e tomar chimarrão. Até agora não entendo como conseguem tomar aquela bebida quente naquele calor. Mas foi o que me disseram, &#8220;é coisa de gaúcho. Só sendo gaúcho para entender.&#8221;.</p>
<p>A comida lá, se você não quiser sofisticar muito, é bem barato. Eu almoçava (comendo a vontade) com no máximo R$ 11,90. Não é comum ter comida por quilo. Existe, mas se você passa do valor do livre, eles te cobram o livre. Não entendeu? Simples&#8230; O kg é R$ 34,00. O livre é R$ 12,00. Se você pegar 500 gr, seriam R$ 17,00, mas não, você paga R$ 12,00 e come a vontade. Isso era bom. Ainda com relação a comida, lá eles chama qualquer lanche de xis. Eles não dizem, vamos  comer lanche, mas sim um xis. Existe um X-Coração, que é feito com coração de galinha&#8230; que deixou saudades. Caso você visite Porto Alegre, vá à uma lanchonete na Av Princesa Isabel, com a São Luis, não me recordo o nome e peça um X-Coração. É barato e MUITO bom. Saí muito pouco lá, mas conheci um barzinho chamado &#8220;Dublin&#8221; e outro &#8220;Dona Neusa&#8221;. Cada um com seu estilo, mas ambos agradáveis.</p>
<p>Foi uma experiência de vida, bem bacana. Acabei voltando para Campinas em fevereiro por alguns motivos que não vêm ao caso, agora. Conheci pessoas muito bacanas lá, que me ajudaram bastante. Quem ver o meu facebook, eu tirei uma foto na &#8216;Redenção&#8217; e fiz uma homenagem com todas as pessoas que me ajudaram lá. Se colocar numa balança, foi uma ótima experiência, mas não encaro uma dessas denovo tão cedo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/05/03/a-vida-em-porto-alegre/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[RAILS] &#8211; REST Actions</title>
		<link>http://www.beneti.com.br/2011/01/29/rails-rest-actions/</link>
		<comments>http://www.beneti.com.br/2011/01/29/rails-rest-actions/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 00:15:54 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=433</guid>
		<description><![CDATA[Faz um tempinho que não posto nada&#8230; Hoje vou falar um pouco sobre REST e Rails. As vezes é necessário crias novas actions no rails que é feito com REST. Se você criar um controller qualquer, vamos chamar aqui de empresas e adicionar no arquivo routes.rb (o rails já faz isso) a seguinte linha: resources [...]]]></description>
			<content:encoded><![CDATA[<p>Faz um tempinho que não posto nada&#8230; Hoje vou falar um pouco sobre REST e Rails. As vezes é necessário crias novas actions no rails que é feito com REST. Se você criar um controller qualquer, vamos chamar aqui de empresas e adicionar no arquivo routes.rb (o rails já faz isso) a seguinte linha:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">resources <span style="color:#ff3333; font-weight:bold;">:empresas</span></pre></div></div>

<p>o rails limita o seu controller em 7 actions, sendo:</p>
<p>- index<br />
- show<br />
- new<br />
- edit<br />
- update<br />
- create<br />
- destroy</p>
<p>na maioria dos casos resolve, mas as vezes é necessário criar novas actions. Vamos supor que você queria adicionar uma action que busque empresas de TI (claro, supondo que exista um indicador para isso). Primeiro defina a action no controller, por exemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> itcompany
  <span style="color:#0066ff; font-weight:bold;">@empresas</span> = Empresa.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;indicadorti = ?&quot;</span>, <span style="color:#996600;">'S'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Para funcionar, você tem que &#8220;dizer&#8221; ao rails que existe essa nova action e qual o tipo de requisição. Para isso no arquivo routes.rb, faça:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">resources <span style="color:#ff3333; font-weight:bold;">:empresa</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  collection <span style="color:#9966CC; font-weight:bold;">do</span>
    get <span style="color:#ff3333; font-weight:bold;">:itcompany</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Com isso, o rails passa a reconhecer o caminho: empresas/itcompany</p>
<p>Agora, para terminar, vamos supor que você queira atualizar esse atributo de indicadorti. Novamente, crie a action, por exemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> setitcompany
  <span style="color:#0066ff; font-weight:bold;">@empresa</span> = Empresa.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0066ff; font-weight:bold;">@empresa</span>.<span style="color:#9900CC;">update_attribute</span> <span style="color:#ff3333; font-weight:bold;">:indicadorit</span>, <span style="color:#996600;">'S'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Agora no routes.rb, é necessário configurar essa nova action:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">resources <span style="color:#ff3333; font-weight:bold;">:empresa</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  collection <span style="color:#9966CC; font-weight:bold;">do</span>
    get <span style="color:#ff3333; font-weight:bold;">:itcompany</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  member <span style="color:#9966CC; font-weight:bold;">do</span>
    put <span style="color:#ff3333; font-weight:bold;">:setitcompany</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Com o member, o rails passa a reconhecer o caminho empresa/:id/setitcompany</p>
<p>Entenda a diferença entre o member e o collaction, com isso seus controllers serão sempre magros. É isso e até a próxima.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2011/01/29/rails-rest-actions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Android] &#8211; Parse XML</title>
		<link>http://www.beneti.com.br/2010/10/16/android-parse-xml/</link>
		<comments>http://www.beneti.com.br/2010/10/16/android-parse-xml/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 00:20:30 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=413</guid>
		<description><![CDATA[Aviso aos navegantes: Essa postagem é longa e com muito código. No entanto, tento explicar da melhora maneira possível para você não perder tempo como eu perdi. Divirta-se! Hoje em dia é muito comum termos arquivos XML e podemos ter uma aplicação que para atualizar seus dados, busque-os em arquivos XML. Para realizar o parse [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-408" title="bg_logo" src="http://www.beneti.com.br/wp-content/uploads/2010/10/bg_logo.png" alt="" width="180" height="50" /></p>
<p>Aviso aos navegantes: Essa postagem é longa e com muito código. No entanto, tento explicar da melhora maneira possível para você não perder tempo como eu perdi. Divirta-se! Hoje em dia é muito comum termos arquivos XML e podemos ter uma aplicação que para atualizar seus dados, busque-os em arquivos XML. Para realizar o parse utilizei a <a href="http://www.saxproject.org/" target="_blank">SAX-Parse</a>, <strong>S</strong>imple <strong>A</strong>PI for <strong>X</strong>ML. </p>
<p>Vamos supor que o arquivo conterá informações sobre a rodada X do Brasileirão (é uma rodada atrasada e só terá 3 jogos). Vamos supor também que as informações desse arquivos são: dia do jogo, horário, local, mandante e visitante. Segue o arquivo utilizado como exemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jogos<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jogo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dia<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>20/10/10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dia<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;horario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>21:50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/horario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Morumbi<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/local<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mandante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>São Paulo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mandante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visitante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Palmeiras<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/visitante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jogo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jogo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dia<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>20/10/10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dia<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;horario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>21:50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/horario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Vila Belmiro<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/local<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mandante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Santos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mandante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visitante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Corinthians<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/visitante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jogo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jogo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dia<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>21/10/10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dia<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;horario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>19:30<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/horario<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Santa Cruz<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/local<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mandante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Botafogo-SP<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mandante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visitante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Comercial<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/visitante<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jogo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jogos<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Primeiro vamos fazer uma classe para os guardar as informações, Jogo.java.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Jogo <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> dia, horario, local, mandante, visitante<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDia<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pDia<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dia</span> <span style="color: #339933;">=</span> pDia<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHorario<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pHorario<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">horario</span> <span style="color: #339933;">=</span> pHorario<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLocal<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pLocal<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">local</span> <span style="color: #339933;">=</span> pLocal<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMandante<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pMandante<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mandante</span> <span style="color: #339933;">=</span> pMandante<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setVisitante<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pVisitante<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">visitante</span> <span style="color: #339933;">=</span> pVisitante<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getDia<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dia</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getHorario<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">horario</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLocal<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">local</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMandante<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mandante</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getVisitante<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">visitante</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Jogo: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mandante</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; x &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">visitante</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Local: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">local</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Data: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dia</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; as &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">horario</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Agora, precisamos criar uma classe que estenda de org.xml.sax.helpers.DefaultHandler. Alguns métodos precisam ser implementados, mas são simples. Neste caso, comentarei no código. Afinal código bom é código comentado <img src='http://www.beneti.com.br/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Eu chamei de JogosHandler.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JogosHandler <span style="color: #000000; font-weight: bold;">extends</span> DefaultHandler<span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//enum para as TAGS do arquivo, eh necessario colocar todos</span>
   <span style="color: #666666; font-style: italic;">//senao vai lancar erro</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">enum</span> TAGS <span style="color: #009900;">&#123;</span> jogos, jogo, dia, horario, local, mandante, visitante <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//Buffer para armazenar o valor entre a &lt;tag&gt;&lt;/tag&gt;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">StringBuffer</span> tempString<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//Necessario para armazenar os 3 jogos</span>
   <span style="color: #000000; font-weight: bold;">private</span> Jogo tempJogo<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> Vector<span style="color: #339933;">&lt;</span>Jogo<span style="color: #339933;">&gt;</span> jogos<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//Necessario para saber exatamente qual é a tag que esta sendo lida</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isJogo, isDia, isHorario, isLocal, isMandante, isVisitante<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> ResumoHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">jogos</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Vector<span style="color: #339933;">&lt;</span>Jogo<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tempString</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Vector<span style="color: #339933;">&lt;</span>Jogo<span style="color: #339933;">&gt;</span> getParsedJogos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> jogos<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override    
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> startDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> endDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Este metodo eh sempre chamado e no primeiro parametro vem o valor </span>
    <span style="color: #666666; font-style: italic;">//do que esta entre tag. exemplo &lt;local&gt;Morumbi&lt;/local&gt;, o valor de ch eh Morumbi</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> characters<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span> ch<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>, <span style="color: #000066; font-weight: bold;">int</span> start, <span style="color: #000066; font-weight: bold;">int</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//so para mostrar que conseguimos saber exatamente com eh a tag que esta sendo lida</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isDia <span style="color: #339933;">||</span> isHorario <span style="color: #339933;">||</span> isLocal <span style="color: #339933;">||</span> isMandante <span style="color: #339933;">||</span> isVisitante<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        	tempString.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>ch,start,length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>	
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Este metodo sempre eh chamado na abertura de uma tag, TODAS.</span>
    <span style="color: #666666; font-style: italic;">//seja &lt;jogos&gt;&lt;jogo&gt;&lt;dia&gt;...</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> startElement<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> n, <span style="color: #003399;">String</span> l, <span style="color: #003399;">String</span> q, <span style="color: #003399;">Attributes</span> a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//sabemos que a cada tag &lt;jogo&gt; temos um novo jogo. </span>
        <span style="color: #666666; font-style: italic;">//ja as demais tags, so marcaremos qual eh a tag e limpamos o buffer</span>
	<span style="color: #666666; font-style: italic;">//o segundo parametro l, estara a tag sem &lt;&gt;: jogos, jogo, dia...</span>
        <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>TAGS.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">case</span> jogo<span style="color: #339933;">:</span> tempJogo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Jogo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> dia<span style="color: #339933;">:</span> isDia <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> tempString.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> horario<span style="color: #339933;">:</span> isHorario <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> tempString.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> local<span style="color: #339933;">:</span> isLocal <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> tempString.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> mandante<span style="color: #339933;">:</span> isMandante <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> tempString.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> visitante<span style="color: #339933;">:</span> isVisitante <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> tempString.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span> tempString.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>	     
&nbsp;
    <span style="color: #666666; font-style: italic;">//Este metodo sempre eh chamado no fechamento de uma tag, TODAS.</span>
    <span style="color: #666666; font-style: italic;">//seja &lt;/jogos&gt;&lt;/jogo&gt;&lt;/dia&gt;...	</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> endElement<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> n, <span style="color: #003399;">String</span> l, <span style="color: #003399;">String</span> q<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//sabemos que a cada tag &lt;/jogo&gt; ja lemos todas as informacoes, sendo assim, adicionamos no vector. </span>
        <span style="color: #666666; font-style: italic;">//ja as demais tags, so desmarcaremos qual eh a tag e setamos o atributo com o valor do buffer</span>
	<span style="color: #666666; font-style: italic;">//o segundo parametro l, estara a tag sem &lt;/&gt;: jogos, jogo, dia...</span>
        <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>TAGS.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">case</span> dia<span style="color: #339933;">:</span> isDia <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> tempJogo.<span style="color: #006633;">setDia</span><span style="color: #009900;">&#40;</span>tempString.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> horario<span style="color: #339933;">:</span> isHorario <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> tempJogo.<span style="color: #006633;">setHorario</span><span style="color: #009900;">&#40;</span>tempString.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> local<span style="color: #339933;">:</span> isLocal <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> tempJogo.<span style="color: #006633;">setLocal</span><span style="color: #009900;">&#40;</span>tempString.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> mandante<span style="color: #339933;">:</span> isMandante <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> tempJogo.<span style="color: #006633;">setMandante</span><span style="color: #009900;">&#40;</span>tempString.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> visitante<span style="color: #339933;">:</span> isVisitante <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> tempJogo.<span style="color: #006633;">setVisitante</span><span style="color: #009900;">&#40;</span>tempString.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> jogo<span style="color: #339933;">:</span> jogos.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tempJogo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Até agora são classes, nada de android. Agora a classe da activity.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ParsingXML <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>	
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle icicle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>icicle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//so um lugar para o resultado</span>
        TextView tv <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextView<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//endereco do XML</span>
            <span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://some_adress/example.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//SAXParser</span>
            SAXParserFactory spf <span style="color: #339933;">=</span> SAXParserFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            SAXParser sp <span style="color: #339933;">=</span> spf.<span style="color: #006633;">newSAXParser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//XMLReader</span>
            XMLReader xr <span style="color: #339933;">=</span> sp.<span style="color: #006633;">getXMLReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//Novo Handler, de acordo com o criado, no caso JogosHandler</span>
            JogosHandler andJogosHandler <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JogosHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            xr.<span style="color: #006633;">setContentHandler</span><span style="color: #009900;">&#40;</span>andJogosHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//Realizando o parse de acordo com a URL</span>
            xr.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InputSource<span style="color: #009900;">&#40;</span>url.<span style="color: #006633;">openStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    Vector<span style="color: #339933;">&lt;</span>Jogo<span style="color: #339933;">&gt;</span> conteudoXML <span style="color: #339933;">=</span> andJogosHandler.<span style="color: #006633;">getParsedJogos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003399;">String</span> text <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #666666; font-style: italic;">//loop para percorrer todas as posicoes</span>
            <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> conteudoXML.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>            
                text <span style="color: #339933;">+=</span> conteudoXML.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>                
&nbsp;
            <span style="color: #666666; font-style: italic;">//so exibir na tela</span>
            tv.<span style="color: #006633;">setContentView</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            tv.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bom, espero que o Parse XML não seja mais tão doloroso <img src='http://www.beneti.com.br/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2010/10/16/android-parse-xml/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>[Android] &#8211; Services</title>
		<link>http://www.beneti.com.br/2010/10/09/android-services/</link>
		<comments>http://www.beneti.com.br/2010/10/09/android-services/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 20:14:51 +0000</pubDate>
		<dc:creator>Beneti</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[manifest]]></category>
		<category><![CDATA[service]]></category>

		<guid isPermaLink="false">http://www.beneti.com.br/?p=407</guid>
		<description><![CDATA[Recentemente, estava desenvolvendo uma app quando o requisito dizia que era necessário criar um serviço. O meu post é baseado neste post do site s s chauhan e neste post do bright hub. Ambos os post e eu também, presumimos que o setup do ambiente e como criar um projeto já esteja feito. Qual a [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-408" title="bg_logo" src="http://www.beneti.com.br/wp-content/uploads/2010/10/bg_logo.png" alt="" width="180" height="50" /></p>
<p>Recentemente, estava desenvolvendo uma app quando o requisito dizia que era necessário criar um serviço. O meu post é baseado <a href="http://www.sschauhan.com/index.php?option=com_content&amp;view=article&amp;id=21:creating-service&amp;catid=6:android-category&amp;Itemid=3" target="_blank">neste post</a> do site s s chauhan e <a href="http://www.brighthub.com/mobile/google-android/articles/34861.aspx" target="_blank">neste post</a> do bright hub. Ambos os post e eu também, presumimos que o setup do ambiente e como criar um projeto já esteja feito. Qual a motivação de criar um service? A sua aplicação pode precisar executar um rotina em background e o service resolve isso.</p>
<p>O primeiro passo é adicionar o service no AndroiManifest.xml, lembre-se que qualquer Activity, Service ou Content Provider tem que estar referenciadas no manifest. A edição é simples. Abra o AndroidManifest.xml, vá na aba Application. Em Application Nodes, clique em Add, escolha service e dê OK. Em name, coloque .ServiceName ou .subpackage.ServiceName. Note que ServiceName é o nome da classe, consequentemente o nome do service. Neste exemplo será BenetiService, então eu colocaria .BenetiService. Clique na aba AndroidManifest.xml para ver o conteúdo, deve existir a seguinte linha:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;.subpackagename.ServiceName&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Neste exemplo, um botão dispara o serviço e o outro cancela. O primeiro abaixo é só para montar a tela com os dois botões e seus listeners.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BenetiHello <span style="color: #000000; font-weight: bold;">extends</span> Activity
<span style="color: #009900;">&#123;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>       
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                     
&nbsp;
        <span style="color: #666666; font-style: italic;">//criando intent</span>
        <span style="color: #000000; font-weight: bold;">final</span> Intent BenetiService <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, BenetiService.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//botao iniciar</span>
        <span style="color: #003399;">Button</span> btnStart <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">btn_start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//listener</span>
        btnStart.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> view<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>    
                <span style="color: #666666; font-style: italic;">//start the service</span>
                startService<span style="color: #009900;">&#40;</span>BenetiService<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//botao parar</span>
        <span style="color: #003399;">Button</span> btnStop <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">btn_stop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//listener</span>
        btnStop.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> view<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>            
                <span style="color: #666666; font-style: italic;">//stop the service</span>
                stopService<span style="color: #009900;">&#40;</span>BenetiService<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>  
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Até aqui, sem dúvidas, certo?  Agora o código do service</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BenetiService <span style="color: #000000; font-weight: bold;">extends</span> Service
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Timer</span> timer<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Timer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">long</span> UPDATE_INTERVAL <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//1 minuto</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">long</span> DELAY_INTERVAL <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> 
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
      startService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
     <span style="color: #000000; font-weight: bold;">public</span> IBinder onBind<span style="color: #009900;">&#40;</span>Intent intent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onDestroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onDestroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      stopService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> startService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>     
      timer.<span style="color: #006633;">scheduleAtFixedRate</span><span style="color: #009900;">&#40;</span>            
              <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">TimerTask</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        doServiceWork<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                  <span style="color: #009900;">&#125;</span>,
                  DELAY_INTERVAL,
                  UPDATE_INTERVAL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> doServiceWork<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//faca algo</span>
       Log.<span style="color: #006633;">i</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;doServiceWork&quot;</span>,<span style="color: #0000ff;">&quot;Executando o servico.&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> stopService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      timer.<span style="color: #006633;">cancel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>É muito importante sobrescrever o método onDestroy para que a tarefa seja cancelada. Durante o meu desenvolvimento, eu não fiz isso. E cada vez que eu clicava no botão, criava um nova nova tarefa, consequentemente comia a bateria. Detalhe que o valor do UPDATE_INTERVAL é sempre em milisegundos, não esquecer de converter, para isso x (número de minutos desejado) * 60 * 1000. Espero que a dica tenha sido boa e que não percam tempo como eu perdi por causa da falta do timer.cancel().</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneti.com.br/2010/10/09/android-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

