<?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>GaanZa</title>
	<atom:link href="http://www.gaanza.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gaanza.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Jan 2012 10:09:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dude!!!  I just want to open (only) email client program via intents</title>
		<link>http://www.gaanza.com/blog/email-client-intent-android/</link>
		<comments>http://www.gaanza.com/blog/email-client-intent-android/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 06:13:50 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[action_send]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[intent]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=984</guid>
		<description><![CDATA[Hola everyone, Been very busy and christmas season on way. Anyway i am here again and have something to show and tell. There was a project i was working on, and i want to send some email message from my app. So i used an intent to open up options of my email clients installed [...]]]></description>
			<content:encoded><![CDATA[<p>Hola everyone,<br />
Been very busy and christmas season on way. Anyway i am here again and have something to show and tell. There was a project i was working on, and i want to send some email message from my app. So i used an intent to open up options of my email clients installed on my device. So its not a big deal to use an intent and i used <strong>android.content.Intent.ACTION_SEND</strong> and i got the options. But i didn&#8217;t just got email clients  but also other communication app like text message, dropbox, facebook, twitter etc. That i didn&#8217;t want it. I just wanted email clients to show up i.e like email, gmail, hotmail, email text only(or other email client u have installed). After doing research for long hours i came up with 2 solutions. First solution works but not perfect and second solution is just awesome, works perfectly. But first i&#8217;l show my code that i used before:</p>
<div class="codesnip-container" >
<div class="codesnip"><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> recipients = <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#123;</span><span class="st0">&#8220;sendme@me.com&#8221;</span>, <span class="st0">&#8220;&#8221;</span><span class="br0">&#125;</span>;<br />
Intent testIntent = <span class="kw2">new</span> Intent<span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">ACTION_SEND</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">setType</span><span class="br0">&#40;</span><span class="st0">&#8220;text/plain&#8221;</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">putExtra</span><span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">EXTRA_SUBJECT</span>, <span class="st0">&#8220;blah blah subject&#8221;</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">putExtra</span><span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">EXTRA_TEXT</span>, <span class="st0">&#8220;blah blah body message&#8221;</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">putExtra</span><span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">EXTRA_EMAIL</span>, recipients<span class="br0">&#41;</span>;<br />
startActivity<span class="br0">&#40;</span>testIntent<span class="br0">&#41;</span>;</div>
</div>
<p>Well the above code doesn&#8217;t work if u need just email clients to show but this code shows all communication apps. So i decided to change setType of intent from (&#8220;text/plain&#8221;) to (&#8220;text/email&#8221;).</p>
<div class="codesnip-container" >
<div class="codesnip">testIntent.<span class="me1">setType</span><span class="br0">&#40;</span><span class="st0">&#8220;text/email&#8221;</span><span class="br0">&#41;</span>;</div>
</div>
<p>Well it did filter some apps but still not perfect because it still showed some apps like andFTP, dropbox, google docs etc.<br />
Now i had to do some serious research, i asked in forum but didn&#8217;t got much help and then i stumbled into one post that asked similar question on stackoverflow. So i found 2 solution, both works, one is not too perfect but works in most scenario, and second solution is awesomely perfect, well it worked for me so u have to test yourself to see if it works for u <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><strong>Solution 1:</strong><br />
just change <strong>setType to &#8220;message/rfc822&#8243;</strong>. Yes this works but with very minor flaw. It filtered out all communicatio app exept one, i.e andFTP yeah it didn&#8217;t filtered out andFTP and this ruined it. But it filtered out others and showed only email clients.</p>
<div class="codesnip-container" >
<div class="codesnip"><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> recipients = <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#123;</span><span class="st0">&#8220;sendme@me.com&#8221;</span>, <span class="st0">&#8220;&#8221;</span><span class="br0">&#125;</span>;<br />
Intent testIntent = <span class="kw2">new</span> Intent<span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">ACTION_SEND</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">setType</span><span class="br0">&#40;</span><span class="st0">&#8220;message/rfc822&#8243;</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">putExtra</span><span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">EXTRA_SUBJECT</span>, <span class="st0">&#8220;blah blah subject&#8221;</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">putExtra</span><span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">EXTRA_TEXT</span>, <span class="st0">&#8220;blah blah body message&#8221;</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">putExtra</span><span class="br0">&#40;</span>android.<span class="me1">content</span>.<span class="me1">Intent</span>.<span class="me1">EXTRA_EMAIL</span>, recipients<span class="br0">&#41;</span>;<br />
startActivity<span class="br0">&#40;</span>testIntent<span class="br0">&#41;</span>;</div>
</div>
<p><strong>Now Solution 2</strong>, which worked perfectly for me. here you don&#8217;t use android.content.Intent.ACTION_SEND but Intent.ACTION_VIEW</p>
<div class="codesnip-container" >
<div class="codesnip">Intent testIntent = <span class="kw2">new</span> Intent<span class="br0">&#40;</span>Intent.<span class="me1">ACTION_VIEW</span><span class="br0">&#41;</span>;<br />
Uri data = Uri.<span class="me1">parse</span><span class="br0">&#40;</span><span class="st0">&#8220;mailto:?subject=&#8221;</span> + <span class="st0">&#8220;blah blah subject&#8221;</span> + <span class="st0">&#8220;&amp;body=&#8221;</span> + <span class="st0">&#8220;blah blah body&#8221;</span> + <span class="st0">&#8220;&amp;to=&#8221;</span> + <span class="st0">&#8220;sendme@me.com&#8221;</span><span class="br0">&#41;</span>;<br />
testIntent.<span class="me1">setData</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span>;<br />
startActivity<span class="br0">&#40;</span>testIntent<span class="br0">&#41;</span>;</div>
</div>
<p><div id="attachment_994" class="wp-caption aligncenter" style="width: 330px"><a href="http://www.gaanza.com/wp-content/uploads/2011/12/intent.png"><img src="http://www.gaanza.com/wp-content/uploads/2011/12/intent.png" alt="" title="intent" width="320" height="480" class="size-full wp-image-994" /></a><p class="wp-caption-text">filtering non email client programs</p></div><br />
Well above code just worked perfectly for me. It filtered out all other communication apps and showed just exclusive email client programs. I hope this works for you also.</p>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/email-client-intent-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dude where is my javascript ?</title>
		<link>http://www.gaanza.com/blog/dude-where-is-my-javascript/</link>
		<comments>http://www.gaanza.com/blog/dude-where-is-my-javascript/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 10:33:26 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webview]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=978</guid>
		<description><![CDATA[Hola everyone, a very hectic schedule going on this season. Working my ass off in my upcoming ambitious project. Anyway i am here and writing about just very basic problem that i faced. For a game project i wanted to show leaderboards, for this part i decided to use web view to show leaderboards page [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Hola everyone,</strong><br />
a very hectic schedule going on this season. Working my ass off in my upcoming ambitious project. Anyway i am here and writing about just very basic problem that i faced. For a game project i wanted to show leaderboards, for this part i decided to use web view to show leaderboards page optimized for device. It has some javascript function that is doing its stuff of retrieving leaderboards details and all that. So i wrote a line to load the url pointing to my leaderboard page and guess what it didn&#8217;t rendered fully and i was again left scratching my head <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  . Then after going through many testing i found that stuffs that were dependent on javascript were not getting rendered on my web view so i got the root of the problem i.e dude where is my javascript ? . Then i did a peroid(.) operator on my webview reference variable and found a method setJavaScriptEnabled(), so i did something like this:</p>
<div class="codesnip-container" >
<div class="codesnip">webView.<span class="me1">getSettings</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">setJavaScriptEnabled</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</div>
<p>and yeah u guessed it right, it rendered fully after calling that method. So i guess by default javascript is disabled on webview. Phew.</p>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/dude-where-is-my-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting Activity from non-activity class</title>
		<link>http://www.gaanza.com/blog/starting-activity-from-non-activity-class/</link>
		<comments>http://www.gaanza.com/blog/starting-activity-from-non-activity-class/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 08:44:38 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[activity]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[intent]]></category>
		<category><![CDATA[non-activity class]]></category>
		<category><![CDATA[startactivity]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=964</guid>
		<description><![CDATA[Hola everyone, While working on android project i got myself into a situation where i had to start an activity from non-activity class (a class that doesn&#8217;t extend Activity), and i had no other option that time. So lets say there is a class called DummyClass having a dummyMethod() and i had to start an [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Hola everyone,</strong></p>
<p>While working on android project i got myself into a situation where i had to start an activity from non-activity class (a class that doesn&#8217;t extend Activity), and i had no other option that time. So lets say there is a class called DummyClass having a dummyMethod() and i had to start an activity called MeActivity, so i wrote this to start an activity, a rough pseudocode:</p>
<div class="codesnip-container" >
<div class="codesnip">DummyClass<span class="br0">&#123;</span><br />
&#8230;<br />
<span class="me1">dummyMethod</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
Intent dummyIntent = <span class="kw2">new</span> Intent<span class="br0">&#40;</span>DummyClass.<span class="kw2">this</span>, MeActivity.<span class="kw2">class</span><span class="br0">&#41;</span>;<br />
<span class="kw2">this</span>.<span class="me1">startActivity</span><span class="br0">&#40;</span>dummyIntent<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
&#8230;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Well as i had my doubts earlier above code is a garbage cuz there is no startActivity() method in my dummyclass. So i did something which worked for me. I declared a public static Context reference variable in MeActivity class and in its constructor i assigned its instance to variable. Here is the code that will look like:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">public</span> <span class="kw2">class</span> MeActivity <span class="kw2">extends</span> Activity<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span class="kw2">public</span> <span class="kw4">static</span> <a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&#038;bntl=1"><span class="kw3">Context</span></a> meActivityContext;<br />
&nbsp; &nbsp; &nbsp;<span class="kw2">public</span> FavoritesActivity<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; MeActivity.<span class="me1">meActivityContext</span>=<span class="kw2">this</span>;<br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>So that was it. Now i used this context variable to start my activity from non-activity class.</p>
<div class="codesnip-container" >
<div class="codesnip">DummyClass<span class="br0">&#123;</span><br />
&#8230;<br />
<span class="me1">dummyMethod</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;Intent dummyIntent = <span class="kw2">new</span> Intent<span class="br0">&#40;</span>MeActivity.<span class="me1">meActivityContext</span>, MeActivity.<span class="kw2">class</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;MeActivity.<span class="me1">meActivityContext</span>.<span class="me1">startActivity</span><span class="br0">&#40;</span>dummyIntent<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
&#8230;<br />
<span class="br0">&#125;</span></div>
</div>
<p>well that worked for me, hope it works for you too.</p>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/starting-activity-from-non-activity-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hide soft keyboard: Android</title>
		<link>http://www.gaanza.com/blog/hide-soft-keyboard-android/</link>
		<comments>http://www.gaanza.com/blog/hide-soft-keyboard-android/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 04:23:47 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[autocompleteview]]></category>
		<category><![CDATA[soft keyboard]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=955</guid>
		<description><![CDATA[I just wanted to share two ways about hiding your soft keyboard. When i was making a screen for submitting score to leaderboards, when i touch edittext to enter my name soft keyboard appears and when i click submit button i wanted that soft keyboard to disappear so i found this one way to do [...]]]></description>
			<content:encoded><![CDATA[<p>I just wanted to share two ways about hiding your soft keyboard. When i was making a screen for submitting score to leaderboards, when i touch edittext to enter my name soft keyboard appears and when i click submit button i wanted that soft keyboard to disappear so i found this one way to do that:</p>
<div class="codesnip-container" >
<div class="codesnip">InputMethodManager inputManager = <span class="br0">&#40;</span>InputMethodManager<span class="br0">&#41;</span>getSystemService<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&#038;bntl=1"><span class="kw3">Context</span></a>.<span class="me1">INPUT_METHOD_SERVICE</span><span class="br0">&#41;</span>; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; inputManager.<span class="me1">hideSoftInputFromWindow</span><span class="br0">&#40;</span>Test.<span class="kw2">this</span>.<span class="me1">getCurrentFocus</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getWindowToken</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, InputMethodManager.<span class="me1">HIDE_NOT_ALWAYS</span><span class="br0">&#41;</span>;</div>
</div>
<p>Now for second issue that i faced, i had a AutoCompleteTextView on my one application activity so whenever that activity takes screen a soft keyboard appears with focus on autocomplete obviously. This thing didn&#8217;t happened with EditText. But whenever i had autocompletetextview soft keyboard appears automatically. I didn&#8217;t wanted this. Instead i wanted soft keyboard to appear only when i touch AutoCompleteTextView. But i found a simple solution for this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;activity</span> android:<span class="re0">name</span>=<span class="st0">&#8220;.MyActivity&#8221;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:<span class="re0">windowSoftInputMode</span>=<span class="st0">&#8220;stateAlwaysHidden&#8221;</span><span class="re2">&gt;</span></span></div>
</div>
<p>yeah just add <strong>android:windowSoftInputMode=&#8221;stateAlwaysHidden&#8221;</strong> attribute to activity tag, so whenever my activity takes screen keyboard will not show up until i touch any editable view. This has worked for me till now, so you can give it a try.</p>
<p><strong>Gracias</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/hide-soft-keyboard-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>world.CreateBody() creating NULL ??</title>
		<link>http://www.gaanza.com/blog/world-createbody-creating-null/</link>
		<comments>http://www.gaanza.com/blog/world-createbody-creating-null/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 06:11:43 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Box 2d]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[step]]></category>
		<category><![CDATA[world]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=951</guid>
		<description><![CDATA[I was doing some test stuff for a game that uses Box 2D flash. I found and learned a thing that i didn&#8217;t knew and it was very important. I had created a world with some bodies(polygons and circles) added to it. I was destroying and creating bodies just to play around. So when i [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some test stuff for a game that uses Box 2D flash. I found and learned a thing that i didn&#8217;t knew and it was very important. I had created a world with some bodies(polygons and circles) added to it. I was destroying and creating bodies just to play around. So when i was creating a body dynamically at runtime, i found out that body wasn&#8217;t getting created because world.CreateBody(bodyDef) was returning NULL. I was really surprised when i found this. I traced everything like if bodyDef and world was not null and all that. So i was looking through my code again and again to find why world.CreateBody was returning null. Then i was suspicious about something. So what i did something to confirm my suspicion that before creating a body i waited all body to sleep i.e when they are not moving or interacting. After all bodies were sleep i created a body and viola bingo bang boom my body was created. So my suspicion was true that when world is stepping then world.CreateBody always returned null (I tested it again and again). Hmnnnnnn so this was pretty interesting. I am still working around to find a solution for this as i haven&#8217;t find any very graceful good solution to create a body during world step. if you have any suggestion/tips or solution please do share.</p>
<p><strong>Gracias</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/world-createbody-creating-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic updating AutoCompleteTextView with remote MySQL data &#8211; Part I</title>
		<link>http://www.gaanza.com/blog/android-autocompletetextview-mysql/</link>
		<comments>http://www.gaanza.com/blog/android-autocompletetextview-mysql/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 05:19:46 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[activity]]></category>
		<category><![CDATA[autocompletetextview]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[how to mysql]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[textwatcher]]></category>
		<category><![CDATA[what is android]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=928</guid>
		<description><![CDATA[Well i have been playing around a lot with android client connectivity with remote MySQL database. Lately i wanted a UI/View, something input textfield, i wanted to show completion suggestions automatically in a drop down menu while the user is typing, suggestions would be coming from MySQL database. Basically whenever i type, i am calling [...]]]></description>
			<content:encoded><![CDATA[<p>Well i have been playing around a lot with android client connectivity with remote MySQL database. Lately i wanted a UI/View, something input textfield, i wanted to show completion suggestions automatically in a drop down menu  while the user is typing, suggestions would be coming from MySQL database. Basically whenever i type, i am calling php sending the input and php will query database and return the values(in my case just names) that have “input” as substring (like if i type ‘pa’ then it would return names that have ‘pa’ as substring). I am sending results to android client via encoded json. In android side i am decoding json and filling my ArrayAdapter. Lets see the points that are being done:</p>
<p><strong>1) PHP</strong></p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">&lt;?php</span><br />
<a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="st0">&#8220;localhost&#8221;</span>,<span class="st0">&#8220;root&#8221;</span>,<span class="st0">&#8220;&#8221;</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="st0">&#8220;dalalstreet&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp;<br />
<span class="re0">$st</span> = <span class="re0">$_REQUEST</span><span class="br0">&#91;</span><span class="st0">&#8216;st&#8217;</span><span class="br0">&#93;</span>;</p>
<p><span class="re0">$q</span>= <a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&#8220;SELECT * FROM world WHERE company LIKE &#8216;%&#8221;</span>.<span class="re0">$st</span>.<span class="st0">&#8220;%&#8217;&#8221;</span><span class="br0">&#41;</span>;</p>
<p><span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$e</span> = <a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$q</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$output</span><span class="br0">&#91;</span><span class="br0">&#93;</span>=<span class="re0">$e</span>;<br />
&nbsp;<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a><span class="br0">&#40;</span>json_encode<span class="br0">&#40;</span><span class="re0">$output</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;<br />
<a href="http://www.php.net/mysql_close"><span class="kw3">mysql_close</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
<p>I somehow looking at google i wrote this code. This php gets the input text from my android and it runs query at database for records whose company names has “input text” as a substring. You can see the query statement above. In the end it encodes the result in json.</p>
<p><strong>2) Main.xml (my layout)</strong><br />
    Here is the xml layout file for my ui.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;</span>?xml <span class="re0">version</span>=<span class="st0">&#8220;1.0&#8243;</span> <span class="re0">encoding</span>=<span class="st0">&#8220;utf-8&#8243;</span>?<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;LinearLayout</span> xmlns:<span class="re0">android</span>=<span class="st0">&#8220;http://schemas.android.com/apk/res/android&#8221;</span><br />
&nbsp; &nbsp; android:<span class="re0">orientation</span>=<span class="st0">&#8220;vertical&#8221;</span><br />
&nbsp; &nbsp; android:layout_<span class="re0">width</span>=<span class="st0">&#8220;fill_parent&#8221;</span><br />
&nbsp; &nbsp; android:layout_<span class="re0">height</span>=<span class="st0">&#8220;fill_parent&#8221;</span><br />
&nbsp; &nbsp; <span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;TextView</span>&nbsp; <br />
&nbsp; &nbsp; android:layout_<span class="re0">width</span>=<span class="st0">&#8220;wrap_content&#8221;</span> <br />
&nbsp; &nbsp; android:layout_<span class="re0">height</span>=<span class="st0">&#8220;wrap_content&#8221;</span> <br />
&nbsp; &nbsp; android:<span class="re0">text</span>=<span class="st0">&#8220;@string/country_label&#8221;</span><br />
&nbsp; &nbsp; <span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;CustomAutoCompleteView</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; android:<span class="re0">id</span>=<span class="st0">&#8220;@+id/autoCompleteCountry&#8221;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; android:layout_<span class="re0">width</span>=<span class="st0">&#8220;fill_parent&#8221;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; android:layout_<span class="re0">height</span>=<span class="st0">&#8220;wrap_content&#8221;</span> <span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/LinearLayout<span class="re2">&gt;</span></span></span></div>
</div>
<p><strong>3) Main Activity class</strong><br />
Here is the main class that extends Activity. Here is the code of calling php module and parsing json. I have explained this all in my previous post so you could go through it. i’l explain just AutoCompleteTextView part here.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co2">import java.io.BufferedReader;</span><br />
<span class="co2">import java.io.InputStream;</span><br />
<span class="co2">import java.io.InputStreamReader;</span><br />
<span class="co2">import java.util.ArrayList;</span></p>
<p><span class="co2">import org.apache.http.HttpEntity;</span><br />
<span class="co2">import org.apache.http.HttpResponse;</span><br />
<span class="co2">import org.apache.http.NameValuePair;</span><br />
<span class="co2">import org.apache.http.client.HttpClient;</span><br />
<span class="co2">import org.apache.http.client.entity.UrlEncodedFormEntity;</span><br />
<span class="co2">import org.apache.http.client.methods.HttpPost;</span><br />
<span class="co2">import org.apache.http.impl.client.DefaultHttpClient;</span><br />
<span class="co2">import org.apache.http.message.BasicNameValuePair;</span><br />
<span class="co2">import org.json.JSONArray;</span><br />
<span class="co2">import org.json.JSONException;</span><br />
<span class="co2">import org.json.JSONObject;</span></p>
<p><span class="co2">import android.app.Activity;</span><br />
<span class="co2">import android.os.Bundle;</span><br />
<span class="co2">import android.text.Editable;</span><br />
<span class="co2">import android.text.TextWatcher;</span><br />
<span class="co2">import android.util.Log;</span><br />
<span class="co2">import android.widget.ArrayAdapter;</span></p>
<p><span class="kw2">public</span> <span class="kw2">class</span> AutoComptest <span class="kw2">extends</span> Activity <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> CustomAutoCompleteView autoComplete;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> ArrayAdapter&lt;String&gt; autoCompleteAdapter;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/** Called when the activity is first created. */</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> onCreate<span class="br0">&#40;</span>Bundle savedInstanceState<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; super.<span class="me1">onCreate</span><span class="br0">&#40;</span>savedInstanceState<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; setContentView<span class="br0">&#40;</span>R.<span class="me1">layout</span>.<span class="me1">main</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; autoCompleteAdapter = <span class="kw2">new</span> ArrayAdapter&lt;String&gt;<span class="br0">&#40;</span><span class="kw2">this</span>, android.<span class="me1">R</span>.<span class="me1">layout</span>.<span class="me1">simple_dropdown_item_1line</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; autoCompleteAdapter.<span class="me1">setNotifyOnChange</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span>; <span class="co1">// This is so I don&#8217;t have to manually sync whenever changed&nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; autoComplete = <span class="br0">&#40;</span>CustomAutoCompleteView<span class="br0">&#41;</span>&nbsp; findViewById<span class="br0">&#40;</span>R.<span class="me1">id</span>.<span class="me1">autoCompleteCountry</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; autoComplete.<span class="me1">setHint</span><span class="br0">&#40;</span><span class="st0">&#8220;Country&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; autoComplete.<span class="me1">setThreshold</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; autoComplete.<span class="me1">setAdapter</span><span class="br0">&#40;</span>autoCompleteAdapter<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; autoComplete.<span class="me1">addTextChangedListener</span><span class="br0">&#40;</span>textChecker<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">final</span> TextWatcher textChecker = <span class="kw2">new</span> TextWatcher<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> afterTextChanged<span class="br0">&#40;</span>Editable s<span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> beforeTextChanged<span class="br0">&#40;</span>CharSequence s, <span class="kw4">int</span> start, <span class="kw4">int</span> count, <span class="kw4">int</span> after<span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> onTextChanged<span class="br0">&#40;</span>CharSequence s, <span class="kw4">int</span> start, <span class="kw4">int</span> before, <span class="kw4">int</span> count<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; autoCompleteAdapter.<span class="me1">clear</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callPHP<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">void</span> callPHP<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> result = <span class="st0">&#8220;&#8221;</span>;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AInputStream+java.sun.com&#038;bntl=1"><span class="kw3">InputStream</span></a> is=<span class="kw2">null</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ArrayList&lt;NameValuePair&gt; nameValuePairs = <span class="kw2">new</span> ArrayList&lt;NameValuePair&gt;<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nameValuePairs.<span class="me1">add</span><span class="br0">&#40;</span><span class="kw2">new</span> BasicNameValuePair<span class="br0">&#40;</span><span class="st0">&#8220;st&#8221;</span>,autoComplete.<span class="me1">getText</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpClient httpclient = <span class="kw2">new</span> DefaultHttpClient<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpPost httppost = <span class="kw2">new</span> HttpPost<span class="br0">&#40;</span><span class="st0">&#8220;http://10.0.2.2/gaanza_android/android_database.php&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;httppost.<span class="me1">setEntity</span><span class="br0">&#40;</span><span class="kw2">new</span> UrlEncodedFormEntity<span class="br0">&#40;</span>nameValuePairs<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpResponse response = httpclient.<span class="me1">execute</span><span class="br0">&#40;</span>httppost<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpEntity entity = response.<span class="me1">getEntity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is = entity.<span class="me1">getContent</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&#038;bntl=1"><span class="kw3">Exception</span></a> e<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span class="me1">e</span><span class="br0">&#40;</span><span class="st0">&#8220;log_tag&#8221;</span>, <span class="st0">&#8220;Error in http connection &#8220;</span>+e.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span><span class="br0">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=allinurl%3ABufferedReader+java.sun.com&#038;bntl=1"><span class="kw3">BufferedReader</span></a> reader = <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3ABufferedReader+java.sun.com&#038;bntl=1"><span class="kw3">BufferedReader</span></a><span class="br0">&#40;</span><span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AInputStreamReader+java.sun.com&#038;bntl=1"><span class="kw3">InputStreamReader</span></a><span class="br0">&#40;</span>is,<span class="st0">&#8220;iso-8859-1&#8243;</span><span class="br0">&#41;</span>,<span class="nu0">8</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StringBuilder sb = <span class="kw2">new</span> StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> line = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">while</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>line = reader.<span class="me1">readLine</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> != <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;sb.<span class="me1">append</span><span class="br0">&#40;</span>line + <span class="st0">&#8220;<span class="es0">\n</span>&#8220;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result=sb.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&#038;bntl=1"><span class="kw3">Exception</span></a> e<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span class="me1">e</span><span class="br0">&#40;</span><span class="st0">&#8220;log_tag&#8221;</span>, <span class="st0">&#8220;Error converting result &#8220;</span>+e.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//parse json data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JSONArray jArray = <span class="kw2">new</span> JSONArray<span class="br0">&#40;</span>result<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;jArray.<span class="me1">length</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;i++<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JSONObject json_data = jArray.<span class="me1">getJSONObject</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;autoCompleteAdapter.<span class="me1">add</span><span class="br0">&#40;</span>json_data.<span class="me1">getString</span><span class="br0">&#40;</span><span class="st0">&#8220;country&#8221;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">catch</span><span class="br0">&#40;</span>JSONException e<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span class="me1">e</span><span class="br0">&#40;</span><span class="st0">&#8220;log_tag&#8221;</span>, <span class="st0">&#8220;Error parsing data &#8220;</span>+e.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p><strong>Note: remember “http://10.0.2.2/&#8221; in my <a href="http://www.gaanza.com/blog/how-to-mysql/" target="_blank">last post</a>. I had to use 10.0.2.2 instead of localhost because emulator consider itself as localhost and my xammp local server is not in emulator localhost.</strong></p>
<p>Ok so i want to detect an event when a text is typed/deleted from my autocompletetextview, basically i want a listener which detects a change in text of my view. So what should we do ? Well in my case i searched the android developer documentation <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  , there i found something called TextWatcher. What i am doing is attach a TextWatcher object to editable like my AutoCompleteTextView so whenever any text changes in my editable the functions/methods of TextWatcher will be called and in these methods i had to write my logic codes which is what i want to achieve if text changes in autocompletetextview ?. There are three abstract methods in TextWatcher class so you have to override them, well anyway thats what we wanted. Methods are:</p>
<blockquote><p>afterTextChanged(Editable s)<br />
	beforeTextChanged(CharSequence c, int start, int count, int after)<br />
	onTextChanged(CharSequence c, int start, int before, int count)</p></blockquote>
<p>Best way to understand them is going through the <a href="http://developer.android.com/reference/android/text/TextWatcher.html" title="TextWatcher" target="_blank">document here</a>. Anyway i had to write my logic code on beforeTextChanged() method so that it performs action whenever there is a change in text of autocompletetextview.</p>
<p>In above code sample i am calling PHP whenever i am typing something. So i am calling callPHP function at onTextChanged() method. So whenever i type something it will call PHP giving text to the function in PHP and PHP will query MySql	database for results and PHP will send results to me in json. This is it. So i decode json and fill the results in ArrayAdapter after clearing it, whenever ArrayAdapter changes it notify the changes being made and AutoCompleteView will show the new drop down suggestions.</p>
<p>There was still one very minor problem and i solved it with my another very stupid solution <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  So problem was that whenever the results from database gets filled in ArrayAdapter and AutoCompleteTextView shows drop down suggestions, it showed me filtered suggestions like suppose i type “can” and i get results(which has “can” as substring) from database, so for “can” ArrayAdapter contents get filtered and i get suggestion starting with text “can” which i didn’t wanted because i already has got filtered results from database and i wanted to show all results that i am receiving from database. So for this i had to write my custom AutoCompleteTextView. It isn’t hard at all, i just had to extend AutoCompleteTextView and override the methods.</p>
<p><strong>4) CustomAutoCompleteView which extends AutoCompletetextView</strong></p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">public</span> <span class="kw2">class</span> CustomAutoCompleteView <span class="kw2">extends</span> AutoCompleteTextView <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> CustomAutoCompleteView<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&#038;bntl=1"><span class="kw3">Context</span></a> context<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super<span class="br0">&#40;</span>context<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// TODO Auto-generated constructor stub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> CustomAutoCompleteView<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&#038;bntl=1"><span class="kw3">Context</span></a> context, <a href="http://www.google.com/search?q=allinurl%3AAttributeSet+java.sun.com&#038;bntl=1"><span class="kw3">AttributeSet</span></a> attrs<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super<span class="br0">&#40;</span>context, attrs<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// TODO Auto-generated constructor stub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> CustomAutoCompleteView<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AContext+java.sun.com&#038;bntl=1"><span class="kw3">Context</span></a> context, <a href="http://www.google.com/search?q=allinurl%3AAttributeSet+java.sun.com&#038;bntl=1"><span class="kw3">AttributeSet</span></a> attrs,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">int</span> defStyle<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super<span class="br0">&#40;</span>context, attrs, defStyle<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// TODO Auto-generated constructor stub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">protected</span> <span class="kw4">void</span> performFiltering<span class="br0">&#40;</span><span class="kw2">final</span> CharSequence text, <span class="kw2">final</span> <span class="kw4">int</span> keyCode<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> filterText = <span class="st0">&#8220;&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super.<span class="me1">performFiltering</span><span class="br0">&#40;</span>filterText, keyCode<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; * After a selection, capture the new value and append to the existing<br />
&nbsp; &nbsp; * text<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span class="kw2">protected</span> <span class="kw4">void</span> replaceText<span class="br0">&#40;</span><span class="kw2">final</span> CharSequence text<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; super.<span class="me1">replaceText</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<p><strong>How to remove the filter on an ArrayAdapter used in an AutoCompleteTextView?</strong> I had to override performFiltering() method. In this method i am telling AutoCompletetextView to not filter any suggestions, just show all suggestions. I searched on google for this topic but i didn’t find any good solution, maybe i didn’t searched it properly. Whatever, i just wrote a stupid trick to remove any filter, actually instead of technically removing filter i am adding a filter which does a job to show all suggestions <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . I defined a filter which filters all suggestion based on “” yeah a blank string <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . But this works like a charm. Just try it.</p>
<p><strong>So now your are getting results suggestion from database dynamically to AutoCompleteTextView.</strong></p>
<p>But But But But But ok enough, In above code way of fetching data from database to AutoCompletetextView just sucks. Never never ever call a http PHP call in UI Thread. I did a lot of testing with this code. When i was getting small number of results from Database(live database not local) it was working fine but when i was getting large number of results say more than 150 and it was taking a bit of time which caused my UI to be non-responsive and thus famous FORCE CLOSE occured. So never call it from UI thread because u don’t know how much time it will take to complete whole http connection. So always call it in separate thread that i will discuss in Part II of this subject. yes i’l be posting new better version of same problem.</p>
<p><strong>Gracias</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/android-autocompletetextview-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Calling google translate api from flash client</title>
		<link>http://www.gaanza.com/blog/google-translate-flash/</link>
		<comments>http://www.gaanza.com/blog/google-translate-flash/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 10:06:16 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Developer]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google translate]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=903</guid>
		<description><![CDATA[Today i was doing some experiment with google translate API. I was trying to use google translate API with AS3. I found many snippets while googling that was using flex but i wanted to do it in flash as3. So I wrote a very basic code snippet to translate text from one language to other [...]]]></description>
			<content:encoded><![CDATA[<p>Today i was doing some experiment with google translate API. I was trying to use google translate API with AS3. I found many snippets while googling that was using flex but i wanted to do it in flash as3. So I wrote a very basic code snippet to translate text from one language to other using google translate API.</p>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="550" height="400"></p>
<param name="movie" value="http://www.gaanza.com/wp-content/uploads/2011/07/translate.swf" />
<param name="quality" value="high" />
  <embed src="http://www.gaanza.com/wp-content/uploads/2011/07/translate.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height=400"></embed><br />
</object></p>
<p>Well i have created two combobox on my fla. I have given instance name to them and then i am just taking the language input for translating text from one language to other.</p>
<p>The main crucial part:</p>
<blockquote><p>&#8216;http://ajax.googleapis.com/ajax/services/language/translate&#8217;+'?v=2.0&#8242;+&#8217;&#038;q=&#8217;+escape(my_input)+&#8217;&#038;langpair=&#8217;+'es&#8217;+'%7C&#8217;+'en&#8217;</p></blockquote>
<p>I am just making a GET HTTP Call to google translate API passing input, and language pair (i.e en(english) to es(espanol) etc). It returns result in JSON. On my flash client i decode that JSON and display the translated result.<br />
<strong>Note: escape method is used to encode the string to url encoded format</strong></p>
<p>Here is the source code:</p>
<div class="codesnip-container" >
<div class="codesnip">package <br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import com.adobe.serialization.json.JSON;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import flash.display.Sprite;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import flash.events.Event;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import flash.events.MouseEvent;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import flash.net.URLLoader;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import flash.net.URLRequest;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import flash.net.URLRequestMethod;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import flash.net.URLVariables;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co2">import fl.data.DataProvider; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * &#8230;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; * @author padam<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">class</span> Main <span class="kw2">extends</span> Sprite <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> function Main<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw4">void</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>stage<span class="br0">&#41;</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> addEventListener<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a>.<span class="me1">ADDED_TO_STAGE</span>, init<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> function init<span class="br0">&#40;</span>e:<a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a> = <span class="kw2">null</span><span class="br0">&#41;</span>:<span class="kw4">void</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeEventListener<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a>.<span class="me1">ADDED_TO_STAGE</span>, init<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// entry point</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initGUI<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; button_p.<span class="me1">addEventListener</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AMouseEvent+java.sun.com&#038;bntl=1"><span class="kw3">MouseEvent</span></a>.<span class="me1">CLICK</span>, translate<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> function initGUI<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw4">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var itemsFrom:<a href="http://www.google.com/search?q=allinurl%3AArray+java.sun.com&#038;bntl=1"><span class="kw3">Array</span></a> = <span class="br0">&#91;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;English&#8221;</span>, data:<span class="st0">&#8220;en&#8221;</span><span class="br0">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;Spanish&#8221;</span>, data:<span class="st0">&#8220;es&#8221;</span><span class="br0">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;French&#8221;</span>, data:<span class="st0">&#8220;fr&#8221;</span><span class="br0">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;Italian&#8221;</span>, data:<span class="st0">&#8220;it&#8221;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var itemsTo:<a href="http://www.google.com/search?q=allinurl%3AArray+java.sun.com&#038;bntl=1"><span class="kw3">Array</span></a> = <span class="br0">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;Hindi&#8221;</span>, data:<span class="st0">&#8220;hi&#8221;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;English&#8221;</span>, data:<span class="st0">&#8220;en&#8221;</span><span class="br0">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;Spanish&#8221;</span>, data:<span class="st0">&#8220;es&#8221;</span><span class="br0">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;French&#8221;</span>, data:<span class="st0">&#8220;fr&#8221;</span><span class="br0">&#125;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>label:<span class="st0">&#8220;Italian&#8221;</span>, data:<span class="st0">&#8220;it&#8221;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fromLanguageCombo.<span class="me1">prompt</span> = <span class="st0">&#8220;Select Language&#8221;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fromLanguageCombo.<span class="me1">dataProvider</span> = <span class="kw2">new</span> DataProvider<span class="br0">&#40;</span>itemsFrom<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toLanguageCombo.<span class="me1">dataProvider</span> = <span class="kw2">new</span> DataProvider<span class="br0">&#40;</span>itemsTo<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> function translate<span class="br0">&#40;</span>event:<a href="http://www.google.com/search?q=allinurl%3AMouseEvent+java.sun.com&#038;bntl=1"><span class="kw3">MouseEvent</span></a><span class="br0">&#41;</span>:<span class="kw4">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var request:URLRequest=<span class="kw2">new</span> URLRequest<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; request.<span class="me1">url</span>=<span class="st0">&#8216;http://ajax.googleapis.com/ajax/services/language/translate&#8217;</span>+<span class="st0">&#8216;?v=2.0&#8242;</span>+<span class="st0">&#8216;&amp;q=&#8217;</span>+escape<span class="br0">&#40;</span>fromInput.<span class="me1">text</span><span class="br0">&#41;</span>+<span class="st0">&#8216;&amp;langpair=&#8217;</span>+fromLanguageCombo.<span class="me1">selectedItem</span>.<span class="me1">data</span>+<span class="st0">&#8216;%7C&#8217;</span>+toLanguageCombo.<span class="me1">selectedItem</span>.<span class="me1">data</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; request.<span class="me1">method</span> = URLRequestMethod.<span class="me1">GET</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var loader:URLLoader=<span class="kw2">new</span> URLLoader<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">addEventListener</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a>.<span class="me1">COMPLETE</span>,messageSent<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">load</span><span class="br0">&#40;</span>request<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">catch</span> <span class="br0">&#40;</span>error:<a href="http://www.google.com/search?q=allinurl%3AError+java.sun.com&#038;bntl=1"><span class="kw3">Error</span></a><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> function messageSent<span class="br0">&#40;</span>evt:<a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a><span class="br0">&#41;</span>:<span class="kw4">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var loader:URLLoader=URLLoader<span class="br0">&#40;</span>evt.<span class="me1">target</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result:<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> = loader.<span class="me1">data</span> as <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var json_<span class="nu0">1</span>:<a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a> = JSON.<span class="me1">decode</span><span class="br0">&#40;</span>result<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span class="me1">text</span> = json_<span class="nu0">1</span><span class="br0">&#91;</span><span class="st0">&#8220;responseData&#8221;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8220;translatedText&#8221;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translationLabel.<span class="me1">text</span> = fromLanguageCombo.<span class="me1">selectedItem</span>.<span class="me1">label</span> + <span class="st0">&#8221; to &#8220;</span> + toLanguageCombo.<span class="me1">selectedItem</span>.<span class="me1">label</span>+<span class="st0">&#8221; translation&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></div>
</div>
<p>Well there is nothing much in code. Just taking the language values from two combo box list and passing it to the translate api. Then after decoding json that i received from api call, i am displaying on textfield. Anyway please note that translate api has been officialy depracated.</p>
<p>Here is the quote from <a href="http://code.google.com/apis/language/translate/overview.html">API site</a>:</p>
<blockquote><p>Important: The Google Translate API has been officially deprecated as of May 26, 2011. Due to the substantial economic burden caused by extensive abuse, the number of requests you may make per day will be limited and the API will be shut off completely on December 1, 2011. For website translations, we encourage you to use the Google Translate Element.</p></blockquote>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/google-translate-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting Android to remote mysql via PHP and JSON</title>
		<link>http://www.gaanza.com/blog/how-to-mysql/</link>
		<comments>http://www.gaanza.com/blog/how-to-mysql/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 05:22:12 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=881</guid>
		<description><![CDATA[While working on submitting and retrieving global game high scores from a remote database like mysql i learned few things. During start experiment i decided to use PHP to connect to mysql database. What i was trying to do is that i wanted to call php, then php would make a database connection and make [...]]]></description>
			<content:encoded><![CDATA[<p>While working on submitting and retrieving global game high scores from a remote database like mysql i learned few things. During start experiment i decided to use PHP to connect to mysql database. What i was trying to do is that i wanted to call php, then php would make a database connection and make a sql query and retrieve the result, then php would encode that result into JSON format and i would decode this JSON at my android program and display the results. I haven&#8217;t done much PHP before(never actually setup PHP server before <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ). So i came to know this xampp server, so i installed/setup the xampp server(its a php apache server and it comes with mysql also). I am not telling how to setup xampp and create a databse and tables as you can find it in their wiki.</p>
<p>I create a php file, which makes a database connection and makes a query and encodes a result. As i told before i am not familiar to PHP so i wrote this code looking here and there by googling it <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . Code looks like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">&lt;?php</span><br />
<a href="http://www.php.net/mysql_connect"><span class="kw3">mysql_connect</span></a><span class="br0">&#40;</span><span class="st0">&#8220;host&#8221;</span>,<span class="st0">&#8220;username&#8221;</span>,<span class="st0">&#8220;password&#8221;</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/mysql_select_db"><span class="kw3">mysql_select_db</span></a><span class="br0">&#40;</span><span class="st0">&#8220;yourdatabsename&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp;<br />
<span class="re0">$q</span>=<a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="st0">&#8220;SELECT * FROM yourtable&#8221;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$e</span>=<a href="http://www.php.net/mysql_fetch_assoc"><span class="kw3">mysql_fetch_assoc</span></a><span class="br0">&#40;</span><span class="re0">$q</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$output</span><span class="br0">&#91;</span><span class="br0">&#93;</span>=<span class="re0">$e</span>;<br />
&nbsp;<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a><span class="br0">&#40;</span>json_encode<span class="br0">&#40;</span><span class="re0">$output</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;<br />
<a href="http://www.php.net/mysql_close"><span class="kw3">mysql_close</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
<p>Well code is not that hard to understand. You are making a mysql connection by providing credentials. Then you select a databse. Then you execute a query and result is assigned to $q. Next what i seen is that result is in ArrayCollection type (i saw it in xampp console) so i think we are converting it into Array while iterating through collection(I am not quite sure so if u know then please share). Then You are just encoding the result into JSON.</p>
<p>Now lets see how we will decode the JSON at our android program. Code looks like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw4">void</span> parseJSON<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> result = <span class="st0">&#8220;&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> x = <span class="st0">&#8220;&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AInputStream+java.sun.com&#038;bntl=1"><span class="kw3">InputStream</span></a> is=<span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//http post</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ArrayList&lt;NameValuePair&gt; nameValuePairs = <span class="kw2">new</span> ArrayList&lt;NameValuePair&gt;<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpClient httpclient = <span class="kw2">new</span> DefaultHttpClient<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpPost httppost = <span class="kw2">new</span> HttpPost<span class="br0">&#40;</span><span class="st0">&#8220;http://localhost/game_php_testing/android_database.php&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;httppost.<span class="me1">setEntity</span><span class="br0">&#40;</span><span class="kw2">new</span> UrlEncodedFormEntity<span class="br0">&#40;</span>nameValuePairs<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpResponse response = httpclient.<span class="me1">execute</span><span class="br0">&#40;</span>httppost<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpEntity entity = response.<span class="me1">getEntity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is = entity.<span class="me1">getContent</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&#038;bntl=1"><span class="kw3">Exception</span></a> e<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span class="me1">e</span><span class="br0">&#40;</span><span class="st0">&#8220;log_tag&#8221;</span>, <span class="st0">&#8220;Error in http connection &#8220;</span>+e.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//convert response to string</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=allinurl%3ABufferedReader+java.sun.com&#038;bntl=1"><span class="kw3">BufferedReader</span></a> reader = <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3ABufferedReader+java.sun.com&#038;bntl=1"><span class="kw3">BufferedReader</span></a><span class="br0">&#40;</span><span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AInputStreamReader+java.sun.com&#038;bntl=1"><span class="kw3">InputStreamReader</span></a><span class="br0">&#40;</span>is,<span class="st0">&#8220;iso-8859-1&#8243;</span><span class="br0">&#41;</span>,<span class="nu0">8</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StringBuilder sb = <span class="kw2">new</span> StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> line = <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">while</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>line = reader.<span class="me1">readLine</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> != <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sb.<span class="me1">append</span><span class="br0">&#40;</span>line + <span class="st0">&#8220;<span class="es0">\n</span>&#8220;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;is.<span class="me1">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result=sb.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&#038;bntl=1"><span class="kw3">Exception</span></a> e<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span class="me1">e</span><span class="br0">&#40;</span><span class="st0">&#8220;log_tag&#8221;</span>, <span class="st0">&#8220;Error converting result &#8220;</span>+e.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//parse json data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JSONArray jArray = <span class="kw2">new</span> JSONArray<span class="br0">&#40;</span>result<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;jArray.<span class="me1">length</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;i++<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JSONObject json_data = jArray.<span class="me1">getJSONObject</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span class="me1">i</span><span class="br0">&#40;</span><span class="st0">&#8220;log_tag&#8221;</span>,<span class="st0">&#8220;id: &#8220;</span>+json_data.<span class="me1">getString</span><span class="br0">&#40;</span><span class="st0">&#8220;id&#8221;</span><span class="br0">&#41;</span>+<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#8220;, name: &#8220;</span>+json_data.<span class="me1">getString</span><span class="br0">&#40;</span><span class="st0">&#8220;Player_name&#8221;</span><span class="br0">&#41;</span>+<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#8220;, price: &#8220;</span>+json_data.<span class="me1">getDouble</span><span class="br0">&#40;</span><span class="st0">&#8220;score&#8221;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">catch</span><span class="br0">&#40;</span>JSONException e<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.<span class="me1">e</span><span class="br0">&#40;</span><span class="st0">&#8220;log_tag&#8221;</span>, <span class="st0">&#8220;Error parsing data &#8220;</span>+e.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</div>
<p>I faced two problems/exception while connecting to php. PHP was connecting to mysql perfectly as when i run in browser it printed results so there was some issues on my above code which i&#8217;l address here and this is common problems which will be faced by every newcomer to android like me <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . Before that i&#8217;l just explain my php file and localhost path setup. When i installed xampp, in xampp folder there must be folder called htDocs so i have to make a project folder here inside htDocs and inside this project folder will be my php. So my php path would look like this &#8220;/htDocs/game_php_testing/android_database.php&#8221; So when i will make a call to php via &#8220;http://localhost/game_php_testing/android_database.php&#8221;</p>
<p>Now i will address the two problems that i faced.<br />
First, </p>
<blockquote><p>java.net.socketexception -permission denied</p></blockquote>
<p>yes whenever i was trying to call my php i was getting this exception. How did i solved it ??? Well i just provided a permission to internet access at AndroidManifest.xml file. You have to put this permission above <application> tag</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;uses</span>-permission android:<span class="re0">name</span>=<span class="st0">&#8220;android.permission.INTERNET&#8221;</span> <span class="re2">/&gt;</span></span></div>
</div>
<p>Now second Problem, this one is very important.</p>
<blockquote><p>java.net.ConnectException -Connection Refused.</p></blockquote>
<p>Well what i found is that when u call localhost android thinks that u r calling to android emulator itself not the localhost machine. So localhost/127.0.0.1 wouldn&#8217;t work. So i found the solution to that: instead of localhost use <strong>10.0.2.2</strong>, code will be like this:</p>
<div class="codesnip-container" >
<div class="codesnip">HttpPost httppost = <span class="kw2">new</span> HttpPost<span class="br0">&#40;</span><span class="st0">&#8220;http://10.0.2.2/game_php_testing/android_database.php&#8221;</span><span class="br0">&#41;</span>;</div>
</div>
<p>Well problem solved <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . Now i decode the json that i got from php. I am printing the result on LOG. Please see that when i am calling &#8220;<strong>json_data.getString(&#8220;Player_name&#8221;)</strong>&#8220;, Player_name is a column/attribute in my database table and its type is varchar so i used getString() on it.</p>
<p>I hope this post helped you as you may also faced similar problem at first time.</p>
<p>Gracias.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/how-to-mysql/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>papervision optimization: laggy internet explorer browser</title>
		<link>http://www.gaanza.com/blog/papervision/</link>
		<comments>http://www.gaanza.com/blog/papervision/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 14:40:35 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Papervision]]></category>
		<category><![CDATA[3d flash]]></category>
		<category><![CDATA[internet explorer browser]]></category>
		<category><![CDATA[optimize it]]></category>
		<category><![CDATA[shadow cast]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=857</guid>
		<description><![CDATA[I am making a very small 3d game (isometric view) using papervision3d. I needed some dynamic shadow element for some elements. I came across this very wonderful class that does the shadow casting from here. So I used ShadowCaster class to cast my shadows of my displayobject3d. I would need this following things for my [...]]]></description>
			<content:encoded><![CDATA[<p>I am making a very small 3d game (isometric view) using papervision3d. I needed some dynamic shadow element for some elements. I came across this very wonderful <a title="Shadowcaster.as" href="http://blog.zupko.info/?p=146" target="_blank">class</a> that does the shadow casting from <a href="http://blog.zupko.info/?p=146" target="_blank">here</a>. So I used ShadowCaster class to cast my shadows of my displayobject3d. I would need this following things for my purpose:<br />
1)      A do3d, target object whose shadow has to be created/rendered<br />
2)      A light source<br />
3)      A plane at which shadow would fall/render.<br />
4)      And of course our ShadowCaster class <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>So i started playing with the shadowcaster class to get my hands dirty. I was trying to cast shadows of 4 plane on another surface plane. I created a light source. So here is how i was casting shadow with the code:</p>
<div class="codesnip-container" >
<div class="codesnip">var blurr:BlurFilter = <span class="kw2">new</span> BlurFilter<span class="br0">&#40;</span><span class="nu0">10</span>, <span class="nu0">10</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;</p>
<p>shadowCaster_one = <span class="kw2">new</span> ShadowCaster<span class="br0">&#40;</span><span class="st0">&#8220;plane1_shadow&#8221;</span>, 0&#215;000000, BlendMode.<span class="me1">MULTIPLY</span>, <span class="nu0">0</span>.<span class="nu0">3</span>, <span class="br0">&#91;</span>blurr<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
shadowCaster_one.<span class="me1">setType</span><span class="br0">&#40;</span>ShadowCaster.<span class="me1">SPOTLIGHT</span><span class="br0">&#41;</span>;</p>
<p>shadowCaster_two = <span class="kw2">new</span> ShadowCaster<span class="br0">&#40;</span><span class="st0">&#8220;plane2_shadow&#8221;</span>, 0&#215;000000, BlendMode.<span class="me1">MULTIPLY</span>, <span class="nu0">1</span>, <span class="br0">&#91;</span>blurr<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
shadowCaster_two.<span class="me1">setType</span><span class="br0">&#40;</span>ShadowCaster.<span class="me1">DIRECTIONAL</span><span class="br0">&#41;</span>;</p>
<p>shadowCaster_three = <span class="kw2">new</span> ShadowCaster<span class="br0">&#40;</span><span class="st0">&#8220;plane3_shadow&#8221;</span>, 0&#215;000000, BlendMode.<span class="me1">MULTIPLY</span>, <span class="nu0">0</span>.<span class="nu0">3</span>, <span class="br0">&#91;</span>blurr<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
shadowCaster_three.<span class="me1">setType</span><span class="br0">&#40;</span>ShadowCaster.<span class="me1">SPOTLIGHT</span><span class="br0">&#41;</span>;</p>
<p>shadowCaster_four = <span class="kw2">new</span> ShadowCaster<span class="br0">&#40;</span><span class="st0">&#8220;plane4_shadow&#8221;</span>, 0&#215;000000, BlendMode.<span class="me1">MULTIPLY</span>, <span class="nu0">1</span>, <span class="br0">&#91;</span>blurr<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
shadowCaster_four.<span class="me1">setType</span><span class="br0">&#40;</span>ShadowCaster.<span class="me1">DIRECTIONAL</span><span class="br0">&#41;</span>;</div>
</div>
<p>Above I created 4 separate shadowcaster to cast on 4 separate plane.</p>
<div class="codesnip-container" >
<div class="codesnip">override <span class="kw2">protected</span> function onRenderTick<span class="br0">&#40;</span>event:<a href="http://www.google.com/search?q=allinurl%3AEvent+java.sun.com&#038;bntl=1"><span class="kw3">Event</span></a> = <span class="kw2">null</span><span class="br0">&#41;</span>:<span class="kw4">void</span><br />
<span class="br0">&#123;</span><br />
super.<span class="me1">onRenderTick</span><span class="br0">&#40;</span>event<span class="br0">&#41;</span>;</p>
<p>shadowCaster_one.<span class="me1">invalidate</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
shadowCaster_two.<span class="me1">invalidate</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
shadowCaster_three.<span class="me1">invalidate</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
shadowCaster_four.<span class="me1">invalidate</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>shadowCaster_one.<span class="me1">castModel</span><span class="br0">&#40;</span>plane1, light, shadowPlane<span class="br0">&#41;</span>;<br />
shadowCaster_two.<span class="me1">castModel</span><span class="br0">&#40;</span>plane2, light, shadowPlane<span class="br0">&#41;</span>;<br />
shadowCaster_three.<span class="me1">castModel</span><span class="br0">&#40;</span>plane3, light, shadowPlane<span class="br0">&#41;</span>;<br />
shadowCaster_four.<span class="me1">castModel</span><span class="br0">&#40;</span>plane4, light, shadowPlane<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Above I am rendering four shadows of four separate planes. I am rendering them on onRenderTick. Now its time to test it in browser.<br />
1) Google chrome browser: Smooth run<br />
2) Firefox: smooth run<br />
3) Safari: smooth run<br />
4) Opera: smooth run<br />
5) Internet Explorer: FPS:1~0 (very very very very lag)</p>
<p>Yes there was very massive frame rate drop on internet explorer, interactive response was almost none.  All other browser ran the game smoothly. Only one thing came to my mind:” Internet Explorer sucks”, but i knew that i had to optimize my code and for that i had to find the code that was consuming so much memory resource. My first suspect was shadow casting code at onRenderTick(), so i commented all shadow casting line and ran it again in internet explorer and yeah you guessed it correct that it ran smoothly. But i had to cast the shadows so i need to optimize this part. So i did some alteration:</p>
<p>First instead of adding those 4 planes directly to scene, i added them to one do3d.</p>
<div class="codesnip-container" >
<div class="codesnip">shadowObjectContainer.<span class="me1">add</span><span class="br0">&#40;</span>plane1<span class="br0">&#41;</span>;<br />
shadowObjectContainer.<span class="me1">add</span><span class="br0">&#40;</span>plane2<span class="br0">&#41;</span>;<br />
shadowObjectContainer.<span class="me1">add</span><span class="br0">&#40;</span>plane3<span class="br0">&#41;</span>;<br />
shadowObjectContainer.<span class="me1">add</span><span class="br0">&#40;</span>plane4<span class="br0">&#41;</span>;</div>
</div>
<p>Second, instead of creating 4 shadow caster, i created only one caster that would cast onto displayobject3d which has four planes as its children.</p>
<div class="codesnip-container" >
<div class="codesnip">shadowCaster = <span class="kw2">new</span> ShadowCaster<span class="br0">&#40;</span><span class="st0">&#8220;plane4_shadow&#8221;</span>, 0&#215;000000, BlendMode.<span class="me1">MULTIPLY</span>, <span class="nu0">1</span>, <span class="br0">&#91;</span>blurr<span class="br0">&#93;</span><span class="br0">&#41;</span>;</p>
<p>shadowCaster.<span class="me1">setType</span><span class="br0">&#40;</span>ShadowCaster.<span class="me1">DIRECTIONAL</span><span class="br0">&#41;</span>;</div>
</div>
<p>Then cast and render the shadow:</p>
<div class="codesnip-container" >
<div class="codesnip">shadowCaster.<span class="me1">invalidate</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
shadowCaster.<span class="me1">castModel</span><span class="br0">&#40;</span>shadowObjectContainer, light, shadowPlane<span class="br0">&#41;</span>;</div>
</div>
<p><strong>This really optimized the performance and frame rate on internet explorer went up.</strong></p>
<p>I am not claiming that this is the way to write. I am just sharing what i just faced and how i tackled it. I am still working on more better approach for optimization of my code and objective. But still i would say internet explorer sucks as only this browser showed massive drop on fps rate without any optimized code <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . But yeah i know writing efficient code makes life easier <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/papervision/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chrome to phone</title>
		<link>http://www.gaanza.com/blog/chrome-to-phone/</link>
		<comments>http://www.gaanza.com/blog/chrome-to-phone/#comments</comments>
		<pubDate>Thu, 26 May 2011 14:10:06 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[apk]]></category>
		<category><![CDATA[Apps]]></category>
		<category><![CDATA[Chrome]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=844</guid>
		<description><![CDATA[Well i have been using chrome to phone extension on my android 2.2.2, and its so magic and useful in my daily life. Anyway Chrome to Phone app is available on android market. But in some countries it is not available. In my country it wasn&#8217;t available in market so i found the apk file [...]]]></description>
			<content:encoded><![CDATA[<p>Well i have been using chrome to phone extension on my android 2.2.2, and its so magic and useful in my daily life. Anyway <strong>Chrome to Phone</strong> app is available on android market. But in some countries it is not available. In my country it wasn&#8217;t available in market so i found the apk file of <strong>google chrome to phone</strong> in some website forum that i don&#8217;t remember. So if u want to download and install this app on your android then scan this link:<a href="http://www.gaanza.com/wp-content/uploads/2011/05/gaanza.com_d_QR_Droid.png"><img src="http://www.gaanza.com/wp-content/uploads/2011/05/gaanza.com_d_QR_Droid.png" alt="google chrome to phone" title="gaanza.com_d_QR_Droid" width="288" height="288" class="aligncenter size-full wp-image-845" /></a></p>
<p><strong>The App version is 2.2.0</strong></p>
<p>I installed the extension plugin for my chrome browser from <a href="https://chrome.google.com/webstore/detail/oadboiipflhobonjjffjbfekfjcgkhco">chrome web store</a>. Here is the video on installing and using and what its all about:<br />
<iframe width="560" height="349" src="http://www.youtube.com/embed/pQb243niMlg" frameborder="0" allowfullscreen></iframe></p>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/chrome-to-phone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

