15345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen/*
25345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * Copyright (C) 2013 The Android Open Source Project
35345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen *
45345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * Licensed under the Apache License, Version 2.0 (the "License");
55345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * you may not use this file except in compliance with the License.
65345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * You may obtain a copy of the License at
75345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen *
85345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen *      http://www.apache.org/licenses/LICENSE-2.0
95345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen *
105345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * Unless required by applicable law or agreed to in writing, software
115345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * distributed under the License is distributed on an "AS IS" BASIS,
125345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * See the License for the specific language governing permissions and
145345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen * limitations under the License
155345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen */
165345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
175345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chenpackage com.android.incallui;
185345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
193a7108ae5fc630730457957629b1115dcc991454Andrew Leeimport android.app.ActionBar;
200cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunnimport android.content.Context;
215345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chenimport android.os.Bundle;
225345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chenimport android.view.LayoutInflater;
235345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chenimport android.view.View;
245345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chenimport android.view.ViewGroup;
250cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunnimport android.widget.ListView;
265345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
273a7108ae5fc630730457957629b1115dcc991454Andrew Leeimport com.android.contacts.common.ContactPhotoManager;
2868d86c656e5522dec1b04e85ebc0e0f78e436c3dSailesh Nepalimport com.android.dialer.R;
290cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn
300cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunnimport java.util.List;
313a7108ae5fc630730457957629b1115dcc991454Andrew Lee
325345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen/**
33979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee * Fragment that allows the user to manage a conference call.
345345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen */
355345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chenpublic class ConferenceManagerFragment
365345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        extends BaseFragment<ConferenceManagerPresenter,
375345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen                ConferenceManagerPresenter.ConferenceManagerUi>
385345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        implements ConferenceManagerPresenter.ConferenceManagerUi {
395345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
40979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee    private static final String KEY_IS_VISIBLE = "key_conference_is_visible";
41979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee
420cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn    private ListView mConferenceParticipantList;
433a7108ae5fc630730457957629b1115dcc991454Andrew Lee    private int mActionBarElevation;
443a7108ae5fc630730457957629b1115dcc991454Andrew Lee    private ContactPhotoManager mContactPhotoManager;
450cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn    private LayoutInflater mInflater;
460cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn    private ConferenceParticipantListAdapter mConferenceParticipantListAdapter;
47979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee    private boolean mIsVisible;
48979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee    private boolean mIsRecreating;
495345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
505345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
519bcd0f1e66d4a8aa9e2e6b2b6d2c3efd6ffddb75Andrew Lee    public ConferenceManagerPresenter createPresenter() {
525345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        return new ConferenceManagerPresenter();
535345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
545345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
555345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
569bcd0f1e66d4a8aa9e2e6b2b6d2c3efd6ffddb75Andrew Lee    public ConferenceManagerPresenter.ConferenceManagerUi getUi() {
575345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        return this;
585345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
595345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
605345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
615345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    public void onCreate(Bundle savedInstanceState) {
625345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        super.onCreate(savedInstanceState);
63979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        if (savedInstanceState != null) {
64979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee            mIsRecreating = true;
65979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee            mIsVisible = savedInstanceState.getBoolean(KEY_IS_VISIBLE);
66979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        }
675345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
685345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
695345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
705345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    public View onCreateView(LayoutInflater inflater, ViewGroup container,
715345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen            Bundle savedInstanceState) {
7221707a656d5097323627b5096276dfa509259150Andrew Lee        final View parent =
7321707a656d5097323627b5096276dfa509259150Andrew Lee                inflater.inflate(R.layout.conference_manager_fragment, container, false);
745345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
750cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn        mConferenceParticipantList = (ListView) parent.findViewById(R.id.participantList);
763a7108ae5fc630730457957629b1115dcc991454Andrew Lee        mContactPhotoManager =
773a7108ae5fc630730457957629b1115dcc991454Andrew Lee                ContactPhotoManager.getInstance(getActivity().getApplicationContext());
783a7108ae5fc630730457957629b1115dcc991454Andrew Lee        mActionBarElevation =
793a7108ae5fc630730457957629b1115dcc991454Andrew Lee                (int) getResources().getDimension(R.dimen.incall_action_bar_elevation);
800cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn        mInflater = LayoutInflater.from(getActivity().getApplicationContext());
815345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
825345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        return parent;
835345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
845345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
855345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
86979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee    public void onResume() {
87979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        super.onResume();
88979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        if (mIsRecreating) {
89979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee            onVisibilityChanged(mIsVisible);
90979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        }
915345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
925345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
935345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
94979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee    public void onSaveInstanceState(Bundle outState) {
95979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        outState.putBoolean(KEY_IS_VISIBLE, mIsVisible);
96979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        super.onSaveInstanceState(outState);
97979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee    }
983a7108ae5fc630730457957629b1115dcc991454Andrew Lee
99979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee    public void onVisibilityChanged(boolean isVisible) {
100979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        mIsVisible = isVisible;
101979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        ActionBar actionBar = getActivity().getActionBar();
102979f38e37da9bdd4c51aceafe7bcc44b305e3d02Yorke Lee        if (isVisible) {
1033a7108ae5fc630730457957629b1115dcc991454Andrew Lee            actionBar.setTitle(R.string.manageConferenceLabel);
1043a7108ae5fc630730457957629b1115dcc991454Andrew Lee            actionBar.setElevation(mActionBarElevation);
1053a7108ae5fc630730457957629b1115dcc991454Andrew Lee            actionBar.setHideOffset(0);
1063a7108ae5fc630730457957629b1115dcc991454Andrew Lee            actionBar.show();
1073a7108ae5fc630730457957629b1115dcc991454Andrew Lee
1085345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen            final CallList calls = CallList.getInstance();
1095345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen            getPresenter().init(getActivity(), calls);
1106b929c026e2d7d9b4fb4ec401829431e817c8606Tyler Gunn            // Request focus on the list of participants for accessibility purposes.  This ensures
1116b929c026e2d7d9b4fb4ec401829431e817c8606Tyler Gunn            // that once the list of participants is shown, the first participant is announced.
1126b929c026e2d7d9b4fb4ec401829431e817c8606Tyler Gunn            mConferenceParticipantList.requestFocus();
1135345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        } else {
1143a7108ae5fc630730457957629b1115dcc991454Andrew Lee            actionBar.setElevation(0);
1153a7108ae5fc630730457957629b1115dcc991454Andrew Lee            actionBar.setHideOffset(actionBar.getHeight());
1165345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        }
1175345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
1185345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
1195345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
1205345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    public boolean isFragmentVisible() {
1215345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        return isVisible();
1225345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
1235345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
1245345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
1250cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn    public void update(Context context, List<Call> participants, boolean parentCanSeparate) {
1260cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn        if (mConferenceParticipantListAdapter == null) {
1270cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn            mConferenceParticipantListAdapter = new ConferenceParticipantListAdapter(
1280cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn                    mConferenceParticipantList, context, mInflater, mContactPhotoManager);
1295345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
1300cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn            mConferenceParticipantList.setAdapter(mConferenceParticipantListAdapter);
1315345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen        }
1320cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn        mConferenceParticipantListAdapter.updateParticipants(participants, parentCanSeparate);
1335345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
1345345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen
1355345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    @Override
1360cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn    public void refreshCall(Call call) {
1370cff18feff43a6915919ac8e32fa44502aa6c320Tyler Gunn        mConferenceParticipantListAdapter.refreshCall(call);
1385345442d7238c1db00dc8d55a49f7f5dd713d994Christine Chen    }
13921707a656d5097323627b5096276dfa509259150Andrew Lee}
140