Merge "Fix IllegalStateException of ViewGroup"

main
Tadashi G. Takaoka 2013-12-16 08:36:44 +00:00 committed by Android (Google) Code Review
commit f3b92fb952
3 changed files with 29 additions and 10 deletions

View File

@ -932,11 +932,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override @Override
public void onShowMoreKeysPanel(final MoreKeysPanel panel) { public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
locatePreviewPlacerView(); locatePreviewPlacerView();
// TODO: Remove this check panel.showInParent(mPreviewPlacerView);
if (panel.isShowingInParent()) {
panel.dismissMoreKeysPanel();
}
mPreviewPlacerView.addView(panel.getContainerView());
mMoreKeysPanel = panel; mMoreKeysPanel = panel;
dimEntireKeyboard(true /* dimmed */); dimEntireKeyboard(true /* dimmed */);
} }
@ -954,7 +950,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
public void onDismissMoreKeysPanel(final MoreKeysPanel panel) { public void onDismissMoreKeysPanel(final MoreKeysPanel panel) {
dimEntireKeyboard(false /* dimmed */); dimEntireKeyboard(false /* dimmed */);
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView()); mMoreKeysPanel.removeFromParent();
mMoreKeysPanel = null; mMoreKeysPanel = null;
} }
} }

View File

@ -21,6 +21,7 @@ import android.content.res.Resources;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -216,11 +217,25 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
return true; return true;
} }
@Override private View getContainerView() {
public View getContainerView() {
return (View)getParent(); return (View)getParent();
} }
@Override
public void showInParent(final ViewGroup parentView) {
removeFromParent();
parentView.addView(getContainerView());
}
@Override
public void removeFromParent() {
final View containerView = getContainerView();
final ViewGroup currentParent = (ViewGroup)containerView.getParent();
if (currentParent != null) {
currentParent.removeView(containerView);
}
}
@Override @Override
public boolean isShowingInParent() { public boolean isShowingInParent() {
return (getContainerView().getParent() != null); return (getContainerView().getParent() != null);

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
public interface MoreKeysPanel { public interface MoreKeysPanel {
public interface Controller { public interface Controller {
@ -119,9 +120,16 @@ public interface MoreKeysPanel {
public int translateY(int y); public int translateY(int y);
/** /**
* Return the view containing the more keys panel. * Show this {@link MoreKeysPanel} in the parent view.
*
* @param parentView the {@link ViewGroup} that hosts this {@link MoreKeysPanel}.
*/ */
public View getContainerView(); public void showInParent(ViewGroup parentView);
/**
* Remove this {@link MoreKeysPanel} from the parent view.
*/
public void removeFromParent();
/** /**
* Return whether the panel is currently being shown. * Return whether the panel is currently being shown.