Browse Source

UI: enable search (only for video)

0.1.x-bugfix
Michael Merg 15 years ago
parent
commit
720aa263ab
  1. 3
      vlc-android/AndroidManifest.xml
  2. 0
      vlc-android/res/color/video_list_title.xml
  3. BIN
      vlc-android/res/drawable/expander_ic_maximized.9.png
  4. BIN
      vlc-android/res/drawable/ic_next.9.png
  5. 6
      vlc-android/res/drawable/ml_path_color.xml
  6. 5
      vlc-android/res/drawable/video_list_length_bg.xml
  7. 14
      vlc-android/res/layout/list_header.xml
  8. 2
      vlc-android/res/layout/media_library.xml
  9. 11
      vlc-android/res/layout/video_list_item.xml
  10. 1
      vlc-android/res/values/strings.xml
  11. 5
      vlc-android/src/org/videolan/vlc/android/MediaItem.java
  12. 2
      vlc-android/src/org/videolan/vlc/android/MediaLibraryActivity.java
  13. 157
      vlc-android/src/org/videolan/vlc/android/SearchActivity.java
  14. 5
      vlc-android/src/org/videolan/vlc/android/SearchHistoryAdapter.java
  15. 44
      vlc-android/src/org/videolan/vlc/android/SearchResultAdapter.java
  16. 1
      vlc-android/src/org/videolan/vlc/android/VideoListActivity.java
  17. 3
      vlc-android/src/org/videolan/vlc/android/VideoListAdapter.java

3
vlc-android/AndroidManifest.xml

@ -20,7 +20,8 @@
</activity>
<activity
android:name="SearchActivity"
android:theme="@android:style/Theme.NoTitleBar">
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

0
vlc-android/res/drawable/ml_title_color.xml → vlc-android/res/color/video_list_title.xml

BIN
vlc-android/res/drawable/expander_ic_maximized.9.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

BIN
vlc-android/res/drawable/ic_next.9.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

6
vlc-android/res/drawable/ml_path_color.xml

@ -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>

5
vlc-android/res/drawable/video_list_length_bg.xml

@ -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>

14
vlc-android/res/layout/list_header.xml

@ -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>

2
vlc-android/res/layout/media_library.xml

@ -27,7 +27,7 @@
android:visibility="invisible"/>
<ImageButton
android:id="@+id/ml_header_button_view"
android:background="@drawable/header_button_browser"
android:background="@drawable/header_button"
android:layout_width="48dip"
android:layout_height="48dip"
android:onClick="changeTabClick"/>

11
vlc-android/res/layout/video_list_item.xml

@ -22,7 +22,7 @@
android:id="@+id/ml_item_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#77000000"
android:background="@drawable/video_list_length_bg"
android:textSize="12dip"
android:textColor="#CCCCCC" />
</LinearLayout>
@ -35,12 +35,13 @@
android:ellipsize="end"
android:maxLines="2"
android:textSize="17dip"
android:textColor="@drawable/ml_title_color"
android:textColor="@color/video_list_title"
android:paddingLeft="12dip"/>
<ImageView
android:id="@+id/ml_item_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/expander_ic_maximized"
android:layout_marginRight="5dip" />
android:layout_height="match_parent"
android:src="@drawable/ic_next"
android:paddingRight="12dip"
android:paddingLeft="5dip" />
</LinearLayout>

1
vlc-android/res/values/strings.xml

@ -14,4 +14,5 @@
<string name="sortby_length">Length</string>
<string name="searchable_hint">Search...</string>
<string name="searchable_label">VLC media player</string>
<string name="search_history">History</string>
</resources>

5
vlc-android/src/org/videolan/vlc/android/MediaItem.java

@ -4,7 +4,6 @@ package org.videolan.vlc.android;
import java.io.File;
import android.graphics.Bitmap;
import android.util.Log;
public class MediaItem implements Comparable<MediaItem> {
@ -22,9 +21,11 @@ public class MediaItem implements Comparable<MediaItem> {
".mp1", ".mp2", ".mp3", ".mpc", ".oga", ".ogg", ".oma", ".rmi", ".s3m", ".spx", ".tta",
".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm"};
public final static int TYPE_ALL = -1;
public final static int TYPE_VIDEO = 0;
public final static int TYPE_AUDIO = 1;
private String mName;
private File mFile;
private long mTime = 0;

2
vlc-android/src/org/videolan/vlc/android/MediaLibraryActivity.java

@ -36,7 +36,7 @@ public class MediaLibraryActivity extends TabActivity {
private static MediaLibraryActivity mInstance;
private DatabaseManager mDBManager;
private final CyclicBarrier mBarrier = new CyclicBarrier(2);
protected List<MediaItem> mItemList = new ArrayList<MediaItem>();
protected ArrayList<MediaItem> mItemList = new ArrayList<MediaItem>();
private ProgressBar mProgressBar;
private TabHost mTabHost;
private int mCurrentState = 0;

157
vlc-android/src/org/videolan/vlc/android/SearchActivity.java

@ -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);
}
}

5
vlc-android/src/org/videolan/vlc/android/SearchHistoryAdapter.java

@ -1,5 +0,0 @@
package org.videolan.vlc.android;
public class SearchHistoryAdapter {
}

44
vlc-android/src/org/videolan/vlc/android/SearchResultAdapter.java

@ -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);
}
}

1
vlc-android/src/org/videolan/vlc/android/VideoListActivity.java

@ -6,7 +6,6 @@ import java.util.concurrent.CyclicBarrier;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.LightingColorFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

3
vlc-android/src/org/videolan/vlc/android/VideoListAdapter.java

@ -130,7 +130,8 @@ public class VideoListAdapter extends ArrayAdapter<MediaItem>
@Override
public void onClick(View v) {
MediaItem item = (MediaItem)v.getTag();
Util.toaster(item.getName() + " submenu");
// TODO: show details
Util.toaster("show details for: " + item.getName());
}
};

Loading…
Cancel
Save