Search in sources :

Example 11 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class SimpleWidgetProvider method onReceive.

// 接收广播的回调函数
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
        this.onEnabled(context);
    } else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
        this.onDisabled(context);
    }
    Log.e(TAG, "action = " + action);
    if (!isInUse) {
        return;
    }
    if (intent.hasCategory(Intent.CATEGORY_ALTERNATIVE)) {
        Uri data = intent.getData();
        int buttonId = Integer.parseInt(data.getSchemeSpecificPart());
        switch(buttonId) {
            case R.id.widget_play:
                pushAction(context, MediaService.TOGGLEPAUSE_ACTION);
                break;
            case R.id.widget_pre:
                pushAction(context, MediaService.PREVIOUS_ACTION);
                break;
            case R.id.widget_next:
                pushAction(context, MediaService.NEXT_ACTION);
                break;
            case R.id.widget_love:
                long[] favlists = PlaylistsManager.getInstance(context).getPlaylistIds(IConstants.FAV_PLAYLIST);
                for (long i : favlists) {
                    if (currentId == i) {
                        isFav = true;
                        break;
                    }
                }
                if (isFav) {
                    PlaylistsManager.getInstance(context).removeItem(context, IConstants.FAV_PLAYLIST, MusicPlayer.getCurrentAudioId());
                    isFav = false;
                } else {
                    try {
                        MusicInfo info = MusicPlayer.getPlayinfos().get(MusicPlayer.getCurrentAudioId());
                        PlaylistsManager.getInstance(context).insertMusic(context, IConstants.FAV_PLAYLIST, info);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    isFav = true;
                }
                pushUpdate(context, AppWidgetManager.getInstance(context), true);
                break;
        }
    } else if (action.equals(MediaService.META_CHANGED)) {
        isPlaying = intent.getBooleanExtra("playing", false);
        pushUpdate(context, AppWidgetManager.getInstance(context), false);
    } else if (action.equals(MediaService.SEND_PROGRESS)) {
        Log.e("widget", "  " + duration + "    " + position);
        duration = intent.getLongExtra("duration", 0);
        position = intent.getLongExtra("position", 0);
        pushUpdate(context, AppWidgetManager.getInstance(context), true);
    } else if (action.equals(MediaService.MUSIC_CHANGED)) {
        trackname = intent.getStringExtra("track");
        art = intent.getStringExtra("artist");
        albumuri = intent.getStringExtra("albumuri");
        isTrackLocal = intent.getBooleanExtra("islocal", true);
        currentId = intent.getLongExtra("id", -1);
        isPlaying = intent.getBooleanExtra("playing", false);
        Log.e("harvic", "art = " + art + "  trackname = " + trackname);
        pushUpdate(context, AppWidgetManager.getInstance(context), false);
    }
    super.onReceive(context, intent);
}
Also used : Uri(android.net.Uri) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 12 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class PlaylistSelectActivity method onClick.

@Override
public void onClick(View v) {
    final ArrayList<MusicInfo> selectList = mAdapter.getSelectedItem();
    switch(v.getId()) {
        case R.id.select_next:
            long[] list = new long[selectList.size()];
            HashMap<Long, MusicInfo> infos = new HashMap();
            for (int i = 0; i < mAdapter.getSelectedItem().size(); i++) {
                MusicInfo info = selectList.get(i);
                list[i] = selectList.get(i).songId;
                info.islocal = true;
                info.albumData = MusicUtils.getAlbumArtUri(info.albumId) + "";
                infos.put(list[i], selectList.get(i));
            }
            MusicPlayer.playNext(this, infos, list);
            break;
        case R.id.select_addtoplaylist:
            long[] list1 = new long[selectList.size()];
            for (int i = 0; i < mAdapter.getSelectedItem().size(); i++) {
                list1[i] = selectList.get(i).songId;
            }
            AddPlaylistDialog.newInstance(list1).show(getSupportFragmentManager(), "add");
            Intent intent = new Intent(MediaService.PLAYLIST_CHANGED);
            sendBroadcast(intent);
            break;
        case R.id.select_del:
            new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.sure_to_delete_music)).setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    new AsyncTask<Void, Void, Void>() {

                        @Override
                        protected Void doInBackground(Void... params) {
                            for (MusicInfo music : selectList) {
                                if (MusicPlayer.getCurrentAudioId() == music.songId) {
                                    if (MusicPlayer.getQueueSize() == 0) {
                                        MusicPlayer.stop();
                                    } else {
                                        MusicPlayer.next();
                                    }
                                }
                                Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, music.songId);
                                PlaylistSelectActivity.this.getContentResolver().delete(uri, null, null);
                                PlaylistsManager.getInstance(PlaylistSelectActivity.this).deleteMusic(PlaylistSelectActivity.this, music.songId);
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void v) {
                            mAdapter.updateDataSet();
                            mAdapter.notifyDataSetChanged();
                            PlaylistSelectActivity.this.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
                        }
                    }.execute();
                    dialog.dismiss();
                }
            }).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();
            break;
    }
}
Also used : HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) Uri(android.net.Uri) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 13 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class SelectActivity method onClick.

