am 402d3fd4: am 41867b63: Merge "Fix the support-v4 demos to work on a platform with APIs V4 (samples part)" into ics-mr1

* commit '402d3fd41838dc6a098ec3482f83b20b32df29f4':
  Fix the support-v4 demos to work on a platform with APIs V4 (samples part)
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentMenuSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentMenuSupport.java
index 37a132d..f2f5ec1 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentMenuSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentMenuSupport.java
@@ -22,7 +22,7 @@
 import android.support.v4.app.FragmentActivity;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
-import android.support.v4.view.MenuCompat;
+import android.support.v4.view.MenuItemCompat;
 
 import android.os.Bundle;
 import android.view.Menu;
@@ -112,9 +112,9 @@
         public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
             MenuItem item;
             item = menu.add("Menu 1a");
-            MenuCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM);
+            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
             item = menu.add("Menu 1b");
-            MenuCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM);
+            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
         }
     }
 
@@ -133,7 +133,7 @@
         public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
             MenuItem item;
             item = menu.add("Menu 2");
-            MenuCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM);
+            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
         }
     }
 }
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentReceiveResultSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentReceiveResultSupport.java
index cdc895e..f63826c 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentReceiveResultSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentReceiveResultSupport.java
@@ -40,8 +40,8 @@
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
-                ViewGroup.LayoutParams.MATCH_PARENT,
-                ViewGroup.LayoutParams.MATCH_PARENT);
+                ViewGroup.LayoutParams.FILL_PARENT,
+                ViewGroup.LayoutParams.FILL_PARENT);
         FrameLayout frame = new FrameLayout(this);
         frame.setId(R.id.simple_fragment);
         setContentView(frame, lp);
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCursorSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCursorSupport.java
index 096316c..dd4237b 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCursorSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCursorSupport.java
@@ -22,16 +22,21 @@
 import android.support.v4.app.LoaderManager;
 import android.support.v4.content.CursorLoader;
 import android.support.v4.content.Loader;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v4.widget.SearchViewCompat;
+import android.support.v4.widget.SearchViewCompat.OnQueryTextListenerCompat;
 import android.support.v4.widget.SimpleCursorAdapter;
 
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
-import android.provider.ContactsContract.Contacts;
+import android.provider.BaseColumns;
+import android.provider.Contacts.People;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.view.View;
 import android.widget.ListView;
 
@@ -39,6 +44,7 @@
  * Demonstration of the use of a CursorLoader to load and display contacts
  * data in a fragment.
  */
+@SuppressWarnings("all")
 public class LoaderCursorSupport extends FragmentActivity {
 
     @Override
@@ -76,9 +82,9 @@
 
             // Create an empty adapter we will use to display the loaded data.
             mAdapter = new SimpleCursorAdapter(getActivity(),
-                    android.R.layout.simple_list_item_2, null,
-                    new String[] { Contacts.DISPLAY_NAME, Contacts.CONTACT_STATUS },
-                    new int[] { android.R.id.text1, android.R.id.text2 }, 0);
+                    android.R.layout.simple_list_item_1, null,
+                    new String[] { People.DISPLAY_NAME },
+                    new int[] { android.R.id.text1}, 0);
             setListAdapter(mAdapter);
 
             // Start out with a progress indicator.
@@ -91,21 +97,25 @@
 
         @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
             // Place an action bar item for searching.
-            //MenuItem item = menu.add("Search");
-            //item.setIcon(android.R.drawable.ic_menu_search);
-            //item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-            //SearchView sv = new SearchView(getActivity());
-            //sv.setOnQueryTextListener(this);
-            //item.setActionView(sv);
-        }
-
-        public boolean onQueryTextChange(String newText) {
-            // Called when the action bar search text has changed.  Update
-            // the search filter, and restart the loader to do a new query
-            // with this filter.
-            mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
-            getLoaderManager().restartLoader(0, null, this);
-            return true;
+            MenuItem item = menu.add("Search");
+            item.setIcon(android.R.drawable.ic_menu_search);
+            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
+            View searchView = SearchViewCompat.newSearchView(getActivity());
+            if (searchView != null) {
+                SearchViewCompat.setOnQueryTextListener(searchView,
+                        new OnQueryTextListenerCompat() {
+                    @Override
+                    public boolean onQueryTextChange(String newText) {
+                        // Called when the action bar search text has changed.  Update
+                        // the search filter, and restart the loader to do a new query
+                        // with this filter.
+                        mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
+                        getLoaderManager().restartLoader(0, null, CursorLoaderListFragment.this);
+                        return true;
+                    }
+                });
+                MenuItemCompat.setActionView(item, searchView);
+            }
         }
 
         @Override public void onListItemClick(ListView l, View v, int position, long id) {
@@ -115,12 +125,8 @@
 
         // These are the Contacts rows that we will retrieve.
         static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
-            Contacts._ID,
-            Contacts.DISPLAY_NAME,
-            Contacts.CONTACT_STATUS,
-            Contacts.CONTACT_PRESENCE,
-            Contacts.PHOTO_ID,
-            Contacts.LOOKUP_KEY,
+            People._ID,
+            People.DISPLAY_NAME,
         };
 
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
@@ -130,20 +136,18 @@
             // currently filtering.
             Uri baseUri;
             if (mCurFilter != null) {
-                baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI,
-                        Uri.encode(mCurFilter));
+                baseUri = Uri.withAppendedPath(People.CONTENT_FILTER_URI, Uri.encode(mCurFilter));
             } else {
-                baseUri = Contacts.CONTENT_URI;
+                baseUri = People.CONTENT_URI;
             }
 
             // Now create and return a CursorLoader that will take care of
             // creating a Cursor for the data being displayed.
-            String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
-                    + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
-                    + Contacts.DISPLAY_NAME + " != '' ))";
+            String select = "((" + People.DISPLAY_NAME + " NOTNULL) AND ("
+                    + People.DISPLAY_NAME + " != '' ))";
             return new CursorLoader(getActivity(), baseUri,
                     CONTACTS_SUMMARY_PROJECTION, select, null,
-                    Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
+                    People.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
         }
 
         public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCustomSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCustomSupport.java
index b222a20..ec59738 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCustomSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderCustomSupport.java
@@ -16,15 +16,6 @@
 
 package com.example.android.supportv4.app;
 
-import com.example.android.supportv4.R;
-
-import java.io.File;
-import java.text.Collator;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -41,7 +32,12 @@
 import android.support.v4.app.ListFragment;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.content.AsyncTaskLoader;
+import android.support.v4.content.IntentCompat;
 import android.support.v4.content.Loader;
+import android.support.v4.content.pm.ActivityInfoCompat;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v4.widget.SearchViewCompat;
+import android.support.v4.widget.SearchViewCompat.OnQueryTextListenerCompat;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -53,9 +49,16 @@
 import android.widget.ArrayAdapter;
 import android.widget.ImageView;
 import android.widget.ListView;
-import android.widget.SearchView;
 import android.widget.TextView;
-import android.widget.SearchView.OnQueryTextListener;
+
+import com.example.android.supportv4.R;
+
+import java.io.File;
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 /**
  * Demonstration of the implementation of a custom Loader.
@@ -166,7 +169,7 @@
             int configChanges = mLastConfiguration.updateFrom(res.getConfiguration());
             boolean densityChanged = mLastDensity != res.getDisplayMetrics().densityDpi;
             if (densityChanged || (configChanges&(ActivityInfo.CONFIG_LOCALE
-                    |ActivityInfo.CONFIG_UI_MODE|ActivityInfo.CONFIG_SCREEN_LAYOUT)) != 0) {
+                    |ActivityInfoCompat.CONFIG_UI_MODE|ActivityInfo.CONFIG_SCREEN_LAYOUT)) != 0) {
                 mLastDensity = res.getDisplayMetrics().densityDpi;
                 return true;
             }
@@ -190,8 +193,8 @@
             mLoader.getContext().registerReceiver(this, filter);
             // Register for events related to sdcard installation.
             IntentFilter sdFilter = new IntentFilter();
-            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
-            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
+            sdFilter.addAction(IntentCompat.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
+            sdFilter.addAction(IntentCompat.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
             mLoader.getContext().registerReceiver(this, sdFilter);
         }
 
@@ -372,7 +375,9 @@
         public void setData(List<AppEntry> data) {
             clear();
             if (data != null) {
-                addAll(data);
+                for (AppEntry appEntry : data) {
+                    add(appEntry);
+                }
             }
         }
 
@@ -397,7 +402,7 @@
     }
 
     public static class AppListFragment extends ListFragment
-            implements OnQueryTextListener, LoaderManager.LoaderCallbacks<List<AppEntry>> {
+            implements LoaderManager.LoaderCallbacks<List<AppEntry>> {
 
         // This is the Adapter being used to display the list's data.
         AppListAdapter mAdapter;
@@ -405,6 +410,8 @@
         // If non-null, this is the current filter the user has provided.
         String mCurFilter;
 
+        OnQueryTextListenerCompat mOnQueryTextListenerCompat;
+
         @Override public void onActivityCreated(Bundle savedInstanceState) {
             super.onActivityCreated(savedInstanceState);
 
@@ -431,23 +438,22 @@
             // Place an action bar item for searching.
             MenuItem item = menu.add("Search");
             item.setIcon(android.R.drawable.ic_menu_search);
-            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-            SearchView sv = new SearchView(getActivity());
-            sv.setOnQueryTextListener(this);
-            item.setActionView(sv);
-        }
-
-        @Override public boolean onQueryTextChange(String newText) {
-            // Called when the action bar search text has changed.  Since this
-            // is a simple array adapter, we can just have it do the filtering.
-            mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
-            mAdapter.getFilter().filter(mCurFilter);
-            return true;
-        }
-
-        @Override public boolean onQueryTextSubmit(String query) {
-            // Don't care about this.
-            return true;
+            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
+            View searchView = SearchViewCompat.newSearchView(getActivity());
+            if (searchView != null) {
+                SearchViewCompat.setOnQueryTextListener(searchView,
+                        new OnQueryTextListenerCompat() {
+                    @Override
+                    public boolean onQueryTextChange(String newText) {
+                        // Called when the action bar search text has changed.  Since this
+                        // is a simple array adapter, we can just have it do the filtering.
+                        mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
+                        mAdapter.getFilter().filter(mCurFilter);
+                        return true;
+                    }
+                });
+                MenuItemCompat.setActionView(item, searchView);
+            }
         }
 
         @Override public void onListItemClick(ListView l, View v, int position, long id) {
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java
index de3f937..a1fb2c7 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/app/LoaderThrottleSupport.java
@@ -17,14 +17,6 @@
 package com.example.android.supportv4.app;
 
 //BEGIN_INCLUDE(complete)
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.ListFragment;
-import android.support.v4.app.LoaderManager;
-import android.support.v4.content.CursorLoader;
-import android.support.v4.content.Loader;
-import android.support.v4.widget.SimpleCursorAdapter;
-
 import android.content.ContentProvider;
 import android.content.ContentResolver;
 import android.content.ContentUris;
@@ -32,7 +24,6 @@
 import android.content.Context;
 import android.content.UriMatcher;
 import android.database.Cursor;
-import android.database.DatabaseUtils;
 import android.database.SQLException;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
@@ -41,6 +32,15 @@
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.provider.BaseColumns;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.ListFragment;
+import android.support.v4.app.LoaderManager;
+import android.support.v4.content.CursorLoader;
+import android.support.v4.content.Loader;
+import android.support.v4.database.DatabaseUtilsCompat;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v4.widget.SimpleCursorAdapter;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
@@ -226,7 +226,7 @@
                     // The incoming URI is for a single row.
                     qb.setProjectionMap(mNotesProjectionMap);
                     qb.appendWhere(MainTable._ID + "=?");
-                    selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
+                    selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                             new String[] { uri.getLastPathSegment() });
                     break;
 
@@ -321,7 +321,7 @@
                 case MAIN_ID:
                     // If URI is for a particular row ID, delete is based on incoming
                     // data but modified to restrict to the given ID.
-                    finalWhere = DatabaseUtils.concatenateWhere(
+                    finalWhere = DatabaseUtilsCompat.concatenateWhere(
                             MainTable._ID + " = " + ContentUris.parseId(uri), where);
                     count = db.delete(MainTable.TABLE_NAME, finalWhere, whereArgs);
                     break;
@@ -353,7 +353,7 @@
                 case MAIN_ID:
                     // If URI is for a particular row ID, update is based on incoming
                     // data but modified to restrict to the given ID.
-                    finalWhere = DatabaseUtils.concatenateWhere(
+                    finalWhere = DatabaseUtilsCompat.concatenateWhere(
                             MainTable._ID + " = " + ContentUris.parseId(uri), where);
                     count = db.update(MainTable.TABLE_NAME, values, finalWhere, whereArgs);
                     break;
@@ -419,10 +419,10 @@
         }
 
         @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
-            menu.add(Menu.NONE, POPULATE_ID, 0, "Populate")
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-            menu.add(Menu.NONE, CLEAR_ID, 0, "Clear")
-                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+            MenuItem populateItem = menu.add(Menu.NONE, POPULATE_ID, 0, "Populate");
+            MenuItemCompat.setShowAsAction(populateItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
+            MenuItem clearItem = menu.add(Menu.NONE, CLEAR_ID, 0, "Clear");
+            MenuItemCompat.setShowAsAction(clearItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
         }
 
         @Override public boolean onOptionsItemSelected(MenuItem item) {
@@ -453,8 +453,7 @@
                             return null;
                         }
                     };
-                    mPopulatingTask.executeOnExecutor(
-                            AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);
+                    mPopulatingTask.execute((Void[]) null);
                     return true;
 
                 case CLEAR_ID:
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/content/LocalServiceBroadcaster.java b/samples/Support4Demos/src/com/example/android/supportv4/content/LocalServiceBroadcaster.java
index d4dc8e1..62a320c 100644
--- a/samples/Support4Demos/src/com/example/android/supportv4/content/LocalServiceBroadcaster.java
+++ b/samples/Support4Demos/src/com/example/android/supportv4/content/LocalServiceBroadcaster.java
@@ -28,6 +28,7 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
+import android.support.v4.app.ServiceCompat;
 import android.support.v4.content.LocalBroadcastManager;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -135,7 +136,6 @@
             mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
         }
 
-        @Override
         public int onStartCommand(Intent intent, int flags, int startId) {
             // Tell any local interested parties about the start.
             mLocalBroadcastManager.sendBroadcast(new Intent(ACTION_STARTED));
@@ -144,7 +144,7 @@
             mHandler.removeMessages(MSG_UPDATE);
             Message msg = mHandler.obtainMessage(MSG_UPDATE);
             mHandler.sendMessageDelayed(msg, 1000);
-            return Service.START_STICKY;
+            return ServiceCompat.START_STICKY;
         }
 
         @Override