NotificationTestHelper.java revision 6fd06b5b8089952a7fa6e3286d246ab910090b79
16fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek/* 26fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * Copyright (C) 2017 The Android Open Source Project 36fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * 46fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 56fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * you may not use this file except in compliance with the License. 66fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * You may obtain a copy of the License at 76fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * 86fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * http://www.apache.org/licenses/LICENSE-2.0 96fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * 106fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * Unless required by applicable law or agreed to in writing, software 116fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 126fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * See the License for the specific language governing permissions and 146fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * limitations under the License 156fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek */ 166fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 176fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekpackage com.android.systemui.statusbar; 186fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 196fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport android.app.ActivityManager; 206fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport android.app.Notification; 216fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport android.content.Context; 226fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport android.os.UserHandle; 236fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport android.service.notification.StatusBarNotification; 246fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport android.view.LayoutInflater; 256fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport android.widget.RemoteViews; 266fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 276fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport com.android.systemui.R; 286fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport com.android.systemui.statusbar.notification.InflationException; 296fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekimport com.android.systemui.statusbar.phone.NotificationGroupManager; 306fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 316fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek/** 326fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek * A helper class to create {@link ExpandableNotificationRow} 336fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek */ 346fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinekpublic class NotificationTestHelper { 356fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 366fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek private final Context mContext; 376fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek private int mId; 386fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek private final NotificationGroupManager mGroupManager = new NotificationGroupManager(); 396fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 406fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek public NotificationTestHelper(Context context) { 416fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek mContext = context; 426fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek } 436fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 446fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek public ExpandableNotificationRow createRow() { 456fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( 466fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek mContext.LAYOUT_INFLATER_SERVICE); 476fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek ExpandableNotificationRow row = (ExpandableNotificationRow) inflater.inflate( 486fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek R.layout.status_bar_notification_row, 496fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek null, false); 506fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek row.setGroupManager(mGroupManager); 516fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek Notification publicVersion = new Notification.Builder(mContext).setSmallIcon( 526fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek R.drawable.ic_person) 536fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek .setCustomContentView(new RemoteViews(mContext.getPackageName(), 546fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek R.layout.custom_view_dark)) 556fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek .build(); 566fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek Notification notification = new Notification.Builder(mContext).setSmallIcon( 576fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek R.drawable.ic_person) 586fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek .setContentTitle("Title") 596fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek .setContentText("Text") 606fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek .setPublicVersion(publicVersion) 616fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek .build(); 626fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser()); 636fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek StatusBarNotification sbn = new StatusBarNotification("com.android.systemui", 646fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek "com.android.systemui", mId++, null, 1000, 656fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 2000, notification, mUser, null, System.currentTimeMillis()); 666fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek NotificationData.Entry entry = new NotificationData.Entry(sbn); 676fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek entry.row = row; 686fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek try { 696fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek entry.createIcons(mContext, sbn); 706fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek row.updateNotification(entry); 716fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek } catch (InflationException e) { 726fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek throw new RuntimeException(e.getMessage()); 736fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek } 746fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek return row; 756fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek } 766fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek 776fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek public ExpandableNotificationRow createGroup() { 786fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek ExpandableNotificationRow row = createRow(); 796fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek row.addChildNotification(createRow()); 806fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek row.addChildNotification(createRow()); 816fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek return row; 826fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek } 836fd06b5b8089952a7fa6e3286d246ab910090b79Selim Cinek} 84