Initial commit of a working Search View.
This commit is contained in:
parent
98e927fb0f
commit
9ce25e7e57
@ -7,23 +7,28 @@ window.setupGeosearch = function() {
|
||||
|
||||
var search = $(this).val();
|
||||
|
||||
if (!runHooks('geoSearch', search)) {
|
||||
return;
|
||||
}
|
||||
if ( window.search(search) ) return;
|
||||
|
||||
$.getJSON(NOMINATIM + encodeURIComponent(search), function(data) {
|
||||
if(!data || !data[0]) return;
|
||||
var b = data[0].boundingbox;
|
||||
if(!b) return;
|
||||
var southWest = new L.LatLng(b[0], b[2]),
|
||||
northEast = new L.LatLng(b[1], b[3]),
|
||||
bounds = new L.LatLngBounds(southWest, northEast);
|
||||
window.map.fitBounds(bounds);
|
||||
if(window.isSmartphone()) window.smartphone.mapButton.click();
|
||||
});
|
||||
e.preventDefault();
|
||||
});
|
||||
$('#geosearchwrapper img').click(function(){
|
||||
map.locate({setView : true, maxZoom: 13});;
|
||||
});
|
||||
}
|
||||
|
||||
window.search = function(search) {
|
||||
if (!runHooks('geoSearch', search)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$.getJSON(NOMINATIM + encodeURIComponent(search), function(data) {
|
||||
if(!data || !data[0]) return true;
|
||||
var b = data[0].boundingbox;
|
||||
if(!b) return true;
|
||||
var southWest = new L.LatLng(b[0], b[2]),
|
||||
northEast = new L.LatLng(b[1], b[3]),
|
||||
bounds = new L.LatLngBounds(southWest, northEast);
|
||||
window.map.fitBounds(bounds);
|
||||
if(window.isSmartphone()) window.smartphone.mapButton.click();
|
||||
});
|
||||
}
|
||||
|
@ -24,13 +24,23 @@
|
||||
android:name="com.cradle.iitc_mobile.IITC_Mobile"
|
||||
android:theme="@style/AppBaseTheme"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<!-- Used for Samsung Multi-Window support -->
|
||||
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Receives the search request. -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH"/>
|
||||
<!-- No category needed, because the Intent will specify this class component-->
|
||||
</intent-filter>
|
||||
|
||||
<!-- Handles the implicit intent to VIEW the www.ingress.com/intel URI -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
@ -46,6 +56,10 @@
|
||||
android:scheme="http"
|
||||
android:pathPrefix="/intel"></data>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Points to searchable meta data. -->
|
||||
<meta-data android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.cradle.iitc_mobile.IITC_Settings"
|
||||
@ -54,6 +68,7 @@
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize">
|
||||
</activity>
|
||||
|
||||
<!-- START Used for Samsung Multi-Window support -->
|
||||
<uses-library
|
||||
android:name="com.sec.android.app.multiwindow"
|
||||
android:required="false"/>
|
||||
@ -74,7 +89,12 @@
|
||||
<meta-data
|
||||
android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H"
|
||||
android:resource="@dimen/app_minimumsize_h"/>
|
||||
<!-- END Used for Samsung Multi-Window support -->
|
||||
|
||||
<!-- Points to searchable activity so the whole app can invoke search. -->
|
||||
<meta-data
|
||||
android:name="android.app.default_searchable"
|
||||
android:value="com.cradle.iitc_mobile.IITC_Mobile"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -4,7 +4,10 @@
|
||||
# view AndroidManifest.xml #generated:23
|
||||
-keep class com.cradle.iitc_mobile.IITC_Mobile { <init>(...); }
|
||||
|
||||
# view AndroidManifest.xml #generated:40
|
||||
# view AndroidManifest.xml #generated:56
|
||||
-keep class com.cradle.iitc_mobile.IITC_SearchableActivity { <init>(...); }
|
||||
|
||||
# view AndroidManifest.xml #generated:50
|
||||
-keep class com.cradle.iitc_mobile.IITC_Settings { <init>(...); }
|
||||
|
||||
# view res/layout/activity_main.xml #generated:6
|
||||
|
@ -1,5 +1,9 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item android:id="@+id/menu_search"
|
||||
android:title="@string/menu_search"
|
||||
android:icon="@drawable/action_search"
|
||||
android:showAsAction="ifRoom|collapseActionView"
|
||||
android:actionViewClass="android.widget.SearchView" />
|
||||
<item
|
||||
android:id="@+id/menu_map"
|
||||
android:icon="@drawable/location_map"
|
||||
|
@ -58,4 +58,6 @@
|
||||
<string name="menu_debug">Debug</string>
|
||||
<string name="choose_account_to_login">Choose account to login</string>
|
||||
<string name="login_failed">Login failed.</string>
|
||||
<string name="search_hint">Search Locations</string>
|
||||
<string name="menu_search">Search</string>
|
||||
</resources>
|
8
mobile/res/xml/searchable.xml
Normal file
8
mobile/res/xml/searchable.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/app_name"
|
||||
android:hint="@string/search_hint"
|
||||
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
|
||||
android:voiceLanguageModel="web_search"
|
||||
android:voiceMaxResults="1">
|
||||
</searchable>
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.SearchManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -20,11 +21,9 @@ import android.os.Handler;
|
||||
import android.os.StrictMode;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.*;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class IITC_Mobile extends Activity {
|
||||
@ -120,8 +119,17 @@ public class IITC_Mobile extends Activity {
|
||||
|
||||
fullscreen_actionbar = sharedPref.getBoolean("pref_fullscreen_actionbar", false);
|
||||
|
||||
handleIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
setIntent(intent);
|
||||
handleIntent(intent);
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
// load new iitc web view with ingress intel page
|
||||
Intent intent = getIntent();
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
Uri uri = intent.getData();
|
||||
@ -133,6 +141,10 @@ public class IITC_Mobile extends Activity {
|
||||
Log.d("iitcm", "loading url...");
|
||||
this.loadUrl(url);
|
||||
}
|
||||
} else if (Intent.ACTION_SEARCH.equals(action)) {
|
||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
||||
query = query.replace("'", "''");
|
||||
iitc_view.loadUrl("javascript:search('" + query + "');");
|
||||
} else {
|
||||
this.loadUrl(intel_url);
|
||||
}
|
||||
@ -238,7 +250,23 @@ public class IITC_Mobile extends Activity {
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
|
||||
// Get the SearchView and set the searchable configuration
|
||||
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||
final MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
|
||||
final SearchView searchView =
|
||||
(SearchView) searchMenuItem.getActionView();
|
||||
// Assumes current activity is the searchable activity
|
||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
|
||||
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
|
||||
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean queryTextFocused) {
|
||||
if(!queryTextFocused) {
|
||||
searchMenuItem.collapseActionView();
|
||||
searchView.setQuery("", false);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -302,6 +330,9 @@ public class IITC_Mobile extends Activity {
|
||||
iitc_view.loadUrl("javascript: window.show('debug')");
|
||||
actionBar.setTitle(getString(R.string.menu_debug));
|
||||
return true;
|
||||
case R.id.menu_search:
|
||||
onSearchRequested();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
@ -26,6 +27,7 @@ public class IITC_WebView extends WebView {
|
||||
|
||||
// init web view
|
||||
private void iitc_init(Context c) {
|
||||
if ( this.isInEditMode() ) return;
|
||||
settings = this.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setDomStorageEnabled(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user