mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
parent
30f2c71861
commit
8fbc14b191
@ -5,11 +5,12 @@ import android.content.pm.PackageManager;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Build.VERSION;
|
import android.os.Build.VERSION;
|
||||||
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.view.MotionEventCompat;
|
import android.support.v4.view.MotionEventCompat;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||||
import android.support.v4.widget.ViewDragHelper;
|
import android.support.v4.widget.ViewDragHelper;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -20,6 +21,8 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
|
import com.nineoldandroids.animation.ObjectAnimator;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.components.InputAwareLayout.InputView;
|
import org.thoughtcrime.securesms.components.InputAwareLayout.InputView;
|
||||||
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
|
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
|
||||||
@ -48,7 +51,6 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
private int halfExpandedHeight;
|
private int halfExpandedHeight;
|
||||||
|
|
||||||
private DrawerState drawerState = DrawerState.COLLAPSED;
|
private DrawerState drawerState = DrawerState.COLLAPSED;
|
||||||
private boolean halfModeUnsupported = VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
|
||||||
private Rect drawChildrenRect = new Rect();
|
private Rect drawChildrenRect = new Rect();
|
||||||
private boolean paused = false;
|
private boolean paused = false;
|
||||||
|
|
||||||
@ -132,10 +134,6 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
return rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270;
|
return rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFullscreenOnly() {
|
|
||||||
return isLandscape() || halfModeUnsupported;
|
|
||||||
}
|
|
||||||
|
|
||||||
private View getCoverView() {
|
private View getCoverView() {
|
||||||
if (coverView == null) coverView = getChildAt(coverViewPosition);
|
if (coverView == null) coverView = getChildAt(coverViewPosition);
|
||||||
return coverView;
|
return coverView;
|
||||||
@ -249,10 +247,11 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);
|
final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);
|
||||||
|
|
||||||
canvas.getClipBounds(drawChildrenRect);
|
canvas.getClipBounds(drawChildrenRect);
|
||||||
if (child == coverView)
|
if (child == coverView) {
|
||||||
drawChildrenRect.bottom = Math.min(drawChildrenRect.bottom, child.getBottom());
|
drawChildrenRect.bottom = Math.min(drawChildrenRect.bottom, child.getBottom());
|
||||||
else if (coverView != null)
|
} else if (coverView != null) {
|
||||||
drawChildrenRect.top = Math.max(drawChildrenRect.top, coverView.getBottom());
|
drawChildrenRect.top = Math.max(drawChildrenRect.top, coverView.getBottom());
|
||||||
|
}
|
||||||
canvas.clipRect(drawChildrenRect);
|
canvas.clipRect(drawChildrenRect);
|
||||||
result = super.drawChild(canvas, child, drawingTime);
|
result = super.drawChild(canvas, child, drawingTime);
|
||||||
canvas.restoreToCount(save);
|
canvas.restoreToCount(save);
|
||||||
@ -261,7 +260,7 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void computeScroll() {
|
public void computeScroll() {
|
||||||
if (dragHelper != null && dragHelper.continueSettling(true)) {
|
if (dragHelper.continueSettling(true)) {
|
||||||
ViewCompat.postInvalidateOnAnimation(this);
|
ViewCompat.postInvalidateOnAnimation(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,14 +281,10 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
fullScreenButton.setImageResource(R.drawable.quick_camera_fullscreen);
|
fullScreenButton.setImageResource(R.drawable.quick_camera_fullscreen);
|
||||||
break;
|
break;
|
||||||
case HALF_EXPANDED:
|
case HALF_EXPANDED:
|
||||||
if (isFullscreenOnly()) {
|
|
||||||
setDrawerState(DrawerState.FULL_EXPANDED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fullScreenButton.setImageResource(R.drawable.quick_camera_fullscreen);
|
fullScreenButton.setImageResource(R.drawable.quick_camera_fullscreen);
|
||||||
break;
|
break;
|
||||||
case FULL_EXPANDED:
|
case FULL_EXPANDED:
|
||||||
fullScreenButton.setImageResource(isFullscreenOnly() ? R.drawable.quick_camera_hide
|
fullScreenButton.setImageResource(isLandscape() ? R.drawable.quick_camera_hide
|
||||||
: R.drawable.quick_camera_exit_fullscreen);
|
: R.drawable.quick_camera_exit_fullscreen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -300,6 +295,12 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public void setSlideOffset(int slideOffset) {
|
||||||
|
this.slideOffset = slideOffset;
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
public int getTargetSlideOffset() {
|
public int getTargetSlideOffset() {
|
||||||
switch (drawerState) {
|
switch (drawerState) {
|
||||||
case FULL_EXPANDED: return getMeasuredHeight();
|
case FULL_EXPANDED: return getMeasuredHeight();
|
||||||
@ -334,7 +335,7 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean tryCaptureView(View child, int pointerId) {
|
public boolean tryCaptureView(View child, int pointerId) {
|
||||||
return child == controls && !halfModeUnsupported;
|
return child == controls;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -398,7 +399,6 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||||
if (dragHelper != null) {
|
|
||||||
final int action = MotionEventCompat.getActionMasked(event);
|
final int action = MotionEventCompat.getActionMasked(event);
|
||||||
|
|
||||||
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
|
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
|
||||||
@ -432,17 +432,12 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
}
|
}
|
||||||
return dragHelper.shouldInterceptTouchEvent(event);
|
return dragHelper.shouldInterceptTouchEvent(event);
|
||||||
}
|
}
|
||||||
return super.onInterceptTouchEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(@NonNull MotionEvent event) {
|
public boolean onTouchEvent(@NonNull MotionEvent event) {
|
||||||
if (dragHelper != null) {
|
|
||||||
dragHelper.processTouchEvent(event);
|
dragHelper.processTouchEvent(event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onTouchEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: Android Studio bug misreports error, squashing the warning.
|
// NOTE: Android Studio bug misreports error, squashing the warning.
|
||||||
// https://code.google.com/p/android/issues/detail?id=175977
|
// https://code.google.com/p/android/issues/detail?id=175977
|
||||||
@ -459,6 +454,10 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int computeCameraTopPosition(int slideOffset) {
|
private int computeCameraTopPosition(int slideOffset) {
|
||||||
|
if (VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||||
|
return getPaddingTop();
|
||||||
|
}
|
||||||
|
|
||||||
final int baseCameraTop = (quickCamera.getMeasuredHeight() - halfExpandedHeight) / 2;
|
final int baseCameraTop = (quickCamera.getMeasuredHeight() - halfExpandedHeight) / 2;
|
||||||
final int baseOffset = getMeasuredHeight() - slideOffset - baseCameraTop;
|
final int baseOffset = getMeasuredHeight() - slideOffset - baseCameraTop;
|
||||||
final float slop = Util.clamp((float)(slideOffset - halfExpandedHeight) / (getMeasuredHeight() - halfExpandedHeight),
|
final float slop = Util.clamp((float)(slideOffset - halfExpandedHeight) / (getMeasuredHeight() - halfExpandedHeight),
|
||||||
@ -472,9 +471,11 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void slideTo(int slideOffset, boolean forceInstant) {
|
private void slideTo(int slideOffset, boolean forceInstant) {
|
||||||
if (dragHelper != null && !halfModeUnsupported && !forceInstant) {
|
if (!forceInstant) {
|
||||||
dragHelper.smoothSlideViewTo(coverView, coverView.getLeft(), computeCoverTopPosition(slideOffset));
|
ObjectAnimator animator = ObjectAnimator.ofInt(this, "slideOffset", this.slideOffset, slideOffset);
|
||||||
dragHelper.smoothSlideViewTo(quickCamera, quickCamera.getLeft(), computeCameraTopPosition(slideOffset));
|
animator.setInterpolator(new FastOutSlowInInterpolator());
|
||||||
|
animator.setDuration(400);
|
||||||
|
animator.start();
|
||||||
ViewCompat.postInvalidateOnAnimation(this);
|
ViewCompat.postInvalidateOnAnimation(this);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "quick sliding to " + slideOffset);
|
Log.w(TAG, "quick sliding to " + slideOffset);
|
||||||
@ -526,7 +527,7 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (drawerState != DrawerState.FULL_EXPANDED) {
|
if (drawerState != DrawerState.FULL_EXPANDED) {
|
||||||
setDrawerStateAndUpdate(DrawerState.FULL_EXPANDED);
|
setDrawerStateAndUpdate(DrawerState.FULL_EXPANDED);
|
||||||
} else if (isFullscreenOnly()) {
|
} else if (isLandscape()) {
|
||||||
setDrawerStateAndUpdate(DrawerState.COLLAPSED);
|
setDrawerStateAndUpdate(DrawerState.COLLAPSED);
|
||||||
} else {
|
} else {
|
||||||
setDrawerStateAndUpdate(DrawerState.HALF_EXPANDED);
|
setDrawerStateAndUpdate(DrawerState.HALF_EXPANDED);
|
||||||
|
Loading…
Reference in New Issue
Block a user