InCallUI负责显示来电界面,通话界面等信息,InCallUI主要显示界面是InCallActivity,有多个Fragment是附着在InCallActivity上。这些Fragment分别是CallCardFragment、CallButtonFragment、DialpadFragment、AnswerFragment、ConferenceManagerFragment、VideoCallFragment。
CallCardFragment:用于显示联系人信息及通话时间等;
CallButtonFragment:通话界面下方的控制按钮。
DialpadFragment:拨号盘显示控件。
AnswerFragment:来电控制控件,用于操作接听/拒接/短信快捷回复。
ConferenceManagerFragment:会议电话的界面。
VideoCallFragment:视屏通话控件。
我们可以先看一下InCallActivity的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main" >
</FrameLayout>
在InCallActivity中有着控制显示与隐藏Fragment的方法,如下所示:
private void showFragment(String tag, boolean show, boolean executeImmediately) {
Trace.beginSection("showFragment - " + tag);
final FragmentManager fm = getFragmentManagerForTag(tag);
if (fm == null) {
Log.w(TAG, "Fragment manager is null for : " + tag);
return;
}
Fragment fragment = fm.findFragmentByTag(tag);
if (!show && fragment == null) {
// Nothing to show, so bail early.
return;
}
final FragmentTransaction transaction = fm.beginTransaction();
if (show) {
if (fragment == null) {
fragment = createNewFragmentForTag(tag);
transaction.add(getContainerIdForFragment(tag), fragment, tag);
} else {
transaction.show(fragment);
}
} else {
transaction.hide(fragment);
}
transaction.commitAllowingStateLoss();
if (executeImmediately) {
fm.executePendingTransactions();
}
Trace.endSection();
}
private Fragment createNewFragmentForTag(String tag) {
if (TAG_DIALPAD_FRAGMENT.equals(tag)) {
mDialpadFragment = new DialpadFragment();
return mDialpadFragment;
} else if (TAG_ANSWER_FRAGMENT.equals(tag)) {
mAnswerFragment = new AnswerFragment();
return mAnswerFragment;
} else if (TAG_CONFERENCE_FRAGMENT.equals(tag)) {
mConferenceManagerFragment = new ConferenceManagerFragment();
return mConferenceManagerFragment;
} else if (TAG_CALLCARD_FRAGMENT.equals(tag)) {
mCallCardFragment = new CallCardFragment();
return mCallCardFragment;
}
throw new IllegalStateException("Unexpected fragment: " + tag);
}
private FragmentManager getFragmentManagerForTag(String tag) {
if (TAG_DIALPAD_FRAGMENT.equals(tag)) {
return mChildFragmentManager;
} else if (TAG_ANSWER_FRAGMENT.equals(tag)) {
return mChildFragmentManager;
} else if (TAG_CONFERENCE_FRAGMENT.equals(tag)) {
return getFragmentManager();
} else if (TAG_CALLCARD_FRAGMENT.equals(tag)) {
return getFragmentManager();
}
throw new IllegalStateException("Unexpected fragment: " + tag);
}
private int getContainerIdForFragment(String tag) {
if (TAG_DIALPAD_FRAGMENT.equals(tag)) {
return R.id.answer_and_dialpad_container;
} else if (TAG_ANSWER_FRAGMENT.equals(tag)) {
return R.id.answer_and_dialpad_container;
} else if (TAG_CONFERENCE_FRAGMENT.equals(tag)) {
return R.id.main;
} else if (TAG_CALLCARD_FRAGMENT.equals(tag)) {
return R.id.main;
}
throw new IllegalStateException("Unexpected fragment: " + tag);
}
从getContainnerIdForFragment方法我们得知CallCardFragment与ConferenceManagerFragment是依附于InCallActivity的布局,至于AnswerFragment与DialpadFragement是依附于CallCardFragment的布局中,我们可以看一下CallCardFragment的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<!-- The main content of the CallCard is either one or two "call info"
blocks, depending on whether one or two lines are in use.
The call_info blocks are stacked vertically inside a CallCard (LinearLayout),
each with layout_weight="1". If only one line is in use (i.e. the
common case) then the 2nd call info will be GONE and thus the 1st one
will expand to fill the full height of the CallCard. -->
<!-- Primary "call card" block, for the foreground call. -->
<LinearLayout
android:id="@+id/primary_call_info_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:elevation="@dimen/primary_call_elevation"
android:layout_centerHorizontal="true"
android:background="@color/incall_call_banner_background_color"
android:paddingTop="@dimen/call_banner_primary_call_container_top_padding"
android:clipChildren="false"
android:clipToPadding="false">
<include layout="@layout/primary_call_info" />
<fragment android:name="com.android.incallui.CallButtonFragment"
android:id="@+id/callButtonFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView android:id="@+id/connectionServiceMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone"
android:padding="@dimen/call_banner_side_padding"
android:background="@android:color/white" />
</LinearLayout>
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="@id/primary_call_info_container"
android:id="@+id/call_card_content">
<!-- Contact photo for primary call info -->
<ImageView android:id="@+id/photo"
android:layout_below="@id/primary_call_info_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="top|center_horizontal"
android:scaleType="centerCrop"
android:importantForAccessibility="no"
android:background="@android:color/white"
android:src="@drawable/img_no_image_automirrored" />
</FrameLayout>
<fragment android:name="com.android.incallui.VideoCallFragment"
android:id="@+id/videoCallFragment"
android:layout_alignParentTop="true"
android:layout_gravity="top|center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Progress spinner, useful for indicating pending operations such as upgrade to video. -->
<FrameLayout
android:id="@+id/progressSpinner"
android:layout_below="@id/primary_call_info_container"
android:background="#63000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone">
<ProgressBar
android:id="@+id/progress_bar"
style="@android:style/Widget.Material.ProgressBar"
android:layout_gravity="center"
android:layout_width="48dp"
android:layout_height="48dp"
android:indeterminate="true" />
</FrameLayout>
<!-- Secondary "Call info" block, for the background ("on hold") call. -->
<include layout="@layout/secondary_call_info" />
<include layout="@layout/manage_conference_call_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/primary_call_info_container" />
<!-- Placeholder for various fragments that are added dynamically underneath the caller info. -->
<FrameLayout
android:id="@+id/answer_and_dialpad_container"
android:layout_below="@id/primary_call_info_container"
android:layout_gravity="bottom|center_horizontal"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="@dimen/dialpad_elevation" />
<fragment android:name="com.android.incallui.ConferenceListFragment"
android:id="@+id/conferenceListFragment"
android:layout_below="@id/primary_call_info_container"
android:layout_gravity="bottom|center_horizontal"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="@dimen/dialpad_elevation"
android:visibility="gone"/>
<FrameLayout
android:id="@+id/floating_end_call_action_button_container"
android:layout_width="@dimen/end_call_floating_action_button_diameter"
android:layout_height="@dimen/end_call_floating_action_button_diameter"
android:background="@drawable/fab_red"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/end_call_button_margin_bottom"
android:layout_alignParentBottom="true" >
<ImageButton android:id="@+id/floating_end_call_action_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/end_call_background"
android:src="@drawable/fab_ic_end_call"
android:scaleType="center"
android:contentDescription="@string/onscreenEndCallText" />
</FrameLayout>
</RelativeLayout>
从中可以看到id为answer_and_dialpad_container的布局,也可以看到CallButtonFragment,ConfereneceManagerFragment是依附在CallCardFragment中。