Home | History | Annotate | Download | only in calllog
      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.dialer.app.calllog;
     18 
     19 import android.view.LayoutInflater;
     20 import android.view.View;
     21 import android.view.ViewGroup;
     22 import com.android.dialer.app.R;
     23 import com.android.dialer.app.alert.AlertManager;
     24 
     25 /**
     26  * Alert manager controls modal view to show message in call log. When modal view is shown, regular
     27  * call log will be hidden.
     28  */
     29 public class CallLogModalAlertManager implements AlertManager {
     30 
     31   interface Listener {
     32     void onShowModalAlert(boolean show);
     33   }
     34 
     35   private final Listener listener;
     36   private final ViewGroup parent;
     37   private final ViewGroup container;
     38   private final LayoutInflater inflater;
     39 
     40   public CallLogModalAlertManager(LayoutInflater inflater, ViewGroup parent, Listener listener) {
     41     this.inflater = inflater;
     42     this.parent = parent;
     43     this.listener = listener;
     44     container = (ViewGroup) parent.findViewById(R.id.modal_message_container);
     45   }
     46 
     47   @Override
     48   public View inflate(int layoutId) {
     49     return inflater.inflate(layoutId, parent, false);
     50   }
     51 
     52   @Override
     53   public void add(View view) {
     54     if (contains(view)) {
     55       return;
     56     }
     57     container.addView(view);
     58     listener.onShowModalAlert(true);
     59   }
     60 
     61   @Override
     62   public void clear() {
     63     container.removeAllViews();
     64     listener.onShowModalAlert(false);
     65   }
     66 
     67   public boolean isEmpty() {
     68     return container.getChildCount() == 0;
     69   }
     70 
     71   public boolean contains(View view) {
     72     return container.indexOfChild(view) != -1;
     73   }
     74 }
     75