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 mNotificationViewController.enable(); 51 mNotificationListenerBound = true; 52 } 53 54 public void onServiceDisconnected(ComponentName className) { 55 Log.d(TAG, "onServiceDisconnected"); 56 mNotificationViewController.disable(); 57 mNotificationViewController = null; 58 mNotificationListener = null; 59 mNotificationListenerBound = false; 60 } 61 }; 62 63 @Override onCreate(Bundle savedInstanceState)64 protected void onCreate(Bundle savedInstanceState) { 65 super.onCreate(savedInstanceState); 66 mPreprocessingManager = PreprocessingManager.getInstance(getApplicationContext()); 67 NotificationApplication app = (NotificationApplication) getApplication(); 68 setContentView(R.layout.notification_center_activity); 69 mCarNotificationView = findViewById(R.id.notification_view); 70 mCarNotificationView.setClickHandlerFactory(app.getClickHandlerFactory()); 71 findViewById(R.id.exit_button_container).setOnClickListener(v -> finish()); 72 } 73 74 @Override onStart()75 protected void onStart() { 76 super.onStart(); 77 // Bind notification listener 78 Intent intent = new Intent(this, CarNotificationListener.class); 79 intent.setAction(CarNotificationListener.ACTION_LOCAL_BINDING); 80 bindService(intent, mNotificationListenerConnectionListener, Context.BIND_AUTO_CREATE); 81 if (mNotificationViewController != null) { 82 mNotificationViewController.onVisibilityChanged(true); 83 } 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