add sane default emoji panel size

fixes #3661
Closes #3691
// FREEBIE
This commit is contained in:
Jake McGinty
2015-07-17 12:50:00 -07:00
committed by Moxie Marlinspike
parent cfc9514f89
commit 39c0fc0e5a
6 changed files with 60 additions and 177 deletions

View File

@@ -29,6 +29,7 @@ import android.view.View;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.Util;
import java.lang.reflect.Field;
import java.util.HashSet;
@@ -46,6 +47,9 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
private final Set<OnKeyboardHiddenListener> hiddenListeners = new HashSet<>();
private final Set<OnKeyboardShownListener> shownListeners = new HashSet<>();
private final int minKeyboardSize;
private final int minCustomKeyboardSize;
private final int defaultCustomKeyboardSize;
private final int minCustomKeyboardTopMargin;
private boolean keyboardOpen = false;
private int rotation = -1;
@@ -60,7 +64,10 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
public KeyboardAwareLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
minKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_keyboard_size);
minKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_keyboard_size);
minCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_size);
defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size);
minCustomKeyboardTopMargin = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@@ -134,10 +141,6 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
notifyHiddenListeners();
}
public boolean isKeyboardOpen() {
return keyboardOpen;
}
public int getKeyboardHeight() {
return isLandscape() ? getKeyboardLandscapeHeight() : getKeyboardPortraitHeight();
}
@@ -156,9 +159,8 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
private int getKeyboardPortraitHeight() {
int keyboardHeight = PreferenceManager.getDefaultSharedPreferences(getContext())
.getInt("keyboard_height_portrait",
getResources().getDimensionPixelSize(R.dimen.min_emoji_drawer_height));
return Math.min(keyboardHeight, getRootView().getHeight() - getResources().getDimensionPixelSize(R.dimen.min_emoji_drawer_top_margin));
.getInt("keyboard_height_portrait", defaultCustomKeyboardSize);
return Util.clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMargin);
}
private void setKeyboardPortraitHeight(int height) {

View File

@@ -18,13 +18,12 @@ import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.widget.ImageButton;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
import org.thoughtcrime.securesms.components.camera.QuickCamera.QuickCameraListener;
import org.thoughtcrime.securesms.util.SoftKeyboardUtil;
import org.thoughtcrime.securesms.util.ServiceUtil;
public class QuickAttachmentDrawer extends ViewGroup {
private static final String TAG = QuickAttachmentDrawer.class.getSimpleName();
@@ -33,23 +32,23 @@ public class QuickAttachmentDrawer extends ViewGroup {
private final ViewDragHelper dragHelper;
private QuickCamera quickCamera;
private int coverViewPosition;
private View coverView;
private View controls;
private ImageButton fullScreenButton;
private ImageButton swapCameraButton;
private ImageButton shutterButton;
private float slideOffset;
private float initialMotionX;
private float initialMotionY;
private int rotation;
private int slideRange;
private int baseHalfHeight;
private AttachmentDrawerListener listener;
private QuickCamera quickCamera;
private int coverViewPosition;
private KeyboardAwareLinearLayout coverView;
private View controls;
private ImageButton fullScreenButton;
private ImageButton swapCameraButton;
private ImageButton shutterButton;
private float slideOffset;
private float initialMotionX;
private float initialMotionY;
private int rotation;
private int slideRange;
private AttachmentDrawerListener listener;
private int halfExpandedHeight;
private float halfExpandedAnchorPoint;
private DrawerState drawerState = DrawerState.COLLAPSED;
private float halfExpandedAnchorPoint = COLLAPSED_ANCHOR_POINT;
private boolean halfModeUnsupported = VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH;
private Rect drawChildrenRect = new Rect();
private boolean paused = false;
@@ -64,8 +63,7 @@ public class QuickAttachmentDrawer extends ViewGroup {
public QuickAttachmentDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
baseHalfHeight = SoftKeyboardUtil.getKeyboardHeight(getContext());
dragHelper = ViewDragHelper.create(this, 1.f, new ViewDragHelperCallback());
dragHelper = ViewDragHelper.create(this, 1.f, new ViewDragHelperCallback());
initializeView();
updateHalfExpandedAnchorPoint();
onConfigurationChanged();
@@ -79,10 +77,6 @@ public class QuickAttachmentDrawer extends ViewGroup {
coverViewPosition = getChildCount();
}
private WindowManager getWindowManager() {
return (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
}
public static boolean isDeviceSupported(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) &&
Camera.getNumberOfCameras() > 0;
@@ -101,7 +95,7 @@ public class QuickAttachmentDrawer extends ViewGroup {
}
public void onConfigurationChanged() {
int rotation = getWindowManager().getDefaultDisplay().getRotation();
int rotation = ServiceUtil.getWindowManager(getContext()).getDefaultDisplay().getRotation();
final boolean rotationChanged = this.rotation != rotation;
this.rotation = rotation;
if (rotationChanged) {
@@ -140,24 +134,24 @@ public class QuickAttachmentDrawer extends ViewGroup {
return isLandscape() || halfModeUnsupported;
}
private void updateHalfExpandedAnchorPoint() {
Log.w(TAG, "updateHalfExpandedAnchorPoint()");
getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation") @Override public void onGlobalLayout() {
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
private KeyboardAwareLinearLayout getCoverView() {
if (coverView != null) return coverView;
coverView = getChildAt(coverViewPosition);
slideRange = getMeasuredHeight();
halfExpandedAnchorPoint = computeSlideOffsetFromCoverBottom(slideRange - baseHalfHeight);
requestLayout();
invalidate();
Log.w(TAG, "updated halfExpandedAnchorPoint!");
}
});
final View coverViewChild = getChildAt(coverViewPosition);
if (coverViewChild != null && !(coverViewChild instanceof KeyboardAwareLinearLayout)) {
throw new IllegalStateException("cover view must be a KeyboardAwareLinearLayout");
}
coverView = (KeyboardAwareLinearLayout) coverViewChild;
return coverView;
}
private void updateHalfExpandedAnchorPoint() {
if (getCoverView() != null) {
slideRange = getMeasuredHeight();
halfExpandedHeight = coverView.getKeyboardHeight();
halfExpandedAnchorPoint = computeSlideOffsetFromCoverBottom(slideRange - halfExpandedHeight);
}
}
@Override
@@ -165,6 +159,8 @@ public class QuickAttachmentDrawer extends ViewGroup {
final int paddingLeft = getPaddingLeft();
final int paddingTop = getPaddingTop();
updateHalfExpandedAnchorPoint();
for (int i = 0; i < getChildCount(); i++) {
final View child = getChildAt(i);
final int childHeight = child.getMeasuredHeight();
@@ -192,8 +188,8 @@ public class QuickAttachmentDrawer extends ViewGroup {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
@@ -477,7 +473,7 @@ public class QuickAttachmentDrawer extends ViewGroup {
clampedOffset = clampedOffset / (FULL_EXPANDED_ANCHOR_POINT - halfExpandedAnchorPoint);
}
float slidePixelOffset = slideOffset * slideRange +
(quickCamera.getMeasuredHeight() - baseHalfHeight) / 2 *
(quickCamera.getMeasuredHeight() - coverView.getKeyboardHeight()) / 2 *
(FULL_EXPANDED_ANCHOR_POINT - clampedOffset);
float marginPixelOffset = (getMeasuredHeight() - quickCamera.getMeasuredHeight()) / 2 * clampedOffset;
return (int) (getMeasuredHeight() - slidePixelOffset + marginPixelOffset);
@@ -528,7 +524,7 @@ public class QuickAttachmentDrawer extends ViewGroup {
@Override
public void onClick(View v) {
boolean crop = drawerState != DrawerState.FULL_EXPANDED;
int imageHeight = crop ? baseHalfHeight : quickCamera.getMeasuredHeight();
int imageHeight = crop ? coverView.getKeyboardHeight() : quickCamera.getMeasuredHeight();
Rect previewRect = new Rect(0, 0, quickCamera.getMeasuredWidth(), imageHeight);
quickCamera.takePicture(previewRect);
}

View File

@@ -73,6 +73,7 @@ public class EmojiDrawer extends LinearLayout {
public void show(KeyboardAwareLinearLayout container) {
ViewGroup.LayoutParams params = getLayoutParams();
params.height = container.getKeyboardHeight();
Log.w("EmojiDrawer", "showing emoji drawer with height " + params.height);
setLayoutParams(params);
setVisibility(VISIBLE);
}