Skip to content

Commit

Permalink
Fixed some issues with switching android text fields. The improvement…
Browse files Browse the repository at this point in the history
… to faster field switching (f3e53a8) appears to hae caused a couple of regressions.

Fixed so that the resize mode (resize or pan) is re-evaluated when the field is switched.  This fixes an issue with the resize mode being fine for the first field, but being inappropriate for the next field.  E.g. in a login dialog you can edit the username, but then the password is covered by a button.
Also fixed so that the on finished editing event is fired in the first text field when changing to the next text field.
  • Loading branch information
shannah committed Apr 27, 2017
1 parent cf3e49c commit 7cbaccf
Showing 1 changed file with 60 additions and 34 deletions.
94 changes: 60 additions & 34 deletions Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java
Expand Up @@ -810,7 +810,7 @@ else if (isEditedFieldSwitch) {
}
}
if (!isEditedFieldSwitch) {
mEditText.addTextChangedListener(mEditText.mTextWatcher);
mEditText.addTextChangedListener(mEditText.mTextWatcher);
}
mEditText.setBackgroundDrawable(null);

Expand Down Expand Up @@ -870,7 +870,7 @@ else if (isEditedFieldSwitch) {
mEditText.setHint(textArea.getHint());
}
if (!isEditedFieldSwitch) {
addView(mEditText, mEditLayoutParams);
addView(mEditText, mEditLayoutParams);
}
invalidate();
setVisibility(VISIBLE);
Expand Down Expand Up @@ -1353,6 +1353,7 @@ public static void edit(final AndroidImplementation impl, final Component compon

final TextArea textArea = (TextArea) component;
final String initialText = textArea.getText();
textArea.putClientProperty("InPlaceEditView.initialText", initialText);
Dimension prefSize = textArea.getPreferredSize();


Expand Down Expand Up @@ -1428,37 +1429,55 @@ public static void edit(final AndroidImplementation impl, final Component compon

if (impl.isAsyncEditMode()) {
isEditedFieldSwitch = true;
final String[] out = new String[1];
TextArea prevTextArea = null;
if(sInstance != null && sInstance.mLastEditText != null) {
prevTextArea = sInstance.mLastEditText.getTextArea();
}

if (prevTextArea != null) {
final TextArea fPrevTextArea = prevTextArea;
final String retVal = sInstance.mLastEditText.getText().toString();
Display.getInstance().callSerially(new Runnable() {
public void run() {
Display.getInstance().onEditingComplete(fPrevTextArea, retVal);
}
});
}


InPlaceEditView.setEditedTextField(textArea);

nextTextArea = null;
} else {
isEditedFieldSwitch = false;

final InPlaceEditView instance = sInstance;
if (instance != null && instance.mEditText != null && instance.mEditText.mTextArea == textArea) {
instance.showTextEditorAgain();
return;
}
if (!isClosing && sInstance != null && sInstance.mEditText != null) {
isClosing = true;
final InPlaceEditView instance = sInstance;
if (instance != null && instance.mEditText != null && instance.mEditText.mTextArea == textArea) {
instance.showTextEditorAgain();
return;
}
if (!isClosing && sInstance != null && sInstance.mEditText != null) {
isClosing = true;

impl.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
instance.endEditing(REASON_UNDEFINED, true);
}
});
}

afterClose = new Runnable() {

impl.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
instance.endEditing(REASON_UNDEFINED, true);
impl.callHideTextEditor();
Display.getInstance().editString(component, textArea.getMaxSize(), inputType, textArea.getText());
}
});
}

afterClose = new Runnable() {

@Override
public void run() {
impl.callHideTextEditor();
Display.getInstance().editString(component, textArea.getMaxSize(), inputType, textArea.getText());
}

};
return;
};
return;
}
} else {
isEditedFieldSwitch = false;
Expand All @@ -1485,32 +1504,35 @@ public void run() {
@Override
public void run() {
if (!isEditedFieldSwitch) {
releaseEdit();
releaseEdit();

if (sInstance == null) {
sInstance = new InPlaceEditView(impl);
impl.relativeLayout.addView(sInstance);
}
if (sInstance == null) {
sInstance = new InPlaceEditView(impl);
impl.relativeLayout.addView(sInstance);
}

// Let's try something new here
// We'll ALWAYS try resize edit mode (since it just works better)
// But we'll detect whether the field is still covered by the keyboard
// and switch to pan mode if necessary.
// Let's try something new here
// We'll ALWAYS try resize edit mode (since it just works better)
// But we'll detect whether the field is still covered by the keyboard
// and switch to pan mode if necessary.



}
if(scrollableParent || parentForm.isFormBottomPaddingEditingMode()){
setEditMode(true);
}else{
trySetEditMode(true);
}
}
sInstance.startEditing(impl.getActivity(), textAreaData, initialText, inputType, isEditedFieldSwitch);
}
});

final String[] out = new String[1];




// In order to reuse the code the runs after edit completion, we will wrap it in a runnable
// For sync edit mode, we will just run onComplete.run() at the end of this method. For
// Async mode we add the Runnable to the textarea as a client property, then run it
Expand Down Expand Up @@ -1662,10 +1684,14 @@ private class TextChange {

}

private class EditView extends AutoCompleteTextView {
class EditView extends AutoCompleteTextView {

private InPlaceEditView mInPlaceEditView;
private TextArea mTextArea = null;

TextArea getTextArea() {
return mTextArea;
}
private ResetableTextWatcher mTextWatcher = new ResetableTextWatcher() {

private boolean started = false;
Expand Down

0 comments on commit 7cbaccf

Please sign in to comment.