Author Archive

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 on my device. So its not a big deal to use an intent and i used android.content.Intent.ACTION_SEND and i got the options. But i didn’t just got email clients but also other communication app like text message, dropbox, facebook, twitter etc. That i didn’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’l show my code that i used before:

String[] recipients = new String[]{“sendme@me.com”, “”};
Intent testIntent = new Intent(android.content.Intent.ACTION_SEND);
testIntent.setType(“text/plain”);
testIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, “blah blah subject”);
testIntent.putExtra(android.content.Intent.EXTRA_TEXT, “blah blah body message”);
testIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
startActivity(testIntent);

Well the above code doesn’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 (“text/plain”) to (“text/email”).

testIntent.setType(“text/email”);

Well it did filter some apps but still not perfect because it still showed some apps like andFTP, dropbox, google docs etc.
Now i had to do some serious research, i asked in forum but didn’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 :P

Solution 1:
just change setType to “message/rfc822″. Yes this works but with very minor flaw. It filtered out all communicatio app exept one, i.e andFTP yeah it didn’t filtered out andFTP and this ruined it. But it filtered out others and showed only email clients.

String[] recipients = new String[]{“sendme@me.com”, “”};
Intent testIntent = new Intent(android.content.Intent.ACTION_SEND);
testIntent.setType(“message/rfc822″);
testIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, “blah blah subject”);
testIntent.putExtra(android.content.Intent.EXTRA_TEXT, “blah blah body message”);
testIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
startActivity(testIntent);

Now Solution 2, which worked perfectly for me. here you don’t use android.content.Intent.ACTION_SEND but Intent.ACTION_VIEW

Intent testIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse(“mailto:?subject=” + “blah blah subject” + “&body=” + “blah blah body” + “&to=” + “sendme@me.com”);
testIntent.setData(data);
startActivity(testIntent);

filtering non email client programs


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.

Gracias.

Dude where is my javascript ?

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 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’t rendered fully and i was again left scratching my head :D . 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:

webView.getSettings().setJavaScriptEnabled(true);

and yeah u guessed it right, it rendered fully after calling that method. So i guess by default javascript is disabled on webview. Phew.

Gracias.

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’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:

DummyClass{

dummyMethod(){
Intent dummyIntent = new Intent(DummyClass.this, MeActivity.class);
this.startActivity(dummyIntent);
}

}

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:

public class MeActivity extends Activity{
     public static Context meActivityContext;
     public FavoritesActivity(){
         MeActivity.meActivityContext=this;
     }
}

So that was it. Now i used this context variable to start my activity from non-activity class.

DummyClass{

dummyMethod(){
     Intent dummyIntent = new Intent(MeActivity.meActivityContext, MeActivity.class);
     MeActivity.meActivityContext.startActivity(dummyIntent);
}

}

well that worked for me, hope it works for you too.

Gracias.

Hide soft keyboard: Android

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:

InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);                              inputManager.hideSoftInputFromWindow(Test.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

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’t happened with EditText. But whenever i had autocompletetextview soft keyboard appears automatically. I didn’t wanted this. Instead i wanted soft keyboard to appear only when i touch AutoCompleteTextView. But i found a simple solution for this:

<activity android:name=“.MyActivity”
                        android:windowSoftInputMode=“stateAlwaysHidden”>

yeah just add android:windowSoftInputMode=”stateAlwaysHidden” 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.

Gracias

world.CreateBody() creating NULL ??

I was doing some test stuff for a game that uses Box 2D flash. I found and learned a thing that i didn’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’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’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.

Gracias

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:

1) PHP

<?php
mysql_connect(“localhost”,“root”,“”);
mysql_select_db(“dalalstreet”);
 
$st = $_REQUEST[‘st’];

$q= mysql_query(“SELECT * FROM world WHERE company LIKE ‘%”.$st.“%’”);

while($e = mysql_fetch_assoc($q))
        $output[]=$e;
 
print(json_encode($output));
 
mysql_close();
?>

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.

2) Main.xml (my layout)
Here is the xml layout file for my ui.

<?xml version=“1.0″ encoding=“utf-8″?>
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
    android:orientation=“vertical”
    android:layout_width=“fill_parent”
    android:layout_height=“fill_parent”
    >

