diff options
Diffstat (limited to 'java/com/android/dialer/callcomposer/CallComposerActivity.java')
-rw-r--r-- | java/com/android/dialer/callcomposer/CallComposerActivity.java | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/java/com/android/dialer/callcomposer/CallComposerActivity.java b/java/com/android/dialer/callcomposer/CallComposerActivity.java index bc20c7314..63d29b514 100644 --- a/java/com/android/dialer/callcomposer/CallComposerActivity.java +++ b/java/com/android/dialer/callcomposer/CallComposerActivity.java @@ -26,10 +26,11 @@ import android.content.Intent; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.support.annotation.NonNull; +import android.support.annotation.VisibleForTesting; import android.support.v4.content.ContextCompat; import android.support.v4.content.FileProvider; -import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.support.v7.app.AppCompatActivity; @@ -42,6 +43,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.QuickContactBadge; import android.widget.RelativeLayout; import android.widget.TextView; @@ -53,6 +55,8 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.UiUtil; import com.android.dialer.common.concurrent.DialerExecutors; +import com.android.dialer.common.concurrent.ThreadUtil; +import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.constants.Constants; import com.android.dialer.dialercontact.DialerContact; import com.android.dialer.enrichedcall.EnrichedCallComponent; @@ -67,6 +71,7 @@ import com.android.dialer.protos.ProtoParsers; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.ViewUtil; import com.android.dialer.widget.DialerToolbar; +import com.android.dialer.widget.LockableViewPager; import com.google.protobuf.InvalidProtocolBufferException; import java.io.File; @@ -96,10 +101,18 @@ public class CallComposerActivity extends AppCompatActivity private static final String ARG_CALL_COMPOSER_CONTACT_BASE64 = "CALL_COMPOSER_CONTACT_BASE64"; private static final String ENTRANCE_ANIMATION_KEY = "entrance_animation_key"; + private static final String SEND_AND_CALL_READY_KEY = "send_and_call_ready_key"; private static final String CURRENT_INDEX_KEY = "current_index_key"; private static final String VIEW_PAGER_STATE_KEY = "view_pager_state_key"; private static final String SESSION_ID_KEY = "session_id_key"; + private final Handler timeoutHandler = ThreadUtil.getUiThreadHandler(); + private final Runnable sessionStartedTimedOut = + () -> { + LogUtil.i("CallComposerActivity.sessionStartedTimedOutRunnable", "session never started"); + setFailedResultAndFinish(); + }; + private DialerContact contact; private Long sessionId = Session.NO_SESSION_ID; @@ -111,10 +124,11 @@ public class CallComposerActivity extends AppCompatActivity private View sendAndCall; private TextView sendAndCallText; + private ProgressBar loading; private ImageView cameraIcon; private ImageView galleryIcon; private ImageView messageIcon; - private ViewPager pager; + private LockableViewPager pager; private CallComposerPagerAdapter adapter; private FrameLayout background; @@ -124,6 +138,7 @@ public class CallComposerActivity extends AppCompatActivity private boolean shouldAnimateEntrance = true; private boolean inFullscreenMode; private boolean isSendAndCallHidingOrHidden = true; + private boolean sendAndCallReady; private int currentIndex; public static Intent newIntent(Context context, DialerContact contact) { @@ -150,6 +165,7 @@ public class CallComposerActivity extends AppCompatActivity toolbar = findViewById(R.id.toolbar); sendAndCall = findViewById(R.id.send_and_call_button); sendAndCallText = findViewById(R.id.send_and_call_text); + loading = findViewById(R.id.call_composer_loading); interpolator = new FastOutSlowInInterpolator(); adapter = @@ -168,6 +184,7 @@ public class CallComposerActivity extends AppCompatActivity if (savedInstanceState != null) { shouldAnimateEntrance = savedInstanceState.getBoolean(ENTRANCE_ANIMATION_KEY); + sendAndCallReady = savedInstanceState.getBoolean(SEND_AND_CALL_READY_KEY); pager.onRestoreInstanceState(savedInstanceState.getParcelable(VIEW_PAGER_STATE_KEY)); currentIndex = savedInstanceState.getInt(CURRENT_INDEX_KEY); sessionId = savedInstanceState.getLong(SESSION_ID_KEY, Session.NO_SESSION_ID); @@ -212,6 +229,7 @@ public class CallComposerActivity extends AppCompatActivity protected void onPause() { super.onPause(); getEnrichedCallManager().unregisterStateChangedListener(this); + timeoutHandler.removeCallbacks(sessionStartedTimedOut); } @Override @@ -231,12 +249,36 @@ public class CallComposerActivity extends AppCompatActivity "state: %s", StateExtension.toString(state)); - if (state == EnrichedCallManager.STATE_START_FAILED - || state == EnrichedCallManager.STATE_CLOSED) { - setFailedResultAndFinish(); + switch (state) { + case EnrichedCallManager.STATE_STARTING: + timeoutHandler.postDelayed(sessionStartedTimedOut, getSessionStartedTimeoutMillis()); + if (sendAndCallReady) { + showLoadingUi(); + } + break; + case EnrichedCallManager.STATE_STARTED: + timeoutHandler.removeCallbacks(sessionStartedTimedOut); + if (sendAndCallReady) { + sendAndCall(); + } + break; + case EnrichedCallManager.STATE_START_FAILED: + case EnrichedCallManager.STATE_CLOSED: + setFailedResultAndFinish(); + break; + case EnrichedCallManager.STATE_MESSAGE_FAILED: + case EnrichedCallManager.STATE_MESSAGE_SENT: + case EnrichedCallManager.STATE_NONE: + default: + break; } } + @VisibleForTesting + public long getSessionStartedTimeoutMillis() { + return ConfigProviderBindings.get(this).getLong("ec_session_started_timeout", 10_000); + } + @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); @@ -262,6 +304,8 @@ public class CallComposerActivity extends AppCompatActivity @Override public void sendAndCall() { if (!sessionReady()) { + sendAndCallReady = true; + showLoadingUi(); LogUtil.i("CallComposerActivity.onClick", "sendAndCall pressed, but the session isn't ready"); Logger.get(this) .logImpression( @@ -329,6 +373,11 @@ public class CallComposerActivity extends AppCompatActivity } } + private void showLoadingUi() { + loading.setVisibility(View.VISIBLE); + pager.setSwipingLocked(true); + } + private boolean sessionReady() { Session session = getEnrichedCallManager().getSession(sessionId); return session != null && session.getState() == EnrichedCallManager.STATE_STARTED; @@ -363,10 +412,6 @@ public class CallComposerActivity extends AppCompatActivity } if (currentIndex == CallComposerPagerAdapter.INDEX_MESSAGE) { UiUtil.hideKeyboardFrom(this, windowContainer); - } else if (position == CallComposerPagerAdapter.INDEX_MESSAGE - && inFullscreenMode - && !isLandscapeLayout()) { - UiUtil.openKeyboardFrom(this, windowContainer); } currentIndex = position; CallComposerFragment fragment = (CallComposerFragment) adapter.instantiateItem(pager, position); @@ -385,6 +430,7 @@ public class CallComposerActivity extends AppCompatActivity super.onSaveInstanceState(outState); outState.putParcelable(VIEW_PAGER_STATE_KEY, pager.onSaveInstanceState()); outState.putBoolean(ENTRANCE_ANIMATION_KEY, shouldAnimateEntrance); + outState.putBoolean(SEND_AND_CALL_READY_KEY, sendAndCallReady); outState.putInt(CURRENT_INDEX_KEY, currentIndex); outState.putLong(SESSION_ID_KEY, sessionId); } |