[Android] [PATCH] Search in Toolbar, dropped for Android Eclair

Jean-Baptiste Kempf jb at videolan.org
Wed Mar 4 13:27:42 CET 2015


LGTM if does not crash Eclair.

On 04 Mar, Geoffrey Métais wrote :
> ---
>  vlc-android/AndroidManifest.xml                    |   3 +
>  vlc-android/res/menu/media_library.xml             |   3 +-
>  vlc-android/res/values/strings.xml                 |   1 +
>  vlc-android/res/xml/searchable.xml                 |   4 +
>  .../src/org/videolan/vlc/MediaDatabase.java        |  32 +--
>  .../src/org/videolan/vlc/gui/MainActivity.java     |  63 +++---
>  .../src/org/videolan/vlc/gui/SearchFragment.java   | 229 ---------------------
>  .../org/videolan/vlc/gui/SearchHistoryAdapter.java |  58 ------
>  .../org/videolan/vlc/gui/SearchResultAdapter.java  |  67 ------
>  .../videolan/vlc/gui/SearchSuggestionsAdapter.java |  71 +++++++
>  10 files changed, 133 insertions(+), 398 deletions(-)
>  create mode 100644 vlc-android/res/xml/searchable.xml
>  delete mode 100644 vlc-android/src/org/videolan/vlc/gui/SearchFragment.java
>  delete mode 100644 vlc-android/src/org/videolan/vlc/gui/SearchHistoryAdapter.java
>  delete mode 100644 vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java
>  create mode 100644 vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
> 
> diff --git a/vlc-android/AndroidManifest.xml b/vlc-android/AndroidManifest.xml
> index e0d1d7d..6e3ca29 100644
> --- a/vlc-android/AndroidManifest.xml
> +++ b/vlc-android/AndroidManifest.xml
> @@ -55,6 +55,9 @@
>  
>                  <category android:name="android.intent.category.LAUNCHER" />
>              </intent-filter>
> +            <meta-data android:name="android.app.searchable"
> +                android:resource="@xml/searchable" />
> +
>          </activity>
>          <activity android:name=".gui.CompatErrorActivity" />
>          <activity android:name=".gui.PreferencesActivity"
> diff --git a/vlc-android/res/menu/media_library.xml b/vlc-android/res/menu/media_library.xml
> index 24086f0..d8d7d9f 100644
> --- a/vlc-android/res/menu/media_library.xml
> +++ b/vlc-android/res/menu/media_library.xml
> @@ -20,9 +20,10 @@
>      <item
>          android:id="@+id/ml_menu_search"
>          android:icon="@drawable/ic_menu_search"
> +        vlc:actionViewClass="android.support.v7.widget.SearchView"
>          android:title="@string/searchable_hint"
>          android:nextFocusDown="@id/ml_menu_search"
> -        vlc:showAsAction="ifRoom" />
> +        vlc:showAsAction="always|collapseActionView"/>
>      <item
>          android:title="@string/sortby"
>          android:icon="@drawable/ic_menu_sortby"
> diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
> index caa5192..9a5f437 100644
> --- a/vlc-android/res/values/strings.xml
> +++ b/vlc-android/res/values/strings.xml
> @@ -318,6 +318,7 @@
>      <string name="network_shares_discovery">Looking for network shares...</string>
>      <string name="network_empty">This directory is empty.</string>
>      <string name="network_connection_needed">No connection to local network.</string>
> +    <string name="search_hint">Search media</string>
>  
>      <string-array name="hardware_acceleration_list">
>          <item>@string/automatic</item>
> diff --git a/vlc-android/res/xml/searchable.xml b/vlc-android/res/xml/searchable.xml
> new file mode 100644
> index 0000000..443afb5
> --- /dev/null
> +++ b/vlc-android/res/xml/searchable.xml
> @@ -0,0 +1,4 @@
> +<?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" />
> \ No newline at end of file
> diff --git a/vlc-android/src/org/videolan/vlc/MediaDatabase.java b/vlc-android/src/org/videolan/vlc/MediaDatabase.java
> index 0912abe..375477c 100644
> --- a/vlc-android/src/org/videolan/vlc/MediaDatabase.java
> +++ b/vlc-android/src/org/videolan/vlc/MediaDatabase.java
> @@ -50,19 +50,19 @@ public class MediaDatabase {
>  
>      private SQLiteDatabase mDb;
>      private static final String DB_NAME = "vlc_database";
> -    private static final int DB_VERSION = 15;
> +    private static final int DB_VERSION = 16;
>      private static final int CHUNK_SIZE = 50;
>  
>      private static final String DIR_TABLE_NAME = "directories_table";
>      private static final String DIR_ROW_PATH = "path";
>  
>      private static final String MEDIA_TABLE_NAME = "media_table";
> -    private static final String MEDIA_LOCATION = "location";
> +    public static final String MEDIA_LOCATION = "_id"; //standard key for primary key, needed for search suggestions
>      private static final String MEDIA_TIME = "time";
>      private static final String MEDIA_LENGTH = "length";
>      private static final String MEDIA_TYPE = "type";
>      private static final String MEDIA_PICTURE = "picture";
> -    private static final String MEDIA_TITLE = "title";
> +    public static final String MEDIA_TITLE = "title";
>      private static final String MEDIA_ARTIST = "artist";
>      private static final String MEDIA_GENRE = "genre";
>      private static final String MEDIA_ALBUM = "album";
> @@ -571,21 +571,23 @@ public class MediaDatabase {
>          return files;
>      }
>  
> -    public synchronized ArrayList<String> searchMedia(String filter, int type){
> -
> -        ArrayList<String> mediaList = new ArrayList<String>();
> -
> +    public synchronized Cursor queryMedia(String query, int type){
>          String[] queryColumns = new String[]{MEDIA_LOCATION, MEDIA_TITLE, MEDIA_ALBUM, MEDIA_ARTIST, MEDIA_TYPE};
>          String queryString = MEDIA_TITLE+" LIKE ? OR "+MEDIA_ALBUM+" LIKE ? OR "+MEDIA_ARTIST+" LIKE ?";
>          String [] queryArgs;
>          if (type != MediaWrapper.TYPE_ALL) {
>              queryString = "( " + queryString + " ) AND " + MEDIA_TYPE + "=?";
> -            queryArgs = new String[]{"%"+filter+"%", "%"+filter+"%", "%"+filter+"%", String.valueOf(type)};
> +            queryArgs = new String[]{"%"+query+"%", "%"+query+"%", "%"+query+"%", String.valueOf(type)};
>          } else
> -            queryArgs = new String[]{"%"+filter+"%", "%"+filter+"%", "%"+filter+"%"};
> +            queryArgs = new String[]{"%"+query+"%", "%"+query+"%", "%"+query+"%"};
>  
> -        Cursor cursor = mDb.query(MEDIA_TABLE_NAME,
> -                queryColumns, queryString, queryArgs, null, null, null, null);
> +        return mDb.query(MEDIA_TABLE_NAME, queryColumns, queryString, queryArgs, null, null, null, null);
> +    }
> +
> +    public synchronized ArrayList<String> searchMedia(String filter, int type){
> +
> +        ArrayList<String> mediaList = new ArrayList<String>();
> +        Cursor cursor = queryMedia(filter, type);
>          if (cursor.moveToFirst()){
>              do {
>                  mediaList.add(cursor.getString(0));
> @@ -830,7 +832,7 @@ public class MediaDatabase {
>              default:
>                  return;
>          }
> -        mDb.update(MEDIA_TABLE_NAME, values, MEDIA_LOCATION + "=?", new String[] { location });
> +        mDb.update(MEDIA_TABLE_NAME, values, MEDIA_LOCATION + "=?", new String[]{location});
>      }
>  
>      /**
> @@ -852,7 +854,7 @@ public class MediaDatabase {
>       * @param path
>       */
>      public synchronized void removeDir(String path) {
> -        mDb.delete(DIR_TABLE_NAME, DIR_ROW_PATH + "=?", new String[] { path });
> +        mDb.delete(DIR_TABLE_NAME, DIR_ROW_PATH + "=?", new String[]{path});
>      }
>  
>      /**
> @@ -924,7 +926,7 @@ public class MediaDatabase {
>          ArrayList<String> history = new ArrayList<String>();
>  
>          Cursor cursor = mDb.query(SEARCHHISTORY_TABLE_NAME,
> -                new String[] { SEARCHHISTORY_KEY },
> +                new String[]{SEARCHHISTORY_KEY},
>                  null, null, null, null,
>                  SEARCHHISTORY_DATE + " DESC",
>                  Integer.toString(size));
> @@ -970,7 +972,7 @@ public class MediaDatabase {
>      }
>  
>      public synchronized void deleteMrlUri(String uri) {
> -        mDb.delete(MRL_TABLE_NAME, MRL_URI + "=?", new String[] { uri });
> +        mDb.delete(MRL_TABLE_NAME, MRL_URI + "=?", new String[]{uri});
>      }
>  
>      public synchronized void clearMrlHistory() {
> diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
> index fdd1520..7619544 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
> @@ -21,12 +21,14 @@
>  package org.videolan.vlc.gui;
>  
>  import android.annotation.TargetApi;
> +import android.app.SearchManager;
>  import android.content.BroadcastReceiver;
>  import android.content.Context;
>  import android.content.Intent;
>  import android.content.IntentFilter;
>  import android.content.SharedPreferences;
>  import android.content.SharedPreferences.Editor;
> +import android.database.Cursor;
>  import android.graphics.Color;
>  import android.os.Build;
>  import android.os.Bundle;
> @@ -38,10 +40,12 @@ import android.support.v4.app.FragmentActivity;
>  import android.support.v4.app.FragmentManager;
>  import android.support.v4.app.FragmentTransaction;
>  import android.support.v4.view.GravityCompat;
> +import android.support.v4.view.MenuItemCompat;
>  import android.support.v4.widget.DrawerLayout;
>  import android.support.v7.app.ActionBar;
>  import android.support.v7.app.ActionBarActivity;
>  import android.support.v7.app.ActionBarDrawerToggle;
> +import android.support.v7.widget.SearchView;
>  import android.support.v7.widget.Toolbar;
>  import android.util.Log;
>  import android.view.KeyEvent;
> @@ -63,6 +67,7 @@ import org.videolan.libvlc.LibVlcUtil;
>  import org.videolan.vlc.BuildConfig;
>  import org.videolan.vlc.MediaDatabase;
>  import org.videolan.vlc.MediaLibrary;
> +import org.videolan.vlc.MediaWrapper;
>  import org.videolan.vlc.R;
>  import org.videolan.vlc.VLCApplication;
>  import org.videolan.vlc.audio.AudioService;
> @@ -87,7 +92,7 @@ import java.util.Arrays;
>  import java.util.HashMap;
>  import java.util.List;
>  
> -public class MainActivity extends ActionBarActivity implements OnItemClickListener {
> +public class MainActivity extends ActionBarActivity implements OnItemClickListener, SearchView.OnQueryTextListener {
>      public final static String TAG = "VLC/MainActivity";
>  
>      protected static final String ACTION_SHOW_PROGRESSBAR = "org.videolan.vlc.gui.ShowProgressBar";
> @@ -132,6 +137,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>      private int mFocusedPrior = 0;
>      private int mActionBarIconId = -1;
>      Menu mMenu;
> +    private SearchView mSearchView;
>  
>      @Override
>      protected void onCreate(Bundle savedInstanceState) {
> @@ -486,8 +492,6 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>              f = new EqualizerFragment();
>          } else if(id.equals("about")) {
>              f = new AboutFragment();
> -        } else if(id.equals("search")) {
> -            f = new SearchFragment();
>          } else if(id.equals("mediaInfo")) {
>              f = new MediaInfoFragment();
>          } else if(id.equals("videoGroupList")) {
> @@ -533,6 +537,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>  
>      /** Create menu from XML
>       */
> +    @TargetApi(Build.VERSION_CODES.FROYO)
>      @Override
>      public boolean onCreateOptionsMenu(Menu menu) {
>          mMenu = menu;
> @@ -542,6 +547,16 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>           */
>          MenuInflater inflater = getMenuInflater();
>          inflater.inflate(R.menu.media_library, menu);
> +
> +        if (LibVlcUtil.isFroyoOrLater()) {
> +            SearchManager searchManager =
> +                    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
> +            mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search));
> +            mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
> +            mSearchView.setOnQueryTextListener(this);
> +            mSearchView.setSuggestionsAdapter(new SearchSuggestionsAdapter(this, null));
> +        } else
> +            menu.findItem(R.id.ml_menu_search).setVisible(false);
>          return super.onCreateOptionsMenu(menu);
>      }
>  
> @@ -557,9 +572,6 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>              menu.findItem(R.id.ml_menu_sortby).setEnabled(true);
>              menu.findItem(R.id.ml_menu_sortby).setVisible(true);
>          }
> -        // Enable the clear search history function for the search fragment.
> -        if (mCurrentFragment != null && mCurrentFragment.equals("search"))
> -            menu.findItem(R.id.search_clear_history).setVisible(true);
>  
>          boolean networkSave = current instanceof NetworkFragment && !((NetworkFragment)current).isRootDirectory();
>          if (networkSave) {
> @@ -576,15 +588,9 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>          menu.findItem(R.id.ml_menu_clean).setVisible(SidebarEntry.ID_MRL.equals(mCurrentFragment));
>          menu.findItem(R.id.ml_menu_last_playlist).setVisible(SidebarEntry.ID_AUDIO.equals(mCurrentFragment));
>  
> -        return super.onPrepareOptionsMenu(menu);
> -    }
>  
> -    @Override
> -    public boolean onSearchRequested() {
> -        if (mCurrentFragment != null && mCurrentFragment.equals("search"))
> -            ((SearchFragment)fetchSecondaryFragment("search")).onSearchKeyPressed();
> -        showSecondaryFragment("search");
> -        return true;
> +
> +        return super.onPrepareOptionsMenu(menu);
>      }
>  
>      /**
> @@ -622,9 +628,6 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>                  Intent i = new Intent(AudioService.ACTION_REMOTE_LAST_PLAYLIST);
>                  sendBroadcast(i);
>                  break;
> -            case R.id.ml_menu_search:
> -                onSearchRequested();
> -                break;
>              case android.R.id.home:
>                  // Slide down the audio player.
>                  if (slideDownAudioPlayer())
> @@ -644,9 +647,6 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>                  if (getFragment(mCurrentFragment) instanceof MRLPanelFragment)
>                      ((MRLPanelFragment)getFragment(mCurrentFragment)).clearHistory();
>                  break;
> -            case R.id.search_clear_history:
> -                MediaDatabase.getInstance().clearSearchHistory();
> -                break;
>              case R.id.ml_menu_save:
>                  if (current == null)
>                      break;
> @@ -785,14 +785,6 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>          mCurrentFragment = sharedPrefs.getString("fragment", "video");
>      }
>  
> -    /**
> -     * onClick event from xml
> -     * @param view
> -     */
> -    public void searchClick(View view) {
> -        onSearchRequested();
> -    }
> -
>      private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {
>          @Override
>          public void onReceive(Context context, Intent intent) {
> @@ -831,6 +823,20 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>          }
>      };
>  
> +    @Override
> +    public boolean onQueryTextSubmit(String query) {
> +        return false;
> +    }
> +
> +    @Override
> +    public boolean onQueryTextChange(String newText) {
> +        if (newText.length() < 3)
> +            return false;
> +        Cursor cursor = MediaDatabase.getInstance().queryMedia(newText, MediaWrapper.TYPE_ALL);
> +        mSearchView.getSuggestionsAdapter().changeCursor(cursor);
> +        return true;
> +    }
> +
>      private static class MainActivityHandler extends WeakHandler<MainActivity> {
>          public MainActivityHandler(MainActivity owner) {
>              super(owner);
> @@ -878,6 +884,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
>       * Show the audio player.
>       */
>      public void showAudioPlayer() {
> +        mActionBar.collapseActionView();
>          // Open the pane only if is entirely opened.
>          if (mSlidingPane.getState() == mSlidingPane.STATE_OPENED_ENTIRELY)
>              mSlidingPane.openPane();
> diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchFragment.java b/vlc-android/src/org/videolan/vlc/gui/SearchFragment.java
> deleted file mode 100644
> index 88c773e..0000000
> --- a/vlc-android/src/org/videolan/vlc/gui/SearchFragment.java
> +++ /dev/null
> @@ -1,229 +0,0 @@
> -/*****************************************************************************
> - * SearchFragment.java
> - *****************************************************************************
> - * Copyright © 2011-2012 VLC authors and VideoLAN
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> - *****************************************************************************/
> -
> -package org.videolan.vlc.gui;
> -
> -import java.util.ArrayList;
> -
> -import org.videolan.vlc.MediaWrapper;
> -import org.videolan.vlc.MediaDatabase;
> -import org.videolan.vlc.MediaLibrary;
> -import org.videolan.vlc.R;
> -import org.videolan.vlc.audio.AudioServiceController;
> -import org.videolan.vlc.gui.video.VideoPlayerActivity;
> -
> -import android.content.Context;
> -import android.os.Bundle;
> -import android.os.Handler;
> -import android.support.v4.app.ListFragment;
> -import android.support.v7.app.ActionBarActivity;
> -import android.text.Editable;
> -import android.text.TextWatcher;
> -import android.view.KeyEvent;
> -import android.view.LayoutInflater;
> -import android.view.View;
> -import android.view.ViewGroup;
> -import android.view.inputmethod.InputMethodManager;
> -import android.widget.EditText;
> -import android.widget.LinearLayout;
> -import android.widget.ListView;
> -import android.widget.TextView;
> -import android.widget.TextView.OnEditorActionListener;
> -
> -public class SearchFragment extends ListFragment {
> -
> -    public final static String TAG = "VLC/SearchActivity";
> -
> -    private EditText mSearchText;
> -    private SearchHistoryAdapter mHistoryAdapter;
> -    private SearchResultAdapter mResultAdapter;
> -    private LinearLayout mListHeader;
> -
> -    final private Handler mHandler = new Handler();
> -
> -    @Override
> -    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
> -        ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(R.string.search);
> -
> -        View v = inflater.inflate(R.layout.search, container, false);
> -
> -        // TODO: create layout
> -        mHistoryAdapter = new SearchHistoryAdapter(getActivity());
> -        mResultAdapter = new SearchResultAdapter(getActivity());
> -
> -        return v;
> -    }
> -
> -    @Override
> -    public void onActivityCreated(Bundle savedInstanceState) {
> -        super.onActivityCreated(savedInstanceState);
> -        View v = getView();
> -
> -        mSearchText = (EditText) v.findViewById(R.id.search_text);
> -        mSearchText.setOnEditorActionListener(searchTextListener);
> -        mSearchText.addTextChangedListener(searchTextWatcher);
> -    }
> -
> -    @Override
> -    public void onResume() {
> -        super.onResume();
> -
> -        mSearchText.requestFocus();
> -
> -        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
> -        imm.showSoftInput(mSearchText, InputMethodManager.SHOW_IMPLICIT);
> -
> -        showSearchHistory();
> -    }
> -
> -    @Override
> -    public void onPause() {
> -        super.onPause();
> -
> -        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
> -        imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
> -    }
> -
> -    private void search(final String key, final int type) {
> -        mResultAdapter.clear();
> -        new Thread(new Runnable() {
> -            public void run() {
> -                final ArrayList<MediaWrapper> mediaList = MediaLibrary.getInstance().searchMedia(key, type);
> -                mHandler.post(new Runnable() {
> -                    public void run() {
> -                        int count = mediaList.size();
> -                        for (int i = 0 ; i < count ; ++i)
> -                            mResultAdapter.add(mediaList.get(i));
> -                        mResultAdapter.sort();
> -
> -                        String headerText = getResources().getQuantityString(R.plurals.search_found_results_quantity, mediaList.size(), mediaList.size());
> -                        showListHeader(headerText);
> -
> -                        setListAdapter(mResultAdapter);
> -                    }
> -                });
> -            }
> -        }).start();
> -
> -    }
> -
> -    private void showListHeader(String text) {
> -        ListView lv = getListView();
> -
> -        // Create a new header if it doesn't already exist
> -        if (mListHeader == null) {
> -            LayoutInflater infalter =  (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
> -            mListHeader = (LinearLayout) infalter.inflate(R.layout.list_header, lv, false);
> -            lv.addHeaderView(mListHeader, null, false);
> -        }
> -
> -        // Set header text
> -        TextView headerText = (TextView) mListHeader.findViewById(R.id.text);
> -        headerText.setText(text);
> -    }
> -
> -    private void showSearchHistory() {
> -        // Add header to the history
> -        String headerText = getString(R.string.search_history);
> -        showListHeader(headerText);
> -
> -        MediaDatabase db = MediaDatabase.getInstance();
> -        mHistoryAdapter.clear();
> -        ArrayList<String> history = db.getSearchhistory(20);
> -        for (String s : history)
> -            mHistoryAdapter.add(s);
> -        mHistoryAdapter.notifyDataSetChanged();
> -        setListAdapter(mHistoryAdapter);
> -    }
> -
> -    private final TextWatcher searchTextWatcher = new TextWatcher() {
> -
> -        @Override
> -        public void onTextChanged(CharSequence s, int start, int before, int count) {
> -            if (s.length() > 0) {
> -                search(s.toString(), MediaWrapper.TYPE_ALL);
> -            } else {
> -                showSearchHistory();
> -            }
> -        }
> -
> -        @Override
> -        public void beforeTextChanged(CharSequence s, int start, int count,
> -                int after) {
> -
> -        }
> -
> -        @Override
> -        public void afterTextChanged(Editable s) {
> -
> -        }
> -    };
> -
> -    private final OnEditorActionListener searchTextListener = new OnEditorActionListener() {
> -        @Override
> -        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
> -            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
> -            imm.hideSoftInputFromWindow(mSearchText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
> -            return false;
> -        }
> -    };
> -
> -    @Override
> -    public void onListItemClick(ListView l, View v, int position, long id) {
> -        if (getListAdapter() == mHistoryAdapter) {
> -            String selection = ((TextView) v.findViewById(android.R.id.text1)).getText().toString();
> -            mSearchText.setText(selection);
> -            mSearchText.setSelection(selection.length());
> -            mSearchText.requestFocus();
> -        } else if (getListAdapter() == mResultAdapter) {
> -            // add search text to the database (history)
> -            MediaDatabase db = MediaDatabase.getInstance();
> -            db.addSearchhistoryItem(mSearchText.getText().toString());
> -
> -            // open media in the player
> -            MediaWrapper item = (MediaWrapper) getListView().getItemAtPosition(position);
> -            if (item != null) {
> -                if (item.getType() == MediaWrapper.TYPE_VIDEO) {
> -                    VideoPlayerActivity.start(getActivity(), item.getLocation());
> -                } else {
> -                    ArrayList<String> arr = new ArrayList<String>();
> -                    for (int i = 0; i < getListAdapter().getCount(); i++) {
> -                        MediaWrapper audioItem = (MediaWrapper) getListAdapter().getItem(i);
> -                        if (audioItem.getType() == MediaWrapper.TYPE_AUDIO)
> -                            arr.add(audioItem.getLocation());
> -                    }
> -                    AudioServiceController.getInstance().load(arr, arr.indexOf(item.getLocation()));
> -                    return;
> -                }
> -            }
> -            super.onListItemClick(l, v, position, id);
> -
> -        }
> -    };
> -
> -    public void onSearchKeyPressed() {
> -        if (mSearchText == null)
> -            return;
> -        mSearchText.requestFocus();
> -        mSearchText.setSelection(mSearchText.getText().length());
> -        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
> -        imm.showSoftInput(mSearchText, InputMethodManager.RESULT_SHOWN);
> -    }
> -}
> diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchHistoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SearchHistoryAdapter.java
> deleted file mode 100644
> index a288f69..0000000
> --- a/vlc-android/src/org/videolan/vlc/gui/SearchHistoryAdapter.java
> +++ /dev/null
> @@ -1,58 +0,0 @@
> -/*****************************************************************************
> - * SearchResultAdapter.java
> - *****************************************************************************
> - * Copyright © 2011-2012 VLC authors and VideoLAN
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> - *****************************************************************************/
> -
> -package org.videolan.vlc.gui;
> -
> -import android.content.Context;
> -import android.view.LayoutInflater;
> -import android.view.View;
> -import android.view.ViewGroup;
> -import android.widget.ArrayAdapter;
> -import android.widget.TextView;
> -
> -public class SearchHistoryAdapter extends ArrayAdapter<String> {
> -
> -    public SearchHistoryAdapter(Context context) {
> -        super(context, 0);
> -    }
> -
> -    @Override
> -    public View getView(int position, View convertView, ViewGroup parent) {
> -        ViewHolder holder;
> -        View view = convertView;
> -        if (view == null) {
> -            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
> -            view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
> -            holder = new ViewHolder();
> -            holder.text = (TextView) view.findViewById(android.R.id.text1);
> -            view.setTag(holder);
> -        } else
> -            holder = (ViewHolder) view.getTag();
> -
> -        String item = getItem(position);
> -        holder.text.setText(item);
> -
> -        return view;
> -    }
> -
> -    static class ViewHolder {
> -        TextView text;
> -    }
> -}
> diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java
> deleted file mode 100644
> index cf177f1..0000000
> --- a/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.java
> +++ /dev/null
> @@ -1,67 +0,0 @@
> -/*****************************************************************************
> - * SearchResultAdapter.java
> - *****************************************************************************
> - * Copyright © 2011-2012 VLC authors and VideoLAN
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> - *****************************************************************************/
> -
> -package org.videolan.vlc.gui;
> -
> -import java.util.Comparator;
> -
> -import org.videolan.vlc.MediaWrapper;
> -import org.videolan.vlc.gui.audio.MediaComparators;
> -
> -import android.content.Context;
> -import android.view.LayoutInflater;
> -import android.view.View;
> -import android.view.ViewGroup;
> -import android.widget.ArrayAdapter;
> -import android.widget.TextView;
> -
> -public class SearchResultAdapter extends ArrayAdapter<MediaWrapper> {
> -
> -    public SearchResultAdapter(Context context) {
> -        super(context, 0);
> -    }
> -
> -    @Override
> -    public View getView(int position, View convertView, ViewGroup parent) {
> -        ViewHolder holder;
> -        View view = convertView;
> -        if (view == null) {
> -            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
> -            view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
> -            holder = new ViewHolder();
> -            holder.text = (TextView) view.findViewById(android.R.id.text1);
> -            view.setTag(holder);
> -        } else
> -            holder = (ViewHolder) view.getTag();
> -
> -        MediaWrapper item = getItem(position);
> -        holder.text.setText(item.getTitle());
> -
> -        return view;
> -    }
> -
> -    public void sort() {
> -        super.sort(MediaComparators.byName);
> -    }
> -
> -    static class ViewHolder {
> -        TextView text;
> -    }
> -}
> diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
> new file mode 100644
> index 0000000..d0217fb
> --- /dev/null
> +++ b/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
> @@ -0,0 +1,71 @@
> +/*
> + * *************************************************************************
> + *  SearchSuggestionsAdapter.java
> + * **************************************************************************
> + *  Copyright © 2015 VLC authors and VideoLAN
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> + *  ***************************************************************************
> + */
> +
> +package org.videolan.vlc.gui;
> +
> +import android.content.Context;
> +import android.database.Cursor;
> +import android.support.v4.widget.CursorAdapter;
> +import android.view.LayoutInflater;
> +import android.view.View;
> +import android.view.ViewGroup;
> +import android.widget.TextView;
> +
> +import org.videolan.vlc.MediaDatabase;
> +import org.videolan.vlc.MediaLibrary;
> +import org.videolan.vlc.MediaWrapper;
> +import org.videolan.vlc.R;
> +import org.videolan.vlc.util.Util;
> +
> +public class SearchSuggestionsAdapter extends CursorAdapter {
> +
> +    public final static String TAG = "VLC/SearchSuggestionsAdapter";
> +
> +    MediaLibrary mMediaLibrary = MediaLibrary.getInstance();
> +
> +    public SearchSuggestionsAdapter(Context context, Cursor cursor){
> +        super(context, cursor, false);
> +    }
> +
> +    @Override
> +    public View newView(Context context, Cursor cursor, ViewGroup parent) {
> +        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
> +        View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
> +        return view;
> +    }
> +
> +    @Override
> +    public void bindView(View view, final Context context, final Cursor cursor) {
> +        final int position = cursor.getPosition();
> +        TextView tv = (TextView) view.findViewById(android.R.id.text1);
> +        tv.setText(cursor.getString(cursor.getColumnIndex(MediaDatabase.MEDIA_TITLE)));
> +        tv.setBackgroundColor(Util.getColorFromAttribute(context, R.attr.background_menu));
> +        tv.setOnClickListener(new View.OnClickListener() {
> +            @Override
> +            public void onClick(View v) {
> +                cursor.moveToPosition(position);
> +                MediaWrapper media = mMediaLibrary.getMediaItem(cursor.getString(cursor.getColumnIndex(MediaDatabase.MEDIA_LOCATION)));
> +                Util.openMedia(context, media);
> +            }
> +        });
> +    }
> +}
> -- 
> 2.1.0
> 
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android

-- 
With my kindest regards,

-- 
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device


More information about the Android mailing list