headers = null;
84 | if (mWebView != null)
85 | mWebView.loadUrl(mUrl, headers);
86 | else {
87 | ToastUtils.showShortToast(this, "网页出现异常,请稍后重试");
88 | finish();
89 | return;
90 | }
91 | }
92 |
93 |
94 | @TargetApi(Build.VERSION_CODES.KITKAT)
95 | @SuppressLint("SetJavaScriptEnabled")
96 | private void setWebView() {
97 | WebSettings ws = mWebView.getSettings();
98 | ws.setBuiltInZoomControls(true);
99 | ws.setSupportZoom(true);
100 | ws.setJavaScriptEnabled(true);
101 | ws.setCacheMode(WebSettings.LOAD_NO_CACHE);
102 | ws.setDomStorageEnabled(true);
103 | mWebView.setWebViewClient(new MyWebViewClient());
104 | mWebView.setWebChromeClient(new MyWebChromeClient());
105 | }
106 |
107 | class MyWebChromeClient extends WebChromeClient {
108 |
109 | @Override
110 | public void onReceivedTitle(WebView view, String title) {
111 | super.onReceivedTitle(view, title);
112 | }
113 |
114 | public void onProgressChanged(WebView view, int newProgress) {
115 | super.onProgressChanged(view, newProgress);
116 | mProgress.setProgress(newProgress);
117 | mProgress.postInvalidate();
118 | }
119 | }
120 |
121 | class MyWebViewClient extends WebViewClient {
122 | @Override
123 | public void onPageFinished(final WebView view, String url) {
124 | super.onPageFinished(view, url);
125 | mProgress.setVisibility(View.GONE);
126 | mWebView.loadUrl("javascript:window.javascript.setTitle( $.utils.getAppTitle() )");
127 | }
128 |
129 |
130 | @Override
131 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
132 | if (!TextUtils.isEmpty(url)) {
133 | if (url.startsWith("tel:")) {
134 | Intent intent = new Intent(Intent.ACTION_DIAL,
135 | Uri.parse(url));
136 | startActivity(intent);
137 | return true;
138 | }
139 | }
140 | if (url.contains("/back-app")) {
141 | WebViewActivity.this.finish();
142 | return true;
143 | }
144 | return false;
145 | }
146 |
147 | }
148 |
149 | @Override
150 | public boolean onKeyDown(int keyCode, KeyEvent event) {
151 | if (keyCode == KeyEvent.KEYCODE_BACK) {
152 | if (mWebView.canGoBack()) {
153 | mWebView.goBack();
154 | } else {
155 | finish();
156 | }
157 | }
158 | return false;
159 | }
160 |
161 | @Override
162 | public boolean onOptionsItemSelected(MenuItem item) {
163 | switch (item.getItemId()) {
164 | case android.R.id.home:
165 | finish();
166 | break;
167 | }
168 | return super.onOptionsItemSelected(item);
169 | }
170 |
171 | @Override
172 | protected void onDestroy() {
173 | if (mWebView != null) {
174 | mWebView.removeAllViews();
175 | }
176 | super.onDestroy();
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lin/mu/helper/MediaPlayerManager.java:
--------------------------------------------------------------------------------
1 | package com.lin.mu.helper;
2 |
3 | import android.content.Context;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorEvent;
6 | import android.hardware.SensorEventListener;
7 | import android.hardware.SensorManager;
8 | import android.media.AudioManager;
9 | import android.media.MediaPlayer;
10 | import android.media.MediaPlayer.OnCompletionListener;
11 | import android.media.MediaPlayer.OnPreparedListener;
12 | import android.os.Handler;
13 | import android.util.Log;
14 |
15 | import java.util.Timer;
16 | import java.util.TimerTask;
17 |
18 |
19 | /**
20 | * Created by lin on 2016/8/4.
21 | */
22 |
23 | public class MediaPlayerManager {
24 |
25 | private static final String TAG = "MediaPlayerManager";
26 | private Context mContext;
27 | private Timer timer;
28 | private Handler handler;
29 | private TimerTask task;
30 |
31 |
32 | private MediaPlayerManager(Context ctx) {
33 | mContext = ctx;
34 | initMediaPlayer();
35 | initSensor();
36 | }
37 |
38 | public static MediaPlayerManager getInstance(Context ctx) {
39 | return new MediaPlayerManager(ctx);
40 | }
41 |
42 | public void initHandler(Handler handler) {
43 | this.handler = handler;
44 | }
45 |
46 |
47 | public void startMediaPlayer(String path) {
48 | if (mMediaPlayer == null) {
49 | initMediaPlayer();
50 | }
51 | mMediaPlayer.reset();
52 | try {
53 | mMediaPlayer.setDataSource(path);
54 | mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
55 | mMediaPlayer.prepareAsync();
56 | } catch (Exception e) {
57 | Log.d(TAG, "startMediaPlayer error");
58 | }
59 | }
60 |
61 | public void stopMediaPlayer() {
62 | if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
63 | mMediaPlayer.stop();
64 | }
65 | }
66 |
67 | public void registerSensorListener() {
68 | if (!isSensorListenerRegistered) {
69 | mSensorManager.registerListener(mSensorListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
70 | isSensorListenerRegistered = true;
71 | }
72 | }
73 |
74 | public void unregisterSensorListener() {
75 | if (isSensorListenerRegistered) {
76 | mSensorManager.unregisterListener(mSensorListener);
77 | isSensorListenerRegistered = false;
78 | }
79 | }
80 |
81 | public void releaseMediaPlayer() {
82 | if (mMediaPlayer != null) {
83 | mMediaPlayer.release();
84 | mMediaPlayer = null;
85 | }
86 | unregisterSensorListener();
87 | }
88 |
89 | /**
90 | * 设置播放器播放完成后的监听事件
91 | */
92 | public void setPlayerCompletionListener(OnCompletionListener listener) {
93 | if (listener != null) {
94 | mCompletionListener = listener;
95 | if (mMediaPlayer == null) {
96 | initMediaPlayer();
97 | }
98 | mMediaPlayer.setOnCompletionListener(listener);
99 | }
100 | }
101 |
102 | public void setOnMediaPlayerListener(OnMediaPlayerListener onMediaPlayerListener) {
103 | this.onMediaPlayerListener = onMediaPlayerListener;
104 | }
105 |
106 | OnMediaPlayerListener onMediaPlayerListener;
107 |
108 | public interface OnMediaPlayerListener {
109 |
110 | void onStart(MediaPlayer mp);
111 | }
112 |
113 | // =================== 播放电话录音 ========================
114 | private MediaPlayer mMediaPlayer;
115 | private OnCompletionListener mCompletionListener;
116 |
117 | private void initMediaPlayer() {
118 | mMediaPlayer = new MediaPlayer();
119 | mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
120 |
121 | @Override
122 | public void onPrepared(MediaPlayer mp) {
123 | mMediaPlayer.start();
124 | startTimer();
125 | if (onMediaPlayerListener != null) {
126 | onMediaPlayerListener.onStart(mp);
127 | }
128 | }
129 | });
130 | if (mCompletionListener != null) {
131 | mMediaPlayer.setOnCompletionListener(mCompletionListener);
132 | }
133 | }
134 |
135 | private void startTimer() {
136 | if (this.handler == null) {
137 | return;
138 | }
139 | if (timer == null) {
140 | timer = new Timer(true);
141 | }
142 | // timer.cancel();
143 | task = new TimerTask() {
144 | @Override
145 | public void run() {
146 | if (mMediaPlayer == null) {
147 | cancelTask();
148 | return;
149 | }
150 | if (mMediaPlayer.isPlaying()) {
151 | handler.sendEmptyMessage(0);
152 | } else {
153 | handler.sendEmptyMessage(1);
154 | }
155 | }
156 | };
157 | timer.schedule(task, 0, 50);
158 | }
159 |
160 | public void cancelTask() {
161 | if (task != null) {
162 | task.cancel();
163 | }
164 | }
165 |
166 |
167 | public MediaPlayer getmMediaPlayer() {
168 | return mMediaPlayer;
169 | }
170 | // =============== 距离传感器 =================
171 |
172 | private SensorManager mSensorManager;
173 | private Sensor mSensor;
174 | private boolean isSensorListenerRegistered = false;
175 | private AudioManager mAudioManager;
176 | private SensorEventListener mSensorListener = new SensorEventListener() {
177 |
178 | @Override
179 | public void onSensorChanged(SensorEvent event) {
180 | if (event.values[0] == mSensor.getMaximumRange()) {
181 | mAudioManager.setMode(AudioManager.MODE_NORMAL);
182 | } else {
183 | mAudioManager.setMode(AudioManager.MODE_IN_CALL);
184 | }
185 | }
186 |
187 | @Override
188 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
189 | }
190 | };
191 |
192 | private void initSensor() {
193 | mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
194 | mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
195 | mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
196 | registerSensorListener();
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lin/mu/utils/SystemUiHider.java:
--------------------------------------------------------------------------------
1 | package com.lin.mu.utils;
2 |
3 | import android.app.Activity;
4 | import android.os.Build;
5 | import android.view.View;
6 |
7 | /**
8 | * A utility class that helps with showing and hiding system UI such as the
9 | * status bar and navigation/system bar. This class uses backward-compatibility
10 | * techniques described in
12 | * Creating Backward-Compatible UIs to ensure that devices running any
13 | * version of ndroid OS are supported. More specifically, there are separate
14 | * implementations of this abstract class: for newer devices,
15 | * {@link #getInstance} will return a {@link SystemUiHiderHoneycomb} instance,
16 | * while on older devices {@link #getInstance} will return a
17 | * {@link SystemUiHiderBase} instance.
18 | *
19 | * For more on system bars, see System Bars.
22 | *
23 | * @see View#setSystemUiVisibility(int)
24 | * @see android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN
25 | */
26 | public abstract class SystemUiHider {
27 | /**
28 | * When this flag is set, the
29 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN}
30 | * flag will be set on older devices, making the status bar "float" on top
31 | * of the activity layout. This is most useful when there are no controls at
32 | * the top of the activity layout.
33 | *
34 | * This flag isn't used on newer devices because the action
36 | * bar, the most important structural element of an Android app, should
37 | * be visible and not obscured by the system UI.
38 | */
39 | public static final int FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES = 0x1;
40 |
41 | /**
42 | * When this flag is set, {@link #show()} and {@link #hide()} will toggle
43 | * the visibility of the status bar. If there is a navigation bar, show and
44 | * hide will toggle low profile mode.
45 | */
46 | public static final int FLAG_FULLSCREEN = 0x2;
47 |
48 | /**
49 | * When this flag is set, {@link #show()} and {@link #hide()} will toggle
50 | * the visibility of the navigation bar, if it's present on the device and
51 | * the device allows hiding it. In cases where the navigation bar is present
52 | * but cannot be hidden, show and hide will toggle low profile mode.
53 | */
54 | public static final int FLAG_HIDE_NAVIGATION = FLAG_FULLSCREEN | 0x4;
55 |
56 | /**
57 | * The activity associated with this UI hider object.
58 | */
59 | protected Activity mActivity;
60 |
61 | /**
62 | * The view on which {@link View#setSystemUiVisibility(int)} will be called.
63 | */
64 | protected View mAnchorView;
65 |
66 | /**
67 | * The current UI hider flags.
68 | *
69 | * @see #FLAG_FULLSCREEN
70 | * @see #FLAG_HIDE_NAVIGATION
71 | * @see #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES
72 | */
73 | protected int mFlags;
74 |
75 | /**
76 | * The current visibility callback.
77 | */
78 | protected OnVisibilityChangeListener mOnVisibilityChangeListener = sDummyListener;
79 |
80 | /**
81 | * Creates and returns an instance of {@link SystemUiHider} that is
82 | * appropriate for this device. The object will be either a
83 | * {@link SystemUiHiderBase} or {@link SystemUiHiderHoneycomb} depending on
84 | * the device.
85 | *
86 | * @param activity The activity whose window's system UI should be
87 | * controlled by this class.
88 | * @param anchorView The view on which
89 | * {@link View#setSystemUiVisibility(int)} will be called.
90 | * @param flags Either 0 or any combination of {@link #FLAG_FULLSCREEN},
91 | * {@link #FLAG_HIDE_NAVIGATION}, and
92 | * {@link #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES}.
93 | */
94 | public static SystemUiHider getInstance(Activity activity, View anchorView, int flags) {
95 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
96 | return new SystemUiHiderHoneycomb(activity, anchorView, flags);
97 | } else {
98 | return new SystemUiHiderBase(activity, anchorView, flags);
99 | }
100 | }
101 |
102 | protected SystemUiHider(Activity activity, View anchorView, int flags) {
103 | mActivity = activity;
104 | mAnchorView = anchorView;
105 | mFlags = flags;
106 | }
107 |
108 | /**
109 | * Sets up the system UI hider. Should be called from
110 | * {@link Activity#onCreate}.
111 | */
112 | public abstract void setup();
113 |
114 | /**
115 | * Returns whether or not the system UI is visible.
116 | */
117 | public abstract boolean isVisible();
118 |
119 | /**
120 | * Hide the system UI.
121 | */
122 | public abstract void hide();
123 |
124 | /**
125 | * Show the system UI.
126 | */
127 | public abstract void show();
128 |
129 | /**
130 | * Toggle the visibility of the system UI.
131 | */
132 | public void toggle() {
133 | if (isVisible()) {
134 | hide();
135 | } else {
136 | show();
137 | }
138 | }
139 |
140 | /**
141 | * Registers a callback, to be triggered when the system UI visibility
142 | * changes.
143 | */
144 | public void setOnVisibilityChangeListener(OnVisibilityChangeListener listener) {
145 | if (listener == null) {
146 | listener = sDummyListener;
147 | }
148 |
149 | mOnVisibilityChangeListener = listener;
150 | }
151 |
152 | /**
153 | * A dummy no-op callback for use when there is no other listener set.
154 | */
155 | private static OnVisibilityChangeListener sDummyListener = new OnVisibilityChangeListener() {
156 | @Override
157 | public void onVisibilityChange(boolean visible) {
158 | }
159 | };
160 |
161 | /**
162 | * A callback interface used to listen for system UI visibility changes.
163 | */
164 | public interface OnVisibilityChangeListener {
165 | /**
166 | * Called when the system UI visibility has changed.
167 | *
168 | * @param visible True if the system UI is visible.
169 | */
170 | public void onVisibilityChange(boolean visible);
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lin/mu/ui/fragment/PhotoFragment.java:
--------------------------------------------------------------------------------
1 | package com.lin.mu.ui.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.support.v7.widget.StaggeredGridLayoutManager;
8 | import android.text.TextUtils;
9 | import android.view.View;
10 |
11 | import com.lin.mu.R;
12 | import com.lin.mu.base.BaseFragment;
13 | import com.lin.mu.contract.PhotoContract;
14 | import com.lin.mu.model.PhotoModel;
15 | import com.lin.mu.ui.adapter.PhotoAdapter;
16 | import com.lin.mu.presenter.PhotoPresenter;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import butterknife.BindView;
22 |
23 | /**
24 | * Created by lin on 2016/8/2.
25 | */
26 | public class PhotoFragment extends BaseFragment implements PhotoContract.View, SwipeRefreshLayout.OnRefreshListener, View.OnClickListener {
27 |
28 | @BindView(R.id.swipeRefreshLayout)
29 | SwipeRefreshLayout swipeRefreshLayout;
30 | @BindView(R.id.mRecycleView)
31 | RecyclerView mRecyclerView;
32 | @BindView(R.id.container_error)
33 | View errorView;
34 | @BindView(R.id.container_no_net)
35 | View noNetView;
36 | @BindView(R.id.container_empty)
37 | View emptyView;
38 |
39 | private PhotoPresenter presenter;
40 | private PhotoAdapter photoAdapter;
41 | private List photos;
42 | private int mPageNum = 1;
43 | private boolean canLoadMore = false;
44 | private String id;
45 | private StaggeredGridLayoutManager mGridViewLayoutManager;
46 |
47 | @Override
48 | protected int getLayoutResource() {
49 | return R.layout.fragment_photo;
50 | }
51 |
52 | @Override
53 | public void onCreate(@Nullable Bundle savedInstanceState) {
54 | super.onCreate(savedInstanceState);
55 | photos = new ArrayList<>();
56 | Bundle bundle = getArguments();
57 | id = (String) bundle.get("extra");
58 | }
59 |
60 | @Override
61 | protected void initView(View view) {
62 | setAdapter();
63 | setPresenter();
64 | addListener();
65 | if (!TextUtils.isEmpty(id)) {
66 | loadPictures(id, true);
67 | }
68 | }
69 |
70 |
71 | private void addListener() {
72 | photoAdapter.setOnItemActionListener(new PhotoAdapter.OnItemActionListener() {
73 | @Override
74 | public void onItemClickListener(View v, int pos) {
75 |
76 | }
77 |
78 | @Override
79 | public boolean onItemLongClickListener(View v, int pos) {
80 | return false;
81 | }
82 | });
83 | swipeRefreshLayout.setOnRefreshListener(this);
84 | swipeRefreshLayout.setColorSchemeColors(R.color.primary_dark);
85 | mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
86 | @Override
87 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
88 | super.onScrollStateChanged(recyclerView, newState);
89 | }
90 |
91 | @Override
92 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
93 | super.onScrolled(recyclerView, dx, dy);
94 | View lastChildView = recyclerView.getLayoutManager().getChildAt(recyclerView.getLayoutManager().getChildCount() - 1);
95 | int lastChildBottom = lastChildView.getBottom();
96 | int recyclerBottom = recyclerView.getBottom() - recyclerView.getPaddingBottom();
97 | int lastPosition = recyclerView.getLayoutManager().getPosition(lastChildView);
98 | if (lastChildBottom == recyclerBottom && lastPosition == recyclerView.getLayoutManager().getItemCount() - 1) {
99 | if (canLoadMore) {
100 | loadPictures(id, false);
101 | }
102 | }
103 | }
104 | });
105 | }
106 |
107 | private void setAdapter() {
108 | photoAdapter = new PhotoAdapter(getContext());
109 | mGridViewLayoutManager = new StaggeredGridLayoutManager(2,
110 | StaggeredGridLayoutManager.VERTICAL);
111 | mRecyclerView.setLayoutManager(mGridViewLayoutManager);
112 | mRecyclerView.setAdapter(photoAdapter);
113 | }
114 |
115 | private void setPresenter() {
116 | presenter = new PhotoPresenter(getContext());
117 | presenter.attachView(this);
118 | }
119 |
120 | @Override
121 | public void onLoadSuccess(List lists) {
122 | if (lists != null && lists.size() > 0) {
123 | if (mPageNum == 1) {
124 | photos.clear();
125 | }
126 | photos.addAll(lists);
127 | photoAdapter.setDatas(photos);
128 | if (isRefresh) {
129 | if (swipeRefreshLayout != null && swipeRefreshLayout.isRefreshing()) {
130 | swipeRefreshLayout.setRefreshing(false);
131 | }
132 | mRecyclerView.smoothScrollToPosition(0);
133 | }
134 | } else {
135 | if (swipeRefreshLayout != null && swipeRefreshLayout.isRefreshing()) {
136 | swipeRefreshLayout.setRefreshing(false);
137 | }
138 | }
139 | }
140 |
141 | @Override
142 | public void canMore(PhotoModel.PageBean page) {
143 | if (page == null) {
144 | return;
145 | }
146 | if (Integer.valueOf(page.allPages) > Integer.valueOf(page.currentPage)) {
147 | canLoadMore = true;
148 | photoAdapter.canLoad(true);
149 | } else {
150 | canLoadMore = false;
151 | photoAdapter.canLoad(false);
152 | }
153 | }
154 |
155 | boolean isRefresh = true;
156 |
157 |
158 | private void loadPictures(String id, boolean isRresh) {
159 | if (isRresh) {
160 | mPageNum = 1;
161 | isRefresh = true;
162 | } else {
163 | mPageNum++;
164 | isRefresh = false;
165 | }
166 | presenter.loadListData(id, mPageNum);
167 | }
168 |
169 | @Override
170 | public void onRefresh() {
171 | swipeRefreshLayout.setRefreshing(true);
172 | loadPictures(id, true);
173 | }
174 |
175 | @Override
176 | public void onClick(View view) {
177 | switch (view.getId()) {
178 | }
179 | }
180 |
181 | @Override
182 | public void showLoading() {
183 | }
184 |
185 | @Override
186 | public void showEmpty() {
187 | }
188 |
189 | @Override
190 | public void showError() {
191 | }
192 |
193 | @Override
194 | public void onDestroy() {
195 | super.onDestroy();
196 | presenter.detachView();
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lin/mu/views/VoiceCircleProgress.java:
--------------------------------------------------------------------------------
1 | package com.lin.mu.views;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Path;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.util.TypedValue;
12 | import android.widget.ProgressBar;
13 |
14 | import com.lin.mu.R;
15 |
16 |
17 | /**
18 | * Created by lin on 2016/7/29.
19 | */
20 | public class VoiceCircleProgress extends ProgressBar {
21 |
22 | private static final int PROGRESS_DEFAULT_COLOR = 0xFFd3d6da;//默认圆(边框)的颜色
23 | private static final int PROGRESS_REACHED_COLOR = 0XFFFC00D1;//进度条的颜色
24 | private static final float PROGRESS_REACHED_HEIGHT = 2.0f;//进度条的高度
25 | private static final float PROGRESS_DEFAULT_HEIGHT = 0.5f;//默认圆的高度
26 | private static final int PROGRESS_RADIUS = 14;//圆的半径
27 |
28 | //View的当前状态,默认为未开始
29 | private Status mStatus = Status.End;
30 | private Paint mPaint;
31 | private int mReachedColor = PROGRESS_REACHED_COLOR;
32 | private int mReachedHeight = dp2px(Integer.valueOf((int) PROGRESS_REACHED_HEIGHT));
33 | private int mDefaultColor = PROGRESS_DEFAULT_COLOR;
34 | private int mDefaultHeight = dp2px(Integer.valueOf((int) PROGRESS_DEFAULT_HEIGHT));
35 | //圆的半径
36 | private int mRadius = dp2px(PROGRESS_RADIUS);
37 | //通过path路径去绘制三角形
38 | private Path mPath;
39 | //三角形的边长
40 | private int triangleLength;
41 |
42 |
43 | public enum Status {
44 | End,
45 | Starting
46 | }
47 |
48 | public VoiceCircleProgress(Context context) {
49 | this(context, null);
50 | }
51 |
52 | public VoiceCircleProgress(Context context, AttributeSet attrs) {
53 | this(context, attrs, 0);
54 | }
55 |
56 | public VoiceCircleProgress(Context context, AttributeSet attrs, int defStyleAttr) {
57 | super(context, attrs, defStyleAttr);
58 | //获取自定义属性的值
59 | TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.CustomCircleProgress);
60 | //默认圆的颜色
61 | mDefaultColor = array.getColor(R.styleable.CustomCircleProgress_progress_default_color, PROGRESS_DEFAULT_COLOR);
62 | //进度条的颜色
63 | mReachedColor = array.getColor(R.styleable.CustomCircleProgress_progress_reached_color, PROGRESS_REACHED_COLOR);
64 | //默认圆的高度
65 | mDefaultHeight = (int) array.getDimension(R.styleable.CustomCircleProgress_progress_default_height, mDefaultHeight);
66 | //进度条的高度
67 | mReachedHeight = (int) array.getDimension(R.styleable.CustomCircleProgress_progress_reached_height, mReachedHeight);
68 | //圆的半径
69 | mRadius = (int) array.getDimension(R.styleable.CustomCircleProgress_circle_radius, mRadius);
70 | array.recycle();
71 |
72 | setPaint();
73 |
74 | //通过path路径绘制三角形
75 | mPath = new Path();
76 | triangleLength = mRadius;
77 | float firstX = (float) ((mRadius * 2 - Math.sqrt(3.0) / 2 * mRadius) / 2);//左上角第一个点的横坐标,根据勾三股四弦五定律,Math.sqrt(3.0)表示对3开方
78 | float mFirstX = (float) (firstX + firstX * 0.2);
79 | float firstY = mRadius - triangleLength / 2.5f;
80 | float secondX = mFirstX;
81 | float secondY = (float) (mRadius + triangleLength / 2.5);
82 | float thirdX = (float) (mFirstX + Math.sqrt(3.0) / 2.5 * mRadius);
83 | float thirdY = mRadius;
84 | mPath.moveTo(mFirstX, firstY);
85 | mPath.lineTo(secondX, secondY);
86 | mPath.lineTo(thirdX, thirdY);
87 | mPath.lineTo(mFirstX, firstY);
88 | }
89 |
90 | private void setPaint() {
91 | mPaint = new Paint();
92 | //下面是设置画笔的一些属性
93 | mPaint.setAntiAlias(true);//抗锯齿
94 | mPaint.setDither(true);//防抖动,绘制出来的图要更加柔和清晰
95 | mPaint.setStyle(Paint.Style.STROKE);//设置填充样式
96 | /**
97 | * Paint.Style.FILL :填充内部
98 | * Paint.Style.FILL_AND_STROKE :填充内部和描边
99 | * Paint.Style.STROKE :仅描边
100 | */
101 | mPaint.setStrokeCap(Paint.Cap.ROUND);//设置画笔笔刷类型
102 | }
103 |
104 |
105 | @Override
106 | protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
107 |
108 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
109 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
110 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
111 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
112 |
113 | int paintHeight = Math.max(mReachedHeight, mDefaultHeight);//比较两数,取最大值
114 |
115 | if (heightMode != MeasureSpec.EXACTLY) {
116 | int exceptHeight = getPaddingTop() + getPaddingBottom() + mRadius * 2 + paintHeight;
117 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(exceptHeight, MeasureSpec.EXACTLY);
118 | }
119 | if (widthMode != MeasureSpec.EXACTLY) {
120 | int exceptWidth = getPaddingLeft() + getPaddingRight() + mRadius * 2 + paintHeight;
121 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(exceptWidth, MeasureSpec.EXACTLY);
122 | }
123 |
124 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
125 | }
126 |
127 | @Override
128 | protected synchronized void onDraw(Canvas canvas) {
129 | super.onDraw(canvas);
130 |
131 | canvas.translate(getPaddingLeft(), getPaddingTop());
132 | mPaint.setStyle(Paint.Style.STROKE);
133 | //画默认圆(边框)的一些设置
134 | mPaint.setColor(mDefaultColor);
135 | mPaint.setStrokeWidth(mDefaultHeight);
136 | canvas.drawCircle(mRadius, mRadius, mRadius, mPaint);
137 |
138 | //画进度条
139 | mPaint.setColor(mReachedColor);
140 | mPaint.setStrokeWidth(mReachedHeight);
141 | float sweepAngle = getProgress() * 1.0f / getMax() * 360;
142 | canvas.drawArc(new RectF(0, 0, mRadius * 2, mRadius * 2), -90, sweepAngle, false, mPaint);//drawArc:绘制圆弧
143 |
144 | if (mStatus == Status.End) {//未开始状态,画笔填充三角形
145 | mPaint.setStyle(Paint.Style.FILL);
146 | //设置颜色
147 | mPaint.setColor(Color.parseColor("#01A1EB"));
148 | //画三角形
149 | canvas.drawPath(mPath, mPaint);
150 | } else {
151 | mPaint.setStyle(Paint.Style.STROKE);
152 | mPaint.setStrokeWidth(dp2px(2));
153 | mPaint.setColor(Color.parseColor("#01A1EB"));
154 | canvas.drawLine(mRadius * 2 / 2.5f, mRadius * 2 / 3.2f, mRadius * 2 / 2.5f, 2 * mRadius * 2 / 3.2f, mPaint);
155 | canvas.drawLine(2 * mRadius - (mRadius * 2 / 2.5f), mRadius * 2 / 3.2f, 2 * mRadius - (mRadius * 2 / 2.5f), 2 * mRadius * 2 / 3.2f, mPaint);
156 | }
157 | canvas.save();
158 |
159 | }
160 |
161 | /**
162 | * dp 2 px
163 | *
164 | * @param dpVal
165 | */
166 | protected int dp2px(int dpVal) {
167 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
168 | dpVal, getResources().getDisplayMetrics());
169 | }
170 |
171 | /**
172 | * sp 2 px
173 | *
174 | * @param spVal
175 | * @return
176 | */
177 | protected int sp2px(int spVal) {
178 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
179 | spVal, getResources().getDisplayMetrics());
180 |
181 | }
182 |
183 |
184 | public Status getStatus() {
185 | return mStatus;
186 | }
187 |
188 | public void setStatus(Status status) {
189 | this.mStatus = status;
190 | invalidate();
191 | }
192 |
193 | }
194 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lin/mu/ui/adapter/MusicAdapter.java:
--------------------------------------------------------------------------------
1 | package com.lin.mu.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.media.MediaPlayer;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.text.TextUtils;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ImageView;
13 | import android.widget.ProgressBar;
14 | import android.widget.TextView;
15 |
16 | import com.bumptech.glide.Glide;
17 | import com.lin.mu.R;
18 | import com.lin.mu.helper.MediaPlayerManager;
19 | import com.lin.mu.model.Music;
20 | import com.lin.mu.model.PhotoModel;
21 | import com.lin.mu.views.VoiceCircleProgress;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import butterknife.BindView;
27 | import butterknife.ButterKnife;
28 |
29 | /**
30 | * Created by lin on 2016/8/2.
31 | */
32 | public class MusicAdapter extends RecyclerView.Adapter {
33 | private Context mContext;
34 | private List mList;
35 | private MediaPlayerManager playerManager;
36 |
37 | public MusicAdapter(Context ctx, List songs) {
38 | mContext = ctx;
39 | mList = songs;
40 | playerManager = MediaPlayerManager.getInstance(mContext);
41 | playerManager.initHandler(handler);
42 | }
43 |
44 |
45 | @Override
46 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
47 | View view = LayoutInflater.from(mContext).inflate(R.layout.layout_item_music, parent, false);
48 | return new ViewHolderMusic(view);
49 | }
50 |
51 | @Override
52 | public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
53 | ViewHolderMusic holder = (ViewHolderMusic) viewHolder;
54 | Music.ResultBean.SongsBean song = mList.get(position);
55 | if (!TextUtils.isEmpty(song.getName())) {
56 | holder.tvSong.setText(song.getName());
57 | }
58 | if (!TextUtils.isEmpty(song.getPicUrl())) {
59 | Glide.with(mContext).
60 | load(song.getPicUrl()).
61 | centerCrop().
62 | dontAnimate().
63 | placeholder(R.mipmap.ic_loading).
64 | error(R.mipmap.ic_loading).
65 | into(holder.imageView);
66 | } else if (!TextUtils.isEmpty(song.getAlbum().getPicUrl())) {
67 | Glide.with(mContext).
68 | load(song.getAlbum().getPicUrl()).
69 | centerCrop().
70 | dontAnimate().
71 | placeholder(R.mipmap.ic_loading).
72 | error(R.mipmap.ic_loading).
73 | into(holder.imageView);
74 | } else {
75 | holder.imageView.setImageResource(R.mipmap.eson);
76 | }
77 | holder.circleProgress.setTag(song);
78 | holder.circleProgress.setOnClickListener(new View.OnClickListener() {
79 | @Override
80 | public void onClick(View v) {
81 | if (v instanceof VoiceCircleProgress) {
82 | final VoiceCircleProgress masterLayout = (VoiceCircleProgress) v;
83 | isPlayingView = masterLayout;
84 | final Music.ResultBean.SongsBean song = (Music.ResultBean.SongsBean) v.getTag();
85 | if (lastMasterLayout != null && lastMasterLayout != masterLayout) {
86 | Music.ResultBean.SongsBean followUpTagLast = (Music.ResultBean.SongsBean) lastMasterLayout.getTag();
87 | lastMasterLayout.setProgress(100);
88 | lastMasterLayout.setStatus(VoiceCircleProgress.Status.End);
89 | followUpTagLast.setPlaying(false);
90 | }
91 | MediaPlayer mediaPlayer = playerManager.getmMediaPlayer();
92 | if (song.isPlaying() || (mediaPlayer != null && mediaPlayer.isPlaying())) {
93 | playerManager.cancelTask();
94 | playerManager.stopMediaPlayer();
95 | playerManager.releaseMediaPlayer();
96 | }
97 | if (song.isPlaying()) {
98 | masterLayout.setProgress(100);
99 | masterLayout.setStatus(VoiceCircleProgress.Status.End);
100 | song.setPlaying(false);
101 | } else {
102 | masterLayout.setProgress(0);
103 | masterLayout.setStatus(VoiceCircleProgress.Status.Starting);
104 | playerManager.startMediaPlayer(song.getAudio());
105 | song.setPlaying(true);
106 | playerManager.setPlayerCompletionListener(new MediaPlayer.OnCompletionListener() {
107 | @Override
108 | public void onCompletion(MediaPlayer mediaPlayer) {
109 | song.setPlaying(false);
110 | playerManager.cancelTask();
111 | playerManager.stopMediaPlayer();
112 | playerManager.releaseMediaPlayer();
113 | isPlayingView.setProgress(100);
114 | isPlayingView.setStatus(VoiceCircleProgress.Status.End);
115 | }
116 | });
117 | }
118 | lastMasterLayout = masterLayout;
119 | }
120 |
121 | }
122 | });
123 | }
124 |
125 |
126 | @Override
127 | public int getItemCount() {
128 | return mList.size() == 0 ? 0 : mList.size();
129 | }
130 |
131 |
132 | class ViewHolderMusic extends RecyclerView.ViewHolder {
133 |
134 | @BindView(R.id.iv_photo)
135 | ImageView imageView;
136 | @BindView(R.id.tv_song)
137 | TextView tvSong;
138 | @BindView(R.id.circleProgress)
139 | VoiceCircleProgress circleProgress;
140 |
141 | public ViewHolderMusic(final View itemView) {
142 | super(itemView);
143 | ButterKnife.bind(this, itemView);
144 | }
145 | }
146 |
147 | public void recycle() {
148 | playerManager.cancelTask();
149 | playerManager.releaseMediaPlayer();
150 | if (handler != null) {
151 | handler.removeCallbacksAndMessages(null);
152 | }
153 | }
154 |
155 | VoiceCircleProgress lastMasterLayout;
156 | VoiceCircleProgress isPlayingView;
157 |
158 |
159 | Handler handler = new Handler() {
160 | @Override
161 | public void handleMessage(Message msg) {
162 | super.handleMessage(msg);
163 | if (msg.what != -1) {
164 | MediaPlayer mediaPlayer = playerManager.getmMediaPlayer();
165 | if (mediaPlayer != null) {
166 | int position = mediaPlayer.getCurrentPosition();
167 | int duration = mediaPlayer.getDuration();
168 | lastMasterLayout.setProgress(position * 100 / duration);
169 | }
170 | if (msg.what == 1) {
171 | lastMasterLayout.setProgress(100);
172 | }
173 | } else {
174 | isPlayingView.setStatus(VoiceCircleProgress.Status.End);
175 | }
176 | }
177 | };
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lin/mu/views/CircleImageView.java:
--------------------------------------------------------------------------------
1 | package com.lin.mu.views;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapShader;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Matrix;
10 | import android.graphics.Paint;
11 | import android.graphics.RectF;
12 | import android.graphics.Shader;
13 | import android.graphics.drawable.BitmapDrawable;
14 | import android.graphics.drawable.ColorDrawable;
15 | import android.graphics.drawable.Drawable;
16 | import android.util.AttributeSet;
17 | import android.widget.ImageView;
18 |
19 | import com.lin.mu.R;
20 |
21 |
22 | public class CircleImageView extends ImageView {
23 |
24 | private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
25 |
26 | private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
27 | private static final int COLORDRAWABLE_DIMENSION = 1;
28 |
29 | private static final int DEFAULT_BORDER_WIDTH = 0;
30 | private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
31 |
32 | private final RectF mDrawableRect = new RectF();
33 | private final RectF mBorderRect = new RectF();
34 |
35 | private final Matrix mShaderMatrix = new Matrix();
36 | private final Paint mBitmapPaint = new Paint();
37 | private final Paint mBorderPaint = new Paint();
38 |
39 | private int mBorderColor = DEFAULT_BORDER_COLOR;
40 | private int mBorderWidth = DEFAULT_BORDER_WIDTH;
41 |
42 | private Bitmap mBitmap;
43 | private BitmapShader mBitmapShader;
44 | private int mBitmapWidth;
45 | private int mBitmapHeight;
46 |
47 | private float mDrawableRadius;
48 | private float mBorderRadius;
49 |
50 | private boolean mReady;
51 | private boolean mSetupPending;
52 |
53 | public CircleImageView(Context context) {
54 | super(context);
55 | }
56 |
57 | public CircleImageView(Context context, AttributeSet attrs) {
58 | this(context, attrs, 0);
59 | }
60 |
61 | public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
62 | super(context, attrs, defStyle);
63 | super.setScaleType(SCALE_TYPE);
64 |
65 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
66 |
67 | mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);
68 | mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR);
69 |
70 | a.recycle();
71 |
72 | mReady = true;
73 |
74 | if (mSetupPending) {
75 | setup();
76 | mSetupPending = false;
77 | }
78 | }
79 |
80 | @Override
81 | public ScaleType getScaleType() {
82 | return SCALE_TYPE;
83 | }
84 |
85 | @Override
86 | public void setScaleType(ScaleType scaleType) {
87 | if (scaleType != SCALE_TYPE) {
88 | throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));
89 | }
90 | }
91 |
92 | @Override
93 | protected void onDraw(Canvas canvas) {
94 | if (getDrawable() == null) {
95 | return;
96 | }
97 |
98 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius, mBitmapPaint);
99 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius, mBorderPaint);
100 | }
101 |
102 | @Override
103 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
104 | super.onSizeChanged(w, h, oldw, oldh);
105 | setup();
106 | }
107 |
108 | public int getBorderColor() {
109 | return mBorderColor;
110 | }
111 |
112 | public void setBorderColor(int borderColor) {
113 | if (borderColor == mBorderColor) {
114 | return;
115 | }
116 |
117 | mBorderColor = borderColor;
118 | mBorderPaint.setColor(mBorderColor);
119 | invalidate();
120 | }
121 |
122 | public int getBorderWidth() {
123 | return mBorderWidth;
124 | }
125 |
126 | public void setBorderWidth(int borderWidth) {
127 | if (borderWidth == mBorderWidth) {
128 | return;
129 | }
130 |
131 | mBorderWidth = borderWidth;
132 | setup();
133 | }
134 |
135 | @Override
136 | public void setImageBitmap(Bitmap bm) {
137 | super.setImageBitmap(bm);
138 | mBitmap = bm;
139 | setup();
140 | }
141 |
142 | @Override
143 | public void setImageDrawable(Drawable drawable) {
144 | super.setImageDrawable(drawable);
145 | mBitmap = getBitmapFromDrawable(drawable);
146 | setup();
147 | }
148 |
149 | @Override
150 | public void setImageResource(int resId) {
151 | super.setImageResource(resId);
152 | mBitmap = getBitmapFromDrawable(getDrawable());
153 | setup();
154 | }
155 |
156 | private Bitmap getBitmapFromDrawable(Drawable drawable) {
157 | if (drawable == null) {
158 | return null;
159 | }
160 |
161 | if (drawable instanceof BitmapDrawable) {
162 | return ((BitmapDrawable) drawable).getBitmap();
163 | }
164 |
165 | try {
166 | Bitmap bitmap;
167 |
168 | if (drawable instanceof ColorDrawable) {
169 | bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
170 | } else {
171 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
172 | }
173 |
174 | Canvas canvas = new Canvas(bitmap);
175 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
176 | drawable.draw(canvas);
177 | return bitmap;
178 | } catch (OutOfMemoryError e) {
179 | return null;
180 | }
181 | }
182 |
183 | private void setup() {
184 | if (!mReady) {
185 | mSetupPending = true;
186 | return;
187 | }
188 |
189 | if (mBitmap == null) {
190 | return;
191 | }
192 |
193 | mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
194 |
195 | mBitmapPaint.setAntiAlias(true);
196 | mBitmapPaint.setShader(mBitmapShader);
197 |
198 | mBorderPaint.setStyle(Paint.Style.STROKE);
199 | mBorderPaint.setAntiAlias(true);
200 | mBorderPaint.setColor(mBorderColor);
201 | mBorderPaint.setStrokeWidth(mBorderWidth);
202 |
203 | mBitmapHeight = mBitmap.getHeight();
204 | mBitmapWidth = mBitmap.getWidth();
205 |
206 | mBorderRect.set(0, 0, getWidth(), getHeight());
207 | mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2);
208 |
209 | mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
210 | mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
211 |
212 | updateShaderMatrix();
213 | invalidate();
214 | }
215 |
216 | private void updateShaderMatrix() {
217 | float scale;
218 | float dx = 0;
219 | float dy = 0;
220 |
221 | mShaderMatrix.set(null);
222 |
223 | if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
224 | scale = mDrawableRect.height() / (float) mBitmapHeight;
225 | dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
226 | } else {
227 | scale = mDrawableRect.width() / (float) mBitmapWidth;
228 | dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
229 | }
230 |
231 | mShaderMatrix.setScale(scale, scale);
232 | mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth);
233 |
234 | mBitmapShader.setLocalMatrix(mShaderMatrix);
235 | }
236 |
237 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/lin/mu/model/Music.java:
--------------------------------------------------------------------------------
1 | package com.lin.mu.model;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by lin on 2016/12/1.
7 | */
8 |
9 | public class Music {
10 |
11 | /**
12 | * result : {"songCount":931,"songs":[{"id":36894385,"name":"周杰伦","artists":[{"id":1040035,"name":"李雪莱","picUrl":null}],"album":{"id":3080398,"name":"李雪莱的Demo","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/CvoyIDli1TB3OSp6d3PChQ==/2539871862437570.jpg"},"audio":"http://m2.music.126.net/DVTJWTJoNUSDjLMsKXtxaw==/3393092905675046.mp3","djProgramId":0,"page":"http://music.163.com/m/song/36894385"},{"id":427609796,"name":"周杰伦《彩虹》","artists":[{"id":1202004,"name":"姜创钢琴","picUrl":null}],"album":{"id":34857346,"name":"周杰伦《彩虹》","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/g3gsJCmKMZ5Ul5lSAsPIvg==/18177126231131590.jpg"},"audio":"http://m2.music.126.net/16ZuBMUPnMf7FueBTVxXgA==/18799449811872323.mp3","djProgramId":0,"page":"http://music.163.com/m/song/427609796"}]}
13 | * code : 200
14 | */
15 |
16 | private ResultBean result;
17 | private int code;
18 |
19 | public ResultBean getResult() {
20 | return result;
21 | }
22 |
23 | public void setResult(ResultBean result) {
24 | this.result = result;
25 | }
26 |
27 | public int getCode() {
28 | return code;
29 | }
30 |
31 | public void setCode(int code) {
32 | this.code = code;
33 | }
34 |
35 | public static class ResultBean {
36 | /**
37 | * songCount : 931
38 | * songs : [{"id":36894385,"name":"周杰伦","artists":[{"id":1040035,"name":"李雪莱","picUrl":null}],"album":{"id":3080398,"name":"李雪莱的Demo","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/CvoyIDli1TB3OSp6d3PChQ==/2539871862437570.jpg"},"audio":"http://m2.music.126.net/DVTJWTJoNUSDjLMsKXtxaw==/3393092905675046.mp3","djProgramId":0,"page":"http://music.163.com/m/song/36894385"},{"id":427609796,"name":"周杰伦《彩虹》","artists":[{"id":1202004,"name":"姜创钢琴","picUrl":null}],"album":{"id":34857346,"name":"周杰伦《彩虹》","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/g3gsJCmKMZ5Ul5lSAsPIvg==/18177126231131590.jpg"},"audio":"http://m2.music.126.net/16ZuBMUPnMf7FueBTVxXgA==/18799449811872323.mp3","djProgramId":0,"page":"http://music.163.com/m/song/427609796"}]
39 | */
40 |
41 | private int songCount;
42 | private List songs;
43 |
44 | public int getSongCount() {
45 | return songCount;
46 | }
47 |
48 | public void setSongCount(int songCount) {
49 | this.songCount = songCount;
50 | }
51 |
52 | public List getSongs() {
53 | return songs;
54 | }
55 |
56 | public void setSongs(List songs) {
57 | this.songs = songs;
58 | }
59 |
60 | public static class SongsBean {
61 | /**
62 | * id : 36894385
63 | * name : 周杰伦
64 | * artists : [{"id":1040035,"name":"李雪莱","picUrl":null}]
65 | * album : {"id":3080398,"name":"李雪莱的Demo","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/CvoyIDli1TB3OSp6d3PChQ==/2539871862437570.jpg"}
66 | * audio : http://m2.music.126.net/DVTJWTJoNUSDjLMsKXtxaw==/3393092905675046.mp3
67 | * djProgramId : 0
68 | * page : http://music.163.com/m/song/36894385
69 | */
70 |
71 | private int id;
72 | private String name;
73 | private AlbumBean album;
74 | private String audio;
75 | private int djProgramId;
76 | private String page;
77 | private String picUrl;
78 | private List artists;
79 | public boolean isPlaying = false;// 是否在播放录音
80 |
81 | public boolean isPlaying() {
82 | return isPlaying;
83 | }
84 |
85 | public void setPlaying(boolean playing) {
86 | isPlaying = playing;
87 | }
88 |
89 | public String getPicUrl() {
90 | return picUrl;
91 | }
92 |
93 | public void setPicUrl(String picUrl) {
94 | this.picUrl = picUrl;
95 | }
96 |
97 | public int getId() {
98 | return id;
99 | }
100 |
101 | public void setId(int id) {
102 | this.id = id;
103 | }
104 |
105 | public String getName() {
106 | return name;
107 | }
108 |
109 | public void setName(String name) {
110 | this.name = name;
111 | }
112 |
113 | public AlbumBean getAlbum() {
114 | return album;
115 | }
116 |
117 | public void setAlbum(AlbumBean album) {
118 | this.album = album;
119 | }
120 |
121 | public String getAudio() {
122 | return audio;
123 | }
124 |
125 | public void setAudio(String audio) {
126 | this.audio = audio;
127 | }
128 |
129 | public int getDjProgramId() {
130 | return djProgramId;
131 | }
132 |
133 | public void setDjProgramId(int djProgramId) {
134 | this.djProgramId = djProgramId;
135 | }
136 |
137 | public String getPage() {
138 | return page;
139 | }
140 |
141 | public void setPage(String page) {
142 | this.page = page;
143 | }
144 |
145 | public List getArtists() {
146 | return artists;
147 | }
148 |
149 | public void setArtists(List artists) {
150 | this.artists = artists;
151 | }
152 |
153 | public static class AlbumBean {
154 | /**
155 | * id : 3080398
156 | * name : 李雪莱的Demo
157 | * artist : {"id":0,"name":"","picUrl":null}
158 | * picUrl : http://p1.music.126.net/CvoyIDli1TB3OSp6d3PChQ==/2539871862437570.jpg
159 | */
160 |
161 | private int id;
162 | private String name;
163 | private ArtistBean artist;
164 | private String picUrl;
165 |
166 | public int getId() {
167 | return id;
168 | }
169 |
170 | public void setId(int id) {
171 | this.id = id;
172 | }
173 |
174 | public String getName() {
175 | return name;
176 | }
177 |
178 | public void setName(String name) {
179 | this.name = name;
180 | }
181 |
182 | public ArtistBean getArtist() {
183 | return artist;
184 | }
185 |
186 | public void setArtist(ArtistBean artist) {
187 | this.artist = artist;
188 | }
189 |
190 | public String getPicUrl() {
191 | return picUrl;
192 | }
193 |
194 | public void setPicUrl(String picUrl) {
195 | this.picUrl = picUrl;
196 | }
197 |
198 | public static class ArtistBean {
199 | /**
200 | * id : 0
201 | * name :
202 | * picUrl : null
203 | */
204 |
205 | private int id;
206 | private String name;
207 | private Object picUrl;
208 |
209 | public int getId() {
210 | return id;
211 | }
212 |
213 | public void setId(int id) {
214 | this.id = id;
215 | }
216 |
217 | public String getName() {
218 | return name;
219 | }
220 |
221 | public void setName(String name) {
222 | this.name = name;
223 | }
224 |
225 | public Object getPicUrl() {
226 | return picUrl;
227 | }
228 |
229 | public void setPicUrl(Object picUrl) {
230 | this.picUrl = picUrl;
231 | }
232 | }
233 | }
234 |
235 | public static class ArtistsBean {
236 | /**
237 | * id : 1040035
238 | * name : 李雪莱
239 | * picUrl : null
240 | */
241 |
242 | private int id;
243 | private String name;
244 | private Object picUrl;
245 |
246 | public int getId() {
247 | return id;
248 | }
249 |
250 | public void setId(int id) {
251 | this.id = id;
252 | }
253 |
254 | public String getName() {
255 | return name;
256 | }
257 |
258 | public void setName(String name) {
259 | this.name = name;
260 | }
261 |
262 | public Object getPicUrl() {
263 | return picUrl;
264 | }
265 |
266 | public void setPicUrl(Object picUrl) {
267 | this.picUrl = picUrl;
268 | }
269 | }
270 | }
271 | }
272 | }
273 |
--------------------------------------------------------------------------------