From c1d1e8418d20edc5871b45263f43b9c28da2633d Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Mon, 9 Mar 2015 11:43:27 -0700 Subject: Dynamically add AnswerFragment AnswerPresenter is a little tricky because it is in charge of responding to incoming calls, so we want it to be alive and getting onIncomingCall callbacks, but we don't want to create an instance of AnswerFragment, which it is dependent on. Move some dependencies around so that AnswerPresenter is created by InCallPresenter instead. It registers for callbacks via InCallPresenter instead of directly to CallList, and shows/hides the AnswerFragment via InCallActivity. Change-Id: I7026150988bf3cda762dda8a319f48e1af132361 --- InCallUI/res/layout-land/call_card_content.xml | 132 ------------------- InCallUI/res/layout-land/call_card_fragment.xml | 122 ++++++++++++++++++ InCallUI/res/layout/answer_fragment.xml | 6 +- InCallUI/res/layout/call_card_content.xml | 139 --------------------- InCallUI/res/layout/call_card_fragment.xml | 130 +++++++++++++++++++ .../src/com/android/incallui/AnswerFragment.java | 10 +- .../src/com/android/incallui/AnswerPresenter.java | 109 ++++++++-------- .../src/com/android/incallui/CallCardFragment.java | 2 +- .../src/com/android/incallui/InCallActivity.java | 29 +++-- .../src/com/android/incallui/InCallPresenter.java | 11 ++ 10 files changed, 343 insertions(+), 347 deletions(-) delete mode 100644 InCallUI/res/layout-land/call_card_content.xml create mode 100644 InCallUI/res/layout-land/call_card_fragment.xml delete mode 100644 InCallUI/res/layout/call_card_content.xml create mode 100644 InCallUI/res/layout/call_card_fragment.xml diff --git a/InCallUI/res/layout-land/call_card_content.xml b/InCallUI/res/layout-land/call_card_content.xml deleted file mode 100644 index 496b6b399..000000000 --- a/InCallUI/res/layout-land/call_card_content.xml +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/InCallUI/res/layout-land/call_card_fragment.xml b/InCallUI/res/layout-land/call_card_fragment.xml new file mode 100644 index 000000000..4c76b95de --- /dev/null +++ b/InCallUI/res/layout-land/call_card_fragment.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InCallUI/res/layout/answer_fragment.xml b/InCallUI/res/layout/answer_fragment.xml index d663b837d..ec6ef30ac 100644 --- a/InCallUI/res/layout/answer_fragment.xml +++ b/InCallUI/res/layout/answer_fragment.xml @@ -19,13 +19,13 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dc="http://schemas.android.com/apk/res-auto" android:id="@+id/glow_pad_view" - android:layout_width="wrap_content" - android:layout_height="wrap_content" + android:layout_width="match_parent" + android:layout_height="match_parent" android:focusable="true" android:layout_centerHorizontal="true" android:gravity="center" android:background="@color/glowpad_background_color" - android:visibility="gone" + android:layout_marginBottom="@dimen/glowpadview_margin_bottom" dc:targetDrawables="@array/incoming_call_widget_audio_with_sms_targets" dc:targetDescriptions="@array/incoming_call_widget_audio_with_sms_target_descriptions" diff --git a/InCallUI/res/layout/call_card_content.xml b/InCallUI/res/layout/call_card_content.xml deleted file mode 100644 index 7a42586ea..000000000 --- a/InCallUI/res/layout/call_card_content.xml +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/InCallUI/res/layout/call_card_fragment.xml b/InCallUI/res/layout/call_card_fragment.xml new file mode 100644 index 000000000..920f8cb4d --- /dev/null +++ b/InCallUI/res/layout/call_card_fragment.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InCallUI/src/com/android/incallui/AnswerFragment.java b/InCallUI/src/com/android/incallui/AnswerFragment.java index cb09dfdcc..8cbce10c6 100644 --- a/InCallUI/src/com/android/incallui/AnswerFragment.java +++ b/InCallUI/src/com/android/incallui/AnswerFragment.java @@ -76,7 +76,7 @@ public class AnswerFragment extends BaseFragment - implements CallList.CallUpdateListener, CallList.Listener { + implements CallList.CallUpdateListener, InCallPresenter.InCallUiListener, + InCallPresenter.IncomingCallListener { private static final String TAG = AnswerPresenter.class.getSimpleName(); @@ -34,57 +42,33 @@ public class AnswerPresenter extends Presenter private boolean mHasTextMessages = false; @Override - public void onUiReady(AnswerUi ui) { - super.onUiReady(ui); - - final CallList calls = CallList.getInstance(); - Call call; - call = calls.getIncomingCall(); - if (call != null) { - processIncomingCall(call); - } - call = calls.getVideoUpgradeRequestCall(); - if (call != null) { - processVideoUpgradeRequestCall(call); - } - - // Listen for incoming calls. - calls.addListener(this); - } - - @Override - public void onUiUnready(AnswerUi ui) { - super.onUiUnready(ui); - - CallList.getInstance().removeListener(this); - - // This is necessary because the activity can be destroyed while an incoming call exists. - // This happens when back button is pressed while incoming call is still being shown. - if (mCallId != null) { - CallList.getInstance().removeCallUpdateListener(mCallId, this); + public void onUiShowing(boolean showing) { + if (showing) { + final CallList calls = CallList.getInstance(); + Call call; + call = calls.getIncomingCall(); + if (call != null) { + processIncomingCall(call); + } + call = calls.getVideoUpgradeRequestCall(); + if (call != null) { + processVideoUpgradeRequestCall(call); + } + } else { + // This is necessary because the activity can be destroyed while an incoming call exists. + // This happens when back button is pressed while incoming call is still being shown. + if (mCallId != null) { + CallList.getInstance().removeCallUpdateListener(mCallId, this); + } } } @Override - public void onCallListChange(CallList callList) { - // no-op - } - - @Override - public void onDisconnect(Call call) { - // no-op - } - - @Override - public void onIncomingCall(Call call) { - // TODO: Ui is being destroyed when the fragment detaches. Need clean up step to stop - // getting updates here. + public void onIncomingCall(InCallState oldState, InCallState newState, Call call) { Log.d(this, "onIncomingCall: " + this); - if (getUi() != null) { - if (!call.getId().equals(mCallId)) { - // A new call is coming in. - processIncomingCall(call); - } + if (!call.getId().equals(mCallId)) { + // A new call is coming in. + processIncomingCall(call); } } @@ -96,9 +80,20 @@ public class AnswerPresenter extends Presenter CallList.getInstance().addCallUpdateListener(mCallId, this); Log.d(TAG, "Showing incoming for call id: " + mCallId + " " + this); - final List textMsgs = CallList.getInstance().getTextResponses(call.getId()); - getUi().showAnswerUi(true); - configureAnswerTargetsForSms(call, textMsgs); + if (showAnswerUi(true)) { + final List textMsgs = CallList.getInstance().getTextResponses(call.getId()); + configureAnswerTargetsForSms(call, textMsgs); + } + } + + private boolean showAnswerUi(boolean show) { + final InCallActivity activity = InCallPresenter.getInstance().getActivity(); + if (activity != null) { + activity.showAnswerFragment(show); + return true; + } else { + return false; + } } private void processVideoUpgradeRequestCall(Call call) { @@ -107,7 +102,7 @@ public class AnswerPresenter extends Presenter // Listen for call updates for the current call. CallList.getInstance().addCallUpdateListener(mCallId, this); - getUi().showAnswerUi(true); + showAnswerUi(true); getUi().showTargets(AnswerFragment.TARGET_SET_FOR_VIDEO_UPGRADE_REQUEST); } @@ -119,7 +114,7 @@ public class AnswerPresenter extends Presenter // Stop listening for updates. CallList.getInstance().removeCallUpdateListener(mCallId, this); - getUi().showAnswerUi(false); + showAnswerUi(false); // mCallId will hold the state of the call. We don't clear the mCall variable here as // it may be useful for sending text messages after phone disconnects. @@ -175,6 +170,10 @@ public class AnswerPresenter extends Presenter } private void configureAnswerTargetsForSms(Call call, List textMsgs) { + if (getUi() == null) { + return; + } + final Context context = getUi().getContext(); mHasTextMessages = textMsgs != null; @@ -199,7 +198,7 @@ public class AnswerPresenter extends Presenter } interface AnswerUi extends Ui { - public void showAnswerUi(boolean show); + public void onShowAnswerUi(boolean shown); public void showTargets(int targetSet); public void showMessageDialog(); public void configureMessageDialog(List textResponses); diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java index 1b17d35d3..6d7e1d581 100644 --- a/InCallUI/src/com/android/incallui/CallCardFragment.java +++ b/InCallUI/src/com/android/incallui/CallCardFragment.java @@ -149,7 +149,7 @@ public class CallCardFragment extends BaseFragment