Android: Simple Class For Easy Writing And Reading SharedPreferences String Value

SharedPreferences is used to store small configurations or settings data in your Android application. For example, as username or user preferences data storage. Just like variables, shared preferences can be identified by “key” string as “variable” name. Shared preferences are relatives to application. So it can not be accessed by other application directly. In the following example, I would like to store the username of logged in user so in Continue reading Android: Simple Class For Easy Writing And Reading SharedPreferences String Value

Thread in Android: An Example

StrictMode is most commonly used to catch accidental disk or network access on the application’s main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application’s main thread (UI thread) responsive, you also prevent ANR (Application Not Responding) dialogs from being shown to users. Network requests being made on UI thread may Continue reading Thread in Android: An Example

Communicating PHP with Android Java using JSON

When you have several variables (data) which you would send to Android using regular text on HTTP, then JSON would become an alternative format to XML. Android has it’s own JSON parser class which able to convert text on JSON format into a JSON Object. Since version 5.2.0, PHP has it’s built in json_encode() and json_decode() function to convert an array into json string and vice versa.

Set Background Color of Android View Programmatically

While you are generating or displaying content through list views, it is sometimes you need to make a zebra-styled rows or coloring the view of row background into a custom color depending on row’s content. This snippets is applicable to any android view which is inheriting View class. So to change or modify view’s background color, it is as easy as the following code on your activity class: View v Continue reading Set Background Color of Android View Programmatically

Android REST: HTTP GET Example

In developing a mobile application on Google Android platform often requires client-server communications. The communication itself often uses TCP/IP protocol on port 80 (HTTP) to represent a client state to a (service) server. This communication style often known as Representational State Transfer (REST). REST is a style of software architecture for distributed systems such as the World Wide Web. REST has emerged as a predominant Web service design model (wikipedia). If REST implemented in HTTP, it is often called Continue reading Android REST: HTTP GET Example

Inflate Android Layout Using Layout Inflater Service

Below is a small snippet in Android Java code to inflate a layout xml file into as a View using a Layout Inflater Service. Very useful if you intend to insert or include (inflate) any layout into another layout during runtime. AbsoluteLayout mainLayout = (AbsoluteLayout) findViewById(R.id.your_main_layout); LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View menuLayout = inflater.inflate(R.layout.your_menu_layout, mainLayout, true); Assuming that your current activity has an AbsoluteLayout container named mainLayout in which a Continue reading Inflate Android Layout Using Layout Inflater Service

Responsive Web Design

“Responsive Web Design” or RWD or a hashtag #rwd on Twitter has become a great plague in web design just like AJAX technologies which arise a few years ago. Almost all people uses AJAX to run their website. Nowadays, people are talking Responsive Web Design rather than CSS3 media queries technology like people are talking jQuery rather than the AJAX technologies itself. What is Reponsive Web Design? Responsive web design (often Continue reading Responsive Web Design

Sorting Array of Objects using Ruby and Python

From my previous post, I had explained on how to sort an array consists of objects by object’s attribute using PHP. While on PHP sorting by object’s attribute requires additional function other than sorting itself, Ruby and Python has it’s own array of object sorting syntax. For example in Ruby, the following one line syntax will sort an array named population by comparing it’s objects length property (attribute) ascendingly without Continue reading Sorting Array of Objects using Ruby and Python

Sorting Array of Objects Using PHP

Consider you have an array or list of objects and wanted to sort it based on one attribute of objects. If the array consists of integer, it is very easy to sort it ascendingly using sort() function, otherwise if the array consists of objects, you have to create custom sorting function which is passed to the PHP usort() function. Here is an example on how to manually sort array of Continue reading Sorting Array of Objects Using PHP

Hello, Ruby!

Ruby was come preinstalled on Mac OS X Mountain Lion, so for you who want to develop application using Ruby this one will come in handy. To check the Ruby version installed on your Mac, fire up the Terminal, and type: ruby -v For other OSes please refer to this article in downloading and installing Ruby on Mac, Linux, and Windows.