1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.incallui;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.TextView;
/**
* Fragment for call card.
*/
public class CallCardFragment extends BaseFragment<CallCardPresenter>
implements CallCardPresenter.CallCardUi {
private TextView mPhoneNumber;
private TextView mNumberLabel;
private TextView mName;
private ViewStub mSecondaryCallInfo;
private TextView mSecondaryCallName;
@Override
CallCardPresenter createPresenter() {
return new CallCardPresenter();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.call_card, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mPhoneNumber = (TextView) view.findViewById(R.id.phoneNumber);
mName = (TextView) view.findViewById(R.id.name);
mNumberLabel = (TextView) view.findViewById(R.id.label);
mSecondaryCallInfo = (ViewStub) view.findViewById(R.id.secondary_call_info);
// This method call will begin the callbacks on CallCardUi. We need to ensure
// everything needed for the callbacks is set up before this is called.
getPresenter().onUiReady(this);
}
@Override
public void setVisible(boolean on) {
if (on) {
getView().setVisibility(View.VISIBLE);
} else {
getView().setVisibility(View.INVISIBLE);
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
getPresenter().setContext(activity);
}
@Override
public void setSecondaryCallInfo(boolean show, String number) {
if (show) {
showAndInitializeSecondaryCallInfo();
// Until we have the name source, use the number as the main text for secondary calls.
mSecondaryCallName.setText(number);
} else {
mSecondaryCallInfo.setVisibility(View.GONE);
}
}
@Override
public void setNumber(String number) {
if (!TextUtils.isEmpty(number)) {
mPhoneNumber.setText(number);
mPhoneNumber.setVisibility(View.VISIBLE);
// We have a real phone number as "mPhoneNumber" so make it always LTR
mPhoneNumber.setTextDirection(View.TEXT_DIRECTION_LTR);
} else {
mPhoneNumber.setVisibility(View.GONE);
}
}
@Override
public void setName(String name, boolean isNumber) {
mName.setText(name);
mName.setVisibility(View.VISIBLE);
if (isNumber) {
mName.setTextDirection(View.TEXT_DIRECTION_LTR);
} else {
mName.setTextDirection(View.TEXT_DIRECTION_INHERIT);
}
}
@Override
public void setName(String name) {
setName(name, false);
}
@Override
public void setNumberLabel(String label) {
if (!TextUtils.isEmpty(label)) {
mNumberLabel.setText(label);
mNumberLabel.setVisibility(View.VISIBLE);
} else {
mNumberLabel.setVisibility(View.GONE);
}
}
private void showAndInitializeSecondaryCallInfo() {
mSecondaryCallInfo.setVisibility(View.VISIBLE);
// mSecondaryCallName is initialized here (vs. onViewCreated) because it is inaccesible
// until mSecondaryCallInfo is inflated in the call above.
if (mSecondaryCallName == null) {
mSecondaryCallName = (TextView) getView().findViewById(R.id.secondaryCallName);
}
}
}
|