| | |
| | | import android.content.Intent; |
| | | import android.content.res.AssetManager; |
| | | import android.media.MediaPlayer; |
| | | import android.net.Uri; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | |
| | | import com.lzy.okgo.cache.CacheMode; |
| | | import com.moral.andbrickslib.baseadapter.headandfooter.DividerItemDecoration; |
| | | import com.moral.andbrickslib.baseadapter.recyclerview.MultiItemTypeAdapter; |
| | | import com.moral.yunfushao.MainApp; |
| | | import com.moral.yunfushao.R; |
| | | import com.moral.yunfushao.adapter.SongAdapter; |
| | | import com.moral.yunfushao.adapter.VoiceAdapter; |
| | | import com.moral.yunfushao.base.BaseListActivity; |
| | | import com.moral.yunfushao.common.API; |
| | | import com.moral.yunfushao.httputils.HttpCallBack; |
| | | import com.moral.yunfushao.httputils.HttpUtils; |
| | | import com.moral.yunfushao.model.Song; |
| | | import com.moral.yunfushao.model.VoiceBean; |
| | | import com.moral.yunfushao.utils.AudioUtils; |
| | | import com.moral.yunfushao.utils.PermissionUtil; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Created by haijiang on 2017/7/12. |
| | | */ |
| | | |
| | | public class ChooseSongActivity extends BaseListActivity implements SongAdapter.OnBtnClickListener{ |
| | | public class ChooseSongActivity extends BaseListActivity implements SongAdapter.OnBtnClickListener { |
| | | private SongAdapter adapter; |
| | | private ArrayList<Song> voiceList = new ArrayList<>(); |
| | | AssetManager am; |
| | | MediaPlayer mp; |
| | | Handler mHandler = new Handler(){ |
| | | Handler mHandler = new Handler() { |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | super.handleMessage(msg); |
| | | if(msg.what == 1){ |
| | | if (msg.what == 1) { |
| | | setNormalView(); |
| | | mPtrFrame.refreshComplete(); |
| | | adapter.notifyDataSetChanged(); |
| | |
| | | } |
| | | }; |
| | | private int index; |
| | | |
| | | @Override |
| | | protected void initOtherView() { |
| | | index = getIntent().getIntExtra("position",0); |
| | | PermissionUtil.verifyStoragePermissions(this); |
| | | index = getIntent().getIntExtra("position", 0); |
| | | tv_title.setText("本地铃声"); |
| | | DividerItemDecoration line = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST); |
| | | mRecyclerView.addItemDecoration(line); |
| | |
| | | protected void onLoadMore() { |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | if(mp!=null&&mp.isPlaying()){ |
| | | if (mp != null && mp.isPlaying()) { |
| | | mp.stop(); |
| | | mp.release(); |
| | | } |
| | |
| | | protected void initListener() { |
| | | |
| | | } |
| | | Thread mThread; |
| | | |
| | | Thread mThread; |
| | | |
| | | @Override |
| | | protected void initData() { |
| | | getData(); |
| | | } |
| | | private void getData(){ |
| | | |
| | | private void getData() { |
| | | setLoadingView(); |
| | | mThread = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | ArrayList<Song> temp = AudioUtils.getAllSongs(ChooseSongActivity.this); |
| | | if(temp!=null){ |
| | | if (temp != null) { |
| | | voiceList.clear(); |
| | | voiceList.addAll(temp); |
| | | mHandler.sendEmptyMessage(1); |
| | |
| | | |
| | | @Override |
| | | protected void processClick(View view) { |
| | | switch (view.getId()){ |
| | | switch (view.getId()) { |
| | | case R.id.tv_left: |
| | | finish(); |
| | | break; |
| | |
| | | @Override |
| | | public void playClick(int position) { |
| | | Song voiceBean = voiceList.get(position); |
| | | if(voiceBean.isPlay()){ |
| | | if (voiceBean.isPlay()) { |
| | | mp.stop(); |
| | | voiceBean.setPlay(false); |
| | | }else{ |
| | | if(mp!=null&&mp.isPlaying()){ |
| | | } else { |
| | | if (mp != null && mp.isPlaying()) { |
| | | mp.stop(); |
| | | mp.release(); |
| | | for (Song voice :voiceList){ |
| | | for (Song voice : voiceList) { |
| | | voice.setPlay(false); |
| | | } |
| | | adapter.notifyDataSetChanged(); |
| | |
| | | @Override |
| | | public void setClick(int position) { |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("position",index); |
| | | intent.putExtra("url",voiceList.get(position).getFileUrl()); |
| | | intent.putExtra("name",voiceList.get(position).getTitle()); |
| | | setResult(RESULT_OK,intent); |
| | | intent.putExtra("position", index); |
| | | intent.putExtra("url", voiceList.get(position).getFileUrl()); |
| | | intent.putExtra("name", voiceList.get(position).getTitle()); |
| | | setResult(RESULT_OK, intent); |
| | | finish(); |
| | | } |
| | | } |