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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
/*
* Copyright (C) 2016 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.dialer.callcomposer;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
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;
import android.text.TextUtils;
import android.util.Base64;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.QuickContactBadge;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.android.contacts.common.ContactPhotoManager;
import com.android.dialer.callcomposer.CallComposerFragment.CallComposerListener;
import com.android.dialer.callintent.CallInitiationType;
import com.android.dialer.callintent.CallIntentBuilder;
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.constants.Constants;
import com.android.dialer.dialercontact.DialerContact;
import com.android.dialer.enrichedcall.EnrichedCallComponent;
import com.android.dialer.enrichedcall.EnrichedCallManager;
import com.android.dialer.enrichedcall.EnrichedCallManager.State;
import com.android.dialer.enrichedcall.Session;
import com.android.dialer.enrichedcall.extensions.StateExtension;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.multimedia.MultimediaData;
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.google.protobuf.InvalidProtocolBufferException;
import java.io.File;
/**
* Implements an activity which prompts for a call with additional media for an outgoing call. The
* activity includes a pop up with:
*
* <ul>
* <li>Contact galleryIcon
* <li>Name
* <li>Number
* <li>Media options to attach a gallery image, camera image or a message
* </ul>
*/
public class CallComposerActivity extends AppCompatActivity
implements OnClickListener,
OnPageChangeListener,
CallComposerListener,
EnrichedCallManager.StateChangedListener {
public static final String KEY_CONTACT_NAME = "contact_name";
private static final int ENTRANCE_ANIMATION_DURATION_MILLIS = 500;
private static final int EXIT_ANIMATION_DURATION_MILLIS = 500;
private static final String ARG_CALL_COMPOSER_CONTACT = "CALL_COMPOSER_CONTACT";
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 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 DialerContact contact;
private Long sessionId = Session.NO_SESSION_ID;
private TextView nameView;
private TextView numberView;
private QuickContactBadge contactPhoto;
private RelativeLayout contactContainer;
private DialerToolbar toolbar;
private View sendAndCall;
private TextView sendAndCallText;
private ImageView cameraIcon;
private ImageView galleryIcon;
private ImageView messageIcon;
private ViewPager pager;
private CallComposerPagerAdapter adapter;
private FrameLayout background;
private LinearLayout windowContainer;
private FastOutSlowInInterpolator interpolator;
private boolean shouldAnimateEntrance = true;
private boolean inFullscreenMode;
private boolean isSendAndCallHidingOrHidden = true;
private int currentIndex;
public static Intent newIntent(Context context, DialerContact contact) {
Intent intent = new Intent(context, CallComposerActivity.class);
ProtoParsers.put(intent, ARG_CALL_COMPOSER_CONTACT, contact);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call_composer_activity);
nameView = findViewById(R.id.contact_name);
numberView = findViewById(R.id.phone_number);
contactPhoto = findViewById(R.id.contact_photo);
cameraIcon = findViewById(R.id.call_composer_camera);
galleryIcon = findViewById(R.id.call_composer_photo);
messageIcon = findViewById(R.id.call_composer_message);
contactContainer = findViewById(R.id.contact_bar);
pager = findViewById(R.id.call_composer_view_pager);
background = findViewById(R.id.background);
windowContainer = findViewById(R.id.call_composer_container);
toolbar = findViewById(R.id.toolbar);
sendAndCall = findViewById(R.id.send_and_call_button);
sendAndCallText = findViewById(R.id.send_and_call_text);
interpolator = new FastOutSlowInInterpolator();
adapter =
new CallComposerPagerAdapter(
getSupportFragmentManager(),
getResources().getInteger(R.integer.call_composer_message_limit));
pager.setAdapter(adapter);
pager.addOnPageChangeListener(this);
cameraIcon.setOnClickListener(this);
galleryIcon.setOnClickListener(this);
messageIcon.setOnClickListener(this);
sendAndCall.setOnClickListener(this);
onHandleIntent(getIntent());
if (savedInstanceState != null) {
shouldAnimateEntrance = savedInstanceState.getBoolean(ENTRANCE_ANIMATION_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);
onPageSelected(currentIndex);
}
// Since we can't animate the views until they are ready to be drawn, we use this listener to
// track that and animate the call compose UI as soon as it's ready.
ViewUtil.doOnPreDraw(
windowContainer,
false,
() -> {
showFullscreen(inFullscreenMode);
runEntranceAnimation();
});
setMediaIconSelected(currentIndex);
}
@Override
protected void onResume() {
super.onResume();
getEnrichedCallManager().registerStateChangedListener(this);
if (sessionId == Session.NO_SESSION_ID) {
LogUtil.i("CallComposerActivity.onResume", "creating new session");
sessionId = getEnrichedCallManager().startCallComposerSession(contact.getNumber());
} else if (getEnrichedCallManager().getSession(sessionId) == null) {
LogUtil.i(
"CallComposerActivity.onResume", "session closed while activity paused, creating new");
sessionId = getEnrichedCallManager().startCallComposerSession(contact.getNumber());
} else {
LogUtil.i("CallComposerActivity.onResume", "session still open, using old");
}
if (sessionId == Session.NO_SESSION_ID) {
LogUtil.w("CallComposerActivity.onResume", "failed to create call composer session");
setFailedResultAndFinish();
}
refreshUiForCallComposerState();
}
@Override
protected void onPause() {
super.onPause();
getEnrichedCallManager().unregisterStateChangedListener(this);
}
@Override
public void onEnrichedCallStateChanged() {
refreshUiForCallComposerState();
}
private void refreshUiForCallComposerState() {
Session session = getEnrichedCallManager().getSession(sessionId);
if (session == null) {
return;
}
@State int state = session.getState();
LogUtil.i(
"CallComposerActivity.refreshUiForCallComposerState",
"state: %s",
StateExtension.toString(state));
if (state == EnrichedCallManager.STATE_START_FAILED
|| state == EnrichedCallManager.STATE_CLOSED) {
setFailedResultAndFinish();
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
onHandleIntent(intent);
}
@Override
public void onClick(View view) {
LogUtil.enterBlock("CallComposerActivity.onClick");
if (view == cameraIcon) {
pager.setCurrentItem(CallComposerPagerAdapter.INDEX_CAMERA, true /* animate */);
} else if (view == galleryIcon) {
pager.setCurrentItem(CallComposerPagerAdapter.INDEX_GALLERY, true /* animate */);
} else if (view == messageIcon) {
pager.setCurrentItem(CallComposerPagerAdapter.INDEX_MESSAGE, true /* animate */);
} else if (view == sendAndCall) {
sendAndCall();
} else {
throw Assert.createIllegalStateFailException("View on click not implemented: " + view);
}
}
@Override
public void sendAndCall() {
if (!sessionReady()) {
LogUtil.i("CallComposerActivity.onClick", "sendAndCall pressed, but the session isn't ready");
Logger.get(this)
.logImpression(
DialerImpression.Type
.CALL_COMPOSER_ACTIVITY_SEND_AND_CALL_PRESSED_WHEN_SESSION_NOT_READY);
return;
}
sendAndCall.setEnabled(false);
CallComposerFragment fragment =
(CallComposerFragment) adapter.instantiateItem(pager, currentIndex);
MultimediaData.Builder builder = MultimediaData.builder();
if (fragment instanceof MessageComposerFragment) {
MessageComposerFragment messageComposerFragment = (MessageComposerFragment) fragment;
builder.setText(messageComposerFragment.getMessage());
placeRCSCall(builder);
}
if (fragment instanceof GalleryComposerFragment) {
GalleryComposerFragment galleryComposerFragment = (GalleryComposerFragment) fragment;
// If the current data is not a copy, make one.
if (!galleryComposerFragment.selectedDataIsCopy()) {
DialerExecutors.createUiTaskBuilder(
getFragmentManager(),
"copyAndResizeImageToSend",
new CopyAndResizeImageWorker(this.getApplicationContext()))
.onSuccess(
output -> {
Uri shareableUri =
FileProvider.getUriForFile(
CallComposerActivity.this,
Constants.get().getFileProviderAuthority(),
output.first);
builder.setImage(grantUriPermission(shareableUri), output.second);
placeRCSCall(builder);
})
.onFailure(
throwable -> {
// TODO(b/34279096) - gracefully handle message failure
LogUtil.e("CallComposerActivity.onCopyFailed", "copy Failed", throwable);
})
.build()
.executeParallel(galleryComposerFragment.getGalleryData().getFileUri());
} else {
Uri shareableUri =
FileProvider.getUriForFile(
this,
Constants.get().getFileProviderAuthority(),
new File(galleryComposerFragment.getGalleryData().getFilePath()));
builder.setImage(
grantUriPermission(shareableUri),
galleryComposerFragment.getGalleryData().getMimeType());
placeRCSCall(builder);
}
}
if (fragment instanceof CameraComposerFragment) {
CameraComposerFragment cameraComposerFragment = (CameraComposerFragment) fragment;
cameraComposerFragment.getCameraUriWhenReady(
uri -> {
builder.setImage(grantUriPermission(uri), cameraComposerFragment.getMimeType());
placeRCSCall(builder);
});
}
}
private boolean sessionReady() {
Session session = getEnrichedCallManager().getSession(sessionId);
return session != null && session.getState() == EnrichedCallManager.STATE_STARTED;
}
private void placeRCSCall(MultimediaData.Builder builder) {
LogUtil.i("CallComposerActivity.placeRCSCall", "placing enriched call");
Logger.get(this).logImpression(DialerImpression.Type.CALL_COMPOSER_ACTIVITY_PLACE_RCS_CALL);
getEnrichedCallManager().sendCallComposerData(sessionId, builder.build());
TelecomUtil.placeCall(
this,
new CallIntentBuilder(contact.getNumber(), CallInitiationType.Type.CALL_COMPOSER).build());
setResult(RESULT_OK);
finish();
}
/** Give permission to Messenger to view our image for RCS purposes. */
private Uri grantUriPermission(Uri uri) {
// TODO: Move this to the enriched call manager.
grantUriPermission(
"com.google.android.apps.messaging", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
return uri;
}
/** Animates {@code contactContainer} to align with content inside viewpager. */
@Override
public void onPageSelected(int position) {
if (position == CallComposerPagerAdapter.INDEX_MESSAGE) {
sendAndCallText.setText(R.string.send_and_call);
} else {
sendAndCallText.setText(R.string.share_and_call);
}
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);
animateSendAndCall(fragment.shouldHide());
setMediaIconSelected(position);
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
@Override
public void onPageScrollStateChanged(int state) {}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(VIEW_PAGER_STATE_KEY, pager.onSaveInstanceState());
outState.putBoolean(ENTRANCE_ANIMATION_KEY, shouldAnimateEntrance);
outState.putInt(CURRENT_INDEX_KEY, currentIndex);
outState.putLong(SESSION_ID_KEY, sessionId);
}
@Override
public void onBackPressed() {
if (!isSendAndCallHidingOrHidden) {
((CallComposerFragment) adapter.instantiateItem(pager, currentIndex)).clearComposer();
} else {
// Unregister first to avoid receiving a callback when the session closes
getEnrichedCallManager().unregisterStateChangedListener(this);
getEnrichedCallManager().endCallComposerSession(sessionId);
runExitAnimation();
}
}
@Override
public void composeCall(CallComposerFragment fragment) {
// Since our ViewPager restores state to our fragments, it's possible that they could call
// #composeCall, so we have to check if the calling fragment is the current fragment.
if (adapter.instantiateItem(pager, currentIndex) != fragment) {
return;
}
animateSendAndCall(fragment.shouldHide());
}
/**
* Reads arguments from the fragment arguments and populates the necessary instance variables.
* Copied from {@link com.android.contacts.common.dialog.CallSubjectDialog}.
*/
private void onHandleIntent(Intent intent) {
if (intent.getExtras().containsKey(ARG_CALL_COMPOSER_CONTACT_BASE64)) {
// Invoked from launch_call_composer.py. The proto is provided as a base64 encoded string.
byte[] bytes =
Base64.decode(intent.getStringExtra(ARG_CALL_COMPOSER_CONTACT_BASE64), Base64.DEFAULT);
try {
contact = DialerContact.parseFrom(bytes);
} catch (InvalidProtocolBufferException e) {
throw Assert.createAssertionFailException(e.toString());
}
} else {
contact =
ProtoParsers.getTrusted(
intent, ARG_CALL_COMPOSER_CONTACT, DialerContact.getDefaultInstance());
}
updateContactInfo();
}
@Override
public boolean isLandscapeLayout() {
return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}
/** Populates the contact info fields based on the current contact information. */
private void updateContactInfo() {
ContactPhotoManager.getInstance(this)
.loadDialerThumbnailOrPhoto(
contactPhoto,
contact.hasContactUri() ? Uri.parse(contact.getContactUri()) : null,
contact.getPhotoId(),
contact.hasPhotoUri() ? Uri.parse(contact.getPhotoUri()) : null,
contact.getNameOrNumber(),
contact.getContactType());
nameView.setText(contact.getNameOrNumber());
toolbar.setTitle(contact.getNameOrNumber());
if (!TextUtils.isEmpty(contact.getDisplayNumber())) {
numberView.setVisibility(View.VISIBLE);
String secondaryInfo =
TextUtils.isEmpty(contact.getNumberLabel())
? contact.getDisplayNumber()
: getString(
com.android.contacts.common.R.string.call_subject_type_and_number,
contact.getNumberLabel(),
contact.getDisplayNumber());
numberView.setText(secondaryInfo);
toolbar.setSubtitle(secondaryInfo);
} else {
numberView.setVisibility(View.GONE);
numberView.setText(null);
}
}
/** Animates compose UI into view */
private void runEntranceAnimation() {
if (!shouldAnimateEntrance) {
return;
}
shouldAnimateEntrance = false;
int value = isLandscapeLayout() ? windowContainer.getWidth() : windowContainer.getHeight();
ValueAnimator contentAnimation = ValueAnimator.ofFloat(value, 0);
contentAnimation.setInterpolator(interpolator);
contentAnimation.setDuration(ENTRANCE_ANIMATION_DURATION_MILLIS);
contentAnimation.addUpdateListener(
animation -> {
if (isLandscapeLayout()) {
windowContainer.setX((Float) animation.getAnimatedValue());
} else {
windowContainer.setY((Float) animation.getAnimatedValue());
}
});
if (!isLandscapeLayout()) {
int colorFrom = ContextCompat.getColor(this, android.R.color.transparent);
int colorTo = ContextCompat.getColor(this, R.color.call_composer_background_color);
ValueAnimator backgroundAnimation =
ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
backgroundAnimation.setInterpolator(interpolator);
backgroundAnimation.setDuration(ENTRANCE_ANIMATION_DURATION_MILLIS); // milliseconds
backgroundAnimation.addUpdateListener(
animator -> background.setBackgroundColor((int) animator.getAnimatedValue()));
AnimatorSet set = new AnimatorSet();
set.play(contentAnimation).with(backgroundAnimation);
set.start();
} else {
contentAnimation.start();
}
}
/** Animates compose UI out of view and ends the activity. */
private void runExitAnimation() {
int value = isLandscapeLayout() ? windowContainer.getWidth() : windowContainer.getHeight();
ValueAnimator contentAnimation = ValueAnimator.ofFloat(0, value);
contentAnimation.setInterpolator(interpolator);
contentAnimation.setDuration(EXIT_ANIMATION_DURATION_MILLIS);
contentAnimation.addUpdateListener(
animation -> {
if (isLandscapeLayout()) {
windowContainer.setX((Float) animation.getAnimatedValue());
} else {
windowContainer.setY((Float) animation.getAnimatedValue());
}
if (animation.getAnimatedFraction() > .95) {
finish();
}
});
if (!isLandscapeLayout()) {
int colorTo = ContextCompat.getColor(this, android.R.color.transparent);
int colorFrom = ContextCompat.getColor(this, R.color.call_composer_background_color);
ValueAnimator backgroundAnimation =
ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
backgroundAnimation.setInterpolator(interpolator);
backgroundAnimation.setDuration(EXIT_ANIMATION_DURATION_MILLIS);
backgroundAnimation.addUpdateListener(
animator -> background.setBackgroundColor((int) animator.getAnimatedValue()));
AnimatorSet set = new AnimatorSet();
set.play(contentAnimation).with(backgroundAnimation);
set.start();
} else {
contentAnimation.start();
}
}
@Override
public void showFullscreen(boolean fullscreen) {
inFullscreenMode = fullscreen;
ViewGroup.LayoutParams layoutParams = pager.getLayoutParams();
if (isLandscapeLayout()) {
layoutParams.height = background.getHeight();
toolbar.setVisibility(View.INVISIBLE);
contactContainer.setVisibility(View.GONE);
} else if (fullscreen || getResources().getBoolean(R.bool.show_toolbar)) {
layoutParams.height = background.getHeight() - toolbar.getHeight();
toolbar.setVisibility(View.VISIBLE);
contactContainer.setVisibility(View.GONE);
} else {
layoutParams.height =
getResources().getDimensionPixelSize(R.dimen.call_composer_view_pager_height);
toolbar.setVisibility(View.INVISIBLE);
contactContainer.setVisibility(View.VISIBLE);
}
pager.setLayoutParams(layoutParams);
}
@Override
public boolean isFullscreen() {
return inFullscreenMode;
}
private void animateSendAndCall(final boolean shouldHide) {
// createCircularReveal doesn't respect animations being disabled, handle it here.
if (ViewUtil.areAnimationsDisabled(this)) {
isSendAndCallHidingOrHidden = shouldHide;
sendAndCall.setVisibility(shouldHide ? View.INVISIBLE : View.VISIBLE);
return;
}
// If the animation is changing directions, start it again. Else do nothing.
if (isSendAndCallHidingOrHidden != shouldHide) {
int centerX = sendAndCall.getWidth() / 2;
int centerY = sendAndCall.getHeight() / 2;
int startRadius = shouldHide ? centerX : 0;
int endRadius = shouldHide ? 0 : centerX;
// When the device rotates and state is restored, the send and call button may not be attached
// yet and this causes a crash when we attempt to to reveal it. To prevent this, we wait until
// {@code sendAndCall} is ready, then animate and reveal it.
ViewUtil.doOnPreDraw(
sendAndCall,
true,
() -> {
Animator animator =
ViewAnimationUtils.createCircularReveal(
sendAndCall, centerX, centerY, startRadius, endRadius);
animator.addListener(
new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
isSendAndCallHidingOrHidden = shouldHide;
sendAndCall.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {
if (isSendAndCallHidingOrHidden) {
sendAndCall.setVisibility(View.INVISIBLE);
}
}
@Override
public void onAnimationCancel(Animator animation) {}
@Override
public void onAnimationRepeat(Animator animation) {}
});
animator.start();
});
}
}
private void setMediaIconSelected(int position) {
float alpha = 0.7f;
cameraIcon.setAlpha(position == CallComposerPagerAdapter.INDEX_CAMERA ? 1 : alpha);
galleryIcon.setAlpha(position == CallComposerPagerAdapter.INDEX_GALLERY ? 1 : alpha);
messageIcon.setAlpha(position == CallComposerPagerAdapter.INDEX_MESSAGE ? 1 : alpha);
}
private void setFailedResultAndFinish() {
setResult(
RESULT_FIRST_USER, new Intent().putExtra(KEY_CONTACT_NAME, contact.getNameOrNumber()));
finish();
}
@NonNull
private EnrichedCallManager getEnrichedCallManager() {
return EnrichedCallComponent.get(this).getEnrichedCallManager();
}
}
|