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 17 package android.print.test.services; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 22 import java.util.ArrayList; 23 24 public class InfoActivity extends Activity { 25 public interface Observer { onCreate(Activity createdActivity)26 void onCreate(Activity createdActivity); 27 } 28 29 private static final ArrayList<Observer> sObservers = new ArrayList<>(); 30 addObserver(Observer observer)31 public static void addObserver(Observer observer) { 32 synchronized (sObservers) { 33 sObservers.add(observer); 34 } 35 } 36 clearObservers()37 public static void clearObservers() { 38 synchronized (sObservers) { 39 sObservers.clear(); 40 } 41 } 42 43 @Override onCreate(Bundle savedInstanceState)44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 47 synchronized (sObservers) { 48 ArrayList<Observer> observers = (ArrayList<Observer>) sObservers.clone(); 49 50 for (Observer observer : observers) { 51 observer.onCreate(this); 52 } 53 } 54 } 55 } 56