1 /*
2  * Copyright (C) 2013 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.incallui;
18 
19 import android.app.ActionBar;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.ListView;
26 
27 import com.android.contacts.common.ContactPhotoManager;
28 import com.android.dialer.R;
29 
30 import java.util.List;
31 
32 /**
33  * Fragment that allows the user to manage a conference call.
34  */
35 public class ConferenceManagerFragment
36         extends BaseFragment<ConferenceManagerPresenter,
37                 ConferenceManagerPresenter.ConferenceManagerUi>
38         implements ConferenceManagerPresenter.ConferenceManagerUi {
39 
40     private static final String KEY_IS_VISIBLE = "key_conference_is_visible";
41 
42     private ListView mConferenceParticipantList;
43     private int mActionBarElevation;
44     private ContactPhotoManager mContactPhotoManager;
45     private LayoutInflater mInflater;
46     private ConferenceParticipantListAdapter mConferenceParticipantListAdapter;
47     private boolean mIsVisible;
48     private boolean mIsRecreating;
49 
50     @Override
createPresenter()51     public ConferenceManagerPresenter createPresenter() {
52         return new ConferenceManagerPresenter();
53     }
54 
55     @Override
getUi()56     public ConferenceManagerPresenter.ConferenceManagerUi getUi() {
57         return this;
58     }
59 
60     @Override
onCreate(Bundle savedInstanceState)61     public void onCreate(Bundle savedInstanceState) {
62         super.onCreate(savedInstanceState);
63         if (savedInstanceState != null) {
64             mIsRecreating = true;
65             mIsVisible = savedInstanceState.getBoolean(KEY_IS_VISIBLE);
66         }
67     }
68 
69     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)70     public View onCreateView(LayoutInflater inflater, ViewGroup container,
71             Bundle savedInstanceState) {
72         final View parent =
73                 inflater.inflate(R.layout.conference_manager_fragment, container, false);
74 
75         mConferenceParticipantList = (ListView) parent.findViewById(R.id.participantList);
76         mContactPhotoManager =
77                 ContactPhotoManager.getInstance(getActivity().getApplicationContext());
78         mActionBarElevation =
79                 (int) getResources().getDimension(R.dimen.incall_action_bar_elevation);
80         mInflater = LayoutInflater.from(getActivity().getApplicationContext());
81 
82         return parent;
83     }
84 
85     @Override
onResume()86     public void onResume() {
87         super.onResume();
88         if (mIsRecreating) {
89             onVisibilityChanged(mIsVisible);
90         }
91     }
92 
93     @Override
onSaveInstanceState(Bundle outState)94     public void onSaveInstanceState(Bundle outState) {
95         outState.putBoolean(KEY_IS_VISIBLE, mIsVisible);
96         super.onSaveInstanceState(outState);
97     }
98 
onVisibilityChanged(boolean isVisible)99     public void onVisibilityChanged(boolean isVisible) {
100         mIsVisible = isVisible;
101         ActionBar actionBar = getActivity().getActionBar();
102         if (isVisible) {
103             actionBar.setTitle(R.string.manageConferenceLabel);
104             actionBar.setElevation(mActionBarElevation);
105             actionBar.setHideOffset(0);
106             actionBar.show();
107 
108             final CallList calls = CallList.getInstance();
109             getPresenter().init(getActivity(), calls);
110             // Request focus on the list of participants for accessibility purposes.  This ensures
111             // that once the list of participants is shown, the first participant is announced.
112             mConferenceParticipantList.requestFocus();
113         } else {
114             actionBar.setElevation(0);
115             actionBar.setHideOffset(actionBar.getHeight());
116         }
117     }
118 
119     @Override
isFragmentVisible()120     public boolean isFragmentVisible() {
121         return isVisible();
122     }
123 
124     @Override
update(Context context, List<Call> participants, boolean parentCanSeparate)125     public void update(Context context, List<Call> participants, boolean parentCanSeparate) {
126         if (mConferenceParticipantListAdapter == null) {
127             mConferenceParticipantListAdapter = new ConferenceParticipantListAdapter(
128                     mConferenceParticipantList, context, mInflater, mContactPhotoManager);
129 
130             mConferenceParticipantList.setAdapter(mConferenceParticipantListAdapter);
131         }
132         mConferenceParticipantListAdapter.updateParticipants(participants, parentCanSeparate);
133     }
134 
135     @Override
refreshCall(Call call)136     public void refreshCall(Call call) {
137         mConferenceParticipantListAdapter.refreshCall(call);
138     }
139 }
140