@Override
public void onClick(View v) {
    final ArrayList<MusicInfo> selectList = mAdapter.getSelectedItem();
    switch(v.getId()) {
        case R.id.select_next:
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    ArrayList<MusicInfo> select = mAdapter.getSelectedItem();
                    long currentAudioId = MusicPlayer.getCurrentAudioId();
                    for (int i = 0; i < select.size(); i++) {
                        if (select.get(i).songId == currentAudioId) {
                            select.remove(i);
                            break;
                        }
                    }
                    final long[] list = new long[select.size()];
                    HashMap<Long, MusicInfo> infos = new HashMap();
                    for (int i = 0; i < select.size(); i++) {
                        list[i] = select.get(i).songId;
                        MusicInfo info = select.get(i);
                        list[i] = info.songId;
                        info.islocal = true;
                        info.albumData = MusicUtils.getAlbumArtUri(info.albumId) + "";
                        infos.put(list[i], select.get(i));
                    }
                    MusicPlayer.playNext(SelectActivity.this, infos, list);
                }
            }, 100);
            break;
        case R.id.select_addtoplaylist:
            long[] list1 = new long[selectList.size()];
            for (int i = 0; i < mAdapter.getSelectedItem().size(); i++) {
                list1[i] = selectList.get(i).songId;
            }
            AddPlaylistDialog.newInstance(list1).show(getSupportFragmentManager(), "add");
            Intent intent = new Intent(MediaService.PLAYLIST_CHANGED);
            sendBroadcast(intent);
            break;
        case R.id.select_del:
            new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.sure_to_delete_music)).setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    new AsyncTask<Void, Void, Void>() {

                        @Override
                        protected Void doInBackground(Void... params) {
                            for (MusicInfo music : selectList) {
                                if (MusicPlayer.getCurrentAudioId() == music.songId) {
                                    if (MusicPlayer.getQueueSize() == 0) {
                                        MusicPlayer.stop();
                                    } else {
                                        MusicPlayer.next();
                                    }
                                }
                                Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, music.songId);
                                SelectActivity.this.getContentResolver().delete(uri, null, null);
                                PlaylistsManager.getInstance(SelectActivity.this).deleteMusic(SelectActivity.this, music.songId);
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void v) {
                            mAdapter.updateDataSet();
                            mAdapter.notifyDataSetChanged();
                            SelectActivity.this.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
                        }
                    }.execute();
                    dialog.dismiss();
                }
            }).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();
            break;
    }
}
Also used : HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) Intent(android.content.Intent) Uri(android.net.Uri) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 14 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class MoreFragment method getList.

private void getList() {
    if (type == IConstants.MUSICOVERFLOW) {
        // long musicId = Long.parseLong(args.trim());
        adapterMusicInfo = getArguments().getParcelable("music");
        if (adapterMusicInfo == null) {
            adapterMusicInfo = new MusicInfo();
        }
        artist = adapterMusicInfo.artist;
        albumId = adapterMusicInfo.albumId + "";
        albumName = adapterMusicInfo.albumName;
        musicName = adapterMusicInfo.musicName;
        topTitle.setText("歌曲:" + " " + musicName);
        heightPercent = 0.6;
        setMusicInfo();
        muaicflowAdapter = new MusicFlowAdapter(mContext, mlistInfo, adapterMusicInfo);
    } else {
        switch(type) {
            case IConstants.ARTISTOVERFLOW:
                String artist = args;
                list = MusicUtils.queryMusic(mContext, artist, IConstants.START_FROM_ARTIST);
                topTitle.setText("歌曲:" + " " + list.get(0).artist);
                break;
            case IConstants.ALBUMOVERFLOW:
                String albumId = args;
                list = MusicUtils.queryMusic(mContext, albumId, IConstants.START_FROM_ALBUM);
                topTitle.setText("专辑:" + " " + list.get(0).albumName);
                break;
            case IConstants.FOLDEROVERFLOW:
                String folder = args;
                list = MusicUtils.queryMusic(mContext, folder, IConstants.START_FROM_FOLDER);
                topTitle.setText("文件夹:" + " " + folder);
                break;
        }
        setCommonInfo();
        heightPercent = 0.3;
        commonAdapter = new OverFlowAdapter(mContext, mlistInfo, list);
    }
}
Also used : OverFlowAdapter(com.wm.remusic.adapter.OverFlowAdapter) MusicFlowAdapter(com.wm.remusic.adapter.MusicFlowAdapter) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 15 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class PlayingActivity method setTools.