<TextView 
    android:layout_width=“wrap_content”
    android:layout_height=“wrap_content”
    android:text=“@string/country_label”
    />

<CustomAutoCompleteView
        android:id=“@+id/autoCompleteCountry”
        android:layout_width=“fill_parent”
        android:layout_height=“wrap_content” />

</LinearLayout>

3) Main Activity class
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.

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;

public class AutoComptest extends Activity {
   
        private CustomAutoCompleteView autoComplete;        
        
        private ArrayAdapter<String> autoCompleteAdapter;
       
        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        autoCompleteAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
        autoCompleteAdapter.setNotifyOnChange(true); // This is so I don’t have to manually sync whenever changed 
        autoComplete = (CustomAutoCompleteView)  findViewById(R.id.autoCompleteCountry);
        autoComplete.setHint(“Country”);
        autoComplete.setThreshold(3);
        autoComplete.setAdapter(autoCompleteAdapter);
       
        autoComplete.addTextChangedListener(textChecker);
       
    }
   
    final TextWatcher textChecker = new TextWatcher() {
        public void afterTextChanged(Editable s) {}
 
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
 
        public void onTextChanged(CharSequence s, int start, int before, int count)
        {
                   
                autoCompleteAdapter.clear();
               
                callPHP();
                               
        }     
    };
   
    private void callPHP(){
        String result = “”;        
        InputStream is=null;       
        try{
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair(“st”,autoComplete.getText().toString()));
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(“http://10.0.2.2/gaanza_android/android_database.php”);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
        }catch(Exception e){
                Log.e(“log_tag”, “Error in http connection “+e.toString());
        }
       
        try{                        
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,“iso-8859-1″),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {                                   
                            sb.append(line + \n);
                }
                is.close();
        
                result=sb.toString();          
        }catch(Exception e){
                Log.e(“log_tag”, “Error converting result “+e.toString());
        }
       
        //parse json data
        try{
                JSONArray jArray = new JSONArray(result);
                for(int i=0;i<jArray.length();i++){
                        JSONObject json_data = jArray.getJSONObject(i);                               
                      
                        autoCompleteAdapter.add(json_data.getString(“country”));
                }
        }
        catch(JSONException e){
                Log.e(“log_tag”, “Error parsing data “+e.toString());
        }
    }
}

Note: remember “http://10.0.2.2/” in my last post. 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.

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 :D , 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:

afterTextChanged(Editable s)
beforeTextChanged(CharSequence c, int start, int count, int after)
onTextChanged(CharSequence c, int start, int before, int count)

Best way to understand them is going through the document here. 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.

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.

There was still one very minor problem and i solved it with my another very stupid solution :P 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.

4) CustomAutoCompleteView which extends AutoCompletetextView

public class CustomAutoCompleteView extends AutoCompleteTextView {
       
        public CustomAutoCompleteView(Context context) {
                super(context);
                // TODO Auto-generated constructor stub
        }

        public CustomAutoCompleteView(Context context, AttributeSet attrs) {
                super(context, attrs);
                // TODO Auto-generated constructor stub
        }

        public CustomAutoCompleteView(Context context, AttributeSet attrs,
                        int defStyle) {
                super(context, attrs, defStyle);
                // TODO Auto-generated constructor stub
        }
       
        @Override
        protected void performFiltering(final CharSequence text, final int keyCode) {
                String filterText = “”;
                super.performFiltering(filterText, keyCode);
        }
    /**
    * After a selection, capture the new value and append to the existing
    * text
    */

    @Override
    protected void replaceText(final CharSequence text) {
        super.replaceText(text);
    }

}

How to remove the filter on an ArrayAdapter used in an AutoCompleteTextView? 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 :D . I defined a filter which filters all suggestion based on “” yeah a blank string :D . But this works like a charm. Just try it.

So now your are getting results suggestion from database dynamically to AutoCompleteTextView.

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.

Gracias

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.


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.

The main crucial part:

‘http://ajax.googleapis.com/ajax/services/language/translate’+'?v=2.0′+’&q=’+escape(my_input)+’&langpair=’+'es’+'%7C’+'en’

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.
Note: escape method is used to encode the string to url encoded format

