BloByJames

Glide와 함께 Circular Notification Icon 만들기 본문

프로그래밍/안드로이드

Glide와 함께 Circular Notification Icon 만들기

blobyjames 2017. 3. 13. 01:46

X카X톡을 사용하시는 분들은 자주 보았을,

Notification icon에 http로 불러 온 image를

원형으로 만들어 봅시다.


우선, image loading을 위해 사용되는 library는 Glide 입니다.


사실, network로 불러 온 image를 Notification icon에

넣는 과정을 위한 posting이므로,

Glide도 좋지만, AUIL(Android Universal Image Loader), Fresco, Volley 등 뭐든 상관이 없고,

취향에 맞는 library를 사용하시면 됩니다.


먼저 NotificationCompat.Builder를 생성하겠습니다.


Builder pattern을 제공하니 원하는 option을 사용합니다.


into()의 parameter로 SimpleTarget을 생성하여 넘겨주고,

onResourceReady()를 override 하면, parameter로 Bitmap을 받을 수 있습니다.


이렇게 받아 온 Bitmap을 원형으로 가공하는 작업이 필요합니다.

미리 정의 된 ImageUtils.getCircularBitmap()에

onResourceReady() parameter로 전달 된 Bitmap을 넘겨주면,

network로 불러 온 이미지가 원형으로 예쁘게 잘리게 됩니다.


이 Bitmap을 새로운 객체로 만들고, Notification에 넘겨주는 일만 남았습니다.


제일 처음에 생성했던 NotificationCompat.Builder 객체를 가지고 setLargeIcon()을 호출합니다.

parameter로는 원형으로 만들어진 Bitmap 객체를 전달해주면 모든 준비는 끝났습니다.


NotificationManager, NotificationManagerCompat을 통해 notify()를 호출하면,




따란! 완성되었습니다.


크게 어려운 작업은 아니었습니다.

예제에 사용 된 source는 notification-android-demo를 통해 확인하실 수 있습니다.


감사합니다.

Comments