<?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>ERiDeM.net &#187; Android Tips</title>
	<atom:link href="http://www.eridem.net/category/blog/androidtips/feed" rel="self" type="application/rss+xml" />
	<link>http://www.eridem.net</link>
	<description>Miguel Ángel Domínguez Coloma&#039;s personal page</description>
	<lastBuildDate>Thu, 10 Jan 2013 13:47:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>Android tip #028 &#8211; Sync two ScrollLayouts when scroll</title>
		<link>http://www.eridem.net/android-tip-028-sync-two-scrolllayouts-when-scroll</link>
		<comments>http://www.eridem.net/android-tip-028-sync-two-scrolllayouts-when-scroll#comments</comments>
		<pubDate>Sat, 04 Jun 2011 10:45:36 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1464</guid>
		<description><![CDATA[Platform/Language: Java/XML/Android Description: if we need to scroll two ScrollLayouts at the same time we can create a new View that implements the standard ScrollView in order to create a listener which allow us to know when this one is scrolling and modify the behavior of the other (or maybe because we want to know about the scroll behavior). Code: IScrollListener.java 1234567public interface IScrollListener &#123; &#160; void onScrollChanged&#40; &#160; &#160; IScrollListener scrollView, &#160; &#160; int x, int y, int oldx, int oldy&#41;; &#125; ObservableScrollView.java 12345678910111213141516171819202122232425262728293031public class ObservableScrollView extends ScrollView &#123; &#160; private IScrollListener listener = null; &#160; public ObservableScrollView&#40;Context context&#41; &#123; &#160; &#160; &#160; super&#40;context&#41;; &#160; &#125; &#160; public ObservableScrollView&#40;Context context, &#160; &#160; &#160; &#160; &#160; &#160;AttributeSet attrs, int defStyle&#41; &#123; &#160; &#160; &#160; super&#40;context, attrs, defStyle&#41;; &#160; &#125; &#160; public ObservableScrollView&#40;Context context, &#160; &#160; &#160; &#160; &#160; &#160;AttributeSet attrs&#41; &#123; &#160; &#160; &#160; super&#40;context, attrs&#41;; &#160; &#125; &#160; public void setScrollViewListener&#40;IScrollListener listener&#41; &#123; &#160; &#160; &#160; this.listener = listener; &#160; &#125; &#160; @Override &#160; protected void onScrollChanged&#40;int x, int y, &#160; &#160; &#160; &#160; &#160; &#160;int oldx, int oldy&#41; &#123; &#160; &#160; &#160; super.onScrollChanged&#40;x, y, oldx, oldy&#41;; &#160; &#160; &#160; if &#40;listener != null&#41; &#123; &#160; &#160; &#160; &#160; [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: Java/XML/Android</p>
<p><strong>Description</strong>: if we need to scroll two ScrollLayouts at the same time we can create a new View that implements the standard ScrollView in order to create a listener which allow us to know when this one is scrolling and modify the behavior of the other (or maybe because we want to know about the scroll behavior).</p>
<p><strong>Code</strong>:</p>
<p align="center"><i>IScrollListener.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IScrollListener <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000066; font-weight: bold;">void</span> onScrollChanged<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; IScrollListener scrollView, <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y, <span style="color: #000066; font-weight: bold;">int</span> oldx, <span style="color: #000066; font-weight: bold;">int</span> oldy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</p>
<p align="center"><i>ObservableScrollView.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ObservableScrollView <span style="color: #000000; font-weight: bold;">extends</span> ScrollView <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> IScrollListener listener <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> ObservableScrollView<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span> context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> ObservableScrollView<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span> context, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003399;">AttributeSet</span> attrs, <span style="color: #000066; font-weight: bold;">int</span> defStyle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>context, attrs, defStyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> ObservableScrollView<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span> context,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003399;">AttributeSet</span> attrs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>context, attrs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setScrollViewListener<span style="color: #009900;">&#40;</span>IScrollListener listener<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">listener</span> <span style="color: #339933;">=</span> listener<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onScrollChanged<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">int</span> oldx, <span style="color: #000066; font-weight: bold;">int</span> oldy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onScrollChanged</span><span style="color: #009900;">&#40;</span>x, y, oldx, oldy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>listener <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listener.<span style="color: #006633;">onScrollChanged</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, x, y, oldx, oldy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</p>
<p>Use two <i>ObservableScrollView</i> in your layout: oScrollViewOne, oScrollViewTwo.</p>
<p align="center"><i>YoutActivity.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> YourActivity <span style="color: #000000; font-weight: bold;">extends</span> Activity <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">implements</span> ScrollViewListener <span style="color: #009900;">&#123;</span><br />
&nbsp; ObservableScrollView oScrollViewOne, oScrollViewTwo<span style="color: #339933;">;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <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><br />
&nbsp; &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><br />
&nbsp; &nbsp; 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><br />
<br />
&nbsp; &nbsp; oScrollViewOne <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ObservableScrollView<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">oScrollViewOne</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; oScrollViewTwo <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ObservableScrollView<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">oScrollViewTwo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; oScrollViewOne.<span style="color: #006633;">setScrollViewListener</span><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><br />
&nbsp; &nbsp; oScrollViewTwo.<span style="color: #006633;">setScrollViewListener</span><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><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000066; font-weight: bold;">void</span> onScrollChanged<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; IScrollListener scrollView, <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y, <span style="color: #000066; font-weight: bold;">int</span> oldx, <span style="color: #000066; font-weight: bold;">int</span> oldy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>scrollView <span style="color: #339933;">==</span> oScrollViewOne<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; oScrollViewTwo.<span style="color: #006633;">scrollTo</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>scrollView <span style="color: #339933;">==</span> oScrollViewTwo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; oScrollViewOne.<span style="color: #006633;">scrollTo</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-028-sync-two-scrolllayouts-when-scroll/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android tip #027 &#8211; Add shadow to labels, buttons and other views</title>
		<link>http://www.eridem.net/android-tip-027-add-shadow-to-lables-buttons-and-other-view</link>
		<comments>http://www.eridem.net/android-tip-027-add-shadow-to-lables-buttons-and-other-view#comments</comments>
		<pubDate>Fri, 03 Jun 2011 19:02:06 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1456</guid>
		<description><![CDATA[Platform/Language: Java/XML/Android Description: We can drop shadows to our controls (TextView, Buttons, Checkbox, &#8230;). Adding this shadow, we can create a better interface in our applications (but be careful adding shadow to everything!). Result Code: my_layout.xml 1234567891011121314&#60;!-- ... --&#62; &#60;TextView &#160; android:layout_width=&#34;wrap_content&#34; &#160; android:layout_height=&#34;wrap_content&#34; &#160; &#160; android:textColor=&#34;@android:color/black&#34; &#160; android:text=&#34;@string/eridemNet&#34; &#160; &#160; android:shadowRadius=&#34;3&#34; &#160; android:shadowDx=&#34;3&#34; &#160; android:shadowDy=&#34;2&#34; &#160; android:shadowColor=&#34;@android:color/black&#34; &#62;&#60;/TextView&#62; &#60;!-- ... --&#62;]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: Java/XML/Android</p>
<p><strong>Description</strong>: We can drop shadows to our controls (TextView, Buttons, Checkbox, &#8230;). Adding this shadow, we can create a better interface in our applications (but be careful adding shadow to everything!).</p>
<p><strong>Result</strong></p>
<p align="center"><img src="http://www.eridem.net/blog/wp-content/uploads/shadow_text.png" alt="" title="shadow_text" width="470" height="65" class="aligncenter size-full wp-image-1457" /></p>
<p><strong>Code</strong>:</p>
<p align="center"><i>my_layout.xml</i></p>
<div class="codecolorer-container xml default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span><br />
<span style="color: #009900;">&nbsp; </span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:textColor</span>=<span style="color: #ff0000;">&quot;@android:color/black&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/eridemNet&quot;</span></span><br />
<span style="color: #009900;">&nbsp; </span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowRadius</span>=<span style="color: #ff0000;">&quot;3&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowDx</span>=<span style="color: #ff0000;">&quot;3&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowDy</span>=<span style="color: #ff0000;">&quot;2&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowColor</span>=<span style="color: #ff0000;">&quot;@android:color/black&quot;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/TextView<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-027-add-shadow-to-lables-buttons-and-other-view/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Android tip #026 &#8211; Create nice buttons with XML</title>
		<link>http://www.eridem.net/android-tip-026-create-nice-buttons-with-xml</link>
		<comments>http://www.eridem.net/android-tip-026-create-nice-buttons-with-xml#comments</comments>
		<pubDate>Fri, 03 Jun 2011 18:46:21 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1448</guid>
		<description><![CDATA[Platform/Language: XML/Android Description: We can create nice buttons simply using few colors and gradients. We need to create a Selector resource and attach all the shape items for every state: pressed, focussed, disabled and normal. In the most common cases, focussed and normal could show the same result. In the case of pressed and normal, we will invert the colors. And in the case of disabled, we will use other colors (like a gray color). Result Code: colors.xml in /values/ 12345678&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;resources&#62; &#160; &#160; &#60;color name=&#34;NiceButtonStartColor&#34;&#62;#4AA02C&#60;/color&#62; &#160; &#160; &#60;color name=&#34;NiceButtonEndColor&#34;&#62;#348017&#60;/color&#62; &#160; &#160; &#60;color name=&#34;NiceButtonDisabledStartColor&#34;&#62;#565051&#60;/color&#62; &#160; &#160; &#60;color name=&#34;NiceButtonDisabledEndColor&#34;&#62;#736F6E&#60;/color&#62; &#160; &#160; &#60;color name=&#34;NiceButtonBorderColor&#34;&#62;#254117&#60;/color&#62; &#60;/resources&#62; nice_button.xml in /drawables/ 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;selector &#160; &#160;xmlns:android=&#34;http://schemas.android.com/apk/res/android&#34;&#62; &#160; &#160; &#60;item android:state_pressed=&#34;true&#34; &#62; &#160; &#160; &#160; &#160; &#60;shape&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;gradient &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;android:endColor=&#34;@color/NiceButtonStartColor&#34; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;android:startColor=&#34;@color/NiceButtonEndColor&#34; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;android:angle=&#34;270&#34; /&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;stroke &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;android:width=&#34;1dp&#34; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;android:color=&#34;@color/NiceButtonBorderColor&#34; /&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;corners &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;android:radius=&#34;3dp&#34; /&#62; &#160; &#160; &#160; &#160; [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: XML/Android</p>
<p><strong>Description</strong>: We can create nice buttons simply using few colors and gradients. We need to create a Selector resource and attach all the shape items for every state: pressed, focussed, disabled and normal. In the most common cases, focussed and normal could show the same result. In the case of pressed and normal, we will invert the colors. And in the case of disabled, we will use other colors (like a gray color).</p>
<p><strong>Result</strong></p>
<p align="center"><img src="http://www.eridem.net/blog/wp-content/uploads/custom_button.png" alt="Custom nice button" title="Custom nice button" width="472" height="67" class="alignnone size-full wp-image-1450" /></p>
<p><strong>Code</strong>:</p>
<p align="center"><i>colors.xml</i> in /values/</p>
<div class="codecolorer-container xml default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;color</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NiceButtonStartColor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#4AA02C<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/color<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;color</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NiceButtonEndColor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#348017<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/color<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;color</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NiceButtonDisabledStartColor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#565051<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/color<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;color</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NiceButtonDisabledEndColor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#736F6E<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/color<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;color</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NiceButtonBorderColor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#254117<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/color<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
</p>
<p align="center"><i>nice_button.xml</i> in /drawables/</p>
<div class="codecolorer-container xml default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;selector</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:state_pressed</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonStartColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonEndColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stroke</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:width</span>=<span style="color: #ff0000;">&quot;1dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:color</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonBorderColor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;3dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;padding</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:left</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:top</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:right</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:bottom</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:state_focused</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonStartColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonEndColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stroke</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:width</span>=<span style="color: #ff0000;">&quot;1dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:color</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonBorderColor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;3dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;padding</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:left</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:top</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:right</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:bottom</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">android:state_enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonDisabledStartColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonDisabledEndColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stroke</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:width</span>=<span style="color: #ff0000;">&quot;1dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:color</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonBorderColor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;3dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;padding</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:left</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:top</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:right</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:bottom</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradient</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:startColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonStartColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:endColor</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonEndColor&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:angle</span>=<span style="color: #ff0000;">&quot;270&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stroke</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:width</span>=<span style="color: #ff0000;">&quot;1dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:color</span>=<span style="color: #ff0000;">&quot;@color/NiceButtonBorderColor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;corners</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:radius</span>=<span style="color: #ff0000;">&quot;3dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;padding</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:left</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:top</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:right</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">android:bottom</span>=<span style="color: #ff0000;">&quot;10dp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/selector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
</p>
<p align="center"><i>my_layout.xml</i></p>
<div class="codecolorer-container xml default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span><br />
<span style="color: #808080; font-style: italic;">&lt;!-- Better if you use most of the attributes in a style --&gt;</span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> </span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/btnStart&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span>&nbsp; </span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;40dp&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:layout_margin</span>=<span style="color: #ff0000;">&quot;3dp&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:gravity</span>=<span style="color: #ff0000;">&quot;center&quot;</span></span><br />
<br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:background</span>=<span style="color: #ff0000;">&quot;@drawable/nice_button&quot;</span></span><br />
<br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/labelStart&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:textColor</span>=<span style="color: #ff0000;">&quot;@android:color/white&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:textSize</span>=<span style="color: #ff0000;">&quot;18sp&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowRadius</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowDx</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowDy</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">android:shadowColor</span>=<span style="color: #ff0000;">&quot;@android:color/black&quot;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/Button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-026-create-nice-buttons-with-xml/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cleaning unused Android resources</title>
		<link>http://www.eridem.net/cleaning-unused-android-resources</link>
		<comments>http://www.eridem.net/cleaning-unused-android-resources#comments</comments>
		<pubDate>Sun, 24 Apr 2011 10:58:49 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1405</guid>
		<description><![CDATA[On middle/big projects we usually add lots of resources that we can use on code files, layouts or other resources. When we start to do modifications to the project, sometimes we forgot to remove unused strings, drawables, layouts and so on. I wanted to create a script to check these unused resources on our Android project, but I found a project which already does this task. This project is called android-unused-resources (good name to google it), and we can download it from: http://code.google.com/p/android-unused-resources/ The use is simple, add the file to the root project and execute it: java -jar AndroidUnusedResources.jar]]></description>
				<content:encoded><![CDATA[<p>On middle/big projects we usually add lots of resources that we can use on code files, layouts or other resources. When we start to do modifications to the project, sometimes we forgot to remove unused strings, drawables, layouts and so on.
<p>I wanted to create a script to check these unused resources on our Android project, but I found a project which already does this task. This project is called <em>android-unused-resources</em> (good name to google it), and we can download it from:
<p align="center"><a href="http://code.google.com/p/android-unused-resources/">http://code.google.com/p/android-unused-resources/</a></p>
<p>The use is simple, add the file to the root project and execute it:</p>
<div class="codecolorer-container bash default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">java <span style="color: #660033;">-jar</span> AndroidUnusedResources.jar</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/cleaning-unused-android-resources/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Check missing strings for a multi-language Android application</title>
		<link>http://www.eridem.net/check-missing-strings-for-a-multi-language-android-app</link>
		<comments>http://www.eridem.net/check-missing-strings-for-a-multi-language-android-app#comments</comments>
		<pubDate>Wed, 20 Apr 2011 07:08:22 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1395</guid>
		<description><![CDATA[When we are creating a multi-language application for Android, we need to create several folders to save the strings of different languages (see Android tip #014 &#8211; Multi-language application). When we are handling hundred or thousand of strings, we can forget adding a string in all language files. Looking for a tool to organize all the strings in my project and check if any string was missing, I found the W.F.M.H&#8217;s blog were you can download a PHP script to help you for checking all your strings. The usage is easy (using ES language as example) ./string-check.php values/strings.xml values-es/strings.xml You could get a result similar to: Missing in &#60;LANG&#62; &#40;You need to add these to your file&#41; File: values-es/strings.xml ------------------------------------------------------ header_title description_label Missing in EN &#40;you probably shall remove it from your &#60;LANG&#62; file&#41; File: values/strings.xml ------------------------------------------------------------------ mysection_label Summary ---------------- BASE file: 'values/strings.xml' LANG file: 'values-de/strings.xml' &#160; &#160;2 missing strings in your LANG file. &#160; &#160;1 obsolete strings in your LANG file. For more information about the project, visit the main website (recommended): W.F.M.H.&#8217;s blog, Android translators&#8217; helper tool Or download the script directly from his/her website: strings-check.zip]]></description>
				<content:encoded><![CDATA[<p>When we are creating a multi-language application for Android, we need to create several folders to save the strings of different languages (see <em><a href="http://www.eridem.net/android-tip-014-multi-language-application">Android tip #014 &#8211; Multi-language application</a></em>). When we are handling hundred or thousand of strings, we can <em>forget</em> adding a string in all language files.</p>
<p>Looking for a tool to organize all the strings in my project and check if any string was missing, I found the <a href="http://wfmh.org.pl/carlos/blog/">W.F.M.H&#8217;s blog</a> were you can download a PHP script to help you for checking all your strings.</p>
<p>The usage is easy (using ES language as example)</p>
<div class="codecolorer-container bash default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>string-check.php values<span style="color: #000000; font-weight: bold;">/</span>strings.xml values-es<span style="color: #000000; font-weight: bold;">/</span>strings.xml</div></div>
<p>You could get a result similar to:</p>
<div class="codecolorer-container bash default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Missing <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">&lt;</span>LANG<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>You need to add these to your <span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
File: values-es<span style="color: #000000; font-weight: bold;">/</span>strings.xml<br />
<span style="color: #660033;">------------------------------------------------------</span><br />
header_title<br />
description_label<br />
<br />
Missing <span style="color: #000000; font-weight: bold;">in</span> EN <span style="color: #7a0874; font-weight: bold;">&#40;</span>you probably shall remove it from your <span style="color: #000000; font-weight: bold;">&lt;</span>LANG<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
File: values<span style="color: #000000; font-weight: bold;">/</span>strings.xml<br />
<span style="color: #660033;">------------------------------------------------------------------</span><br />
mysection_label<br />
<br />
Summary<br />
<span style="color: #660033;">----------------</span><br />
BASE file: <span style="color: #ff0000;">'values/strings.xml'</span><br />
LANG file: <span style="color: #ff0000;">'values-de/strings.xml'</span><br />
&nbsp; &nbsp;<span style="color: #000000;">2</span> missing <span style="color: #c20cb9; font-weight: bold;">strings</span> <span style="color: #000000; font-weight: bold;">in</span> your LANG file.<br />
&nbsp; &nbsp;<span style="color: #000000;">1</span> obsolete <span style="color: #c20cb9; font-weight: bold;">strings</span> <span style="color: #000000; font-weight: bold;">in</span> your LANG file.</div></div>
<p>For more information about the project, visit the main website (recommended): <br /><strong><a href="http://wfmh.org.pl/carlos/blog/2010/07/06/android-translators-helper-tool/">W.F.M.H.&#8217;s blog, Android translators&#8217; helper tool</a></strong></p>
<p>Or download the script directly from his/her website: <strong><a href="http://wfmh.org.pl/carlos/blog/wp-content/strings-check.zip">strings-check.zip</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/check-missing-strings-for-a-multi-language-android-app/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android tip #025 &#8211; Launch Activity from a service</title>
		<link>http://www.eridem.net/android-tip-025-launch-activity-from-a-service</link>
		<comments>http://www.eridem.net/android-tip-025-launch-activity-from-a-service#comments</comments>
		<pubDate>Mon, 18 Apr 2011 13:52:39 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1391</guid>
		<description><![CDATA[Platform/Language: Java/Android Description: if we have a service in background and we need to launch an Activity in foreground, we need to add the tag FLAG_ACTIVITY_NEW_TASK to the Intent. Code: MyService.java 1234567891011public class MyService extends Service &#123; &#160; /* ... */ &#160; private void launchActivity&#40;&#41; &#123; &#160; &#160; Intent intent = new Intent&#40;this, MyActivity.class&#41;; &#160; &#160; intent.addFlags&#40;Intent.FLAG_ACTIVITY_NEW_TASK&#41;; &#160; &#160; this.startActivity&#40;intent&#41;; &#160; &#125; &#160; /* ... */ &#125;]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: Java/Android</p>
<p><strong>Description</strong>: if we have a service in background and we need to launch an Activity in foreground, we need to add the tag <em>FLAG_ACTIVITY_NEW_TASK</em> to the Intent.</p>
<p><strong>Code</strong>:</p>
<p align="center"><i>MyService.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyService <span style="color: #000000; font-weight: bold;">extends</span> Service <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">/* ... */</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> launchActivity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Intent intent <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>, MyActivity.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; intent.<span style="color: #006633;">addFlags</span><span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">FLAG_ACTIVITY_NEW_TASK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">startActivity</span><span style="color: #009900;">&#40;</span>intent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">/* ... */</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-025-launch-activity-from-a-service/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android tip #024 &#8211; Optimize lists a 175%</title>
		<link>http://www.eridem.net/android-tip-024-optimize-lists-a-175</link>
		<comments>http://www.eridem.net/android-tip-024-optimize-lists-a-175#comments</comments>
		<pubDate>Sat, 09 Apr 2011 14:15:53 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1379</guid>
		<description><![CDATA[Platform/Language: Java/XML/Android Related with: Optimize lists a 150% Description: two operations are expensive when we create custom lists: Inflate (covered on the tip 23) and findByViewId(int). We can avoid call to this second operation saving the views used for every row in a wrapper. This pattern implies use a Model and a Wrapper. The Model will save the information of every row and the Wrapper will save the Views. We need to save the wrapper in every row view using the properties getTag() and setTag(Object). This example will use only one value in the model and a TextView in the wrapper, but you can extend it as much as you wish. Code: Model: Item.java 1234567891011121314public class Item &#123; &#160; private String value = null; &#160; public String getValue&#40;&#41; &#123; &#160; &#160; if &#40;this.value == null&#41; &#123; &#160; &#160; &#160; this.value = &#34;&#34;; &#160; &#160; &#125; &#160; &#160; return this.value; &#160; &#125; &#160; public void setValue&#40;String value&#41; &#123; &#160; &#160; &#160; this.value = value; &#160; &#125; &#125; Wrapper: ItemWrapper.java 1234567891011121314151617181920public class ItemWrapper &#123; &#160; private View row = null; &#160; private TextView mTextView = null; &#160; public ItemWrapper&#40;View row&#41; &#123; &#160; &#160; this.mRow = row; &#160; &#125; &#160; private TextView getMTextView&#40;&#41; [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: Java/XML/Android</p>
<p><strong>Related with:</strong> <a href="/android-tip-023-optimize-lists-a-150">Optimize lists a 150%</a></p>
<p><strong>Description</strong>: two operations are <em>expensive</em> when we create custom lists: Inflate (covered on the <a href="/android-tip-023-optimize-lists-a-150">tip 23</a>) and <em>findByViewId(int)</em>. We can avoid call to this second operation saving the views used for every row in a wrapper.</p>
<p>This pattern implies use a Model and a Wrapper. The Model will save the information of every row and the Wrapper will save the Views. We need to save the wrapper in every row view using the properties <em>getTag()</em> and <em>setTag(Object)</em>.</p>
<p>This example will use only one value in the model and a TextView in the wrapper, but you can extend it as much as you wish.</p>
<p><strong>Code</strong>:</p>
<p align="center">Model: <i>Item.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Item <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> value <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <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;">value</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setValue<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</p>
<p align="center">Wrapper: <i>ItemWrapper.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ItemWrapper <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">View</span> row <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> TextView mTextView <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> ItemWrapper<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> row<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mRow</span> <span style="color: #339933;">=</span> row<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> TextView getMTextView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <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;">mTextView</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mTextView</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">row</span>.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">your_row_layout_textview</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mTextView</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> populate<span style="color: #009900;">&#40;</span>Item item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getMTextView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>item.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</p>
<p align="center">Adapter: <i>MyAdapter.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Item<span style="color: #339933;">&gt;</span> items<span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* ... */</span><br />
<br />
@Override<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">View</span> getView<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position, <span style="color: #003399;">View</span> convertView,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ViewGroup parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003399;">View</span> row <span style="color: #339933;">=</span> convertView<span style="color: #339933;">;</span><br />
&nbsp; ItemWrapper wrapper <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>row <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; LayoutInflater inflater <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>LayoutInflater<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mContext</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">getSystemService</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span>.<span style="color: #006633;">LAYOUT_INFLATER_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; row <span style="color: #339933;">=</span> inflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">your_row_layout</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; wrapper <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ItemWrapper<span style="color: #009900;">&#40;</span>row<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; row.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>wrapper<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; <br />
&nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; wrapper <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ItemWrapper<span style="color: #009900;">&#41;</span> row.<span style="color: #006633;">getTag</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">/* Populate row */</span><br />
&nbsp; wrapper.<span style="color: #006633;">populate</span><span style="color: #009900;">&#40;</span>items.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; <br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">return</span> row<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-024-optimize-lists-a-175/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android tip #023 &#8211; Optimize lists a 150%</title>
		<link>http://www.eridem.net/android-tip-023-optimize-lists-a-150</link>
		<comments>http://www.eridem.net/android-tip-023-optimize-lists-a-150#comments</comments>
		<pubDate>Sat, 09 Apr 2011 13:49:21 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1373</guid>
		<description><![CDATA[Platform/Language: Java/XML/Android Related with: Optimize lists a 175% Description: we can optimize the Adapters attached to a ListView inflating our custom layouts when it is necessary. This process is easy to implement with only one condition (Android will managed the rest of the work). MyAdapter.java 12345678910111213141516171819/* ... */ @Override public View getView&#40;int position, View convertView, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ViewGroup parent&#41; &#123; &#160; View row = convertView; &#160; if &#40;row == null&#41; &#123; &#160; &#160; LayoutInflater inflater = &#40;LayoutInflater&#41; this.mContext &#160; &#160; &#160; &#160; .getSystemService&#40;Context.LAYOUT_INFLATER_SERVICE&#41;; &#160; &#160; row = inflater.inflate&#40;R.layout.your_row_layout, null&#41;; &#160; &#160; &#125; &#160; /* Populate row */ &#160; &#160; return row; &#125; /* ... */]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: Java/XML/Android</p>
<p><strong>Related with:</strong> <a href="/android-tip-024-optimize-lists-a-175">Optimize lists a 175%</a></p>
<p><strong>Description</strong>: we can optimize the Adapters attached to a ListView inflating our custom layouts when it is necessary. This process is easy to implement with only one condition (Android will managed the rest of the work).</p>
<p align="center"><i>MyAdapter.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/* ... */</span><br />
<br />
@Override<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">View</span> getView<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position, <span style="color: #003399;">View</span> convertView,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ViewGroup parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003399;">View</span> row <span style="color: #339933;">=</span> convertView<span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>row <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; LayoutInflater inflater <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>LayoutInflater<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mContext</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">getSystemService</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span>.<span style="color: #006633;">LAYOUT_INFLATER_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; row <span style="color: #339933;">=</span> inflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">your_row_layout</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">/* Populate row */</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">return</span> row<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* ... */</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-023-optimize-lists-a-150/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android tip #022 &#8211; Play alarm sound</title>
		<link>http://www.eridem.net/android-tip-022-play-alarm-sound</link>
		<comments>http://www.eridem.net/android-tip-022-play-alarm-sound#comments</comments>
		<pubDate>Fri, 01 Apr 2011 13:22:12 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1320</guid>
		<description><![CDATA[Platform/Language: Java/Android Description: we can play the user&#8217;s alarm sound in our application using the class RingtoneManager and MediaPlayer. Code: YourActivity.java 12345678910111213141516171819202122/* ... */ private MediaPlayer playAlarmSound&#40;&#41; &#123; &#160; Uri alert = RingtoneManager.getDefaultUri&#40; &#160; &#160; &#160; &#160; &#160; &#160; &#160; RingtoneManager.TYPE_ALARM&#41;; &#160; MediaPlayer mMediaPlayer = new MediaPlayer&#40;&#41;; &#160; mMediaPlayer.setDataSource&#40;this, alert&#41;; &#160; AudioManager audioManager = &#40;AudioManager&#41;getSystemService&#40; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Context.AUDIO_SERVICE&#41;; &#160; int volumen = audioManager.getStreamVolume&#40; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; AudioManager.STREAM_ALARM&#41;; &#160; &#160; if &#40;volumen != 0&#41; &#123; &#160; &#160; mMediaPlayer.setAudioStreamType&#40;AudioManager.STREAM_ALARM&#41;; &#160; &#160; mMediaPlayer.setLooping&#40;true&#41;; &#160; &#160; mMediaPlayer.prepare&#40;&#41;; &#160; &#160; mMediaPlayer.start&#40;&#41;; &#160; &#125; &#160; return mMediaPlayer; // We can stop it outside &#125;]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: Java/Android</p>
<p><strong>Description</strong>: we can play the user&#8217;s alarm sound in our application using the class RingtoneManager and MediaPlayer.</p>
<p><strong>Code</strong>:</p>
<p align="center"><i>YourActivity.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/* ... */</span><br />
<br />
<span style="color: #000000; font-weight: bold;">private</span> MediaPlayer playAlarmSound<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; Uri alert <span style="color: #339933;">=</span> RingtoneManager.<span style="color: #006633;">getDefaultUri</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RingtoneManager.<span style="color: #006633;">TYPE_ALARM</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; MediaPlayer mMediaPlayer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MediaPlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; mMediaPlayer.<span style="color: #006633;">setDataSource</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, alert<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; AudioManager audioManager <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AudioManager<span style="color: #009900;">&#41;</span>getSystemService<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Context</span>.<span style="color: #006633;">AUDIO_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">int</span> volumen <span style="color: #339933;">=</span> audioManager.<span style="color: #006633;">getStreamVolume</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AudioManager.<span style="color: #006633;">STREAM_ALARM</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>volumen <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; mMediaPlayer.<span style="color: #006633;">setAudioStreamType</span><span style="color: #009900;">&#40;</span>AudioManager.<span style="color: #006633;">STREAM_ALARM</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; mMediaPlayer.<span style="color: #006633;">setLooping</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; mMediaPlayer.<span style="color: #006633;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; mMediaPlayer.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">return</span> mMediaPlayer<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// We can stop it outside</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-022-play-alarm-sound/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android tip #021 &#8211; SSH, execute remote commands with Android</title>
		<link>http://www.eridem.net/android-tip-021-ssh-execute-remote-commands-with-android</link>
		<comments>http://www.eridem.net/android-tip-021-ssh-execute-remote-commands-with-android#comments</comments>
		<pubDate>Wed, 30 Mar 2011 11:31:20 +0000</pubDate>
		<dc:creator>ERiDeM</dc:creator>
				<category><![CDATA[Android Tips]]></category>

		<guid isPermaLink="false">http://www.eridem.net/?p=1220</guid>
		<description><![CDATA[Platform/Language: Java/XML/Android Description: we can use some external libraries to create a SSH connection and execute commands on remote. We need to download the JSCH libraries and JZLIB libraries that we can get directly on here: Download JSCH 0.1.44 Download JZLib 1.0.7 Furthermore, we need to give INTERNET permission to our application in the manifest file. In this example we execute the command ls in a remote machine using SSH and return the result. NOTE: you should improve the code for exception handling. Code: AndroidManifest.xml 1234&#60;manifest ... &#62; &#160;&#60;!-- ... --&#62; &#160; &#160; &#160;&#60;uses-permission android:name=&#34;android.permission.INTERNET&#34; /&#62; &#60;/manifest&#62; YourClass.java 12345678910111213141516171819202122232425262728293031323334/* ... */ public static String executeRemoteCommand&#40; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;String username, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;String password, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;String hostname, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;int port&#41; throws Exception &#123; &#160; &#160; &#160; &#160; &#160; JSch jsch = new JSch&#40;&#41;; &#160; Session session = jsch.getSession&#40;username, hostname, 22&#41;; &#160; session.setPassword&#40;password&#41;; &#160; &#160; &#160; &#160; &#160; // Avoid asking for key confirmation &#160; Properties prop = new Properties&#40;&#41;; &#160; prop.put&#40;&#34;StrictHostKeyChecking&#34;, &#34;no&#34;&#41;; &#160; [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Platform/Language</strong>: Java/XML/Android</p>
<p><strong>Description</strong>: we can use some external libraries to create a SSH connection and execute commands on remote.</p>
<p>We need to download the <a href="http://www.jcraft.com/jsch/">JSCH</a> libraries and <a href="http://www.jcraft.com/jzlib/">JZLIB</a> libraries that we can get directly on here:</p>
<ul>
<li><a href="http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.44/jsch-0.1.44.jar/download">Download JSCH 0.1.44</a></li>
<li><a href="http://www.jcraft.com/jzlib/jzlib-1.0.7.tar.gz">Download JZLib 1.0.7</a></li>
</ul>
<p>Furthermore, we need to give INTERNET permission to our application in the manifest file.</p>
<p>In this example we execute the command <i>ls</i> in a remote machine using SSH and return the result. NOTE: you should improve the code for exception handling.</p>
<p><strong>Code</strong>:</p>
<p align="center"><i>AndroidManifest.xml</i></p>
<div class="codecolorer-container xml default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest</span> ... <span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp;<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span> &nbsp; &nbsp;<br />
&nbsp;<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><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
</p>
<p align="center"><i>YourClass.java</i></p>
<div class="codecolorer-container java default notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/* ... */</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> executeRemoteCommand<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003399;">String</span> username,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003399;">String</span> password,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003399;">String</span> hostname,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp;<br />
&nbsp; JSch jsch <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Session session <span style="color: #339933;">=</span> jsch.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span>username, hostname, <span style="color: #cc66cc;">22</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; session.<span style="color: #006633;">setPassword</span><span style="color: #009900;">&#40;</span>password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// Avoid asking for key confirmation</span><br />
&nbsp; <span style="color: #003399;">Properties</span> prop <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Properties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; prop.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;StrictHostKeyChecking&quot;</span>, <span style="color: #0000ff;">&quot;no&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; session.<span style="color: #006633;">setConfig</span><span style="color: #009900;">&#40;</span>prop<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; session.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// SSH Channel</span><br />
&nbsp; ChannelExec channelssh <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ChannelExec<span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;session.<span style="color: #006633;">openChannel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;exec&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; <span style="color: #003399;">ByteArrayOutputStream</span> baos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; channelssh.<span style="color: #006633;">setOutputStream</span><span style="color: #009900;">&#40;</span>baos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// Execute command</span><br />
&nbsp; channelssh.<span style="color: #006633;">setCommand</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ls&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; channelssh.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; channelssh.<span style="color: #006633;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">return</span> baos.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* ... */</span></div></td></tr></tbody></table></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.eridem.net/android-tip-021-ssh-execute-remote-commands-with-android/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
