mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 01:08:48 +02:00
Android Search - Enter goes to what was typed in the search field (uses it as an address)
This commit is contained in:
parent
0ae564b9b6
commit
e784d45b24
4 changed files with 37 additions and 12 deletions
|
@ -11,9 +11,6 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
public class GotoActivity extends AppCompatActivity {
|
public class GotoActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static final String PARAM_DOMAIN_URL = "domain_url";
|
public static final String PARAM_DOMAIN_URL = "domain_url";
|
||||||
|
@ -60,15 +57,7 @@ public class GotoActivity extends AppCompatActivity {
|
||||||
private void actionGo() {
|
private void actionGo() {
|
||||||
String urlString = mUrlEditText.getText().toString();
|
String urlString = mUrlEditText.getText().toString();
|
||||||
if (!urlString.trim().isEmpty()) {
|
if (!urlString.trim().isEmpty()) {
|
||||||
URI uri;
|
urlString = HifiUtils.getInstance().sanitizeHifiUrl(urlString);
|
||||||
try {
|
|
||||||
uri = new URI(urlString);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (uri.getScheme()==null || uri.getScheme().isEmpty()) {
|
|
||||||
urlString = "hifi://" + urlString;
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(GotoActivity.PARAM_DOMAIN_URL, urlString);
|
intent.putExtra(GotoActivity.PARAM_DOMAIN_URL, urlString);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package io.highfidelity.hifiinterface;
|
package io.highfidelity.hifiinterface;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gabriel Calero & Cristian Duarte on 4/13/18.
|
* Created by Gabriel Calero & Cristian Duarte on 4/13/18.
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +21,22 @@ public class HifiUtils {
|
||||||
return instance;
|
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 getCurrentAddress();
|
||||||
|
|
||||||
public native String protocolVersionSignature();
|
public native String protocolVersionSignature();
|
||||||
|
|
|
@ -14,6 +14,7 @@ import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -120,6 +121,20 @@ public class HomeActivity extends AppCompatActivity implements NavigationView.On
|
||||||
domainAdapter.loadDomains(editable.toString());
|
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();
|
updateLoginMenu();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
android:gravity="center_vertical|end"
|
android:gravity="center_vertical|end"
|
||||||
android:paddingStart="32dp"
|
android:paddingStart="32dp"
|
||||||
android:paddingEnd="32dp"
|
android:paddingEnd="32dp"
|
||||||
|
android:inputType="textUri"
|
||||||
|
android:imeOptions="actionGo"
|
||||||
/>
|
/>
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@android:id/tabcontent"
|
android:id="@android:id/tabcontent"
|
||||||
|
|
Loading…
Reference in a new issue