Here is the source code:

package
{
        import com.adobe.serialization.json.JSON;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        import flash.net.URLRequestMethod;
        import flash.net.URLVariables;
        import fl.data.DataProvider;
       
        /**
         * …
         * @author padam
         */

        public class Main extends Sprite
        {
               
                public function Main():void
                {
                        if (stage) init();
                        else addEventListener(Event.ADDED_TO_STAGE, init);
                }
               
                private function init(e:Event = null):void
                {
                        removeEventListener(Event.ADDED_TO_STAGE, init);
                        // entry point
                       
                        initGUI();
                        button_p.addEventListener(MouseEvent.CLICK, translate);
                }
               
                private function initGUI():void {
                        var itemsFrom:Array = [
                        {label:“English”, data:“en”},
                        {label:“Spanish”, data:“es”},
                        {label:“French”, data:“fr”},
                        {label:“Italian”, data:“it”}
                        ];
                       
                        var itemsTo:Array = [
                        {label:“Hindi”, data:“hi”},
                        {label:“English”, data:“en”},
                        {label:“Spanish”, data:“es”},
                        {label:“French”, data:“fr”},
                        {label:“Italian”, data:“it” }
                        ];
                       
                        fromLanguageCombo.prompt = “Select Language”;
                        fromLanguageCombo.dataProvider = new DataProvider(itemsFrom);
                        toLanguageCombo.dataProvider = new DataProvider(itemsTo);
                       
                }
               
                private function translate(event:MouseEvent):void {
                        var request:URLRequest=new URLRequest();
                        request.url=‘http://ajax.googleapis.com/ajax/services/language/translate’+‘?v=2.0′+‘&q=’+escape(fromInput.text)+‘&langpair=’+fromLanguageCombo.selectedItem.data+‘%7C’+toLanguageCombo.selectedItem.data;
                        request.method = URLRequestMethod.GET;
                       
                        var loader:URLLoader=new URLLoader();
                        loader.addEventListener(Event.COMPLETE,messageSent);
                        try
                        {
                                loader.load(request);
                        }
                        catch (error:Error)
                        {
                               
                        }
                }
               
                private function messageSent(evt:Event):void
                {
                        var loader:URLLoader=URLLoader(evt.target);
                        var result:String = loader.data as String;
                       
                        var json_1:Object = JSON.decode(result);
                        output.text = json_1[“responseData”][“translatedText”];
                        translationLabel.text = fromLanguageCombo.selectedItem.label + ” to “ + toLanguageCombo.selectedItem.label+” translation”;
               
                }
               
        }
       
}

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.

Here is the quote from API site:

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.

Gracias.

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’t done much PHP before(never actually setup PHP server before :D ). 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.

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 :D . Code looks like this:

<?php
mysql_connect(“host”,“username”,“password”);
mysql_select_db(“yourdatabsename”);
 
$q=mysql_query(“SELECT * FROM yourtable”);
while($e=mysql_fetch_assoc($q))
        $output[]=$e;
 
print(json_encode($output));
 
mysql_close();
?>

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.

Now lets see how we will decode the JSON at our android program. Code looks like this:

void parseJSON()
    {
       
        String result = “”;
        String x = “”;
        InputStream is=null;
        //http post
        try{
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(“http://localhost/game_php_testing/android_database.php”);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
        }catch(Exception e){
                Log.e(“log_tag”, “Error in http connection “+e.toString());
        }
        //convert response to string
        try{
                
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,“iso-8859-1″),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + \n);
                }
                is.close();
        
                result=sb.toString();
                
        }catch(Exception e){
                Log.e(“log_tag”, “Error converting result “+e.toString());
        }
        
        //parse json data
        try{
                JSONArray jArray = new JSONArray(result);
                for(int i=0;i<jArray.length();i++){
                        JSONObject json_data = jArray.getJSONObject(i);                                    
                        
                        Log.i(“log_tag”,“id: “+json_data.getString(“id”)+
                                “, name: “+json_data.getString(“Player_name”)+
                                “, price: “+json_data.getDouble(“score”)
                        );
                }
                
        }
        catch(JSONException e){
                Log.e(“log_tag”, “Error parsing data “+e.toString());
        }
    }

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’l address here and this is common problems which will be faced by every newcomer to android like me :D . Before that i’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 “/htDocs/game_php_testing/android_database.php” So when i will make a call to php via “http://localhost/game_php_testing/android_database.php”

