Android Search - Enter goes to what was typed in the search field (uses it as an address)

This commit is contained in:
Cristian Luis Duarte 2018-04-18 21:40:37 -03:00
parent 0ae564b9b6
commit e784d45b24
4 changed files with 37 additions and 12 deletions

View file

@ -11,9 +11,6 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import java.net.URI;
import java.net.URISyntaxException;
public class GotoActivity extends AppCompatActivity {
public static final String PARAM_DOMAIN_URL = "domain_url";
@ -60,15 +57,7 @@ public class GotoActivity extends AppCompatActivity {
private void actionGo() {
String urlString = mUrlEditText.getText().toString();
if (!urlString.trim().isEmpty()) {
URI uri;
try {
uri = new URI(urlString);
} catch (URISyntaxException e) {
return;
}
if (uri.getScheme()==null || uri.getScheme().isEmpty()) {
urlString = "hifi://" + urlString;
}
urlString = HifiUtils.getInstance().sanitizeHifiUrl(urlString);
Intent intent = new Intent();
intent.putExtra(GotoActivity.PARAM_DOMAIN_URL, urlString);

View file

@ -1,5 +1,8 @@
package io.highfidelity.hifiinterface;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created by Gabriel Calero & Cristian Duarte on 4/13/18.
*/
@ -18,6 +21,22 @@ public class HifiUtils {
return instance;
}
public String sanitizeHifiUrl(String urlString) {
urlString = urlString.trim();
if (!urlString.isEmpty()) {
URI uri;
try {
uri = new URI(urlString);
} catch (URISyntaxException e) {
return urlString;
}
if (uri.getScheme() == null || uri.getScheme().isEmpty()) {
urlString = "hifi://" + urlString;
}
}
return urlString;
}
public native String getCurrentAddress();
public native String protocolVersionSignature();

View file

@ -14,6 +14,7 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -120,6 +121,20 @@ public class HomeActivity extends AppCompatActivity implements NavigationView.On
domainAdapter.loadDomains(editable.toString());
}
});
searchView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (i == KeyEvent.KEYCODE_ENTER) {
String urlString = searchView.getText().toString();
if (!urlString.trim().isEmpty()) {
urlString = HifiUtils.getInstance().sanitizeHifiUrl(urlString);
}
gotoDomain(urlString);
return true;
}
return false;
}
});
updateLoginMenu();
}

View file

@ -36,6 +36,8 @@
android:gravity="center_vertical|end"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:inputType="textUri"
android:imeOptions="actionGo"
/>
<FrameLayout
android:id="@android:id/tabcontent"