am 6630bfd9: Merge "update searchable dictionary for Android U class" into ics-mr1

* commit '6630bfd9ac3df7ee11c3b8e9abd4c1ee2b58fc17':
  update searchable dictionary for Android U class
This commit is contained in:
Robert Ly
2012-03-14 15:43:18 -07:00
committed by Android Git Automerger
4 changed files with 23 additions and 15 deletions

View File

@@ -21,7 +21,7 @@
android:versionCode="2" android:versionCode="2"
android:versionName="2.0"> android:versionName="2.0">
<uses-sdk android:minSdkVersion="11" /> <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<application android:label="@string/app_name" <application android:label="@string/app_name"
android:icon="@drawable/ic_dictionary"> android:icon="@drawable/ic_dictionary">

View File

@@ -21,6 +21,6 @@
<item android:id="@+id/search" <item android:id="@+id/search"
android:title="@string/menu_search" android:title="@string/menu_search"
android:icon="@drawable/ic_menu_search" android:icon="@drawable/ic_menu_search"
android:showAsAction="ifRoom" android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" /> android:actionViewClass="android.widget.SearchView" />
</menu> </menu>

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@@ -59,7 +60,7 @@ public class SearchableDictionary extends Activity {
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
// Because this activity has set launchMode="singleTop", the system calls this method // Because this activity has set launchMode="singleTop", the system calls this method
// to deliver the intent if this actvity is currently the foreground activity when // to deliver the intent if this activity is currently the foreground activity when
// invoked again (when the user executes a search from this activity, we don't create // invoked again (when the user executes a search from this activity, we don't create
// a new instance of this activity, so the system delivers the search intent here) // a new instance of this activity, so the system delivers the search intent here)
handleIntent(intent); handleIntent(intent);
@@ -71,7 +72,6 @@ public class SearchableDictionary extends Activity {
Intent wordIntent = new Intent(this, WordActivity.class); Intent wordIntent = new Intent(this, WordActivity.class);
wordIntent.setData(intent.getData()); wordIntent.setData(intent.getData());
startActivity(wordIntent); startActivity(wordIntent);
finish();
} else if (Intent.ACTION_SEARCH.equals(intent.getAction())) { } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
// handles a search query // handles a search query
String query = intent.getStringExtra(SearchManager.QUERY); String query = intent.getStringExtra(SearchManager.QUERY);
@@ -113,6 +113,8 @@ public class SearchableDictionary extends Activity {
// Define the on-click listener for the list items // Define the on-click listener for the list items
mListView.setOnItemClickListener(new OnItemClickListener() { mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Build the Intent used to open WordActivity with a specific word Uri // Build the Intent used to open WordActivity with a specific word Uri
Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class); Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
@@ -130,10 +132,12 @@ public class SearchableDictionary extends Activity {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu); inflater.inflate(R.menu.options_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setIconifiedByDefault(false); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
}
return true; return true;
} }

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@@ -34,14 +35,15 @@ import android.widget.TextView;
* Displays a word and its definition. * Displays a word and its definition.
*/ */
public class WordActivity extends Activity { public class WordActivity extends Activity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.word); setContentView(R.layout.word);
ActionBar actionBar = getActionBar(); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
actionBar.setDisplayHomeAsUpEnabled(true); ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
Uri uri = getIntent().getData(); Uri uri = getIntent().getData();
Cursor cursor = managedQuery(uri, null, null, null, null); Cursor cursor = managedQuery(uri, null, null, null, null);
@@ -67,10 +69,12 @@ public class WordActivity extends Activity {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu); inflater.inflate(R.menu.options_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setIconifiedByDefault(false); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
}
return true; return true;
} }