Home | History | Annotate | Download | only in incallui
      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.graphics.drawable.Drawable;
     21 import android.net.Uri;
     22 import android.os.Bundle;
     23 import android.text.TextUtils;
     24 import android.view.LayoutInflater;
     25 import android.view.View;
     26 import android.view.ViewGroup;
     27 import android.widget.ImageView;
     28 import android.widget.TextView;
     29 
     30 import com.android.contacts.common.ContactPhotoManager;
     31 import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
     32 
     33 /**
     34  * Fragment for call control buttons
     35  */
     36 public class ConferenceManagerFragment
     37         extends BaseFragment<ConferenceManagerPresenter,
     38                 ConferenceManagerPresenter.ConferenceManagerUi>
     39         implements ConferenceManagerPresenter.ConferenceManagerUi {
     40 
     41     private ViewGroup[] mConferenceCallList;
     42     private int mActionBarElevation;
     43     private ContactPhotoManager mContactPhotoManager;
     44 
     45     @Override
     46     ConferenceManagerPresenter createPresenter() {
     47         // having a singleton instance.
     48         return new ConferenceManagerPresenter();
     49     }
     50 
     51     @Override
     52     ConferenceManagerPresenter.ConferenceManagerUi getUi() {
     53         return this;
     54     }
     55 
     56     @Override
     57     public void onCreate(Bundle savedInstanceState) {
     58         super.onCreate(savedInstanceState);
     59     }
     60 
     61     @Override
     62     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     63             Bundle savedInstanceState) {
     64         final View parent = inflater.inflate(R.layout.conference_manager_fragment, container,
     65                 false);
     66 
     67         // Create list of conference call widgets
     68         mConferenceCallList = new ViewGroup[getPresenter().getMaxCallersInConference()];
     69         final int[] viewGroupIdList = { R.id.caller0, R.id.caller1, R.id.caller2,
     70                                         R.id.caller3, R.id.caller4 };
     71         for (int i = 0; i < getPresenter().getMaxCallersInConference(); i++) {
     72             mConferenceCallList[i] = (ViewGroup) parent.findViewById(viewGroupIdList[i]);
     73         }
     74 
     75         mContactPhotoManager =
     76                 ContactPhotoManager.getInstance(getActivity().getApplicationContext());
     77 
     78         mActionBarElevation =
     79                 (int) getResources().getDimension(R.dimen.incall_action_bar_elevation);
     80 
     81         return parent;
     82     }
     83 
     84     @Override
     85     public void onActivityCreated(Bundle savedInstanceState) {
     86         super.onActivityCreated(savedInstanceState);
     87     }
     88 
     89     @Override
     90     public void setVisible(boolean on) {
     91         ActionBar actionBar = getActivity().getActionBar();
     92 
     93         if (on) {
     94             actionBar.setTitle(R.string.manageConferenceLabel);
     95             actionBar.setElevation(mActionBarElevation);
     96             actionBar.setHideOffset(0);
     97             actionBar.show();
     98 
     99             final CallList calls = CallList.getInstance();
    100             getPresenter().init(getActivity(), calls);
    101             getView().setVisibility(View.VISIBLE);
    102         } else {
    103             getView().setVisibility(View.GONE);
    104 
    105             actionBar.setElevation(0);
    106             actionBar.setHideOffset(actionBar.getHeight());
    107         }
    108     }
    109 
    110     @Override
    111     public boolean isFragmentVisible() {
    112         return isVisible();
    113     }
    114 
    115     @Override
    116     public void setRowVisible(int rowId, boolean on) {
    117         if (on) {
    118             mConferenceCallList[rowId].setVisibility(View.VISIBLE);
    119         } else {
    120             mConferenceCallList[rowId].setVisibility(View.GONE);
    121         }
    122     }
    123 
    124     /**
    125      * Helper function to fill out the Conference Call(er) information
    126      * for each item in the "Manage Conference Call" list.
    127      */
    128     @Override
    129     public final void displayCallerInfoForConferenceRow(int rowId, String callerName,
    130             String callerNumber, String callerNumberType, String lookupKey, Uri photoUri) {
    131 
    132         final ImageView photoView = (ImageView) mConferenceCallList[rowId].findViewById(
    133                 R.id.callerPhoto);
    134         final TextView nameTextView = (TextView) mConferenceCallList[rowId].findViewById(
    135                 R.id.conferenceCallerName);
    136         final TextView numberTextView = (TextView) mConferenceCallList[rowId].findViewById(
    137                 R.id.conferenceCallerNumber);
    138         final TextView numberTypeTextView = (TextView) mConferenceCallList[rowId].findViewById(
    139                 R.id.conferenceCallerNumberType);
    140 
    141         DefaultImageRequest imageRequest = (photoUri != null) ? null :
    142                 new DefaultImageRequest(callerName, lookupKey, true /* isCircularPhoto */);
    143         mContactPhotoManager.loadDirectoryPhoto(photoView, photoUri, false, true, imageRequest);
    144 
    145         // set the caller name
    146         nameTextView.setText(callerName);
    147 
    148         // set the caller number in subscript, or make the field disappear.
    149         if (TextUtils.isEmpty(callerNumber)) {
    150             numberTextView.setVisibility(View.GONE);
    151             numberTypeTextView.setVisibility(View.GONE);
    152         } else {
    153             numberTextView.setVisibility(View.VISIBLE);
    154             numberTextView.setText(callerNumber);
    155             numberTypeTextView.setVisibility(View.VISIBLE);
    156             numberTypeTextView.setText(callerNumberType);
    157         }
    158     }
    159 
    160     @Override
    161     public final void setupEndButtonForRow(final int rowId, boolean canDisconnect) {
    162         View endButton = mConferenceCallList[rowId].findViewById(R.id.conferenceCallerDisconnect);
    163 
    164         // Comment
    165         if (canDisconnect) {
    166             endButton.setOnClickListener(new View.OnClickListener() {
    167                 @Override
    168                 public void onClick(View v) {
    169                     getPresenter().endConferenceConnection(rowId);
    170                 }
    171             });
    172             endButton.setVisibility(View.VISIBLE);
    173         } else {
    174             endButton.setVisibility(View.INVISIBLE);
    175         }
    176     }
    177 
    178     @Override
    179     public final void setupSeparateButtonForRow(final int rowId, boolean canSeparate) {
    180         final View separateButton =
    181                 mConferenceCallList[rowId].findViewById(R.id.conferenceCallerSeparate);
    182 
    183         if (canSeparate) {
    184             separateButton.setOnClickListener(new View.OnClickListener() {
    185                 @Override
    186                 public void onClick(View v) {
    187                     getPresenter().separateConferenceConnection(rowId);
    188                 }
    189             });
    190             separateButton.setVisibility(View.VISIBLE);
    191         } else {
    192             separateButton.setVisibility(View.INVISIBLE);
    193         }
    194     }
    195 }