17 changed files with 232 additions and 27 deletions
|
Before Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 334 B |
@ -1,6 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
|||
<item android:state_selected="true" android:color="#000000" /> |
|||
<item android:state_pressed="true" android:color="#000000" /> |
|||
<item android:color="#888888" /> |
|||
</selector> |
|||
@ -0,0 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> |
|||
<solid android:color="#77000000"/> |
|||
<corners android:radius="3dip"/> |
|||
</shape> |
|||
@ -0,0 +1,14 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout |
|||
xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:orientation="vertical" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:background="#505050" |
|||
android:padding="2dip"> |
|||
<TextView |
|||
android:id="@+id/list_header_text" |
|||
android:layout_height="wrap_content" |
|||
android:layout_width="match_parent" |
|||
android:layout_marginLeft="3dip"/> |
|||
</LinearLayout> |
|||
@ -1,30 +1,181 @@ |
|||
package org.videolan.vlc.android; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
import android.app.ListActivity; |
|||
import android.app.SearchManager; |
|||
import android.content.Context; |
|||
import android.content.Intent; |
|||
import android.os.Bundle; |
|||
import android.text.Editable; |
|||
import android.text.TextWatcher; |
|||
import android.view.KeyEvent; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.inputmethod.InputMethodManager; |
|||
import android.widget.ArrayAdapter; |
|||
import android.widget.EditText; |
|||
import android.widget.LinearLayout; |
|||
import android.widget.ListView; |
|||
import android.widget.TextView; |
|||
import android.widget.TextView.OnEditorActionListener; |
|||
|
|||
public class SearchActivity extends ListActivity { |
|||
public final static String TAG = "VLC/SearchActivit"; |
|||
|
|||
private EditText mSearchText; |
|||
private String[] mSearchHistory; |
|||
private ArrayAdapter<String> mHistoryAdapter; |
|||
private SearchResultAdapter mResultAdapter; |
|||
private LinearLayout mListHeader; |
|||
|
|||
@Override |
|||
public void onCreate(Bundle savedInstanceState) { |
|||
super.onCreate(savedInstanceState); |
|||
setContentView(R.layout.search); |
|||
|
|||
// TODO: create layout
|
|||
mResultAdapter = new SearchResultAdapter(this, android.R.layout.simple_list_item_1); |
|||
|
|||
mSearchText = (EditText)findViewById(R.id.search_text); |
|||
mSearchText.setOnEditorActionListener(searchTextListener); |
|||
mSearchText.addTextChangedListener(searchTextWatcher); |
|||
|
|||
final Intent queryIntent = getIntent(); |
|||
final String queryAction = queryIntent.getAction(); |
|||
if (Intent.ACTION_SEARCH.equals(queryAction)) { |
|||
mSearchText.setText(queryIntent.getStringExtra(SearchManager.QUERY)); |
|||
mSearchText.requestFocus(); |
|||
String query = queryIntent.getStringExtra(SearchManager.QUERY); |
|||
mSearchText.setText(query); |
|||
mSearchText.setSelection(query.length()); |
|||
} else { |
|||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); |
|||
imm.showSoftInput(mSearchText, InputMethodManager.RESULT_SHOWN); |
|||
} |
|||
|
|||
|
|||
mSearchText.requestFocus(); |
|||
showSearchHistory(); |
|||
|
|||
} |
|||
|
|||
private void search(CharSequence key, int type) { |
|||
|
|||
// set result adapter to the list
|
|||
removeListHeader(); |
|||
setListAdapter(null); |
|||
mResultAdapter.clear(); |
|||
ArrayList<MediaItem> allItems = MediaLibraryActivity.getInstance().mItemList; |
|||
for (int i = 0; i < allItems.size(); i++) { |
|||
MediaItem item = allItems.get(i); |
|||
if ((type == MediaItem.TYPE_VIDEO || // Only video by now!
|
|||
type == item.getType()) && |
|||
item.getName().contains(key) || |
|||
item.getPath().contains(key)) { |
|||
mResultAdapter.add(item); |
|||
} |
|||
} |
|||
mResultAdapter.sort(); |
|||
setListAdapter(mResultAdapter); |
|||
} |
|||
|
|||
|
|||
|
|||
private void addListHeader(int resid) { |
|||
ListView lv = getListView(); |
|||
|
|||
if (mListHeader == null) { |
|||
LayoutInflater infalter = getLayoutInflater(); |
|||
mListHeader = (LinearLayout) infalter.inflate(R.layout.list_header, lv, false); |
|||
} |
|||
|
|||
TextView headerText = (TextView)mListHeader.findViewById(R.id.list_header_text); |
|||
headerText.setText(R.string.search_history); |
|||
getListView().addHeaderView(mListHeader, null, false); |
|||
} |
|||
|
|||
private void removeListHeader() { |
|||
if (mListHeader != null) |
|||
getListView().removeHeaderView(mListHeader); |
|||
} |
|||
|
|||
private void showSearchHistory() { |
|||
setListAdapter(null); |
|||
// Add header to the history
|
|||
addListHeader(R.string.search_history); |
|||
|
|||
if (mSearchHistory == null) |
|||
loadSearchHistory(); |
|||
if (mHistoryAdapter == null) |
|||
mHistoryAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mSearchHistory); |
|||
setListAdapter(mHistoryAdapter); |
|||
} |
|||
|
|||
private void loadSearchHistory() { |
|||
// TODO: load real history from database
|
|||
mSearchHistory = new String[]{ "test0", "test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9" }; |
|||
} |
|||
|
|||
private TextWatcher searchTextWatcher = new TextWatcher() { |
|||
|
|||
@Override |
|||
public void onTextChanged(CharSequence s, int start, int before, int count) { |
|||
if (s.length() > 0) { |
|||
search(s, MediaItem.TYPE_ALL); |
|||
} else { |
|||
showSearchHistory(); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void beforeTextChanged(CharSequence s, int start, int count, |
|||
int after) { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void afterTextChanged(Editable s) { |
|||
|
|||
} |
|||
}; |
|||
|
|||
|
|||
|
|||
private OnEditorActionListener searchTextListener = new OnEditorActionListener() { |
|||
@Override |
|||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
|||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); |
|||
imm.hideSoftInputFromWindow(mSearchText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); |
|||
return false; |
|||
} |
|||
}; |
|||
|
|||
protected 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) { |
|||
MediaItem item = (MediaItem) getListAdapter().getItem(position); |
|||
Intent intent = new Intent(this, VideoPlayerActivity.class); |
|||
intent.putExtra("filePath", item.getPath()); |
|||
startActivity(intent); |
|||
super.onListItemClick(l, v, position, id); |
|||
} |
|||
}; |
|||
|
|||
@Override |
|||
public boolean onKeyDown(int keyCode, KeyEvent event) { |
|||
if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
|||
mSearchText.requestFocus(); |
|||
mSearchText.setSelection(mSearchText.getText().length()); |
|||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); |
|||
imm.showSoftInput(mSearchText, InputMethodManager.RESULT_SHOWN); |
|||
return true; |
|||
} |
|||
|
|||
return super.onKeyDown(keyCode, event); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
@ -1,5 +0,0 @@ |
|||
package org.videolan.vlc.android; |
|||
|
|||
public class SearchHistoryAdapter { |
|||
|
|||
} |
|||
@ -1,5 +1,47 @@ |
|||
package org.videolan.vlc.android; |
|||
|
|||
public class SearchResultAdapter { |
|||
import java.util.Comparator; |
|||
|
|||
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<MediaItem> |
|||
implements Comparator<MediaItem> { |
|||
|
|||
public SearchResultAdapter(Context context, int textViewResourceId) { |
|||
super(context, textViewResourceId); |
|||
} |
|||
|
|||
@Override |
|||
public View getView(int position, View convertView, ViewGroup parent) { |
|||
View v = convertView; |
|||
if (v == null){ |
|||
LayoutInflater inflater = (LayoutInflater) |
|||
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|||
v = inflater.inflate(android.R.layout.simple_list_item_1, |
|||
parent, false); |
|||
} |
|||
|
|||
MediaItem item = getItem(position); |
|||
TextView textView = (TextView)v.findViewById(android.R.id.text1); |
|||
textView.setText(item.getName()); |
|||
|
|||
return v; |
|||
} |
|||
|
|||
@Override |
|||
public int compare(MediaItem object1, MediaItem object2) { |
|||
return object1.getName().compareToIgnoreCase(object2.getName()); |
|||
} |
|||
|
|||
public void sort() { |
|||
super.sort(this); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
Loading…
Reference in new issue