Fix right-to-left language support for voice recording

Bug: fixes #5999

// FREEBIE
This commit is contained in:
Veeti Paananen
2017-01-04 22:43:02 +02:00
committed by Moxie Marlinspike
parent 49e78d16ba
commit 4dae4444bc
7 changed files with 37 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ import android.os.Build;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
@@ -21,7 +22,6 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
import org.thoughtcrime.securesms.components.emoji.EmojiEditText;
import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.ViewUtil;
@@ -146,7 +146,12 @@ public class InputPanel extends LinearLayout
public void onRecordMoved(float x, float absoluteX) {
slideToCancel.moveTo(x);
if (absoluteX / recordingContainer.getWidth() <= 0.5) {
int direction = ViewCompat.getLayoutDirection(this);
float position = absoluteX / recordingContainer.getWidth();
if (direction == ViewCompat.LAYOUT_DIRECTION_LTR && position <= 0.5 ||
direction == ViewCompat.LAYOUT_DIRECTION_RTL && position >= 0.6)
{
this.microphoneRecorderView.cancelAction();
}
}
@@ -225,7 +230,7 @@ public class InputPanel extends LinearLayout
public ListenableFuture<Void> hide(float x) {
final SettableFuture<Void> future = new SettableFuture<>();
float offset = -Math.max(0, this.startPositionX - x);
float offset = getOffset(x);
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new TranslateAnimation(Animation.ABSOLUTE, offset,
@@ -255,7 +260,7 @@ public class InputPanel extends LinearLayout
}
public void moveTo(float x) {
float offset = -Math.max(0, this.startPositionX - x);
float offset = getOffset(x);
Animation animation = new TranslateAnimation(Animation.ABSOLUTE, offset,
Animation.ABSOLUTE, offset,
Animation.RELATIVE_TO_SELF, 0,
@@ -268,6 +273,11 @@ public class InputPanel extends LinearLayout
slideToCancelView.startAnimation(animation);
}
private float getOffset(float x) {
return ViewCompat.getLayoutDirection(slideToCancelView) == ViewCompat.LAYOUT_DIRECTION_LTR ?
-Math.max(0, this.startPositionX - x) : Math.max(0, x - this.startPositionX);
}
}
private static class RecordTime implements Runnable {

View File

@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.components;
import android.content.Context;
import android.graphics.PorterDuff;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -113,9 +114,12 @@ public class MicrophoneRecorderView extends FrameLayout implements View.OnTouchL
recordButtonFab.setVisibility(View.VISIBLE);
float translation = ViewCompat.getLayoutDirection(recordButtonFab) ==
ViewCompat.LAYOUT_DIRECTION_LTR ? -.25f : .25f;
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, -.25f,
Animation.RELATIVE_TO_SELF, -.25f,
animation.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, translation,
Animation.RELATIVE_TO_SELF, translation,
Animation.RELATIVE_TO_SELF, -.25f,
Animation.RELATIVE_TO_SELF, -.25f));
@@ -134,8 +138,8 @@ public class MicrophoneRecorderView extends FrameLayout implements View.OnTouchL
public void moveTo(float x) {
this.lastPositionX = x;
float offset = -Math.max(0, this.startPositionX - x);
int widthAdjustment = -(recordButtonFab.getWidth() / 4);
float offset = getOffset(x);
int widthAdjustment = getWidthAdjustment();
Animation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, widthAdjustment + offset,
Animation.ABSOLUTE, widthAdjustment + offset,
@@ -152,8 +156,8 @@ public class MicrophoneRecorderView extends FrameLayout implements View.OnTouchL
public void hide(float x) {
this.lastPositionX = x;
float offset = -Math.max(0, this.startPositionX - x);
int widthAdjustment = -(recordButtonFab.getWidth() / 4);
float offset = getOffset(x);
int widthAdjustment = getWidthAdjustment();
AnimationSet animation = new AnimationSet(false);
Animation scaleAnimation = new ScaleAnimation(1, 0.5f, 1, 0.5f,
@@ -179,6 +183,16 @@ public class MicrophoneRecorderView extends FrameLayout implements View.OnTouchL
recordButtonFab.startAnimation(animation);
}
private float getOffset(float x) {
return ViewCompat.getLayoutDirection(recordButtonFab) == ViewCompat.LAYOUT_DIRECTION_LTR ?
-Math.max(0, this.startPositionX - x) : Math.max(0, x - this.startPositionX);
}
private int getWidthAdjustment() {
int width = recordButtonFab.getWidth() / 4;
return ViewCompat.getLayoutDirection(recordButtonFab) == ViewCompat.LAYOUT_DIRECTION_LTR ? -width : width;
}
}
}