1e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng/*
2e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * Copyright (C) 2013 The Android Open Source Project
3e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng *
4e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License");
5e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * you may not use this file except in compliance with the License.
6e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * You may obtain a copy of the License at
7e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng *
8e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng *      http://www.apache.org/licenses/LICENSE-2.0
9e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng *
10e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * Unless required by applicable law or agreed to in writing, software
11e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS,
12e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * See the License for the specific language governing permissions and
14e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * limitations under the License
15e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng */
16e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng
17e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Chengpackage com.android.incallui;
18e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng
19ea83891eb10811d5020cc5fdaf34b711012dab32Santos Cordonimport android.animation.LayoutTransition;
20b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordonimport android.content.Context;
21988d06b64b99a13f4f060dc82594edcb738d9113Yorke Leeimport android.graphics.Bitmap;
22988d06b64b99a13f4f060dc82594edcb738d9113Yorke Leeimport android.graphics.drawable.BitmapDrawable;
23988d06b64b99a13f4f060dc82594edcb738d9113Yorke Leeimport android.graphics.drawable.Drawable;
24e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Chengimport android.os.Bundle;
257ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Leeimport android.text.TextUtils;
26a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordonimport android.view.Gravity;
27e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Chengimport android.view.LayoutInflater;
28e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Chengimport android.view.View;
299240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Leeimport android.view.View.OnClickListener;
30e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Chengimport android.view.ViewGroup;
31150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordonimport android.view.ViewStub;
32442721af112b39d5f85cc3c1ecd341855a300555Yorke Leeimport android.view.accessibility.AccessibilityEvent;
33988d06b64b99a13f4f060dc82594edcb738d9113Yorke Leeimport android.widget.ImageView;
34a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordonimport android.widget.TextView;
35e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng
36a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordonimport com.android.services.telephony.common.Call;
37a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
38442721af112b39d5f85cc3c1ecd341855a300555Yorke Leeimport java.util.List;
39442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee
40e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng/**
41e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng * Fragment for call card.
42e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng */
431fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Chengpublic class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPresenter.CallCardUi>
44a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon        implements CallCardPresenter.CallCardUi {
45a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon
4688dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon    // Primary caller info
47a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    private TextView mPhoneNumber;
487ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee    private TextView mNumberLabel;
498b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    private TextView mPrimaryName;
50a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon    private TextView mCallStateLabel;
51c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee    private TextView mCallTypeLabel;
5288dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon    private ImageView mPhoto;
5388dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon    private TextView mElapsedTime;
543d9e39bef65a67b9b04a2584b12f8b655fcc2e7cSantos Cordon    private View mProviderInfo;
553d9e39bef65a67b9b04a2584b12f8b655fcc2e7cSantos Cordon    private TextView mProviderLabel;
563d9e39bef65a67b9b04a2584b12f8b655fcc2e7cSantos Cordon    private TextView mProviderNumber;
57ea83891eb10811d5020cc5fdaf34b711012dab32Santos Cordon    private ViewGroup mSupplementaryInfoContainer;
5888dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon
5988dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon    // Secondary caller info
60150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon    private ViewStub mSecondaryCallInfo;
61150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon    private TextView mSecondaryCallName;
624bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon    private ImageView mSecondaryPhoto;
639240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee    private View mSecondaryPhotoOverlay;
64150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon
65b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon    // Cached DisplayMetrics density.
66b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon    private float mDensity;
67b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
68a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    @Override
691fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    CallCardPresenter.CallCardUi getUi() {
701fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng        return this;
711fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    }
721fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng
731fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    @Override
74a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    CallCardPresenter createPresenter() {
759de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon        return new CallCardPresenter();
76a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    }
77e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng
78e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng    @Override
791fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    public void onCreate(Bundle savedInstanceState) {
801fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng        super.onCreate(savedInstanceState);
81eaf5e4bc87797eeb5098982803af33e4a66d13d8Christine Chen    }
82eaf5e4bc87797eeb5098982803af33e4a66d13d8Christine Chen
83eaf5e4bc87797eeb5098982803af33e4a66d13d8Christine Chen
84eaf5e4bc87797eeb5098982803af33e4a66d13d8Christine Chen    @Override
85eaf5e4bc87797eeb5098982803af33e4a66d13d8Christine Chen    public void onActivityCreated(Bundle savedInstanceState) {
86eaf5e4bc87797eeb5098982803af33e4a66d13d8Christine Chen        super.onActivityCreated(savedInstanceState);
871fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng
888b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        final CallList calls = CallList.getInstance();
898b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        final Call call = calls.getFirstCall();
90101bed44998ff35c3a56f431345fac5c8229ec0eJay Shrauner        getPresenter().init(getActivity(), call);
911fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    }
921fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng
931fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    @Override
94e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng    public View onCreateView(LayoutInflater inflater, ViewGroup container,
95e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng            Bundle savedInstanceState) {
961fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng        super.onCreateView(inflater, container, savedInstanceState);
971fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng
98b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        mDensity = getResources().getDisplayMetrics().density;
99b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
100150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon        return inflater.inflate(R.layout.call_card, container, false);
101e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng    }
102a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon
103a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    @Override
104a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    public void onViewCreated(View view, Bundle savedInstanceState) {
1051fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng        super.onViewCreated(view, savedInstanceState);
1061fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng
107a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon        mPhoneNumber = (TextView) view.findViewById(R.id.phoneNumber);
1088b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        mPrimaryName = (TextView) view.findViewById(R.id.name);
1097ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee        mNumberLabel = (TextView) view.findViewById(R.id.label);
110150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon        mSecondaryCallInfo = (ViewStub) view.findViewById(R.id.secondary_call_info);
111988d06b64b99a13f4f060dc82594edcb738d9113Yorke Lee        mPhoto = (ImageView) view.findViewById(R.id.photo);
112a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        mCallStateLabel = (TextView) view.findViewById(R.id.callStateLabel);
113c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee        mCallTypeLabel = (TextView) view.findViewById(R.id.callTypeLabel);
11488dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon        mElapsedTime = (TextView) view.findViewById(R.id.elapsedTime);
1153d9e39bef65a67b9b04a2584b12f8b655fcc2e7cSantos Cordon        mProviderInfo = view.findViewById(R.id.providerInfo);
1163d9e39bef65a67b9b04a2584b12f8b655fcc2e7cSantos Cordon        mProviderLabel = (TextView) view.findViewById(R.id.providerLabel);
1173d9e39bef65a67b9b04a2584b12f8b655fcc2e7cSantos Cordon        mProviderNumber = (TextView) view.findViewById(R.id.providerAddress);
118ea83891eb10811d5020cc5fdaf34b711012dab32Santos Cordon        mSupplementaryInfoContainer =
119ea83891eb10811d5020cc5fdaf34b711012dab32Santos Cordon            (ViewGroup) view.findViewById(R.id.supplementary_info_container);
120a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    }
121a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon
122a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    @Override
1235b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    public void setVisible(boolean on) {
1245b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen        if (on) {
1255b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen            getView().setVisibility(View.VISIBLE);
1265b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen        } else {
1275b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen            getView().setVisibility(View.INVISIBLE);
1285b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen        }
1295b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    }
1305b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen
1315b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    @Override
1328b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    public void setPrimaryName(String name, boolean nameIsNumber) {
1338b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (TextUtils.isEmpty(name)) {
1348b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            mPrimaryName.setText("");
1358b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        } else {
1368b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            mPrimaryName.setText(name);
1378b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
1388b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            // Set direction of the name field
1398b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            int nameDirection = View.TEXT_DIRECTION_INHERIT;
1408b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            if (nameIsNumber) {
1418b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng                nameDirection = View.TEXT_DIRECTION_LTR;
1428b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            }
1438b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            mPrimaryName.setTextDirection(nameDirection);
1448b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
1451fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    }
1461fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng
1471fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    @Override
14814dbc3f0ca3a7998c9c5d28aba637487724f529fSantos Cordon    public void setPrimaryImage(Drawable image) {
1492f21162c5eb1dbb11f892601574d4de7170b4960Chiao Cheng        if (image != null) {
15014dbc3f0ca3a7998c9c5d28aba637487724f529fSantos Cordon            setDrawableToImageView(mPhoto, image);
1512f21162c5eb1dbb11f892601574d4de7170b4960Chiao Cheng        }
1521fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    }
1531fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng
1541fa0782281ef7774ddcdfdf8efb7d8f65cf589e7Chiao Cheng    @Override
1558b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    public void setPrimaryPhoneNumber(String number) {
1564bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        // Set the number
1574bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        if (TextUtils.isEmpty(number)) {
1584bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            mPhoneNumber.setText("");
1594bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            mPhoneNumber.setVisibility(View.GONE);
1604bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        } else {
1617ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee            mPhoneNumber.setText(number);
1627ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee            mPhoneNumber.setVisibility(View.VISIBLE);
1637ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee            mPhoneNumber.setTextDirection(View.TEXT_DIRECTION_LTR);
1647ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee        }
1658b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    }
1667ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee
1678b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    @Override
1688b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    public void setPrimaryLabel(String label) {
1698b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (!TextUtils.isEmpty(label)) {
1708b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            mNumberLabel.setText(label);
1718b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            mNumberLabel.setVisibility(View.VISIBLE);
1728b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        } else {
1738b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            mNumberLabel.setVisibility(View.GONE);
1748b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
1758b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
1768b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    }
1778b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
1788b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    @Override
1798b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng    public void setPrimary(String number, String name, boolean nameIsNumber, String label,
180625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon            Drawable photo, boolean isConference, boolean isGeneric, boolean isSipCall) {
1815c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        Log.d(this, "Setting primary call");
182a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon
1838b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (isConference) {
184625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon            name = getConferenceString(isGeneric);
185625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon            photo = getConferencePhoto(isGeneric);
1860f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            nameIsNumber = false;
1874bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        }
1887ef707319c0e3563ff92a772ba53cb5dca0e3ae1Yorke Lee
1898b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        setPrimaryPhoneNumber(number);
1908b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
1918b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        // set the name field.
1928b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        setPrimaryName(name, nameIsNumber);
1938b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
1944bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        // Set the label (Mobile, Work, etc)
1958b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        setPrimaryLabel(label);
1964bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon
197c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee        showInternetCallLabel(isSipCall);
198c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee
1994bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        setDrawableToImageView(mPhoto, photo);
2004bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon    }
2014bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon
2024bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon    @Override
2034be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee    public void setSecondary(boolean show, String name, boolean nameIsNumber, String label,
204625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon            Drawable photo, boolean isConference, boolean isGeneric) {
2054bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon
2064bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        if (show) {
2070f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            if (isConference) {
208625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon                name = getConferenceString(isGeneric);
209625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon                photo = getConferencePhoto(isGeneric);
2100f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                nameIsNumber = false;
2110f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            }
2120f09a02be361d5bb36fac6981649204f5d6987faChristine Chen
2134bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            showAndInitializeSecondaryCallInfo();
2144bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            mSecondaryCallName.setText(name);
2154be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee
2164be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee            int nameDirection = View.TEXT_DIRECTION_INHERIT;
2174be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee            if (nameIsNumber) {
2184be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee                nameDirection = View.TEXT_DIRECTION_LTR;
2194be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee            }
2204be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee            mSecondaryCallName.setTextDirection(nameDirection);
2214be1bdd9ee8e9d3afa1aaa765e86b963fb6c7b3dYorke Lee
2224bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            setDrawableToImageView(mSecondaryPhoto, photo);
2234bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        } else {
2244bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            mSecondaryCallInfo.setVisibility(View.GONE);
2254bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        }
226a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon    }
227a012c22dfbfedffe2e751f9b1ab776baa325a26fSantos Cordon
228a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon    @Override
22914dbc3f0ca3a7998c9c5d28aba637487724f529fSantos Cordon    public void setSecondaryImage(Drawable image) {
23014dbc3f0ca3a7998c9c5d28aba637487724f529fSantos Cordon        if (image != null) {
23114dbc3f0ca3a7998c9c5d28aba637487724f529fSantos Cordon            setDrawableToImageView(mSecondaryPhoto, image);
232af2589a6aa68d9906fe46b31ffaf214010632c02Chiao Cheng        }
233af2589a6aa68d9906fe46b31ffaf214010632c02Chiao Cheng    }
234af2589a6aa68d9906fe46b31ffaf214010632c02Chiao Cheng
235af2589a6aa68d9906fe46b31ffaf214010632c02Chiao Cheng    @Override
2365c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki    public void setCallState(int state, Call.DisconnectCause cause, boolean bluetoothOn,
2375c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            String gatewayLabel, String gatewayNumber) {
238a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        String callStateLabel = null;
239a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
240a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        // States other than disconnected not yet supported
241b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        callStateLabel = getCallStateLabelFromState(state, cause);
242a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
243ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen        Log.v(this, "setCallState " + callStateLabel);
244ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen        Log.v(this, "DisconnectCause " + cause);
245ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen        Log.v(this, "bluetooth on " + bluetoothOn);
2465c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        Log.v(this, "gateway " + gatewayLabel + gatewayNumber);
2475c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki
2485c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        // There are cases where we totally skip the animation, in which case remove the transition
2495c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        // animation here and restore it afterwards.
250672b16d0620d033e10fab30ccd70f5dd23e823b7Santos Cordon        final boolean skipAnimation = (Call.State.isDialing(state)
251ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen                || state == Call.State.DISCONNECTED || state == Call.State.DISCONNECTING);
2525c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        LayoutTransition transition = null;
2535c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        if (skipAnimation) {
2545c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            transition = mSupplementaryInfoContainer.getLayoutTransition();
2555c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            mSupplementaryInfoContainer.setLayoutTransition(null);
2565c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        }
257a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
2585c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        // Update the call state label.
259a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        if (!TextUtils.isEmpty(callStateLabel)) {
260a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            mCallStateLabel.setVisibility(View.VISIBLE);
261a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            mCallStateLabel.setText(callStateLabel);
262b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
263b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            if (Call.State.INCOMING == state) {
264b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon                setBluetoothOn(bluetoothOn);
265b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            }
266a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        } else {
267a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            mCallStateLabel.setVisibility(View.GONE);
268a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            // Gravity is aligned left when receiving an incoming call in landscape.
269a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            // In that rare case, the gravity needs to be reset to the right.
270a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            // Also, setText("") is used since there is a delay in making the view GONE,
271a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            // so the user will otherwise see the text jump to the right side before disappearing.
272a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            if(mCallStateLabel.getGravity() != Gravity.END) {
273a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                mCallStateLabel.setText("");
274a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                mCallStateLabel.setGravity(Gravity.END);
275a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            }
276a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        }
2775c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki
2785c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        // Provider info: (e.g. "Calling via <gatewayLabel>")
2795c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        if (!TextUtils.isEmpty(gatewayLabel) && !TextUtils.isEmpty(gatewayNumber)) {
2805c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            mProviderLabel.setText(gatewayLabel);
2815c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            mProviderNumber.setText(gatewayNumber);
2825c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            mProviderInfo.setVisibility(View.VISIBLE);
2835c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        } else {
2845c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            mProviderInfo.setVisibility(View.GONE);
2855c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        }
2865c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki
2875c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        // Restore the animation.
2885c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        if (skipAnimation) {
2895c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki            mSupplementaryInfoContainer.setLayoutTransition(transition);
2905c1830662d8daca84aae65c2eddf88c19c7772f1Makoto Onuki        }
291a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon    }
292a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
293c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee    private void showInternetCallLabel(boolean show) {
294c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee        if (show) {
295c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee            final String label = getView().getContext().getString(
296c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee                    R.string.incall_call_type_label_sip);
297c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee            mCallTypeLabel.setVisibility(View.VISIBLE);
298c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee            mCallTypeLabel.setText(label);
299c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee        } else {
300c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee            mCallTypeLabel.setVisibility(View.GONE);
301c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee        }
302c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee    }
303c59f3c672a0494cfba564ff117eafc1ab5e17641Yorke Lee
30488dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon    @Override
30588dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon    public void setPrimaryCallElapsedTime(boolean show, String callTimeElapsed) {
30688dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon        if (show) {
30788dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon            if (mElapsedTime.getVisibility() != View.VISIBLE) {
30888dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon                AnimationUtils.Fade.show(mElapsedTime);
30988dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon            }
31088dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon            mElapsedTime.setText(callTimeElapsed);
31188dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon        } else {
31288dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon            // hide() animation has no effect if it is already hidden.
31388dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon            AnimationUtils.Fade.hide(mElapsedTime, View.INVISIBLE);
31488dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon        }
31588dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon    }
31688dbc6b3dbf35b322fe09c1a289c7e884e8fba22Santos Cordon
3174bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon    private void setDrawableToImageView(ImageView view, Drawable photo) {
3184bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        if (photo == null) {
3190e27ca6253114be60b85f912a1af62dbf35c1b9eSantos Cordon            photo = view.getResources().getDrawable(R.drawable.picture_unknown);
3204bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        }
3214bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon
3224bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        final Drawable current = view.getDrawable();
3234bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        if (current == null) {
3244bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            view.setImageDrawable(photo);
3254bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            AnimationUtils.Fade.show(view);
3264bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        } else {
3274bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            AnimationUtils.startCrossFade(view, current, photo);
328625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon            view.setVisibility(View.VISIBLE);
3294bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        }
3304bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon    }
3314bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon
332625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon    private String getConferenceString(boolean isGeneric) {
333625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon        Log.v(this, "isGenericString: " + isGeneric);
334625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon        final int resId = isGeneric ? R.string.card_title_in_call : R.string.card_title_conf_call;
335625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon        return getView().getResources().getString(resId);
336625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon    }
337625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon
338625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon    private Drawable getConferencePhoto(boolean isGeneric) {
339625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon        Log.v(this, "isGenericPhoto: " + isGeneric);
340625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon        final int resId = isGeneric ? R.drawable.picture_dialing : R.drawable.picture_conference;
341625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon        return getView().getResources().getDrawable(resId);
342625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon    }
343625ac576cb403744ef0baeba8e8993da963461eeSantos Cordon
344b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon    private void setBluetoothOn(boolean onOff) {
345b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        // Also, display a special icon (alongside the "Incoming call"
346b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        // label) if there's an incoming call and audio will be routed
347b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        // to bluetooth when you answer it.
348cff70d5848ce3dcd13e41e5b156602ff2a3ff785Christine Chen        final int bluetoothIconId = R.drawable.ic_in_call_bt_dk;
349b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
350b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        if (onOff) {
351b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            mCallStateLabel.setCompoundDrawablesWithIntrinsicBounds(bluetoothIconId, 0, 0, 0);
352b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            mCallStateLabel.setCompoundDrawablePadding((int) (mDensity * 5));
353b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        } else {
354b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            // Clear out any icons
355b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            mCallStateLabel.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
356b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        }
357b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon    }
358b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
359b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon    /**
360b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon     * Gets the call state label based on the state of the call and
361b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon     * cause of disconnect
362b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon     */
363b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon    private String getCallStateLabelFromState(int state, Call.DisconnectCause cause) {
364b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        final Context context = getView().getContext();
365b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        String callStateLabel = null;  // Label to display as part of the call banner
366b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
367b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        if (Call.State.IDLE == state) {
368b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            // "Call state" is meaningless in this state.
369b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
370b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        } else if (Call.State.ACTIVE == state) {
371b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            // We normally don't show a "call state label" at all in
372b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            // this state (but see below for some special cases).
373b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
374b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        } else if (Call.State.ONHOLD == state) {
375b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            callStateLabel = context.getString(R.string.card_title_on_hold);
376b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        } else if (Call.State.DIALING == state) {
377b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            callStateLabel = context.getString(R.string.card_title_dialing);
378672b16d0620d033e10fab30ccd70f5dd23e823b7Santos Cordon        } else if (Call.State.REDIALING == state) {
379672b16d0620d033e10fab30ccd70f5dd23e823b7Santos Cordon            callStateLabel = context.getString(R.string.card_title_redialing);
380b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        } else if (Call.State.INCOMING == state || Call.State.CALL_WAITING == state) {
381b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            callStateLabel = context.getString(R.string.card_title_incoming_call);
382b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
383ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen        } else if (Call.State.DISCONNECTING == state) {
384ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen            // While in the DISCONNECTING state we display a "Hanging up"
385ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen            // message in order to make the UI feel more responsive.  (In
386ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen            // GSM it's normal to see a delay of a couple of seconds while
387ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen            // negotiating the disconnect with the network, so the "Hanging
388ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen            // up" state at least lets the user know that we're doing
389ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen            // something.  This state is currently not used with CDMA.)
390ecabb6923e6587e0f0ca98cc895be7d99e694015Christine Chen            callStateLabel = context.getString(R.string.card_title_hanging_up);
391b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
392b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        } else if (Call.State.DISCONNECTED == state) {
393b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon            callStateLabel = getCallFailedString(cause);
394b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
395b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        } else {
3961a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng            Log.wtf(this, "updateCallStateWidgets: unexpected call: " + state);
397b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        }
398b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
399b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon        return callStateLabel;
400b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon    }
401b70af18a174fa334d15b28a2cdaa617f9ba2a4b7Santos Cordon
402a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon    /**
403a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon     * Maps the disconnect cause to a resource string.
404a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon     */
405a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon    private String getCallFailedString(Call.DisconnectCause cause) {
406a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        int resID = R.string.card_title_call_ended;
407a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
408a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        // TODO: The card *title* should probably be "Call ended" in all
409a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        // cases, but if the DisconnectCause was an error condition we should
410a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        // probably also display the specific failure reason somewhere...
411a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
412a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        switch (cause) {
413a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case BUSY:
414a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_userBusy;
415a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
416a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
417a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case CONGESTION:
418a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_congestion;
419a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
420a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
421a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case TIMED_OUT:
422a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_timedOut;
423a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
424a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
425a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case SERVER_UNREACHABLE:
426a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_server_unreachable;
427a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
428a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
429a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case NUMBER_UNREACHABLE:
430a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_number_unreachable;
431a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
432a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
433a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case INVALID_CREDENTIALS:
434a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_invalid_credentials;
435a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
436a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
437a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case SERVER_ERROR:
438a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_server_error;
439a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
440a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
441a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case OUT_OF_NETWORK:
442a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_out_of_network;
443a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
444a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
445a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case LOST_SIGNAL:
446a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case CDMA_DROP:
447a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_noSignal;
448a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
449a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
450a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case LIMIT_EXCEEDED:
451a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_limitExceeded;
452a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
453a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
454a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case POWER_OFF:
455a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_powerOff;
456a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
457a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
458a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case ICC_ERROR:
459a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_simError;
460a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
461a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
462a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case OUT_OF_SERVICE:
463a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_outOfService;
464a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
465a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
466a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case INVALID_NUMBER:
467a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            case UNOBTAINABLE_NUMBER:
468a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.callFailed_unobtainable_number;
469a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
470a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
471a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon            default:
472a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                resID = R.string.card_title_call_ended;
473a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon                break;
474a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        }
475a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon        return this.getView().getContext().getString(resID);
476a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon    }
477a12f2589f424e26c63c8ee5b6fad89e30b69d7fbSantos Cordon
478150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon    private void showAndInitializeSecondaryCallInfo() {
479150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon        mSecondaryCallInfo.setVisibility(View.VISIBLE);
480150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon
481150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon        // mSecondaryCallName is initialized here (vs. onViewCreated) because it is inaccesible
482150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon        // until mSecondaryCallInfo is inflated in the call above.
483150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon        if (mSecondaryCallName == null) {
484150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon            mSecondaryCallName = (TextView) getView().findViewById(R.id.secondaryCallName);
485150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon        }
4864bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon        if (mSecondaryPhoto == null) {
4874bbe4c6900dfe3584f674161dbe15e248d5adbe7Santos Cordon            mSecondaryPhoto = (ImageView) getView().findViewById(R.id.secondaryCallPhoto);
488988d06b64b99a13f4f060dc82594edcb738d9113Yorke Lee        }
4899240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee
4909240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee        if (mSecondaryPhotoOverlay == null) {
4919240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee            mSecondaryPhotoOverlay = getView().findViewById(R.id.dim_effect_for_secondary_photo);
4929240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee            mSecondaryPhotoOverlay.setOnClickListener(new OnClickListener() {
4939240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee                @Override
4949240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee                public void onClick(View v) {
4959240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee                    getPresenter().secondaryPhotoClicked();
4969240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee                }
4979240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee            });
498083c494c07681cdb826a1f2958d2143cf694de82Santos Cordon            mSecondaryPhotoOverlay.setOnTouchListener(new SmallerHitTargetTouchListener());
4999240895e9df2fcae8f0baea707eb4d24c6e50997Yorke Lee        }
500988d06b64b99a13f4f060dc82594edcb738d9113Yorke Lee    }
501442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee
502442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee    public void dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
503442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
504442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee            dispatchPopulateAccessibilityEvent(event, mPrimaryName);
505442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee            dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
506442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee            return;
507442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        }
508442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        dispatchPopulateAccessibilityEvent(event, mCallStateLabel);
509442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        dispatchPopulateAccessibilityEvent(event, mPrimaryName);
510442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
511442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        dispatchPopulateAccessibilityEvent(event, mCallTypeLabel);
512442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        dispatchPopulateAccessibilityEvent(event, mSecondaryCallName);
513442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee
514442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        return;
515442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee    }
516442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee
517442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee    private void dispatchPopulateAccessibilityEvent(AccessibilityEvent event, View view) {
518442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        if (view == null) return;
519442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        final List<CharSequence> eventText = event.getText();
520442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        int size = eventText.size();
521442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        view.dispatchPopulateAccessibilityEvent(event);
522442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        // if no text added write null to keep relative position
523442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        if (size == eventText.size()) {
524442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee            eventText.add(null);
525442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee        }
526442721af112b39d5f85cc3c1ecd341855a300555Yorke Lee    }
527e331d604d5ab345b06976c0ff7a930930f6b9e41Chiao Cheng}
528