fix issue with camera controls going missing

fixes #3775
Closes #3823
// FREEBIE
This commit is contained in:
Jake McGinty 2015-07-27 17:00:44 -07:00 committed by Moxie Marlinspike
parent 8fbc14b191
commit 5cf95f5b3d
2 changed files with 15 additions and 8 deletions

View File

@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
import org.thoughtcrime.securesms.components.camera.QuickCamera.QuickCameraListener; import org.thoughtcrime.securesms.components.camera.QuickCamera.QuickCameraListener;
import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
public class QuickAttachmentDrawer extends ViewGroup implements InputView { public class QuickAttachmentDrawer extends ViewGroup implements InputView {
private static final String TAG = QuickAttachmentDrawer.class.getSimpleName(); private static final String TAG = QuickAttachmentDrawer.class.getSimpleName();
@ -112,11 +113,10 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
} }
private void updateControlsView() { private void updateControlsView() {
int controlsIndex = indexOfChild(controls); Log.w(TAG, "updateControlsView()");
if (controlsIndex > -1) removeView(controls); View controls = LayoutInflater.from(getContext()).inflate(isLandscape() ? R.layout.quick_camera_controls_land
controls = LayoutInflater.from(getContext()).inflate(isLandscape() ? R.layout.quick_camera_controls_land : R.layout.quick_camera_controls,
: R.layout.quick_camera_controls, this, false);
this, false);
shutterButton = (ImageButton) controls.findViewById(R.id.shutter_button); shutterButton = (ImageButton) controls.findViewById(R.id.shutter_button);
swapCameraButton = (ImageButton) controls.findViewById(R.id.swap_camera_button); swapCameraButton = (ImageButton) controls.findViewById(R.id.swap_camera_button);
fullScreenButton = (ImageButton) controls.findViewById(R.id.fullscreen_button); fullScreenButton = (ImageButton) controls.findViewById(R.id.fullscreen_button);
@ -126,8 +126,8 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
} }
shutterButton.setOnClickListener(new ShutterClickListener()); shutterButton.setOnClickListener(new ShutterClickListener());
fullScreenButton.setOnClickListener(new FullscreenClickListener()); fullScreenButton.setOnClickListener(new FullscreenClickListener());
controls.setVisibility(INVISIBLE); ViewUtil.swapChildInPlace(this, this.controls, controls, indexOfChild(quickCamera) + 1);
addView(controls, controlsIndex > -1 ? controlsIndex : indexOfChild(quickCamera) + 1); this.controls = controls;
} }
private boolean isLandscape() { private boolean isLandscape() {
@ -499,7 +499,7 @@ public class QuickAttachmentDrawer extends ViewGroup implements InputView {
COLLAPSED, HALF_EXPANDED, FULL_EXPANDED; COLLAPSED, HALF_EXPANDED, FULL_EXPANDED;
public boolean isVisible() { public boolean isVisible() {
return this == HALF_EXPANDED || this == FULL_EXPANDED; return this != COLLAPSED;
} }
} }

View File

@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.util;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
public class ViewUtil { public class ViewUtil {
public static void setBackgroundSavingPadding(View v, Drawable drawable) { public static void setBackgroundSavingPadding(View v, Drawable drawable) {
@ -38,4 +39,10 @@ public class ViewUtil {
v.setBackgroundResource(resId); v.setBackgroundResource(resId);
v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); 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);
}
} }