Skip to content

Commit

Permalink
Camera content descriptions and allow camera capture in talk back.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal authored and greyson-signal committed Aug 1, 2019
1 parent af8042c commit 5a614fa
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 55 deletions.
5 changes: 4 additions & 1 deletion res/layout/camera_controls_landscape.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
<org.thoughtcrime.securesms.mediasend.CameraButtonView
android:id="@+id/camera_capture_button"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginEnd="24dp"
android:background="@drawable/ic_camera_shutter"
android:contentDescription="@string/CameraXFragment_capture_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
Expand All @@ -25,6 +26,7 @@
android:src="@drawable/ic_switch_camera_32"
android:scaleType="fitCenter"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/CameraXFragment_change_camera_description"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand All @@ -35,6 +37,7 @@
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginBottom="42dp"
android:contentDescription="@string/CameraXFragment_open_gallery_description"
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="@id/camera_capture_button"
app:layout_constraintStart_toStartOf="@id/camera_capture_button"
Expand Down
5 changes: 4 additions & 1 deletion res/layout/camera_controls_portrait.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
<org.thoughtcrime.securesms.mediasend.CameraButtonView
android:id="@+id/camera_capture_button"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="24dp"
android:background="@drawable/ic_camera_shutter"
android:contentDescription="@string/CameraXFragment_capture_description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -25,6 +26,7 @@
android:src="@drawable/ic_switch_camera_32"
android:scaleType="fitCenter"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/CameraXFragment_change_camera_description"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -35,6 +37,7 @@
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="32dp"
android:contentDescription="@string/CameraXFragment_open_gallery_description"
android:scaleType="centerCrop"
app:layout_constraintTop_toTopOf="@id/camera_capture_button"
app:layout_constraintBottom_toBottomOf="@id/camera_capture_button"
Expand Down
1 change: 1 addition & 0 deletions res/layout/conversation_list_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="88dp"
android:contentDescription="@string/conversation_list_fragment__open_camera_description"
android:src="@drawable/ic_camera_filled_24"
android:tint="?conversation_list_camera_icon_tint"
android:focusable="true"
Expand Down
1 change: 1 addition & 0 deletions res/layout/mediasend_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
android:layout_gravity="bottom|end"
android:padding="6dp"
android:background="@drawable/media_continue_button_background"
android:contentDescription="@string/MediaSendActivity_select_recipients_description"
android:visibility="gone"
app:srcCompat="@drawable/ic_continue_24"
tools:visibility="visible"/>
Expand Down
2 changes: 1 addition & 1 deletion res/menu/camera_contacts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:title=""
android:title="@string/CameraContacts__menu_search"
android:id="@+id/menu_search"
android:icon="@drawable/ic_search_white_24dp"
app:actionViewClass="androidx.appcompat.widget.SearchView"
Expand Down
2 changes: 1 addition & 1 deletion res/menu/mediapicker_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:title=""
android:title="@string/MediaPickerActivity__menu_open_camera"
android:id="@+id/mediapicker_menu_camera"
android:visible="true"
android:icon="@drawable/ic_camera_alt_white_24dp"
Expand Down
9 changes: 9 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<!-- CameraActivity -->
<string name="CameraActivity_image_save_failure">Failed to save image.</string>

<!-- CameraXFragment -->
<string name="CameraXFragment_capture_description">Capture</string>
<string name="CameraXFragment_change_camera_description">Change camera</string>
<string name="CameraXFragment_open_gallery_description">Open gallery</string>

<!-- CameraContacts -->
<string name="CameraContacts_recent_contacts">Recent contacts</string>
<string name="CameraContacts_signal_contacts">Signal contacts</string>
Expand All @@ -102,6 +107,7 @@
<string name="CameraContacts_you_can_only_use_the_camera_button">You can only use the camera button to send photos to Signal contacts. </string>
<string name="CameraContacts_cant_find_who_youre_looking_for">Can\'t find who you\'re looking for?</string>
<string name="CameraContacts_invite_a_contact_to_join_signal">Invite a contact to join Signal</string>
<string name="CameraContacts__menu_search">Search</string>

<!-- ClearProfileActivity -->
<string name="ClearProfileActivity_remove">Remove</string>
Expand Down Expand Up @@ -484,6 +490,7 @@

<!-- MediaPickerActivity -->
<string name="MediaPickerActivity_send_to">Send to %s</string>
<string name="MediaPickerActivity__menu_open_camera">Open camera</string>

<!-- MediaPickerItemFragment -->
<string name="MediaPickerItemFragment_tap_to_select">Tap to select</string>
Expand All @@ -501,6 +508,7 @@
<item quantity="one">You can\'t share more than %d item.</item>
<item quantity="other">You can\'t share more than %d items.</item>
</plurals>
<string name="MediaSendActivity_select_recipients_description">Select recipients</string>

<!-- MediaRepository -->
<string name="MediaRepository_all_media">All media</string>
Expand Down Expand Up @@ -1423,6 +1431,7 @@

<!-- conversation_list_fragment -->
<string name="conversation_list_fragment__fab_content_description">New conversation</string>
<string name="conversation_list_fragment__open_camera_description">Open Camera</string>
<string name="conversation_list_fragment__give_your_inbox_something_to_write_home_about_get_started_by_messaging_a_friend">Give your inbox something to write home about. Get started by messaging a friend.</string>


