1 /* 2 * Copyright (C) 2018 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 package com.android.car.notification; 17 18 import android.app.Activity; 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.ServiceConnection; 23 import android.os.Bundle; 24 import android.os.IBinder; 25 import android.util.Log; 26 27 /** 28 * Displays all undismissed notifications. 29 */ 30 public class CarNotificationCenterActivity extends Activity { 31 32 private static final String TAG = "CarNotificationActivity"; 33 34 private boolean mNotificationListenerBound; 35 private CarNotificationListener mNotificationListener; 36 private PreprocessingManager mPreprocessingManager; 37 private CarNotificationView mCarNotificationView; 38 private NotificationViewController mNotificationViewController; 39 40 private ServiceConnection mNotificationListenerConnectionListener = new ServiceConnection() { 41 public void onServiceConnected(ComponentName className, IBinder binder) { 42 Log.d(TAG, "onServiceConnected"); 43 mNotificationListener = ((CarNotificationListener.LocalBinder) binder).getService(); 44 NotificationApplication app = (NotificationApplication) getApplication(); 45 mNotificationViewController = 46 new NotificationViewController(mCarNotificationView, 47 mPreprocessingManager, 48 mNotificationListener, 49 app.getCarUxRestrictionWrapper(), 50 new NotificationDataManager() 51 ); 52 mNotificationViewController.enable(); 53 mNotificationListenerBound = true; 54 } 55 56 public void onServiceDisconnected(ComponentName className) { 57 Log.d(TAG, "onServiceDisconnected"); 58 mNotificationViewController.disable(); 59 mNotificationViewController = null; 60 mNotificationListener = null; 61 mNotificationListenerBound = false; 62 } 63 }; 64 65 @Override onCreate(Bundle savedInstanceState)66 protected void onCreate(Bundle savedInstanceState) { 67 super.onCreate(savedInstanceState); 68 mPreprocessingManager = PreprocessingManager.getInstance(getApplicationContext()); 69 NotificationApplication app = (NotificationApplication) getApplication(); 70 setContentView(R.layout.notification_center_activity); 71 mCarNotificationView = findViewById(R.id.notification_view); 72 mCarNotificationView.setClickHandlerFactory(app.getClickHandlerFactory()); 73 findViewById(R.id.exit_button_container).setOnClickListener(v -> finish()); 74 } 75 76 @Override onStart()77 protected void onStart() { 78 super.onStart(); 79 // Bind notification listener 80 Intent intent = new Intent(this, CarNotificationListener.class); 81 intent.setAction(CarNotificationListener.ACTION_LOCAL_BINDING); 82 bindService(intent, mNotificationListenerConnectionListener, Context.BIND_AUTO_CREATE); 83 mNotificationViewController.onVisibilityChanged(true); 84 } 85 86 @Override onStop()87 protected void onStop() { 88 super.onStop(); 89 mNotificationViewController.onVisibilityChanged(false); 90 // Unbind notification listener 91 if (mNotificationListenerBound) { 92 mNotificationViewController.disable(); 93 mNotificationViewController = null; 94 mNotificationListener = null; 95 unbindService(mNotificationListenerConnectionListener); 96 mNotificationListenerBound = false; 97 } 98 } 99 100 } 101