private void setTools() {
    mPlayingmode.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MusicPlayer.cycleRepeat();
            updatePlaymode();
        }
    });
    mPre.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // MusicPlayer.previous(PlayingActivity.this.getApplication(), true);
            Message msg = new Message();
            msg.what = PRE_MUSIC;
            mPlayHandler.sendMessage(msg);
        }
    });
    mControl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (MusicPlayer.isPlaying()) {
                mControl.setImageResource(R.drawable.play_rdi_btn_pause);
            } else {
                mControl.setImageResource(R.drawable.play_rdi_btn_play);
            }
            if (MusicPlayer.getQueueSize() != 0) {
                MusicPlayer.playOrPause();
            }
        }
    });
    mNext.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mRotateAnim != null) {
                mRotateAnim.end();
                mRotateAnim = null;
            }
            //                mHandler.removeCallbacks(mNextRunnable);
            //                mHandler.postDelayed(mNextRunnable,300);
            Message msg = new Message();
            msg.what = NEXT_MUSIC;
            mPlayHandler.sendMessage(msg);
        //   MusicPlayer.mNext();
        }
    });
    mPlaylist.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PlayQueueFragment playQueueFragment = new PlayQueueFragment();
            playQueueFragment.show(getSupportFragmentManager(), "playlistframent");
        }
    });
    mMore.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SimpleMoreFragment moreFragment = SimpleMoreFragment.newInstance(MusicPlayer.getCurrentAudioId());
            moreFragment.show(getSupportFragmentManager(), "music");
        }
    });
    mFav.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isFav) {
                mPlaylistsManager.removeItem(PlayingActivity.this, IConstants.FAV_PLAYLIST, MusicPlayer.getCurrentAudioId());
                mFav.setImageResource(R.drawable.play_rdi_icn_love);
                isFav = false;
            } else {
                try {
                    MusicInfo info = MusicPlayer.getPlayinfos().get(MusicPlayer.getCurrentAudioId());
                    mPlaylistsManager.insertMusic(PlayingActivity.this, IConstants.FAV_PLAYLIST, info);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                mFav.setImageResource(R.drawable.play_icn_loved);
                isFav = true;
            }
            Intent intent = new Intent(IConstants.PLAYLIST_COUNT_CHANGED);
            sendBroadcast(intent);
        }
    });
}
Also used : Message(android.os.Message) PlayQueueFragment(com.wm.remusic.fragment.PlayQueueFragment) SimpleMoreFragment(com.wm.remusic.fragment.SimpleMoreFragment) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LrcView(com.wm.remusic.lrc.LrcView) MusicInfo(com.wm.remusic.info.MusicInfo) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

MusicInfo (com.wm.remusic.info.MusicInfo)25 Intent (android.content.Intent)10 ArrayList (java.util.ArrayList)9 View (android.view.View)7 TextView (android.widget.TextView)7 Uri (android.net.Uri)6 RecyclerView (android.support.v7.widget.RecyclerView)6 DialogInterface (android.content.DialogInterface)5 AsyncTask (android.os.AsyncTask)5 HashMap (java.util.HashMap)5 AlertDialog (android.support.v7.app.AlertDialog)4 MusicFlowAdapter (com.wm.remusic.adapter.MusicFlowAdapter)4 Cursor (android.database.Cursor)3 ImageView (android.widget.ImageView)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ContentResolver (android.content.ContentResolver)2 Handler (android.os.Handler)2 LinearLayout (android.widget.LinearLayout)2 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)2