张海江
2017-07-26 8dcf4645301af81d39bbcb936b52eb8f904352e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.moral.yunfushao.activity;
 
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
 
import com.moral.andbrickslib.baseadapter.headandfooter.DividerItemDecoration;
import com.moral.yunfushao.R;
import com.moral.yunfushao.adapter.VoiceAdapter;
import com.moral.yunfushao.base.BaseListActivity;
import com.moral.yunfushao.model.VoiceBean;
 
import java.util.ArrayList;
 
/**
 * Created by haijiang on 2017/7/12.
 */
 
public class VoiceSetActivity extends BaseListActivity implements VoiceAdapter.OnBtnClickListener{
    private VoiceAdapter adapter;
    private ArrayList<VoiceBean> voiceList = new ArrayList<>();
    AssetManager am;
    MediaPlayer mp;
    @Override
    protected void initOtherView() {
        tv_title.setText("设置铃声");
        VoiceBean voiceBean = new VoiceBean();
        voiceBean.setId(0);
        voiceBean.setRes(R.raw.music);
        voiceBean.setName("music");
        voiceList.add(voiceBean);
        voiceBean = new VoiceBean();
        voiceBean.setId(1);
        voiceBean.setRes(R.raw.music1);
        voiceBean.setName("music1");
        voiceList.add(voiceBean);
        DividerItemDecoration line = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST);
        mRecyclerView.addItemDecoration(line);
        adapter = new VoiceAdapter(mRecyclerView, R.layout.list_item_voice, voiceList);
        adapter.setOnBtnClickListener(this);
        mRecyclerView.setAdapter(adapter);
    }
 
    @Override
    protected void onLoadMore() {
 
    }
 
    @Override
    protected void onRefresh() {
 
    }
 
    @Override
    protected void getBundleExtras(Bundle extras) {
 
    }
 
    @Override
    protected void initListener() {
 
    }
 
    @Override
    protected void initData() {
        setNormalView();
 
    }
 
    @Override
    protected void processClick(View view) {
        switch (view.getId()){
            case R.id.tv_left:
                finish();
                break;
        }
 
    }
 
    @Override
    protected void onErrorPageClick() {
 
    }
 
    @Override
    public void playClick(int position) {
        VoiceBean voiceBean = voiceList.get(position);
        if(voiceBean.isPlay()){
            mp.stop();
            voiceBean.setPlay(false);
        }else{
            if(mp!=null&&mp.isPlaying()){
                mp.stop();
                mp.release();
                for (VoiceBean voice :voiceList){
                    voice.setPlay(false);
                }
                adapter.notifyDataSetChanged();
            }
            mp = MediaPlayer.create(this, voiceBean.getRes());
            mp.start();
            voiceBean.setPlay(true);
        }
        adapter.notifyDataSetChanged();
    }
 
    @Override
    public void setClick(int position) {
 
    }
}