mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c8e91328d | |||
| 5c30e9e16a |
@@ -0,0 +1,78 @@
|
||||
package org.thoughtcrime.securesms.components.viewpager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Matrix;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
public class RtlSafeViewPager extends HackyViewPager {
|
||||
private final Matrix mirrorMatrix = new Matrix();
|
||||
private boolean rtl;
|
||||
|
||||
public RtlSafeViewPager(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public RtlSafeViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
updateLayoutDirection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRtlPropertiesChanged(int layoutDirection) {
|
||||
super.onRtlPropertiesChanged(layoutDirection);
|
||||
updateLayoutDirection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if (!isRtl()) {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
MotionEvent mirrored = getMirroredMotionEvent(ev);
|
||||
try {
|
||||
return super.onInterceptTouchEvent(mirrored);
|
||||
} finally {
|
||||
mirrored.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (!isRtl()) {
|
||||
return super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
MotionEvent mirrored = getMirroredMotionEvent(ev);
|
||||
try {
|
||||
return super.onTouchEvent(mirrored);
|
||||
} finally {
|
||||
mirrored.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRtl() {
|
||||
return rtl;
|
||||
}
|
||||
|
||||
private MotionEvent getMirroredMotionEvent(@NonNull MotionEvent ev) {
|
||||
MotionEvent mirrored = MotionEvent.obtain(ev);
|
||||
mirrorMatrix.reset();
|
||||
mirrorMatrix.setScale(-1f, 1f, getWidth() / 2f, 0f);
|
||||
mirrored.transform(mirrorMatrix);
|
||||
return mirrored;
|
||||
}
|
||||
|
||||
private void updateLayoutDirection() {
|
||||
rtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<org.thoughtcrime.securesms.components.viewpager.RtlSafeViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<org.thoughtcrime.securesms.components.viewpager.RtlSafeViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
app:tabSelectedTextColor="@color/white"
|
||||
app:tabMode="fixed" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<org.thoughtcrime.securesms.components.viewpager.RtlSafeViewPager
|
||||
android:id="@+id/camera_sticker_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0px"
|
||||
|
||||
Reference in New Issue
Block a user