Now i will address the two problems that i faced.
First,

java.net.socketexception -permission denied

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 tag

<uses-permission android:name=“android.permission.INTERNET” />

Now second Problem, this one is very important.

java.net.ConnectException -Connection Refused.

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’t work. So i found the solution to that: instead of localhost use 10.0.2.2, code will be like this:

HttpPost httppost = new HttpPost(“http://10.0.2.2/game_php_testing/android_database.php”);

Well problem solved :D . Now i decode the json that i got from php. I am printing the result on LOG. Please see that when i am calling “json_data.getString(“Player_name”)“, Player_name is a column/attribute in my database table and its type is varchar so i used getString() on it.

I hope this post helped you as you may also faced similar problem at first time.

Gracias.

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 purpose:
1) A do3d, target object whose shadow has to be created/rendered
2) A light source
3) A plane at which shadow would fall/render.
4) And of course our ShadowCaster class :D

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:

var blurr:BlurFilter = new BlurFilter(10, 10, 1);

shadowCaster_one = new ShadowCaster(“plane1_shadow”, 0×000000, BlendMode.MULTIPLY, 0.3, [blurr]);
shadowCaster_one.setType(ShadowCaster.SPOTLIGHT);

shadowCaster_two = new ShadowCaster(“plane2_shadow”, 0×000000, BlendMode.MULTIPLY, 1, [blurr]);
shadowCaster_two.setType(ShadowCaster.DIRECTIONAL);

shadowCaster_three = new ShadowCaster(“plane3_shadow”, 0×000000, BlendMode.MULTIPLY, 0.3, [blurr]);
shadowCaster_three.setType(ShadowCaster.SPOTLIGHT);

shadowCaster_four = new ShadowCaster(“plane4_shadow”, 0×000000, BlendMode.MULTIPLY, 1, [blurr]);
shadowCaster_four.setType(ShadowCaster.DIRECTIONAL);

Above I created 4 separate shadowcaster to cast on 4 separate plane.

override protected function onRenderTick(event:Event = null):void
{
super.onRenderTick(event);

shadowCaster_one.invalidate();
shadowCaster_two.invalidate();
shadowCaster_three.invalidate();
shadowCaster_four.invalidate();

shadowCaster_one.castModel(plane1, light, shadowPlane);
shadowCaster_two.castModel(plane2, light, shadowPlane);
shadowCaster_three.castModel(plane3, light, shadowPlane);
shadowCaster_four.castModel(plane4, light, shadowPlane);
}

Above I am rendering four shadows of four separate planes. I am rendering them on onRenderTick. Now its time to test it in browser.
1) Google chrome browser: Smooth run
2) Firefox: smooth run
3) Safari: smooth run
4) Opera: smooth run
5) Internet Explorer: FPS:1~0 (very very very very lag)

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:

First instead of adding those 4 planes directly to scene, i added them to one do3d.

shadowObjectContainer.add(plane1);
shadowObjectContainer.add(plane2);
shadowObjectContainer.add(plane3);
shadowObjectContainer.add(plane4);

Second, instead of creating 4 shadow caster, i created only one caster that would cast onto displayobject3d which has four planes as its children.

shadowCaster = new ShadowCaster(“plane4_shadow”, 0×000000, BlendMode.MULTIPLY, 1, [blurr]);

shadowCaster.setType(ShadowCaster.DIRECTIONAL);

Then cast and render the shadow:

shadowCaster.invalidate();
shadowCaster.castModel(shadowObjectContainer, light, shadowPlane);

This really optimized the performance and frame rate on internet explorer went up.

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 :D . But yeah i know writing efficient code makes life easier :P

Gracias.

Chrome to phone

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’t available in market so i found the apk file of google chrome to phone in some website forum that i don’t remember. So if u want to download and install this app on your android then scan this link:google chrome to phone

The App version is 2.2.0

I installed the extension plugin for my chrome browser from chrome web store. Here is the video on installing and using and what its all about:

Gracias.