----------CustomTypefaceSpan.class-----------------
package com.example.notification;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;
public class CustomTypefaceSpan extends TypefaceSpan {
private final Typeface newType;
public CustomTypefaceSpan(String family, Typeface type) {
super(family);
newType = type;
}
@Override
public void updateDrawState(TextPaint ds) {
applyCustomTypeFace(ds, newType);
}
@Override
public void updateMeasureState(TextPaint paint) {
applyCustomTypeFace(paint, newType);
}
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
int oldStyle;
Typeface old = paint.getTypeface();
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.getStyle();
}
int fake = oldStyle & ~tf.getStyle();
if ((fake & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fake & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.setTypeface(tf);
}
}
-------Notification class--------------
package com.example.notification;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Typeface;
import android.renderscript.Font;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Typeface font=Typeface.createFromAsset(getAssets(), "raavi.ttf");
SpannableStringBuilder sb=new SpannableStringBuilder("à¨à¨¾à¨°à¨¤ ਨਤੀਜੀਆਂ ਦੇ ਬਾਰੇ ਵਿੱਚ ਹਰੇਕ ਵਿਅਕਤੀ ਨੂੰ ਵਿਦਿਆ ਹਾਸਲ ਕਰਨ ਦਾ ਹੱਕ ਹੈ");
sb.setSpan (new CustomTypefaceSpan("", font), 0, sb.length()-1,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
showNotification(sb);
}
public void showNotification(SpannableStringBuilder sb) {
PendingIntent contentIntent;
// CharSequence text=" Satnam Shri vaheguru...You have a new sabad to read.";
CharSequence title="title";
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, sb, System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
Intent showIntent =new Intent(this,MainActivity.class);
showIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
contentIntent = PendingIntent.getActivity(this, 0,
showIntent, 0);
notification.setLatestEventInfo(this,title, sb, contentIntent);
nm.notify(1, notification);
}
}