A friend of mine claimed about a year ago that he was in talks with the top honchos at Cafe Coffee Day, a hep coffee shop, to open a branch in Kharagpur. I found it hard to believe then. Not my friend's reach, no, but the idea that an urban phenomenon such as CCD could possibly work in the bucolic shit-hole that is Kharagpur. I stand corrected. CCD opened in my campus a few days ago and has already attracted a large crowd (mostly of the Page 3 variety). The fact of the matter is that the spending capacity of the modern Indian youth has increased. As our values become more westernized, our attitudes towards living a frugal life, consuming food items not traditionally considered healthy or "Indian" , change.
Now if that is a good or a bad thing is something that I will not touch upon, because honestly, I do not know. What I do know is that CCD will probably do good business, and may encourage investors to create franchises of other famous food brands like McDonalds and KFC. Generally these fast-food joints are located on or near prime real-estate. Thus, one of the major contributors to their costs are establishment and rent charges. Leasing land in Kharagpur on the other hand is relatively inexpensive. Add to it the fact that at present a lot of land in the IIT campus is not utilized. Hence the costs saved there can be passed on directly to the students. Its a win-win situation!
On a more technical note, I have been working with the Android API recently and I frankly, do not like it much. Sure its much better than the Symbian platform, but I cannot compare it with the IPhone as I have not really used it. The Android API is in a constant state of flux and Google keeps adding and removing stuff. Its not the adding I am concerned about, but the removing irritates me. Many important utility functions pertaining to text encoding have not been implemented which means writing a serious HTTP client is a major pain in the backside.
And of course, code breaks. When a method or class is deprecated it can have an adverse impact on your application if it depends on that method/class. Generally it means that you have to rewrite certain parts to make use of the new replacement. Occasionally it can mean having to completely rethink and reimplement the application logic in the framework provided by the new
API.
I have been experimenting a bit with REST based APIs recently and thought of incorporating a twitter client into SMS Invite. Here is the skeleton code that I came up with. Enjoy!
package com.android.test.webstuff;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.net.URLEncoder;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.ByteArrayBuffer;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloActivity extends Activity {
TextView tv;
String text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tv = new TextView(this);
postData();
setContentView(tv);
}
public void postData(){
String Username = "myusername";
String Password = "mypassword";
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.twitter.com/statuses/update.xml");
httpclient.getParams().setBooleanParameter("http.protocol.expect-continue", false);
try {
// Add your data
List
nameValuePairs = new ArrayList(1);
nameValuePairs.add(new BasicNameValuePair("status", "test"));
/.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.addHeader("Authorization", "Basic "+Base64.encodeBytes((Username+":"+Password).getBytes()));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
InputStream is = response.getEntity().getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
/* Convert the Bytes read to a String. */
text = new String(baf.toByteArray());
tv.setText(text);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
PS: The Base64 routine converts a byte array of characters to its Base 64 encoding. Its a bit long so I have not posted that.