Monday, January 30, 2012

Using Custom Font in android

How to use Custom Font whose file size is higher than asset folder in android?

Step 1: Just place that font file on raw folder "/res/raw/chen.ttf" , Say here the font name is chen.ttf

Step 2: 

Typeface  typeFace= readFont(R.raw.chen); 
textView.setTypeface(typeFace);

Step 3:

Create a method which reads the font file and set it to typeface object
 
Step 4:  

Typeface readFont(int resource)
{  
Typeface tf_obj = null;
InputStream is = getResources().openRawResource(resource);
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/gmg_underground_tmp";
File f = new File(path);
if (!f.exists())
{
    if (!f.mkdirs())
        return null;
}
String outPath = path + "/tmp.raw";
try
{
    byte[] buffer = new byte[is.available()];
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outPath));

    int l = 0;
    while((l = is.read(buffer)) > 0)
    {
        bos.write(buffer, 0, l);
    }
    bos.close();

    tf_obj = Typeface.createFromFile(outPath);

    File f2 = new File(outPath);
    f2.delete();
}
catch (IOException e)
{
    return null;
}
return tf_obj;      }

Notification in Android Using AlarmManager, BoradCastReceiver & Services

    Our aim is to show notification message to user in a specific time.     Say For example , I have planned to show Notification ...