CreatePlaylistpublic class CreatePlaylist extends android.app.Activity
Fields Summary |
---|
private android.widget.EditText | mPlaylist | private android.widget.TextView | mPrompt | private android.widget.Button | mSaveButton | android.text.TextWatcher | mTextWatcher | private View.OnClickListener | mOpenClicked |
Methods Summary |
---|
private int | idForplaylist(java.lang.String name)
Cursor c = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Playlists._ID },
MediaStore.Audio.Playlists.NAME + "=?",
new String[] { name },
MediaStore.Audio.Playlists.NAME);
int id = -1;
if (c != null) {
c.moveToFirst();
if (!c.isAfterLast()) {
id = c.getInt(0);
}
}
c.close();
return id;
| private java.lang.String | makePlaylistName()
String template = getString(R.string.new_playlist_name_template);
int num = 1;
String[] cols = new String[] {
MediaStore.Audio.Playlists.NAME
};
ContentResolver resolver = getContentResolver();
String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
Cursor c = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
cols, whereclause, null,
MediaStore.Audio.Playlists.NAME);
if (c == null) {
return null;
}
String suggestedname;
suggestedname = String.format(template, num++);
// Need to loop until we've made 1 full pass through without finding a match.
// Looping more than once shouldn't happen very often, but will happen if
// you have playlists named "New Playlist 1"/10/2/3/4/5/6/7/8/9, where
// making only one pass would result in "New Playlist 10" being erroneously
// picked for the new name.
boolean done = false;
while (!done) {
done = true;
c.moveToFirst();
while (! c.isAfterLast()) {
String playlistname = c.getString(0);
if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
suggestedname = String.format(template, num++);
done = false;
}
c.moveToNext();
}
}
c.close();
return suggestedname;
| public void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.create_playlist);
getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT);
mPrompt = (TextView)findViewById(R.id.prompt);
mPlaylist = (EditText)findViewById(R.id.playlist);
mSaveButton = (Button) findViewById(R.id.create);
mSaveButton.setOnClickListener(mOpenClicked);
((Button)findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
String defaultname = icicle != null ? icicle.getString("defaultname") : makePlaylistName();
if (defaultname == null) {
finish();
return;
}
String promptformat = getString(R.string.create_playlist_create_text_prompt);
String prompt = String.format(promptformat, defaultname);
mPrompt.setText(prompt);
mPlaylist.setText(defaultname);
mPlaylist.setSelection(defaultname.length());
mPlaylist.addTextChangedListener(mTextWatcher);
| public void | onResume()
super.onResume();
| public void | onSaveInstanceState(android.os.Bundle outcicle)
outcicle.putString("defaultname", mPlaylist.getText().toString());
|
|