⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playlistbrowseractivity.java

📁 Android平台上的media player, iPhone风格
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (mCreateShortcut) {            return;        }        AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;                if (mi.id < 0) {            menu.add(0, PLAY_SELECTION, 0, R.string.play_selection);            menu.add(0, EDIT_PLAYLIST, 0, R.string.edit_playlist_menu);            mPlaylistCursor.moveToPosition(mi.position);            menu.setHeaderTitle(mPlaylistCursor.getString(mPlaylistCursor.getColumnIndex(MediaStore.Audio.Playlists.NAME)));        } else {            menu.add(0, PLAY_SELECTION, 0, R.string.play_selection);            menu.add(0, DELETE_PLAYLIST, 0, R.string.delete_playlist_menu);            menu.add(0, EDIT_PLAYLIST, 0, R.string.edit_playlist_menu);            menu.add(0, RENAME_PLAYLIST, 0, R.string.rename_playlist_menu);            mPlaylistCursor.moveToPosition(mi.position);            menu.setHeaderTitle(mPlaylistCursor.getString(mPlaylistCursor.getColumnIndex(MediaStore.Audio.Playlists.NAME)));        }    }    @Override    public boolean onContextItemSelected(MenuItem item) {        AdapterContextMenuInfo mi = (AdapterContextMenuInfo) item.getMenuInfo();        switch (item.getItemId()) {            case PLAY_SELECTION:                if (mi.id == RECENTLY_ADDED_PLAYLIST) {                    playRecentlyAdded();                } else {                    MusicUtils.playPlaylist(this, mi.id);                }                break;            case DELETE_PLAYLIST:                mPlaylistCursor.moveToPosition(mi.position);//                mPlaylistCursor.deleteRow();//                mPlaylistCursor.commitUpdates();                Toast.makeText(this, R.string.playlist_deleted_message, Toast.LENGTH_SHORT).show();                if (mPlaylistCursor.getCount() == 0) {                    setTitle(R.string.no_playlists_title);                }                break;            case EDIT_PLAYLIST:                if (mi.id == RECENTLY_ADDED_PLAYLIST) {                    Intent intent = new Intent();                    intent.setClass(this, WeekSelector.class);                    startActivityForResult(intent, CHANGE_WEEKS);                    return true;                } else {                    Intent intent = new Intent(Intent.ACTION_EDIT);                    intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/Track");                    intent.putExtra("playlist", Long.valueOf(mi.id).toString());                    startActivity(intent);                }                break;            case RENAME_PLAYLIST:                Intent intent = new Intent();                intent.setClass(this, RenamePlaylist.class);                intent.putExtra("rename", mi.id);                startActivityForResult(intent, RENAME_PLAYLIST);                break;        }        return true;    }    @Override    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {        switch (requestCode) {            case SCAN_DONE:                if (resultCode == RESULT_CANCELED) {                    finish();                } else {                    init();                }                break;        }    }    @Override    protected void onListItemClick(ListView l, View v, int position, long id)    {        if (mCreateShortcut) {            final Intent shortcut = new Intent();            shortcut.setAction(Intent.ACTION_VIEW);            shortcut.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/Playlist");            shortcut.putExtra("playlist", String.valueOf(id));            final Intent intent = new Intent();            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);            intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ((TextView) v.findViewById(R.id.line1)).getText());            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(                    this, R.drawable.app_music));            setResult(RESULT_OK, intent);            finish();            return;        }        if (id == RECENTLY_ADDED_PLAYLIST) {            playRecentlyAdded();        } else {            MusicUtils.playPlaylist(this, id);        }    }    private void playRecentlyAdded() {        // do a query for all playlists in the last X weeks        int X = MusicUtils.getIntPref(this, "numweeks", 2) * (3600 * 24 * 7);        final String[] ccols = new String[] { MediaStore.Audio.Media._ID};        String where = MediaStore.MediaColumns.DATE_ADDED + ">" + (System.currentTimeMillis() / 1000 - X);        Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,                ccols, where, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);                if (cursor == null) {            // Todo: show a message            return;        }        int len = cursor.getCount();        int [] list = new int[len];        for (int i = 0; i < len; i++) {            cursor.moveToNext();            list[i] = cursor.getInt(0);        }        cursor.close();        MusicUtils.playAll(this, list, 0);    }        private Cursor getPlaylistCursor(String filterstring) {        String[] cols = new String[] {                MediaStore.Audio.Playlists._ID,                MediaStore.Audio.Playlists.NAME        };        StringBuilder where = new StringBuilder();        where.append(MediaStore.Audio.Playlists.NAME + " != ''");                // Add in the filtering constraints        String [] keywords = null;        if (filterstring != null) {            String [] searchWords = filterstring.split(" ");            keywords = new String[searchWords.length];            Collator col = Collator.getInstance();            col.setStrength(Collator.PRIMARY);            for (int i = 0; i < searchWords.length; i++) {                keywords[i] = '%' + searchWords[i] + '%';            }            for (int i = 0; i < searchWords.length; i++) {                where.append(" AND ");                where.append(MediaStore.Audio.Playlists.NAME + " LIKE ?");            }        }                String whereclause = where.toString();                Cursor results = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,            cols, whereclause, keywords,            MediaStore.Audio.Playlists.NAME);                if (results == null) {            return null;        }        ArrayList<ArrayList> autoplaylists = new ArrayList<ArrayList>();        if (mCreateShortcut) {            ArrayList<Object> all = new ArrayList<Object>(2);            all.add(ALL_SONGS_PLAYLIST);            all.add(getString(R.string.play_all));            autoplaylists.add(all);        }        ArrayList<Object> recent = new ArrayList<Object>(2);        recent.add(RECENTLY_ADDED_PLAYLIST);        recent.add(getString(R.string.recentlyadded));        autoplaylists.add(recent);        ArrayListCursor autoplaylistscursor = new ArrayListCursor(cols, autoplaylists);                Cursor c = new MergeCursor(new Cursor [] {autoplaylistscursor, results});                return c;    }        class PlaylistListAdapter extends SimpleCursorAdapter {        int mTitleIdx;        PlaylistListAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to) {            super(context, layout, cursor, from, to);                        mTitleIdx = cursor.getColumnIndex(MediaStore.Audio.Playlists.NAME);        }        @Override        public void bindView(View view, Context context, Cursor cursor) {                        TextView tv = (TextView) view.findViewById(R.id.line1);                        String name = cursor.getString(mTitleIdx);            tv.setText(name);                        ImageView iv = (ImageView) view.findViewById(R.id.icon);            iv.setImageResource(R.drawable.ic_mp_playlist_list);            ViewGroup.LayoutParams p = iv.getLayoutParams();            p.width = ViewGroup.LayoutParams.WRAP_CONTENT;            p.height = ViewGroup.LayoutParams.WRAP_CONTENT;//            iv = (ImageView) view.findViewById(R.id.play_indicator);//            iv.setVisibility(View.GONE);        }        @Override        public void changeCursor(Cursor cursor) {            super.changeCursor(cursor);            mPlaylistCursor = cursor;        }        @Override        public Cursor runQueryOnBackgroundThread(CharSequence constraint) {            return getPlaylistCursor(constraint.toString());        }    }        private Cursor mPlaylistCursor;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -