Skip to content

Commit

Permalink
Merge pull request #15 from EyeSeeTea/bug-scrolling_problems_when_pre…
Browse files Browse the repository at this point in the history
…ss_keyboard_next

Bug scrolling problems when press keyboard next
  • Loading branch information
xurxodev authored May 25, 2017
2 parents 72f4ab3 + 1ad9dd3 commit c2982be
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.JsonArray;
Expand Down Expand Up @@ -66,7 +69,7 @@ public class DataEntryActivity extends BaseActivity implements LoaderManager.Loa
private AppCompatSpinner formGroupSpinner;

// data entry view
private ListView dataEntryListView;
private static ListView dataEntryListView;
private List<FieldAdapter> adapters;

// state
Expand Down Expand Up @@ -545,4 +548,25 @@ private String buildFieldKey(String dataElement, String categoryOptionCombinatio
return null;
}
}
public static class CustomOnEditorActionListener implements TextView.OnEditorActionListener{

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
final TextView view = v;
if(actionId == EditorInfo.IME_ACTION_NEXT) {
int position=dataEntryListView.getPositionForView(v);
dataEntryListView.smoothScrollToPosition(position+1);
dataEntryListView.postDelayed(new Runnable() {
public void run() {
TextView nextField = (TextView)view.focusSearch(View.FOCUS_DOWN);
if(nextField != null) {
nextField.requestFocus();
}
}
}, 200);
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.io.models.Option;
import org.dhis2.mobile.io.models.OptionSet;
import org.dhis2.mobile.ui.activities.DataEntryActivity;
import org.dhis2.mobile.ui.adapters.dataEntry.AutoCompleteAdapter;

import java.util.ArrayList;
Expand Down Expand Up @@ -115,6 +116,7 @@ public View getView(View convertView) {
holder.listener.setAutoComplete(holder.autoComplete);
holder.button.setOnClickListener(holder.listener);
holder.autoComplete.clearFocus();
holder.autoComplete.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@

package org.dhis2.mobile.ui.adapters.dataEntry.rows;

import org.dhis2.mobile.io.models.Field;

import org.dhis2.mobile.R;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import org.dhis2.mobile.R;
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.ui.activities.DataEntryActivity;

public class IntegerRow implements Row {
private final LayoutInflater inflater;
private final Field field;
Expand Down Expand Up @@ -75,7 +75,8 @@ public View getView(View convertView) {
holder.editText.addTextChangedListener(holder.textWatcher);
holder.editText.setText(field.getValue());
holder.editText.clearFocus();

holder.editText.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@

package org.dhis2.mobile.ui.adapters.dataEntry.rows;

import org.dhis2.mobile.io.models.Field;

import org.dhis2.mobile.R;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import org.dhis2.mobile.R;
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.ui.activities.DataEntryActivity;

public class LongTextRow implements Row {
private final LayoutInflater inflater;
private final Field field;
Expand Down Expand Up @@ -75,7 +75,8 @@ public View getView(View convertView) {
holder.editText.addTextChangedListener(holder.textWatcher);
holder.editText.setText(field.getValue());
holder.editText.clearFocus();

holder.editText.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@

package org.dhis2.mobile.ui.adapters.dataEntry.rows;

import org.dhis2.mobile.io.models.Field;

import org.dhis2.mobile.R;

import android.text.InputFilter;
import android.text.Spanned;
import android.view.LayoutInflater;
Expand All @@ -41,6 +37,10 @@
import android.widget.EditText;
import android.widget.TextView;

import org.dhis2.mobile.R;
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.ui.activities.DataEntryActivity;

public class NegativeIntegerRow implements Row {
private final LayoutInflater inflater;
private final Field field;
Expand Down Expand Up @@ -78,6 +78,7 @@ public View getView(View convertView) {
holder.editText.addTextChangedListener(holder.textWatcher);
holder.editText.setText(field.getValue());
holder.editText.clearFocus();
holder.editText.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@

package org.dhis2.mobile.ui.adapters.dataEntry.rows;

import org.dhis2.mobile.io.models.Field;

import org.dhis2.mobile.R;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import org.dhis2.mobile.R;
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.ui.activities.DataEntryActivity;

public class NumberRow implements Row {
private final LayoutInflater inflater;
private final Field field;
Expand Down Expand Up @@ -75,7 +75,8 @@ public View getView(View convertView) {
holder.editText.addTextChangedListener(holder.textWatcher);
holder.editText.setText(field.getValue());
holder.editText.clearFocus();

holder.editText.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@

package org.dhis2.mobile.ui.adapters.dataEntry.rows;

import org.dhis2.mobile.io.models.Field;

import org.dhis2.mobile.R;

import android.text.InputFilter;
import android.text.Spanned;
import android.view.LayoutInflater;
Expand All @@ -41,6 +37,10 @@
import android.widget.EditText;
import android.widget.TextView;

import org.dhis2.mobile.R;
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.ui.activities.DataEntryActivity;

public class PosIntegerRow implements Row {
private final LayoutInflater inflater;
private final Field field;
Expand Down Expand Up @@ -78,7 +78,8 @@ public View getView(View convertView) {
holder.editText.addTextChangedListener(holder.textWatcher);
holder.editText.setText(field.getValue());
holder.editText.clearFocus();

holder.editText.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@

package org.dhis2.mobile.ui.adapters.dataEntry.rows;

import org.dhis2.mobile.io.models.Field;

import org.dhis2.mobile.R;

import android.text.InputFilter;
import android.text.Spanned;
import android.view.LayoutInflater;
Expand All @@ -41,6 +37,10 @@
import android.widget.EditText;
import android.widget.TextView;

import org.dhis2.mobile.R;
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.ui.activities.DataEntryActivity;

public class PosOrZeroIntegerRow implements Row {
private final LayoutInflater inflater;
private final Field field;
Expand Down Expand Up @@ -78,7 +78,8 @@ public View getView(View convertView) {
holder.editText.addTextChangedListener(holder.textWatcher);
holder.editText.setText(field.getValue());
holder.editText.clearFocus();

holder.editText.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@

package org.dhis2.mobile.ui.adapters.dataEntry.rows;

import org.dhis2.mobile.io.models.Field;

import org.dhis2.mobile.R;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
Expand All @@ -41,6 +37,10 @@
import android.widget.EditText;
import android.widget.TextView;

import org.dhis2.mobile.R;
import org.dhis2.mobile.io.models.Field;
import org.dhis2.mobile.ui.activities.DataEntryActivity;

public class TextRow implements Row {
private final LayoutInflater inflater;
private final Field field;
Expand Down Expand Up @@ -77,6 +77,7 @@ public View getView(View convertView) {
holder.editText.addTextChangedListener(holder.textWatcher);
holder.editText.setText(field.getValue());
holder.editText.clearFocus();
holder.editText.setOnEditorActionListener(new DataEntryActivity.CustomOnEditorActionListener());

return view;
}
Expand Down

0 comments on commit c2982be

Please sign in to comment.