1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.car.cluster.sample; 18 19import static com.android.car.cluster.sample.DebugUtil.DEBUG; 20 21import android.app.Notification; 22import android.os.Handler; 23import android.os.Message; 24import android.service.notification.StatusBarNotification; 25import android.util.Log; 26 27import com.android.car.cluster.sample.MessagingConverter.MessageContactDetails; 28 29/** 30 * Handles messaging {@link StatusBarNotification}. 31 */ 32class MessagingNotificationHandler extends Handler { 33 private static final String TAG = DebugUtil.getTag(MessagingNotificationHandler.class); 34 35 private final ClusterView mClusterView; 36 37 MessagingNotificationHandler(ClusterView cluster) { 38 mClusterView = cluster; 39 } 40 41 @Override 42 public void handleMessage(Message msg) { 43 if (DEBUG) { 44 Log.d(TAG, "NotificationHandler, handleMessage: " + msg); 45 } 46 if (msg.obj instanceof StatusBarNotification) { 47 StatusBarNotification sbn = (StatusBarNotification) msg.obj; 48 Notification notification = sbn.getNotification(); 49 if (notification != null) { 50 if (DEBUG) { 51 Log.d(TAG, "NotificationHandler, notification extras: " 52 + notification.extras.toString()); 53 } 54 if (MessagingConverter.canConvert(sbn)) { 55 MessageContactDetails data = MessagingConverter.convert(sbn); 56 mClusterView.handleHangoutMessage( 57 data.getContactImage(), data.getContactName()); 58 } else { 59 Log.w(TAG, "Can't convert message: " + sbn); 60 } 61 } 62 } else { 63 Log.w(TAG, "Unexpected message with object: " + msg.obj); 64 } 65 } 66}