Expand Down
37 changes: 9 additions & 28 deletions src/org/thoughtcrime/securesms/mediasend/Camera1Fragment.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.thoughtcrime.securesms.mediasend;

import android.annotation.SuppressLint;
import androidx.lifecycle.ViewModelProviders;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Matrix;
Expand All @@ -10,9 +9,6 @@
import android.graphics.SurfaceTexture;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.Display;
import android.view.GestureDetector;
import android.view.LayoutInflater;
Expand All @@ -22,14 +18,17 @@
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.Transformation;
Expand Down Expand Up @@ -61,7 +60,7 @@ public class Camera1Fragment extends Fragment implements CameraFragment,
private TextureView cameraPreview;
private ViewGroup controlsContainer;
private ImageButton flipButton;
private Button captureButton;
private View captureButton;
private Camera1Controller camera;
private Controller controller;
private OrderEnforcer<Stage> orderEnforcer;
Expand Down Expand Up @@ -218,34 +217,16 @@ private void presentHud(@Nullable MediaSendViewModel.HudState state) {
}
}

@SuppressLint("ClickableViewAccessibility")
private void initControls() {
flipButton = requireView().findViewById(R.id.camera_flip_button);
captureButton = requireView().findViewById(R.id.camera_capture_button);

View galleryButton = requireView().findViewById(R.id.camera_gallery_button);
View countButton = requireView().findViewById(R.id.camera_count_button);

captureButton.setOnTouchListener((v, event) -> {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Animation shrinkAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.camera_capture_button_shrink);
shrinkAnimation.setFillAfter(true);
shrinkAnimation.setFillEnabled(true);
captureButton.startAnimation(shrinkAnimation);
onCaptureClicked();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_OUTSIDE:
Animation growAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.camera_capture_button_grow);
growAnimation.setFillAfter(true);
growAnimation.setFillEnabled(true);
captureButton.startAnimation(growAnimation);
captureButton.setEnabled(false);
break;
}
return true;
captureButton.setOnClickListener(v -> {
captureButton.setEnabled(false);
onCaptureClicked();
});

orderEnforcer.run(Stage.CAMERA_PROPERTIES_AVAILABLE, () -> {
Expand Down
64 changes: 64 additions & 0 deletions src/org/thoughtcrime/securesms/mediasend/CameraButtonView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.thoughtcrime.securesms.mediasend;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import androidx.appcompat.widget.AppCompatButton;

import org.thoughtcrime.securesms.R;

public final class CameraButtonView extends AppCompatButton {

private Animation shrinkAnimation;
private Animation growAnimation;

public CameraButtonView(Context context) {
super(context);
init(context);
}

public CameraButtonView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}

public CameraButtonView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}

public void init(Context context) {
shrinkAnimation = AnimationUtils.loadAnimation(context, R.anim.camera_capture_button_shrink);
growAnimation = AnimationUtils.loadAnimation(context, R.anim.camera_capture_button_grow);

shrinkAnimation.setFillAfter(true);
shrinkAnimation.setFillEnabled(true);

growAnimation.setFillAfter(true);
growAnimation.setFillEnabled(true);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (isEnabled()) {
startAnimation(shrinkAnimation);
performClick();
}
return true;
case MotionEvent.ACTION_UP:
startAnimation(growAnimation);
return true;
}
return false;
}

@Override
public boolean performClick() {
return super.performClick();
}
}
30 changes: 7 additions & 23 deletions src/org/thoughtcrime/securesms/mediasend/CameraXFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
Expand Down Expand Up @@ -166,26 +165,10 @@ private void initControls() {
View galleryButton = requireView().findViewById(R.id.camera_gallery_button);
View countButton = requireView().findViewById(R.id.camera_count_button);

captureButton.setOnTouchListener((v, event) -> {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Animation shrinkAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.camera_capture_button_shrink);
shrinkAnimation.setFillAfter(true);
shrinkAnimation.setFillEnabled(true);
captureButton.startAnimation(shrinkAnimation);
onCaptureClicked();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_OUTSIDE:
Animation growAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.camera_capture_button_grow);
growAnimation.setFillAfter(true);
growAnimation.setFillEnabled(true);
captureButton.startAnimation(growAnimation);
captureButton.setEnabled(false);
break;
}
return true;
captureButton.setOnClickListener(v -> {
captureButton.setEnabled(false);
flipButton.setEnabled(false);
onCaptureClicked();
});

if (camera.hasCameraWithLensFacing(CameraX.LensFacing.FRONT) && camera.hasCameraWithLensFacing(CameraX.LensFacing.BACK)) {
Expand All @@ -203,14 +186,15 @@ private void initControls() {
GestureDetector gestureDetector = new GestureDetector(requireContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
flipButton.performClick();
if (flipButton.isEnabled()) {
flipButton.performClick();
}
return true;
}
});

camera.setOnTouchListener((v, event) -> gestureDetector.onTouchEvent(event));


} else {
flipButton.setVisibility(View.GONE);
}
Expand Down

0 comments on commit 5a614fa

Please sign in to comment.