Rework song selector filter

Now simply uses the virtual keyboard
This commit is contained in:
Christopher Eby 2010-03-03 23:00:46 -06:00
parent ada3acacab
commit ce1df6f732
3 changed files with 41 additions and 123 deletions

View File

@ -15,20 +15,26 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".OneCellWidget" android:label="Vanilla Music 1x1">
<receiver
android:name=".OneCellWidget"
android:label="Vanilla Music 1x1">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/one_cell_widget" />
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/one_cell_widget" />
</receiver>
<activity
android:name="RemoteActivity"
android:theme="@android:style/Theme.Dialog"
android:excludeFromRecents="true"
android:launchMode="singleInstance" />
<activity
android:name="SongSelector"
android:windowSoftInputMode="adjustResize" />
<service android:name="PlaybackService" />
<activity android:name="PreferencesActivity" />
<activity android:name="SongSelector"/>
</application>
<uses-sdk android:minSdkVersion="3"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />

View File

@ -11,49 +11,8 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:fastScrollEnabled="true" />
<LinearLayout
android:id="@+id/filter_layout"
android:layout_height="wrap_content"
<EditText
android:id="@+id/filter_text"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/filter_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5px"
android:layout_weight="1" />
<Button
android:id="@+id/backspace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="&lt;" />
<Button
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x" />
</LinearLayout>
<TableLayout
android:id="@+id/numpad"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:stretchColumns="0,1,2"
android:visibility="gone">
<TableRow>
<Button android:id="@+id/Button1" android:text="0 1" />
<Button android:id="@+id/Button2" android:text="2 abc" />
<Button android:id="@+id/Button3" android:text="3 def" />
</TableRow>
<TableRow>
<Button android:id="@+id/Button4" android:text="4 ghi" />
<Button android:id="@+id/Button5" android:text="5 jkl" />
<Button android:id="@+id/Button6" android:text="6 mno" />
</TableRow>
<TableRow>
<Button android:id="@+id/Button7" android:text="7 pqrs" />
<Button android:id="@+id/Button8" android:text="8 tuv" />
<Button android:id="@+id/Button9" android:text="9 wxyz" />
</TableRow>
</TableLayout>
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -22,26 +22,19 @@ import org.kreed.vanilla.R;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class SongSelector extends Activity implements View.OnClickListener, OnItemClickListener {
private ListView mListView;
public class SongSelector extends Activity implements AdapterView.OnItemClickListener, TextWatcher {
private SongAdapter mAdapter;
private LinearLayout mFilterLayout;
private TextView mFilterText;
private Button mBackspaceButton;
private Button mCloseButton;
private View mNumpad;
private Button[] mButtons;
private ListView mListView;
private TextView mTextView;
@Override
public void onCreate(Bundle icicle)
@ -49,78 +42,25 @@ public class SongSelector extends Activity implements View.OnClickListener, OnIt
super.onCreate(icicle);
setContentView(R.layout.song_selector);
mListView = (ListView)findViewById(R.id.song_list);
mAdapter = new SongAdapter(this);
mListView = (ListView)findViewById(R.id.song_list);
mListView.setAdapter(mAdapter);
mListView.setTextFilterEnabled(true);
mListView.setOnItemClickListener(this);
mFilterLayout = (LinearLayout)findViewById(R.id.filter_layout);
mFilterText = (TextView)findViewById(R.id.filter_text);
mBackspaceButton = (Button)findViewById(R.id.backspace);
mBackspaceButton.setOnClickListener(this);
mCloseButton = (Button)findViewById(R.id.close);
mCloseButton.setOnClickListener(this);
mNumpad = findViewById(R.id.numpad);
Configuration config = getResources().getConfiguration();
boolean hasKeyboard = config.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO && config.keyboard == Configuration.KEYBOARD_QWERTY;
mNumpad.setVisibility(hasKeyboard ? View.GONE : View.VISIBLE);
mButtons = new Button[] {
(Button)findViewById(R.id.Button1),
(Button)findViewById(R.id.Button2),
(Button)findViewById(R.id.Button3),
(Button)findViewById(R.id.Button4),
(Button)findViewById(R.id.Button5),
(Button)findViewById(R.id.Button6),
(Button)findViewById(R.id.Button7),
(Button)findViewById(R.id.Button8),
(Button)findViewById(R.id.Button9)
};
for (Button button : mButtons)
button.setOnClickListener(this);
mTextView = (TextView)findViewById(R.id.filter_text);
mTextView.addTextChangedListener(this);
}
@Override
public boolean onSearchRequested()
public boolean onKeyDown(int keyCode, KeyEvent event)
{
mNumpad.setVisibility(mNumpad.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
return false;
}
public void onClick(View view)
{
String defaultText = getResources().getString(R.string.filter) + ' ';
if (super.onKeyDown(keyCode, event))
return true;
int visible = View.VISIBLE;
String text = mFilterText.getText().toString();
if (text.length() == 0)
text = defaultText;
if (view == mCloseButton) {
visible = View.GONE;
text = null;
} else if (view == mBackspaceButton) {
if (text.length() > defaultText.length())
text = text.substring(0, text.length() - 1);
} else {
int i = -1;
while (++i != mButtons.length)
if (mButtons[i] == view)
break;
text += i + 1;
}
mFilterText.setText(text);
mFilterLayout.setVisibility(visible);
mListView.setTextFilterEnabled(visible == View.VISIBLE);
String filterText = text == null || text.length() <= defaultText.length() ? null : text.substring(defaultText.length());
mAdapter.getFilter().filter(filterText);
mTextView.requestFocus();
return mTextView.onKeyDown(keyCode, event);
}
public void onItemClick(AdapterView<?> list, View view, int pos, long id)
@ -129,4 +69,17 @@ public class SongSelector extends Activity implements View.OnClickListener, OnIt
intent.putExtra("songId", (int)id);
startService(intent);
}
public void afterTextChanged(Editable editable)
{
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
public void onTextChanged(CharSequence s, int start, int before, int count)
{
mAdapter.getFilter().filter(s);
}
}