Skip to content

Commit e18b331

Browse files
fix: done button on keyboard will connect to ESP (#2174)
1 parent 710af57 commit e18b331

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

app/src/main/java/io/pslab/fragment/ESPFragment.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import android.support.design.widget.Snackbar;
88
import android.support.v4.app.DialogFragment;
99
import android.util.Log;
10+
import android.view.KeyEvent;
1011
import android.view.LayoutInflater;
1112
import android.view.View;
1213
import android.view.ViewGroup;
14+
import android.view.inputmethod.EditorInfo;
1315
import android.widget.Button;
1416
import android.widget.EditText;
1517
import android.widget.ProgressBar;
18+
import android.widget.TextView;
1619

1720
import java.io.IOException;
1821

@@ -47,14 +50,25 @@ public void onClick(View v) {
4750
if (espIPAddress.length() == 0) {
4851
CustomSnackBar.showSnackBar(getActivity().findViewById(android.R.id.content),
4952
getString(R.string.incorrect_IP_address_message),null,null, Snackbar.LENGTH_SHORT);
53+
5054
} else {
5155
new ESPTask().execute();
5256
}
5357
}
58+
59+
});
60+
espIPEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
61+
@Override
62+
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
63+
if (actionId == EditorInfo.IME_ACTION_DONE) {
64+
espConnectBtn.performClick();
65+
return true;
66+
}
67+
return false;
68+
}
5469
});
5570
return rootView;
5671
}
57-
5872
@Override
5973
public void onResume() {
6074
super.onResume();

app/src/main/res/layout/fragment_esp.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
56
android:padding="@dimen/esp_fragment_padding">
67

78
<EditText
89
android:id="@+id/esp_ip_edit_text"
910
android:layout_width="wrap_content"
1011
android:layout_height="wrap_content"
1112
android:layout_centerHorizontal="true"
13+
android:imeOptions="actionDone"
14+
android:singleLine="true"
1215
android:hint="@string/enter_IP_hint" />
1316

1417
<Button

0 commit comments

Comments
 (0)