Messaging: Let there be lambdas
Change-Id: Iee1fc46c92ea9159abb10d92d34baee937bdee0c
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -121,23 +122,20 @@ public class AudioRecordView extends FrameLayout implements
|
||||
mHintTextView = (TextView) findViewById(R.id.hint_text);
|
||||
mTimerTextView = (PausableChronometer) findViewById(R.id.timer_text);
|
||||
mSoundLevels.setLevelSource(mMediaRecorder.getLevelSource());
|
||||
mRecordButton.setOnTouchListener(new OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(final View v, final MotionEvent event) {
|
||||
final int action = event.getActionMasked();
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
onRecordButtonTouchDown();
|
||||
mRecordButton.setOnTouchListener((v, event) -> {
|
||||
final int action = event.getActionMasked();
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
onRecordButtonTouchDown();
|
||||
|
||||
// Don't let the record button handle the down event to let it fall through
|
||||
// so that we can handle it for the entire panel in onTouchEvent(). This is
|
||||
// done so that: 1) the user taps on the record button to start recording
|
||||
// 2) the entire panel owns the touch event so we'd keep recording even
|
||||
// if the user moves outside the button region.
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
// Don't let the record button handle the down event to let it fall through
|
||||
// so that we can handle it for the entire panel in onTouchEvent(). This is
|
||||
// done so that: 1) the user taps on the record button to start recording
|
||||
// 2) the entire panel owns the touch event so we'd keep recording even
|
||||
// if the user moves outside the button region.
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -242,18 +240,15 @@ public class AudioRecordView extends FrameLayout implements
|
||||
boolean onRecordButtonTouchDown() {
|
||||
if (!mMediaRecorder.isRecording() && mCurrentMode == MODE_IDLE) {
|
||||
setMode(MODE_STARTING);
|
||||
playAudioStartSound(new OnCompletionListener() {
|
||||
@Override
|
||||
public void onCompletion() {
|
||||
// Double-check the current mode before recording since the user may have
|
||||
// lifted finger from the button before the beeping sound is played through.
|
||||
final int maxSize = MmsConfig.get(mHostInterface.getConversationSelfSubId())
|
||||
.getMaxMessageSize();
|
||||
if (mCurrentMode == MODE_STARTING &&
|
||||
mMediaRecorder.startRecording(AudioRecordView.this,
|
||||
AudioRecordView.this, maxSize)) {
|
||||
setMode(MODE_RECORDING);
|
||||
}
|
||||
playAudioStartSound(() -> {
|
||||
// Double-check the current mode before recording since the user may have
|
||||
// lifted finger from the button before the beeping sound is played through.
|
||||
final int maxSize = MmsConfig.get(mHostInterface.getConversationSelfSubId())
|
||||
.getMaxMessageSize();
|
||||
if (mCurrentMode == MODE_STARTING &&
|
||||
mMediaRecorder.startRecording(AudioRecordView.this,
|
||||
AudioRecordView.this, maxSize)) {
|
||||
setMode(MODE_RECORDING);
|
||||
}
|
||||
});
|
||||
mAudioRecordStartTimeMillis = System.currentTimeMillis();
|
||||
@@ -270,25 +265,17 @@ public class AudioRecordView extends FrameLayout implements
|
||||
// "tap+hold" to record audio.
|
||||
final Uri outputUri = stopRecording();
|
||||
if (outputUri != null) {
|
||||
SafeAsyncTask.executeOnThreadPool(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SafeAsyncTask.executeOnThreadPool(() ->
|
||||
Factory.get().getApplicationContext().getContentResolver().delete(
|
||||
outputUri, null, null);
|
||||
}
|
||||
});
|
||||
outputUri, null, null));
|
||||
}
|
||||
setMode(MODE_IDLE);
|
||||
mHintTextView.setTypeface(null, Typeface.BOLD);
|
||||
} else if (isRecording()) {
|
||||
// Record for some extra time to ensure the ending part is saved.
|
||||
setMode(MODE_STOPPING);
|
||||
ThreadUtil.getMainThreadHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onFinishedRecording();
|
||||
}
|
||||
}, AUDIO_RECORD_ENDING_BUFFER_MILLIS);
|
||||
ThreadUtil.getMainThreadHandler().postDelayed(this::onFinishedRecording,
|
||||
AUDIO_RECORD_ENDING_BUFFER_MILLIS);
|
||||
} else {
|
||||
setMode(MODE_IDLE);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.OrientationEventListener;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.messaging.datamodel.data.DraftMessageData.DraftMessageSubscriptionDataProvider;
|
||||
@@ -268,18 +267,15 @@ class CameraManager implements FocusOverlayManager.Listener {
|
||||
|
||||
if (preview != null) {
|
||||
Assert.isTrue(preview.isValid());
|
||||
preview.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(final View view, final MotionEvent motionEvent) {
|
||||
if ((motionEvent.getActionMasked() & MotionEvent.ACTION_UP) ==
|
||||
MotionEvent.ACTION_UP) {
|
||||
mFocusOverlayManager.setPreviewSize(view.getWidth(), view.getHeight());
|
||||
mFocusOverlayManager.onSingleTapUp(
|
||||
(int) motionEvent.getX() + view.getLeft(),
|
||||
(int) motionEvent.getY() + view.getTop());
|
||||
}
|
||||
return true;
|
||||
preview.setOnTouchListener((view, motionEvent) -> {
|
||||
if ((motionEvent.getActionMasked() & MotionEvent.ACTION_UP) ==
|
||||
MotionEvent.ACTION_UP) {
|
||||
mFocusOverlayManager.setPreviewSize(view.getWidth(), view.getHeight());
|
||||
mFocusOverlayManager.onSingleTapUp(
|
||||
(int) motionEvent.getX() + view.getLeft(),
|
||||
(int) motionEvent.getY() + view.getTop());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
mCameraPreview = preview;
|
||||
@@ -542,36 +538,33 @@ class CameraManager implements FocusOverlayManager.Listener {
|
||||
callback.onMediaFailed(null);
|
||||
return;
|
||||
}
|
||||
final Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
|
||||
@Override
|
||||
public void onPictureTaken(final byte[] bytes, final Camera camera) {
|
||||
mTakingPicture = false;
|
||||
if (mCamera != camera) {
|
||||
// This may happen if the camera was changed between front/back while the
|
||||
// picture is being taken.
|
||||
callback.onMediaInfo(MediaCallback.MEDIA_CAMERA_CHANGED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bytes == null) {
|
||||
callback.onMediaInfo(MediaCallback.MEDIA_NO_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
final Camera.Size size = camera.getParameters().getPictureSize();
|
||||
int width;
|
||||
int height;
|
||||
if (mRotation == 90 || mRotation == 270) {
|
||||
width = size.height;
|
||||
height = size.width;
|
||||
} else {
|
||||
width = size.width;
|
||||
height = size.height;
|
||||
}
|
||||
new ImagePersistTask(
|
||||
width, height, heightPercent, bytes, mCameraPreview.getContext(), callback)
|
||||
.executeOnThreadPool();
|
||||
final Camera.PictureCallback jpegCallback = (bytes, camera) -> {
|
||||
mTakingPicture = false;
|
||||
if (mCamera != camera) {
|
||||
// This may happen if the camera was changed between front/back while the
|
||||
// picture is being taken.
|
||||
callback.onMediaInfo(MediaCallback.MEDIA_CAMERA_CHANGED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bytes == null) {
|
||||
callback.onMediaInfo(MediaCallback.MEDIA_NO_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
final Camera.Size size = camera.getParameters().getPictureSize();
|
||||
int width;
|
||||
int height;
|
||||
if (mRotation == 90 || mRotation == 270) {
|
||||
width = size.height;
|
||||
height = size.width;
|
||||
} else {
|
||||
width = size.width;
|
||||
height = size.height;
|
||||
}
|
||||
new ImagePersistTask(
|
||||
width, height, heightPercent, bytes, mCameraPreview.getContext(), callback)
|
||||
.executeOnThreadPool();
|
||||
};
|
||||
|
||||
mTakingPicture = true;
|
||||
@@ -757,12 +750,8 @@ class CameraManager implements FocusOverlayManager.Listener {
|
||||
mCamera.setParameters(params);
|
||||
mCameraPreview.startPreview(mCamera);
|
||||
mCamera.startPreview();
|
||||
mCamera.setAutoFocusMoveCallback(new Camera.AutoFocusMoveCallback() {
|
||||
@Override
|
||||
public void onAutoFocusMoving(final boolean start, final Camera camera) {
|
||||
mFocusOverlayManager.onAutoFocusMoving(start);
|
||||
}
|
||||
});
|
||||
mCamera.setAutoFocusMoveCallback((start, camera) ->
|
||||
mFocusOverlayManager.onAutoFocusMoving(start));
|
||||
mFocusOverlayManager.setParameters(mCamera.getParameters());
|
||||
mFocusOverlayManager.setMirror(mCameraInfo.facing == CameraInfo.CAMERA_FACING_BACK);
|
||||
mFocusOverlayManager.onPreviewStarted();
|
||||
@@ -830,24 +819,17 @@ class CameraManager implements FocusOverlayManager.Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
mMediaRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {
|
||||
@Override
|
||||
public void onError(final MediaRecorder mediaRecorder, final int what,
|
||||
final int extra) {
|
||||
if (mListener != null) {
|
||||
mListener.onCameraError(ERROR_RECORDING_VIDEO, null);
|
||||
}
|
||||
restoreRequestedOrientation();
|
||||
mMediaRecorder.setOnErrorListener((mediaRecorder, what, extra) -> {
|
||||
if (mListener != null) {
|
||||
mListener.onCameraError(ERROR_RECORDING_VIDEO, null);
|
||||
}
|
||||
restoreRequestedOrientation();
|
||||
});
|
||||
|
||||
mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
|
||||
@Override
|
||||
public void onInfo(final MediaRecorder mediaRecorder, final int what, final int extra) {
|
||||
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED ||
|
||||
what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
|
||||
stopVideo();
|
||||
}
|
||||
mMediaRecorder.setOnInfoListener((mediaRecorder, what, extra) -> {
|
||||
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED ||
|
||||
what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
|
||||
stopVideo();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1094,12 +1076,8 @@ class CameraManager implements FocusOverlayManager.Listener {
|
||||
}
|
||||
|
||||
try {
|
||||
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(final boolean success, final Camera camera) {
|
||||
mFocusOverlayManager.onAutoFocus(success, false /* shutterDown */);
|
||||
}
|
||||
});
|
||||
mCamera.autoFocus((success, camera) -> mFocusOverlayManager.onAutoFocus(success,
|
||||
false /* shutterDown */));
|
||||
} catch (final RuntimeException e) {
|
||||
LogUtil.e(TAG, "RuntimeException in CameraManager.autoFocus", e);
|
||||
// If autofocus fails, the camera should have called the callback with success=false,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +25,6 @@ import android.hardware.Camera;
|
||||
import android.net.Uri;
|
||||
import android.os.SystemClock;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
@@ -92,120 +92,98 @@ class CameraMediaChooser extends MediaChooser implements
|
||||
false /* attachToRoot */);
|
||||
mCameraPreviewHost = (CameraPreview.CameraPreviewHost) view.findViewById(
|
||||
R.id.camera_preview);
|
||||
mCameraPreviewHost.getView().setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(final View view, final MotionEvent motionEvent) {
|
||||
if (CameraManager.get().isVideoMode()) {
|
||||
// Prevent the swipe down in video mode because video is always captured in
|
||||
// full screen
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
mCameraPreviewHost.getView().setOnTouchListener((view1, motionEvent) -> {
|
||||
if (CameraManager.get().isVideoMode()) {
|
||||
// Prevent the swipe down in video mode because video is always captured in
|
||||
// full screen
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
final View shutterVisual = view.findViewById(R.id.camera_shutter_visual);
|
||||
|
||||
mFullScreenButton = (ImageButton) view.findViewById(R.id.camera_fullScreen_button);
|
||||
mFullScreenButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
mMediaPicker.setFullScreen(true);
|
||||
}
|
||||
});
|
||||
mFullScreenButton.setOnClickListener(view12 -> mMediaPicker.setFullScreen(true));
|
||||
|
||||
mSwapCameraButton = (ImageButton) view.findViewById(R.id.camera_swapCamera_button);
|
||||
mSwapCameraButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
CameraManager.get().swapCamera();
|
||||
}
|
||||
});
|
||||
mSwapCameraButton.setOnClickListener(view13 -> CameraManager.get().swapCamera());
|
||||
|
||||
mCaptureButton = (ImageButton) view.findViewById(R.id.camera_capture_button);
|
||||
mCaptureButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
final float heightPercent = Math.min(mMediaPicker.getViewPager().getHeight() /
|
||||
(float) mCameraPreviewHost.getView().getHeight(), 1);
|
||||
mCaptureButton.setOnClickListener(v -> {
|
||||
final float heightPercent = Math.min(mMediaPicker.getViewPager().getHeight() /
|
||||
(float) mCameraPreviewHost.getView().getHeight(), 1);
|
||||
|
||||
if (CameraManager.get().isRecording()) {
|
||||
CameraManager.get().stopVideo();
|
||||
} else {
|
||||
final CameraManager.MediaCallback callback = new CameraManager.MediaCallback() {
|
||||
@Override
|
||||
public void onMediaReady(
|
||||
final Uri uriToVideo, final String contentType,
|
||||
final int width, final int height) {
|
||||
mVideoCounter.stop();
|
||||
if (mVideoCancelled || uriToVideo == null) {
|
||||
mVideoCancelled = false;
|
||||
} else {
|
||||
final Rect startRect = new Rect();
|
||||
// It's possible to throw out the chooser while taking the
|
||||
// picture/video. In that case, still use the attachment, just
|
||||
// skip the startRect
|
||||
if (mView != null) {
|
||||
mView.getGlobalVisibleRect(startRect);
|
||||
}
|
||||
mMediaPicker.dispatchItemsSelected(
|
||||
new MediaPickerMessagePartData(startRect, contentType,
|
||||
uriToVideo, width, height),
|
||||
true /* dismissMediaPicker */);
|
||||
if (CameraManager.get().isRecording()) {
|
||||
CameraManager.get().stopVideo();
|
||||
} else {
|
||||
final MediaCallback callback = new MediaCallback() {
|
||||
@Override
|
||||
public void onMediaReady(
|
||||
final Uri uriToVideo, final String contentType,
|
||||
final int width, final int height) {
|
||||
mVideoCounter.stop();
|
||||
if (mVideoCancelled || uriToVideo == null) {
|
||||
mVideoCancelled = false;
|
||||
} else {
|
||||
final Rect startRect = new Rect();
|
||||
// It's possible to throw out the chooser while taking the
|
||||
// picture/video. In that case, still use the attachment, just
|
||||
// skip the startRect
|
||||
if (mView != null) {
|
||||
mView.getGlobalVisibleRect(startRect);
|
||||
}
|
||||
updateViewState();
|
||||
mMediaPicker.dispatchItemsSelected(
|
||||
new MediaPickerMessagePartData(startRect, contentType,
|
||||
uriToVideo, width, height),
|
||||
true /* dismissMediaPicker */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaFailed(final Exception exception) {
|
||||
UiUtils.showToastAtBottom(R.string.camera_media_failure);
|
||||
updateViewState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaInfo(final int what) {
|
||||
if (what == MediaCallback.MEDIA_NO_DATA) {
|
||||
UiUtils.showToastAtBottom(R.string.camera_media_failure);
|
||||
}
|
||||
updateViewState();
|
||||
}
|
||||
};
|
||||
if (CameraManager.get().isVideoMode()) {
|
||||
CameraManager.get().startVideo(callback);
|
||||
mVideoCounter.setBase(SystemClock.elapsedRealtime());
|
||||
mVideoCounter.start();
|
||||
updateViewState();
|
||||
} else {
|
||||
showShutterEffect(shutterVisual);
|
||||
CameraManager.get().takePicture(heightPercent, callback);
|
||||
updateViewState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaFailed(final Exception exception) {
|
||||
UiUtils.showToastAtBottom(R.string.camera_media_failure);
|
||||
updateViewState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaInfo(final int what) {
|
||||
if (what == MediaCallback.MEDIA_NO_DATA) {
|
||||
UiUtils.showToastAtBottom(R.string.camera_media_failure);
|
||||
}
|
||||
updateViewState();
|
||||
}
|
||||
};
|
||||
if (CameraManager.get().isVideoMode()) {
|
||||
CameraManager.get().startVideo(callback);
|
||||
mVideoCounter.setBase(SystemClock.elapsedRealtime());
|
||||
mVideoCounter.start();
|
||||
updateViewState();
|
||||
} else {
|
||||
showShutterEffect(shutterVisual);
|
||||
CameraManager.get().takePicture(heightPercent, callback);
|
||||
updateViewState();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mSwapModeButton = (ImageButton) view.findViewById(R.id.camera_swap_mode_button);
|
||||
mSwapModeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
final boolean isSwitchingToVideo = !CameraManager.get().isVideoMode();
|
||||
if (isSwitchingToVideo && !OsUtil.hasRecordAudioPermission()) {
|
||||
requestRecordAudioPermission();
|
||||
} else {
|
||||
onSwapMode();
|
||||
}
|
||||
mSwapModeButton.setOnClickListener(view14 -> {
|
||||
final boolean isSwitchingToVideo = !CameraManager.get().isVideoMode();
|
||||
if (isSwitchingToVideo && !OsUtil.hasRecordAudioPermission()) {
|
||||
requestRecordAudioPermission();
|
||||
} else {
|
||||
onSwapMode();
|
||||
}
|
||||
});
|
||||
|
||||
mCancelVideoButton = (ImageButton) view.findViewById(R.id.camera_cancel_button);
|
||||
mCancelVideoButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
mVideoCancelled = true;
|
||||
CameraManager.get().stopVideo();
|
||||
mMediaPicker.dismiss(true);
|
||||
}
|
||||
mCancelVideoButton.setOnClickListener(view15 -> {
|
||||
mVideoCancelled = true;
|
||||
CameraManager.get().stopVideo();
|
||||
mMediaPicker.dismiss(true);
|
||||
});
|
||||
|
||||
mVideoCounter = (Chronometer) view.findViewById(R.id.camera_video_counter);
|
||||
|
||||
@@ -83,23 +83,20 @@ public class CameraMediaChooserView extends FrameLayout implements PersistentIns
|
||||
if (!canvas.isHardwareAccelerated() && !mIsSoftwareFallbackActive) {
|
||||
mIsSoftwareFallbackActive = true;
|
||||
// Post modifying the tree since we can't modify the view tree during a draw pass
|
||||
ThreadUtil.getMainThreadHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final HardwareCameraPreview cameraPreview =
|
||||
(HardwareCameraPreview) findViewById(R.id.camera_preview);
|
||||
if (cameraPreview == null) {
|
||||
return;
|
||||
}
|
||||
final ViewGroup parent = ((ViewGroup) cameraPreview.getParent());
|
||||
final int index = parent.indexOfChild(cameraPreview);
|
||||
final SoftwareCameraPreview softwareCameraPreview =
|
||||
new SoftwareCameraPreview(getContext());
|
||||
// Be sure to remove the hardware view before adding the software view to
|
||||
// prevent having 2 camera previews active at the same time
|
||||
parent.removeView(cameraPreview);
|
||||
parent.addView(softwareCameraPreview, index);
|
||||
ThreadUtil.getMainThreadHandler().post(() -> {
|
||||
final HardwareCameraPreview cameraPreview =
|
||||
(HardwareCameraPreview) findViewById(R.id.camera_preview);
|
||||
if (cameraPreview == null) {
|
||||
return;
|
||||
}
|
||||
final ViewGroup parent = ((ViewGroup) cameraPreview.getParent());
|
||||
final int index = parent.indexOfChild(cameraPreview);
|
||||
final SoftwareCameraPreview softwareCameraPreview =
|
||||
new SoftwareCameraPreview(getContext());
|
||||
// Be sure to remove the hardware view before adding the software view to
|
||||
// prevent having 2 camera previews active at the same time
|
||||
parent.removeView(cameraPreview);
|
||||
parent.addView(softwareCameraPreview, index);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,14 +78,10 @@ class ContactMediaChooser extends MediaChooser {
|
||||
false /* attachToRoot */);
|
||||
mEnabledView = view.findViewById(R.id.mediapicker_enabled);
|
||||
mMissingPermissionView = view.findViewById(R.id.missing_permission_view);
|
||||
mEnabledView.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
// Launch an external picker to pick a contact as attachment.
|
||||
UIIntents.get().launchContactCardPicker(mMediaPicker);
|
||||
}
|
||||
});
|
||||
mEnabledView.setOnClickListener(v -> {
|
||||
// Launch an external picker to pick a contact as attachment.
|
||||
UIIntents.get().launchContactCardPicker(mMediaPicker);
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -128,14 +125,11 @@ class ContactMediaChooser extends MediaChooser {
|
||||
}
|
||||
final Uri vCardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
|
||||
if (vCardUri != null) {
|
||||
SafeAsyncTask.executeOnThreadPool(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PendingAttachmentData pendingItem =
|
||||
PendingAttachmentData.createPendingAttachmentData(
|
||||
ContentType.TEXT_X_VCARD.toLowerCase(), vCardUri);
|
||||
mMediaPicker.dispatchPendingItemAdded(pendingItem);
|
||||
}
|
||||
SafeAsyncTask.executeOnThreadPool(() -> {
|
||||
final PendingAttachmentData pendingItem =
|
||||
PendingAttachmentData.createPendingAttachmentData(
|
||||
ContentType.TEXT_X_VCARD.toLowerCase(), vCardUri);
|
||||
mMediaPicker.dispatchPendingItemAdded(pendingItem);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,12 +92,9 @@ public class GalleryGridItemView extends FrameLayout {
|
||||
mFileName = (TextView) findViewById(R.id.file_name);
|
||||
mFileType = (TextView) findViewById(R.id.file_type);
|
||||
setOnClickListener(mOnClickListener);
|
||||
final OnLongClickListener longClickListener = new OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(final View v) {
|
||||
mHostInterface.onItemClicked(v, mData, true /* longClick */);
|
||||
return true;
|
||||
}
|
||||
final OnLongClickListener longClickListener = v -> {
|
||||
mHostInterface.onItemClicked(v, mData, true /* longClick */);
|
||||
return true;
|
||||
};
|
||||
setOnLongClickListener(longClickListener);
|
||||
mCheckBox.setOnLongClickListener(longClickListener);
|
||||
|
||||
@@ -38,9 +38,7 @@ import com.android.messaging.datamodel.data.GalleryGridItemData;
|
||||
import com.android.messaging.datamodel.data.MediaPickerData;
|
||||
import com.android.messaging.datamodel.data.MessagePartData;
|
||||
import com.android.messaging.datamodel.data.MediaPickerData.MediaPickerDataListener;
|
||||
import com.android.messaging.datamodel.data.PendingAttachmentData;
|
||||
import com.android.messaging.ui.UIIntents;
|
||||
import com.android.messaging.ui.mediapicker.DocumentImagePicker.SelectionListener;
|
||||
import com.android.messaging.util.Assert;
|
||||
import com.android.messaging.util.OsUtil;
|
||||
|
||||
@@ -59,15 +57,11 @@ class GalleryMediaChooser extends MediaChooser implements
|
||||
GalleryMediaChooser(final MediaPicker mediaPicker) {
|
||||
super(mediaPicker);
|
||||
mAdapter = new GalleryGridAdapter(Factory.get().getApplicationContext(), null);
|
||||
mDocumentImagePicker = new DocumentImagePicker(mMediaPicker,
|
||||
new SelectionListener() {
|
||||
@Override
|
||||
public void onDocumentSelected(final PendingAttachmentData data) {
|
||||
if (mBindingRef.isBound()) {
|
||||
mMediaPicker.dispatchPendingItemAdded(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
mDocumentImagePicker = new DocumentImagePicker(mMediaPicker, data -> {
|
||||
if (mBindingRef.isBound()) {
|
||||
mMediaPicker.dispatchPendingItemAdded(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -146,13 +147,9 @@ public class LevelTrackingMediaRecorder {
|
||||
"media recorder. " + ex);
|
||||
if (mOutputUri != null) {
|
||||
final Uri outputUri = mOutputUri;
|
||||
SafeAsyncTask.executeOnThreadPool(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SafeAsyncTask.executeOnThreadPool(() ->
|
||||
Factory.get().getApplicationContext().getContentResolver().delete(
|
||||
outputUri, null, null);
|
||||
}
|
||||
});
|
||||
outputUri, null, null));
|
||||
mOutputUri = null;
|
||||
}
|
||||
} finally {
|
||||
@@ -191,26 +188,23 @@ public class LevelTrackingMediaRecorder {
|
||||
|
||||
private void startTrackingSoundLevel() {
|
||||
stopTrackingSoundLevel();
|
||||
mRefreshLevelThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
synchronized (LevelTrackingMediaRecorder.class) {
|
||||
if (mRecorder != null) {
|
||||
mLevelSource.setSpeechLevel(getAmplitude());
|
||||
} else {
|
||||
// The recording session is over, finish the thread.
|
||||
return;
|
||||
}
|
||||
mRefreshLevelThread = new Thread(() -> {
|
||||
try {
|
||||
while (true) {
|
||||
synchronized (LevelTrackingMediaRecorder.class) {
|
||||
if (mRecorder != null) {
|
||||
mLevelSource.setSpeechLevel(getAmplitude());
|
||||
} else {
|
||||
// The recording session is over, finish the thread.
|
||||
return;
|
||||
}
|
||||
Thread.sleep(REFRESH_INTERVAL_MILLIS);
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
Thread.sleep(REFRESH_INTERVAL_MILLIS);
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
};
|
||||
});
|
||||
mRefreshLevelThread.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +25,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
@@ -93,12 +93,7 @@ abstract class MediaChooser extends BasePagerViewHolder
|
||||
mTabButton.setContentDescription(
|
||||
inflater.getContext().getResources().getString(getIconDescriptionResource()));
|
||||
setSelected(mSelected);
|
||||
mTabButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
mMediaPicker.selectChooser(MediaChooser.this);
|
||||
}
|
||||
});
|
||||
mTabButton.setOnClickListener(view -> mMediaPicker.selectChooser(MediaChooser.this));
|
||||
}
|
||||
|
||||
protected Context getContext() {
|
||||
|
||||
@@ -543,12 +543,7 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
|
||||
mOpen = true;
|
||||
mPagerAdapter.notifyDataSetChanged();
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onOpened();
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onOpened());
|
||||
}
|
||||
if (mSelectedChooser != null) {
|
||||
mSelectedChooser.onFullScreenChanged(false);
|
||||
@@ -560,12 +555,7 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
|
||||
setHasOptionsMenu(false);
|
||||
mOpen = false;
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onDismissed();
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onDismissed());
|
||||
}
|
||||
if (mSelectedChooser != null) {
|
||||
mSelectedChooser.onOpenedChanged(false);
|
||||
@@ -575,12 +565,7 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
|
||||
void dispatchFullScreen(final boolean fullScreen) {
|
||||
setHasOptionsMenu(fullScreen);
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onFullScreenChanged(fullScreen);
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onFullScreenChanged(fullScreen));
|
||||
}
|
||||
if (mSelectedChooser != null) {
|
||||
mSelectedChooser.onFullScreenChanged(fullScreen);
|
||||
@@ -596,12 +581,7 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
|
||||
void dispatchItemsSelected(final Collection<MessagePartData> items,
|
||||
final boolean dismissMediaPicker) {
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onItemsSelected(items, dismissMediaPicker);
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onItemsSelected(items, dismissMediaPicker));
|
||||
}
|
||||
|
||||
if (isFullScreen() && !dismissMediaPicker) {
|
||||
@@ -611,12 +591,7 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
|
||||
|
||||
void dispatchItemUnselected(final MessagePartData item) {
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onItemUnselected(item);
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onItemUnselected(item));
|
||||
}
|
||||
|
||||
if (isFullScreen()) {
|
||||
@@ -626,23 +601,13 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
|
||||
|
||||
void dispatchConfirmItemSelection() {
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onConfirmItemSelection();
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onConfirmItemSelection());
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchPendingItemAdded(final PendingAttachmentData pendingItem) {
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onPendingItemAdded(pendingItem);
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onPendingItemAdded(pendingItem));
|
||||
}
|
||||
|
||||
if (isFullScreen()) {
|
||||
@@ -652,12 +617,7 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
|
||||
|
||||
void dispatchChooserSelected(final int chooserIndex) {
|
||||
if (mListener != null) {
|
||||
mListenerHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mListener.onChooserSelected(chooserIndex);
|
||||
}
|
||||
});
|
||||
mListenerHandler.post(() -> mListener.onChooserSelected(chooserIndex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -250,12 +251,7 @@ public class MediaPickerPanel extends ViewGroup {
|
||||
}
|
||||
mFullScreen = false;
|
||||
mExpanded = expanded;
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setDesiredHeight(getDesiredHeight(), animate);
|
||||
}
|
||||
});
|
||||
mHandler.post(() -> setDesiredHeight(getDesiredHeight(), animate));
|
||||
if (expanded) {
|
||||
setupViewPager(startingPage);
|
||||
mMediaPicker.dispatchOpened();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,13 +111,9 @@ class MmsVideoRecorder extends MediaRecorder {
|
||||
|
||||
void cleanupTempFile() {
|
||||
final Uri tempUri = mTempVideoUri;
|
||||
SafeAsyncTask.executeOnThreadPool(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SafeAsyncTask.executeOnThreadPool(() ->
|
||||
Factory.get().getApplicationContext().getContentResolver().delete(
|
||||
tempUri, null, null);
|
||||
}
|
||||
});
|
||||
tempUri, null, null));
|
||||
mTempVideoUri = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.android.messaging.ui.mediapicker;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.TimeAnimator;
|
||||
import android.animation.TimeAnimator.TimeListener;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
@@ -107,13 +106,7 @@ public class SoundLevels extends View {
|
||||
// which might improve things further.
|
||||
mSpeechLevelsAnimator = new TimeAnimator();
|
||||
mSpeechLevelsAnimator.setRepeatCount(ObjectAnimator.INFINITE);
|
||||
mSpeechLevelsAnimator.setTimeListener(new TimeListener() {
|
||||
@Override
|
||||
public void onTimeUpdate(final TimeAnimator animation, final long totalTime,
|
||||
final long deltaTime) {
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
mSpeechLevelsAnimator.setTimeListener((animation, totalTime, deltaTime) -> invalidate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user