Notification

old/UI Design 2010. 6. 17. 15:57
1. Toast Notification
 
    1) Basic
      
Toast.makeText(context, text, duration).show();


    2) Custom
      
    Context context = getApplicationContext();   // Context 얻어오기
    LayoutInflater inflater = getLayoutInflater();   // inflater 불러들이기
    View layout = inflater.inflate(R.layout.custom_layout, (ViewGroup) findViewById(R.id.toast_layout_root));  // custom_layout에서 toast_layout_root를 확장하기 위해 불러오자.
   
    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(android.R.drawable.ic_dialog_alert);
   
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText("This is a custom Toast");
   
    Toast toast = new Toast(context);
    toast.setGravity(Gravity.BOTTOM, 0,0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();


2. Status Bar Notification

    1) Basic
   
        (1) notification manager에 대한 reference 얻기 
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);

        (2) notification의 instance화 하기
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);

        (3) notification 확장 및 intent 정의
Context contex = getApplicaitonContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World";
Intent notificationintent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, conentIntent);

       (4) notification manager에게 notification 전달
private static final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);

     
      (5) option 기능들
[sound 설정]
notification.defaults |= Notification.DEFAULT_SOUND;  // 기본 sound 재생
notification.sound = Uri.parse(file:///위치지정);  // 디바이스 sdcard에서 찾기
notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "번호");  // Media Store에서 사용

[진동 설정]
notification.defaults |= Notification.DEFAULT_VIBRATE;  // 기본 설정으로
long[] vibrate = {0,100,200,300}; // {시작전대기, 진동길이, 꺼진후대기,...}
notification.vibrate = vibrate;

'old > UI Design' 카테고리의 다른 글

String & StyledText  (0) 2010.06.30
Style & Theme  (0) 2010.06.30
UI 이벤트 처리  (0) 2010.06.15
style  (0) 2010.02.22
기본 UI 생성 순서  (0) 2010.02.22
Posted by jazzlife
,