1 /* 2 * Copyright (C) 2017 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 com.android.systemui.statusbar.notification; 18 19 import android.content.Context; 20 import android.support.v4.view.AsyncLayoutInflater; 21 import android.view.View; 22 import android.view.ViewGroup; 23 24 import com.android.systemui.R; 25 import com.android.systemui.statusbar.InflationTask; 26 import com.android.systemui.statusbar.ExpandableNotificationRow; 27 import com.android.systemui.statusbar.NotificationData; 28 29 /** 30 * An inflater task that asynchronously inflates a ExpandableNotificationRow 31 */ 32 public class RowInflaterTask implements InflationTask, AsyncLayoutInflater.OnInflateFinishedListener { 33 private RowInflationFinishedListener mListener; 34 private NotificationData.Entry mEntry; 35 private boolean mCancelled; 36 37 /** 38 * Inflates a new notificationView. This should not be called twice on this object 39 */ 40 public void inflate(Context context, ViewGroup parent, NotificationData.Entry entry, 41 RowInflationFinishedListener listener) { 42 mListener = listener; 43 AsyncLayoutInflater inflater = new AsyncLayoutInflater(context); 44 mEntry = entry; 45 entry.setInflationTask(this); 46 inflater.inflate(R.layout.status_bar_notification_row, parent, this); 47 } 48 49 @Override 50 public void abort() { 51 mCancelled = true; 52 } 53 54 @Override 55 public void onInflateFinished(View view, int resid, ViewGroup parent) { 56 if (!mCancelled) { 57 mEntry.onInflationTaskFinished(); 58 mListener.onInflationFinished((ExpandableNotificationRow) view); 59 } 60 } 61 62 public interface RowInflationFinishedListener { 63 void onInflationFinished(ExpandableNotificationRow row); 64 } 65 } 66