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