📄 playlistbrowseractivity.java
字号:
/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.android.imusic;import java.text.Collator;import java.util.ArrayList;import android.app.ListActivity;import android.content.BroadcastReceiver;import android.content.ComponentName;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.content.ServiceConnection;import com.android.internal.database.ArrayListCursor;import android.database.Cursor;import android.database.MergeCursor;import android.media.AudioManager;import android.net.Uri;import android.os.Bundle;import android.os.Handler;import android.os.IBinder;import android.os.Message;import android.provider.MediaStore;import android.util.Log;import android.view.ContextMenu;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.view.Window;import android.view.ContextMenu.ContextMenuInfo;import android.widget.ImageView;import android.widget.ListView;import android.widget.SimpleCursorAdapter;import android.widget.TextView;import android.widget.Toast;import android.widget.AdapterView.AdapterContextMenuInfo;public class PlaylistBrowserActivity extends ListActivity implements View.OnCreateContextMenuListener, MusicUtils.Defs{ private static final int DELETE_PLAYLIST = CHILD_MENU_BASE + 1; private static final int EDIT_PLAYLIST = CHILD_MENU_BASE + 2; private static final int RENAME_PLAYLIST = CHILD_MENU_BASE + 3; private static final int CHANGE_WEEKS = CHILD_MENU_BASE + 4; private static final long RECENTLY_ADDED_PLAYLIST = -1; private static final long ALL_SONGS_PLAYLIST = -2; private boolean mCreateShortcut; public PlaylistBrowserActivity() { } /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); final Intent intent = getIntent(); final String action = intent.getAction(); if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { mCreateShortcut = true; } requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setVolumeControlStream(AudioManager.STREAM_MUSIC); MusicUtils.bindToService(this, new ServiceConnection() { public void onServiceConnected(ComponentName classname, IBinder obj) { if (Intent.ACTION_VIEW.equals(action)) { long id = Long.parseLong(intent.getExtras().getString("playlist")); if (id == RECENTLY_ADDED_PLAYLIST) { playRecentlyAdded(); } else if (id == ALL_SONGS_PLAYLIST) { int [] list = MusicUtils.getAllSongs(PlaylistBrowserActivity.this); if (list != null) { MusicUtils.playAll(PlaylistBrowserActivity.this, list, 0); } } else { MusicUtils.playPlaylist(PlaylistBrowserActivity.this, id); } finish(); } } public void onServiceDisconnected(ComponentName classname) { } }); IntentFilter f = new IntentFilter(); f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); f.addAction(Intent.ACTION_MEDIA_UNMOUNTED); f.addDataScheme("file"); registerReceiver(mScanListener, f); init(); } @Override public void onDestroy() { MusicUtils.unbindFromService(this); if (mPlaylistCursor != null) { mPlaylistCursor.close(); } unregisterReceiver(mScanListener); super.onDestroy(); } @Override public void onResume() { super.onResume(); MusicUtils.setSpinnerState(this); } @Override public void onPause() { mReScanHandler.removeCallbacksAndMessages(null); super.onPause(); } private BroadcastReceiver mScanListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { MusicUtils.setSpinnerState(PlaylistBrowserActivity.this); mReScanHandler.sendEmptyMessage(0); } }; private Handler mReScanHandler = new Handler() { public void handleMessage(Message msg) { init(); if (mPlaylistCursor == null) { sendEmptyMessageDelayed(0, 1000); } } }; public void init() { mPlaylistCursor = getPlaylistCursor(null); if (mPlaylistCursor == null) { MusicUtils.displayDatabaseError(this); setContentView(R.layout.no_sd_card); return; } setContentView(R.layout.media_picker_activity); if (mPlaylistCursor.getCount() > 0) { mPlaylistCursor.moveToFirst(); setTitle(R.string.playlists_title); } else { setTitle(R.string.no_playlists_title); } // Map Cursor columns to views defined in media_list_item.xml PlaylistListAdapter adapter = new PlaylistListAdapter( this, R.layout.track_list_item, mPlaylistCursor, new String[] { MediaStore.Audio.Playlists.NAME}, new int[] { android.R.id.text1 }); setListAdapter(adapter); ListView lv = getListView(); lv.setOnCreateContextMenuListener(this); lv.setTextFilterEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { if (!mCreateShortcut) { menu.add(0, GOTO_START, 0, R.string.goto_start).setIcon( R.drawable.ic_menu_music_library); menu.add(0, GOTO_PLAYBACK, 0, R.string.goto_playback).setIcon( R.drawable.ic_menu_playback).setVisible(MusicUtils.isMusicLoaded()); } return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; switch (item.getItemId()) { case GOTO_START: intent = new Intent(); intent.setClass(this, MusicBrowserActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case GOTO_PLAYBACK: intent = new Intent("com.android.imusic.PLAYBACK_VIEWER"); startActivity(intent); return true; } return super.onOptionsItemSelected(item); } public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -