Showing posts from June, 2014

Rotate Animation to ImageView

Rotate the image at center axis, by using Rotate Animation.

RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
        anim.setInterpolator(new LinearInterpolator());

and set into image like this


ActionBar Compatibility in lower version

Using ActionBar in lower version of android is big task for developers. Action bar is not compatible in API level 9. Action bar is supporting from HoneyComb version. If developers want to action bar is lower versions, Use the sherlock library. That's best way.

Sherlock Library

Change the font of ActionBar title

Change the font of ActionBar title using SpannableString.

Just follow the code.

SpannableString s = new SpannableString("It's a new font");
s.setSpan(new TypefaceSpan(this, "arial.ttf"), 0, s.length(),

Back Navigation in action bar

Sometimes most of developers now using ActionBar. They need to navigate button on top, if they need just add few lines in the code.



public boolean onOptionsItemSelected(MenuItem item) {
// Take appropriate action for each action item click
switch (item.getItemId()) {
return true;
return super.onOptionsItemSelected(item);

Using Color HEX codes in android

This is transparent level codes of hex codes.

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00

If you provide 6 hex digits, that means RGB (2 hex digits for each value of red, green and blue).

If you provide 8 hex digits, it's an ARGB (2 hex digits for each value of alpha, red, green and blue respectively).

So actually you're changing from R=B4, G=55, B=55 to A=B5, R=55, G=55, B=55 which is why it's a mostly-transparent grey colour.

if you want to some transparent level of color using in layout or widgets, just use like that

Current Weather Demo

I'm so happy today, because today is my first web based application released in google play. previously i'm developed the some web based applications, but that's not in google play or any public markets. all are third party usage applications. Now it's time to move some small steps.

Current Weather Demo

Get the Current Weather Status by City ID and City Name

Before that, just signup and get the APPID from

Get the City ID and City name information from

This is just a demo application, soon release the full functionality app.

You can download the source from Github

Download the App from Google Play

Disable Predictable Text in EditText

In EditText, if you want to set the filter,


Check the connectivity status in android

Many of web based applications, check the internet connections, before done the web services.

You can set the permission for network state, like this

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


public boolean networkAvailability() {
ConnectivityManager connectivity = (ConnectivityManager) context
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;

return false;

Add Degree symbol in java

In java based applications, if you can add the degree symbol in your applications. Just add "\u00b0".


String Celsius= "35 \u00b0 C";


Convert the Kelvin into celsius

celsius= kelvin-273.15;

subtract 273.15 from kelvin value, you got the celsius value.

public String kevinToCelsius(String kelvin) {
double kel, celsius;
kel = Double.parseDouble(kelvin);
celsius = kel - 273.15;
return String.valueOf(celsius).substring(0, 4);

Change the Unix timestamp into date format

It's very interesting. Sometimes you got the result as unix timestamp from any backend apis or some results. It's simple method to convert the unix timestamp into date format.

// Unix timestamp into time format
public String getDateFormat(String dateformat) {
long dt = Long.parseLong(dateformat);
Date date = new Date(dt * 1000L); // *1000 is to convert seconds to
// milliseconds
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); // the
String formattedDate = sdf.format(date);
return formattedDate;

Slide Navigation

Slide Navigation

Most of new android applications uses the slide navigation. you can do left to right and right to left slide navigations. Like an gmail or facebook app.

I develop the slide navigation app demo.
Click Here to download from Google Play
Also you can get the source from GitHub
App and Source include the Colored ListView, Numbers to Words, Coloring textview examples..

Change the TextView color Continuosly using UIThread

Have a nice day. Now i write the code for changing the textview continuosly using UIThread.

Just try out.

handler = new Handler();
new Thread(new Runnable() {

public void run() {
final int totalCount=1000;
// TODO Auto-generated method stub
for(int i=0;i<totalCount;i++){
try {
runOnUiThread(new Runnable() {
                       public void run() {                        
Random r = new Random();
r.nextInt(256), r.nextInt(256)));                          

} catch (InterruptedException e) {
// TODO Auto-generated catch block


Textview is continuously changing the textcolor. I'm set the 1000 milliseconds (1 Second).

Set other font to textview

To set the other fonts into textview, using Typeface.

Copy the fonts into assets folder,

Typeface type = Typeface.createFromAsset(getAssets(),"fonts/consolas.ttf");


Copy the Database into SDCARD

To copy the Database into SDCARD, you can use following code to do that,

InputStream myInput = new FileInputStream("/data/data/pack_name/databases/databasename.db");

File directory = new File("/sdcard/some_folder");
if (!directory.exists()) {

OutputStream myOutput = new FileOutputStream(directory.getPath() + "/AppName.backup");

byte[] buffer = new byte[1024];
int length;
while ((length = > 0) {
    myOutput.write(buffer, 0, length);


Creating the Database in SDCARD

public class MyDataBase extends SQLiteOpenHelper {

    MyDataBase (final Context context) {        super(context, Environment.getExternalStorageDirectory()
                + File.separator + "/DataBase/" + File.separator
                + DATABASE_NAME, null, DATABASE_VERSION);

Set the permission for READ and WRITE ACCESS.
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Creating or Formatting the JSON.

JSON - JavaScript Object Notation is lightweight interchange format. JSON is more comfortable than XML. Also fast than the parsing. Most of web services is achieved through this JSON.

Some peoples are struggling to create and formatting the JSON strings and arrays. Here i give the links, its very useful for formatting and creating JSON. Just try it and give your feedback. --> My Best Option.