NotificationComparator.java revision f953664dc17dca23bd724bd64f89189c16c83263
1/* 2 * Copyright (C) 2014 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 */ 16package com.android.server.notification; 17 18import java.util.Comparator; 19 20/** 21 * Sorts notificaitons into attention-relelvant order. 22 */ 23public class NotificationComparator 24 implements Comparator<NotificationManagerService.NotificationRecord> { 25 26 @Override 27 public int compare(NotificationManagerService.NotificationRecord lhs, 28 NotificationManagerService.NotificationRecord rhs) { 29 final int leftScore = lhs.sbn.getScore(); 30 final int rightScore = rhs.sbn.getScore(); 31 if (leftScore != rightScore) { 32 // by priority, high to low 33 return -1 * Integer.compare(leftScore, rightScore); 34 } 35 final float leftPeple = lhs.getContactAffinity(); 36 final float rightPeople = rhs.getContactAffinity(); 37 if (leftPeple != rightPeople) { 38 // by contact proximity, close to far 39 return -1 * Float.compare(leftPeple, rightPeople); 40 } 41 // then break ties by time, most recent first 42 return -1 * Long.compare(lhs.sbn.getPostTime(), rhs.sbn.getPostTime()); 43 } 44} 45