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