From 5cf95f5b3d885232f64eb4ba9abe52ccc59634af Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Mon, 27 Jul 2015 17:00:44 -0700 Subject: [PATCH] fix issue with camera controls going missing fixes #3775 Closes #3823 // FREEBIE --- .../components/camera/QuickAttachmentDrawer.java | 16 ++++++++-------- .../thoughtcrime/securesms/util/ViewUtil.java | 7 +++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/components/camera/QuickAttachmentDrawer.java b/src/org/thoughtcrime/securesms/components/camera/QuickAttachmentDrawer.java index 665c3d275f..291e0a6984 100644 --- a/src/org/thoughtcrime/securesms/components/camera/QuickAttachmentDrawer.java +++ b/src/org/thoughtcrime/securesms/components/camera/QuickAttachmentDrawer.java @@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout; import org.thoughtcrime.securesms.components.camera.QuickCamera.QuickCameraListener; import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.Util; +import org.thoughtcrime.securesms.util.ViewUtil; public class QuickAttachmentDrawer extends ViewGroup implements InputView { private static final String TAG = QuickAttachmentDrawer.class.getSimpleName(); @@ -112,11 +113,10 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView { } private void updateControlsView() { - int controlsIndex = indexOfChild(controls); - if (controlsIndex > -1) removeView(controls); - controls = LayoutInflater.from(getContext()).inflate(isLandscape() ? R.layout.quick_camera_controls_land - : R.layout.quick_camera_controls, - this, false); + Log.w(TAG, "updateControlsView()"); + View controls = LayoutInflater.from(getContext()).inflate(isLandscape() ? R.layout.quick_camera_controls_land + : R.layout.quick_camera_controls, + this, false); shutterButton = (ImageButton) controls.findViewById(R.id.shutter_button); swapCameraButton = (ImageButton) controls.findViewById(R.id.swap_camera_button); fullScreenButton = (ImageButton) controls.findViewById(R.id.fullscreen_button); @@ -126,8 +126,8 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView { } shutterButton.setOnClickListener(new ShutterClickListener()); fullScreenButton.setOnClickListener(new FullscreenClickListener()); - controls.setVisibility(INVISIBLE); - addView(controls, controlsIndex > -1 ? controlsIndex : indexOfChild(quickCamera) + 1); + ViewUtil.swapChildInPlace(this, this.controls, controls, indexOfChild(quickCamera) + 1); + this.controls = controls; } private boolean isLandscape() { @@ -499,7 +499,7 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView { COLLAPSED, HALF_EXPANDED, FULL_EXPANDED; public boolean isVisible() { - return this == HALF_EXPANDED || this == FULL_EXPANDED; + return this != COLLAPSED; } } diff --git a/src/org/thoughtcrime/securesms/util/ViewUtil.java b/src/org/thoughtcrime/securesms/util/ViewUtil.java index cb29744ef2..1d801c82cb 100644 --- a/src/org/thoughtcrime/securesms/util/ViewUtil.java +++ b/src/org/thoughtcrime/securesms/util/ViewUtil.java @@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.util; import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; import android.view.View; +import android.view.ViewGroup; public class ViewUtil { public static void setBackgroundSavingPadding(View v, Drawable drawable) { @@ -38,4 +39,10 @@ public class ViewUtil { v.setBackgroundResource(resId); v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } + + public static void swapChildInPlace(ViewGroup parent, View toRemove, View toAdd, int defaultIndex) { + int childIndex = parent.indexOfChild(toRemove); + if (childIndex > -1) parent.removeView(toRemove); + parent.addView(toAdd, childIndex > -1 ? childIndex : defaultIndex); + } }